Add missing DownloadService build*Intent and startWith* methods
PiperOrigin-RevId: 244196081
This commit is contained in:
parent
4ea2463856
commit
f9f009645d
@ -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'
|
||||
|
@ -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'
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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')
|
||||
}
|
||||
|
@ -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')
|
||||
}
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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'
|
||||
}
|
||||
|
||||
|
@ -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'
|
||||
}
|
||||
|
@ -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')
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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<? extends DownloadService> 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<? extends DownloadService> 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<? extends DownloadService> 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<? extends DownloadService> 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<? extends DownloadService> 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<? extends DownloadService> 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<? extends DownloadService> 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<? extends DownloadService> 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<? extends DownloadService> 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<? extends DownloadService> 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<? extends DownloadService> clazz, String action, boolean foreground) {
|
||||
return getIntent(context, clazz, action).putExtra(KEY_FOREGROUND, foreground);
|
||||
}
|
||||
|
||||
private static Intent getIntent(
|
||||
Context context, Class<? extends DownloadService> 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;
|
||||
|
@ -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')
|
||||
}
|
||||
|
||||
|
@ -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')
|
||||
|
@ -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')
|
||||
}
|
||||
|
||||
|
@ -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')
|
||||
}
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user