Commit 7b2da629 by eguven Committed by Oliver Woodman

Make it possible to disable DownloadService notifications

Issue: #4389

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=204728270
parent 8f0729b5
......@@ -79,7 +79,7 @@
<service android:name="com.google.android.exoplayer2.demo.DemoDownloadService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.exoplayer.downloadService.action.INIT"/>
<action android:name="com.google.android.exoplayer.downloadService.action.RESTART"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</service>
......
......@@ -87,7 +87,7 @@ public final class RequirementsWatcher {
public void start() {
Assertions.checkNotNull(Looper.myLooper());
checkRequirements(true);
requirementsWereMet = requirements.checkRequirements(context);
IntentFilter filter = new IntentFilter();
if (requirements.getRequiredNetworkType() != Requirements.NETWORK_TYPE_NONE) {
......@@ -158,13 +158,11 @@ public final class RequirementsWatcher {
}
}
private void checkRequirements(boolean force) {
private void checkRequirements() {
boolean requirementsAreMet = requirements.checkRequirements(context);
if (!force) {
if (requirementsAreMet == requirementsWereMet) {
logd("requirementsAreMet is still " + requirementsAreMet);
return;
}
if (requirementsAreMet == requirementsWereMet) {
logd("requirementsAreMet is still " + requirementsAreMet);
return;
}
requirementsWereMet = requirementsAreMet;
if (requirementsAreMet) {
......@@ -187,7 +185,7 @@ public final class RequirementsWatcher {
public void onReceive(Context context, Intent intent) {
if (!isInitialStickyBroadcast()) {
logd(RequirementsWatcher.this + " received " + intent.getAction());
checkRequirements(false);
checkRequirements();
}
}
}
......@@ -198,14 +196,14 @@ public final class RequirementsWatcher {
public void onAvailable(Network network) {
super.onAvailable(network);
logd(RequirementsWatcher.this + " NetworkCallback.onAvailable");
checkRequirements(false);
checkRequirements();
}
@Override
public void onLost(Network network) {
super.onLost(network);
logd(RequirementsWatcher.this + " NetworkCallback.onLost");
checkRequirements(false);
checkRequirements();
}
}
}
......@@ -20,14 +20,12 @@ import static com.google.android.exoplayer2.source.dash.offline.DashDownloadTest
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertCacheEmpty;
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertCachedData;
import android.app.Notification;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.offline.DownloadAction;
import com.google.android.exoplayer2.offline.DownloadManager;
import com.google.android.exoplayer2.offline.DownloadManager.TaskState;
import com.google.android.exoplayer2.offline.DownloadService;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.StreamKey;
......@@ -52,7 +50,6 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
......@@ -135,18 +132,12 @@ public class DownloadServiceDashTest {
dashDownloadManager.startDownloads();
dashDownloadService =
new DownloadService(/*foregroundNotificationId=*/ 1) {
new DownloadService(DownloadService.FOREGROUND_NOTIFICATION_ID_NONE) {
@Override
protected DownloadManager getDownloadManager() {
return dashDownloadManager;
}
@Override
protected Notification getForegroundNotification(TaskState[] taskStates) {
return Mockito.mock(Notification.class);
}
@Nullable
@Override
protected Scheduler getScheduler() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment