diff options
-rw-r--r-- | packages/Keyguard/res/values/strings.xml | 6 | ||||
-rw-r--r-- | packages/Keyguard/src/com/android/keyguard/KeyguardSimPinView.java | 109 |
2 files changed, 84 insertions, 31 deletions
diff --git a/packages/Keyguard/res/values/strings.xml b/packages/Keyguard/res/values/strings.xml index 4837911..45e2827 100644 --- a/packages/Keyguard/res/values/strings.xml +++ b/packages/Keyguard/res/values/strings.xml @@ -343,4 +343,10 @@ <!-- 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> + </resources> diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardSimPinView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardSimPinView.java index aeac912..9dcef3a 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardSimPinView.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardSimPinView.java @@ -49,7 +49,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; @@ -58,7 +59,12 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView { @Override public void onSimStateChanged(int subId, int slotId, State simState) { if (DEBUG) Log.v(TAG, "onSimStateChanged(subId=" + subId + ",state=" + simState + ")"); - resetState(); + switch (simState) { + case NOT_READY: + case ABSENT: + closeKeyGuard(); + break; + } }; }; @@ -73,25 +79,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(); } } @@ -101,17 +90,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); @@ -143,6 +134,9 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView { @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); + if (mShowDefaultMessage) { + showDefaultMessage(); + } KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback); } @@ -221,7 +215,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); @@ -255,15 +249,15 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView { void onSimCheckResponse(final int result, final int attemptsRemaining) { post(new Runnable() { public void run() { + mRemainingAttempts = attemptsRemaining; if (mSimUnlockProgressDialog != null) { mSimUnlockProgressDialog.hide(); } resetPasswordText(true /* animate */); if (result == PhoneConstants.PIN_RESULT_SUCCESS) { - KeyguardUpdateMonitor.getInstance(getContext()) - .reportSimUnlocked(mSubId); - mCallback.dismiss(true); + closeKeyGuard(); } else { + mShowDefaultMessage = false; if (result == PhoneConstants.PIN_PASSWORD_INCORRECT) { if (attemptsRemaining <= 2) { // this is getting critical - show dialog @@ -271,7 +265,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 @@ -302,5 +297,57 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView { public boolean startDisappearAnimation(Runnable finishRunnable) { return false; } + + private void closeKeyGuard() { + if (DEBUG) Log.d(TAG, "closeKeyGuard: Verification Completed, closing Keyguard."); + mRemainingAttempts = -1; + KeyguardUpdateMonitor.getInstance(getContext()) + .reportSimUnlocked(mSubId); + mCallback.dismiss(true); + mShowDefaultMessage = true; + reset(); + } + + 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(); + } } |