diff options
| author | 2020-04-28 15:22:01 -0700 | |
|---|---|---|
| committer | 2020-04-28 20:06:03 -0700 | |
| commit | a114b793923b94fc352a00d8dc2ece442f549890 (patch) | |
| tree | 224bbb427b6a8eb67e8e2bb7214c70a0b2e84c55 | |
| parent | 920cd50f5ca198543bed5608747043677be69a4f (diff) | |
Fix CTS
* fix BubbleExtractor tests to work with this & better
test things now that the channel is a tristate
Test: atest NotificationManagerTest BubbleExtractorTest
Bug: 155025024
Change-Id: I8b75c1b0087ca79cea29741e32c7c524cb056d04
3 files changed, 89 insertions, 45 deletions
diff --git a/core/java/android/app/NotificationChannel.java b/core/java/android/app/NotificationChannel.java index 9f8d3c4090d6..cf2f7690bc2c 100644 --- a/core/java/android/app/NotificationChannel.java +++ b/core/java/android/app/NotificationChannel.java @@ -161,6 +161,19 @@ public final class NotificationChannel implements Parcelable { USER_LOCKED_ALLOW_BUBBLE }; + /** + * @hide + */ + public static final int DEFAULT_ALLOW_BUBBLE = -1; + /** + * @hide + */ + public static final int ALLOW_BUBBLE_ON = 1; + /** + * @hide + */ + public static final int ALLOW_BUBBLE_OFF = 0; + private static final int DEFAULT_LIGHT_COLOR = 0; private static final int DEFAULT_VISIBILITY = NotificationManager.VISIBILITY_NO_OVERRIDE; @@ -168,12 +181,6 @@ public final class NotificationChannel implements Parcelable { NotificationManager.IMPORTANCE_UNSPECIFIED; private static final boolean DEFAULT_DELETED = false; private static final boolean DEFAULT_SHOW_BADGE = true; - /** - * @hide - */ - public static final int DEFAULT_ALLOW_BUBBLE = -1; - private static final int ALLOW_BUBBLE_ON = 1; - private static final int ALLOW_BUBBLE_OFF = 0; @UnsupportedAppUsage private String mId; diff --git a/services/core/java/com/android/server/notification/BubbleExtractor.java b/services/core/java/com/android/server/notification/BubbleExtractor.java index b1a09c1c0d37..d7d413c2ffb0 100644 --- a/services/core/java/com/android/server/notification/BubbleExtractor.java +++ b/services/core/java/com/android/server/notification/BubbleExtractor.java @@ -17,7 +17,7 @@ package com.android.server.notification; import static android.app.Notification.FLAG_BUBBLE; import static android.app.Notification.FLAG_FOREGROUND_SERVICE; -import static android.app.NotificationChannel.USER_LOCKED_ALLOW_BUBBLE; +import static android.app.NotificationChannel.ALLOW_BUBBLE_OFF; import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED; @@ -82,10 +82,7 @@ public class BubbleExtractor implements NotificationSignalExtractor { // the app is allowed but there's no channel to check record.setAllowBubble(true); } else if (bubblePreference == BUBBLE_PREFERENCE_ALL) { - // by default the channel is not allowed, only don't bubble if the user specified - boolean userLockedNoBubbles = !recordChannel.canBubble() - && (recordChannel.getUserLockedFields() & USER_LOCKED_ALLOW_BUBBLE) != 0; - record.setAllowBubble(!userLockedNoBubbles); + record.setAllowBubble(recordChannel.getAllowBubbles() != ALLOW_BUBBLE_OFF); } else if (bubblePreference == BUBBLE_PREFERENCE_SELECTED) { record.setAllowBubble(recordChannel.canBubble()); } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/BubbleExtractorTest.java b/services/tests/uiservicestests/src/com/android/server/notification/BubbleExtractorTest.java index 229bd3f35cac..38b71b707196 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/BubbleExtractorTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/BubbleExtractorTest.java @@ -15,10 +15,13 @@ */ package com.android.server.notification; -import static android.app.NotificationChannel.USER_LOCKED_ALLOW_BUBBLE; +import static android.app.NotificationChannel.ALLOW_BUBBLE_OFF; +import static android.app.NotificationChannel.ALLOW_BUBBLE_ON; +import static android.app.NotificationChannel.DEFAULT_ALLOW_BUBBLE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED; +import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE; import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; @@ -59,6 +62,7 @@ import org.mockito.MockitoAnnotations; @RunWith(AndroidJUnit4.class) public class BubbleExtractorTest extends UiServiceTestCase { + private static final String CHANNEL_ID = "bubbleExtractorChannelId"; private static final String SHORTCUT_ID = "shortcut"; private static final String PKG = "com.android.server.notification"; private static final String TAG = null; @@ -68,12 +72,11 @@ public class BubbleExtractorTest extends UiServiceTestCase { UserHandle mUser = UserHandle.of(ActivityManager.getCurrentUser()); BubbleExtractor mBubbleExtractor; + NotificationChannel mChannel; @Mock RankingConfig mConfig; @Mock - NotificationChannel mChannel; - @Mock Notification.BubbleMetadata mBubbleMetadata; @Mock PendingIntent mPendingIntent; @@ -95,7 +98,8 @@ public class BubbleExtractorTest extends UiServiceTestCase { mBubbleExtractor.setShortcutHelper(mShortcutHelper); mBubbleExtractor.setActivityManager(mActivityManager); - when(mConfig.getNotificationChannel(PKG, UID, "a", false)).thenReturn(mChannel); + mChannel = new NotificationChannel(CHANNEL_ID, CHANNEL_ID, IMPORTANCE_DEFAULT); + when(mConfig.getNotificationChannel(PKG, UID, CHANNEL_ID, false)).thenReturn(mChannel); when(mShortcutInfo.getId()).thenReturn(SHORTCUT_ID); } @@ -147,10 +151,10 @@ public class BubbleExtractorTest extends UiServiceTestCase { when(mShortcutHelper.getValidShortcutInfo(SHORTCUT_ID, PKG, mUser)).thenReturn(answer); } - void setUpBubblesEnabled(boolean feature, int app, boolean channel) { + void setUpBubblesEnabled(boolean feature, int app, int channel) { when(mConfig.bubblesEnabled()).thenReturn(feature); when(mConfig.getBubblePreference(anyString(), anyInt())).thenReturn(app); - when(mChannel.canBubble()).thenReturn(channel); + mChannel.setAllowBubbles(channel); } // @@ -161,9 +165,8 @@ public class BubbleExtractorTest extends UiServiceTestCase { public void testAppYesChannelNo() { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_ALL /* app */, - false /* channel */); + ALLOW_BUBBLE_OFF /* channel */); NotificationRecord r = getNotificationRecord(true /* bubble */); - when(mChannel.getUserLockedFields()).thenReturn(USER_LOCKED_ALLOW_BUBBLE); mBubbleExtractor.process(r); assertFalse(r.canBubble()); @@ -171,23 +174,22 @@ public class BubbleExtractorTest extends UiServiceTestCase { } @Test - public void testAppNoChannelYes() throws Exception { + public void testAppYesChannelDefault() { setUpBubblesEnabled(true /* feature */, - BUBBLE_PREFERENCE_NONE /* app */, - true /* channel */); + BUBBLE_PREFERENCE_ALL /* app */, + DEFAULT_ALLOW_BUBBLE /* channel */); NotificationRecord r = getNotificationRecord(true /* bubble */); mBubbleExtractor.process(r); - assertFalse(r.canBubble()); - assertFalse(r.getNotification().isBubbleNotification()); + assertTrue(r.canBubble()); } @Test public void testAppYesChannelYes() { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_ALL /* app */, - true /* channel */); + ALLOW_BUBBLE_ON /* channel */); NotificationRecord r = getNotificationRecord(true /* bubble */); mBubbleExtractor.process(r); @@ -196,10 +198,23 @@ public class BubbleExtractorTest extends UiServiceTestCase { } @Test - public void testAppNoChannelNo() { + public void testAppYesChannelYesFeatureNo() { + setUpBubblesEnabled(false /* feature */, + BUBBLE_PREFERENCE_ALL /* app */, + ALLOW_BUBBLE_ON /* channel */); + NotificationRecord r = getNotificationRecord(true /* bubble */); + + mBubbleExtractor.process(r); + + assertFalse(r.canBubble()); + assertFalse(r.getNotification().isBubbleNotification()); + } + + @Test + public void testAppNoChannelYes() throws Exception { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_NONE /* app */, - false /* channel */); + ALLOW_BUBBLE_ON /* channel */); NotificationRecord r = getNotificationRecord(true /* bubble */); mBubbleExtractor.process(r); @@ -209,10 +224,23 @@ public class BubbleExtractorTest extends UiServiceTestCase { } @Test - public void testAppYesChannelYesUserNo() { - setUpBubblesEnabled(false /* feature */, - BUBBLE_PREFERENCE_ALL /* app */, - true /* channel */); + public void testAppNoChannelDefault() { + setUpBubblesEnabled(true /* feature */, + BUBBLE_PREFERENCE_NONE /* app */, + DEFAULT_ALLOW_BUBBLE /* channel */); + NotificationRecord r = getNotificationRecord(true /* bubble */); + + mBubbleExtractor.process(r); + + assertFalse(r.canBubble()); + assertFalse(r.getNotification().isBubbleNotification()); + } + + @Test + public void testAppSelectedChannelDefault() { + setUpBubblesEnabled(true /* feature */, + BUBBLE_PREFERENCE_SELECTED /* app */, + DEFAULT_ALLOW_BUBBLE /* channel */); NotificationRecord r = getNotificationRecord(true /* bubble */); mBubbleExtractor.process(r); @@ -225,7 +253,7 @@ public class BubbleExtractorTest extends UiServiceTestCase { public void testAppSelectedChannelNo() { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_SELECTED /* app */, - false /* channel */); + ALLOW_BUBBLE_OFF /* channel */); NotificationRecord r = getNotificationRecord(true /* bubble */); mBubbleExtractor.process(r); @@ -238,15 +266,27 @@ public class BubbleExtractorTest extends UiServiceTestCase { public void testAppSeletedChannelYes() { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_SELECTED /* app */, - true /* channel */); + ALLOW_BUBBLE_ON /* channel */); NotificationRecord r = getNotificationRecord(true /* bubble */); - when(mChannel.getUserLockedFields()).thenReturn(USER_LOCKED_ALLOW_BUBBLE); mBubbleExtractor.process(r); assertTrue(r.canBubble()); } + @Test + public void testAppSeletedChannelYesFeatureNo() { + setUpBubblesEnabled(false /* feature */, + BUBBLE_PREFERENCE_SELECTED /* app */, + ALLOW_BUBBLE_ON /* channel */); + NotificationRecord r = getNotificationRecord(true /* bubble */); + + mBubbleExtractor.process(r); + + assertFalse(r.canBubble()); + assertFalse(r.getNotification().isBubbleNotification()); + } + // // Tests for flagging it as a bubble. // @@ -255,7 +295,7 @@ public class BubbleExtractorTest extends UiServiceTestCase { public void testFlagBubble_false_previouslyRemoved() { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_ALL /* app */, - true /* channel */); + DEFAULT_ALLOW_BUBBLE /* channel */); when(mActivityManager.isLowRamDevice()).thenReturn(false); setUpShortcutBubble(true /* isValid */); @@ -272,7 +312,7 @@ public class BubbleExtractorTest extends UiServiceTestCase { public void testFlagBubble_true_shortcutBubble() { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_ALL /* app */, - true /* channel */); + DEFAULT_ALLOW_BUBBLE /* channel */); when(mActivityManager.isLowRamDevice()).thenReturn(false); setUpShortcutBubble(true /* isValid */); @@ -287,7 +327,7 @@ public class BubbleExtractorTest extends UiServiceTestCase { public void testFlagBubble_true_intentBubble() { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_ALL /* app */, - true /* channel */); + DEFAULT_ALLOW_BUBBLE /* channel */); when(mActivityManager.isLowRamDevice()).thenReturn(false); setUpIntentBubble(true /* isValid */); @@ -302,7 +342,7 @@ public class BubbleExtractorTest extends UiServiceTestCase { public void testFlagBubble_false_noIntentInvalidShortcut() { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_ALL /* app */, - true /* channel */); + DEFAULT_ALLOW_BUBBLE /* channel */); when(mActivityManager.isLowRamDevice()).thenReturn(false); setUpShortcutBubble(false /* isValid */); @@ -318,7 +358,7 @@ public class BubbleExtractorTest extends UiServiceTestCase { public void testFlagBubble_false_invalidIntentNoShortcut() { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_ALL /* app */, - true /* channel */); + DEFAULT_ALLOW_BUBBLE /* channel */); when(mActivityManager.isLowRamDevice()).thenReturn(false); setUpIntentBubble(false /* isValid */); @@ -334,7 +374,7 @@ public class BubbleExtractorTest extends UiServiceTestCase { public void testFlagBubble_false_noIntentNoShortcut() { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_ALL /* app */, - true /* channel */); + DEFAULT_ALLOW_BUBBLE /* channel */); when(mActivityManager.isLowRamDevice()).thenReturn(false); // Shortcut here is for the notification not the bubble @@ -349,7 +389,7 @@ public class BubbleExtractorTest extends UiServiceTestCase { public void testFlagBubble_false_noMetadata() { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_ALL /* app */, - true /* channel */); + DEFAULT_ALLOW_BUBBLE /* channel */); when(mActivityManager.isLowRamDevice()).thenReturn(false); NotificationRecord r = getNotificationRecord(false /* bubble */); @@ -363,7 +403,7 @@ public class BubbleExtractorTest extends UiServiceTestCase { public void testFlagBubble_false_notConversation() { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_ALL /* app */, - true /* channel */); + DEFAULT_ALLOW_BUBBLE /* channel */); when(mActivityManager.isLowRamDevice()).thenReturn(false); setUpIntentBubble(true /* isValid */); @@ -382,7 +422,7 @@ public class BubbleExtractorTest extends UiServiceTestCase { public void testFlagBubble_false_lowRamDevice() { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_ALL /* app */, - true /* channel */); + DEFAULT_ALLOW_BUBBLE /* channel */); when(mActivityManager.isLowRamDevice()).thenReturn(true); setUpIntentBubble(true /* isValid */); @@ -397,7 +437,7 @@ public class BubbleExtractorTest extends UiServiceTestCase { public void testFlagBubble_false_noIntent() { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_ALL /* app */, - true /* channel */); + DEFAULT_ALLOW_BUBBLE /* channel */); when(mActivityManager.isLowRamDevice()).thenReturn(true); setUpIntentBubble(true /* isValid */); when(mPendingIntent.getIntent()).thenReturn(null); @@ -413,7 +453,7 @@ public class BubbleExtractorTest extends UiServiceTestCase { public void testFlagBubble_false_noActivityInfo() { setUpBubblesEnabled(true /* feature */, BUBBLE_PREFERENCE_ALL /* app */, - true /* channel */); + DEFAULT_ALLOW_BUBBLE /* channel */); when(mActivityManager.isLowRamDevice()).thenReturn(true); setUpIntentBubble(true /* isValid */); when(mPendingIntent.getIntent()).thenReturn(mIntent); |