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

Commit f964e793 authored by Vadim Tryshev's avatar Vadim Tryshev Committed by Android (Google) Code Review
Browse files

Merge "Preventing unnecessary switching to a user upon lockscreen dismissing."

parents f85a4974 8702ca7e
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -154,7 +154,7 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
            mCallback.reportUnlockAttempt(userId, true, 0);
            mCallback.reportUnlockAttempt(userId, true, 0);
            if (dismissKeyguard) {
            if (dismissKeyguard) {
                mDismissing = true;
                mDismissing = true;
                mCallback.dismiss(true);
                mCallback.dismiss(true, userId);
            }
            }
        } else {
        } else {
            if (isValidPassword) {
            if (isValidPassword) {
+13 −12
Original line number Original line Diff line number Diff line
@@ -88,7 +88,7 @@ public class KeyguardHostView extends FrameLayout implements SecurityCallback {
                        // the user proved presence via some other way to the trust agent.
                        // the user proved presence via some other way to the trust agent.
                        Log.i(TAG, "TrustAgent dismissed Keyguard.");
                        Log.i(TAG, "TrustAgent dismissed Keyguard.");
                    }
                    }
                    dismiss(false /* authenticated */);
                    dismiss(false /* authenticated */, userId);
                } else {
                } else {
                    mViewMediatorCallback.playTrustedSound();
                    mViewMediatorCallback.playTrustedSound();
                }
                }
@@ -177,16 +177,16 @@ public class KeyguardHostView extends FrameLayout implements SecurityCallback {


    /**
    /**
     * Dismisses the keyguard by going to the next screen or making it gone.
     * Dismisses the keyguard by going to the next screen or making it gone.
     *
     * @param targetUserId a user that needs to be the foreground user at the dismissal completion.
     * @return True if the keyguard is done.
     * @return True if the keyguard is done.
     */
     */
    public boolean dismiss() {
    public boolean dismiss(int targetUserId) {
        return dismiss(false);
        return dismiss(false, targetUserId);
    }
    }


    public boolean handleBackKey() {
    public boolean handleBackKey() {
        if (mSecurityContainer.getCurrentSecuritySelection() != SecurityMode.None) {
        if (mSecurityContainer.getCurrentSecuritySelection() != SecurityMode.None) {
            mSecurityContainer.dismiss(false);
            mSecurityContainer.dismiss(false, KeyguardUpdateMonitor.getCurrentUser());
            return true;
            return true;
        }
        }
        return false;
        return false;
@@ -207,8 +207,8 @@ public class KeyguardHostView extends FrameLayout implements SecurityCallback {
    }
    }


    @Override
    @Override
    public boolean dismiss(boolean authenticated) {
    public boolean dismiss(boolean authenticated, int targetUserId) {
        return mSecurityContainer.showNextSecurityScreenOrFinish(authenticated);
        return mSecurityContainer.showNextSecurityScreenOrFinish(authenticated, targetUserId);
    }
    }


    /**
    /**
@@ -217,9 +217,10 @@ public class KeyguardHostView extends FrameLayout implements SecurityCallback {
     *
     *
     * @param strongAuth whether the user has authenticated with strong authentication like
     * @param strongAuth whether the user has authenticated with strong authentication like
     *                   pattern, password or PIN but not by trust agents or fingerprint
     *                   pattern, password or PIN but not by trust agents or fingerprint
     * @param targetUserId a user that needs to be the foreground user at the dismissal completion.
     */
     */
    @Override
    @Override
    public void finish(boolean strongAuth) {
    public void finish(boolean strongAuth, int targetUserId) {
        // If there's a pending runnable because the user interacted with a widget
        // If there's a pending runnable because the user interacted with a widget
        // and we're leaving keyguard, then run it.
        // and we're leaving keyguard, then run it.
        boolean deferKeyguardDone = false;
        boolean deferKeyguardDone = false;
@@ -230,9 +231,9 @@ public class KeyguardHostView extends FrameLayout implements SecurityCallback {
        }
        }
        if (mViewMediatorCallback != null) {
        if (mViewMediatorCallback != null) {
            if (deferKeyguardDone) {
            if (deferKeyguardDone) {
                mViewMediatorCallback.keyguardDonePending(strongAuth);
                mViewMediatorCallback.keyguardDonePending(strongAuth, targetUserId);
            } else {
            } else {
                mViewMediatorCallback.keyguardDone(strongAuth);
                mViewMediatorCallback.keyguardDone(strongAuth, targetUserId);
            }
            }
        }
        }
    }
    }
+1 −1
Original line number Original line Diff line number Diff line
@@ -258,7 +258,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
                mCallback.reportUnlockAttempt(userId, true, 0);
                mCallback.reportUnlockAttempt(userId, true, 0);
                if (dismissKeyguard) {
                if (dismissKeyguard) {
                    mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Correct);
                    mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Correct);
                    mCallback.dismiss(true);
                    mCallback.dismiss(true, userId);
                }
                }
            } else {
            } else {
                mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Wrong);
                mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Wrong);
+2 −1
Original line number Original line Diff line number Diff line
@@ -20,8 +20,9 @@ public interface KeyguardSecurityCallback {
    /**
    /**
     * Dismiss the given security screen.
     * Dismiss the given security screen.
     * @param securityVerified true if the user correctly entered credentials for the given screen.
     * @param securityVerified true if the user correctly entered credentials for the given screen.
     * @param targetUserId a user that needs to be the foreground user at the dismissal completion.
     */
     */
    void dismiss(boolean securityVerified);
    void dismiss(boolean securityVerified, int targetUserId);


    /**
    /**
     * Manually report user activity to keep the device awake.
     * Manually report user activity to keep the device awake.
+22 −20
Original line number Original line Diff line number Diff line
@@ -51,15 +51,16 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe


    // Used to notify the container when something interesting happens.
    // Used to notify the container when something interesting happens.
    public interface SecurityCallback {
    public interface SecurityCallback {
        public boolean dismiss(boolean authenticated);
        public boolean dismiss(boolean authenticated, int targetUserId);
        public void userActivity();
        public void userActivity();
        public void onSecurityModeChanged(SecurityMode securityMode, boolean needsInput);
        public void onSecurityModeChanged(SecurityMode securityMode, boolean needsInput);


        /**
        /**
         * @param strongAuth wheher the user has authenticated with strong authentication like
         * @param strongAuth wheher the user has authenticated with strong authentication like
         *                   pattern, password or PIN but not by trust agents or fingerprint
         *                   pattern, password or PIN but not by trust agents or fingerprint
         * @param targetUserId a user that needs to be the foreground user at the finish completion.
         */
         */
        public void finish(boolean strongAuth);
        public void finish(boolean strongAuth, int targetUserId);
        public void reset();
        public void reset();
    }
    }


@@ -181,11 +182,11 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
        dialog.show();
        dialog.show();
    }
    }


    private void showTimeoutDialog(int timeoutMs) {
    private void showTimeoutDialog(int userId, int timeoutMs) {
        int timeoutInSeconds = (int) timeoutMs / 1000;
        int timeoutInSeconds = (int) timeoutMs / 1000;
        int messageId = 0;
        int messageId = 0;


        switch (mSecurityModel.getSecurityMode()) {
        switch (mSecurityModel.getSecurityMode(userId)) {
            case Pattern:
            case Pattern:
                messageId = R.string.kg_too_many_failed_pattern_attempts_dialog_message;
                messageId = R.string.kg_too_many_failed_pattern_attempts_dialog_message;
                break;
                break;
@@ -205,8 +206,7 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe


        if (messageId != 0) {
        if (messageId != 0) {
            final String message = mContext.getString(messageId,
            final String message = mContext.getString(messageId,
                    KeyguardUpdateMonitor.getInstance(mContext).getFailedUnlockAttempts(
                    KeyguardUpdateMonitor.getInstance(mContext).getFailedUnlockAttempts(userId),
                            KeyguardUpdateMonitor.getCurrentUser()),
                    timeoutInSeconds);
                    timeoutInSeconds);
            showDialog(null, message);
            showDialog(null, message);
        }
        }
@@ -289,7 +289,7 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
        monitor.reportFailedStrongAuthUnlockAttempt(userId);
        monitor.reportFailedStrongAuthUnlockAttempt(userId);
        mLockPatternUtils.reportFailedPasswordAttempt(userId);
        mLockPatternUtils.reportFailedPasswordAttempt(userId);
        if (timeoutMs > 0) {
        if (timeoutMs > 0) {
            showTimeoutDialog(timeoutMs);
            showTimeoutDialog(userId, timeoutMs);
        }
        }
    }
    }


@@ -299,7 +299,8 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
     * @param turningOff true if the device is being turned off
     * @param turningOff true if the device is being turned off
     */
     */
    void showPrimarySecurityScreen(boolean turningOff) {
    void showPrimarySecurityScreen(boolean turningOff) {
        SecurityMode securityMode = mSecurityModel.getSecurityMode();
        SecurityMode securityMode = mSecurityModel.getSecurityMode(
                KeyguardUpdateMonitor.getCurrentUser());
        if (DEBUG) Log.v(TAG, "showPrimarySecurityScreen(turningOff=" + turningOff + ")");
        if (DEBUG) Log.v(TAG, "showPrimarySecurityScreen(turningOff=" + turningOff + ")");
        showSecurityScreen(securityMode);
        showSecurityScreen(securityMode);
    }
    }
@@ -307,17 +308,18 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
    /**
    /**
     * Shows the next security screen if there is one.
     * Shows the next security screen if there is one.
     * @param authenticated true if the user entered the correct authentication
     * @param authenticated true if the user entered the correct authentication
     * @param targetUserId a user that needs to be the foreground user at the finish (if called)
     *     completion.
     * @return true if keyguard is done
     * @return true if keyguard is done
     */
     */
    boolean showNextSecurityScreenOrFinish(boolean authenticated) {
    boolean showNextSecurityScreenOrFinish(boolean authenticated, int targetUserId) {
        if (DEBUG) Log.d(TAG, "showNextSecurityScreenOrFinish(" + authenticated + ")");
        if (DEBUG) Log.d(TAG, "showNextSecurityScreenOrFinish(" + authenticated + ")");
        boolean finish = false;
        boolean finish = false;
        boolean strongAuth = false;
        boolean strongAuth = false;
        if (mUpdateMonitor.getUserCanSkipBouncer(
        if (mUpdateMonitor.getUserCanSkipBouncer(targetUserId)) {
                KeyguardUpdateMonitor.getCurrentUser())) {
            finish = true;
            finish = true;
        } else if (SecurityMode.None == mCurrentSecuritySelection) {
        } else if (SecurityMode.None == mCurrentSecuritySelection) {
            SecurityMode securityMode = mSecurityModel.getSecurityMode();
            SecurityMode securityMode = mSecurityModel.getSecurityMode(targetUserId);
            if (SecurityMode.None == securityMode) {
            if (SecurityMode.None == securityMode) {
                finish = true; // no security required
                finish = true; // no security required
            } else {
            } else {
@@ -335,7 +337,7 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
                case SimPin:
                case SimPin:
                case SimPuk:
                case SimPuk:
                    // Shortcut for SIM PIN/PUK to go to directly to user's security screen or home
                    // Shortcut for SIM PIN/PUK to go to directly to user's security screen or home
                    SecurityMode securityMode = mSecurityModel.getSecurityMode();
                    SecurityMode securityMode = mSecurityModel.getSecurityMode(targetUserId);
                    if (securityMode != SecurityMode.None
                    if (securityMode != SecurityMode.None
                            || !mLockPatternUtils.isLockScreenDisabled(
                            || !mLockPatternUtils.isLockScreenDisabled(
                            KeyguardUpdateMonitor.getCurrentUser())) {
                            KeyguardUpdateMonitor.getCurrentUser())) {
@@ -352,7 +354,7 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
            }
            }
        }
        }
        if (finish) {
        if (finish) {
            mSecurityCallback.finish(strongAuth);
            mSecurityCallback.finish(strongAuth, targetUserId);
        }
        }
        return finish;
        return finish;
    }
    }
@@ -414,8 +416,8 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
            }
            }
        }
        }


        public void dismiss(boolean authenticated) {
        public void dismiss(boolean authenticated, int targetId) {
            mSecurityCallback.dismiss(authenticated);
            mSecurityCallback.dismiss(authenticated, targetId);
        }
        }


        public boolean isVerifyUnlockOnly() {
        public boolean isVerifyUnlockOnly() {
@@ -448,7 +450,7 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
        @Override
        @Override
        public boolean isVerifyUnlockOnly() { return false; }
        public boolean isVerifyUnlockOnly() { return false; }
        @Override
        @Override
        public void dismiss(boolean securityVerified) { }
        public void dismiss(boolean securityVerified, int targetUserId) { }
        @Override
        @Override
        public void reset() {}
        public void reset() {}
    };
    };
@@ -477,7 +479,7 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
    }
    }


    public SecurityMode getSecurityMode() {
    public SecurityMode getSecurityMode() {
        return mSecurityModel.getSecurityMode();
        return mSecurityModel.getSecurityMode(KeyguardUpdateMonitor.getCurrentUser());
    }
    }


    public SecurityMode getCurrentSecurityMode() {
    public SecurityMode getCurrentSecurityMode() {
@@ -493,8 +495,8 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
        return mCurrentSecuritySelection;
        return mCurrentSecuritySelection;
    }
    }


    public void dismiss(boolean authenticated) {
    public void dismiss(boolean authenticated, int targetUserId) {
        mCallback.dismiss(authenticated);
        mCallback.dismiss(authenticated, targetUserId);
    }
    }


    public boolean needsInput() {
    public boolean needsInput() {
Loading