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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationBuilderFactory.java

Issue 2808163002: [Android O] Refactor channel initialization (Closed)
Patch Set: fix 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/notifications/NotificationBuilderFactory.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationBuilderFactory.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationBuilderFactory.java
index 609be47354a260390696b7334e5fbc25332087ce..5b00acf333bd0512475f8064250d355ef00507b8 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationBuilderFactory.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationBuilderFactory.java
@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.notifications;
+import android.annotation.SuppressLint;
+import android.app.NotificationManager;
import android.content.Context;
import org.chromium.base.BuildInfo;
@@ -20,26 +22,29 @@ public class NotificationBuilderFactory {
*
* TODO(crbug.com/704152) Remove this once we've updated to revision 26 of the support library.
* Then we can use NotificationCompat.Builder and set the channel directly everywhere.
+ * Although we will still need to ensure the channel is always initialized first.
*
* @param preferCompat true if a NotificationCompat.Builder is preferred.
* A Notification.Builder will be used regardless on Android O.
- * @param channelId The ID of the channel the notification should be posted to.
- * @param channelName The name of the channel the notification should be posted to.
- * Used to create the channel if a channel with channelId does not exist.
- * @param channelGroupId The ID of the channel group the channel belongs to. Used when creating
- * the channel if a channel with channelId does not exist.
- * @param channelGroupName The name of the channel group the channel belongs to.
- * Used to create the channel group if a channel group with
- * channelGroupId does not already exist.
+ * @param channelId The ID of the channel the notification should be posted to. This channel
+ * will be created if it did not already exist. Must be a known channel within
+ * {@link ChannelsInitializer#ensureInitialized(String)}.
*/
- public static ChromeNotificationBuilder createChromeNotificationBuilder(boolean preferCompat,
- String channelId, String channelName, String channelGroupId, String channelGroupName) {
+ public static ChromeNotificationBuilder createChromeNotificationBuilder(
+ boolean preferCompat, @ChannelsInitializer.ChannelId String channelId) {
Context context = ContextUtils.getApplicationContext();
if (BuildInfo.isAtLeastO()) {
- return new NotificationBuilderForO(ContextUtils.getApplicationContext(), channelId,
- channelName, channelGroupId, channelGroupName);
+ return createNotificationBuilderForO(channelId, context);
}
return preferCompat ? new NotificationCompatBuilder(context)
: new NotificationBuilder(context);
}
+
+ @SuppressLint("NewApi") // for Context.getSystemService(Class)
+ private static ChromeNotificationBuilder createNotificationBuilderForO(
+ @ChannelsInitializer.ChannelId String channelId, Context context) {
+ return new NotificationBuilderForO(context, channelId,
+ new ChannelsInitializer(new NotificationManagerProxyImpl(
+ context.getSystemService(NotificationManager.class))));
+ }
}

Powered by Google App Engine
This is Rietveld 408576698