Commit 540399d5 authored by qinmin's avatar qinmin Committed by Commit bot

Fix an issue that download progress notification is shown when killing browser

When browser gets killed, we should show a paused notification.
However, onTaskRemoved() is often called too early before process fully
stops.
As a result, a progress notification can arrive after Chrome changes all the
notification to paused.
This may cause chrome to show a paused notification and then immediately
change it to progress while killing the browser.
Only progress notification matters, cancel/pause doesn't really matter.

BUG=642191

Review-Url: https://codereview.chromium.org/2296913002
Cr-Commit-Position: refs/heads/master@{#415439}
parent 51a16bde
...@@ -82,6 +82,7 @@ public class DownloadNotificationService extends Service { ...@@ -82,6 +82,7 @@ public class DownloadNotificationService extends Service {
private Context mContext; private Context mContext;
private int mNextNotificationId; private int mNextNotificationId;
private int mNumAutoResumptionAttemptLeft; private int mNumAutoResumptionAttemptLeft;
private boolean mStopPostingProgressNotifications;
/** /**
* Class for clients to access. * Class for clients to access.
...@@ -94,6 +95,7 @@ public class DownloadNotificationService extends Service { ...@@ -94,6 +95,7 @@ public class DownloadNotificationService extends Service {
@Override @Override
public void onTaskRemoved(Intent rootIntent) { public void onTaskRemoved(Intent rootIntent) {
mStopPostingProgressNotifications = true;
// This funcion is called when Chrome is swiped away from the recent apps // This funcion is called when Chrome is swiped away from the recent apps
// drawer. So it doesn't catch all scenarios that chrome can get killed. // drawer. So it doesn't catch all scenarios that chrome can get killed.
// This will only help Android 4.4.2. // This will only help Android 4.4.2.
...@@ -102,6 +104,7 @@ public class DownloadNotificationService extends Service { ...@@ -102,6 +104,7 @@ public class DownloadNotificationService extends Service {
@Override @Override
public void onCreate() { public void onCreate() {
mStopPostingProgressNotifications = false;
mContext = getApplicationContext(); mContext = getApplicationContext();
mNotificationManager = (NotificationManager) mContext.getSystemService( mNotificationManager = (NotificationManager) mContext.getSystemService(
Context.NOTIFICATION_SERVICE); Context.NOTIFICATION_SERVICE);
...@@ -206,6 +209,7 @@ public class DownloadNotificationService extends Service { ...@@ -206,6 +209,7 @@ public class DownloadNotificationService extends Service {
public void notifyDownloadProgress(String downloadGuid, String fileName, int percentage, public void notifyDownloadProgress(String downloadGuid, String fileName, int percentage,
long timeRemainingInMillis, long startTime, boolean isOffTheRecord, long timeRemainingInMillis, long startTime, boolean isOffTheRecord,
boolean canDownloadWhileMetered, boolean isOfflinePage) { boolean canDownloadWhileMetered, boolean isOfflinePage) {
if (mStopPostingProgressNotifications) return;
boolean indeterminate = percentage == INVALID_DOWNLOAD_PERCENTAGE; boolean indeterminate = percentage == INVALID_DOWNLOAD_PERCENTAGE;
NotificationCompat.Builder builder = buildNotification( NotificationCompat.Builder builder = buildNotification(
android.R.drawable.stat_sys_download, fileName, null); android.R.drawable.stat_sys_download, fileName, null);
......
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