From bd04e7d58f2df2ae6bc2b9c80f3f2230d2374079 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Thu, 24 Mar 2022 18:44:59 +0000 Subject: [PATCH] Use KeyguardStateController to listen for unlocked shade state Using keyguard state controller allows us to check the occlusion state and hide / show based on that as well. Test: manual - have screensaver turn on and ensure bubbles are hidden Test: atest BubblesTest NewNotifPipelineBubblesTest Bug: 223913857 Change-Id: I29992ed76c7cdd4e99b4920849c143f6520f9c42 --- .../wm/shell/bubbles/BubbleController.java | 3 +- .../systemui/dagger/SystemUIModule.java | 42 +++++++++++++------ .../systemui/wmshell/BubblesManager.java | 41 +++++++++++------- .../android/systemui/wmshell/BubblesTest.java | 20 ++++++++- .../wmshell/NewNotifPipelineBubblesTest.java | 20 ++++++++- 5 files changed, 97 insertions(+), 29 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 d2a1c55d1c29c..80afdee2283ab 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 @@ -530,7 +530,8 @@ public class BubbleController { } } - private void onStatusBarStateChanged(boolean isShade) { + @VisibleForTesting + public void onStatusBarStateChanged(boolean isShade) { mIsStatusBarShade = isShade; if (!mIsStatusBarShade) { collapseStack(); diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java index 59fcf87c5029a..7b65f453815c6 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java @@ -45,7 +45,6 @@ import com.android.systemui.lowlightclock.LowLightClockController; import com.android.systemui.model.SysUiState; import com.android.systemui.navigationbar.NavigationBarComponent; import com.android.systemui.plugins.BcSmartspaceDataPlugin; -import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.recents.Recents; import com.android.systemui.screenshot.dagger.ScreenshotModule; import com.android.systemui.settings.dagger.SettingsModule; @@ -72,6 +71,7 @@ import com.android.systemui.statusbar.phone.ShadeController; import com.android.systemui.statusbar.phone.dagger.CentralSurfacesComponent; import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.statusbar.policy.HeadsUpManager; +import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.statusbar.policy.ZenModeController; import com.android.systemui.statusbar.policy.dagger.SmartRepliesInflationModule; import com.android.systemui.statusbar.policy.dagger.StatusBarPolicyModule; @@ -198,25 +198,43 @@ public abstract class SystemUIModule { static Optional provideBubblesManager(Context context, Optional bubblesOptional, NotificationShadeWindowController notificationShadeWindowController, - StatusBarStateController statusBarStateController, ShadeController shadeController, + KeyguardStateController keyguardStateController, + ShadeController shadeController, ConfigurationController configurationController, @Nullable IStatusBarService statusBarService, INotificationManager notificationManager, NotificationVisibilityProvider visibilityProvider, NotificationInterruptStateProvider interruptionStateProvider, - ZenModeController zenModeController, NotificationLockscreenUserManager notifUserManager, - NotificationGroupManagerLegacy groupManager, NotificationEntryManager entryManager, + ZenModeController zenModeController, + NotificationLockscreenUserManager notifUserManager, + NotificationGroupManagerLegacy groupManager, + NotificationEntryManager entryManager, CommonNotifCollection notifCollection, - NotifPipeline notifPipeline, SysUiState sysUiState, - NotifPipelineFlags notifPipelineFlags, DumpManager dumpManager, + NotifPipeline notifPipeline, + SysUiState sysUiState, + NotifPipelineFlags notifPipelineFlags, + DumpManager dumpManager, @Main Executor sysuiMainExecutor) { - return Optional.ofNullable(BubblesManager.create(context, bubblesOptional, - notificationShadeWindowController, statusBarStateController, shadeController, - configurationController, statusBarService, notificationManager, + return Optional.ofNullable(BubblesManager.create(context, + bubblesOptional, + notificationShadeWindowController, + keyguardStateController, + shadeController, + configurationController, + statusBarService, + notificationManager, visibilityProvider, - interruptionStateProvider, zenModeController, notifUserManager, - groupManager, entryManager, notifCollection, notifPipeline, sysUiState, - notifPipelineFlags, dumpManager, sysuiMainExecutor)); + interruptionStateProvider, + zenModeController, + notifUserManager, + groupManager, + entryManager, + notifCollection, + notifPipeline, + sysUiState, + notifPipelineFlags, + dumpManager, + sysuiMainExecutor)); } @BindsOptionalOf diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/BubblesManager.java b/packages/SystemUI/src/com/android/systemui/wmshell/BubblesManager.java index 8a961942123bc..4d34aa38b3cd1 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/BubblesManager.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/BubblesManager.java @@ -28,7 +28,6 @@ import static android.service.notification.NotificationListenerService.REASON_GR import static android.service.notification.NotificationStats.DISMISSAL_BUBBLE; import static android.service.notification.NotificationStats.DISMISS_SENTIMENT_NEUTRAL; -import static com.android.systemui.statusbar.StatusBarState.SHADE; import static com.android.systemui.statusbar.notification.NotificationEntryManager.UNDEFINED_DISMISS_REASON; import static com.android.wm.shell.bubbles.BubbleDebugConfig.TAG_BUBBLES; import static com.android.wm.shell.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME; @@ -61,7 +60,6 @@ import com.android.systemui.Dumpable; import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dump.DumpManager; import com.android.systemui.model.SysUiState; -import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.shared.system.QuickStepContract; import com.android.systemui.statusbar.NotificationLockscreenUserManager; import com.android.systemui.statusbar.NotificationShadeWindowController; @@ -81,6 +79,7 @@ import com.android.systemui.statusbar.notification.collection.render.Notificatio import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider; import com.android.systemui.statusbar.phone.ShadeController; import com.android.systemui.statusbar.policy.ConfigurationController; +import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.statusbar.policy.ZenModeController; import com.android.wm.shell.bubbles.Bubble; import com.android.wm.shell.bubbles.BubbleEntry; @@ -132,7 +131,7 @@ public class BubblesManager implements Dumpable { public static BubblesManager create(Context context, Optional bubblesOptional, NotificationShadeWindowController notificationShadeWindowController, - StatusBarStateController statusBarStateController, + KeyguardStateController keyguardStateController, ShadeController shadeController, ConfigurationController configurationController, @Nullable IStatusBarService statusBarService, @@ -150,13 +149,26 @@ public class BubblesManager implements Dumpable { DumpManager dumpManager, Executor sysuiMainExecutor) { if (bubblesOptional.isPresent()) { - return new BubblesManager(context, bubblesOptional.get(), - notificationShadeWindowController, statusBarStateController, shadeController, - configurationController, statusBarService, notificationManager, + return new BubblesManager(context, + bubblesOptional.get(), + notificationShadeWindowController, + keyguardStateController, + shadeController, + configurationController, + statusBarService, + notificationManager, visibilityProvider, - interruptionStateProvider, zenModeController, notifUserManager, - groupManager, entryManager, notifCollection, notifPipeline, sysUiState, - notifPipelineFlags, dumpManager, sysuiMainExecutor); + interruptionStateProvider, + zenModeController, + notifUserManager, + groupManager, + entryManager, + notifCollection, + notifPipeline, + sysUiState, + notifPipelineFlags, + dumpManager, + sysuiMainExecutor); } else { return null; } @@ -166,7 +178,7 @@ public class BubblesManager implements Dumpable { BubblesManager(Context context, Bubbles bubbles, NotificationShadeWindowController notificationShadeWindowController, - StatusBarStateController statusBarStateController, + KeyguardStateController keyguardStateController, ShadeController shadeController, ConfigurationController configurationController, @Nullable IStatusBarService statusBarService, @@ -210,11 +222,12 @@ public class BubblesManager implements Dumpable { dumpManager.registerDumpable(TAG, this); - statusBarStateController.addCallback(new StatusBarStateController.StateListener() { + keyguardStateController.addCallback(new KeyguardStateController.Callback() { @Override - public void onStateChanged(int newState) { - boolean isShade = newState == SHADE; - bubbles.onStatusBarStateChanged(isShade); + public void onKeyguardShowingChanged() { + boolean isUnlockedShade = !keyguardStateController.isShowing() + && !keyguardStateController.isOccluded(); + bubbles.onStatusBarStateChanged(isUnlockedShade); } }); 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 78ee9e8921ea2..ca67bd2d6fcae 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java @@ -70,6 +70,7 @@ import android.service.notification.NotificationListenerService; import android.service.notification.ZenModeConfig; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; +import android.view.View; import android.view.WindowManager; import androidx.test.filters.SmallTest; @@ -377,7 +378,7 @@ public class BubblesTest extends SysuiTestCase { mContext, mBubbleController.asBubbles(), mNotificationShadeWindowController, - mStatusBarStateController, + mock(KeyguardStateController.class), mShadeController, mConfigurationController, mStatusBarService, @@ -1427,6 +1428,23 @@ public class BubblesTest extends SysuiTestCase { assertStackCollapsed(); } + @Test + public void testOnStatusBarStateChanged() { + mBubbleController.updateBubble(mBubbleEntry); + mBubbleData.setExpanded(true); + assertStackExpanded(); + BubbleStackView stackView = mBubbleController.getStackView(); + assertThat(stackView.getVisibility()).isEqualTo(View.VISIBLE); + + mBubbleController.onStatusBarStateChanged(false); + + assertStackCollapsed(); + assertThat(stackView.getVisibility()).isEqualTo(View.INVISIBLE); + + mBubbleController.onStatusBarStateChanged(true); + assertThat(stackView.getVisibility()).isEqualTo(View.VISIBLE); + } + /** Creates a bubble using the userId and package. */ private Bubble createBubble(int userId, String pkg) { final UserHandle userHandle = new UserHandle(userId); diff --git a/packages/SystemUI/tests/src/com/android/systemui/wmshell/NewNotifPipelineBubblesTest.java b/packages/SystemUI/tests/src/com/android/systemui/wmshell/NewNotifPipelineBubblesTest.java index fafe4b3fdb5f3..40657fb614124 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wmshell/NewNotifPipelineBubblesTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/wmshell/NewNotifPipelineBubblesTest.java @@ -59,6 +59,7 @@ import android.service.notification.NotificationListenerService; import android.service.notification.ZenModeConfig; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; +import android.view.View; import android.view.WindowManager; import androidx.test.filters.SmallTest; @@ -342,7 +343,7 @@ public class NewNotifPipelineBubblesTest extends SysuiTestCase { mContext, mBubbleController.asBubbles(), mNotificationShadeWindowController, - mStatusBarStateController, + mock(KeyguardStateController.class), mShadeController, mConfigurationController, mStatusBarService, @@ -1247,6 +1248,23 @@ public class NewNotifPipelineBubblesTest extends SysuiTestCase { assertStackCollapsed(); } + @Test + public void testOnStatusBarStateChanged() { + mBubbleController.updateBubble(mBubbleEntry); + mBubbleData.setExpanded(true); + assertStackExpanded(); + BubbleStackView stackView = mBubbleController.getStackView(); + assertThat(stackView.getVisibility()).isEqualTo(View.VISIBLE); + + mBubbleController.onStatusBarStateChanged(false); + + assertStackCollapsed(); + assertThat(stackView.getVisibility()).isEqualTo(View.INVISIBLE); + + mBubbleController.onStatusBarStateChanged(true); + assertThat(stackView.getVisibility()).isEqualTo(View.VISIBLE); + } + /** * Sets the bubble metadata flags for this entry. These flags are normally set by * NotificationManagerService when the notification is sent, however, these tests do not