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

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

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
parent a652dac6
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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,
+16 −1
Original line number Diff line number Diff line
@@ -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
+26 −1
Original line number Diff line number Diff line
@@ -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<IntentFilter> mFilterArgumentCaptor;
    @Captor
    private ArgumentCaptor<BroadcastReceiver> mBroadcastReceiverArgumentCaptor;
    @Captor
    private ArgumentCaptor<KeyguardStateController.Callback> 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