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

Commit 55e333c5 authored by kaiyiz's avatar kaiyiz Committed by Gerrit - the friendly Code Review server
Browse files

SystemUI: Fix prompt message is wrong in pattern unlock mode issue

The value of config_max_unlock_countdown_times control whether support
countdown counts or not, should judge it before get the prompt message.
The function of countdown counts isn't complete, it doesn't support
factory data reset yet.

Judge the value of config_max_unlock_countdown_times before show the
prompt message.
Improve the factory data reset function.

CRs-Fixed: 768890

Change-Id: Id0081e7ebea7526ff02f8c730920e1efc106a24a
parent b120e568
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -161,4 +161,8 @@
    <item quantity="other" msgid="2215723361575359486">"输入 SIM PIN,您还有<xliff:g id="NUMBER">%d</xliff:g>次尝试机会。"</item>
  </plurals>
    <string name="kg_remaining_attempts">剩余次数: <xliff:g id="number">%d</xliff:g></string>
    <string name="kg_failed_pin_attempts_now_wiping">您输入了<xliff:g id="number">%d</xliff:g>次错误的PIN, 是否重启并恢复出厂设置?</string>
    <string name="kg_failed_password_attempts_now_wiping">您输入了<xliff:g id="number">%d</xliff:g>次错误的密码, 是否重启并恢复出厂设置?</string>
    <string name="kg_failed_pattern_attempts_now_wiping">您输入了<xliff:g id="number">%d</xliff:g>次错误图案, 是否重启并恢复出厂设置?</string>
    <string name="kg_failed_attempts_now_wiping_confirm">将要清除您设备上的全部用户数据并且设备恢复成出厂设置。</string>
</resources>
+15 −0
Original line number Diff line number Diff line
@@ -383,6 +383,21 @@
        This is displayed if the phone is not connected to a carrier.-->
    <string name="keyguard_carrier_default">No service.</string>
    <string name="kg_remaining_attempts">Remaining attempts: <xliff:g id="number">%d</xliff:g></string>
    <string name="kg_failed_pin_attempts_now_wiping">
        You entered the wrong PIN <xliff:g id="number">%d</xliff:g> times,
        do you want to reset your phone to factory settings?
    </string>
    <string name="kg_failed_password_attempts_now_wiping">
        You entered the wrong Password <xliff:g id="number">%d</xliff:g> times,
        do you want to reset your phone to factory settings?
    </string>
    <string name="kg_failed_pattern_attempts_now_wiping">
        You entered the wrong Pattern <xliff:g id="number">%d</xliff:g> times,
        do you want to reset your phone to factory settings?
    </string>
    <string name="kg_failed_attempts_now_wiping_confirm">
        This will erase all data from your device\'s internal storage and your device will be back to factory settings.
    </string>

    <!-- Dismiss button text in SIM pin/puk unlock view -->
    <string name="kg_dismiss">Dismiss</string>
+1 −1
Original line number Diff line number Diff line
@@ -262,7 +262,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit

    private String getWrongPasswordMessage() {
        String msg = getContext().getString(R.string.kg_wrong_pattern);
        if (getRemainingCount() >= 0) {
        if ((mMaxCountdownTimes > 0) && (getRemainingCount() >= 0)) {
            msg += " - " + getContext().getResources().getString(R.string.kg_remaining_attempts,
                    getRemainingCount());
        }
+74 −3
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@
package com.android.keyguard;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Slog;
@@ -44,6 +47,8 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe

    private final KeyguardUpdateMonitor mUpdateMonitor;

    private WipeConfirmListener mWipeConfirmListener = null;

    // Used to notify the container when something interesting happens.
    public interface SecurityCallback {
        public boolean dismiss(boolean authenticated);
@@ -218,6 +223,64 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
        showDialog(null, message);
    }

    private void showCountdownWipeDialog(int attempts) {
        int msgId = R.string.kg_failed_attempts_now_wiping;
        switch (mSecurityModel.getSecurityMode()) {
            case PIN:
                msgId = R.string.kg_failed_pin_attempts_now_wiping;
                break;
            case Password:
                msgId = R.string.kg_failed_password_attempts_now_wiping;
                break;
            case Pattern:
                msgId = R.string.kg_failed_pattern_attempts_now_wiping;
                break;
        }
        if (mWipeConfirmListener == null) {
            mWipeConfirmListener = new WipeConfirmListener();
        }
        final AlertDialog dialog = new AlertDialog.Builder(mContext)
            .setMessage(mContext.getString(msgId, attempts))
            .setNegativeButton(com.android.internal.R.string.gpsVerifYes,// reuse public Yes/No
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            showWipeConfirmDialog();
                        }
                    })
            .setPositiveButton(com.android.internal.R.string.gpsVerifNo, mWipeConfirmListener)
            .setCancelable(false)
            .create();
        if (!(mContext instanceof Activity)) {
            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
        }
        dialog.show();
    }

    private void showWipeConfirmDialog() {
        final AlertDialog dialog = new AlertDialog.Builder(mContext)
            .setMessage(R.string.kg_failed_attempts_now_wiping_confirm)
            .setNegativeButton(com.android.internal.R.string.gpsVerifYes, mWipeConfirmListener)
            .setPositiveButton(com.android.internal.R.string.gpsVerifNo, mWipeConfirmListener)
            .setCancelable(false)
            .create();
        if (!(mContext instanceof Activity)) {
            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
        }
        dialog.show();
    }

    private class WipeConfirmListener implements DialogInterface.OnClickListener {
        public void onClick(DialogInterface dialog, int which) {
            if (DialogInterface.BUTTON_POSITIVE == which) {
                KeyguardUpdateMonitor.getInstance(mContext).clearFailedUnlockAttempts();
            } else {
                if (ActivityManager.isUserAMonkey()) return;
                Intent wipeIntent = new Intent("android.intent.action.MASTER_CLEAR");
                mContext.sendBroadcast(wipeIntent);
            }
        }
    }

    private void showAlmostAtAccountLoginDialog() {
        final int timeoutInSeconds = (int) LockPatternUtils.FAILED_ATTEMPT_TIMEOUT_MS / 1000;
        final int count = LockPatternUtils.FAILED_ATTEMPTS_BEFORE_RESET
@@ -235,6 +298,12 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe

        SecurityMode mode = mSecurityModel.getSecurityMode();
        final boolean usingPattern = mode == KeyguardSecurityModel.SecurityMode.Pattern;
        final boolean usingPIN = mode == KeyguardSecurityModel.SecurityMode.PIN;
        final boolean usingPassword = mode == KeyguardSecurityModel.SecurityMode.Password;
        final int maxCountdownTimes = mContext.getResources()
                .getInteger(R.integer.config_max_unlock_countdown_times);
        final boolean enableTimesCounter = maxCountdownTimes > 0 && (usingPattern || usingPIN
                || usingPassword);

        final int failedAttemptsBeforeWipe = mLockPatternUtils.getDevicePolicyManager()
                .getMaximumFailedPasswordsForWipe(null, mLockPatternUtils.getCurrentUser());
@@ -247,7 +316,9 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
                : Integer.MAX_VALUE; // because DPM returns 0 if no restriction

        boolean showTimeout = false;
        if (remainingBeforeWipe < LockPatternUtils.FAILED_ATTEMPTS_BEFORE_WIPE_GRACE) {
        if (enableTimesCounter && (failedAttempts >= maxCountdownTimes)) {
            showCountdownWipeDialog(failedAttempts);
        } else if (remainingBeforeWipe < LockPatternUtils.FAILED_ATTEMPTS_BEFORE_WIPE_GRACE) {
            // The user has installed a DevicePolicyManager that requests a user/profile to be wiped
            // N attempts. Once we get below the grace period, we post this dialog every time as a
            // clear warning until the deletion fires.
@@ -263,8 +334,8 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe
                showWipeDialog(failedAttempts);
            }
        } else {
            showTimeout =
                (failedAttempts % LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT) == 0;
            showTimeout = !enableTimesCounter &&
                ((failedAttempts % LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT) == 0);
            if (usingPattern && mEnableFallback) {
                if (failedAttempts == failedAttemptWarning) {
                    showAlmostAtAccountLoginDialog();