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

Commit b68c24b6 authored by Bryce Lee's avatar Bryce Lee Committed by Automerger Merge Worker
Browse files

Merge "Check for non-interactive dreams when wake and unlocking." into udc-dev...

Merge "Check for non-interactive dreams when wake and unlocking." into udc-dev am: dcfa4882 am: 36cfce40

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24248316



Change-Id: I6bd512c54f0003db9eed8c2cb239a6c793b70b0d
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 1fc805cd 36cfce40
Loading
Loading
Loading
Loading
+77 −5
Original line number Original line Diff line number Diff line
@@ -100,6 +100,7 @@ import android.view.WindowManagerPolicyConstants;
import android.view.animation.Animation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.AnimationUtils;


import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.VisibleForTesting;
@@ -173,6 +174,8 @@ import com.android.wm.shell.keyguard.KeyguardTransitions;
import dagger.Lazy;
import dagger.Lazy;


import java.io.PrintWriter;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Objects;
import java.util.Objects;
@@ -257,6 +260,22 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
    private static final int SYSTEM_READY = 18;
    private static final int SYSTEM_READY = 18;
    private static final int CANCEL_KEYGUARD_EXIT_ANIM = 19;
    private static final int CANCEL_KEYGUARD_EXIT_ANIM = 19;


    /** Enum for reasons behind updating wakeAndUnlock state. */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(
            value = {
                    WakeAndUnlockUpdateReason.HIDE,
                    WakeAndUnlockUpdateReason.SHOW,
                    WakeAndUnlockUpdateReason.FULFILL,
                    WakeAndUnlockUpdateReason.WAKE_AND_UNLOCK,
            })
    @interface WakeAndUnlockUpdateReason {
        int HIDE = 0;
        int SHOW = 1;
        int FULFILL = 2;
        int WAKE_AND_UNLOCK = 3;
    }

    /**
    /**
     * The default amount of time we stay awake (used for all key input)
     * The default amount of time we stay awake (used for all key input)
     */
     */
@@ -808,7 +827,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
            // dreaming. It's time to wake up.
            // dreaming. It's time to wake up.
            if (mUnlockingAndWakingFromDream) {
            if (mUnlockingAndWakingFromDream) {
                Log.d(TAG, "waking from dream after unlock");
                Log.d(TAG, "waking from dream after unlock");
                mUnlockingAndWakingFromDream = false;
                setUnlockAndWakeFromDream(false, WakeAndUnlockUpdateReason.FULFILL);


                if (mKeyguardStateController.isShowing()) {
                if (mKeyguardStateController.isShowing()) {
                    Log.d(TAG, "keyguard showing after keyguardGone, dismiss");
                    Log.d(TAG, "keyguard showing after keyguardGone, dismiss");
@@ -2685,7 +2704,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,


            mKeyguardExitAnimationRunner = null;
            mKeyguardExitAnimationRunner = null;
            mWakeAndUnlocking = false;
            mWakeAndUnlocking = false;
            mUnlockingAndWakingFromDream = false;
            setUnlockAndWakeFromDream(false, WakeAndUnlockUpdateReason.SHOW);
            setPendingLock(false);
            setPendingLock(false);


            // Force if we we're showing in the middle of hiding, to ensure we end up in the correct
            // Force if we we're showing in the middle of hiding, to ensure we end up in the correct
@@ -2791,6 +2810,51 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
        tryKeyguardDone();
        tryKeyguardDone();
    };
    };


    private void setUnlockAndWakeFromDream(boolean updatedValue,
            @WakeAndUnlockUpdateReason int reason) {
        if (updatedValue == mUnlockingAndWakingFromDream) {
            return;
        }

        final String reasonDescription;

        switch(reason) {
            case WakeAndUnlockUpdateReason.FULFILL:
                reasonDescription = "fulfilling existing request";
                break;
            case WakeAndUnlockUpdateReason.HIDE:
                reasonDescription = "hiding keyguard";
                break;
            case WakeAndUnlockUpdateReason.SHOW:
                reasonDescription = "showing keyguard";
                break;
            case WakeAndUnlockUpdateReason.WAKE_AND_UNLOCK:
                reasonDescription = "waking to unlock";
                break;
            default:
                throw new IllegalStateException("Unexpected value: " + reason);
        }

        final boolean unsetUnfulfilled = !updatedValue
                && reason != WakeAndUnlockUpdateReason.FULFILL;

        mUnlockingAndWakingFromDream = updatedValue;

        final String description;

        if (unsetUnfulfilled) {
            description = "Interrupting request to wake and unlock";
        } else if (mUnlockingAndWakingFromDream) {
            description = "Initiating request to wake and unlock";
        } else {
            description = "Fulfilling request to wake and unlock";
        }

        Log.d(TAG, String.format(
                "Updating waking and unlocking request to %b. description:[%s]. reason:[%s]",
                mUnlockingAndWakingFromDream,  description, reasonDescription));
    }

    /**
    /**
     * Handle message sent by {@link #hideLocked()}
     * Handle message sent by {@link #hideLocked()}
     * @see #HIDE
     * @see #HIDE
@@ -2810,8 +2874,11 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,


            mHiding = true;
            mHiding = true;


            mUnlockingAndWakingFromDream = mStatusBarStateController.isDreaming()
            // If waking and unlocking, waking from dream has been set properly.
                    && !mStatusBarStateController.isDozing();
            if (!mWakeAndUnlocking) {
                setUnlockAndWakeFromDream(mStatusBarStateController.isDreaming()
                        && mPM.isInteractive(), WakeAndUnlockUpdateReason.HIDE);
            }


            if ((mShowing && !mOccluded) || mUnlockingAndWakingFromDream) {
            if ((mShowing && !mOccluded) || mUnlockingAndWakingFromDream) {
                if (mUnlockingAndWakingFromDream) {
                if (mUnlockingAndWakingFromDream) {
@@ -3313,9 +3380,14 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
        }
        }
    }
    }


    public void onWakeAndUnlocking() {
    /**
     * Informs the keyguard view mediator that the device is waking and unlocking.
     * @param fromDream Whether waking and unlocking is happening over an interactive dream.
     */
    public void onWakeAndUnlocking(boolean fromDream) {
        Trace.beginSection("KeyguardViewMediator#onWakeAndUnlocking");
        Trace.beginSection("KeyguardViewMediator#onWakeAndUnlocking");
        mWakeAndUnlocking = true;
        mWakeAndUnlocking = true;
        setUnlockAndWakeFromDream(fromDream, WakeAndUnlockUpdateReason.WAKE_AND_UNLOCK);


        mKeyguardViewControllerLazy.get().notifyKeyguardAuthenticated(/* primaryAuth */ false);
        mKeyguardViewControllerLazy.get().notifyKeyguardAuthenticated(/* primaryAuth */ false);
        userActivity();
        userActivity();
+2 −2
Original line number Original line Diff line number Diff line
@@ -471,7 +471,7 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
        };
        };


        final boolean wakingFromDream = mMode == MODE_WAKE_AND_UNLOCK_FROM_DREAM
        final boolean wakingFromDream = mMode == MODE_WAKE_AND_UNLOCK_FROM_DREAM
                && !mStatusBarStateController.isDozing();
                && mPowerManager.isInteractive();


        if (mMode != MODE_NONE && !wakingFromDream) {
        if (mMode != MODE_NONE && !wakingFromDream) {
            wakeUp.run();
            wakeUp.run();
@@ -509,7 +509,7 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
                    // later to awaken.
                    // later to awaken.
                }
                }
                mNotificationShadeWindowController.setNotificationShadeFocusable(false);
                mNotificationShadeWindowController.setNotificationShadeFocusable(false);
                mKeyguardViewMediator.onWakeAndUnlocking();
                mKeyguardViewMediator.onWakeAndUnlocking(wakingFromDream);
                Trace.endSection();
                Trace.endSection();
                break;
                break;
            case MODE_ONLY_WAKE:
            case MODE_ONLY_WAKE:
+33 −4
Original line number Original line Diff line number Diff line
@@ -275,7 +275,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
        TestableLooper.get(this).processAllMessages();
        TestableLooper.get(this).processAllMessages();


        mViewMediator.onStartedGoingToSleep(OFF_BECAUSE_OF_USER);
        mViewMediator.onStartedGoingToSleep(OFF_BECAUSE_OF_USER);
        mViewMediator.onWakeAndUnlocking();
        mViewMediator.onWakeAndUnlocking(false);
        mViewMediator.onStartedWakingUp(OFF_BECAUSE_OF_USER, false);
        mViewMediator.onStartedWakingUp(OFF_BECAUSE_OF_USER, false);
        TestableLooper.get(this).processAllMessages();
        TestableLooper.get(this).processAllMessages();


@@ -707,14 +707,14 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {


    @Test
    @Test
    public void testWakeAndUnlocking() {
    public void testWakeAndUnlocking() {
        mViewMediator.onWakeAndUnlocking();
        mViewMediator.onWakeAndUnlocking(false);
        verify(mStatusBarKeyguardViewManager).notifyKeyguardAuthenticated(anyBoolean());
        verify(mStatusBarKeyguardViewManager).notifyKeyguardAuthenticated(anyBoolean());
    }
    }


    @Test
    @Test
    public void testWakeAndUnlockingOverDream() {
    public void testWakeAndUnlockingOverDream() {
        // Send signal to wake
        // Send signal to wake
        mViewMediator.onWakeAndUnlocking();
        mViewMediator.onWakeAndUnlocking(true);


        // Ensure not woken up yet
        // Ensure not woken up yet
        verify(mPowerManager, never()).wakeUp(anyLong(), anyInt(), anyString());
        verify(mPowerManager, never()).wakeUp(anyLong(), anyInt(), anyString());
@@ -743,7 +743,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
    @Test
    @Test
    public void testWakeAndUnlockingOverDream_signalAuthenticateIfStillShowing() {
    public void testWakeAndUnlockingOverDream_signalAuthenticateIfStillShowing() {
        // Send signal to wake
        // Send signal to wake
        mViewMediator.onWakeAndUnlocking();
        mViewMediator.onWakeAndUnlocking(true);


        // Ensure not woken up yet
        // Ensure not woken up yet
        verify(mPowerManager, never()).wakeUp(anyLong(), anyInt(), anyString());
        verify(mPowerManager, never()).wakeUp(anyLong(), anyInt(), anyString());
@@ -772,6 +772,35 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
        verify(mStatusBarKeyguardViewManager).notifyKeyguardAuthenticated(anyBoolean());
        verify(mStatusBarKeyguardViewManager).notifyKeyguardAuthenticated(anyBoolean());
    }
    }


    @Test
    public void testWakeAndUnlockingOverNonInteractiveDream_noWakeByKeyguardViewMediator() {
        // Send signal to wake
        mViewMediator.onWakeAndUnlocking(false);

        // Ensure not woken up yet
        verify(mPowerManager, never()).wakeUp(anyLong(), anyInt(), anyString());

        // Verify keyguard told of authentication
        verify(mStatusBarKeyguardViewManager).notifyKeyguardAuthenticated(anyBoolean());
        mViewMediator.mViewMediatorCallback.keyguardDonePending(true,
                mUpdateMonitor.getCurrentUser());
        mViewMediator.mViewMediatorCallback.readyForKeyguardDone();
        final ArgumentCaptor<Runnable> animationRunnableCaptor =
                ArgumentCaptor.forClass(Runnable.class);
        verify(mStatusBarKeyguardViewManager).startPreHideAnimation(
                animationRunnableCaptor.capture());

        when(mStatusBarStateController.isDreaming()).thenReturn(true);
        when(mStatusBarStateController.isDozing()).thenReturn(false);
        animationRunnableCaptor.getValue().run();

        when(mKeyguardStateController.isShowing()).thenReturn(false);
        mViewMediator.mViewMediatorCallback.keyguardGone();

        // Verify not woken up.
        verify(mPowerManager, never()).wakeUp(anyLong(), anyInt(), anyString());
    }

    @Test
    @Test
    @TestableLooper.RunWithLooper(setAsMainLooper = true)
    @TestableLooper.RunWithLooper(setAsMainLooper = true)
    public void testDoKeyguardWhileInteractive_resets() {
    public void testDoKeyguardWhileInteractive_resets() {
+4 −3
Original line number Original line Diff line number Diff line
@@ -199,7 +199,7 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
        mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT,
        mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT,
                BiometricSourceType.FINGERPRINT, true /* isStrongBiometric */);
                BiometricSourceType.FINGERPRINT, true /* isStrongBiometric */);


        verify(mKeyguardViewMediator).onWakeAndUnlocking();
        verify(mKeyguardViewMediator).onWakeAndUnlocking(false);
        assertThat(mBiometricUnlockController.getMode())
        assertThat(mBiometricUnlockController.getMode())
                .isEqualTo(BiometricUnlockController.MODE_WAKE_AND_UNLOCK_PULSING);
                .isEqualTo(BiometricUnlockController.MODE_WAKE_AND_UNLOCK_PULSING);
    }
    }
@@ -217,7 +217,7 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
        mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT,
        mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT,
                BiometricSourceType.FINGERPRINT, true /* isStrongBiometric */);
                BiometricSourceType.FINGERPRINT, true /* isStrongBiometric */);


        verify(mKeyguardViewMediator).onWakeAndUnlocking();
        verify(mKeyguardViewMediator).onWakeAndUnlocking(false);
        assertThat(mBiometricUnlockController.getMode())
        assertThat(mBiometricUnlockController.getMode())
                .isEqualTo(MODE_WAKE_AND_UNLOCK);
                .isEqualTo(MODE_WAKE_AND_UNLOCK);
    }
    }
@@ -671,8 +671,9 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
        when(mWakefulnessLifecycle.getLastWakeReason())
        when(mWakefulnessLifecycle.getLastWakeReason())
                .thenReturn(PowerManager.WAKE_REASON_POWER_BUTTON);
                .thenReturn(PowerManager.WAKE_REASON_POWER_BUTTON);
        givenDreamingLocked();
        givenDreamingLocked();
        when(mPowerManager.isInteractive()).thenReturn(true);
        mBiometricUnlockController.startWakeAndUnlock(BiometricSourceType.FINGERPRINT, true);
        mBiometricUnlockController.startWakeAndUnlock(BiometricSourceType.FINGERPRINT, true);
        verify(mKeyguardViewMediator).onWakeAndUnlocking();
        verify(mKeyguardViewMediator).onWakeAndUnlocking(true);
        // Ensure that the power hasn't been told to wake up yet.
        // Ensure that the power hasn't been told to wake up yet.
        verify(mPowerManager, never()).wakeUp(anyLong(), anyInt(), anyString());
        verify(mPowerManager, never()).wakeUp(anyLong(), anyInt(), anyString());
    }
    }