Remove DownloadService from nullness blacklist.
PiperOrigin-RevId: 258038961
This commit is contained in:
parent
3fe0b1a6fe
commit
bbcd1126b2
@ -175,7 +175,7 @@ public abstract class DownloadService extends Service {
|
|||||||
@Nullable private final String channelId;
|
@Nullable private final String channelId;
|
||||||
@StringRes private final int channelNameResourceId;
|
@StringRes private final int channelNameResourceId;
|
||||||
|
|
||||||
private DownloadManager downloadManager;
|
@Nullable private DownloadManager downloadManager;
|
||||||
private int lastStartId;
|
private int lastStartId;
|
||||||
private boolean startedInForeground;
|
private boolean startedInForeground;
|
||||||
private boolean taskRemoved;
|
private boolean taskRemoved;
|
||||||
@ -575,6 +575,7 @@ public abstract class DownloadService extends Service {
|
|||||||
if (intentAction == null) {
|
if (intentAction == null) {
|
||||||
intentAction = ACTION_INIT;
|
intentAction = ACTION_INIT;
|
||||||
}
|
}
|
||||||
|
DownloadManager downloadManager = Assertions.checkNotNull(this.downloadManager);
|
||||||
switch (intentAction) {
|
switch (intentAction) {
|
||||||
case ACTION_INIT:
|
case ACTION_INIT:
|
||||||
case ACTION_RESTART:
|
case ACTION_RESTART:
|
||||||
@ -640,8 +641,9 @@ public abstract class DownloadService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
isDestroyed = true;
|
isDestroyed = true;
|
||||||
DownloadManagerHelper downloadManagerHelper = downloadManagerListeners.get(getClass());
|
DownloadManagerHelper downloadManagerHelper =
|
||||||
boolean unschedule = !downloadManager.isWaitingForRequirements();
|
Assertions.checkNotNull(downloadManagerListeners.get(getClass()));
|
||||||
|
boolean unschedule = !downloadManagerHelper.downloadManager.isWaitingForRequirements();
|
||||||
downloadManagerHelper.detachService(this, unschedule);
|
downloadManagerHelper.detachService(this, unschedule);
|
||||||
if (foregroundNotificationUpdater != null) {
|
if (foregroundNotificationUpdater != null) {
|
||||||
foregroundNotificationUpdater.stopPeriodicUpdates();
|
foregroundNotificationUpdater.stopPeriodicUpdates();
|
||||||
@ -775,7 +777,6 @@ public abstract class DownloadService extends Service {
|
|||||||
private final int notificationId;
|
private final int notificationId;
|
||||||
private final long updateInterval;
|
private final long updateInterval;
|
||||||
private final Handler handler;
|
private final Handler handler;
|
||||||
private final Runnable updateRunnable;
|
|
||||||
|
|
||||||
private boolean periodicUpdatesStarted;
|
private boolean periodicUpdatesStarted;
|
||||||
private boolean notificationDisplayed;
|
private boolean notificationDisplayed;
|
||||||
@ -784,7 +785,6 @@ public abstract class DownloadService extends Service {
|
|||||||
this.notificationId = notificationId;
|
this.notificationId = notificationId;
|
||||||
this.updateInterval = updateInterval;
|
this.updateInterval = updateInterval;
|
||||||
this.handler = new Handler(Looper.getMainLooper());
|
this.handler = new Handler(Looper.getMainLooper());
|
||||||
this.updateRunnable = this::update;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startPeriodicUpdates() {
|
public void startPeriodicUpdates() {
|
||||||
@ -794,7 +794,7 @@ public abstract class DownloadService extends Service {
|
|||||||
|
|
||||||
public void stopPeriodicUpdates() {
|
public void stopPeriodicUpdates() {
|
||||||
periodicUpdatesStarted = false;
|
periodicUpdatesStarted = false;
|
||||||
handler.removeCallbacks(updateRunnable);
|
handler.removeCallbacksAndMessages(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showNotificationIfNotAlready() {
|
public void showNotificationIfNotAlready() {
|
||||||
@ -810,12 +810,12 @@ public abstract class DownloadService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void update() {
|
private void update() {
|
||||||
List<Download> downloads = downloadManager.getCurrentDownloads();
|
List<Download> downloads = Assertions.checkNotNull(downloadManager).getCurrentDownloads();
|
||||||
startForeground(notificationId, getForegroundNotification(downloads));
|
startForeground(notificationId, getForegroundNotification(downloads));
|
||||||
notificationDisplayed = true;
|
notificationDisplayed = true;
|
||||||
if (periodicUpdatesStarted) {
|
if (periodicUpdatesStarted) {
|
||||||
handler.removeCallbacks(updateRunnable);
|
handler.removeCallbacksAndMessages(null);
|
||||||
handler.postDelayed(updateRunnable, updateInterval);
|
handler.postDelayed(this::update, updateInterval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -840,7 +840,8 @@ public abstract class DownloadService extends Service {
|
|||||||
downloadManager.addListener(this);
|
downloadManager.addListener(this);
|
||||||
if (scheduler != null) {
|
if (scheduler != null) {
|
||||||
Requirements requirements = downloadManager.getRequirements();
|
Requirements requirements = downloadManager.getRequirements();
|
||||||
setSchedulerEnabled(/* enabled= */ !requirements.checkRequirements(context), requirements);
|
setSchedulerEnabled(
|
||||||
|
scheduler, /* enabled= */ !requirements.checkRequirements(context), requirements);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -894,11 +895,12 @@ public abstract class DownloadService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (scheduler != null) {
|
if (scheduler != null) {
|
||||||
setSchedulerEnabled(/* enabled= */ !requirementsMet, requirements);
|
setSchedulerEnabled(scheduler, /* enabled= */ !requirementsMet, requirements);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSchedulerEnabled(boolean enabled, Requirements requirements) {
|
private void setSchedulerEnabled(
|
||||||
|
Scheduler scheduler, boolean enabled, Requirements requirements) {
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
scheduler.cancel();
|
scheduler.cancel();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user