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

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

Issue 2797573002: Fix startForegroundService API calls. (Closed)
Patch Set: Addressed comments 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 e9abf9eb6ae6dc8f4b84ed8dbe702cd646e0f3d7..71c65beedbc66edddc31bcd78d8bb5140ca98a0d 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
@@ -145,6 +145,12 @@ public class DownloadNotificationService extends Service {
private DownloadSharedPreferenceHelper mDownloadSharedPreferenceHelper;
/**
+ * {@code true} when this service should be put into the foreground before processing an
+ * {@link Intent}.
+ */
+ private boolean mShouldMakeForeground;
+
+ /**
* @return Whether or not this service should be made a foreground service if there are active
* downloads.
*/
@@ -207,9 +213,7 @@ public class DownloadNotificationService extends Service {
return;
}
- AppHooks.get().startServiceWithNotification(intent,
- NotificationConstants.NOTIFICATION_ID_DOWNLOAD_SUMMARY,
- buildSummaryNotification(context, manager));
+ AppHooks.get().startForegroundService(intent);
} else {
context.startService(intent);
}
@@ -440,6 +444,7 @@ public class DownloadNotificationService extends Service {
mDownloadSharedPreferenceHelper = DownloadSharedPreferenceHelper.getInstance();
mNextNotificationId = mSharedPrefs.getInt(
KEY_NEXT_DOWNLOAD_NOTIFICATION_ID, STARTING_NOTIFICATION_ID);
+ mShouldMakeForeground = true;
}
@Override
@@ -451,6 +456,10 @@ public class DownloadNotificationService extends Service {
@Override
public int onStartCommand(final Intent intent, int flags, int startId) {
+ if (mShouldMakeForeground) {
+ mShouldMakeForeground = false;
+ startForegroundInternal();
+ }
if (intent == null) {
// Intent is only null during a process restart because of returning START_STICKY. In
// this case cancel the off the record notifications and put the normal notifications

Powered by Google App Engine
This is Rietveld 408576698