blob: 27f71d1ae2be102157fb70108983a5b2d161c6ee [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;
Lucas Dupin2e838ac2019-04-17 16:50:58 -070026import android.content.res.TypedArray;
Jorim Jaggid05064b2014-11-20 21:35:33 +010027import android.graphics.Color;
Jim Millerdcb3d842012-08-23 19:18:12 -070028import android.os.RemoteException;
29import android.os.ServiceManager;
Jim Miller52a61332014-11-12 19:29:51 -080030import android.telephony.SubscriptionInfo;
31import android.telephony.SubscriptionManager;
32import android.telephony.TelephonyManager;
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;
Jim Miller52a61332014-11-12 19:29:51 -080041import com.android.internal.telephony.IccCardConstants.State;
Gus Prevasab336792018-11-14 13:52:20 -050042import com.android.internal.telephony.PhoneConstants;
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 Ebingere6c6f722018-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;
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700168 TypedArray array = mContext.obtainStyledAttributes(new int[] { R.attr.wallpaperTextColor });
169 int color = array.getColor(0, Color.WHITE);
170 array.recycle();
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530171 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 }
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700185 if (mSecurityMessageDisplay != null) {
186 mSecurityMessageDisplay.setMessage(msg);
187 }
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530188 mSimImageView.setImageTintList(ColorStateList.valueOf(color));
189
190 // Sending empty PUK here to query the number of remaining PIN attempts
191 new CheckSimPuk("", "", mSubId) {
192 void onSimLockChangedResponse(final int result, final int attemptsRemaining) {
193 Log.d(LOG_TAG, "onSimCheckResponse " + " dummy One result" + result +
194 " attemptsRemaining=" + attemptsRemaining);
195 if (attemptsRemaining >= 0) {
196 mRemainingAttempts = attemptsRemaining;
197 mSecurityMessageDisplay.setMessage(
198 getPukPasswordErrorMessage(attemptsRemaining, true));
199 }
200 }
201 }.start();
202 }
203
204 private void handleSubInfoChangeIfNeeded() {
205 KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
206 int subId = monitor.getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED);
207 if (subId != mSubId && SubscriptionManager.isValidSubscriptionId(subId)) {
208 mSubId = subId;
209 mShowDefaultMessage = true;
210 mRemainingAttempts = -1;
211 }
212 }
213
Selim Cinek3122fa82015-06-18 01:38:59 -0700214 @Override
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800215 protected int getPromptReasonStringRes(int reason) {
Selim Cinek3122fa82015-06-18 01:38:59 -0700216 // No message on SIM Puk
217 return 0;
218 }
219
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530220 private String getPukPasswordErrorMessage(int attemptsRemaining, boolean isDefault) {
Wink Savilleb896b9f2013-10-23 15:44:26 -0700221 String displayMessage;
222
223 if (attemptsRemaining == 0) {
224 displayMessage = getContext().getString(R.string.kg_password_wrong_puk_code_dead);
225 } else if (attemptsRemaining > 0) {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530226 int msgId = isDefault ? R.plurals.kg_password_default_puk_message :
227 R.plurals.kg_password_wrong_puk_code;
Wink Savilleb896b9f2013-10-23 15:44:26 -0700228 displayMessage = getContext().getResources()
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530229 .getQuantityString(msgId, attemptsRemaining, attemptsRemaining);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700230 } else {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530231 int msgId = isDefault ? R.string.kg_puk_enter_puk_hint :
232 R.string.kg_password_puk_failed;
233 displayMessage = getContext().getString(msgId);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700234 }
Qingxi Li2febffb2018-01-23 16:16:35 -0800235 if (KeyguardEsimArea.isEsimLocked(mContext, mSubId)) {
236 displayMessage = getResources()
237 .getString(R.string.kg_sim_lock_esim_instructions, displayMessage);
238 }
Wink Savilleb896b9f2013-10-23 15:44:26 -0700239 if (DEBUG) Log.d(LOG_TAG, "getPukPasswordErrorMessage:"
240 + " attemptsRemaining=" + attemptsRemaining + " displayMessage=" + displayMessage);
241 return displayMessage;
242 }
243
Jim Miller4db942c2016-05-16 18:06:50 -0700244 @Override
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400245 public void resetState() {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700246 super.resetState();
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400247 mStateMachine.reset();
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400248 }
249
250 @Override
Jim Miller7d5e00a2013-10-11 22:45:57 -0700251 protected boolean shouldLockout(long deadline) {
252 // SIM PUK doesn't have a timed lockout
253 return false;
254 }
255
256 @Override
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400257 protected int getPasswordTextViewId() {
Jorim Jaggifa9189f2014-04-17 20:17:30 +0200258 return R.id.pukEntry;
Jim Millerdcb3d842012-08-23 19:18:12 -0700259 }
260
261 @Override
262 protected void onFinishInflate() {
263 super.onFinishInflate();
Jim Miller0b728242012-10-28 19:42:30 -0700264
Jorim Jaggi40a0b382014-05-27 21:12:27 +0200265 if (mEcaView instanceof EmergencyCarrierArea) {
266 ((EmergencyCarrierArea) mEcaView).setCarrierTextVisible(true);
267 }
Alan Viverette51efddb2017-04-05 10:00:01 -0400268 mSimImageView = findViewById(R.id.keyguard_sim);
Jim Millerdcb3d842012-08-23 19:18:12 -0700269 }
270
Adam Cohen6fb841f2012-10-24 13:15:38 -0700271 @Override
Jim Miller52a61332014-11-12 19:29:51 -0800272 protected void onAttachedToWindow() {
273 super.onAttachedToWindow();
274 KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback);
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700275 resetState();
Jim Miller52a61332014-11-12 19:29:51 -0800276 }
277
278 @Override
279 protected void onDetachedFromWindow() {
280 super.onDetachedFromWindow();
281 KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateMonitorCallback);
282 }
283
284 @Override
Adam Cohen6fb841f2012-10-24 13:15:38 -0700285 public void showUsabilityHint() {
286 }
287
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400288 @Override
289 public void onPause() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700290 // dismiss the dialog.
291 if (mSimUnlockProgressDialog != null) {
292 mSimUnlockProgressDialog.dismiss();
293 mSimUnlockProgressDialog = null;
294 }
295 }
296
297 /**
298 * Since the IPC can block, we want to run the request in a separate thread
299 * with a callback.
300 */
301 private abstract class CheckSimPuk extends Thread {
302
303 private final String mPin, mPuk;
Jim Miller52a61332014-11-12 19:29:51 -0800304 private final int mSubId;
Jim Millerdcb3d842012-08-23 19:18:12 -0700305
Jim Miller52a61332014-11-12 19:29:51 -0800306 protected CheckSimPuk(String puk, String pin, int subId) {
Jim Millerdcb3d842012-08-23 19:18:12 -0700307 mPuk = puk;
308 mPin = pin;
Jim Miller52a61332014-11-12 19:29:51 -0800309 mSubId = subId;
Jim Millerdcb3d842012-08-23 19:18:12 -0700310 }
311
Wink Savilleb896b9f2013-10-23 15:44:26 -0700312 abstract void onSimLockChangedResponse(final int result, final int attemptsRemaining);
Jim Millerdcb3d842012-08-23 19:18:12 -0700313
314 @Override
315 public void run() {
316 try {
Jim Miller52a61332014-11-12 19:29:51 -0800317 if (DEBUG) Log.v(TAG, "call supplyPukReportResult()");
Wink Savilleb896b9f2013-10-23 15:44:26 -0700318 final int[] result = ITelephony.Stub.asInterface(ServiceManager
Jim Miller52a61332014-11-12 19:29:51 -0800319 .checkService("phone")).supplyPukReportResultForSubscriber(mSubId, mPuk, mPin);
320 if (DEBUG) {
321 Log.v(TAG, "supplyPukReportResult returned: " + result[0] + " " + result[1]);
322 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700323 post(new Runnable() {
Jim Miller4db942c2016-05-16 18:06:50 -0700324 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700325 public void run() {
Wink Savilleb896b9f2013-10-23 15:44:26 -0700326 onSimLockChangedResponse(result[0], result[1]);
Jim Millerdcb3d842012-08-23 19:18:12 -0700327 }
328 });
329 } catch (RemoteException e) {
Jim Miller4fc2b012013-11-04 16:47:48 -0800330 Log.e(TAG, "RemoteException for supplyPukReportResult:", e);
Jim Millerdcb3d842012-08-23 19:18:12 -0700331 post(new Runnable() {
Jim Miller4db942c2016-05-16 18:06:50 -0700332 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700333 public void run() {
Wink Savilleb896b9f2013-10-23 15:44:26 -0700334 onSimLockChangedResponse(PhoneConstants.PIN_GENERAL_FAILURE, -1);
Jim Millerdcb3d842012-08-23 19:18:12 -0700335 }
336 });
337 }
338 }
339 }
340
Jim Millerdcb3d842012-08-23 19:18:12 -0700341 private Dialog getSimUnlockProgressDialog() {
342 if (mSimUnlockProgressDialog == null) {
343 mSimUnlockProgressDialog = new ProgressDialog(mContext);
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400344 mSimUnlockProgressDialog.setMessage(
345 mContext.getString(R.string.kg_sim_unlock_progress_dialog_message));
Jim Millerdcb3d842012-08-23 19:18:12 -0700346 mSimUnlockProgressDialog.setIndeterminate(true);
347 mSimUnlockProgressDialog.setCancelable(false);
348 if (!(mContext instanceof Activity)) {
349 mSimUnlockProgressDialog.getWindow().setType(
350 WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
351 }
352 }
353 return mSimUnlockProgressDialog;
354 }
355
Wink Savilleb896b9f2013-10-23 15:44:26 -0700356 private Dialog getPukRemainingAttemptsDialog(int remaining) {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530357 String msg = getPukPasswordErrorMessage(remaining, false);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700358 if (mRemainingAttemptsDialog == null) {
359 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
360 builder.setMessage(msg);
361 builder.setCancelable(false);
362 builder.setNeutralButton(R.string.ok, null);
363 mRemainingAttemptsDialog = builder.create();
364 mRemainingAttemptsDialog.getWindow().setType(
365 WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
366 } else {
367 mRemainingAttemptsDialog.setMessage(msg);
368 }
369 return mRemainingAttemptsDialog;
370 }
371
Jim Miller3efe1062012-09-28 16:59:31 -0700372 private boolean checkPuk() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700373 // make sure the puk is at least 8 digits long.
Rakesh Pallerlab8b7bd32014-01-08 15:49:34 +0530374 if (mPasswordEntry.getText().length() == 8) {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700375 mPukText = mPasswordEntry.getText();
Jim Miller3efe1062012-09-28 16:59:31 -0700376 return true;
Jim Millerdcb3d842012-08-23 19:18:12 -0700377 }
Jim Miller3efe1062012-09-28 16:59:31 -0700378 return false;
379 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700380
Jim Miller3efe1062012-09-28 16:59:31 -0700381 private boolean checkPin() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700382 // make sure the PIN is between 4 and 8 digits
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400383 int length = mPasswordEntry.getText().length();
Jim Miller3efe1062012-09-28 16:59:31 -0700384 if (length >= 4 && length <= 8) {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700385 mPinText = mPasswordEntry.getText();
Jim Miller3efe1062012-09-28 16:59:31 -0700386 return true;
Jim Millerdcb3d842012-08-23 19:18:12 -0700387 }
Jim Miller3efe1062012-09-28 16:59:31 -0700388 return false;
389 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700390
Jim Miller3efe1062012-09-28 16:59:31 -0700391 public boolean confirmPin() {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700392 return mPinText.equals(mPasswordEntry.getText());
Jim Miller3efe1062012-09-28 16:59:31 -0700393 }
394
395 private void updateSim() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700396 getSimUnlockProgressDialog().show();
397
Jim Miller4fc2b012013-11-04 16:47:48 -0800398 if (mCheckSimPukThread == null) {
Jim Miller52a61332014-11-12 19:29:51 -0800399 mCheckSimPukThread = new CheckSimPuk(mPukText, mPinText, mSubId) {
Jim Miller4db942c2016-05-16 18:06:50 -0700400 @Override
Wink Savilleb896b9f2013-10-23 15:44:26 -0700401 void onSimLockChangedResponse(final int result, final int attemptsRemaining) {
Jim Miller3efe1062012-09-28 16:59:31 -0700402 post(new Runnable() {
Jim Miller4db942c2016-05-16 18:06:50 -0700403 @Override
Jim Miller4b09dd32012-09-04 14:27:25 -0700404 public void run() {
405 if (mSimUnlockProgressDialog != null) {
406 mSimUnlockProgressDialog.hide();
407 }
Jim Miller4db942c2016-05-16 18:06:50 -0700408 resetPasswordText(true /* animate */,
409 result != PhoneConstants.PIN_RESULT_SUCCESS /* announce */);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700410 if (result == PhoneConstants.PIN_RESULT_SUCCESS) {
Jim Miller52a61332014-11-12 19:29:51 -0800411 KeyguardUpdateMonitor.getInstance(getContext())
412 .reportSimUnlocked(mSubId);
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530413 mRemainingAttempts = -1;
414 mShowDefaultMessage = true;
415 if (mCallback != null) {
416 mCallback.dismiss(true, KeyguardUpdateMonitor.getCurrentUser());
417 }
Jim Miller4b09dd32012-09-04 14:27:25 -0700418 } else {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530419 mShowDefaultMessage = false;
Wink Savilleb896b9f2013-10-23 15:44:26 -0700420 if (result == PhoneConstants.PIN_PASSWORD_INCORRECT) {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530421 // show message
422 mSecurityMessageDisplay.setMessage(getPukPasswordErrorMessage(
423 attemptsRemaining, false));
Wink Savilleb896b9f2013-10-23 15:44:26 -0700424 if (attemptsRemaining <= 2) {
425 // this is getting critical - show dialog
426 getPukRemainingAttemptsDialog(attemptsRemaining).show();
427 } else {
428 // show message
429 mSecurityMessageDisplay.setMessage(
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530430 getPukPasswordErrorMessage(
431 attemptsRemaining, false));
Wink Savilleb896b9f2013-10-23 15:44:26 -0700432 }
433 } else {
434 mSecurityMessageDisplay.setMessage(getContext().getString(
Adrian Roosdb327e92016-10-12 16:41:28 -0700435 R.string.kg_password_puk_failed));
Wink Savilleb896b9f2013-10-23 15:44:26 -0700436 }
437 if (DEBUG) Log.d(LOG_TAG, "verifyPasswordAndUnlock "
438 + " UpdateSim.onSimCheckResponse: "
439 + " attemptsRemaining=" + attemptsRemaining);
Jim Miller3efe1062012-09-28 16:59:31 -0700440 mStateMachine.reset();
Jim Miller4b09dd32012-09-04 14:27:25 -0700441 }
Jim Miller4fc2b012013-11-04 16:47:48 -0800442 mCheckSimPukThread = null;
Jim Millerdcb3d842012-08-23 19:18:12 -0700443 }
Jim Miller4b09dd32012-09-04 14:27:25 -0700444 });
445 }
Jim Miller4fc2b012013-11-04 16:47:48 -0800446 };
447 mCheckSimPukThread.start();
Jim Miller4b09dd32012-09-04 14:27:25 -0700448 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700449 }
450
451 @Override
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400452 protected void verifyPasswordAndUnlock() {
453 mStateMachine.next();
Jim Miller9cf2c522012-10-04 22:02:29 -0700454 }
Jorim Jaggic14f8292014-05-27 02:25:45 +0200455
456 @Override
457 public void startAppearAnimation() {
458 // noop.
459 }
Jorim Jaggi76a16232014-08-08 17:00:47 +0200460
461 @Override
462 public boolean startDisappearAnimation(Runnable finishRunnable) {
463 return false;
464 }
Phil Weaver7d847b02018-02-13 16:02:35 -0800465
466 @Override
467 public CharSequence getTitle() {
468 return getContext().getString(
469 com.android.internal.R.string.keyguard_accessibility_sim_puk_unlock);
470 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700471}
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400472
473