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

Commit 2dced4c7 authored by Umashankar Godachi's avatar Umashankar Godachi Committed by Linux Build Service Account
Browse files

Fix available/remaining PIN/PUK attempts.

* Fix to properly display attempts remaining for PIN/PUK.
* On bootup show the available PIN/PUK attempts if sim
is locked on PIN/PUK.
* Show incorrect password message on entering wrong PIN/PUK
password.

Cherry-picked from commits
2c68d443
b2194e67
d85e7560
3830fd69499b60615771122a9ffbada3d80da931
c35875ec0e5e83e7116784615bffcd84cb12429b

Change-Id: I9e46b7ff646bf68f73a75b2b0015085be6c4c7ec
parent e9b142f8
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -363,4 +363,20 @@
    <!-- Fingerprint hint message when finger was not recognized.-->
    <string name="fingerprint_not_recognized">Not recognized</string>

    <!-- Instructions telling the user remaining times when enter SIM PIN view.  -->
    <plurals name="kg_password_default_pin_message">
        <item quantity="one">Enter SIM PIN, you have <xliff:g id="number">%d</xliff:g> remaining
attempt before you must contact your carrier to unlock your device.</item>
        <item quantity="other">Enter SIM PIN, you have <xliff:g id="number">%d</xliff:g> remaining
attempts.</item>
    </plurals>

    <!-- Instructions telling the user remaining times when enter SIM PUK view.  -->
    <plurals name="kg_password_default_puk_message">
        <item quantity="one">SIM is now disabled. Enter PUK code to continue. You have <xliff:g id="
number">%d</xliff:g> remaining attempt before SIM becomes permanently unusable. Contact carrier for details.</item>
        <item quantity="other">SIM is now disabled. Enter PUK code to continue. You have <xliff:g id="
number">%d</xliff:g> remaining attempts before SIM becomes permanently unusable. Contact carrier for details.</item>
    </plurals>

</resources>
+66 −28
Original line number Diff line number Diff line
@@ -50,7 +50,8 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {

    private ProgressDialog mSimUnlockProgressDialog = null;
    private CheckSimPin mCheckSimPinThread;

    private boolean mShowDefaultMessage = true;
    private int mRemainingAttempts = -1;
    private AlertDialog mRemainingAttemptsDialog;
    private int mSubId;
    private ImageView mSimImageView;
@@ -75,25 +76,8 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
    public void resetState() {
        super.resetState();
        if (DEBUG) Log.v(TAG, "Resetting state");
        KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
        mSubId = monitor.getNextSubIdForState(IccCardConstants.State.PIN_REQUIRED);
        if (SubscriptionManager.isValidSubscriptionId(mSubId)) {
            int count = TelephonyManager.getDefault().getSimCount();
            Resources rez = getResources();
            final String msg;
            int color = Color.WHITE;
            if (count < 2) {
                msg = rez.getString(R.string.kg_sim_pin_instructions);
            } else {
                SubscriptionInfo info = monitor.getSubscriptionInfoForSubId(mSubId);
                CharSequence displayName = info != null ? info.getDisplayName() : ""; // don't crash
                msg = rez.getString(R.string.kg_sim_pin_instructions_multi, displayName);
                if (info != null) {
                    color = info.getIconTint();
                }
            }
            mSecurityMessageDisplay.setMessage(msg, true);
            mSimImageView.setImageTintList(ColorStateList.valueOf(color));
        if (mShowDefaultMessage) {
            showDefaultMessage();
        }
    }

@@ -109,17 +93,19 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
        return 0;
    }

    private String getPinPasswordErrorMessage(int attemptsRemaining) {
    private String getPinPasswordErrorMessage(int attemptsRemaining, boolean isDefault) {
        String displayMessage;

        int msgId;
        if (attemptsRemaining == 0) {
            displayMessage = getContext().getString(R.string.kg_password_wrong_pin_code_pukked);
        } else if (attemptsRemaining > 0) {
            msgId = isDefault ? R.plurals.kg_password_default_pin_message :
                     R.plurals.kg_password_wrong_pin_code;
            displayMessage = getContext().getResources()
                    .getQuantityString(R.plurals.kg_password_wrong_pin_code, attemptsRemaining,
                            attemptsRemaining);
                    .getQuantityString(msgId, attemptsRemaining, attemptsRemaining);
        } else {
            displayMessage = getContext().getString(R.string.kg_password_pin_failed);
            msgId = isDefault ? R.string.kg_sim_pin_instructions : R.string.kg_password_pin_failed;
            displayMessage = getContext().getString(msgId);
        }
        if (DEBUG) Log.d(LOG_TAG, "getPinPasswordErrorMessage:"
                + " attemptsRemaining=" + attemptsRemaining + " displayMessage=" + displayMessage);
@@ -151,6 +137,9 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (mShowDefaultMessage) {
            showDefaultMessage();
        }
        KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback);
    }

@@ -231,7 +220,7 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
    }

    private Dialog getSimRemainingAttemptsDialog(int remaining) {
        String msg = getPinPasswordErrorMessage(remaining);
        String msg = getPinPasswordErrorMessage(remaining, false);
        if (mRemainingAttemptsDialog == null) {
            Builder builder = new AlertDialog.Builder(mContext);
            builder.setMessage(msg);
@@ -267,6 +256,7 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
                    post(new Runnable() {
                        @Override
                        public void run() {
                            mRemainingAttempts = attemptsRemaining;
                            if (mSimUnlockProgressDialog != null) {
                                mSimUnlockProgressDialog.hide();
                            }
@@ -275,8 +265,13 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
                            if (result == PhoneConstants.PIN_RESULT_SUCCESS) {
                                KeyguardUpdateMonitor.getInstance(getContext())
                                        .reportSimUnlocked(mSubId);
                                mRemainingAttempts = -1;
                                mShowDefaultMessage = true;
                                if (mCallback != null) {
                                    mCallback.dismiss(true);
                                }
                            } else {
                                mShowDefaultMessage = false;
                                if (result == PhoneConstants.PIN_PASSWORD_INCORRECT) {
                                    if (attemptsRemaining <= 2) {
                                        // this is getting critical - show dialog
@@ -284,7 +279,8 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
                                    } else {
                                        // show message
                                        mSecurityMessageDisplay.setMessage(
                                                getPinPasswordErrorMessage(attemptsRemaining), true);
                                                getPinPasswordErrorMessage(
                                                attemptsRemaining, false), true);
                                    }
                                } else {
                                    // "PIN operation failed!" - no idea what this was and no way to
@@ -315,5 +311,47 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
    public boolean startDisappearAnimation(Runnable finishRunnable) {
        return false;
    }

    private void showDefaultMessage() {
        KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
        mSubId = monitor.getNextSubIdForState(IccCardConstants.State.PIN_REQUIRED);
        if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
            return;
        }
        if (mRemainingAttempts >= 0) {
            mSecurityMessageDisplay.setMessage(getPinPasswordErrorMessage(
                    mRemainingAttempts, true), true);
            return;
        }

        int count = TelephonyManager.getDefault().getSimCount();
        Resources rez = getResources();
        final String msg;
        int color = Color.WHITE;
        if (count < 2) {
            msg = rez.getString(R.string.kg_sim_pin_instructions);
        } else {
            SubscriptionInfo info = monitor.getSubscriptionInfoForSubId(mSubId);
            CharSequence displayName = info != null ? info.getDisplayName() : ""; // don't crash
            msg = rez.getString(R.string.kg_sim_pin_instructions_multi, displayName);
            if (info != null) {
                color = info.getIconTint();
            }
        }
        mSecurityMessageDisplay.setMessage(msg, true);
        mSimImageView.setImageTintList(ColorStateList.valueOf(color));

        new CheckSimPin("", mSubId) {
            void onSimCheckResponse(final int result, final int attemptsRemaining) {
                Log.d(LOG_TAG, "onSimCheckResponse " + " dummy One result" + result +
                        " attemptsRemaining=" + attemptsRemaining);
                if (attemptsRemaining >= 0) {
                    mRemainingAttempts = attemptsRemaining;
                    mSecurityMessageDisplay.setMessage(
                            getPinPasswordErrorMessage(attemptsRemaining, true), true);
                }
            }
        }.start();
    }
}
+68 −26
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {

    private ProgressDialog mSimUnlockProgressDialog = null;
    private CheckSimPuk mCheckSimPukThread;
    private boolean mShowDefaultMessage = true;
    private int mRemainingAttempts = -1;
    private String mPukText;
    private String mPinText;
    private StateMachine mStateMachine = new StateMachine();
@@ -116,25 +118,8 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {
            mPinText="";
            mPukText="";
            state = ENTER_PUK;
            KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
            mSubId = monitor.getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED);
            if (SubscriptionManager.isValidSubscriptionId(mSubId)) {
                int count = TelephonyManager.getDefault().getSimCount();
                Resources rez = getResources();
                final String msg;
                int color = Color.WHITE;
                if (count < 2) {
                    msg = rez.getString(R.string.kg_puk_enter_puk_hint);
                } else {
                    SubscriptionInfo info = monitor.getSubscriptionInfoForSubId(mSubId);
                    CharSequence displayName = info != null ? info.getDisplayName() : "";
                    msg = rez.getString(R.string.kg_puk_enter_puk_hint_multi, displayName);
                    if (info != null) {
                        color = info.getIconTint();
                    }
                }
                mSecurityMessageDisplay.setMessage(msg, true);
                mSimImageView.setImageTintList(ColorStateList.valueOf(color));
            if (mShowDefaultMessage) {
                showDefaultMessage();
            }
            mPasswordEntry.requestFocus();
        }
@@ -146,17 +131,20 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {
        return 0;
    }

    private String getPukPasswordErrorMessage(int attemptsRemaining) {
    private String getPukPasswordErrorMessage(int attemptsRemaining, boolean isDefault) {
        String displayMessage;

        if (attemptsRemaining == 0) {
            displayMessage = getContext().getString(R.string.kg_password_wrong_puk_code_dead);
        } else if (attemptsRemaining > 0) {
            int msgId = isDefault ? R.plurals.kg_password_default_puk_message :
                    R.plurals.kg_password_wrong_puk_code;
            displayMessage = getContext().getResources()
                    .getQuantityString(R.plurals.kg_password_wrong_puk_code, attemptsRemaining,
                            attemptsRemaining);
                    .getQuantityString(msgId, attemptsRemaining, attemptsRemaining);
        } else {
            displayMessage = getContext().getString(R.string.kg_password_puk_failed);
            int msgId = isDefault ? R.string.kg_puk_enter_puk_hint :
                    R.string.kg_password_puk_failed;
            displayMessage = getContext().getString(msgId);
        }
        if (DEBUG) Log.d(LOG_TAG, "getPukPasswordErrorMessage:"
                + " attemptsRemaining=" + attemptsRemaining + " displayMessage=" + displayMessage);
@@ -194,6 +182,9 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {
    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (mShowDefaultMessage) {
            showDefaultMessage();
        }
        KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback);
    }

@@ -276,7 +267,7 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {
    }

    private Dialog getPukRemainingAttemptsDialog(int remaining) {
        String msg = getPukPasswordErrorMessage(remaining);
        String msg = getPukPasswordErrorMessage(remaining, false);
        if (mRemainingAttemptsDialog == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setMessage(msg);
@@ -332,16 +323,25 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {
                            if (result == PhoneConstants.PIN_RESULT_SUCCESS) {
                                KeyguardUpdateMonitor.getInstance(getContext())
                                        .reportSimUnlocked(mSubId);
                                mRemainingAttempts = -1;
                                mShowDefaultMessage = true;
                                if (mCallback != null) {
                                    mCallback.dismiss(true);
                                }
                            } else {
                                mShowDefaultMessage = false;
                                if (result == PhoneConstants.PIN_PASSWORD_INCORRECT) {
                                    // show message
                                    mSecurityMessageDisplay.setMessage(getPukPasswordErrorMessage(
                                            attemptsRemaining, false), true);
                                    if (attemptsRemaining <= 2) {
                                        // this is getting critical - show dialog
                                        getPukRemainingAttemptsDialog(attemptsRemaining).show();
                                    } else {
                                        // show message
                                        mSecurityMessageDisplay.setMessage(
                                                getPukPasswordErrorMessage(attemptsRemaining), true);
                                                getPukPasswordErrorMessage(
                                                attemptsRemaining, false), true);
                                    }
                                } else {
                                    mSecurityMessageDisplay.setMessage(getContext().getString(
@@ -375,6 +375,48 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {
    public boolean startDisappearAnimation(Runnable finishRunnable) {
        return false;
    }

    private void showDefaultMessage() {
        KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
        mSubId = monitor.getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED);
        if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
            return;
        }
        if (mRemainingAttempts >= 0) {
            mSecurityMessageDisplay.setMessage(getPukPasswordErrorMessage(
                    mRemainingAttempts, true), true);
            return;
        }

        int count = TelephonyManager.getDefault().getSimCount();
        Resources rez = getResources();
        final String msg;
        int color = Color.WHITE;
        if (count < 2) {
            msg = rez.getString(R.string.kg_puk_enter_puk_hint);
        } else {
            SubscriptionInfo info = monitor.getSubscriptionInfoForSubId(mSubId);
            CharSequence displayName = info != null ? info.getDisplayName() : "";
            msg = rez.getString(R.string.kg_puk_enter_puk_hint_multi, displayName);
            if (info != null) {
                color = info.getIconTint();
            }
        }
        mSecurityMessageDisplay.setMessage(msg, true);
        mSimImageView.setImageTintList(ColorStateList.valueOf(color));

        new CheckSimPuk("", "", mSubId) {
            void onSimLockChangedResponse(final int result, final int attemptsRemaining) {
                Log.d(LOG_TAG, "onSimCheckResponse " + " dummy One result" + result +
                        " attemptsRemaining=" + attemptsRemaining);
                if (attemptsRemaining >= 0) {
                    mRemainingAttempts = attemptsRemaining;
                    mSecurityMessageDisplay.setMessage(
                            getPukPasswordErrorMessage(attemptsRemaining, true), true);
                }
            }
        }.start();
    }
}