From 38159cee769ae239574bbd5f24a3e97306704f61 Mon Sep 17 00:00:00 2001 From: Beverly Date: Thu, 13 Jul 2017 16:39:24 -0400 Subject: [PATCH] "Block notifications screen off" setting is used Fixes: 63520128 Test: runtest -x packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java Change-Id: Ib0f737999aac9fc944812fb90644a5be5c801da2 (cherry picked from commit 6cfa71486ea4b11456a5bd945a7b5c49c9d862f2) --- .../systemui/statusbar/phone/StatusBar.java | 10 ++- .../statusbar/phone/StatusBarTest.java | 77 +++++++++++++++++++ 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index ec6f747db8f3e..ed2c2164a9cb4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -104,6 +104,7 @@ import android.os.UserHandle; import android.os.UserManager; import android.os.Vibrator; import android.provider.Settings; +import android.service.notification.NotificationListenerService; import android.service.notification.NotificationListenerService.RankingMap; import android.service.notification.StatusBarNotification; import android.service.vr.IVrManager; @@ -564,7 +565,7 @@ public class StatusBar extends SystemUI implements DemoMode, }}; private boolean mWaitingForKeyguardExit; - private boolean mDozing; + protected boolean mDozing; private boolean mDozingRequested; protected boolean mScrimSrcModeEnabled; @@ -7215,7 +7216,12 @@ public class StatusBar extends SystemUI implements DemoMode, return false; } - if (mNotificationData.shouldSuppressScreenOn(sbn.getKey())) { + if (!isDozing() && mNotificationData.shouldSuppressScreenOn(sbn.getKey())) { + if (DEBUG) Log.d(TAG, "No peeking: suppressed by DND: " + sbn.getKey()); + return false; + } + + if (isDozing() && mNotificationData.shouldSuppressScreenOff(sbn.getKey())) { if (DEBUG) Log.d(TAG, "No peeking: suppressed by DND: " + sbn.getKey()); return false; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java index 8a4983c330a28..c33897e6b3a11 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java @@ -333,6 +333,83 @@ public class StatusBarTest extends SysuiTestCase { assertFalse(mStatusBar.shouldPeek(entry, sbn)); } + @Test + public void testShouldPeek_suppressedScreenOn_dozing() { + when(mPowerManager.isScreenOn()).thenReturn(true); + when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); + when(mNotificationData.shouldFilterOut(any())).thenReturn(false); + when(mSystemServicesProxy.isDreaming()).thenReturn(false); + when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); + + mStatusBar.mDozing = true; + when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(true); + when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(false); + + Notification n = new Notification.Builder(getContext(), "a").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_suppressedScreenOn_noDoze() { + when(mPowerManager.isScreenOn()).thenReturn(true); + when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); + when(mNotificationData.shouldFilterOut(any())).thenReturn(false); + when(mSystemServicesProxy.isDreaming()).thenReturn(false); + when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); + + mStatusBar.mDozing = false; + when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(true); + when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(false); + + Notification n = new Notification.Builder(getContext(), "a").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)); + } + @Test + public void testShouldPeek_suppressedScreenOff_dozing() { + when(mPowerManager.isScreenOn()).thenReturn(true); + when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); + when(mNotificationData.shouldFilterOut(any())).thenReturn(false); + when(mSystemServicesProxy.isDreaming()).thenReturn(false); + when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); + + mStatusBar.mDozing = true; + when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); + when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(true); + + Notification n = new Notification.Builder(getContext(), "a").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)); + } + + @Test + public void testShouldPeek_suppressedScreenOff_noDoze() { + when(mPowerManager.isScreenOn()).thenReturn(true); + when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); + when(mNotificationData.shouldFilterOut(any())).thenReturn(false); + when(mSystemServicesProxy.isDreaming()).thenReturn(false); + when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); + + mStatusBar.mDozing = false; + when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); + when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(true); + + Notification n = new Notification.Builder(getContext(), "a").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 testLogHidden() { try {