Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadNotificationService.java

Issue 2813723002: Workaround for NotificationManager race condition (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadNotificationService.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadNotificationService.java b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadNotificationService.java
index 69f7c14d071f42bacdfc05bdb9aa3607e674a005..00f47ec50efe440f171986cea7d4b0f1bb799225 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadNotificationService.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadNotificationService.java
@@ -161,14 +161,16 @@ public class DownloadNotificationService extends Service {
* notification thinks it's in the foreground, this will start the service with the goal of
* shutting it down. That is because if the service is in the foreground it's not possible to
* stop it through the notification manager.
+ * @param removedNotificationId The id of the notification that was just removed or {@code -1}
+ * if this does not apply.
*/
@TargetApi(Build.VERSION_CODES.M)
- public static void hideDanglingSummaryNotification(Context context) {
+ public static void hideDanglingSummaryNotification(Context context, int removedNotificationId) {
if (!useForegroundService()) return;
NotificationManager manager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- if (hasDownloadNotifications(manager, -1)) return;
+ if (hasDownloadNotifications(manager, removedNotificationId)) return;
StatusBarNotification summary = getSummaryNotification(manager);
if (summary == null) return;
@@ -688,8 +690,13 @@ public class DownloadNotificationService extends Service {
}
} else {
// If we don't have a valid summary, just guarantee that we aren't in the foreground for
- // safety.
- stopForegroundInternal(false);
+ // safety. Still try to remove the summary notification to make sure it's gone. This
+ // is because querying for it might fail if we have just recently started up and began
+ // showing it. This might leave us in a bad state if the cancel request fails inside
+ // the framework.
+ // TODO(dtrainor): Add a way to attempt to automatically clean up the notification
+ // shortly after this.
+ stopForegroundInternal(true);
}
// Stop the service which should start the destruction process. At this point we should be
@@ -965,6 +972,7 @@ public class DownloadNotificationService extends Service {
intent.putExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS, idArray);
intent.putExtra(EXTRA_DOWNLOAD_FILE_PATH, filePath);
intent.putExtra(EXTRA_IS_SUPPORTED_MIME_TYPE, isSupportedMimeType);
+ intent.putExtra(NotificationConstants.EXTRA_NOTIFICATION_ID, notificationId);
}
intent.setComponent(component);
builder.setContentIntent(PendingIntent.getBroadcast(

Powered by Google App Engine
This is Rietveld 408576698