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 @@ ...@@ -79,7 +79,7 @@
<service android:name="com.google.android.exoplayer2.demo.DemoDownloadService" <service android:name="com.google.android.exoplayer2.demo.DemoDownloadService"
android:exported="false"> android:exported="false">
<intent-filter> <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"/> <category android:name="android.intent.category.DEFAULT"/>
</intent-filter> </intent-filter>
</service> </service>
......
...@@ -87,7 +87,7 @@ public final class RequirementsWatcher { ...@@ -87,7 +87,7 @@ public final class RequirementsWatcher {
public void start() { public void start() {
Assertions.checkNotNull(Looper.myLooper()); Assertions.checkNotNull(Looper.myLooper());
checkRequirements(true); requirementsWereMet = requirements.checkRequirements(context);
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
if (requirements.getRequiredNetworkType() != Requirements.NETWORK_TYPE_NONE) { if (requirements.getRequiredNetworkType() != Requirements.NETWORK_TYPE_NONE) {
...@@ -158,13 +158,11 @@ public final class RequirementsWatcher { ...@@ -158,13 +158,11 @@ public final class RequirementsWatcher {
} }
} }
private void checkRequirements(boolean force) { private void checkRequirements() {
boolean requirementsAreMet = requirements.checkRequirements(context); boolean requirementsAreMet = requirements.checkRequirements(context);
if (!force) { if (requirementsAreMet == requirementsWereMet) {
if (requirementsAreMet == requirementsWereMet) { logd("requirementsAreMet is still " + requirementsAreMet);
logd("requirementsAreMet is still " + requirementsAreMet); return;
return;
}
} }
requirementsWereMet = requirementsAreMet; requirementsWereMet = requirementsAreMet;
if (requirementsAreMet) { if (requirementsAreMet) {
...@@ -187,7 +185,7 @@ public final class RequirementsWatcher { ...@@ -187,7 +185,7 @@ public final class RequirementsWatcher {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (!isInitialStickyBroadcast()) { if (!isInitialStickyBroadcast()) {
logd(RequirementsWatcher.this + " received " + intent.getAction()); logd(RequirementsWatcher.this + " received " + intent.getAction());
checkRequirements(false); checkRequirements();
} }
} }
} }
...@@ -198,14 +196,14 @@ public final class RequirementsWatcher { ...@@ -198,14 +196,14 @@ public final class RequirementsWatcher {
public void onAvailable(Network network) { public void onAvailable(Network network) {
super.onAvailable(network); super.onAvailable(network);
logd(RequirementsWatcher.this + " NetworkCallback.onAvailable"); logd(RequirementsWatcher.this + " NetworkCallback.onAvailable");
checkRequirements(false); checkRequirements();
} }
@Override @Override
public void onLost(Network network) { public void onLost(Network network) {
super.onLost(network); super.onLost(network);
logd(RequirementsWatcher.this + " NetworkCallback.onLost"); logd(RequirementsWatcher.this + " NetworkCallback.onLost");
checkRequirements(false); checkRequirements();
} }
} }
} }
...@@ -20,14 +20,12 @@ import static com.google.android.exoplayer2.source.dash.offline.DashDownloadTest ...@@ -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.assertCacheEmpty;
import static com.google.android.exoplayer2.testutil.CacheAsserts.assertCachedData; import static com.google.android.exoplayer2.testutil.CacheAsserts.assertCachedData;
import android.app.Notification;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import com.google.android.exoplayer2.offline.DownloadAction; import com.google.android.exoplayer2.offline.DownloadAction;
import com.google.android.exoplayer2.offline.DownloadManager; 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.DownloadService;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper; import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.StreamKey; import com.google.android.exoplayer2.offline.StreamKey;
...@@ -52,7 +50,6 @@ import org.junit.Before; ...@@ -52,7 +50,6 @@ import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
...@@ -135,18 +132,12 @@ public class DownloadServiceDashTest { ...@@ -135,18 +132,12 @@ public class DownloadServiceDashTest {
dashDownloadManager.startDownloads(); dashDownloadManager.startDownloads();
dashDownloadService = dashDownloadService =
new DownloadService(/*foregroundNotificationId=*/ 1) { new DownloadService(DownloadService.FOREGROUND_NOTIFICATION_ID_NONE) {
@Override @Override
protected DownloadManager getDownloadManager() { protected DownloadManager getDownloadManager() {
return dashDownloadManager; return dashDownloadManager;
} }
@Override
protected Notification getForegroundNotification(TaskState[] taskStates) {
return Mockito.mock(Notification.class);
}
@Nullable @Nullable
@Override @Override
protected Scheduler getScheduler() { 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