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

Commit bfb9382e authored by brycelee's avatar brycelee
Browse files

Do not reset keyguard state from delay while dreaming.

This changelist makes sure that the delayed keyguard lock after dreaming
does not lead to the keyguard reseting its state. Doing so will cause
the notification shade to collapse. This can lead to the UI disappearing
and dismiss logic dependent on shade collapse not working properly.

Fixes: 413573405
Test: atest KeyguardViewMediatorTestKt#doKeyguardTimeout_dreaming_keyguardNotReset
Flag: EXEMPT bugfix
Change-Id: I18c7a9df2fd049d2943bc76b0db93e59c9c44035
parent 4d4c030d
Loading
Loading
Loading
Loading
+24 −10
Original line number Diff line number Diff line
@@ -2439,10 +2439,14 @@ public class KeyguardViewMediator implements CoreStartable,
        }
    }

    private void doKeyguardLocked(Bundle options) {
        doKeyguardLocked(options, true /* resetState */);
    }

    /**
     * Enable the keyguard if the settings are appropriate.
     */
    private void doKeyguardLocked(Bundle options) {
    private void doKeyguardLocked(Bundle options, boolean resetState) {
        // If the power button behavior requests to open the glanceable hub.
        if (options != null && options.getBoolean(EXTRA_TRIGGER_HUB)) {
            if (mCommunalSettingsInteractor.get().getAutoOpenEnabled().getValue()) {
@@ -2505,7 +2509,9 @@ public class KeyguardViewMediator implements CoreStartable,
                                    + "already showing, we're interactive, we were not "
                                    + "previously hiding. It should be safe to short-circuit "
                                    + "here.");
                    if (resetState) {
                        resetStateLocked(/* hideBouncer= */ false);
                    }
                    notifyLockNowCallback();
                    return;
                }
@@ -2715,14 +2721,8 @@ public class KeyguardViewMediator implements CoreStartable,
        @Override
        public void onReceive(Context context, Intent intent) {
            if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
                final int sequence = intent.getIntExtra("seq", 0);
                if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
                        + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
                synchronized (KeyguardViewMediator.this) {
                    if (mDelayedShowingSequence == sequence) {
                        doKeyguardLocked(null);
                    }
                }
                doDelayedKeyguardAction(intent.getIntExtra("seq", 0));

            } else if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) {
                final int sequence = intent.getIntExtra("seq", 0);
                int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, 0);
@@ -2737,6 +2737,20 @@ public class KeyguardViewMediator implements CoreStartable,
        }
    };

    @VisibleForTesting
    void doDelayedKeyguardAction(int sequence) {
        if (DEBUG) {
            Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
                    + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
        }

        synchronized (KeyguardViewMediator.this) {
            if (mDelayedShowingSequence == sequence) {
                doKeyguardLocked(null, !mUpdateMonitor.isDreaming());
            }
        }
    }

    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
+16 −3
Original line number Diff line number Diff line
@@ -38,8 +38,8 @@ import android.view.WindowManager
import androidx.test.filters.SmallTest
import com.android.internal.logging.uiEventLogger
import com.android.internal.widget.lockPatternUtils
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.keyguard.keyguardUnlockAnimationController
import com.android.keyguard.keyguardUpdateMonitor
import com.android.keyguard.mediator.ScreenOnCoordinator
import com.android.keyguard.trustManager
import com.android.systemui.Flags.FLAG_KEYGUARD_WM_STATE_REFACTOR
@@ -106,6 +106,7 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.doReturn
@@ -151,7 +152,7 @@ class KeyguardViewMediatorTestKt : SysuiTestCase() {
                broadcastDispatcher,
                { statusBarKeyguardViewManager },
                dismissCallbackRegistry,
                mock<KeyguardUpdateMonitor>(),
                keyguardUpdateMonitor,
                dumpManager,
                fakeExecutor,
                powerManager,
@@ -243,6 +244,18 @@ class KeyguardViewMediatorTestKt : SysuiTestCase() {
            assertThat(communalSceneRepository.currentScene.value).isEqualTo(CommunalScenes.Blank)
        }

    @Test
    fun doKeyguardTimeout_dreaming_keyguardNotReset() =
        kosmos.runTest {
            underTest.setShowingLocked(true, "")
            whenever(powerManager.isInteractive()).thenReturn(true)
            whenever(keyguardStateController.isShowing()).thenReturn(true)
            whenever(keyguardUpdateMonitor.isDreaming).thenReturn(true)
            underTest.doDelayedKeyguardAction(0)
            testableLooper.processAllMessages()
            verify(statusBarKeyguardViewManager, never()).reset(anyBoolean())
        }

    @Test
    fun doKeyguardTimeout_hubConditionNotActive_sleeps() =
        kosmos.runTest {