diff options
-rw-r--r-- | api/current.txt | 1 | ||||
-rw-r--r-- | core/java/android/app/Notification.java | 14 | ||||
-rw-r--r-- | services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java | 30 |
3 files changed, 39 insertions, 6 deletions
diff --git a/api/current.txt b/api/current.txt index a6919bb5e0b5..69c9b29b8dcc 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 0ab1a85372f5..a90185cf1468 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 * <p>This data will be ignored unless the notification is posted to a channel that * allows {@link NotificationChannel#canBubble() bubbles}.</p> * - * <b>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.</b> + * <p>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.</p> */ @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 b0788253d0a7..bafcd5f0f8bd 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -4289,6 +4289,36 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } @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! mService.setPreferencesHelper(mPreferencesHelper); |