blob: 5da764d90f73b8c061a2cfb952d782437afe9d53 [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) {
Brad Ebinger4cd3bdc2017-08-21 14:58:52 -070073 // If the SIM is unlocked via a key sequence through the emergency dialer, it will
74 // move into the READY state and the PUK lock keyguard should be removed.
75 case READY: {
Brad Ebinger4b2f6e22018-12-20 21:11:44 -080076 mRemainingAttempts = -1;
77 mShowDefaultMessage = true;
Brad Ebinger71306752017-10-05 11:39:06 -070078 // mCallback can be null if onSimStateChanged callback is called when keyguard
79 // isn't active.
80 if (mCallback != null) {
81 mCallback.dismiss(true, KeyguardUpdateMonitor.getCurrentUser());
82 }
Brad Ebinger4cd3bdc2017-08-21 14:58:52 -070083 break;
84 }
85 default:
86 resetState();
87 }
88 }
Jim Miller52a61332014-11-12 19:29:51 -080089 };
90
91 public KeyguardSimPukView(Context context) {
92 this(context, null);
93 }
94
95 public KeyguardSimPukView(Context context, AttributeSet attrs) {
96 super(context, attrs);
97 }
Jim Miller3efe1062012-09-28 16:59:31 -070098
99 private class StateMachine {
100 final int ENTER_PUK = 0;
101 final int ENTER_PIN = 1;
102 final int CONFIRM_PIN = 2;
103 final int DONE = 3;
104 private int state = ENTER_PUK;
105
106 public void next() {
107 int msg = 0;
108 if (state == ENTER_PUK) {
109 if (checkPuk()) {
110 state = ENTER_PIN;
111 msg = R.string.kg_puk_enter_pin_hint;
112 } else {
113 msg = R.string.kg_invalid_sim_puk_hint;
114 }
115 } else if (state == ENTER_PIN) {
116 if (checkPin()) {
117 state = CONFIRM_PIN;
118 msg = R.string.kg_enter_confirm_pin_hint;
119 } else {
120 msg = R.string.kg_invalid_sim_pin_hint;
121 }
122 } else if (state == CONFIRM_PIN) {
123 if (confirmPin()) {
124 state = DONE;
Jim Miller5ecd8112013-01-09 18:50:26 -0800125 msg = R.string.keyguard_sim_unlock_progress_dialog_message;
Jim Miller3efe1062012-09-28 16:59:31 -0700126 updateSim();
127 } else {
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400128 state = ENTER_PIN; // try again?
Jim Miller3efe1062012-09-28 16:59:31 -0700129 msg = R.string.kg_invalid_confirm_pin_hint;
130 }
131 }
Jim Miller4db942c2016-05-16 18:06:50 -0700132 resetPasswordText(true /* animate */, true /* announce */);
Jim Miller3efe1062012-09-28 16:59:31 -0700133 if (msg != 0) {
Adrian Roosdb327e92016-10-12 16:41:28 -0700134 mSecurityMessageDisplay.setMessage(msg);
Jim Miller3efe1062012-09-28 16:59:31 -0700135 }
136 }
137
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530138
Jim Miller3efe1062012-09-28 16:59:31 -0700139 void reset() {
140 mPinText="";
141 mPukText="";
142 state = ENTER_PUK;
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530143 handleSubInfoChangeIfNeeded();
144 if (mShowDefaultMessage) {
145 showDefaultMessage();
Jim Miller52a61332014-11-12 19:29:51 -0800146 }
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530147 boolean isEsimLocked = KeyguardEsimArea.isEsimLocked(mContext, mSubId);
148
qingxi12f2de42017-05-24 15:33:13 -0700149 KeyguardEsimArea esimButton = findViewById(R.id.keyguard_esim_area);
150 esimButton.setVisibility(isEsimLocked ? View.VISIBLE : View.GONE);
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400151 mPasswordEntry.requestFocus();
Jim Miller3efe1062012-09-28 16:59:31 -0700152 }
qingxi12f2de42017-05-24 15:33:13 -0700153
154
Jim Miller3efe1062012-09-28 16:59:31 -0700155 }
156
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530157 private void showDefaultMessage() {
158 if (mRemainingAttempts >= 0) {
159 mSecurityMessageDisplay.setMessage(getPukPasswordErrorMessage(
160 mRemainingAttempts, true));
161 return;
162 }
163
164 boolean isEsimLocked = KeyguardEsimArea.isEsimLocked(mContext, mSubId);
165 int count = TelephonyManager.getDefault().getSimCount();
166 Resources rez = getResources();
167 String msg;
168 int color = Color.WHITE;
169 if (count < 2) {
170 msg = rez.getString(R.string.kg_puk_enter_puk_hint);
171 } else {
172 SubscriptionInfo info = KeyguardUpdateMonitor.getInstance(mContext).
173 getSubscriptionInfoForSubId(mSubId);
174 CharSequence displayName = info != null ? info.getDisplayName() : "";
175 msg = rez.getString(R.string.kg_puk_enter_puk_hint_multi, displayName);
176 if (info != null) {
177 color = info.getIconTint();
178 }
179 }
180 if (isEsimLocked) {
Qingxi Li2febffb2018-01-23 16:16:35 -0800181 msg = rez.getString(R.string.kg_sim_lock_esim_instructions, msg);
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530182 }
183 mSecurityMessageDisplay.setMessage(msg);
184 mSimImageView.setImageTintList(ColorStateList.valueOf(color));
185
186 // Sending empty PUK here to query the number of remaining PIN attempts
187 new CheckSimPuk("", "", mSubId) {
188 void onSimLockChangedResponse(final int result, final int attemptsRemaining) {
189 Log.d(LOG_TAG, "onSimCheckResponse " + " dummy One result" + result +
190 " attemptsRemaining=" + attemptsRemaining);
191 if (attemptsRemaining >= 0) {
192 mRemainingAttempts = attemptsRemaining;
193 mSecurityMessageDisplay.setMessage(
194 getPukPasswordErrorMessage(attemptsRemaining, true));
195 }
196 }
197 }.start();
198 }
199
200 private void handleSubInfoChangeIfNeeded() {
201 KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
202 int subId = monitor.getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED);
203 if (subId != mSubId && SubscriptionManager.isValidSubscriptionId(subId)) {
204 mSubId = subId;
205 mShowDefaultMessage = true;
206 mRemainingAttempts = -1;
207 }
208 }
209
Selim Cinek3122fa82015-06-18 01:38:59 -0700210 @Override
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800211 protected int getPromptReasonStringRes(int reason) {
Selim Cinek3122fa82015-06-18 01:38:59 -0700212 // No message on SIM Puk
213 return 0;
214 }
215
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530216 private String getPukPasswordErrorMessage(int attemptsRemaining, boolean isDefault) {
Wink Savilleb896b9f2013-10-23 15:44:26 -0700217 String displayMessage;
218
219 if (attemptsRemaining == 0) {
220 displayMessage = getContext().getString(R.string.kg_password_wrong_puk_code_dead);
221 } else if (attemptsRemaining > 0) {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530222 int msgId = isDefault ? R.plurals.kg_password_default_puk_message :
223 R.plurals.kg_password_wrong_puk_code;
Wink Savilleb896b9f2013-10-23 15:44:26 -0700224 displayMessage = getContext().getResources()
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530225 .getQuantityString(msgId, attemptsRemaining, attemptsRemaining);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700226 } else {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530227 int msgId = isDefault ? R.string.kg_puk_enter_puk_hint :
228 R.string.kg_password_puk_failed;
229 displayMessage = getContext().getString(msgId);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700230 }
Qingxi Li2febffb2018-01-23 16:16:35 -0800231 if (KeyguardEsimArea.isEsimLocked(mContext, mSubId)) {
232 displayMessage = getResources()
233 .getString(R.string.kg_sim_lock_esim_instructions, displayMessage);
234 }
Wink Savilleb896b9f2013-10-23 15:44:26 -0700235 if (DEBUG) Log.d(LOG_TAG, "getPukPasswordErrorMessage:"
236 + " attemptsRemaining=" + attemptsRemaining + " displayMessage=" + displayMessage);
237 return displayMessage;
238 }
239
Jim Miller4db942c2016-05-16 18:06:50 -0700240 @Override
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400241 public void resetState() {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700242 super.resetState();
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400243 mStateMachine.reset();
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400244 }
245
246 @Override
Jim Miller7d5e00a2013-10-11 22:45:57 -0700247 protected boolean shouldLockout(long deadline) {
248 // SIM PUK doesn't have a timed lockout
249 return false;
250 }
251
252 @Override
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400253 protected int getPasswordTextViewId() {
Jorim Jaggifa9189f2014-04-17 20:17:30 +0200254 return R.id.pukEntry;
Jim Millerdcb3d842012-08-23 19:18:12 -0700255 }
256
257 @Override
258 protected void onFinishInflate() {
259 super.onFinishInflate();
Jim Miller0b728242012-10-28 19:42:30 -0700260
Jorim Jaggi40a0b382014-05-27 21:12:27 +0200261 if (mEcaView instanceof EmergencyCarrierArea) {
262 ((EmergencyCarrierArea) mEcaView).setCarrierTextVisible(true);
263 }
Alan Viverette51efddb2017-04-05 10:00:01 -0400264 mSimImageView = findViewById(R.id.keyguard_sim);
Jim Millerdcb3d842012-08-23 19:18:12 -0700265 }
266
Adam Cohen6fb841f2012-10-24 13:15:38 -0700267 @Override
Jim Miller52a61332014-11-12 19:29:51 -0800268 protected void onAttachedToWindow() {
269 super.onAttachedToWindow();
270 KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback);
271 }
272
273 @Override
274 protected void onDetachedFromWindow() {
275 super.onDetachedFromWindow();
276 KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateMonitorCallback);
277 }
278
279 @Override
Adam Cohen6fb841f2012-10-24 13:15:38 -0700280 public void showUsabilityHint() {
281 }
282
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400283 @Override
284 public void onPause() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700285 // dismiss the dialog.
286 if (mSimUnlockProgressDialog != null) {
287 mSimUnlockProgressDialog.dismiss();
288 mSimUnlockProgressDialog = null;
289 }
290 }
291
292 /**
293 * Since the IPC can block, we want to run the request in a separate thread
294 * with a callback.
295 */
296 private abstract class CheckSimPuk extends Thread {
297
298 private final String mPin, mPuk;
Jim Miller52a61332014-11-12 19:29:51 -0800299 private final int mSubId;
Jim Millerdcb3d842012-08-23 19:18:12 -0700300
Jim Miller52a61332014-11-12 19:29:51 -0800301 protected CheckSimPuk(String puk, String pin, int subId) {
Jim Millerdcb3d842012-08-23 19:18:12 -0700302 mPuk = puk;
303 mPin = pin;
Jim Miller52a61332014-11-12 19:29:51 -0800304 mSubId = subId;
Jim Millerdcb3d842012-08-23 19:18:12 -0700305 }
306
Wink Savilleb896b9f2013-10-23 15:44:26 -0700307 abstract void onSimLockChangedResponse(final int result, final int attemptsRemaining);
Jim Millerdcb3d842012-08-23 19:18:12 -0700308
309 @Override
310 public void run() {
311 try {
Jim Miller52a61332014-11-12 19:29:51 -0800312 if (DEBUG) Log.v(TAG, "call supplyPukReportResult()");
Wink Savilleb896b9f2013-10-23 15:44:26 -0700313 final int[] result = ITelephony.Stub.asInterface(ServiceManager
Jim Miller52a61332014-11-12 19:29:51 -0800314 .checkService("phone")).supplyPukReportResultForSubscriber(mSubId, mPuk, mPin);
315 if (DEBUG) {
316 Log.v(TAG, "supplyPukReportResult returned: " + result[0] + " " + result[1]);
317 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700318 post(new Runnable() {
Jim Miller4db942c2016-05-16 18:06:50 -0700319 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700320 public void run() {
Wink Savilleb896b9f2013-10-23 15:44:26 -0700321 onSimLockChangedResponse(result[0], result[1]);
Jim Millerdcb3d842012-08-23 19:18:12 -0700322 }
323 });
324 } catch (RemoteException e) {
Jim Miller4fc2b012013-11-04 16:47:48 -0800325 Log.e(TAG, "RemoteException for supplyPukReportResult:", e);
Jim Millerdcb3d842012-08-23 19:18:12 -0700326 post(new Runnable() {
Jim Miller4db942c2016-05-16 18:06:50 -0700327 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700328 public void run() {
Wink Savilleb896b9f2013-10-23 15:44:26 -0700329 onSimLockChangedResponse(PhoneConstants.PIN_GENERAL_FAILURE, -1);
Jim Millerdcb3d842012-08-23 19:18:12 -0700330 }
331 });
332 }
333 }
334 }
335
Jim Millerdcb3d842012-08-23 19:18:12 -0700336 private Dialog getSimUnlockProgressDialog() {
337 if (mSimUnlockProgressDialog == null) {
338 mSimUnlockProgressDialog = new ProgressDialog(mContext);
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400339 mSimUnlockProgressDialog.setMessage(
340 mContext.getString(R.string.kg_sim_unlock_progress_dialog_message));
Jim Millerdcb3d842012-08-23 19:18:12 -0700341 mSimUnlockProgressDialog.setIndeterminate(true);
342 mSimUnlockProgressDialog.setCancelable(false);
343 if (!(mContext instanceof Activity)) {
344 mSimUnlockProgressDialog.getWindow().setType(
345 WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
346 }
347 }
348 return mSimUnlockProgressDialog;
349 }
350
Wink Savilleb896b9f2013-10-23 15:44:26 -0700351 private Dialog getPukRemainingAttemptsDialog(int remaining) {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530352 String msg = getPukPasswordErrorMessage(remaining, false);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700353 if (mRemainingAttemptsDialog == null) {
354 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
355 builder.setMessage(msg);
356 builder.setCancelable(false);
357 builder.setNeutralButton(R.string.ok, null);
358 mRemainingAttemptsDialog = builder.create();
359 mRemainingAttemptsDialog.getWindow().setType(
360 WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
361 } else {
362 mRemainingAttemptsDialog.setMessage(msg);
363 }
364 return mRemainingAttemptsDialog;
365 }
366
Jim Miller3efe1062012-09-28 16:59:31 -0700367 private boolean checkPuk() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700368 // make sure the puk is at least 8 digits long.
Rakesh Pallerlab8b7bd32014-01-08 15:49:34 +0530369 if (mPasswordEntry.getText().length() == 8) {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700370 mPukText = mPasswordEntry.getText();
Jim Miller3efe1062012-09-28 16:59:31 -0700371 return true;
Jim Millerdcb3d842012-08-23 19:18:12 -0700372 }
Jim Miller3efe1062012-09-28 16:59:31 -0700373 return false;
374 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700375
Jim Miller3efe1062012-09-28 16:59:31 -0700376 private boolean checkPin() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700377 // make sure the PIN is between 4 and 8 digits
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400378 int length = mPasswordEntry.getText().length();
Jim Miller3efe1062012-09-28 16:59:31 -0700379 if (length >= 4 && length <= 8) {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700380 mPinText = mPasswordEntry.getText();
Jim Miller3efe1062012-09-28 16:59:31 -0700381 return true;
Jim Millerdcb3d842012-08-23 19:18:12 -0700382 }
Jim Miller3efe1062012-09-28 16:59:31 -0700383 return false;
384 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700385
Jim Miller3efe1062012-09-28 16:59:31 -0700386 public boolean confirmPin() {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700387 return mPinText.equals(mPasswordEntry.getText());
Jim Miller3efe1062012-09-28 16:59:31 -0700388 }
389
390 private void updateSim() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700391 getSimUnlockProgressDialog().show();
392
Jim Miller4fc2b012013-11-04 16:47:48 -0800393 if (mCheckSimPukThread == null) {
Jim Miller52a61332014-11-12 19:29:51 -0800394 mCheckSimPukThread = new CheckSimPuk(mPukText, mPinText, mSubId) {
Jim Miller4db942c2016-05-16 18:06:50 -0700395 @Override
Wink Savilleb896b9f2013-10-23 15:44:26 -0700396 void onSimLockChangedResponse(final int result, final int attemptsRemaining) {
Jim Miller3efe1062012-09-28 16:59:31 -0700397 post(new Runnable() {
Jim Miller4db942c2016-05-16 18:06:50 -0700398 @Override
Jim Miller4b09dd32012-09-04 14:27:25 -0700399 public void run() {
400 if (mSimUnlockProgressDialog != null) {
401 mSimUnlockProgressDialog.hide();
402 }
Jim Miller4db942c2016-05-16 18:06:50 -0700403 resetPasswordText(true /* animate */,
404 result != PhoneConstants.PIN_RESULT_SUCCESS /* announce */);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700405 if (result == PhoneConstants.PIN_RESULT_SUCCESS) {
Jim Miller52a61332014-11-12 19:29:51 -0800406 KeyguardUpdateMonitor.getInstance(getContext())
407 .reportSimUnlocked(mSubId);
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530408 mRemainingAttempts = -1;
409 mShowDefaultMessage = true;
410 if (mCallback != null) {
411 mCallback.dismiss(true, KeyguardUpdateMonitor.getCurrentUser());
412 }
Jim Miller4b09dd32012-09-04 14:27:25 -0700413 } else {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530414 mShowDefaultMessage = false;
Wink Savilleb896b9f2013-10-23 15:44:26 -0700415 if (result == PhoneConstants.PIN_PASSWORD_INCORRECT) {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530416 // show message
417 mSecurityMessageDisplay.setMessage(getPukPasswordErrorMessage(
418 attemptsRemaining, false));
Wink Savilleb896b9f2013-10-23 15:44:26 -0700419 if (attemptsRemaining <= 2) {
420 // this is getting critical - show dialog
421 getPukRemainingAttemptsDialog(attemptsRemaining).show();
422 } else {
423 // show message
424 mSecurityMessageDisplay.setMessage(
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530425 getPukPasswordErrorMessage(
426 attemptsRemaining, false));
Wink Savilleb896b9f2013-10-23 15:44:26 -0700427 }
428 } else {
429 mSecurityMessageDisplay.setMessage(getContext().getString(
Adrian Roosdb327e92016-10-12 16:41:28 -0700430 R.string.kg_password_puk_failed));
Wink Savilleb896b9f2013-10-23 15:44:26 -0700431 }
432 if (DEBUG) Log.d(LOG_TAG, "verifyPasswordAndUnlock "
433 + " UpdateSim.onSimCheckResponse: "
434 + " attemptsRemaining=" + attemptsRemaining);
Jim Miller3efe1062012-09-28 16:59:31 -0700435 mStateMachine.reset();
Jim Miller4b09dd32012-09-04 14:27:25 -0700436 }
Jim Miller4fc2b012013-11-04 16:47:48 -0800437 mCheckSimPukThread = null;
Jim Millerdcb3d842012-08-23 19:18:12 -0700438 }
Jim Miller4b09dd32012-09-04 14:27:25 -0700439 });
440 }
Jim Miller4fc2b012013-11-04 16:47:48 -0800441 };
442 mCheckSimPukThread.start();
Jim Miller4b09dd32012-09-04 14:27:25 -0700443 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700444 }
445
446 @Override
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400447 protected void verifyPasswordAndUnlock() {
448 mStateMachine.next();
Jim Miller9cf2c522012-10-04 22:02:29 -0700449 }
Jorim Jaggic14f8292014-05-27 02:25:45 +0200450
451 @Override
452 public void startAppearAnimation() {
453 // noop.
454 }
Jorim Jaggi76a16232014-08-08 17:00:47 +0200455
456 @Override
457 public boolean startDisappearAnimation(Runnable finishRunnable) {
458 return false;
459 }
Phil Weaver7d847b02018-02-13 16:02:35 -0800460
461 @Override
462 public CharSequence getTitle() {
463 return getContext().getString(
464 com.android.internal.R.string.keyguard_accessibility_sim_puk_unlock);
465 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700466}
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400467
468