Commit e424e1f9 authored by awdf's avatar awdf Committed by Commit bot

Android notifications: set group for push notifications

- Push notifications are no longer grouped with all other Chrome
  notifications

- However, this patch makes them standalone, rather than grouped by
  origin, as we aren't yet setting a summary notification.

BUG=674015,674335

Review-Url: https://codereview.chromium.org/2628723003
Cr-Commit-Position: refs/heads/master@{#443285}
parent 690cb481
......@@ -162,6 +162,7 @@ public class CustomNotificationBuilder extends NotificationBuilderBase {
if (mSettingsAction != null) {
addActionToBuilder(builder, mSettingsAction);
}
setGroupOnBuilder(builder, mOrigin);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Notification.Builder.setPublicVersion was added in Android L.
builder.setPublicVersion(createPublicNotification(mContext));
......
......@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.notifications;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.PendingIntent;
......@@ -429,6 +430,21 @@ public abstract class NotificationBuilderBase {
}
}
/**
* Sets the notification group for the builder, determined by the origin provided.
* Note, after this notification is built and posted, a further summary notification must be
* posted for notifications in the group to appear grouped in the notification shade.
*/
@SuppressLint("NewApi") // For setGroup
static void setGroupOnBuilder(Notification.Builder builder, CharSequence origin) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH || origin == null) return;
builder.setGroup(NotificationConstants.GROUP_WEB_PREFIX + origin);
// TODO(crbug.com/674927) Post a group summary notification.
// Notifications with the same group will only actually be stacked if we post a group
// summary notification. Calling setGroup at least prevents them being autobundled with
// all Chrome notifications on N though (see crbug.com/674015).
}
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // For Notification.Action.Builder
@SuppressWarnings("deprecation") // For Builder(int, CharSequence, PendingIntent)
private static Notification.Action.Builder getActionBuilder(Action action) {
......
......@@ -66,4 +66,8 @@ public class NotificationConstants {
public static final String GROUP_MEDIA_PRESENTATION = "MediaPresentation";
public static final String GROUP_MEDIA_REMOTE = "MediaRemote";
public static final String GROUP_SYNC = "Sync";
// Web notification group names are set dynamically as this prefix + notification origin.
// For example, 'Web:chromium.org' for a notification from chromium.org.
static final String GROUP_WEB_PREFIX = "Web:";
}
......@@ -56,6 +56,7 @@ public class StandardNotificationBuilder extends NotificationBuilderBase {
builder.setVibrate(mVibratePattern);
builder.setWhen(mTimestamp);
builder.setOnlyAlertOnce(!mRenotify);
setGroupOnBuilder(builder, mOrigin);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Notification.Builder.setPublicVersion was added in Android L.
builder.setPublicVersion(createPublicNotification(mContext));
......
......@@ -93,6 +93,10 @@ public class CustomNotificationBuilderTest extends NativeLibraryTestBase {
assertEquals("title", NotificationTestUtil.getExtraTitle(notification));
assertEquals("body", NotificationTestUtil.getExtraText(notification));
assertEquals("origin", NotificationTestUtil.getExtraSubText(notification));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
assertEquals(
NotificationConstants.GROUP_WEB_PREFIX + "origin", notification.getGroup());
}
assertEquals("ticker", notification.tickerText.toString());
assertEquals(Notification.DEFAULT_ALL, notification.defaults);
......
......@@ -93,6 +93,10 @@ public class StandardNotificationBuilderTest extends NativeLibraryTestBase {
assertEquals("title", NotificationTestUtil.getExtraTitle(notification));
assertEquals("body", NotificationTestUtil.getExtraText(notification));
assertEquals("origin", NotificationTestUtil.getExtraSubText(notification));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
assertEquals(
NotificationConstants.GROUP_WEB_PREFIX + "origin", notification.getGroup());
}
assertEquals("ticker", notification.tickerText.toString());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// EXTRA_TEMPLATE was added in Android L; style cannot be verified in earlier versions.
......
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