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

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

Issue 2765003002: [Android O] Upstreaming notification channels code (Closed)
Patch Set: Rebase + update tag Created 3 years, 9 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
new file mode 100644
index 0000000000000000000000000000000000000000..609be47354a260390696b7334e5fbc25332087ce
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationBuilderFactory.java
@@ -0,0 +1,45 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.notifications;
+
+import android.content.Context;
+
+import org.chromium.base.BuildInfo;
+import org.chromium.base.ContextUtils;
+
+/**
+ * Factory which supplies the appropriate type of notification builder based on Android version.
+ * Should be used for all notifications we create, to ensure a notification channel is set on O.
+ */
+public class NotificationBuilderFactory {
+ /**
+ * Creates either a Notification.Builder or NotificationCompat.Builder under the hood, wrapped
+ * in our own common interface.
+ *
+ * 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.
+ *
+ * @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.
+ */
+ public static ChromeNotificationBuilder createChromeNotificationBuilder(boolean preferCompat,
+ String channelId, String channelName, String channelGroupId, String channelGroupName) {
+ Context context = ContextUtils.getApplicationContext();
+ if (BuildInfo.isAtLeastO()) {
+ return new NotificationBuilderForO(ContextUtils.getApplicationContext(), channelId,
+ channelName, channelGroupId, channelGroupName);
+ }
+ return preferCompat ? new NotificationCompatBuilder(context)
+ : new NotificationBuilder(context);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698