blob: 81f8c67605fe1b05d63e9ce9728b7f30574add0c [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;
Sunny Goyal87fccf02019-08-13 17:39:10 -070043import com.android.systemui.R;
Wink Savilleb896b9f2013-10-23 15:44:26 -070044
45
Daniel Sandler23d7a6e2012-11-02 00:21:07 -040046/**
47 * Displays a PIN pad for entering a PUK (Pin Unlock Kode) provided by a carrier.
48 */
Selim Cinek4e8b9ed2014-06-20 16:37:04 -070049public class KeyguardSimPukView extends KeyguardPinBasedInputView {
Wink Savilleb896b9f2013-10-23 15:44:26 -070050 private static final String LOG_TAG = "KeyguardSimPukView";
Jorim Jaggi5cf17872014-03-26 18:31:48 +010051 private static final boolean DEBUG = KeyguardConstants.DEBUG;
Jim Miller4fc2b012013-11-04 16:47:48 -080052 public static final String TAG = "KeyguardSimPukView";
Jim Millerdcb3d842012-08-23 19:18:12 -070053
54 private ProgressDialog mSimUnlockProgressDialog = null;
Jim Miller4fc2b012013-11-04 16:47:48 -080055 private CheckSimPuk mCheckSimPukThread;
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +053056
57 // Below flag is set to true during power-up or when a new SIM card inserted on device.
58 // When this is true and when SIM card is PUK locked state, on PIN lock screen, message would
59 // be displayed to inform user about the number of remaining PUK attempts left.
60 private boolean mShowDefaultMessage = true;
61 private int mRemainingAttempts = -1;
Jim Miller3efe1062012-09-28 16:59:31 -070062 private String mPukText;
Jim Miller3efe1062012-09-28 16:59:31 -070063 private String mPinText;
64 private StateMachine mStateMachine = new StateMachine();
Wink Savilleb896b9f2013-10-23 15:44:26 -070065 private AlertDialog mRemainingAttemptsDialog;
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +053066 private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Jorim Jaggid05064b2014-11-20 21:35:33 +010067 private ImageView mSimImageView;
Jim Miller52a61332014-11-12 19:29:51 -080068
69 KeyguardUpdateMonitorCallback mUpdateMonitorCallback = new KeyguardUpdateMonitorCallback() {
70 @Override
71 public void onSimStateChanged(int subId, int slotId, State simState) {
Brad Ebinger4cd3bdc2017-08-21 14:58:52 -070072 if (DEBUG) Log.v(TAG, "onSimStateChanged(subId=" + subId + ",state=" + simState + ")");
73 switch(simState) {
Brad Ebinger4cd3bdc2017-08-21 14:58:52 -070074 // If the SIM is unlocked via a key sequence through the emergency dialer, it will
75 // move into the READY state and the PUK lock keyguard should be removed.
76 case READY: {
Brad Ebingere6c6f722018-12-20 21:11:44 -080077 mRemainingAttempts = -1;
78 mShowDefaultMessage = true;
Brad Ebinger71306752017-10-05 11:39:06 -070079 // mCallback can be null if onSimStateChanged callback is called when keyguard
80 // isn't active.
81 if (mCallback != null) {
82 mCallback.dismiss(true, KeyguardUpdateMonitor.getCurrentUser());
83 }
Brad Ebinger4cd3bdc2017-08-21 14:58:52 -070084 break;
85 }
86 default:
87 resetState();
88 }
89 }
Jim Miller52a61332014-11-12 19:29:51 -080090 };
91
92 public KeyguardSimPukView(Context context) {
93 this(context, null);
94 }
95
96 public KeyguardSimPukView(Context context, AttributeSet attrs) {
97 super(context, attrs);
98 }
Jim Miller3efe1062012-09-28 16:59:31 -070099
100 private class StateMachine {
101 final int ENTER_PUK = 0;
102 final int ENTER_PIN = 1;
103 final int CONFIRM_PIN = 2;
104 final int DONE = 3;
105 private int state = ENTER_PUK;
106
107 public void next() {
108 int msg = 0;
109 if (state == ENTER_PUK) {
110 if (checkPuk()) {
111 state = ENTER_PIN;
112 msg = R.string.kg_puk_enter_pin_hint;
113 } else {
114 msg = R.string.kg_invalid_sim_puk_hint;
115 }
116 } else if (state == ENTER_PIN) {
117 if (checkPin()) {
118 state = CONFIRM_PIN;
119 msg = R.string.kg_enter_confirm_pin_hint;
120 } else {
121 msg = R.string.kg_invalid_sim_pin_hint;
122 }
123 } else if (state == CONFIRM_PIN) {
124 if (confirmPin()) {
125 state = DONE;
Jim Miller5ecd8112013-01-09 18:50:26 -0800126 msg = R.string.keyguard_sim_unlock_progress_dialog_message;
Jim Miller3efe1062012-09-28 16:59:31 -0700127 updateSim();
128 } else {
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400129 state = ENTER_PIN; // try again?
Jim Miller3efe1062012-09-28 16:59:31 -0700130 msg = R.string.kg_invalid_confirm_pin_hint;
131 }
132 }
Jim Miller4db942c2016-05-16 18:06:50 -0700133 resetPasswordText(true /* animate */, true /* announce */);
Jim Miller3efe1062012-09-28 16:59:31 -0700134 if (msg != 0) {
Adrian Roosdb327e92016-10-12 16:41:28 -0700135 mSecurityMessageDisplay.setMessage(msg);
Jim Miller3efe1062012-09-28 16:59:31 -0700136 }
137 }
138
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530139
Jim Miller3efe1062012-09-28 16:59:31 -0700140 void reset() {
141 mPinText="";
142 mPukText="";
143 state = ENTER_PUK;
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530144 handleSubInfoChangeIfNeeded();
145 if (mShowDefaultMessage) {
146 showDefaultMessage();
Jim Miller52a61332014-11-12 19:29:51 -0800147 }
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530148 boolean isEsimLocked = KeyguardEsimArea.isEsimLocked(mContext, mSubId);
149
qingxi12f2de42017-05-24 15:33:13 -0700150 KeyguardEsimArea esimButton = findViewById(R.id.keyguard_esim_area);
151 esimButton.setVisibility(isEsimLocked ? View.VISIBLE : View.GONE);
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400152 mPasswordEntry.requestFocus();
Jim Miller3efe1062012-09-28 16:59:31 -0700153 }
qingxi12f2de42017-05-24 15:33:13 -0700154
155
Jim Miller3efe1062012-09-28 16:59:31 -0700156 }
157
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530158 private void showDefaultMessage() {
159 if (mRemainingAttempts >= 0) {
160 mSecurityMessageDisplay.setMessage(getPukPasswordErrorMessage(
161 mRemainingAttempts, true));
162 return;
163 }
164
165 boolean isEsimLocked = KeyguardEsimArea.isEsimLocked(mContext, mSubId);
166 int count = TelephonyManager.getDefault().getSimCount();
167 Resources rez = getResources();
168 String msg;
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700169 TypedArray array = mContext.obtainStyledAttributes(new int[] { R.attr.wallpaperTextColor });
170 int color = array.getColor(0, Color.WHITE);
171 array.recycle();
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530172 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 }
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700186 if (mSecurityMessageDisplay != null) {
187 mSecurityMessageDisplay.setMessage(msg);
188 }
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530189 mSimImageView.setImageTintList(ColorStateList.valueOf(color));
190
191 // Sending empty PUK here to query the number of remaining PIN attempts
192 new CheckSimPuk("", "", mSubId) {
193 void onSimLockChangedResponse(final int result, final int attemptsRemaining) {
194 Log.d(LOG_TAG, "onSimCheckResponse " + " dummy One result" + result +
195 " attemptsRemaining=" + attemptsRemaining);
196 if (attemptsRemaining >= 0) {
197 mRemainingAttempts = attemptsRemaining;
198 mSecurityMessageDisplay.setMessage(
199 getPukPasswordErrorMessage(attemptsRemaining, true));
200 }
201 }
202 }.start();
203 }
204
205 private void handleSubInfoChangeIfNeeded() {
206 KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
207 int subId = monitor.getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED);
208 if (subId != mSubId && SubscriptionManager.isValidSubscriptionId(subId)) {
209 mSubId = subId;
210 mShowDefaultMessage = true;
211 mRemainingAttempts = -1;
212 }
213 }
214
Selim Cinek3122fa82015-06-18 01:38:59 -0700215 @Override
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800216 protected int getPromptReasonStringRes(int reason) {
Selim Cinek3122fa82015-06-18 01:38:59 -0700217 // No message on SIM Puk
218 return 0;
219 }
220
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530221 private String getPukPasswordErrorMessage(int attemptsRemaining, boolean isDefault) {
Wink Savilleb896b9f2013-10-23 15:44:26 -0700222 String displayMessage;
223
224 if (attemptsRemaining == 0) {
225 displayMessage = getContext().getString(R.string.kg_password_wrong_puk_code_dead);
226 } else if (attemptsRemaining > 0) {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530227 int msgId = isDefault ? R.plurals.kg_password_default_puk_message :
228 R.plurals.kg_password_wrong_puk_code;
Wink Savilleb896b9f2013-10-23 15:44:26 -0700229 displayMessage = getContext().getResources()
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530230 .getQuantityString(msgId, attemptsRemaining, attemptsRemaining);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700231 } else {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530232 int msgId = isDefault ? R.string.kg_puk_enter_puk_hint :
233 R.string.kg_password_puk_failed;
234 displayMessage = getContext().getString(msgId);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700235 }
Qingxi Li2febffb2018-01-23 16:16:35 -0800236 if (KeyguardEsimArea.isEsimLocked(mContext, mSubId)) {
237 displayMessage = getResources()
238 .getString(R.string.kg_sim_lock_esim_instructions, displayMessage);
239 }
Wink Savilleb896b9f2013-10-23 15:44:26 -0700240 if (DEBUG) Log.d(LOG_TAG, "getPukPasswordErrorMessage:"
241 + " attemptsRemaining=" + attemptsRemaining + " displayMessage=" + displayMessage);
242 return displayMessage;
243 }
244
Jim Miller4db942c2016-05-16 18:06:50 -0700245 @Override
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400246 public void resetState() {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700247 super.resetState();
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400248 mStateMachine.reset();
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400249 }
250
251 @Override
Jim Miller7d5e00a2013-10-11 22:45:57 -0700252 protected boolean shouldLockout(long deadline) {
253 // SIM PUK doesn't have a timed lockout
254 return false;
255 }
256
257 @Override
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400258 protected int getPasswordTextViewId() {
Jorim Jaggifa9189f2014-04-17 20:17:30 +0200259 return R.id.pukEntry;
Jim Millerdcb3d842012-08-23 19:18:12 -0700260 }
261
262 @Override
263 protected void onFinishInflate() {
264 super.onFinishInflate();
Jim Miller0b728242012-10-28 19:42:30 -0700265
Jorim Jaggi40a0b382014-05-27 21:12:27 +0200266 if (mEcaView instanceof EmergencyCarrierArea) {
267 ((EmergencyCarrierArea) mEcaView).setCarrierTextVisible(true);
268 }
Alan Viverette51efddb2017-04-05 10:00:01 -0400269 mSimImageView = findViewById(R.id.keyguard_sim);
Jim Millerdcb3d842012-08-23 19:18:12 -0700270 }
271
Adam Cohen6fb841f2012-10-24 13:15:38 -0700272 @Override
Jim Miller52a61332014-11-12 19:29:51 -0800273 protected void onAttachedToWindow() {
274 super.onAttachedToWindow();
275 KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback);
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700276 resetState();
Jim Miller52a61332014-11-12 19:29:51 -0800277 }
278
279 @Override
280 protected void onDetachedFromWindow() {
281 super.onDetachedFromWindow();
282 KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateMonitorCallback);
283 }
284
285 @Override
Adam Cohen6fb841f2012-10-24 13:15:38 -0700286 public void showUsabilityHint() {
287 }
288
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400289 @Override
290 public void onPause() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700291 // dismiss the dialog.
292 if (mSimUnlockProgressDialog != null) {
293 mSimUnlockProgressDialog.dismiss();
294 mSimUnlockProgressDialog = null;
295 }
296 }
297
298 /**
299 * Since the IPC can block, we want to run the request in a separate thread
300 * with a callback.
301 */
302 private abstract class CheckSimPuk extends Thread {
303
304 private final String mPin, mPuk;
Jim Miller52a61332014-11-12 19:29:51 -0800305 private final int mSubId;
Jim Millerdcb3d842012-08-23 19:18:12 -0700306
Jim Miller52a61332014-11-12 19:29:51 -0800307 protected CheckSimPuk(String puk, String pin, int subId) {
Jim Millerdcb3d842012-08-23 19:18:12 -0700308 mPuk = puk;
309 mPin = pin;
Jim Miller52a61332014-11-12 19:29:51 -0800310 mSubId = subId;
Jim Millerdcb3d842012-08-23 19:18:12 -0700311 }
312
Wink Savilleb896b9f2013-10-23 15:44:26 -0700313 abstract void onSimLockChangedResponse(final int result, final int attemptsRemaining);
Jim Millerdcb3d842012-08-23 19:18:12 -0700314
315 @Override
316 public void run() {
317 try {
Jim Miller52a61332014-11-12 19:29:51 -0800318 if (DEBUG) Log.v(TAG, "call supplyPukReportResult()");
Wink Savilleb896b9f2013-10-23 15:44:26 -0700319 final int[] result = ITelephony.Stub.asInterface(ServiceManager
Jim Miller52a61332014-11-12 19:29:51 -0800320 .checkService("phone")).supplyPukReportResultForSubscriber(mSubId, mPuk, mPin);
321 if (DEBUG) {
322 Log.v(TAG, "supplyPukReportResult returned: " + result[0] + " " + result[1]);
323 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700324 post(new Runnable() {
Jim Miller4db942c2016-05-16 18:06:50 -0700325 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700326 public void run() {
Wink Savilleb896b9f2013-10-23 15:44:26 -0700327 onSimLockChangedResponse(result[0], result[1]);
Jim Millerdcb3d842012-08-23 19:18:12 -0700328 }
329 });
330 } catch (RemoteException e) {
Jim Miller4fc2b012013-11-04 16:47:48 -0800331 Log.e(TAG, "RemoteException for supplyPukReportResult:", e);
Jim Millerdcb3d842012-08-23 19:18:12 -0700332 post(new Runnable() {
Jim Miller4db942c2016-05-16 18:06:50 -0700333 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700334 public void run() {
Wink Savilleb896b9f2013-10-23 15:44:26 -0700335 onSimLockChangedResponse(PhoneConstants.PIN_GENERAL_FAILURE, -1);
Jim Millerdcb3d842012-08-23 19:18:12 -0700336 }
337 });
338 }
339 }
340 }
341
Jim Millerdcb3d842012-08-23 19:18:12 -0700342 private Dialog getSimUnlockProgressDialog() {
343 if (mSimUnlockProgressDialog == null) {
344 mSimUnlockProgressDialog = new ProgressDialog(mContext);
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400345 mSimUnlockProgressDialog.setMessage(
346 mContext.getString(R.string.kg_sim_unlock_progress_dialog_message));
Jim Millerdcb3d842012-08-23 19:18:12 -0700347 mSimUnlockProgressDialog.setIndeterminate(true);
348 mSimUnlockProgressDialog.setCancelable(false);
349 if (!(mContext instanceof Activity)) {
350 mSimUnlockProgressDialog.getWindow().setType(
351 WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
352 }
353 }
354 return mSimUnlockProgressDialog;
355 }
356
Wink Savilleb896b9f2013-10-23 15:44:26 -0700357 private Dialog getPukRemainingAttemptsDialog(int remaining) {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530358 String msg = getPukPasswordErrorMessage(remaining, false);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700359 if (mRemainingAttemptsDialog == null) {
360 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
361 builder.setMessage(msg);
362 builder.setCancelable(false);
363 builder.setNeutralButton(R.string.ok, null);
364 mRemainingAttemptsDialog = builder.create();
365 mRemainingAttemptsDialog.getWindow().setType(
366 WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
367 } else {
368 mRemainingAttemptsDialog.setMessage(msg);
369 }
370 return mRemainingAttemptsDialog;
371 }
372
Jim Miller3efe1062012-09-28 16:59:31 -0700373 private boolean checkPuk() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700374 // make sure the puk is at least 8 digits long.
Rakesh Pallerlab8b7bd32014-01-08 15:49:34 +0530375 if (mPasswordEntry.getText().length() == 8) {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700376 mPukText = mPasswordEntry.getText();
Jim Miller3efe1062012-09-28 16:59:31 -0700377 return true;
Jim Millerdcb3d842012-08-23 19:18:12 -0700378 }
Jim Miller3efe1062012-09-28 16:59:31 -0700379 return false;
380 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700381
Jim Miller3efe1062012-09-28 16:59:31 -0700382 private boolean checkPin() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700383 // make sure the PIN is between 4 and 8 digits
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400384 int length = mPasswordEntry.getText().length();
Jim Miller3efe1062012-09-28 16:59:31 -0700385 if (length >= 4 && length <= 8) {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700386 mPinText = mPasswordEntry.getText();
Jim Miller3efe1062012-09-28 16:59:31 -0700387 return true;
Jim Millerdcb3d842012-08-23 19:18:12 -0700388 }
Jim Miller3efe1062012-09-28 16:59:31 -0700389 return false;
390 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700391
Jim Miller3efe1062012-09-28 16:59:31 -0700392 public boolean confirmPin() {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -0700393 return mPinText.equals(mPasswordEntry.getText());
Jim Miller3efe1062012-09-28 16:59:31 -0700394 }
395
396 private void updateSim() {
Jim Millerdcb3d842012-08-23 19:18:12 -0700397 getSimUnlockProgressDialog().show();
398
Jim Miller4fc2b012013-11-04 16:47:48 -0800399 if (mCheckSimPukThread == null) {
Jim Miller52a61332014-11-12 19:29:51 -0800400 mCheckSimPukThread = new CheckSimPuk(mPukText, mPinText, mSubId) {
Jim Miller4db942c2016-05-16 18:06:50 -0700401 @Override
Wink Savilleb896b9f2013-10-23 15:44:26 -0700402 void onSimLockChangedResponse(final int result, final int attemptsRemaining) {
Jim Miller3efe1062012-09-28 16:59:31 -0700403 post(new Runnable() {
Jim Miller4db942c2016-05-16 18:06:50 -0700404 @Override
Jim Miller4b09dd32012-09-04 14:27:25 -0700405 public void run() {
406 if (mSimUnlockProgressDialog != null) {
407 mSimUnlockProgressDialog.hide();
408 }
Jim Miller4db942c2016-05-16 18:06:50 -0700409 resetPasswordText(true /* animate */,
410 result != PhoneConstants.PIN_RESULT_SUCCESS /* announce */);
Wink Savilleb896b9f2013-10-23 15:44:26 -0700411 if (result == PhoneConstants.PIN_RESULT_SUCCESS) {
Jim Miller52a61332014-11-12 19:29:51 -0800412 KeyguardUpdateMonitor.getInstance(getContext())
413 .reportSimUnlocked(mSubId);
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530414 mRemainingAttempts = -1;
415 mShowDefaultMessage = true;
416 if (mCallback != null) {
417 mCallback.dismiss(true, KeyguardUpdateMonitor.getCurrentUser());
418 }
Jim Miller4b09dd32012-09-04 14:27:25 -0700419 } else {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530420 mShowDefaultMessage = false;
Wink Savilleb896b9f2013-10-23 15:44:26 -0700421 if (result == PhoneConstants.PIN_PASSWORD_INCORRECT) {
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530422 // show message
423 mSecurityMessageDisplay.setMessage(getPukPasswordErrorMessage(
424 attemptsRemaining, false));
Wink Savilleb896b9f2013-10-23 15:44:26 -0700425 if (attemptsRemaining <= 2) {
426 // this is getting critical - show dialog
427 getPukRemainingAttemptsDialog(attemptsRemaining).show();
428 } else {
429 // show message
430 mSecurityMessageDisplay.setMessage(
Ruthwar Kumar Ambeer118e5742017-03-09 18:46:17 +0530431 getPukPasswordErrorMessage(
432 attemptsRemaining, false));
Wink Savilleb896b9f2013-10-23 15:44:26 -0700433 }
434 } else {
435 mSecurityMessageDisplay.setMessage(getContext().getString(
Adrian Roosdb327e92016-10-12 16:41:28 -0700436 R.string.kg_password_puk_failed));
Wink Savilleb896b9f2013-10-23 15:44:26 -0700437 }
438 if (DEBUG) Log.d(LOG_TAG, "verifyPasswordAndUnlock "
439 + " UpdateSim.onSimCheckResponse: "
440 + " attemptsRemaining=" + attemptsRemaining);
Jim Miller3efe1062012-09-28 16:59:31 -0700441 mStateMachine.reset();
Jim Miller4b09dd32012-09-04 14:27:25 -0700442 }
Jim Miller4fc2b012013-11-04 16:47:48 -0800443 mCheckSimPukThread = null;
Jim Millerdcb3d842012-08-23 19:18:12 -0700444 }
Jim Miller4b09dd32012-09-04 14:27:25 -0700445 });
446 }
Jim Miller4fc2b012013-11-04 16:47:48 -0800447 };
448 mCheckSimPukThread.start();
Jim Miller4b09dd32012-09-04 14:27:25 -0700449 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700450 }
451
452 @Override
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400453 protected void verifyPasswordAndUnlock() {
454 mStateMachine.next();
Jim Miller9cf2c522012-10-04 22:02:29 -0700455 }
Jorim Jaggic14f8292014-05-27 02:25:45 +0200456
457 @Override
458 public void startAppearAnimation() {
459 // noop.
460 }
Jorim Jaggi76a16232014-08-08 17:00:47 +0200461
462 @Override
463 public boolean startDisappearAnimation(Runnable finishRunnable) {
464 return false;
465 }
Phil Weaver7d847b02018-02-13 16:02:35 -0800466
467 @Override
468 public CharSequence getTitle() {
469 return getContext().getString(
470 com.android.internal.R.string.keyguard_accessibility_sim_puk_unlock);
471 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700472}
Daniel Sandler23d7a6e2012-11-02 00:21:07 -0400473
474