From 24653c3bbaa0e9749ee1bb8d118fa392a1c23463 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Fri, 2 Mar 2018 13:16:37 -0500 Subject: [PATCH] Make systemui obey new visual effect flags Test: runtest systemui Bug: 74075050 Change-Id: I46a3e762ecdab132edcb81880ef3e4f7f2e55aac --- .../systemui/statusbar/NotificationData.java | 54 +++++++++++- .../statusbar/NotificationEntryManager.java | 11 +-- .../statusbar/NotificationPresenter.java | 5 -- .../phone/NotificationIconAreaController.java | 2 +- .../systemui/statusbar/phone/StatusBar.java | 1 + .../statusbar/phone/StatusBarTest.java | 86 +++++-------------- 6 files changed, 79 insertions(+), 80 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java index d53cb03cfcb73..22a186ff1706a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java @@ -16,6 +16,13 @@ package com.android.systemui.statusbar; +import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT; +import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT; +import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS; +import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST; +import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK; +import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR; + import android.app.AppGlobals; import android.app.AppOpsManager; import android.app.Notification; @@ -445,20 +452,47 @@ public class NotificationData { return Ranking.VISIBILITY_NO_OVERRIDE; } - public boolean shouldSuppressScreenOff(String key) { + public boolean shouldSuppressFullScreenIntent(String key) { if (mRankingMap != null) { getRanking(key, mTmpRanking); return (mTmpRanking.getSuppressedVisualEffects() - & NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_OFF) != 0; + & SUPPRESSED_EFFECT_FULL_SCREEN_INTENT) != 0; } return false; } - public boolean shouldSuppressScreenOn(String key) { + public boolean shouldSuppressPeek(String key) { if (mRankingMap != null) { getRanking(key, mTmpRanking); return (mTmpRanking.getSuppressedVisualEffects() - & NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_ON) != 0; + & SUPPRESSED_EFFECT_PEEK) != 0; + } + return false; + } + + public boolean shouldSuppressStatusBar(String key) { + if (mRankingMap != null) { + getRanking(key, mTmpRanking); + return (mTmpRanking.getSuppressedVisualEffects() + & SUPPRESSED_EFFECT_STATUS_BAR) != 0; + } + return false; + } + + public boolean shouldSuppressAmbient(String key) { + if (mRankingMap != null) { + getRanking(key, mTmpRanking); + return (mTmpRanking.getSuppressedVisualEffects() + & SUPPRESSED_EFFECT_AMBIENT) != 0; + } + return false; + } + + public boolean shouldSuppressNotificationList(String key) { + if (mRankingMap != null) { + getRanking(key, mTmpRanking); + return (mTmpRanking.getSuppressedVisualEffects() + & SUPPRESSED_EFFECT_NOTIFICATION_LIST) != 0; } return false; } @@ -576,6 +610,14 @@ public class NotificationData { return true; } + if (mEnvironment.isDozing() && shouldSuppressAmbient(sbn.getKey())) { + return true; + } + + if (!mEnvironment.isDozing() && shouldSuppressNotificationList(sbn.getKey())) { + return true; + } + if (!StatusBar.ENABLE_CHILD_NOTIFICATIONS && mGroupManager.isChildInGroupWithSummary(sbn)) { return true; @@ -670,5 +712,9 @@ public class NotificationData { public boolean isNotificationForCurrentProfiles(StatusBarNotification sbn); public String getCurrentMediaNotificationKey(); public NotificationGroupManager getGroupManager(); + /** + * @return true iff the device is dozing + */ + boolean isDozing(); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationEntryManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationEntryManager.java index 146de008b6108..48828ab9d032e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationEntryManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationEntryManager.java @@ -304,11 +304,7 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater. return true; } - if (mPowerManager.isInteractive()) { - return mNotificationData.shouldSuppressScreenOn(key); - } else { - return mNotificationData.shouldSuppressScreenOff(key); - } + return mNotificationData.shouldSuppressFullScreenIntent(key); } private void inflateViews(NotificationData.Entry entry, ViewGroup parent) { @@ -849,12 +845,13 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater. return false; } - if (!mPresenter.isDozing() && mNotificationData.shouldSuppressScreenOn(sbn.getKey())) { + if (!mPresenter.isDozing() && mNotificationData.shouldSuppressPeek(sbn.getKey())) { if (DEBUG) Log.d(TAG, "No peeking: suppressed by DND: " + sbn.getKey()); return false; } - if (mPresenter.isDozing() && mNotificationData.shouldSuppressScreenOff(sbn.getKey())) { + // Peeking triggers an ambient display pulse, so disable peek is ambient is active + if (mPresenter.isDozing() && mNotificationData.shouldSuppressAmbient(sbn.getKey())) { if (DEBUG) Log.d(TAG, "No peeking: suppressed by DND: " + sbn.getKey()); return false; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationPresenter.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationPresenter.java index 5263bb4173a32..21d3d810cf562 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationPresenter.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationPresenter.java @@ -100,11 +100,6 @@ public interface NotificationPresenter extends NotificationData.Environment, */ void updateNotificationViews(); - /** - * @return true iff the device is dozing - */ - boolean isDozing(); - /** * Returns the maximum number of notifications to show while locked. * diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconAreaController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconAreaController.java index e77b135043372..e1aed7a04c35e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconAreaController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconAreaController.java @@ -141,7 +141,7 @@ public class NotificationIconAreaController implements DarkReceiver { } // showAmbient == show in shade but not shelf - if (!showAmbient && notificationData.shouldSuppressScreenOn(entry.key)) { + if (!showAmbient && notificationData.shouldSuppressStatusBar(entry.key)) { return false; } 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 d3fbe27ff3a50..899b93626a7f1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -4603,6 +4603,7 @@ public class StatusBar extends SystemUI implements DemoMode, if (mAmbientIndicationContainer instanceof DozeReceiver) { ((DozeReceiver) mAmbientIndicationContainer).setDozing(mDozing); } + mEntryManager.updateNotifications(); updateDozingState(); updateReportRejectedTouchVisibility(); Trace.endSection(); 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 ff545f0bd6533..14baaeb292b33 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 @@ -346,7 +346,7 @@ public class StatusBarTest extends SysuiTestCase { public void testShouldPeek_nonSuppressedGroupSummary() { when(mPowerManager.isScreenOn()).thenReturn(true); when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); - when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); + when(mNotificationData.shouldSuppressStatusBar(any())).thenReturn(false); when(mNotificationData.shouldFilterOut(any())).thenReturn(false); when(mSystemServicesProxy.isDreaming()).thenReturn(false); when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); @@ -367,7 +367,7 @@ public class StatusBarTest extends SysuiTestCase { public void testShouldPeek_suppressedGroupSummary() { when(mPowerManager.isScreenOn()).thenReturn(true); when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); - when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); + when(mNotificationData.shouldSuppressStatusBar(any())).thenReturn(false); when(mNotificationData.shouldFilterOut(any())).thenReturn(false); when(mSystemServicesProxy.isDreaming()).thenReturn(false); when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); @@ -385,16 +385,32 @@ public class StatusBarTest extends SysuiTestCase { } @Test - public void testShouldPeek_suppressedScreenOn_dozing() { + public void testShouldPeek_suppressedPeek() { 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); + when(mNotificationData.shouldSuppressPeek(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(mEntryManager.shouldPeek(entry, sbn)); + } + + @Test + public void testShouldPeek_noSuppressedPeek() { + 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); + + when(mNotificationData.shouldSuppressPeek(any())).thenReturn(false); Notification n = new Notification.Builder(getContext(), "a").build(); StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, @@ -404,63 +420,6 @@ public class StatusBarTest extends SysuiTestCase { assertTrue(mEntryManager.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(mEntryManager.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(mEntryManager.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(mEntryManager.shouldPeek(entry, sbn)); - } - - @Test public void testLogHidden() { try { @@ -574,6 +533,7 @@ public class StatusBarTest extends SysuiTestCase { public void testFingerprintNotification_UpdatesScrims() { mStatusBar.mStatusBarWindowManager = mock(StatusBarWindowManager.class); mStatusBar.mDozeScrimController = mock(DozeScrimController.class); + mStatusBar.mNotificationIconAreaController = mock(NotificationIconAreaController.class); mStatusBar.notifyFpAuthModeChanged(); verify(mScrimController).transitionTo(any(), any()); }