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

Commit b54d7e2a authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Hide "swipe up to unlock" when entering Doze

"Swipe up to unlock" should only be visible when the screen is
interactive, even though it would last for 5sec otherwise.

Test: manual
Test: atest KeyguardIndicationControllerTest
Fixes: 139400542
Change-Id: If7290459a3ae28f689cf4c9e2311398e5f6bcf13
Merged-In: If7290459a3ae28f689cf4c9e2311398e5f6bcf13
parent e39c7bd2
Loading
Loading
Loading
Loading
+23 −14
Original line number Original line Diff line number Diff line
@@ -108,6 +108,7 @@ public class KeyguardIndicationController implements StateListener,
    private ColorStateList mTransientTextColorState;
    private ColorStateList mTransientTextColorState;
    private ColorStateList mInitialTextColorState;
    private ColorStateList mInitialTextColorState;
    private boolean mVisible;
    private boolean mVisible;
    private boolean mHideTransientMessageOnScreenOff;


    private boolean mPowerPluggedIn;
    private boolean mPowerPluggedIn;
    private boolean mPowerPluggedInWired;
    private boolean mPowerPluggedInWired;
@@ -317,15 +318,17 @@ public class KeyguardIndicationController implements StateListener,
     * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}.
     * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}.
     */
     */
    public void showTransientIndication(CharSequence transientIndication) {
    public void showTransientIndication(CharSequence transientIndication) {
        showTransientIndication(transientIndication, mInitialTextColorState);
        showTransientIndication(transientIndication, mInitialTextColorState,
                false /* hideOnScreenOff */);
    }
    }


    /**
    /**
     * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}.
     * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}.
     */
     */
    public void showTransientIndication(CharSequence transientIndication,
    private void showTransientIndication(CharSequence transientIndication,
            ColorStateList textColorState) {
            ColorStateList textColorState, boolean hideOnScreenOff) {
        mTransientIndication = transientIndication;
        mTransientIndication = transientIndication;
        mHideTransientMessageOnScreenOff = hideOnScreenOff && transientIndication != null;
        mTransientTextColorState = textColorState;
        mTransientTextColorState = textColorState;
        mHandler.removeMessages(MSG_HIDE_TRANSIENT);
        mHandler.removeMessages(MSG_HIDE_TRANSIENT);
        mHandler.removeMessages(MSG_SWIPE_UP_TO_UNLOCK);
        mHandler.removeMessages(MSG_SWIPE_UP_TO_UNLOCK);
@@ -344,6 +347,7 @@ public class KeyguardIndicationController implements StateListener,
    public void hideTransientIndication() {
    public void hideTransientIndication() {
        if (mTransientIndication != null) {
        if (mTransientIndication != null) {
            mTransientIndication = null;
            mTransientIndication = null;
            mHideTransientMessageOnScreenOff = false;
            mHandler.removeMessages(MSG_HIDE_TRANSIENT);
            mHandler.removeMessages(MSG_HIDE_TRANSIENT);
            updateIndication(false);
            updateIndication(false);
        }
        }
@@ -566,7 +570,8 @@ public class KeyguardIndicationController implements StateListener,
            String message = mContext.getString(R.string.keyguard_retry);
            String message = mContext.getString(R.string.keyguard_retry);
            mStatusBarKeyguardViewManager.showBouncerMessage(message, mInitialTextColorState);
            mStatusBarKeyguardViewManager.showBouncerMessage(message, mInitialTextColorState);
        } else if (mKeyguardUpdateMonitor.isScreenOn()) {
        } else if (mKeyguardUpdateMonitor.isScreenOn()) {
            showTransientIndication(mContext.getString(R.string.keyguard_unlock));
            showTransientIndication(mContext.getString(R.string.keyguard_unlock),
                    mInitialTextColorState, true /* hideOnScreenOff */);
            hideTransientIndicationDelayed(BaseKeyguardCallback.HIDE_DELAY_MS);
            hideTransientIndicationDelayed(BaseKeyguardCallback.HIDE_DELAY_MS);
        }
        }
    }
    }
@@ -576,7 +581,11 @@ public class KeyguardIndicationController implements StateListener,
            return;
            return;
        }
        }
        mDozing = dozing;
        mDozing = dozing;
        if (mHideTransientMessageOnScreenOff && mDozing) {
            hideTransientIndication();
        } else {
            updateIndication(false);
            updateIndication(false);
        }
        updateDisclosure();
        updateDisclosure();
    }
    }


@@ -646,8 +655,7 @@ public class KeyguardIndicationController implements StateListener,
        @Override
        @Override
        public void onBiometricHelp(int msgId, String helpString,
        public void onBiometricHelp(int msgId, String helpString,
                BiometricSourceType biometricSourceType) {
                BiometricSourceType biometricSourceType) {
            KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
            if (!mKeyguardUpdateMonitor.isUnlockingWithBiometricAllowed()) {
            if (!updateMonitor.isUnlockingWithBiometricAllowed()) {
                return;
                return;
            }
            }
            boolean showSwipeToUnlock =
            boolean showSwipeToUnlock =
@@ -655,8 +663,8 @@ public class KeyguardIndicationController implements StateListener,
            if (mStatusBarKeyguardViewManager.isBouncerShowing()) {
            if (mStatusBarKeyguardViewManager.isBouncerShowing()) {
                mStatusBarKeyguardViewManager.showBouncerMessage(helpString,
                mStatusBarKeyguardViewManager.showBouncerMessage(helpString,
                        mInitialTextColorState);
                        mInitialTextColorState);
            } else if (updateMonitor.isScreenOn()) {
            } else if (mKeyguardUpdateMonitor.isScreenOn()) {
                showTransientIndication(helpString);
                showTransientIndication(helpString, mInitialTextColorState, showSwipeToUnlock);
                if (!showSwipeToUnlock) {
                if (!showSwipeToUnlock) {
                    hideTransientIndicationDelayed(TRANSIENT_BIOMETRIC_ERROR_TIMEOUT);
                    hideTransientIndicationDelayed(TRANSIENT_BIOMETRIC_ERROR_TIMEOUT);
                }
                }
@@ -670,8 +678,7 @@ public class KeyguardIndicationController implements StateListener,
        @Override
        @Override
        public void onBiometricError(int msgId, String errString,
        public void onBiometricError(int msgId, String errString,
                BiometricSourceType biometricSourceType) {
                BiometricSourceType biometricSourceType) {
            KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
            if (shouldSuppressBiometricError(msgId, biometricSourceType, mKeyguardUpdateMonitor)) {
            if (shouldSuppressBiometricError(msgId, biometricSourceType, updateMonitor)) {
                return;
                return;
            }
            }
            animatePadlockError();
            animatePadlockError();
@@ -681,7 +688,7 @@ public class KeyguardIndicationController implements StateListener,
                showSwipeUpToUnlock();
                showSwipeUpToUnlock();
            } else if (mStatusBarKeyguardViewManager.isBouncerShowing()) {
            } else if (mStatusBarKeyguardViewManager.isBouncerShowing()) {
                mStatusBarKeyguardViewManager.showBouncerMessage(errString, mInitialTextColorState);
                mStatusBarKeyguardViewManager.showBouncerMessage(errString, mInitialTextColorState);
            } else if (updateMonitor.isScreenOn()) {
            } else if (mKeyguardUpdateMonitor.isScreenOn()) {
                showTransientIndication(errString);
                showTransientIndication(errString);
                // We want to keep this message around in case the screen was off
                // We want to keep this message around in case the screen was off
                hideTransientIndicationDelayed(HIDE_DELAY_MS);
                hideTransientIndicationDelayed(HIDE_DELAY_MS);
@@ -721,13 +728,15 @@ public class KeyguardIndicationController implements StateListener,


        @Override
        @Override
        public void onTrustAgentErrorMessage(CharSequence message) {
        public void onTrustAgentErrorMessage(CharSequence message) {
            showTransientIndication(message, Utils.getColorError(mContext));
            showTransientIndication(message, Utils.getColorError(mContext),
                    false /* hideOnScreenOff */);
        }
        }


        @Override
        @Override
        public void onScreenTurnedOn() {
        public void onScreenTurnedOn() {
            if (mMessageToShowOnScreenOn != null) {
            if (mMessageToShowOnScreenOn != null) {
                showTransientIndication(mMessageToShowOnScreenOn, Utils.getColorError(mContext));
                showTransientIndication(mMessageToShowOnScreenOn, Utils.getColorError(mContext),
                        false /* hideOnScreenOff */);
                // We want to keep this message around in case the screen was off
                // We want to keep this message around in case the screen was off
                hideTransientIndicationDelayed(HIDE_DELAY_MS);
                hideTransientIndicationDelayed(HIDE_DELAY_MS);
                mMessageToShowOnScreenOn = null;
                mMessageToShowOnScreenOn = null;
+56 −0
Original line number Original line Diff line number Diff line
@@ -35,8 +35,11 @@ import android.app.admin.DevicePolicyManager;
import android.app.trust.TrustManager;
import android.app.trust.TrustManager;
import android.content.Context;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Color;
import android.hardware.biometrics.BiometricSourceType;
import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Looper;
import android.os.Looper;
import android.os.UserManager;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup;


@@ -53,6 +56,7 @@ import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.phone.KeyguardIndicationTextView;
import com.android.systemui.statusbar.phone.KeyguardIndicationTextView;
import com.android.systemui.statusbar.phone.LockIcon;
import com.android.systemui.statusbar.phone.LockIcon;
import com.android.systemui.statusbar.phone.ShadeController;
import com.android.systemui.statusbar.phone.ShadeController;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.statusbar.phone.UnlockMethodCache;
import com.android.systemui.statusbar.phone.UnlockMethodCache;
import com.android.systemui.statusbar.policy.AccessibilityController;
import com.android.systemui.statusbar.policy.AccessibilityController;
import com.android.systemui.util.wakelock.WakeLockFake;
import com.android.systemui.util.wakelock.WakeLockFake;
@@ -92,6 +96,10 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
    private StatusBarStateController mStatusBarStateController;
    private StatusBarStateController mStatusBarStateController;
    @Mock
    @Mock
    private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
    private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
    @Mock
    private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
    @Mock
    private UserManager mUserManager;
    private KeyguardIndicationTextView mTextView;
    private KeyguardIndicationTextView mTextView;


    private KeyguardIndicationController mController;
    private KeyguardIndicationController mController;
@@ -105,14 +113,18 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
        mTextView = new KeyguardIndicationTextView(mContext);
        mTextView = new KeyguardIndicationTextView(mContext);


        mContext.addMockSystemService(Context.DEVICE_POLICY_SERVICE, mDevicePolicyManager);
        mContext.addMockSystemService(Context.DEVICE_POLICY_SERVICE, mDevicePolicyManager);
        mContext.addMockSystemService(UserManager.class, mUserManager);
        mContext.addMockSystemService(Context.TRUST_SERVICE, mock(TrustManager.class));
        mContext.addMockSystemService(Context.TRUST_SERVICE, mock(TrustManager.class));
        mContext.addMockSystemService(Context.FINGERPRINT_SERVICE, mock(FingerprintManager.class));
        mContext.addMockSystemService(Context.FINGERPRINT_SERVICE, mock(FingerprintManager.class));
        mDisclosureWithOrganization = mContext.getString(R.string.do_disclosure_with_name,
        mDisclosureWithOrganization = mContext.getString(R.string.do_disclosure_with_name,
                ORGANIZATION_NAME);
                ORGANIZATION_NAME);


        when(mKeyguardUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true);
        when(mKeyguardUpdateMonitor.isScreenOn()).thenReturn(true);
        when(mIndicationArea.findViewById(R.id.keyguard_indication_enterprise_disclosure))
        when(mIndicationArea.findViewById(R.id.keyguard_indication_enterprise_disclosure))
                .thenReturn(mDisclosure);
                .thenReturn(mDisclosure);
        when(mIndicationArea.findViewById(R.id.keyguard_indication_text)).thenReturn(mTextView);
        when(mIndicationArea.findViewById(R.id.keyguard_indication_text)).thenReturn(mTextView);
        when(mUserManager.isUserUnlocked(anyInt())).thenReturn(true);


        mWakeLock = new WakeLockFake();
        mWakeLock = new WakeLockFake();
    }
    }
@@ -124,6 +136,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
        mController = new KeyguardIndicationController(mContext, mIndicationArea, mLockIcon,
        mController = new KeyguardIndicationController(mContext, mIndicationArea, mLockIcon,
                mLockPatternUtils, mWakeLock, mShadeController, mAccessibilityController,
                mLockPatternUtils, mWakeLock, mShadeController, mAccessibilityController,
                mUnlockMethodCache, mStatusBarStateController, mKeyguardUpdateMonitor);
                mUnlockMethodCache, mStatusBarStateController, mKeyguardUpdateMonitor);
        mController.setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager);
    }
    }


    @Test
    @Test
@@ -244,6 +257,49 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
        assertThat(mTextView.getAlpha()).isEqualTo(1f);
        assertThat(mTextView.getAlpha()).isEqualTo(1f);
    }
    }


    @Test
    public void transientIndication_visibleWhenDozing_unlessSwipeUp_fromHelp() {
        createController();
        String message = "A message";

        mController.setVisible(true);
        mController.getKeyguardCallback().onBiometricHelp(
                KeyguardUpdateMonitor.BIOMETRIC_HELP_FACE_NOT_RECOGNIZED, message,
                BiometricSourceType.FACE);
        assertThat(mTextView.getText()).isEqualTo(message);
        mController.setDozing(true);

        assertThat(mTextView.getText()).isNotEqualTo(message);
    }

    @Test
    public void transientIndication_visibleWhenDozing_unlessSwipeUp_fromError() {
        createController();
        String message = mContext.getString(R.string.keyguard_unlock);

        mController.setVisible(true);
        mController.getKeyguardCallback().onBiometricError(FaceManager.FACE_ERROR_TIMEOUT,
                "A message", BiometricSourceType.FACE);

        assertThat(mTextView.getText()).isEqualTo(message);
        mController.setDozing(true);

        assertThat(mTextView.getText()).isNotEqualTo(message);
    }

    @Test
    public void transientIndication_swipeUpToRetry() {
        createController();
        String message = mContext.getString(R.string.keyguard_retry);
        when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true);

        mController.setVisible(true);
        mController.getKeyguardCallback().onBiometricError(FaceManager.FACE_ERROR_TIMEOUT,
                "A message", BiometricSourceType.FACE);

        verify(mStatusBarKeyguardViewManager).showBouncerMessage(eq(message), any());
    }

    @Test
    @Test
    public void lockIcon_click() {
    public void lockIcon_click() {
        createController();
        createController();