Commit e62c8302 authored by David Trainor's avatar David Trainor Committed by Commit Bot

Address more download stuck notification states

Increase the wait delay before trying to dismiss a notification.  This
is a workaround due to an Android OS bug with Service lifecycles and
notification states.  A quick startForeground/stopForeground can cause a
notification to end up being stuck showing forever.  This CL doubles the
delay from 100ms to 200ms and adds more logs to help track what is
happening w.r.t. this delay (when it is in effect, etc.) to help with
future tracking.

BUG=852188,b/79337416

Change-Id: I2eaa21277c6fb60bc40232584ea50f1de1d06c34
Reviewed-on: https://chromium-review.googlesource.com/1097738
Commit-Queue: David Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#566901}
parent be6dfe64
...@@ -80,7 +80,7 @@ public class DownloadForegroundService extends Service { ...@@ -80,7 +80,7 @@ public class DownloadForegroundService extends Service {
int oldNotificationId, Notification oldNotification, boolean killOldNotification) { int oldNotificationId, Notification oldNotification, boolean killOldNotification) {
Log.w(TAG, Log.w(TAG,
"startOrUpdateForegroundService new: " + newNotificationId "startOrUpdateForegroundService new: " + newNotificationId
+ ", old: " + oldNotificationId); + ", old: " + oldNotificationId + ", kill old: " + killOldNotification);
// Handle notifications and start foreground. // Handle notifications and start foreground.
if (oldNotificationId == INVALID_NOTIFICATION_ID && oldNotification == null) { if (oldNotificationId == INVALID_NOTIFICATION_ID && oldNotification == null) {
// If there is no old notification or old notification id, just start foreground. // If there is no old notification or old notification id, just start foreground.
......
...@@ -51,7 +51,7 @@ public class DownloadForegroundServiceManager { ...@@ -51,7 +51,7 @@ public class DownloadForegroundServiceManager {
private static final String TAG = "DownloadFg"; private static final String TAG = "DownloadFg";
// Delay to ensure start/stop foreground doesn't happen too quickly (b/74236718). // Delay to ensure start/stop foreground doesn't happen too quickly (b/74236718).
private static final int WAIT_TIME_MS = 100; private static final int WAIT_TIME_MS = 200;
// Used to track existing notifications for UMA stats. // Used to track existing notifications for UMA stats.
private final List<Integer> mExistingNotifications = new ArrayList<>(); private final List<Integer> mExistingNotifications = new ArrayList<>();
...@@ -61,9 +61,11 @@ public class DownloadForegroundServiceManager { ...@@ -61,9 +61,11 @@ public class DownloadForegroundServiceManager {
private final Runnable mMaybeStopServiceRunnable = new Runnable() { private final Runnable mMaybeStopServiceRunnable = new Runnable() {
@Override @Override
public void run() { public void run() {
Log.w(TAG, "Checking if delayed stopAndUnbindService needs to be resolved.");
mStopServiceDelayed = false; mStopServiceDelayed = false;
processDownloadUpdateQueue(false /* not isProcessingPending */); processDownloadUpdateQueue(false /* not isProcessingPending */);
mHandler.removeCallbacks(mMaybeStopServiceRunnable); mHandler.removeCallbacks(mMaybeStopServiceRunnable);
Log.w(TAG, "Done checking if delayed stopAndUnbindService needs to be resolved.");
} }
}; };
private boolean mStopServiceDelayed = false; private boolean mStopServiceDelayed = false;
...@@ -130,6 +132,7 @@ public class DownloadForegroundServiceManager { ...@@ -130,6 +132,7 @@ public class DownloadForegroundServiceManager {
// In the pending case, start foreground with specific notificationId and notification. // In the pending case, start foreground with specific notificationId and notification.
if (isProcessingPending) { if (isProcessingPending) {
Log.w(TAG, "Starting service with type " + downloadUpdate.mDownloadStatus);
startOrUpdateForegroundService( startOrUpdateForegroundService(
downloadUpdate.mNotificationId, downloadUpdate.mNotification); downloadUpdate.mNotificationId, downloadUpdate.mNotification);
...@@ -145,6 +148,8 @@ public class DownloadForegroundServiceManager { ...@@ -145,6 +148,8 @@ public class DownloadForegroundServiceManager {
if (!mStopServiceDelayed) { if (!mStopServiceDelayed) {
stopAndUnbindService(downloadUpdate.mDownloadStatus); stopAndUnbindService(downloadUpdate.mDownloadStatus);
cleanDownloadUpdateQueue(); cleanDownloadUpdateQueue();
} else {
Log.w(TAG, "Delaying call to stopAndUnbindService.");
} }
return; return;
} }
......
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 to comment