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

Commit cbec7357 authored by kaiyiz's avatar kaiyiz
Browse files

Keyguard: Show PIN/PUK remaining times by default

As the original design, unless you input a wrong password, it will not
prompt the PIN/PUK remaining times. We should prompt it by default,
so that the users can enter the password more carefully.

When the keyguard SIM PIN/PUK view is attached to the window or it
resets input state, we will show PIN/PUK remaining times. And we will
get the remaining times in another thread.

CRs-Fixed: 628782

Change-Id: I5d932a647c2d268a79c7cb2418d541a676978418
parent 4ce17650
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -154,4 +154,13 @@
    <string name="keyguard_transport_play_description" msgid="2924628863741150956">"“播放”按钮"</string>
    <string name="keyguard_transport_stop_description" msgid="3084179324810575787">"“停止”按钮"</string>
    <string name="keyguard_carrier_default" msgid="8700650403054042153">"无服务。"</string>

  <plurals name="kg_password_default_pin_message">
    <item quantity="one" msgid="8134313997799638254">"输入 SIM PIN,您还有<xliff:g id="NUMBER">%d</xliff:g>次尝试机会。如果仍然失败,则必须联系运营商帮您解锁设备。"</item>
    <item quantity="other" msgid="2215723361575359486">"输入 SIM PIN,您还有<xliff:g id="NUMBER">%d</xliff:g>次尝试机会。"</item>
  </plurals>
  <plurals name="kg_password_default_puk_message">
    <item quantity="one" msgid="3256893607561060649">"SIM 卡已被停用,需要输入 PUK 码才能继续使用。您还有<xliff:g id="NUMBER">%d</xliff:g>次尝试机会。如果仍然失败,SIM 卡将永远无法使用。有关详情,请联系您的运营商。"</item>
    <item quantity="other" msgid="5477305226026342036">"SIM 卡已被停用,需要输入 PUK 码才能继续使用。您还有<xliff:g id="NUMBER">%d</xliff:g>次尝试机会。如果仍然失败,SIM 卡将永远无法使用。有关详情,请联系您的运营商。"</item>
  </plurals>
</resources>
+11 −0
Original line number Diff line number Diff line
@@ -407,4 +407,15 @@

    <!-- Carrier text used in Multi SIM enabled view -->
    <string name="msim_carrier_text_format"><xliff:g id="text_1">%s</xliff:g>, <xliff:g id="text_2">%s</xliff:g></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>
+46 −5
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ public class KeyguardSimPinView extends KeyguardAbsKeyInputView
    protected ProgressDialog mSimUnlockProgressDialog = null;
    private CheckSimPin mCheckSimPinThread;
    protected boolean mShowDefaultMessage = true;
    protected int mRemainingAttempts = -1;
    protected AlertDialog mRemainingAttemptsDialog;
    public KeyguardSimPinView(Context context) {
        this(context, null);
@@ -76,7 +77,7 @@ public class KeyguardSimPinView extends KeyguardAbsKeyInputView

    public void resetState() {
        if (mShowDefaultMessage) {
            mSecurityMessageDisplay.setMessage(R.string.kg_sim_pin_instructions, true);
            showDefaultMessage();
        }
        mPasswordEntry.setEnabled(true);
    }
@@ -98,6 +99,21 @@ public class KeyguardSimPinView extends KeyguardAbsKeyInputView
        return displayMessage;
    }

    protected String getPinDefaultMessage(int attemptsRemaining) {
        String displayMessage = getContext().getString(R.string.kg_sim_pin_instructions);

        if (attemptsRemaining == 0) {
            displayMessage = getContext().getString(R.string.kg_password_wrong_pin_code_pukked);
        } else if (attemptsRemaining > 0) {
            displayMessage = getContext().getResources()
                    .getQuantityString(R.plurals.kg_password_default_pin_message,
                    attemptsRemaining, attemptsRemaining);
        }
        if (DEBUG) Log.d(LOG_TAG, "getPinDefaultMessage:"
                + " attemptsRemaining=" + attemptsRemaining
                + " displayMessage=" + displayMessage);
        return displayMessage;
    }

    @Override
    protected boolean shouldLockout(long deadline) {
@@ -161,6 +177,14 @@ public class KeyguardSimPinView extends KeyguardAbsKeyInputView
    public void showUsabilityHint() {
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (mShowDefaultMessage) {
            showDefaultMessage();
        }
    }

    @Override
    public void onPause() {
        // dismiss the dialog.
@@ -265,14 +289,14 @@ public class KeyguardSimPinView extends KeyguardAbsKeyInputView
                                mCallback.dismiss(true);
                            } else {
                                mShowDefaultMessage = false;
                                mRemainingAttempts = attemptsRemaining;
                                if (result == PhoneConstants.PIN_PASSWORD_INCORRECT) {
                                    if (attemptsRemaining <= 2) {
                                        // this is getting critical - show dialog
                                        getSimRemainingAttemptsDialog(attemptsRemaining).show();
                                    } else {
                                    // show message
                                    mSecurityMessageDisplay.setMessage(
                                            getPinPasswordErrorMessage(attemptsRemaining), true);
                                    if (attemptsRemaining <= 2) {
                                        // this is getting critical - show dialog
                                        getSimRemainingAttemptsDialog(attemptsRemaining).show();
                                    }
                                } else {
                                    // "PIN operation failed!" - no idea what this was and no way to
@@ -294,5 +318,22 @@ public class KeyguardSimPinView extends KeyguardAbsKeyInputView
            mCheckSimPinThread.start();
        }
    }

    protected void showDefaultMessage() {
        if (mRemainingAttempts >= 0) {
            mSecurityMessageDisplay.setMessage(
                    getPinDefaultMessage(mRemainingAttempts), true);
            return;
        }
        new CheckSimPin("") {
            void onSimCheckResponse(final int result, final int attemptsRemaining) {
                 if (attemptsRemaining >= 0) {
                    mRemainingAttempts = attemptsRemaining;
                    mSecurityMessageDisplay.setMessage(
                            getPinDefaultMessage(attemptsRemaining), true);
                }
            }
        }.start();
    }
}
+50 −5
Original line number Diff line number Diff line
@@ -55,6 +55,8 @@ public class KeyguardSimPukView extends KeyguardAbsKeyInputView
    protected String mPinText;
    protected StateMachine mStateMachine = new StateMachine();
    protected AlertDialog mRemainingAttemptsDialog;
    protected boolean mShowDefaultMessage = true;
    protected int mRemainingAttempts = -1;

    protected class StateMachine {
        final int ENTER_PUK = 0;
@@ -99,7 +101,9 @@ public class KeyguardSimPukView extends KeyguardAbsKeyInputView
            mPinText="";
            mPukText="";
            state = ENTER_PUK;
            mSecurityMessageDisplay.setMessage(R.string.kg_puk_enter_puk_hint, true);
            if (mShowDefaultMessage) {
                showDefaultMessage();
            }
            mPasswordEntry.requestFocus();
        }
    }
@@ -121,6 +125,21 @@ public class KeyguardSimPukView extends KeyguardAbsKeyInputView
        return displayMessage;
    }

    protected String getPukDefaultMessage(int attemptsRemaining) {
        String displayMessage = getContext().getString(R.string.kg_puk_enter_puk_hint);

        if (attemptsRemaining == 0) {
            displayMessage = getContext().getString(R.string.kg_password_wrong_puk_code_dead);
        } else if (attemptsRemaining > 0) {
            displayMessage = getContext().getResources()
                    .getQuantityString(R.plurals.kg_password_default_puk_message,
                    attemptsRemaining, attemptsRemaining);
        }
        if (DEBUG) Log.d(LOG_TAG, "getPukDefaultMessage:" + " attemptsRemaining=" +
                attemptsRemaining + " displayMessage=" + displayMessage);
        return displayMessage;
    }

    public KeyguardSimPukView(Context context) {
        this(context, null);
    }
@@ -192,6 +211,14 @@ public class KeyguardSimPukView extends KeyguardAbsKeyInputView
        mSecurityMessageDisplay.setTimeout(0); // don't show ownerinfo/charging status by default
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (mShowDefaultMessage) {
            showDefaultMessage();
        }
    }

    @Override
    public void showUsabilityHint() {
    }
@@ -312,14 +339,15 @@ public class KeyguardSimPukView extends KeyguardAbsKeyInputView
                                KeyguardUpdateMonitor.getInstance(getContext()).reportSimUnlocked();
                                mCallback.dismiss(true);
                            } else {
                                mShowDefaultMessage = false;
                                mRemainingAttempts = attemptsRemaining;
                                if (result == PhoneConstants.PIN_PASSWORD_INCORRECT) {
                                    if (attemptsRemaining <= 2) {
                                        // this is getting critical - show dialog
                                        getPukRemainingAttemptsDialog(attemptsRemaining).show();
                                    } else {
                                    // show message
                                    mSecurityMessageDisplay.setMessage(
                                            getPukPasswordErrorMessage(attemptsRemaining), true);
                                    if (attemptsRemaining <= 2) {
                                        // this is getting critical - show dialog
                                        getPukRemainingAttemptsDialog(attemptsRemaining).show();
                                    }
                                } else {
                                    mSecurityMessageDisplay.setMessage(getContext().getString(
@@ -343,6 +371,23 @@ public class KeyguardSimPukView extends KeyguardAbsKeyInputView
    protected void verifyPasswordAndUnlock() {
        mStateMachine.next();
    }

    protected void showDefaultMessage() {
        if (mRemainingAttempts >= 0) {
            mSecurityMessageDisplay.setMessage(
                    getPukDefaultMessage(mRemainingAttempts), true);
            return;
        }
        new CheckSimPuk("", "") {
            void onSimLockChangedResponse(final int result, final int attemptsRemaining) {
                 if (attemptsRemaining >= 0) {
                    mRemainingAttempts = attemptsRemaining;
                    mSecurityMessageDisplay.setMessage(
                            getPukDefaultMessage(attemptsRemaining), true);
                }
            }
        }.start();
    }
}

+25 −8
Original line number Diff line number Diff line
@@ -141,8 +141,7 @@ public class MSimKeyguardSimPinView extends KeyguardSimPinView {

    public void resetState() {
        if (mShowDefaultMessage) {
            mSecurityMessageDisplay.setMessage(
                    getSecurityMessageDisplay(R.string.kg_sim_pin_instructions), true);
            showDefaultMessage();
        }
        mPasswordEntry.setEnabled(true);
    }
@@ -235,15 +234,15 @@ public class MSimKeyguardSimPinView extends KeyguardSimPinView {
                            } else {
                                mShowDefaultMessage = false;
                                if (result == PhoneConstants.PIN_PASSWORD_INCORRECT) {
                                    if (attemptsRemaining <= 2) {
                                        // this is getting critical - show dialog
                                        getSimRemainingAttemptsDialog(attemptsRemaining).show();
                                    } else {
                                    mRemainingAttempts = attemptsRemaining;
                                    // show message
                                    mSecurityMessageDisplay.setMessage(
                                            getSecurityMessageDisplay(
                                            getPinPasswordErrorMessage(
                                            attemptsRemaining)), true);
                                    if (attemptsRemaining <= 2) {
                                        // this is getting critical - show dialog
                                        getSimRemainingAttemptsDialog(attemptsRemaining).show();
                                    }
                                } else {
                                    // "PIN operation failed!" - no idea what this was and no way to
@@ -281,5 +280,23 @@ public class MSimKeyguardSimPinView extends KeyguardSimPinView {
                KeyguardUpdateMonitor.getInstance(mContext).getPinLockedSubscription()+1,msg);
    }

    @Override
    protected void showDefaultMessage() {
        if (mRemainingAttempts >= 0) {
            mSecurityMessageDisplay.setMessage(getSecurityMessageDisplay(
                    getPinDefaultMessage(mRemainingAttempts)), true);
            return;
        }
        int sub = KeyguardUpdateMonitor.getInstance(mContext).getPinLockedSubscription();
        new MSimCheckSimPin("", sub) {
            void onSimCheckResponse(final int result, final int attemptsRemaining) {
                if (attemptsRemaining >= 0) {
                    mRemainingAttempts = attemptsRemaining;
                    mSecurityMessageDisplay.setMessage(getSecurityMessageDisplay(
                            getPinDefaultMessage(attemptsRemaining)), true);
                }
            }
        }.start();
    }
}
Loading