From 65dcaa933850594126023e0baa8b293ca4c8cf1d Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Wed, 3 Apr 2019 12:21:44 -0700 Subject: [PATCH] Make FLAG_BUBBLE public; update some documentation Test: atest NotificationManagerServiceTest Bug: 128459529 Change-Id: I4378b231059f92ffb529e9aca9549ee9b566d5a6 --- api/current.txt | 1 + core/java/android/app/Notification.java | 14 +++++---- .../NotificationManagerServiceTest.java | 30 +++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/api/current.txt b/api/current.txt index f78dfde30c3e8..42357e9ff4655 100644 --- a/api/current.txt +++ b/api/current.txt @@ -5335,6 +5335,7 @@ package android.app { field public static final String EXTRA_TITLE = "android.title"; field public static final String EXTRA_TITLE_BIG = "android.title.big"; field public static final int FLAG_AUTO_CANCEL = 16; // 0x10 + field public static final int FLAG_BUBBLE = 4096; // 0x1000 field public static final int FLAG_FOREGROUND_SERVICE = 64; // 0x40 field public static final int FLAG_GROUP_SUMMARY = 512; // 0x200 field @Deprecated public static final int FLAG_HIGH_PRIORITY = 128; // 0x80 diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 0ab1a85372f53..a90185cf1468d 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -618,9 +618,11 @@ public class Notification implements Parcelable public static final int FLAG_CAN_COLORIZE = 0x00000800; /** - * Bit to be bitswised-ored into the {@link #flags} field that should be - * set if this notification can be shown as a bubble. - * @hide + * Bit to be bitswised-ored into the {@link #flags} field that should be set if this + * notification is showing as a bubble. This will be set by the system if it is determined + * that your notification is allowed to be a bubble. + * + * @see {@link Notification.Builder#setBubbleMetadata(BubbleMetadata)} */ public static final int FLAG_BUBBLE = 0x00001000; @@ -3578,9 +3580,9 @@ public class Notification implements Parcelable *

This data will be ignored unless the notification is posted to a channel that * allows {@link NotificationChannel#canBubble() bubbles}.

* - * Notifications with a valid and allowed bubble metadata will display in collapsed state - * outside of the notification shade on unlocked devices. When a user interacts with the - * collapsed state, the bubble intent will be invoked and displayed. + *

Notifications allowed to bubble that have valid bubble metadata will display in + * collapsed state outside of the notification shade on unlocked devices. When a user + * interacts with the collapsed state, the bubble intent will be invoked and displayed.

*/ @NonNull public Builder setBubbleMetadata(@Nullable BubbleMetadata data) { diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index ca7a71ecad759..5c00adcce0ef8 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -4304,6 +4304,36 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .onGranted(eq(xmlConfig), eq(0), eq(true)); } + @Test + public void testFlagBubble() throws RemoteException { + // Bubbles are allowed! + mService.setPreferencesHelper(mPreferencesHelper); + when(mPreferencesHelper.areBubblesAllowed(anyString(), anyInt())).thenReturn(true); + when(mPreferencesHelper.getNotificationChannel( + anyString(), anyInt(), anyString(), anyBoolean())).thenReturn( + mTestNotificationChannel); + when(mPreferencesHelper.getImportance(anyString(), anyInt())).thenReturn( + mTestNotificationChannel.getImportance()); + + // Notif with bubble metadata but not our other misc requirements + NotificationRecord nr = generateNotificationRecord(mTestNotificationChannel, + null /* tvExtender */, true /* isBubble */); + + // Say we're foreground + when(mActivityManager.getPackageImportance(nr.sbn.getPackageName())).thenReturn( + IMPORTANCE_FOREGROUND); + + mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", + nr.sbn.getId(), nr.sbn.getNotification(), nr.sbn.getUserId()); + waitForIdle(); + + StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); + assertEquals(1, notifs.length); + assertTrue((notifs[0].getNotification().flags & FLAG_BUBBLE) != 0); + assertTrue(mService.getNotificationRecord( + nr.sbn.getKey()).getNotification().isBubbleNotification()); + } + @Test public void testFlagBubbleNotifs_flag_appForeground() throws RemoteException { // Bubbles are allowed!