Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd04e7d5 authored by Mady Mellor's avatar Mady Mellor
Browse files

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
parent d9fe67ca
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -530,7 +530,8 @@ public class BubbleController {
        }
    }

    private void onStatusBarStateChanged(boolean isShade) {
    @VisibleForTesting
    public void onStatusBarStateChanged(boolean isShade) {
        mIsStatusBarShade = isShade;
        if (!mIsStatusBarShade) {
            collapseStack();
+30 −12
Original line number Diff line number Diff line
@@ -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<BubblesManager> provideBubblesManager(Context context,
            Optional<Bubbles> 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
+27 −14
Original line number Diff line number Diff line
@@ -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<Bubbles> 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);
            }
        });

+19 −1
Original line number Diff line number Diff line
@@ -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);
+19 −1
Original line number Diff line number Diff line
@@ -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