diff options
13 files changed, 119 insertions, 177 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java index 38c344322a30..7cbe28ff4263 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java @@ -2226,6 +2226,7 @@ public class BubbleController implements ConfigurationChangeListener, pw.print(prefix); pw.println(" currentUserId= " + mCurrentUserId); pw.print(prefix); pw.println(" isStatusBarShade= " + mIsStatusBarShade); pw.print(prefix); pw.println(" isShowingAsBubbleBar= " + isShowingAsBubbleBar()); + pw.print(prefix); pw.println(" isImeVisible= " + mBubblePositioner.isImeVisible()); pw.println(); mBubbleData.dump(pw); @@ -2729,7 +2730,7 @@ public class BubbleController implements ConfigurationChangeListener, public boolean canShowBubbleNotification() { // in bubble bar mode, when the IME is visible we can't animate new bubbles. if (BubbleController.this.isShowingAsBubbleBar()) { - return !BubbleController.this.mBubblePositioner.getIsImeVisible(); + return !BubbleController.this.mBubblePositioner.isImeVisible(); } return true; } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java index a35a004cdace..66a77d08984c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java @@ -325,7 +325,7 @@ public class BubblePositioner { } /** Returns whether the IME is visible. */ - public boolean getIsImeVisible() { + public boolean isImeVisible() { return mImeVisible; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/CommonVisualInterruptionSuppressors.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/CommonVisualInterruptionSuppressors.kt index 87f11f131f32..938a71fd7b82 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/CommonVisualInterruptionSuppressors.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/CommonVisualInterruptionSuppressors.kt @@ -48,6 +48,9 @@ import com.android.systemui.statusbar.policy.HeadsUpManager import com.android.systemui.util.settings.GlobalSettings import com.android.systemui.util.settings.SystemSettings import com.android.systemui.util.time.SystemClock +import com.android.wm.shell.bubbles.Bubbles +import java.util.Optional +import kotlin.jvm.optionals.getOrElse class PeekDisabledSuppressor( private val globalSettings: GlobalSettings, @@ -119,12 +122,18 @@ class PeekPackageSnoozedSuppressor(private val headsUpManager: HeadsUpManager) : } } -class PeekAlreadyBubbledSuppressor(private val statusBarStateController: StatusBarStateController) : - VisualInterruptionFilter(types = setOf(PEEK), reason = "already bubbled") { +class PeekAlreadyBubbledSuppressor( + private val statusBarStateController: StatusBarStateController, + private val bubbles: Optional<Bubbles> +) : VisualInterruptionFilter(types = setOf(PEEK), reason = "already bubbled") { override fun shouldSuppress(entry: NotificationEntry) = when { statusBarStateController.state != SHADE -> false - else -> entry.isBubble + else -> { + val bubblesCanShowNotification = + bubbles.map { it.canShowBubbleNotification() }.getOrElse { false } + entry.isBubble && bubblesCanShowNotification + } } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImpl.java index 9c6a42384a53..74925c8dd506 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImpl.java @@ -52,9 +52,11 @@ import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.util.EventLog; import com.android.systemui.util.settings.GlobalSettings; import com.android.systemui.util.time.SystemClock; +import com.android.wm.shell.bubbles.Bubbles; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import javax.inject.Inject; @@ -83,6 +85,7 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter private final SystemClock mSystemClock; private final GlobalSettings mGlobalSettings; private final EventLog mEventLog; + private final Optional<Bubbles> mBubbles; @VisibleForTesting protected boolean mUseHeadsUp = false; @@ -132,7 +135,8 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter DeviceProvisionedController deviceProvisionedController, SystemClock systemClock, GlobalSettings globalSettings, - EventLog eventLog) { + EventLog eventLog, + Optional<Bubbles> bubbles) { mPowerManager = powerManager; mBatteryController = batteryController; mAmbientDisplayConfiguration = ambientDisplayConfiguration; @@ -148,6 +152,7 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter mSystemClock = systemClock; mGlobalSettings = globalSettings; mEventLog = eventLog; + mBubbles = bubbles; ContentObserver headsUpObserver = new ContentObserver(mainHandler) { @Override public void onChange(boolean selfChange) { @@ -440,7 +445,9 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter } boolean inShade = mStatusBarStateController.getState() == SHADE; - if (entry.isBubble() && inShade) { + boolean bubblesCanShowNotification = + mBubbles.isPresent() && mBubbles.get().canShowBubbleNotification(); + if (entry.isBubble() && inShade && bubblesCanShowNotification) { if (log) mLogger.logNoHeadsUpAlreadyBubbled(entry); return false; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderImpl.kt index f68e194aace2..7e16cd5a693f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderImpl.kt @@ -43,6 +43,8 @@ import com.android.systemui.util.EventLog import com.android.systemui.util.settings.GlobalSettings import com.android.systemui.util.settings.SystemSettings import com.android.systemui.util.time.SystemClock +import com.android.wm.shell.bubbles.Bubbles +import java.util.Optional import javax.inject.Inject class VisualInterruptionDecisionProviderImpl @@ -65,7 +67,8 @@ constructor( private val userTracker: UserTracker, private val avalancheProvider: AvalancheProvider, private val systemSettings: SystemSettings, - private val packageManager: PackageManager + private val packageManager: PackageManager, + private val bubbles: Optional<Bubbles> ) : VisualInterruptionDecisionProvider { init { @@ -158,7 +161,7 @@ constructor( addCondition(PulseDisabledSuppressor(ambientDisplayConfiguration, userTracker)) addCondition(PulseBatterySaverSuppressor(batteryController)) addFilter(PeekPackageSnoozedSuppressor(headsUpManager)) - addFilter(PeekAlreadyBubbledSuppressor(statusBarStateController)) + addFilter(PeekAlreadyBubbledSuppressor(statusBarStateController, bubbles)) addFilter(PeekDndSuppressor()) addFilter(PeekNotImportantSuppressor()) addCondition(PeekDeviceNotInUseSuppressor(powerManager, statusBarStateController)) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImplTest.java index 3e8461a225b2..bfe5c6e233d3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImplTest.java @@ -58,7 +58,6 @@ import android.graphics.drawable.Icon; import android.hardware.display.AmbientDisplayConfiguration; import android.os.Handler; import android.os.PowerManager; -import android.os.RemoteException; import android.platform.test.annotations.DisableFlags; import androidx.test.ext.junit.runners.AndroidJUnit4; @@ -81,6 +80,7 @@ import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.util.FakeEventLog; import com.android.systemui.util.settings.FakeGlobalSettings; import com.android.systemui.util.time.FakeSystemClock; +import com.android.wm.shell.bubbles.Bubbles; import org.junit.Before; import org.junit.Test; @@ -90,6 +90,7 @@ import org.mockito.MockitoAnnotations; import java.util.Arrays; import java.util.HashSet; +import java.util.Optional; import java.util.Set; /** @@ -127,6 +128,8 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { UserTracker mUserTracker; @Mock DeviceProvisionedController mDeviceProvisionedController; + @Mock + Bubbles mBubbles; FakeSystemClock mSystemClock; FakeGlobalSettings mGlobalSettings; FakeEventLog mEventLog; @@ -137,6 +140,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { public void setup() { MockitoAnnotations.initMocks(this); when(mUserTracker.getUserId()).thenReturn(ActivityManager.getCurrentUser()); + when(mBubbles.canShowBubbleNotification()).thenReturn(true); mUiEventLoggerFake = new UiEventLoggerFake(); mSystemClock = new FakeSystemClock(); @@ -161,7 +165,8 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { mDeviceProvisionedController, mSystemClock, mGlobalSettings, - mEventLog); + mEventLog, + Optional.of(mBubbles)); mNotifInterruptionStateProvider.mUseHeadsUp = true; } @@ -170,7 +175,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { * {@link NotificationInterruptStateProviderImpl#shouldHeadsUp(NotificationEntry)} will * pass as long its provided NotificationEntry fulfills importance & DND checks. */ - private void ensureStateForHeadsUpWhenAwake() throws RemoteException { + private void ensureStateForHeadsUpWhenAwake() { when(mHeadsUpManager.isSnoozed(any())).thenReturn(false); when(mStatusBarStateController.isDozing()).thenReturn(false); @@ -208,7 +213,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldHeadsUpAwake() throws RemoteException { + public void testShouldHeadsUpAwake() { ensureStateForHeadsUpWhenAwake(); NotificationEntry entry = createNotification(IMPORTANCE_HIGH); @@ -216,7 +221,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldNotHeadsUp_suppressedForGroups() throws RemoteException { + public void testShouldNotHeadsUp_suppressedForGroups() { // GIVEN state for "heads up when awake" is true ensureStateForHeadsUpWhenAwake(); @@ -315,7 +320,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldHeadsUp() throws RemoteException { + public void testShouldHeadsUp() { ensureStateForHeadsUpWhenAwake(); NotificationEntry entry = createNotification(IMPORTANCE_HIGH); @@ -327,7 +332,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { * the bubble is shown rather than the heads up. */ @Test - public void testShouldNotHeadsUp_bubble() throws RemoteException { + public void testShouldNotHeadsUp_bubble() { ensureStateForHeadsUpWhenAwake(); // Bubble bit only applies to interruption when we're in the shade @@ -337,10 +342,26 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } /** + * If the notification is a bubble, and the user is not on AOD / lockscreen, but a bubble + * notification can't be shown, then show the heads up. + */ + @Test + public void testShouldHeadsUp_bubble_bubblesCannotShowNotification() { + ensureStateForHeadsUpWhenAwake(); + + // Bubble bit only applies to interruption when we're in the shade + when(mStatusBarStateController.getState()).thenReturn(SHADE); + + when(mBubbles.canShowBubbleNotification()).thenReturn(false); + + assertThat(mNotifInterruptionStateProvider.shouldHeadsUp(createBubble())).isTrue(); + } + + /** * If we're not allowed to alert in general, we shouldn't be shown as heads up. */ @Test - public void testShouldNotHeadsUp_filtered() throws RemoteException { + public void testShouldNotHeadsUp_filtered() { ensureStateForHeadsUpWhenAwake(); // Make canAlertCommon false by saying it's filtered out when(mKeyguardNotificationVisibilityProvider.shouldHideNotification(any())) @@ -355,7 +376,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { * {@link android.app.NotificationManager.Policy#SUPPRESSED_EFFECT_PEEK}. */ @Test - public void testShouldNotHeadsUp_suppressPeek() throws RemoteException { + public void testShouldNotHeadsUp_suppressPeek() { ensureStateForHeadsUpWhenAwake(); NotificationEntry entry = createNotification(IMPORTANCE_HIGH); @@ -371,7 +392,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { * to show as a heads up. */ @Test - public void testShouldNotHeadsUp_lessImportant() throws RemoteException { + public void testShouldNotHeadsUp_lessImportant() { ensureStateForHeadsUpWhenAwake(); NotificationEntry entry = createNotification(IMPORTANCE_DEFAULT); @@ -382,7 +403,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { * If the device is not in use then we shouldn't be shown as heads up. */ @Test - public void testShouldNotHeadsUp_deviceNotInUse() throws RemoteException { + public void testShouldNotHeadsUp_deviceNotInUse() { ensureStateForHeadsUpWhenAwake(); NotificationEntry entry = createNotification(IMPORTANCE_HIGH); @@ -397,7 +418,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldNotHeadsUp_headsUpSuppressed() throws RemoteException { + public void testShouldNotHeadsUp_headsUpSuppressed() { ensureStateForHeadsUpWhenAwake(); // If a suppressor is suppressing heads up, then it shouldn't be shown as a heads up. @@ -408,7 +429,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldNotHeadsUpAwake_awakeInterruptsSuppressed() throws RemoteException { + public void testShouldNotHeadsUpAwake_awakeInterruptsSuppressed() { ensureStateForHeadsUpWhenAwake(); // If a suppressor is suppressing heads up, then it shouldn't be shown as a heads up. @@ -446,7 +467,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldHeadsUp_oldWhen_whenNow() throws Exception { + public void testShouldHeadsUp_oldWhen_whenNow() { ensureStateForHeadsUpWhenAwake(); NotificationEntry entry = createNotification(IMPORTANCE_HIGH); @@ -458,7 +479,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldHeadsUp_oldWhen_whenRecent() throws Exception { + public void testShouldHeadsUp_oldWhen_whenRecent() { ensureStateForHeadsUpWhenAwake(); NotificationEntry entry = createNotification(IMPORTANCE_HIGH); @@ -472,7 +493,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { @Test @DisableFlags(Flags.FLAG_SORT_SECTION_BY_TIME) - public void testShouldHeadsUp_oldWhen_whenZero() throws Exception { + public void testShouldHeadsUp_oldWhen_whenZero() { ensureStateForHeadsUpWhenAwake(); NotificationEntry entry = createNotification(IMPORTANCE_HIGH); @@ -486,7 +507,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldHeadsUp_oldWhen_whenNegative() throws Exception { + public void testShouldHeadsUp_oldWhen_whenNegative() { ensureStateForHeadsUpWhenAwake(); NotificationEntry entry = createNotification(IMPORTANCE_HIGH); @@ -499,7 +520,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldHeadsUp_oldWhen_hasFullScreenIntent() throws Exception { + public void testShouldHeadsUp_oldWhen_hasFullScreenIntent() { ensureStateForHeadsUpWhenAwake(); long when = makeWhenHoursAgo(25); @@ -514,7 +535,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldHeadsUp_oldWhen_isForegroundService() throws Exception { + public void testShouldHeadsUp_oldWhen_isForegroundService() { ensureStateForHeadsUpWhenAwake(); long when = makeWhenHoursAgo(25); @@ -529,7 +550,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldNotHeadsUp_oldWhen() throws Exception { + public void testShouldNotHeadsUp_oldWhen() { ensureStateForHeadsUpWhenAwake(); long when = makeWhenHoursAgo(25); @@ -543,7 +564,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldNotFullScreen_notPendingIntent() throws RemoteException { + public void testShouldNotFullScreen_notPendingIntent() { NotificationEntry entry = createNotification(IMPORTANCE_HIGH); when(mPowerManager.isInteractive()).thenReturn(true); when(mStatusBarStateController.isDreaming()).thenReturn(false); @@ -559,7 +580,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldNotFullScreen_suppressedOnlyByDND() throws RemoteException { + public void testShouldNotFullScreen_suppressedOnlyByDND() { NotificationEntry entry = createFsiNotification(IMPORTANCE_HIGH, /* silenced */ false); modifyRanking(entry) .setSuppressedVisualEffects(SUPPRESSED_EFFECT_FULL_SCREEN_INTENT) @@ -578,7 +599,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldNotFullScreen_suppressedByDNDAndOther() throws RemoteException { + public void testShouldNotFullScreen_suppressedByDNDAndOther() { NotificationEntry entry = createFsiNotification(IMPORTANCE_LOW, /* silenced */ false); modifyRanking(entry) .setSuppressedVisualEffects(SUPPRESSED_EFFECT_FULL_SCREEN_INTENT) @@ -597,7 +618,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldNotFullScreen_notHighImportance() throws RemoteException { + public void testShouldNotFullScreen_notHighImportance() { NotificationEntry entry = createFsiNotification(IMPORTANCE_DEFAULT, /* silenced */ false); when(mPowerManager.isInteractive()).thenReturn(true); when(mStatusBarStateController.isDreaming()).thenReturn(false); @@ -613,7 +634,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldNotFullScreen_isGroupAlertSilenced() throws RemoteException { + public void testShouldNotFullScreen_isGroupAlertSilenced() { NotificationEntry entry = createFsiNotification(IMPORTANCE_HIGH, /* silenced */ true); when(mPowerManager.isInteractive()).thenReturn(false); when(mStatusBarStateController.isDreaming()).thenReturn(true); @@ -664,7 +685,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldFullScreen_notInteractive() throws RemoteException { + public void testShouldFullScreen_notInteractive() { NotificationEntry entry = createFsiNotification(IMPORTANCE_HIGH, /* silenced */ false); Notification.BubbleMetadata bubbleMetadata = new Notification.BubbleMetadata.Builder("foo") .setSuppressNotification(false).build(); @@ -683,7 +704,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldFullScreen_isDreaming() throws RemoteException { + public void testShouldFullScreen_isDreaming() { NotificationEntry entry = createFsiNotification(IMPORTANCE_HIGH, /* silenced */ false); when(mPowerManager.isInteractive()).thenReturn(true); when(mStatusBarStateController.isDreaming()).thenReturn(true); @@ -699,7 +720,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldFullScreen_onKeyguard() throws RemoteException { + public void testShouldFullScreen_onKeyguard() { NotificationEntry entry = createFsiNotification(IMPORTANCE_HIGH, /* silenced */ false); when(mPowerManager.isInteractive()).thenReturn(true); when(mStatusBarStateController.isDreaming()).thenReturn(false); @@ -734,7 +755,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldNotFullScreen_willHun() throws RemoteException { + public void testShouldNotFullScreen_willHun() { NotificationEntry entry = createFsiNotification(IMPORTANCE_HIGH, /* silenced */ false); when(mPowerManager.isInteractive()).thenReturn(true); when(mPowerManager.isScreenOn()).thenReturn(true); @@ -751,7 +772,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldNotFullScreen_snoozed_occluding() throws Exception { + public void testShouldNotFullScreen_snoozed_occluding() { NotificationEntry entry = createFsiNotification(IMPORTANCE_HIGH, /* silenced */ false); when(mPowerManager.isInteractive()).thenReturn(true); when(mPowerManager.isScreenOn()).thenReturn(true); @@ -771,7 +792,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldHeadsUp_snoozed_occluding() throws Exception { + public void testShouldHeadsUp_snoozed_occluding() { NotificationEntry entry = createFsiNotification(IMPORTANCE_HIGH, /* silenced */ false); when(mPowerManager.isInteractive()).thenReturn(true); when(mPowerManager.isScreenOn()).thenReturn(true); @@ -795,7 +816,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldNotFullScreen_snoozed_lockedShade() throws Exception { + public void testShouldNotFullScreen_snoozed_lockedShade() { NotificationEntry entry = createFsiNotification(IMPORTANCE_HIGH, /* silenced */ false); when(mPowerManager.isInteractive()).thenReturn(true); when(mPowerManager.isScreenOn()).thenReturn(true); @@ -815,7 +836,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldHeadsUp_snoozed_lockedShade() throws Exception { + public void testShouldHeadsUp_snoozed_lockedShade() { NotificationEntry entry = createFsiNotification(IMPORTANCE_HIGH, /* silenced */ false); when(mPowerManager.isInteractive()).thenReturn(true); when(mPowerManager.isScreenOn()).thenReturn(true); @@ -839,7 +860,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldNotFullScreen_snoozed_unlocked() throws Exception { + public void testShouldNotFullScreen_snoozed_unlocked() { NotificationEntry entry = createFsiNotification(IMPORTANCE_HIGH, /* silenced */ false); when(mPowerManager.isInteractive()).thenReturn(true); when(mPowerManager.isScreenOn()).thenReturn(true); @@ -859,7 +880,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldNotScreen_appSuspended() throws RemoteException { + public void testShouldNotScreen_appSuspended() { NotificationEntry entry = createFsiNotification(IMPORTANCE_HIGH, /* silenced */ false); when(mPowerManager.isInteractive()).thenReturn(false); when(mStatusBarStateController.isDreaming()).thenReturn(false); @@ -902,7 +923,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase { } @Test - public void testShouldHeadsUp_snoozed_unlocked() throws Exception { + public void testShouldHeadsUp_snoozed_unlocked() { NotificationEntry entry = createFsiNotification(IMPORTANCE_HIGH, /* silenced */ false); when(mPowerManager.isInteractive()).thenReturn(true); when(mPowerManager.isScreenOn()).thenReturn(true); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderWrapperTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderWrapperTest.kt index a6177e8feb1b..6c7a95fc7fd0 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderWrapperTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderWrapperTest.kt @@ -27,6 +27,7 @@ import com.android.systemui.statusbar.notification.interruption.NotificationInte import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider.FullScreenIntentDecision.NO_FSI_SUPPRESSED_ONLY_BY_DND import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProviderWrapper.DecisionImpl import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProviderWrapper.FullScreenIntentDecisionImpl +import java.util.Optional import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue @@ -55,7 +56,8 @@ class NotificationInterruptStateProviderWrapperTest : VisualInterruptionDecision deviceProvisionedController, systemClock, globalSettings, - eventLog + eventLog, + Optional.of(bubbles) ) ) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderImplTest.kt index eeb51a684d42..7903a731c1d0 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderImplTest.kt @@ -28,6 +28,7 @@ import com.android.systemui.statusbar.notification.collection.NotificationEntry import com.android.systemui.statusbar.notification.interruption.VisualInterruptionType.BUBBLE import com.android.systemui.statusbar.notification.interruption.VisualInterruptionType.PEEK import com.android.systemui.statusbar.notification.interruption.VisualInterruptionType.PULSE +import java.util.Optional import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mockito.anyString @@ -56,7 +57,8 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro userTracker, avalancheProvider, systemSettings, - packageManager + packageManager, + Optional.of(bubbles) ) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderTestBase.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderTestBase.kt index 71e7dc522e20..a45740502012 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderTestBase.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderTestBase.kt @@ -75,8 +75,6 @@ import com.android.systemui.statusbar.notification.interruption.NotificationInte import com.android.systemui.statusbar.policy.FakeDeviceProvisionedController import com.android.systemui.statusbar.policy.HeadsUpManager import com.android.systemui.util.FakeEventLog -import com.android.systemui.util.mockito.any -import com.android.systemui.util.mockito.mock import com.android.systemui.util.settings.FakeGlobalSettings import com.android.systemui.util.settings.FakeSettings import com.android.systemui.util.settings.SystemSettings @@ -85,12 +83,15 @@ import com.android.systemui.utils.leaks.FakeBatteryController import com.android.systemui.utils.leaks.FakeKeyguardStateController import com.android.systemui.utils.leaks.LeakCheckedTest import com.android.systemui.utils.os.FakeHandler +import com.android.wm.shell.bubbles.Bubbles import junit.framework.Assert.assertFalse import junit.framework.Assert.assertTrue import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Test -import org.mockito.Mockito.`when` as whenever +import org.mockito.kotlin.any +import org.mockito.kotlin.mock +import org.mockito.kotlin.whenever abstract class VisualInterruptionDecisionProviderTestBase : SysuiTestCase() { private val fakeLogBuffer = @@ -129,6 +130,7 @@ abstract class VisualInterruptionDecisionProviderTestBase : SysuiTestCase() { protected val uiEventLogger = UiEventLoggerFake() protected val userTracker = FakeUserTracker() protected val avalancheProvider: AvalancheProvider = mock() + protected val bubbles: Bubbles = mock() lateinit var systemSettings: SystemSettings protected val packageManager: PackageManager = mock() @@ -159,6 +161,7 @@ abstract class VisualInterruptionDecisionProviderTestBase : SysuiTestCase() { deviceProvisionedController.currentUser = userId userTracker.set(listOf(user), /* currentUserIndex = */ 0) systemSettings = FakeSettings() + whenever(bubbles.canShowBubbleNotification()).thenReturn(true) provider.start() } @@ -208,6 +211,14 @@ abstract class VisualInterruptionDecisionProviderTestBase : SysuiTestCase() { } @Test + fun testShouldPeek_bubblesCannotShowNotification() { + whenever(bubbles.canShowBubbleNotification()).thenReturn(false) + ensurePeekState { statusBarState = SHADE } + assertShouldHeadsUp(buildPeekEntry { isBubble = true }) + assertNoEventsLogged() + } + + @Test fun testShouldPeek_isBubble_shadeLocked() { ensurePeekState { statusBarState = SHADE_LOCKED } assertShouldHeadsUp(buildPeekEntry { isBubble = true }) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderTestUtil.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderTestUtil.kt index 61c008b55ad0..01e638b0ab17 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderTestUtil.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderTestUtil.kt @@ -32,6 +32,8 @@ import com.android.systemui.util.EventLog import com.android.systemui.util.settings.GlobalSettings import com.android.systemui.util.settings.SystemSettings import com.android.systemui.util.time.SystemClock +import com.android.wm.shell.bubbles.Bubbles +import java.util.Optional object VisualInterruptionDecisionProviderTestUtil { fun createProviderByFlag( @@ -55,6 +57,7 @@ object VisualInterruptionDecisionProviderTestUtil { avalancheProvider: AvalancheProvider, systemSettings: SystemSettings, packageManager: PackageManager, + bubbles: Optional<Bubbles>, ): VisualInterruptionDecisionProvider { return if (VisualInterruptionRefactor.isEnabled) { VisualInterruptionDecisionProviderImpl( @@ -75,7 +78,8 @@ object VisualInterruptionDecisionProviderTestUtil { userTracker, avalancheProvider, systemSettings, - packageManager + packageManager, + bubbles ) } else { NotificationInterruptStateProviderWrapper( @@ -95,7 +99,8 @@ object VisualInterruptionDecisionProviderTestUtil { deviceProvisionedController, systemClock, globalSettings, - eventLog + eventLog, + bubbles ) ) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java index cde241bbe918..62804ed1412e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java @@ -172,7 +172,6 @@ import com.android.systemui.statusbar.notification.init.NotificationsController; import com.android.systemui.statusbar.notification.interruption.AvalancheProvider; import com.android.systemui.statusbar.notification.interruption.KeyguardNotificationVisibilityProvider; import com.android.systemui.statusbar.notification.interruption.NotificationInterruptLogger; -import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProviderImpl; import com.android.systemui.statusbar.notification.interruption.VisualInterruptionDecisionLogger; import com.android.systemui.statusbar.notification.interruption.VisualInterruptionDecisionProvider; import com.android.systemui.statusbar.notification.interruption.VisualInterruptionDecisionProviderTestUtil; @@ -189,7 +188,6 @@ import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.statusbar.policy.UserInfoControllerImpl; import com.android.systemui.statusbar.window.StatusBarWindowController; import com.android.systemui.statusbar.window.StatusBarWindowStateController; -import com.android.systemui.util.EventLog; import com.android.systemui.util.FakeEventLog; import com.android.systemui.util.WallpaperController; import com.android.systemui.util.concurrency.FakeExecutor; @@ -197,10 +195,8 @@ import com.android.systemui.util.concurrency.MessageRouterImpl; import com.android.systemui.util.kotlin.JavaAdapter; import com.android.systemui.util.settings.FakeGlobalSettings; import com.android.systemui.util.settings.FakeSettings; -import com.android.systemui.util.settings.GlobalSettings; import com.android.systemui.util.settings.SystemSettings; import com.android.systemui.util.time.FakeSystemClock; -import com.android.systemui.util.time.SystemClock; import com.android.systemui.volume.VolumeComponent; import com.android.wm.shell.bubbles.Bubbles; import com.android.wm.shell.startingsurface.StartingSurface; @@ -374,6 +370,8 @@ public class CentralSurfacesImplTest extends SysuiTestCase { mFakeGlobalSettings.putInt(HEADS_UP_NOTIFICATIONS_ENABLED, HEADS_UP_ON); + when(mBubbles.canShowBubbleNotification()).thenReturn(true); + mVisualInterruptionDecisionProvider = VisualInterruptionDecisionProviderTestUtil.INSTANCE.createProviderByFlag( mAmbientDisplayConfiguration, @@ -395,7 +393,8 @@ public class CentralSurfacesImplTest extends SysuiTestCase { mUserTracker, mAvalancheProvider, mSystemSettings, - mPackageManager); + mPackageManager, + Optional.of(mBubbles)); mVisualInterruptionDecisionProvider.start(); mContext.addMockSystemService(TrustManager.class, mock(TrustManager.class)); @@ -1418,46 +1417,4 @@ public class CentralSurfacesImplTest extends SysuiTestCase { verify(mStatusBarStateController).addCallback(callbackCaptor.capture(), anyInt()); callbackCaptor.getValue().onDozingChanged(isDozing); } - - public static class TestableNotificationInterruptStateProviderImpl extends - NotificationInterruptStateProviderImpl { - - TestableNotificationInterruptStateProviderImpl( - PowerManager powerManager, - AmbientDisplayConfiguration ambientDisplayConfiguration, - StatusBarStateController controller, - KeyguardStateController keyguardStateController, - BatteryController batteryController, - HeadsUpManager headsUpManager, - NotificationInterruptLogger logger, - Handler mainHandler, - NotifPipelineFlags flags, - KeyguardNotificationVisibilityProvider keyguardNotificationVisibilityProvider, - UiEventLogger uiEventLogger, - UserTracker userTracker, - DeviceProvisionedController deviceProvisionedController, - SystemClock systemClock, - GlobalSettings globalSettings, - EventLog eventLog) { - super( - powerManager, - ambientDisplayConfiguration, - batteryController, - controller, - keyguardStateController, - headsUpManager, - logger, - mainHandler, - flags, - keyguardNotificationVisibilityProvider, - uiEventLogger, - userTracker, - deviceProvisionedController, - systemClock, - globalSettings, - eventLog - ); - mUseHeadsUp = true; - } - } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java b/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java index daea7b94ac4f..3e65bfa8684b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java @@ -468,7 +468,8 @@ public class BubblesTest extends SysuiTestCase { mock(UserTracker.class), mock(AvalancheProvider.class), mock(SystemSettings.class), - mock(PackageManager.class) + mock(PackageManager.class), + Optional.of(mock(Bubbles.class)) ); interruptionDecisionProvider.start(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/wmshell/TestableNotificationInterruptStateProviderImpl.java b/packages/SystemUI/tests/src/com/android/systemui/wmshell/TestableNotificationInterruptStateProviderImpl.java deleted file mode 100644 index c9964c233d44..000000000000 --- a/packages/SystemUI/tests/src/com/android/systemui/wmshell/TestableNotificationInterruptStateProviderImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.wmshell; - -import android.hardware.display.AmbientDisplayConfiguration; -import android.os.Handler; -import android.os.PowerManager; - -import com.android.internal.logging.UiEventLogger; -import com.android.systemui.plugins.statusbar.StatusBarStateController; -import com.android.systemui.settings.UserTracker; -import com.android.systemui.statusbar.notification.NotifPipelineFlags; -import com.android.systemui.statusbar.notification.interruption.KeyguardNotificationVisibilityProvider; -import com.android.systemui.statusbar.notification.interruption.NotificationInterruptLogger; -import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProviderImpl; -import com.android.systemui.statusbar.policy.BatteryController; -import com.android.systemui.statusbar.policy.DeviceProvisionedController; -import com.android.systemui.statusbar.policy.HeadsUpManager; -import com.android.systemui.statusbar.policy.KeyguardStateController; -import com.android.systemui.util.EventLog; -import com.android.systemui.util.settings.GlobalSettings; -import com.android.systemui.util.time.SystemClock; - -public class TestableNotificationInterruptStateProviderImpl - extends NotificationInterruptStateProviderImpl { - - TestableNotificationInterruptStateProviderImpl( - PowerManager powerManager, - AmbientDisplayConfiguration ambientDisplayConfiguration, - StatusBarStateController statusBarStateController, - KeyguardStateController keyguardStateController, - BatteryController batteryController, - HeadsUpManager headsUpManager, - NotificationInterruptLogger logger, - Handler mainHandler, - NotifPipelineFlags flags, - KeyguardNotificationVisibilityProvider keyguardNotificationVisibilityProvider, - UiEventLogger uiEventLogger, - UserTracker userTracker, - DeviceProvisionedController deviceProvisionedController, - SystemClock systemClock, - GlobalSettings globalSettings, - EventLog eventLog) { - super( - powerManager, - ambientDisplayConfiguration, - batteryController, - statusBarStateController, - keyguardStateController, - headsUpManager, - logger, - mainHandler, - flags, - keyguardNotificationVisibilityProvider, - uiEventLogger, - userTracker, - deviceProvisionedController, - systemClock, - globalSettings, - eventLog); - mUseHeadsUp = true; - } -} |