From ddf81fc112ff6ee25e9205ebea3dbeae93fbfcb1 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Thu, 11 Aug 2022 11:50:42 -0700 Subject: [PATCH] Fix bubbles hiding when unlocked with showOnLockscreen Activity KeyguardStateController#isOccluded was being used to determine if the device was showing the screen saver / dreams. However, this method returns true even if the device is in unlocked state. This can happen when an activity is showing that has showOnLockscreen set to true even while the device is unlocked. This CL uses DreamManager to check if the device is dreaming instead of KeyguardStateController#isOccluded which only returns true if the device is actually showing screen saver / dreams. Bug: 240510360 Test: atest BubblesTest Test: manual - open calculator and verify bubbles remain visible - start dream and verify bubbles are hidden Change-Id: I6997c17d26c2f8ccbe80a5920f9348b3ce53d754 --- .../systemui/dagger/SystemUIModule.java | 3 +++ .../systemui/wmshell/BubblesManager.java | 17 +++++++++++- .../android/systemui/wmshell/BubblesTest.java | 27 ++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java index f32ea353bf506..2dadf573fd12b 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java @@ -18,6 +18,7 @@ package com.android.systemui.dagger; import android.app.INotificationManager; import android.content.Context; +import android.service.dreams.IDreamManager; import androidx.annotation.Nullable; @@ -213,6 +214,7 @@ public abstract class SystemUIModule { ShadeController shadeController, @Nullable IStatusBarService statusBarService, INotificationManager notificationManager, + IDreamManager dreamManager, NotificationVisibilityProvider visibilityProvider, NotificationInterruptStateProvider interruptionStateProvider, ZenModeController zenModeController, @@ -230,6 +232,7 @@ public abstract class SystemUIModule { shadeController, statusBarService, notificationManager, + dreamManager, visibilityProvider, interruptionStateProvider, zenModeController, diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/BubblesManager.java b/packages/SystemUI/src/com/android/systemui/wmshell/BubblesManager.java index 4c762702892a0..aeab2dff94216 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/BubblesManager.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/BubblesManager.java @@ -38,6 +38,7 @@ import android.os.RemoteException; import android.os.ServiceManager; import android.os.UserHandle; import android.provider.Settings; +import android.service.dreams.IDreamManager; import android.service.notification.NotificationListenerService.RankingMap; import android.service.notification.ZenModeConfig; import android.util.Log; @@ -101,6 +102,7 @@ public class BubblesManager implements Dumpable { private final ShadeController mShadeController; private final IStatusBarService mBarService; private final INotificationManager mNotificationManager; + private final IDreamManager mDreamManager; private final NotificationVisibilityProvider mVisibilityProvider; private final NotificationInterruptStateProvider mNotificationInterruptStateProvider; private final NotificationLockscreenUserManager mNotifUserManager; @@ -126,6 +128,7 @@ public class BubblesManager implements Dumpable { ShadeController shadeController, @Nullable IStatusBarService statusBarService, INotificationManager notificationManager, + IDreamManager dreamManager, NotificationVisibilityProvider visibilityProvider, NotificationInterruptStateProvider interruptionStateProvider, ZenModeController zenModeController, @@ -144,6 +147,7 @@ public class BubblesManager implements Dumpable { shadeController, statusBarService, notificationManager, + dreamManager, visibilityProvider, interruptionStateProvider, zenModeController, @@ -167,6 +171,7 @@ public class BubblesManager implements Dumpable { ShadeController shadeController, @Nullable IStatusBarService statusBarService, INotificationManager notificationManager, + IDreamManager dreamManager, NotificationVisibilityProvider visibilityProvider, NotificationInterruptStateProvider interruptionStateProvider, ZenModeController zenModeController, @@ -182,6 +187,7 @@ public class BubblesManager implements Dumpable { mNotificationShadeWindowController = notificationShadeWindowController; mShadeController = shadeController; mNotificationManager = notificationManager; + mDreamManager = dreamManager; mVisibilityProvider = visibilityProvider; mNotificationInterruptStateProvider = interruptionStateProvider; mNotifUserManager = notifUserManager; @@ -203,7 +209,7 @@ public class BubblesManager implements Dumpable { @Override public void onKeyguardShowingChanged() { boolean isUnlockedShade = !keyguardStateController.isShowing() - && !keyguardStateController.isOccluded(); + && !isDreamingOrInPreview(); bubbles.onStatusBarStateChanged(isUnlockedShade); } }); @@ -397,6 +403,15 @@ public class BubblesManager implements Dumpable { mBubbles.setSysuiProxy(mSysuiProxy); } + private boolean isDreamingOrInPreview() { + try { + return mDreamManager.isDreamingOrInPreview(); + } catch (RemoteException e) { + Log.e(TAG, "Failed to query dream manager.", e); + return false; + } + } + private void setupNotifPipeline() { mNotifPipeline.addCollectionListener(new NotifCollectionListener() { @Override 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 18acf3f6ce531..8f2b715ba051b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java @@ -63,6 +63,7 @@ import android.graphics.drawable.Icon; import android.hardware.display.AmbientDisplayConfiguration; import android.os.Handler; import android.os.PowerManager; +import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; import android.service.dreams.IDreamManager; @@ -204,6 +205,8 @@ public class BubblesTest extends SysuiTestCase { private ArgumentCaptor mFilterArgumentCaptor; @Captor private ArgumentCaptor mBroadcastReceiverArgumentCaptor; + @Captor + private ArgumentCaptor mKeyguardStateControllerCallbackCaptor; private BubblesManager mBubblesManager; private TestableBubbleController mBubbleController; @@ -240,6 +243,8 @@ public class BubblesTest extends SysuiTestCase { @Mock private IStatusBarService mStatusBarService; @Mock + private IDreamManager mIDreamManager; + @Mock private NotificationVisibilityProvider mVisibilityProvider; @Mock private LauncherApps mLauncherApps; @@ -371,10 +376,11 @@ public class BubblesTest extends SysuiTestCase { mContext, mBubbleController.asBubbles(), mNotificationShadeWindowController, - mock(KeyguardStateController.class), + mKeyguardStateController, mShadeController, mStatusBarService, mock(INotificationManager.class), + mIDreamManager, mVisibilityProvider, interruptionStateProvider, mZenModeController, @@ -391,6 +397,25 @@ public class BubblesTest extends SysuiTestCase { verify(mNotifPipeline, atLeastOnce()) .addCollectionListener(mNotifListenerCaptor.capture()); mEntryListener = mNotifListenerCaptor.getValue(); + + // Get a reference to KeyguardStateController.Callback + verify(mKeyguardStateController, atLeastOnce()) + .addCallback(mKeyguardStateControllerCallbackCaptor.capture()); + } + + @Test + public void dreamingHidesBubbles() throws RemoteException { + mBubbleController.updateBubble(mBubbleEntry); + assertTrue(mBubbleController.hasBubbles()); + assertThat(mBubbleController.getStackView().getVisibility()).isEqualTo(View.VISIBLE); + + when(mIDreamManager.isDreamingOrInPreview()).thenReturn(true); // dreaming is happening + when(mKeyguardStateController.isShowing()).thenReturn(false); // device is unlocked + KeyguardStateController.Callback callback = + mKeyguardStateControllerCallbackCaptor.getValue(); + callback.onKeyguardShowingChanged(); + + assertThat(mBubbleController.getStackView().getVisibility()).isEqualTo(View.INVISIBLE); } @Test