blob: 1157f86872ec2cae97ab0498607c6c699ae386aa [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 Millerdcb3d842012-08-23 19:18:12 -070019import android.app.Activity;
Wink Savilleb896b9f2013-10-23 15:44:26 -070020import android.app.AlertDialog;
Jim Millerdcb3d842012-08-23 19:18:12 -070021import android.app.Dialog;
22import android.app.ProgressDialog;
Gus Prevasab336792018-11-14 13:52:20 -050023import android.content.Context;
24import android.content.res.ColorStateList;
25import android.content.res.Resources;
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;
Jim Millerdcb3d842012-08-23 19:18:12 -070032import android.util.AttributeSet;
Wink Savilleb896b9f2013-10-23 15:44:26 -070033import android.util.Log;
qingxi12f2de42017-05-24 15:33:13 -070034import android.view.View;
Jim Millerdcb3d842012-08-23 19:18:12 -070035import android.view.WindowManager;
Jorim Jaggid05064b2014-11-20 21:35:33 +010036import android.widget.ImageView;
Jim Millerdcb3d842012-08-23 19:18:12 -070037
Wink Savilleb896b9f2013-10-23 15:44:26 -070038import com.android.internal.telephony.ITelephony;
Jim Miller52a61332014-11-12 19:29:51 -080039import com.android.internal.telephony.IccCardConstants;
Jim Miller52a61332014-11-12 19:29:51 -080040import com.android.internal.telephony.IccCardConstants.State;
Gus Prevasab336792018-11-14 13:52:20 -050041import com.android.internal.telephony.PhoneConstants;
Wink Savilleb896b9f2013-10-23 15:44:26 -070042
43
Daniel Sandler23d7a6e2012-11-02 00:21:07 -040044/**
45 * Displays a PIN pad for entering a PUK (Pin Unlock Kode) provided by a carrier.
46 */
Selim Cinek4e8b9ed2014-06-20 16:37:04 -070047public class KeyguardSimPukView extends KeyguardPinBasedInputView {
Wink Savilleb896b9f2013-10-23 15:44:26 -070048 private static final String LOG_TAG = "KeyguardSimPukView";
Jorim Jaggi5cf17872014-03-26 18:31:48 +010049 private static final boolean DEBUG = KeyguardConstants.DEBUG;
Jim Miller4fc2b012013-11-04 16:47:48 -080050 public static final String TAG = "KeyguardSimPukView";
Jim Millerdcb3d842012-08-23 19:18:12 -070051
52 private ProgressDialog mSimUnlockProgressDialog = null;
Jim Miller4fc2b012013-11-04 16:47:48 -080053 private CheckSimPuk mCheckSimPukThread;
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +053054
55 // Below flag is set to true during power-up or when a new SIM card inserted on device.
56 // When this is true and when SIM card is PUK locked state, on PIN lock screen, message would
57 // be displayed to inform user about the number of remaining PUK attempts left.
58 private boolean mShowDefaultMessage = true;
59 private int mRemainingAttempts = -1;
Jim Miller3efe1062012-09-28 16:59:31 -070060 private String mPukText;
Jim Miller3efe1062012-09-28 16:59:31 -070061 private String mPinText;
62 private StateMachine mStateMachine = new StateMachine();
Wink Savilleb896b9f2013-10-23 15:44:26 -070063 private AlertDialog mRemainingAttemptsDialog;
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +053064 private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Jorim Jaggid05064b2014-11-20 21:35:33 +010065 private ImageView mSimImageView;
Jim Miller52a61332014-11-12 19:29:51 -080066
67 KeyguardUpdateMonitorCallback mUpdateMonitorCallback = new KeyguardUpdateMonitorCallback() {
68 @Override
69 public void onSimStateChanged(int subId, int slotId, State simState) {
Brad Ebinger4cd3bdc2017-08-21 14:58:52 -070070 if (DEBUG) Log.v(TAG, "onSimStateChanged(subId=" + subId + ",state=" + simState + ")");
71 switch(simState) {
72 // If the SIM is removed, then we must remove the keyguard. It will be put up
73 // again when the PUK locked SIM is re-entered.
74 case ABSENT:
75 // intentional fall-through
76 // If the SIM is unlocked via a key sequence through the emergency dialer, it will
77 // move into the READY state and the PUK lock keyguard should be removed.
78 case READY: {
79 KeyguardUpdateMonitor.getInstance(getContext()).reportSimUnlocked(mSubId);
Brad Ebinger71306752017-10-05 11:39:06 -070080 // mCallback can be null if onSimStateChanged callback is called when keyguard
81 // isn't active.
82 if (mCallback != null) {
83 mCallback.dismiss(true, KeyguardUpdateMonitor.getCurrentUser());
84 }
Brad Ebinger4cd3bdc2017-08-21 14:58:52 -070085 break;
86 }
87 default:
88 resetState();
89 }
90 }
Jim Miller52a61332014-11-12 19:29:51 -080091 };
92
93 public KeyguardSimPukView(Context context) {
94 this(context, null);
95 }
96
97 public KeyguardSimPukView(Context context, AttributeSet attrs) {
98 super(context, attrs);
99 }
Jim Miller3efe1062012-09-28 16:59:31 -0700100
101 private class StateMachine {
102 final int ENTER_PUK = 0;
103 final int ENTER_PIN = 1;
104 final int CONFIRM_PIN = 2;
105 final int DONE = 3;
106 private int state = ENTER_PUK;
107
108 public void next() {
109 int msg = 0;
110 if (state == ENTER_PUK) {
111 if (checkPuk()) {
112 state = ENTER_PIN;
113 msg = R.string.kg_puk_enter_pin_hint;
114 } else {
115 msg = R.string.kg_invalid_sim_puk_hint;
116 }
117 } else if (state == ENTER_PIN) {
118 if (checkPin()) {
119 state = CONFIRM_PIN;
120 msg = R.string.kg_enter_confirm_pin_hint;
121 } else {
122 msg = R.string.kg_invalid_sim_pin_hint;
123 }
124 } else if (state == CONFIRM_PIN) {
125 if (confirmPin()) {
126 state = DONE;
Jim Miller5ecd8112013-01-09 18:50:26 -0800127 msg = R.string.keyguard_sim_unlock_progress_dialog_message;
Jim Miller3efe1062012-09-28 16:59:31 -0700128 updateSim();
129 } else {
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400130 state = ENTER_PIN; // try again?
Jim Miller3efe1062012-09-28 16:59:31 -0700131 msg = R.string.kg_invalid_confirm_pin_hint;
132 }
133 }
Jim Miller4db942c2016-05-16 18:06:50 -0700134 resetPasswordText(true /* animate */, true /* announce */);
Jim Miller3efe1062012-09-28 16:59:31 -0700135 if (msg != 0) {
Adrian Roosdb327e92016-10-12 16:41:28 -0700136 mSecurityMessageDisplay.setMessage(msg);
Jim Miller3efe1062012-09-28 16:59:31 -0700137 }
138 }
139
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530140
Jim Miller3efe1062012-09-28 16:59:31 -0700141 void reset() {
142 mPinText="";
143 mPukText="";
144 state = ENTER_PUK;
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530145 handleSubInfoChangeIfNeeded();
146 if (mShowDefaultMessage) {
147 showDefaultMessage();
Jim Miller52a61332014-11-12 19:29:51 -0800148 }
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530149 boolean isEsimLocked = KeyguardEsimArea.isEsimLocked(mContext, mSubId);
150
qingxi12f2de42017-05-24 15:33:13 -0700151 KeyguardEsimArea esimButton = findViewById(R.id.keyguard_esim_area);
152 esimButton.setVisibility(isEsimLocked ? View.VISIBLE : View.GONE);
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400153 mPasswordEntry.requestFocus();
Jim Miller3efe1062012-09-28 16:59:31 -0700154 }
qingxi12f2de42017-05-24 15:33:13 -0700155
156
Jim Miller3efe1062012-09-28 16:59:31 -0700157 }
158
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530159 private void showDefaultMessage() {
160 if (mRemainingAttempts >= 0) {
161 mSecurityMessageDisplay.setMessage(getPukPasswordErrorMessage(
162 mRemainingAttempts, true));
163 return;
164 }
165
166 boolean isEsimLocked = KeyguardEsimArea.isEsimLocked(mContext, mSubId);
167 int count = TelephonyManager.getDefault().getSimCount();
168 Resources rez = getResources();
169 String msg;
170 int color = Color.WHITE;
171 if (count < 2) {
172 msg = rez.getString(R.string.kg_puk_enter_puk_hint);
173 } else {
174 SubscriptionInfo info = KeyguardUpdateMonitor.getInstance(mContext).
175 getSubscriptionInfoForSubId(mSubId);
176 CharSequence displayName = info != null ? info.getDisplayName() : "";
177 msg = rez.getString(R.string.kg_puk_enter_puk_hint_multi, displayName);
178 if (info != null) {
179 color = info.getIconTint();
180 }
181 }
182 if (isEsimLocked) {
Qingxi Li2febffb2018-01-23 16:16:35 -0800183 msg = rez.getString(R.string.kg_sim_lock_esim_instructions, msg);
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530184 }
185 mSecurityMessageDisplay.setMessage(msg);
186 mSimImageView.setImageTintList(ColorStateList.valueOf(color));
187
188 // Sending empty PUK here to query the number of remaining PIN attempts
189 new CheckSimPuk("", "", mSubId) {
190 void onSimLockChangedResponse(final int result, final int attemptsRemaining) {
191 Log.d(LOG_TAG, "onSimCheckResponse " + " dummy One result" + result +
192 " attemptsRemaining=" + attemptsRemaining);
193 if (attemptsRemaining >= 0) {
194 mRemainingAttempts = attemptsRemaining;
195 mSecurityMessageDisplay.setMessage(
196 getPukPasswordErrorMessage(attemptsRemaining, true));
197 }
198 }
199 }.start();
200 }
201
202 private void handleSubInfoChangeIfNeeded() {
203 KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
204 int subId = monitor.getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED);
205 if (subId != mSubId && SubscriptionManager.isValidSubscriptionId(subId)) {
206 mSubId = subId;
207 mShowDefaultMessage = true;
208 mRemainingAttempts = -1;
209 }
210 }
211
Selim Cinek3122fa82015-06-18 01:38:59 -0700212 @Override
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800213 protected int getPromptReasonStringRes(int reason) {
Selim Cinek3122fa82015-06-18 01:38:59 -0700214 // No message on SIM Puk
215 return 0;
216 }
217
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530218 private String getPukPasswordErrorMessage(int attemptsRemaining, boolean isDefault) {
Wink Savilleb896b9f2013-10-23 15:44:26 -0700219 String displayMessage;
220
221 if (attemptsRemaining == 0) {
222 displayMessage = getContext().getString(R.string.kg_password_wrong_puk_code_dead);
223 } else if (attemptsRemaining > 0) {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530224 int msgId = isDefault ? R.plurals.kg_password_default_puk_message :
225 R.plurals.kg_password_wrong_puk_code;
Wink Savilleb896b9f2013-10-23 15:44:26 -0700226 displayMessage = getContext().getResources()
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530227 .getQuantityString(msgId, attemptsRemaining, attemptsRemaining);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700228 } else {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530229 int msgId = isDefault ? R.string.kg_puk_enter_puk_hint :
230 R.string.kg_password_puk_failed;
231 displayMessage = getContext().getString(msgId);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700232 }
Qingxi Li2febffb2018-01-23 16:16:35 -0800233 if (KeyguardEsimArea.isEsimLocked(mContext, mSubId)) {
234 displayMessage = getResources()
235 .getString(R.string.kg_sim_lock_esim_instructions, displayMessage);
236 }
Wink Savilleb896b9f2013-10-23 15:44:26 -0700237 if (DEBUG) Log.d(LOG_TAG, "getPukPasswordErrorMessage:"
238 + " attemptsRemaining=" + attemptsRemaining + " displayMessage=" + displayMessage);
239 return displayMessage;
240 }
241
Jim Miller4db942c2016-05-16 18:06:50 -0700242 @Override
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400243 public void resetState() {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700244 super.resetState();
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400245 mStateMachine.reset();
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400246 }
247
248 @Override
Jim Miller7d5e00a2013-10-11 22:45:57 -0700249 protected boolean shouldLockout(long deadline) {
250 // SIM PUK doesn't have a timed lockout
251 return false;
252 }
253
254 @Override
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400255 protected int getPasswordTextViewId() {
Jorim Jaggifa9189f2014-04-17 20:17:30 +0200256 return R.id.pukEntry;
Jim Millerdcb3d842012-08-23 19:18:12 -0700257 }
258
259 @Override
260 protected void onFinishInflate() {
261 super.onFinishInflate();
Jim Miller0b728242012-10-28 19:42:30 -0700262
Jorim Jaggi40a0b382014-05-27 21:12:27 +0200263 if (mEcaView instanceof EmergencyCarrierArea) {
264 ((EmergencyCarrierArea) mEcaView).setCarrierTextVisible(true);
265 }
Alan Viverette51efddb2017-04-05 10:00:01 -0400266 mSimImageView = findViewById(R.id.keyguard_sim);
Jim Millerdcb3d842012-08-23 19:18:12 -0700267 }
268
Adam Cohen6fb841f2012-10-24 13:15:38 -0700269 @Override
Jim Miller52a61332014-11-12 19:29:51 -0800270 protected void onAttachedToWindow() {
271 super.onAttachedToWindow();
272 KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback);
273 }
274
275 @Override
276 protected void onDetachedFromWindow() {
277 super.onDetachedFromWindow();
278 KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateMonitorCallback);
279 }
280
281 @Override
Adam Cohen6fb841f2012-10-24 13:15:38 -0700282 public void showUsabilityHint() {
283 }
284
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400285 @Override
286 public void onPause() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700287 // dismiss the dialog.
288 if (mSimUnlockProgressDialog != null) {
289 mSimUnlockProgressDialog.dismiss();
290 mSimUnlockProgressDialog = null;
291 }
292 }
293
294 /**
295 * Since the IPC can block, we want to run the request in a separate thread
296 * with a callback.
297 */
298 private abstract class CheckSimPuk extends Thread {
299
300 private final String mPin, mPuk;
Jim Miller52a61332014-11-12 19:29:51 -0800301 private final int mSubId;
Jim Millerdcb3d842012-08-23 19:18:12 -0700302
Jim Miller52a61332014-11-12 19:29:51 -0800303 protected CheckSimPuk(String puk, String pin, int subId) {
Jim Millerdcb3d842012-08-23 19:18:12 -0700304 mPuk = puk;
305 mPin = pin;
Jim Miller52a61332014-11-12 19:29:51 -0800306 mSubId = subId;
Jim Millerdcb3d842012-08-23 19:18:12 -0700307 }
308
Wink Savilleb896b9f2013-10-23 15:44:26 -0700309 abstract void onSimLockChangedResponse(final int result, final int attemptsRemaining);
Jim Millerdcb3d842012-08-23 19:18:12 -0700310
311 @Override
312 public void run() {
313 try {
Jim Miller52a61332014-11-12 19:29:51 -0800314 if (DEBUG) Log.v(TAG, "call supplyPukReportResult()");
Wink Savilleb896b9f2013-10-23 15:44:26 -0700315 final int[] result = ITelephony.Stub.asInterface(ServiceManager
Jim Miller52a61332014-11-12 19:29:51 -0800316 .checkService("phone")).supplyPukReportResultForSubscriber(mSubId, mPuk, mPin);
317 if (DEBUG) {
318 Log.v(TAG, "supplyPukReportResult returned: " + result[0] + " " + result[1]);
319 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700320 post(new Runnable() {
Jim Miller4db942c2016-05-16 18:06:50 -0700321 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700322 public void run() {
Wink Savilleb896b9f2013-10-23 15:44:26 -0700323 onSimLockChangedResponse(result[0], result[1]);
Jim Millerdcb3d842012-08-23 19:18:12 -0700324 }
325 });
326 } catch (RemoteException e) {
Jim Miller4fc2b012013-11-04 16:47:48 -0800327 Log.e(TAG, "RemoteException for supplyPukReportResult:", e);
Jim Millerdcb3d842012-08-23 19:18:12 -0700328 post(new Runnable() {
Jim Miller4db942c2016-05-16 18:06:50 -0700329 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700330 public void run() {
Wink Savilleb896b9f2013-10-23 15:44:26 -0700331 onSimLockChangedResponse(PhoneConstants.PIN_GENERAL_FAILURE, -1);
Jim Millerdcb3d842012-08-23 19:18:12 -0700332 }
333 });
334 }
335 }
336 }
337
Jim Millerdcb3d842012-08-23 19:18:12 -0700338 private Dialog getSimUnlockProgressDialog() {
339 if (mSimUnlockProgressDialog == null) {
340 mSimUnlockProgressDialog = new ProgressDialog(mContext);
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400341 mSimUnlockProgressDialog.setMessage(
342 mContext.getString(R.string.kg_sim_unlock_progress_dialog_message));
Jim Millerdcb3d842012-08-23 19:18:12 -0700343 mSimUnlockProgressDialog.setIndeterminate(true);
344 mSimUnlockProgressDialog.setCancelable(false);
345 if (!(mContext instanceof Activity)) {
346 mSimUnlockProgressDialog.getWindow().setType(
347 WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
348 }
349 }
350 return mSimUnlockProgressDialog;
351 }
352
Wink Savilleb896b9f2013-10-23 15:44:26 -0700353 private Dialog getPukRemainingAttemptsDialog(int remaining) {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530354 String msg = getPukPasswordErrorMessage(remaining, false);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700355 if (mRemainingAttemptsDialog == null) {
356 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
357 builder.setMessage(msg);
358 builder.setCancelable(false);
359 builder.setNeutralButton(R.string.ok, null);
360 mRemainingAttemptsDialog = builder.create();
361 mRemainingAttemptsDialog.getWindow().setType(
362 WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
363 } else {
364 mRemainingAttemptsDialog.setMessage(msg);
365 }
366 return mRemainingAttemptsDialog;
367 }
368
Jim Miller3efe1062012-09-28 16:59:31 -0700369 private boolean checkPuk() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700370 // make sure the puk is at least 8 digits long.
Rakesh Pallerlab8b7bd32014-01-08 15:49:34 +0530371 if (mPasswordEntry.getText().length() == 8) {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700372 mPukText = mPasswordEntry.getText();
Jim Miller3efe1062012-09-28 16:59:31 -0700373 return true;
Jim Millerdcb3d842012-08-23 19:18:12 -0700374 }
Jim Miller3efe1062012-09-28 16:59:31 -0700375 return false;
376 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700377
Jim Miller3efe1062012-09-28 16:59:31 -0700378 private boolean checkPin() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700379 // make sure the PIN is between 4 and 8 digits
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400380 int length = mPasswordEntry.getText().length();
Jim Miller3efe1062012-09-28 16:59:31 -0700381 if (length >= 4 && length <= 8) {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700382 mPinText = mPasswordEntry.getText();
Jim Miller3efe1062012-09-28 16:59:31 -0700383 return true;
Jim Millerdcb3d842012-08-23 19:18:12 -0700384 }
Jim Miller3efe1062012-09-28 16:59:31 -0700385 return false;
386 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700387
Jim Miller3efe1062012-09-28 16:59:31 -0700388 public boolean confirmPin() {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700389 return mPinText.equals(mPasswordEntry.getText());
Jim Miller3efe1062012-09-28 16:59:31 -0700390 }
391
392 private void updateSim() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700393 getSimUnlockProgressDialog().show();
394
Jim Miller4fc2b012013-11-04 16:47:48 -0800395 if (mCheckSimPukThread == null) {
Jim Miller52a61332014-11-12 19:29:51 -0800396 mCheckSimPukThread = new CheckSimPuk(mPukText, mPinText, mSubId) {
Jim Miller4db942c2016-05-16 18:06:50 -0700397 @Override
Wink Savilleb896b9f2013-10-23 15:44:26 -0700398 void onSimLockChangedResponse(final int result, final int attemptsRemaining) {
Jim Miller3efe1062012-09-28 16:59:31 -0700399 post(new Runnable() {
Jim Miller4db942c2016-05-16 18:06:50 -0700400 @Override
Jim Miller4b09dd32012-09-04 14:27:25 -0700401 public void run() {
402 if (mSimUnlockProgressDialog != null) {
403 mSimUnlockProgressDialog.hide();
404 }
Jim Miller4db942c2016-05-16 18:06:50 -0700405 resetPasswordText(true /* animate */,
406 result != PhoneConstants.PIN_RESULT_SUCCESS /* announce */);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700407 if (result == PhoneConstants.PIN_RESULT_SUCCESS) {
Jim Miller52a61332014-11-12 19:29:51 -0800408 KeyguardUpdateMonitor.getInstance(getContext())
409 .reportSimUnlocked(mSubId);
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530410 mRemainingAttempts = -1;
411 mShowDefaultMessage = true;
412 if (mCallback != null) {
413 mCallback.dismiss(true, KeyguardUpdateMonitor.getCurrentUser());
414 }
Jim Miller4b09dd32012-09-04 14:27:25 -0700415 } else {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530416 mShowDefaultMessage = false;
Wink Savilleb896b9f2013-10-23 15:44:26 -0700417 if (result == PhoneConstants.PIN_PASSWORD_INCORRECT) {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530418 // show message
419 mSecurityMessageDisplay.setMessage(getPukPasswordErrorMessage(
420 attemptsRemaining, false));
Wink Savilleb896b9f2013-10-23 15:44:26 -0700421 if (attemptsRemaining <= 2) {
422 // this is getting critical - show dialog
423 getPukRemainingAttemptsDialog(attemptsRemaining).show();
424 } else {
425 // show message
426 mSecurityMessageDisplay.setMessage(
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530427 getPukPasswordErrorMessage(
428 attemptsRemaining, false));
Wink Savilleb896b9f2013-10-23 15:44:26 -0700429 }
430 } else {
431 mSecurityMessageDisplay.setMessage(getContext().getString(
Adrian Roosdb327e92016-10-12 16:41:28 -0700432 R.string.kg_password_puk_failed));
Wink Savilleb896b9f2013-10-23 15:44:26 -0700433 }
434 if (DEBUG) Log.d(LOG_TAG, "verifyPasswordAndUnlock "
435 + " UpdateSim.onSimCheckResponse: "
436 + " attemptsRemaining=" + attemptsRemaining);
Jim Miller3efe1062012-09-28 16:59:31 -0700437 mStateMachine.reset();
Jim Miller4b09dd32012-09-04 14:27:25 -0700438 }
Jim Miller4fc2b012013-11-04 16:47:48 -0800439 mCheckSimPukThread = null;
Jim Millerdcb3d842012-08-23 19:18:12 -0700440 }
Jim Miller4b09dd32012-09-04 14:27:25 -0700441 });
442 }
Jim Miller4fc2b012013-11-04 16:47:48 -0800443 };
444 mCheckSimPukThread.start();
Jim Miller4b09dd32012-09-04 14:27:25 -0700445 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700446 }
447
448 @Override
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400449 protected void verifyPasswordAndUnlock() {
450 mStateMachine.next();
Jim Miller9cf2c522012-10-04 22:02:29 -0700451 }
Jorim Jaggic14f8292014-05-27 02:25:45 +0200452
453 @Override
454 public void startAppearAnimation() {
455 // noop.
456 }
Jorim Jaggi76a16232014-08-08 17:00:47 +0200457
458 @Override
459 public boolean startDisappearAnimation(Runnable finishRunnable) {
460 return false;
461 }
Phil Weaver7d847b02018-02-13 16:02:35 -0800462
463 @Override
464 public CharSequence getTitle() {
465 return getContext().getString(
466 com.android.internal.R.string.keyguard_accessibility_sim_puk_unlock);
467 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700468}
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400469
470