diff --git a/demos/ima/build.gradle b/demos/ima/build.gradle index 1d2068e5f7..33161b4121 100644 --- a/demos/ima/build.gradle +++ b/demos/ima/build.gradle @@ -53,7 +53,7 @@ dependencies { implementation project(modulePrefix + 'library-hls') implementation project(modulePrefix + 'library-smoothstreaming') implementation project(modulePrefix + 'extension-ima') - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' } apply plugin: 'com.google.android.gms.strict-version-matcher-plugin' diff --git a/demos/main/build.gradle b/demos/main/build.gradle index 84a8a4087c..7089d4d731 100644 --- a/demos/main/build.gradle +++ b/demos/main/build.gradle @@ -62,7 +62,7 @@ android { } dependencies { - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' implementation 'androidx.legacy:legacy-support-core-ui:1.0.0' implementation 'androidx.fragment:fragment:1.0.0' implementation 'com.google.android.material:material:1.0.0' diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java index 4a7a810314..a860d96e43 100644 --- a/demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java @@ -101,7 +101,7 @@ public class DownloadTracker { RenderersFactory renderersFactory) { Download download = downloads.get(uri); if (download != null) { - DownloadService.startWithRemoveDownload( + DownloadService.sendRemoveDownload( context, DemoDownloadService.class, download.request.id, /* foreground= */ false); } else { if (startDownloadDialogHelper != null) { @@ -263,7 +263,7 @@ public class DownloadTracker { } private void startDownload(DownloadRequest downloadRequest) { - DownloadService.startWithNewDownload( + DownloadService.sendNewDownload( context, DemoDownloadService.class, downloadRequest, /* foreground= */ false); } diff --git a/extensions/cast/build.gradle b/extensions/cast/build.gradle index 573426df2e..4dc463ff81 100644 --- a/extensions/cast/build.gradle +++ b/extensions/cast/build.gradle @@ -32,7 +32,7 @@ android { dependencies { api 'com.google.android.gms:play-services-cast-framework:16.1.2' - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' implementation project(modulePrefix + 'library-core') implementation project(modulePrefix + 'library-ui') compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion diff --git a/extensions/cronet/build.gradle b/extensions/cronet/build.gradle index baf925acbd..ad45f61d98 100644 --- a/extensions/cronet/build.gradle +++ b/extensions/cronet/build.gradle @@ -33,7 +33,7 @@ android { dependencies { api 'org.chromium.net:cronet-embedded:72.3626.96' implementation project(modulePrefix + 'library-core') - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' testImplementation project(modulePrefix + 'library') testImplementation project(modulePrefix + 'testutils-robolectric') } diff --git a/extensions/ffmpeg/build.gradle b/extensions/ffmpeg/build.gradle index ee3358d21a..ffecdcd16f 100644 --- a/extensions/ffmpeg/build.gradle +++ b/extensions/ffmpeg/build.gradle @@ -38,7 +38,7 @@ android { dependencies { implementation project(modulePrefix + 'library-core') - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion testImplementation project(modulePrefix + 'testutils-robolectric') } diff --git a/extensions/flac/build.gradle b/extensions/flac/build.gradle index 9a247c3f8f..06a5888404 100644 --- a/extensions/flac/build.gradle +++ b/extensions/flac/build.gradle @@ -39,7 +39,7 @@ android { dependencies { implementation project(modulePrefix + 'library-core') - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' androidTestImplementation project(modulePrefix + 'testutils') androidTestImplementation 'androidx.test:runner:' + androidXTestVersion testImplementation project(modulePrefix + 'testutils-robolectric') diff --git a/extensions/gvr/build.gradle b/extensions/gvr/build.gradle index 6c4bfa469a..50acd6c040 100644 --- a/extensions/gvr/build.gradle +++ b/extensions/gvr/build.gradle @@ -33,7 +33,7 @@ android { dependencies { implementation project(modulePrefix + 'library-core') implementation project(modulePrefix + 'library-ui') - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' api 'com.google.vr:sdk-base:1.190.0' compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion } diff --git a/extensions/leanback/build.gradle b/extensions/leanback/build.gradle index a86eedc2d4..c6f5a216ce 100644 --- a/extensions/leanback/build.gradle +++ b/extensions/leanback/build.gradle @@ -32,7 +32,7 @@ android { dependencies { implementation project(modulePrefix + 'library-core') - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' implementation 'androidx.leanback:leanback:1.0.0' } diff --git a/extensions/okhttp/build.gradle b/extensions/okhttp/build.gradle index eddd364370..db2e073c8a 100644 --- a/extensions/okhttp/build.gradle +++ b/extensions/okhttp/build.gradle @@ -33,7 +33,7 @@ android { dependencies { implementation project(modulePrefix + 'library-core') - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion api 'com.squareup.okhttp3:okhttp:3.12.1' } diff --git a/extensions/rtmp/build.gradle b/extensions/rtmp/build.gradle index e7c7fce164..ca734c3657 100644 --- a/extensions/rtmp/build.gradle +++ b/extensions/rtmp/build.gradle @@ -33,7 +33,7 @@ android { dependencies { implementation project(modulePrefix + 'library-core') implementation 'net.butterflytv.utils:rtmp-client:3.0.1' - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' testImplementation project(modulePrefix + 'testutils-robolectric') } diff --git a/extensions/vp9/build.gradle b/extensions/vp9/build.gradle index 4b2ba26ca2..02b68b831d 100644 --- a/extensions/vp9/build.gradle +++ b/extensions/vp9/build.gradle @@ -39,7 +39,7 @@ android { dependencies { implementation project(modulePrefix + 'library-core') - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' testImplementation project(modulePrefix + 'testutils-robolectric') androidTestImplementation 'androidx.test:runner:' + androidXTestVersion androidTestImplementation 'androidx.test.ext:junit:' + androidXTestVersion diff --git a/library/core/build.gradle b/library/core/build.gradle index deb9f24dce..68ff8cc977 100644 --- a/library/core/build.gradle +++ b/library/core/build.gradle @@ -58,7 +58,7 @@ android { } dependencies { - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion compileOnly 'org.checkerframework:checker-compat-qual:' + checkerframeworkVersion androidTestImplementation 'androidx.test:runner:' + androidXTestVersion diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadService.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadService.java index c206a94d6d..6922d6a787 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadService.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadService.java @@ -117,8 +117,8 @@ public abstract class DownloadService extends Service { public static final String KEY_DOWNLOAD_REQUEST = "download_request"; /** - * Key for the content id in {@link #ACTION_START}, {@link #ACTION_STOP} and {@link - * #ACTION_REMOVE} intents. + * Key for the content id in {@link #ACTION_SET_MANUAL_STOP_REASON} and {@link #ACTION_REMOVE} + * intents. */ public static final String KEY_CONTENT_ID = "content_id"; @@ -265,10 +265,9 @@ public abstract class DownloadService extends Service { DownloadRequest downloadRequest, int manualStopReason, boolean foreground) { - return getIntent(context, clazz, ACTION_ADD) + return getIntent(context, clazz, ACTION_ADD, foreground) .putExtra(KEY_DOWNLOAD_REQUEST, downloadRequest) - .putExtra(KEY_MANUAL_STOP_REASON, manualStopReason) - .putExtra(KEY_FOREGROUND, foreground); + .putExtra(KEY_MANUAL_STOP_REASON, manualStopReason); } /** @@ -282,9 +281,7 @@ public abstract class DownloadService extends Service { */ public static Intent buildRemoveDownloadIntent( Context context, Class clazz, String id, boolean foreground) { - return getIntent(context, clazz, ACTION_REMOVE) - .putExtra(KEY_CONTENT_ID, id) - .putExtra(KEY_FOREGROUND, foreground); + return getIntent(context, clazz, ACTION_REMOVE, foreground).putExtra(KEY_CONTENT_ID, id); } /** @@ -295,55 +292,122 @@ public abstract class DownloadService extends Service { * @param clazz The concrete download service being targeted by the intent. * @param id The content id, or {@code null} to set the manual stop reason for all downloads. * @param manualStopReason An application defined stop reason. + * @param foreground Whether this intent will be used to start the service in the foreground. * @return Created Intent. */ public static Intent buildSetManualStopReasonIntent( Context context, Class clazz, @Nullable String id, - int manualStopReason) { - return getIntent(context, clazz, ACTION_STOP) + int manualStopReason, + boolean foreground) { + return getIntent(context, clazz, ACTION_SET_MANUAL_STOP_REASON, foreground) .putExtra(KEY_CONTENT_ID, id) .putExtra(KEY_MANUAL_STOP_REASON, manualStopReason); } /** - * Starts the service, adding a new download. + * Builds an {@link Intent} for starting all downloads. + * + * @param context A {@link Context}. + * @param clazz The concrete download service being targeted by the intent. + * @param foreground Whether this intent will be used to start the service in the foreground. + * @return Created Intent. + */ + public static Intent buildStartDownloadsIntent( + Context context, Class clazz, boolean foreground) { + return getIntent(context, clazz, ACTION_START, foreground); + } + + /** + * Builds an {@link Intent} for stopping all downloads. + * + * @param context A {@link Context}. + * @param clazz The concrete download service being targeted by the intent. + * @param foreground Whether this intent will be used to start the service in the foreground. + * @return Created Intent. + */ + public static Intent buildStopDownloadsIntent( + Context context, Class clazz, boolean foreground) { + return getIntent(context, clazz, ACTION_STOP, foreground); + } + + /** + * Starts the service if not started already and adds a new download. * * @param context A {@link Context}. * @param clazz The concrete download service to be started. * @param downloadRequest The request to be executed. * @param foreground Whether the service is started in the foreground. */ - public static void startWithNewDownload( + public static void sendNewDownload( Context context, Class clazz, DownloadRequest downloadRequest, boolean foreground) { Intent intent = buildAddRequestIntent(context, clazz, downloadRequest, foreground); - if (foreground) { - Util.startForegroundService(context, intent); - } else { - context.startService(intent); - } + startService(context, intent, foreground); } /** - * Starts the service to remove a download. + * Starts the service if not started already and removes a download. * * @param context A {@link Context}. * @param clazz The concrete download service to be started. * @param id The content id. * @param foreground Whether the service is started in the foreground. */ - public static void startWithRemoveDownload( + public static void sendRemoveDownload( Context context, Class clazz, String id, boolean foreground) { Intent intent = buildRemoveDownloadIntent(context, clazz, id, foreground); - if (foreground) { - Util.startForegroundService(context, intent); - } else { - context.startService(intent); - } + startService(context, intent, foreground); + } + + /** + * Starts the service if not started already and sets the manual stop reason for one or all + * downloads. To clear manual stop reason, pass {@link Download#MANUAL_STOP_REASON_NONE}. + * + * @param context A {@link Context}. + * @param clazz The concrete download service to be started. + * @param id The content id, or {@code null} to set the manual stop reason for all downloads. + * @param manualStopReason An application defined stop reason. + * @param foreground Whether the service is started in the foreground. + */ + public static void sendManualStopReason( + Context context, + Class clazz, + @Nullable String id, + int manualStopReason, + boolean foreground) { + Intent intent = + buildSetManualStopReasonIntent(context, clazz, id, manualStopReason, foreground); + startService(context, intent, foreground); + } + + /** + * Starts the service if not started already and starts all downloads. + * + * @param context A {@link Context}. + * @param clazz The concrete download service to be started. + * @param foreground Whether the service is started in the foreground. + */ + public static void sendStartDownloads( + Context context, Class clazz, boolean foreground) { + Intent intent = buildStartDownloadsIntent(context, clazz, foreground); + startService(context, intent, foreground); + } + + /** + * Starts the service if not started already and stops all downloads. + * + * @param context A {@link Context}. + * @param clazz The concrete download service to be started. + * @param foreground Whether the service is started in the foreground. + */ + public static void sendStopDownloads( + Context context, Class clazz, boolean foreground) { + Intent intent = buildStopDownloadsIntent(context, clazz, foreground); + startService(context, intent, foreground); } /** @@ -367,7 +431,7 @@ public abstract class DownloadService extends Service { * @see #start(Context, Class) */ public static void startForeground(Context context, Class clazz) { - Intent intent = getIntent(context, clazz, ACTION_INIT).putExtra(KEY_FOREGROUND, true); + Intent intent = getIntent(context, clazz, ACTION_INIT, true); Util.startForegroundService(context, intent); } @@ -588,11 +652,24 @@ public abstract class DownloadService extends Service { } } + private static Intent getIntent( + Context context, Class clazz, String action, boolean foreground) { + return getIntent(context, clazz, action).putExtra(KEY_FOREGROUND, foreground); + } + private static Intent getIntent( Context context, Class clazz, String action) { return new Intent(context, clazz).setAction(action); } + private static void startService(Context context, Intent intent, boolean foreground) { + if (foreground) { + Util.startForegroundService(context, intent); + } else { + context.startService(intent); + } + } + private final class ForegroundNotificationUpdater { private final int notificationId; diff --git a/library/dash/build.gradle b/library/dash/build.gradle index c7e68f548a..f6981a2220 100644 --- a/library/dash/build.gradle +++ b/library/dash/build.gradle @@ -41,7 +41,7 @@ android { dependencies { implementation project(modulePrefix + 'library-core') compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' testImplementation project(modulePrefix + 'testutils-robolectric') } diff --git a/library/hls/build.gradle b/library/hls/build.gradle index 99619bf750..8e9696af70 100644 --- a/library/hls/build.gradle +++ b/library/hls/build.gradle @@ -39,7 +39,7 @@ android { } dependencies { - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion implementation project(modulePrefix + 'library-core') testImplementation project(modulePrefix + 'testutils-robolectric') diff --git a/library/smoothstreaming/build.gradle b/library/smoothstreaming/build.gradle index ba3b4ab65d..a2e81fb304 100644 --- a/library/smoothstreaming/build.gradle +++ b/library/smoothstreaming/build.gradle @@ -41,7 +41,7 @@ android { dependencies { implementation project(modulePrefix + 'library-core') compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' testImplementation project(modulePrefix + 'testutils-robolectric') } diff --git a/library/ui/build.gradle b/library/ui/build.gradle index 9c47f3684d..49446b25de 100644 --- a/library/ui/build.gradle +++ b/library/ui/build.gradle @@ -41,7 +41,7 @@ android { dependencies { implementation project(modulePrefix + 'library-core') implementation 'androidx.media:media:1.0.0' - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion testImplementation project(modulePrefix + 'testutils-robolectric') } diff --git a/playbacktests/build.gradle b/playbacktests/build.gradle index 0e1c8a1268..dd5cfa64a7 100644 --- a/playbacktests/build.gradle +++ b/playbacktests/build.gradle @@ -34,7 +34,7 @@ android { dependencies { androidTestImplementation 'androidx.test:rules:' + androidXTestVersion androidTestImplementation 'androidx.test:runner:' + androidXTestVersion - androidTestImplementation 'androidx.annotation:annotation:1.0.1' + androidTestImplementation 'androidx.annotation:annotation:1.0.2' androidTestImplementation project(modulePrefix + 'library-core') androidTestImplementation project(modulePrefix + 'library-dash') androidTestImplementation project(modulePrefix + 'library-hls') diff --git a/testutils/build.gradle b/testutils/build.gradle index ab78e6673f..bdc26d5c19 100644 --- a/testutils/build.gradle +++ b/testutils/build.gradle @@ -41,7 +41,7 @@ dependencies { api 'org.mockito:mockito-core:' + mockitoVersion api 'androidx.test.ext:junit:' + androidXTestVersion api 'androidx.test.ext:truth:' + androidXTestVersion - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' implementation project(modulePrefix + 'library-core') implementation 'com.google.auto.value:auto-value-annotations:' + autoValueVersion annotationProcessor 'com.google.auto.value:auto-value:' + autoValueVersion diff --git a/testutils_robolectric/build.gradle b/testutils_robolectric/build.gradle index feee9536bb..78fa5dbd87 100644 --- a/testutils_robolectric/build.gradle +++ b/testutils_robolectric/build.gradle @@ -41,6 +41,6 @@ dependencies { api 'org.robolectric:robolectric:' + robolectricVersion api project(modulePrefix + 'testutils') implementation project(modulePrefix + 'library-core') - implementation 'androidx.annotation:annotation:1.0.1' + implementation 'androidx.annotation:annotation:1.0.2' annotationProcessor 'com.google.auto.service:auto-service:' + autoServiceVersion }