DownloadService: Only call getScheduler once
The second getScheduler() call violates the documentation of the class, which states that getScheduler() is not called if foregroundNotificationId if FOREGROUND_NOTIFICATION_ID_NONE. Presumably implementing subclasses would return null, in which case this didn't do any harm, but we should make sure the implementation behaves as documented regardless. PiperOrigin-RevId: 397167603
This commit is contained in:
parent
a95ee0aeba
commit
6edf9c31bf
@ -178,6 +178,7 @@ public abstract class DownloadService extends Service {
|
|||||||
@StringRes private final int channelNameResourceId;
|
@StringRes private final int channelNameResourceId;
|
||||||
@StringRes private final int channelDescriptionResourceId;
|
@StringRes private final int channelDescriptionResourceId;
|
||||||
|
|
||||||
|
private @MonotonicNonNull Scheduler scheduler;
|
||||||
private @MonotonicNonNull DownloadManager downloadManager;
|
private @MonotonicNonNull DownloadManager downloadManager;
|
||||||
private int lastStartId;
|
private int lastStartId;
|
||||||
private boolean startedInForeground;
|
private boolean startedInForeground;
|
||||||
@ -582,6 +583,9 @@ public abstract class DownloadService extends Service {
|
|||||||
if (downloadManagerHelper == null) {
|
if (downloadManagerHelper == null) {
|
||||||
boolean foregroundAllowed = foregroundNotificationUpdater != null;
|
boolean foregroundAllowed = foregroundNotificationUpdater != null;
|
||||||
@Nullable Scheduler scheduler = foregroundAllowed ? getScheduler() : null;
|
@Nullable Scheduler scheduler = foregroundAllowed ? getScheduler() : null;
|
||||||
|
if (scheduler != null) {
|
||||||
|
this.scheduler = scheduler;
|
||||||
|
}
|
||||||
downloadManager = getDownloadManager();
|
downloadManager = getDownloadManager();
|
||||||
downloadManager.resumeDownloads();
|
downloadManager.resumeDownloads();
|
||||||
downloadManagerHelper =
|
downloadManagerHelper =
|
||||||
@ -589,6 +593,9 @@ public abstract class DownloadService extends Service {
|
|||||||
getApplicationContext(), downloadManager, foregroundAllowed, scheduler, clazz);
|
getApplicationContext(), downloadManager, foregroundAllowed, scheduler, clazz);
|
||||||
downloadManagerHelpers.put(clazz, downloadManagerHelper);
|
downloadManagerHelpers.put(clazz, downloadManagerHelper);
|
||||||
} else {
|
} else {
|
||||||
|
if (downloadManagerHelper.scheduler != null) {
|
||||||
|
scheduler = downloadManagerHelper.scheduler;
|
||||||
|
}
|
||||||
downloadManager = downloadManagerHelper.downloadManager;
|
downloadManager = downloadManagerHelper.downloadManager;
|
||||||
}
|
}
|
||||||
downloadManagerHelper.attachService(this);
|
downloadManagerHelper.attachService(this);
|
||||||
@ -658,7 +665,6 @@ public abstract class DownloadService extends Service {
|
|||||||
if (requirements == null) {
|
if (requirements == null) {
|
||||||
Log.e(TAG, "Ignored SET_REQUIREMENTS: Missing " + KEY_REQUIREMENTS + " extra");
|
Log.e(TAG, "Ignored SET_REQUIREMENTS: Missing " + KEY_REQUIREMENTS + " extra");
|
||||||
} else {
|
} else {
|
||||||
@Nullable Scheduler scheduler = getScheduler();
|
|
||||||
if (scheduler != null) {
|
if (scheduler != null) {
|
||||||
Requirements supportedRequirements = scheduler.getSupportedRequirements(requirements);
|
Requirements supportedRequirements = scheduler.getSupportedRequirements(requirements);
|
||||||
if (!supportedRequirements.equals(requirements)) {
|
if (!supportedRequirements.equals(requirements)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user