Loading core/java/android/app/Notification.java +14 −0 Original line number Diff line number Diff line Loading @@ -2639,6 +2639,20 @@ public class Notification implements Parcelable return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; } /** * @hide */ public boolean suppressAlertingDueToGrouping() { if (isGroupSummary() && getGroupAlertBehavior() == Notification.GROUP_ALERT_CHILDREN) { return true; } else if (isGroupChild() && getGroupAlertBehavior() == Notification.GROUP_ALERT_SUMMARY) { return true; } return false; } /** * Builder class for {@link Notification} objects. * Loading packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +10 −2 Original line number Diff line number Diff line Loading @@ -771,6 +771,7 @@ public class StatusBar extends SystemUI implements DemoMode, mBatteryController = Dependency.get(BatteryController.class); mAssistManager = Dependency.get(AssistManager.class); mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class); mSystemServicesProxy = SystemServicesProxy.getInstance(mContext); mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); mDisplay = mWindowManager.getDefaultDisplay(); Loading Loading @@ -5258,6 +5259,7 @@ public class StatusBar extends SystemUI implements DemoMode, protected KeyguardManager mKeyguardManager; private LockPatternUtils mLockPatternUtils; private DeviceProvisionedController mDeviceProvisionedController; protected SystemServicesProxy mSystemServicesProxy; // UI-specific methods Loading Loading @@ -6908,6 +6910,7 @@ public class StatusBar extends SystemUI implements DemoMode, protected boolean shouldPeek(Entry entry, StatusBarNotification sbn) { if (!mUseHeadsUp || isDeviceInVrMode()) { if (DEBUG) Log.d(TAG, "No peeking: no huns or vr mode"); return false; } Loading @@ -6916,8 +6919,7 @@ public class StatusBar extends SystemUI implements DemoMode, return false; } boolean inUse = mPowerManager.isScreenOn() && !SystemServicesProxy.getInstance(mContext).isDreaming(); boolean inUse = mPowerManager.isScreenOn() && !mSystemServicesProxy.isDreaming(); if (!inUse && !isDozing()) { if (DEBUG) { Loading Loading @@ -6960,6 +6962,12 @@ public class StatusBar extends SystemUI implements DemoMode, } } // Don't peek notifications that are suppressed due to group alert behavior if (sbn.isGroup() && sbn.getNotification().suppressAlertingDueToGrouping()) { if (DEBUG) Log.d(TAG, "No peeking: suppressed due to group alert behavior"); return false; } return true; } Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java +82 −3 Original line number Diff line number Diff line Loading @@ -16,13 +16,27 @@ package com.android.systemui.statusbar.phone; import static android.app.NotificationManager.IMPORTANCE_HIGH; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import android.app.Notification; import android.metrics.LogMaker; import android.os.Handler; import android.os.HandlerThread; import android.os.IPowerManager; import android.os.Looper; import android.os.PowerManager; import android.os.UserHandle; import android.service.notification.StatusBarNotification; import android.support.test.filters.SmallTest; import android.support.test.metricshelper.MetricsAsserts; import android.support.test.runner.AndroidJUnit4; Loading @@ -33,9 +47,11 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.testing.FakeMetricsLogger; import com.android.keyguard.KeyguardHostView.OnDismissAction; import com.android.systemui.SysuiTestCase; import com.android.systemui.recents.misc.SystemServicesProxy; import com.android.systemui.statusbar.ActivatableNotificationView; import com.android.systemui.statusbar.KeyguardIndicationController; import com.android.systemui.statusbar.NotificationData; import com.android.systemui.statusbar.policy.HeadsUpManager; import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; import org.junit.Before; Loading @@ -52,19 +68,34 @@ public class StatusBarTest extends SysuiTestCase { NotificationStackScrollLayout mStackScroller; StatusBar mStatusBar; FakeMetricsLogger mMetricsLogger; HeadsUpManager mHeadsUpManager; NotificationData mNotificationData; PowerManager mPowerManager; SystemServicesProxy mSystemServicesProxy; private DisplayMetrics mDisplayMetrics = new DisplayMetrics(); @Before public void setup() { public void setup() throws Exception { mStatusBarKeyguardViewManager = mock(StatusBarKeyguardViewManager.class); mUnlockMethodCache = mock(UnlockMethodCache.class); mKeyguardIndicationController = mock(KeyguardIndicationController.class); mStackScroller = mock(NotificationStackScrollLayout.class); mMetricsLogger = new FakeMetricsLogger(); mHeadsUpManager = mock(HeadsUpManager.class); mNotificationData = mock(NotificationData.class); mSystemServicesProxy = mock(SystemServicesProxy.class); IPowerManager powerManagerService = mock(IPowerManager.class); HandlerThread handlerThread = new HandlerThread("TestThread"); handlerThread.start(); mPowerManager = new PowerManager(mContext, powerManagerService, new Handler(handlerThread.getLooper())); when(powerManagerService.isInteractive()).thenReturn(true); mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); mStatusBar = new TestableStatusBar(mStatusBarKeyguardViewManager, mUnlockMethodCache, mKeyguardIndicationController, mStackScroller); mKeyguardIndicationController, mStackScroller, mHeadsUpManager, mNotificationData, mPowerManager, mSystemServicesProxy); doAnswer(invocation -> { OnDismissAction onDismissAction = (OnDismissAction) invocation.getArguments()[0]; Loading Loading @@ -210,14 +241,62 @@ public class StatusBarTest extends SysuiTestCase { .setType(MetricsEvent.TYPE_ACTION)); } @Test public void testShouldPeek_nonSuppressedGroupSummary() { when(mPowerManager.isScreenOn()).thenReturn(true); when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); when(mNotificationData.shouldFilterOut(any())).thenReturn(false); when(mSystemServicesProxy.isDreaming()).thenReturn(false); when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); Notification n = new Notification.Builder(getContext(), "a") .setGroup("a") .setGroupSummary(true) .setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY) .build(); StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, UserHandle.of(0), null, 0); NotificationData.Entry entry = new NotificationData.Entry(sbn); assertTrue(mStatusBar.shouldPeek(entry, sbn)); } @Test public void testShouldPeek_suppressedGroupSummary() { when(mPowerManager.isScreenOn()).thenReturn(true); when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); when(mNotificationData.shouldFilterOut(any())).thenReturn(false); when(mSystemServicesProxy.isDreaming()).thenReturn(false); when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); Notification n = new Notification.Builder(getContext(), "a") .setGroup("a") .setGroupSummary(true) .setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN) .build(); StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, UserHandle.of(0), null, 0); NotificationData.Entry entry = new NotificationData.Entry(sbn); assertFalse(mStatusBar.shouldPeek(entry, sbn)); } static class TestableStatusBar extends StatusBar { public TestableStatusBar(StatusBarKeyguardViewManager man, UnlockMethodCache unlock, KeyguardIndicationController key, NotificationStackScrollLayout stack) { NotificationStackScrollLayout stack, HeadsUpManager hum, NotificationData nd, PowerManager pm, SystemServicesProxy ssp) { mStatusBarKeyguardViewManager = man; mUnlockMethodCache = unlock; mKeyguardIndicationController = key; mStackScroller = stack; mHeadsUpManager = hum; mNotificationData = nd; mUseHeadsUp = true; mPowerManager = pm; mSystemServicesProxy = ssp; } @Override Loading services/core/java/com/android/server/notification/NotificationManagerService.java +1 −7 Original line number Diff line number Diff line Loading @@ -3759,13 +3759,7 @@ public class NotificationManagerService extends SystemService { return true; } if (record.sbn.isGroup()) { if (notification.isGroupSummary() && notification.getGroupAlertBehavior() == Notification.GROUP_ALERT_CHILDREN) { return true; } else if (notification.isGroupChild() && notification.getGroupAlertBehavior() == Notification.GROUP_ALERT_SUMMARY) { return true; } return notification.suppressAlertingDueToGrouping(); } return false; } Loading Loading
core/java/android/app/Notification.java +14 −0 Original line number Diff line number Diff line Loading @@ -2639,6 +2639,20 @@ public class Notification implements Parcelable return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; } /** * @hide */ public boolean suppressAlertingDueToGrouping() { if (isGroupSummary() && getGroupAlertBehavior() == Notification.GROUP_ALERT_CHILDREN) { return true; } else if (isGroupChild() && getGroupAlertBehavior() == Notification.GROUP_ALERT_SUMMARY) { return true; } return false; } /** * Builder class for {@link Notification} objects. * Loading
packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +10 −2 Original line number Diff line number Diff line Loading @@ -771,6 +771,7 @@ public class StatusBar extends SystemUI implements DemoMode, mBatteryController = Dependency.get(BatteryController.class); mAssistManager = Dependency.get(AssistManager.class); mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class); mSystemServicesProxy = SystemServicesProxy.getInstance(mContext); mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); mDisplay = mWindowManager.getDefaultDisplay(); Loading Loading @@ -5258,6 +5259,7 @@ public class StatusBar extends SystemUI implements DemoMode, protected KeyguardManager mKeyguardManager; private LockPatternUtils mLockPatternUtils; private DeviceProvisionedController mDeviceProvisionedController; protected SystemServicesProxy mSystemServicesProxy; // UI-specific methods Loading Loading @@ -6908,6 +6910,7 @@ public class StatusBar extends SystemUI implements DemoMode, protected boolean shouldPeek(Entry entry, StatusBarNotification sbn) { if (!mUseHeadsUp || isDeviceInVrMode()) { if (DEBUG) Log.d(TAG, "No peeking: no huns or vr mode"); return false; } Loading @@ -6916,8 +6919,7 @@ public class StatusBar extends SystemUI implements DemoMode, return false; } boolean inUse = mPowerManager.isScreenOn() && !SystemServicesProxy.getInstance(mContext).isDreaming(); boolean inUse = mPowerManager.isScreenOn() && !mSystemServicesProxy.isDreaming(); if (!inUse && !isDozing()) { if (DEBUG) { Loading Loading @@ -6960,6 +6962,12 @@ public class StatusBar extends SystemUI implements DemoMode, } } // Don't peek notifications that are suppressed due to group alert behavior if (sbn.isGroup() && sbn.getNotification().suppressAlertingDueToGrouping()) { if (DEBUG) Log.d(TAG, "No peeking: suppressed due to group alert behavior"); return false; } return true; } Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java +82 −3 Original line number Diff line number Diff line Loading @@ -16,13 +16,27 @@ package com.android.systemui.statusbar.phone; import static android.app.NotificationManager.IMPORTANCE_HIGH; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import android.app.Notification; import android.metrics.LogMaker; import android.os.Handler; import android.os.HandlerThread; import android.os.IPowerManager; import android.os.Looper; import android.os.PowerManager; import android.os.UserHandle; import android.service.notification.StatusBarNotification; import android.support.test.filters.SmallTest; import android.support.test.metricshelper.MetricsAsserts; import android.support.test.runner.AndroidJUnit4; Loading @@ -33,9 +47,11 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.testing.FakeMetricsLogger; import com.android.keyguard.KeyguardHostView.OnDismissAction; import com.android.systemui.SysuiTestCase; import com.android.systemui.recents.misc.SystemServicesProxy; import com.android.systemui.statusbar.ActivatableNotificationView; import com.android.systemui.statusbar.KeyguardIndicationController; import com.android.systemui.statusbar.NotificationData; import com.android.systemui.statusbar.policy.HeadsUpManager; import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; import org.junit.Before; Loading @@ -52,19 +68,34 @@ public class StatusBarTest extends SysuiTestCase { NotificationStackScrollLayout mStackScroller; StatusBar mStatusBar; FakeMetricsLogger mMetricsLogger; HeadsUpManager mHeadsUpManager; NotificationData mNotificationData; PowerManager mPowerManager; SystemServicesProxy mSystemServicesProxy; private DisplayMetrics mDisplayMetrics = new DisplayMetrics(); @Before public void setup() { public void setup() throws Exception { mStatusBarKeyguardViewManager = mock(StatusBarKeyguardViewManager.class); mUnlockMethodCache = mock(UnlockMethodCache.class); mKeyguardIndicationController = mock(KeyguardIndicationController.class); mStackScroller = mock(NotificationStackScrollLayout.class); mMetricsLogger = new FakeMetricsLogger(); mHeadsUpManager = mock(HeadsUpManager.class); mNotificationData = mock(NotificationData.class); mSystemServicesProxy = mock(SystemServicesProxy.class); IPowerManager powerManagerService = mock(IPowerManager.class); HandlerThread handlerThread = new HandlerThread("TestThread"); handlerThread.start(); mPowerManager = new PowerManager(mContext, powerManagerService, new Handler(handlerThread.getLooper())); when(powerManagerService.isInteractive()).thenReturn(true); mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); mStatusBar = new TestableStatusBar(mStatusBarKeyguardViewManager, mUnlockMethodCache, mKeyguardIndicationController, mStackScroller); mKeyguardIndicationController, mStackScroller, mHeadsUpManager, mNotificationData, mPowerManager, mSystemServicesProxy); doAnswer(invocation -> { OnDismissAction onDismissAction = (OnDismissAction) invocation.getArguments()[0]; Loading Loading @@ -210,14 +241,62 @@ public class StatusBarTest extends SysuiTestCase { .setType(MetricsEvent.TYPE_ACTION)); } @Test public void testShouldPeek_nonSuppressedGroupSummary() { when(mPowerManager.isScreenOn()).thenReturn(true); when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); when(mNotificationData.shouldFilterOut(any())).thenReturn(false); when(mSystemServicesProxy.isDreaming()).thenReturn(false); when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); Notification n = new Notification.Builder(getContext(), "a") .setGroup("a") .setGroupSummary(true) .setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY) .build(); StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, UserHandle.of(0), null, 0); NotificationData.Entry entry = new NotificationData.Entry(sbn); assertTrue(mStatusBar.shouldPeek(entry, sbn)); } @Test public void testShouldPeek_suppressedGroupSummary() { when(mPowerManager.isScreenOn()).thenReturn(true); when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); when(mNotificationData.shouldFilterOut(any())).thenReturn(false); when(mSystemServicesProxy.isDreaming()).thenReturn(false); when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); Notification n = new Notification.Builder(getContext(), "a") .setGroup("a") .setGroupSummary(true) .setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN) .build(); StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, UserHandle.of(0), null, 0); NotificationData.Entry entry = new NotificationData.Entry(sbn); assertFalse(mStatusBar.shouldPeek(entry, sbn)); } static class TestableStatusBar extends StatusBar { public TestableStatusBar(StatusBarKeyguardViewManager man, UnlockMethodCache unlock, KeyguardIndicationController key, NotificationStackScrollLayout stack) { NotificationStackScrollLayout stack, HeadsUpManager hum, NotificationData nd, PowerManager pm, SystemServicesProxy ssp) { mStatusBarKeyguardViewManager = man; mUnlockMethodCache = unlock; mKeyguardIndicationController = key; mStackScroller = stack; mHeadsUpManager = hum; mNotificationData = nd; mUseHeadsUp = true; mPowerManager = pm; mSystemServicesProxy = ssp; } @Override Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +1 −7 Original line number Diff line number Diff line Loading @@ -3759,13 +3759,7 @@ public class NotificationManagerService extends SystemService { return true; } if (record.sbn.isGroup()) { if (notification.isGroupSummary() && notification.getGroupAlertBehavior() == Notification.GROUP_ALERT_CHILDREN) { return true; } else if (notification.isGroupChild() && notification.getGroupAlertBehavior() == Notification.GROUP_ALERT_SUMMARY) { return true; } return notification.suppressAlertingDueToGrouping(); } return false; } Loading