blob: 347c9792ec95b0b6ae9c80e55b41d5542844ea1a [file] [log] [blame]
Jim Millerdcb3d842012-08-23 19:18:12 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jim Millerdcb3d842012-08-23 19:18:12 -070016
Jim Miller5ecd8112013-01-09 18:50:26 -080017package com.android.keyguard;
18
Jim Miller5ecd8112013-01-09 18:50:26 -080019import android.content.Context;
Jorim Jaggid05064b2014-11-20 21:35:33 +010020import android.content.res.ColorStateList;
Jim Miller52a61332014-11-12 19:29:51 -080021import android.content.res.Resources;
Jim Millerdcb3d842012-08-23 19:18:12 -070022import android.app.Activity;
Wink Savilleb896b9f2013-10-23 15:44:26 -070023import android.app.AlertDialog;
Jim Millerdcb3d842012-08-23 19:18:12 -070024import android.app.Dialog;
25import android.app.ProgressDialog;
Jorim Jaggid05064b2014-11-20 21:35:33 +010026import android.graphics.Color;
Jim Millerdcb3d842012-08-23 19:18:12 -070027import android.os.RemoteException;
28import android.os.ServiceManager;
Jim Miller52a61332014-11-12 19:29:51 -080029import android.telephony.SubscriptionInfo;
30import android.telephony.SubscriptionManager;
31import android.telephony.TelephonyManager;
qingxi3d768742017-04-12 11:07:11 -070032import android.telephony.euicc.EuiccManager;
Jim Millerdcb3d842012-08-23 19:18:12 -070033import android.util.AttributeSet;
Wink Savilleb896b9f2013-10-23 15:44:26 -070034import android.util.Log;
qingxi12f2de42017-05-24 15:33:13 -070035import android.view.View;
Jim Millerdcb3d842012-08-23 19:18:12 -070036import android.view.WindowManager;
Jorim Jaggid05064b2014-11-20 21:35:33 +010037import android.widget.ImageView;
Jim Millerdcb3d842012-08-23 19:18:12 -070038
Wink Savilleb896b9f2013-10-23 15:44:26 -070039import com.android.internal.telephony.ITelephony;
Jim Miller52a61332014-11-12 19:29:51 -080040import com.android.internal.telephony.IccCardConstants;
Wink Savilleb896b9f2013-10-23 15:44:26 -070041import com.android.internal.telephony.PhoneConstants;
Jim Miller52a61332014-11-12 19:29:51 -080042import com.android.internal.telephony.IccCardConstants.State;
Wink Savilleb896b9f2013-10-23 15:44:26 -070043
44
Daniel Sandler23d7a6e2012-11-02 00:21:07 -040045/**
46 * Displays a PIN pad for entering a PUK (Pin Unlock Kode) provided by a carrier.
47 */
Selim Cinek4e8b9ed2014-06-20 16:37:04 -070048public class KeyguardSimPukView extends KeyguardPinBasedInputView {
Wink Savilleb896b9f2013-10-23 15:44:26 -070049 private static final String LOG_TAG = "KeyguardSimPukView";
Jorim Jaggi5cf17872014-03-26 18:31:48 +010050 private static final boolean DEBUG = KeyguardConstants.DEBUG;
Jim Miller4fc2b012013-11-04 16:47:48 -080051 public static final String TAG = "KeyguardSimPukView";
Jim Millerdcb3d842012-08-23 19:18:12 -070052
53 private ProgressDialog mSimUnlockProgressDialog = null;
Jim Miller4fc2b012013-11-04 16:47:48 -080054 private CheckSimPuk mCheckSimPukThread;
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +053055
56 // Below flag is set to true during power-up or when a new SIM card inserted on device.
57 // When this is true and when SIM card is PUK locked state, on PIN lock screen, message would
58 // be displayed to inform user about the number of remaining PUK attempts left.
59 private boolean mShowDefaultMessage = true;
60 private int mRemainingAttempts = -1;
Jim Miller3efe1062012-09-28 16:59:31 -070061 private String mPukText;
Jim Miller3efe1062012-09-28 16:59:31 -070062 private String mPinText;
63 private StateMachine mStateMachine = new StateMachine();
Wink Savilleb896b9f2013-10-23 15:44:26 -070064 private AlertDialog mRemainingAttemptsDialog;
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +053065 private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Jorim Jaggid05064b2014-11-20 21:35:33 +010066 private ImageView mSimImageView;
Jim Miller52a61332014-11-12 19:29:51 -080067
68 KeyguardUpdateMonitorCallback mUpdateMonitorCallback = new KeyguardUpdateMonitorCallback() {
69 @Override
70 public void onSimStateChanged(int subId, int slotId, State simState) {
Brad Ebinger4cd3bdc2017-08-21 14:58:52 -070071 if (DEBUG) Log.v(TAG, "onSimStateChanged(subId=" + subId + ",state=" + simState + ")");
72 switch(simState) {
73 // If the SIM is removed, then we must remove the keyguard. It will be put up
74 // again when the PUK locked SIM is re-entered.
75 case ABSENT:
76 // intentional fall-through
77 // If the SIM is unlocked via a key sequence through the emergency dialer, it will
78 // move into the READY state and the PUK lock keyguard should be removed.
79 case READY: {
80 KeyguardUpdateMonitor.getInstance(getContext()).reportSimUnlocked(mSubId);
Brad Ebinger71306752017-10-05 11:39:06 -070081 // mCallback can be null if onSimStateChanged callback is called when keyguard
82 // isn't active.
83 if (mCallback != null) {
84 mCallback.dismiss(true, KeyguardUpdateMonitor.getCurrentUser());
85 }
Brad Ebinger4cd3bdc2017-08-21 14:58:52 -070086 break;
87 }
88 default:
89 resetState();
90 }
91 }
Jim Miller52a61332014-11-12 19:29:51 -080092 };
93
94 public KeyguardSimPukView(Context context) {
95 this(context, null);
96 }
97
98 public KeyguardSimPukView(Context context, AttributeSet attrs) {
99 super(context, attrs);
100 }
Jim Miller3efe1062012-09-28 16:59:31 -0700101
102 private class StateMachine {
103 final int ENTER_PUK = 0;
104 final int ENTER_PIN = 1;
105 final int CONFIRM_PIN = 2;
106 final int DONE = 3;
107 private int state = ENTER_PUK;
108
109 public void next() {
110 int msg = 0;
111 if (state == ENTER_PUK) {
112 if (checkPuk()) {
113 state = ENTER_PIN;
114 msg = R.string.kg_puk_enter_pin_hint;
115 } else {
116 msg = R.string.kg_invalid_sim_puk_hint;
117 }
118 } else if (state == ENTER_PIN) {
119 if (checkPin()) {
120 state = CONFIRM_PIN;
121 msg = R.string.kg_enter_confirm_pin_hint;
122 } else {
123 msg = R.string.kg_invalid_sim_pin_hint;
124 }
125 } else if (state == CONFIRM_PIN) {
126 if (confirmPin()) {
127 state = DONE;
Jim Miller5ecd8112013-01-09 18:50:26 -0800128 msg = R.string.keyguard_sim_unlock_progress_dialog_message;
Jim Miller3efe1062012-09-28 16:59:31 -0700129 updateSim();
130 } else {
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400131 state = ENTER_PIN; // try again?
Jim Miller3efe1062012-09-28 16:59:31 -0700132 msg = R.string.kg_invalid_confirm_pin_hint;
133 }
134 }
Jim Miller4db942c2016-05-16 18:06:50 -0700135 resetPasswordText(true /* animate */, true /* announce */);
Jim Miller3efe1062012-09-28 16:59:31 -0700136 if (msg != 0) {
Adrian Roosdb327e92016-10-12 16:41:28 -0700137 mSecurityMessageDisplay.setMessage(msg);
Jim Miller3efe1062012-09-28 16:59:31 -0700138 }
139 }
140
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530141
Jim Miller3efe1062012-09-28 16:59:31 -0700142 void reset() {
143 mPinText="";
144 mPukText="";
145 state = ENTER_PUK;
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530146 handleSubInfoChangeIfNeeded();
147 if (mShowDefaultMessage) {
148 showDefaultMessage();
Jim Miller52a61332014-11-12 19:29:51 -0800149 }
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530150 boolean isEsimLocked = KeyguardEsimArea.isEsimLocked(mContext, mSubId);
151
qingxi12f2de42017-05-24 15:33:13 -0700152 KeyguardEsimArea esimButton = findViewById(R.id.keyguard_esim_area);
153 esimButton.setVisibility(isEsimLocked ? View.VISIBLE : View.GONE);
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400154 mPasswordEntry.requestFocus();
Jim Miller3efe1062012-09-28 16:59:31 -0700155 }
qingxi12f2de42017-05-24 15:33:13 -0700156
157
Jim Miller3efe1062012-09-28 16:59:31 -0700158 }
159
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530160 private void showDefaultMessage() {
161 if (mRemainingAttempts >= 0) {
162 mSecurityMessageDisplay.setMessage(getPukPasswordErrorMessage(
163 mRemainingAttempts, true));
164 return;
165 }
166
167 boolean isEsimLocked = KeyguardEsimArea.isEsimLocked(mContext, mSubId);
168 int count = TelephonyManager.getDefault().getSimCount();
169 Resources rez = getResources();
170 String msg;
171 int color = Color.WHITE;
172 if (count < 2) {
173 msg = rez.getString(R.string.kg_puk_enter_puk_hint);
174 } else {
175 SubscriptionInfo info = KeyguardUpdateMonitor.getInstance(mContext).
176 getSubscriptionInfoForSubId(mSubId);
177 CharSequence displayName = info != null ? info.getDisplayName() : "";
178 msg = rez.getString(R.string.kg_puk_enter_puk_hint_multi, displayName);
179 if (info != null) {
180 color = info.getIconTint();
181 }
182 }
183 if (isEsimLocked) {
Qingxi Li2febffb2018-01-23 16:16:35 -0800184 msg = rez.getString(R.string.kg_sim_lock_esim_instructions, msg);
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530185 }
186 mSecurityMessageDisplay.setMessage(msg);
187 mSimImageView.setImageTintList(ColorStateList.valueOf(color));
188
189 // Sending empty PUK here to query the number of remaining PIN attempts
190 new CheckSimPuk("", "", mSubId) {
191 void onSimLockChangedResponse(final int result, final int attemptsRemaining) {
192 Log.d(LOG_TAG, "onSimCheckResponse " + " dummy One result" + result +
193 " attemptsRemaining=" + attemptsRemaining);
194 if (attemptsRemaining >= 0) {
195 mRemainingAttempts = attemptsRemaining;
196 mSecurityMessageDisplay.setMessage(
197 getPukPasswordErrorMessage(attemptsRemaining, true));
198 }
199 }
200 }.start();
201 }
202
203 private void handleSubInfoChangeIfNeeded() {
204 KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
205 int subId = monitor.getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED);
206 if (subId != mSubId && SubscriptionManager.isValidSubscriptionId(subId)) {
207 mSubId = subId;
208 mShowDefaultMessage = true;
209 mRemainingAttempts = -1;
210 }
211 }
212
Selim Cinek3122fa82015-06-18 01:38:59 -0700213 @Override
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800214 protected int getPromptReasonStringRes(int reason) {
Selim Cinek3122fa82015-06-18 01:38:59 -0700215 // No message on SIM Puk
216 return 0;
217 }
218
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530219 private String getPukPasswordErrorMessage(int attemptsRemaining, boolean isDefault) {
Wink Savilleb896b9f2013-10-23 15:44:26 -0700220 String displayMessage;
221
222 if (attemptsRemaining == 0) {
223 displayMessage = getContext().getString(R.string.kg_password_wrong_puk_code_dead);
224 } else if (attemptsRemaining > 0) {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530225 int msgId = isDefault ? R.plurals.kg_password_default_puk_message :
226 R.plurals.kg_password_wrong_puk_code;
Wink Savilleb896b9f2013-10-23 15:44:26 -0700227 displayMessage = getContext().getResources()
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530228 .getQuantityString(msgId, attemptsRemaining, attemptsRemaining);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700229 } else {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530230 int msgId = isDefault ? R.string.kg_puk_enter_puk_hint :
231 R.string.kg_password_puk_failed;
232 displayMessage = getContext().getString(msgId);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700233 }
Qingxi Li2febffb2018-01-23 16:16:35 -0800234 if (KeyguardEsimArea.isEsimLocked(mContext, mSubId)) {
235 displayMessage = getResources()
236 .getString(R.string.kg_sim_lock_esim_instructions, displayMessage);
237 }
Wink Savilleb896b9f2013-10-23 15:44:26 -0700238 if (DEBUG) Log.d(LOG_TAG, "getPukPasswordErrorMessage:"
239 + " attemptsRemaining=" + attemptsRemaining + " displayMessage=" + displayMessage);
240 return displayMessage;
241 }
242
Jim Miller4db942c2016-05-16 18:06:50 -0700243 @Override
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400244 public void resetState() {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700245 super.resetState();
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400246 mStateMachine.reset();
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400247 }
248
249 @Override
Jim Miller7d5e00a2013-10-11 22:45:57 -0700250 protected boolean shouldLockout(long deadline) {
251 // SIM PUK doesn't have a timed lockout
252 return false;
253 }
254
255 @Override
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400256 protected int getPasswordTextViewId() {
Jorim Jaggifa9189f2014-04-17 20:17:30 +0200257 return R.id.pukEntry;
Jim Millerdcb3d842012-08-23 19:18:12 -0700258 }
259
260 @Override
261 protected void onFinishInflate() {
262 super.onFinishInflate();
Jim Miller0b728242012-10-28 19:42:30 -0700263
Jorim Jaggi40a0b382014-05-27 21:12:27 +0200264 if (mEcaView instanceof EmergencyCarrierArea) {
265 ((EmergencyCarrierArea) mEcaView).setCarrierTextVisible(true);
266 }
Alan Viverette51efddb2017-04-05 10:00:01 -0400267 mSimImageView = findViewById(R.id.keyguard_sim);
Jim Millerdcb3d842012-08-23 19:18:12 -0700268 }
269
Adam Cohen6fb841f2012-10-24 13:15:38 -0700270 @Override
Jim Miller52a61332014-11-12 19:29:51 -0800271 protected void onAttachedToWindow() {
272 super.onAttachedToWindow();
273 KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback);
274 }
275
276 @Override
277 protected void onDetachedFromWindow() {
278 super.onDetachedFromWindow();
279 KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateMonitorCallback);
280 }
281
282 @Override
Adam Cohen6fb841f2012-10-24 13:15:38 -0700283 public void showUsabilityHint() {
284 }
285
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400286 @Override
287 public void onPause() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700288 // dismiss the dialog.
289 if (mSimUnlockProgressDialog != null) {
290 mSimUnlockProgressDialog.dismiss();
291 mSimUnlockProgressDialog = null;
292 }
293 }
294
295 /**
296 * Since the IPC can block, we want to run the request in a separate thread
297 * with a callback.
298 */
299 private abstract class CheckSimPuk extends Thread {
300
301 private final String mPin, mPuk;
Jim Miller52a61332014-11-12 19:29:51 -0800302 private final int mSubId;
Jim Millerdcb3d842012-08-23 19:18:12 -0700303
Jim Miller52a61332014-11-12 19:29:51 -0800304 protected CheckSimPuk(String puk, String pin, int subId) {
Jim Millerdcb3d842012-08-23 19:18:12 -0700305 mPuk = puk;
306 mPin = pin;
Jim Miller52a61332014-11-12 19:29:51 -0800307 mSubId = subId;
Jim Millerdcb3d842012-08-23 19:18:12 -0700308 }
309
Wink Savilleb896b9f2013-10-23 15:44:26 -0700310 abstract void onSimLockChangedResponse(final int result, final int attemptsRemaining);
Jim Millerdcb3d842012-08-23 19:18:12 -0700311
312 @Override
313 public void run() {
314 try {
Jim Miller52a61332014-11-12 19:29:51 -0800315 if (DEBUG) Log.v(TAG, "call supplyPukReportResult()");
Wink Savilleb896b9f2013-10-23 15:44:26 -0700316 final int[] result = ITelephony.Stub.asInterface(ServiceManager
Jim Miller52a61332014-11-12 19:29:51 -0800317 .checkService("phone")).supplyPukReportResultForSubscriber(mSubId, mPuk, mPin);
318 if (DEBUG) {
319 Log.v(TAG, "supplyPukReportResult returned: " + result[0] + " " + result[1]);
320 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700321 post(new Runnable() {
Jim Miller4db942c2016-05-16 18:06:50 -0700322 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700323 public void run() {
Wink Savilleb896b9f2013-10-23 15:44:26 -0700324 onSimLockChangedResponse(result[0], result[1]);
Jim Millerdcb3d842012-08-23 19:18:12 -0700325 }
326 });
327 } catch (RemoteException e) {
Jim Miller4fc2b012013-11-04 16:47:48 -0800328 Log.e(TAG, "RemoteException for supplyPukReportResult:", e);
Jim Millerdcb3d842012-08-23 19:18:12 -0700329 post(new Runnable() {
Jim Miller4db942c2016-05-16 18:06:50 -0700330 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700331 public void run() {
Wink Savilleb896b9f2013-10-23 15:44:26 -0700332 onSimLockChangedResponse(PhoneConstants.PIN_GENERAL_FAILURE, -1);
Jim Millerdcb3d842012-08-23 19:18:12 -0700333 }
334 });
335 }
336 }
337 }
338
Jim Millerdcb3d842012-08-23 19:18:12 -0700339 private Dialog getSimUnlockProgressDialog() {
340 if (mSimUnlockProgressDialog == null) {
341 mSimUnlockProgressDialog = new ProgressDialog(mContext);
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400342 mSimUnlockProgressDialog.setMessage(
343 mContext.getString(R.string.kg_sim_unlock_progress_dialog_message));
Jim Millerdcb3d842012-08-23 19:18:12 -0700344 mSimUnlockProgressDialog.setIndeterminate(true);
345 mSimUnlockProgressDialog.setCancelable(false);
346 if (!(mContext instanceof Activity)) {
347 mSimUnlockProgressDialog.getWindow().setType(
348 WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
349 }
350 }
351 return mSimUnlockProgressDialog;
352 }
353
Wink Savilleb896b9f2013-10-23 15:44:26 -0700354 private Dialog getPukRemainingAttemptsDialog(int remaining) {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530355 String msg = getPukPasswordErrorMessage(remaining, false);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700356 if (mRemainingAttemptsDialog == null) {
357 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
358 builder.setMessage(msg);
359 builder.setCancelable(false);
360 builder.setNeutralButton(R.string.ok, null);
361 mRemainingAttemptsDialog = builder.create();
362 mRemainingAttemptsDialog.getWindow().setType(
363 WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
364 } else {
365 mRemainingAttemptsDialog.setMessage(msg);
366 }
367 return mRemainingAttemptsDialog;
368 }
369
Jim Miller3efe1062012-09-28 16:59:31 -0700370 private boolean checkPuk() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700371 // make sure the puk is at least 8 digits long.
Rakesh Pallerlab8b7bd32014-01-08 15:49:34 +0530372 if (mPasswordEntry.getText().length() == 8) {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700373 mPukText = mPasswordEntry.getText();
Jim Miller3efe1062012-09-28 16:59:31 -0700374 return true;
Jim Millerdcb3d842012-08-23 19:18:12 -0700375 }
Jim Miller3efe1062012-09-28 16:59:31 -0700376 return false;
377 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700378
Jim Miller3efe1062012-09-28 16:59:31 -0700379 private boolean checkPin() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700380 // make sure the PIN is between 4 and 8 digits
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400381 int length = mPasswordEntry.getText().length();
Jim Miller3efe1062012-09-28 16:59:31 -0700382 if (length >= 4 && length <= 8) {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700383 mPinText = mPasswordEntry.getText();
Jim Miller3efe1062012-09-28 16:59:31 -0700384 return true;
Jim Millerdcb3d842012-08-23 19:18:12 -0700385 }
Jim Miller3efe1062012-09-28 16:59:31 -0700386 return false;
387 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700388
Jim Miller3efe1062012-09-28 16:59:31 -0700389 public boolean confirmPin() {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700390 return mPinText.equals(mPasswordEntry.getText());
Jim Miller3efe1062012-09-28 16:59:31 -0700391 }
392
393 private void updateSim() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700394 getSimUnlockProgressDialog().show();
395
Jim Miller4fc2b012013-11-04 16:47:48 -0800396 if (mCheckSimPukThread == null) {
Jim Miller52a61332014-11-12 19:29:51 -0800397 mCheckSimPukThread = new CheckSimPuk(mPukText, mPinText, mSubId) {
Jim Miller4db942c2016-05-16 18:06:50 -0700398 @Override
Wink Savilleb896b9f2013-10-23 15:44:26 -0700399 void onSimLockChangedResponse(final int result, final int attemptsRemaining) {
Jim Miller3efe1062012-09-28 16:59:31 -0700400 post(new Runnable() {
Jim Miller4db942c2016-05-16 18:06:50 -0700401 @Override
Jim Miller4b09dd32012-09-04 14:27:25 -0700402 public void run() {
403 if (mSimUnlockProgressDialog != null) {
404 mSimUnlockProgressDialog.hide();
405 }
Jim Miller4db942c2016-05-16 18:06:50 -0700406 resetPasswordText(true /* animate */,
407 result != PhoneConstants.PIN_RESULT_SUCCESS /* announce */);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700408 if (result == PhoneConstants.PIN_RESULT_SUCCESS) {
Jim Miller52a61332014-11-12 19:29:51 -0800409 KeyguardUpdateMonitor.getInstance(getContext())
410 .reportSimUnlocked(mSubId);
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530411 mRemainingAttempts = -1;
412 mShowDefaultMessage = true;
413 if (mCallback != null) {
414 mCallback.dismiss(true, KeyguardUpdateMonitor.getCurrentUser());
415 }
Jim Miller4b09dd32012-09-04 14:27:25 -0700416 } else {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530417 mShowDefaultMessage = false;
Wink Savilleb896b9f2013-10-23 15:44:26 -0700418 if (result == PhoneConstants.PIN_PASSWORD_INCORRECT) {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530419 // show message
420 mSecurityMessageDisplay.setMessage(getPukPasswordErrorMessage(
421 attemptsRemaining, false));
Wink Savilleb896b9f2013-10-23 15:44:26 -0700422 if (attemptsRemaining <= 2) {
423 // this is getting critical - show dialog
424 getPukRemainingAttemptsDialog(attemptsRemaining).show();
425 } else {
426 // show message
427 mSecurityMessageDisplay.setMessage(
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530428 getPukPasswordErrorMessage(
429 attemptsRemaining, false));
Wink Savilleb896b9f2013-10-23 15:44:26 -0700430 }
431 } else {
432 mSecurityMessageDisplay.setMessage(getContext().getString(
Adrian Roosdb327e92016-10-12 16:41:28 -0700433 R.string.kg_password_puk_failed));
Wink Savilleb896b9f2013-10-23 15:44:26 -0700434 }
435 if (DEBUG) Log.d(LOG_TAG, "verifyPasswordAndUnlock "
436 + " UpdateSim.onSimCheckResponse: "
437 + " attemptsRemaining=" + attemptsRemaining);
Jim Miller3efe1062012-09-28 16:59:31 -0700438 mStateMachine.reset();
Jim Miller4b09dd32012-09-04 14:27:25 -0700439 }
Jim Miller4fc2b012013-11-04 16:47:48 -0800440 mCheckSimPukThread = null;
Jim Millerdcb3d842012-08-23 19:18:12 -0700441 }
Jim Miller4b09dd32012-09-04 14:27:25 -0700442 });
443 }
Jim Miller4fc2b012013-11-04 16:47:48 -0800444 };
445 mCheckSimPukThread.start();
Jim Miller4b09dd32012-09-04 14:27:25 -0700446 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700447 }
448
449 @Override
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400450 protected void verifyPasswordAndUnlock() {
451 mStateMachine.next();
Jim Miller9cf2c522012-10-04 22:02:29 -0700452 }
Jorim Jaggic14f8292014-05-27 02:25:45 +0200453
454 @Override
455 public void startAppearAnimation() {
456 // noop.
457 }
Jorim Jaggi76a16232014-08-08 17:00:47 +0200458
459 @Override
460 public boolean startDisappearAnimation(Runnable finishRunnable) {
461 return false;
462 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700463}
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400464
465