1 /*
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  */
16 
17 package com.android.keyguard;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.util.Log;
22 
23 import com.android.systemui.R;
24 
25 
26 /**
27  * Displays a PIN pad for entering a PUK (Pin Unlock Kode) provided by a carrier.
28  */
29 public class KeyguardSimPukView extends KeyguardPinBasedInputView {
30     private static final boolean DEBUG = KeyguardConstants.DEBUG;
31     public static final String TAG = "KeyguardSimPukView";
32 
KeyguardSimPukView(Context context)33     public KeyguardSimPukView(Context context) {
34         this(context, null);
35     }
36 
KeyguardSimPukView(Context context, AttributeSet attrs)37     public KeyguardSimPukView(Context context, AttributeSet attrs) {
38         super(context, attrs);
39     }
40 
41     @Override
getPromptReasonStringRes(int reason)42     protected int getPromptReasonStringRes(int reason) {
43         // No message on SIM Puk
44         return 0;
45     }
46 
getPukPasswordErrorMessage( int attemptsRemaining, boolean isDefault, boolean isEsimLocked)47     String getPukPasswordErrorMessage(
48             int attemptsRemaining, boolean isDefault, boolean isEsimLocked) {
49         String displayMessage;
50 
51         if (attemptsRemaining == 0) {
52             displayMessage = getContext().getString(R.string.kg_password_wrong_puk_code_dead);
53         } else if (attemptsRemaining > 0) {
54             int msgId = isDefault ? R.plurals.kg_password_default_puk_message :
55                     R.plurals.kg_password_wrong_puk_code;
56             displayMessage = getContext().getResources()
57                     .getQuantityString(msgId, attemptsRemaining, attemptsRemaining);
58         } else {
59             int msgId = isDefault ? R.string.kg_puk_enter_puk_hint :
60                     R.string.kg_password_puk_failed;
61             displayMessage = getContext().getString(msgId);
62         }
63         if (isEsimLocked) {
64             displayMessage = getResources()
65                     .getString(R.string.kg_sim_lock_esim_instructions, displayMessage);
66         }
67         if (DEBUG) {
68             Log.d(TAG, "getPukPasswordErrorMessage:"
69                     + " attemptsRemaining=" + attemptsRemaining
70                     + " displayMessage=" + displayMessage);
71         }
72         return displayMessage;
73     }
74 
75     @Override
getPasswordTextViewId()76     protected int getPasswordTextViewId() {
77         return R.id.pukEntry;
78     }
79 
80     @Override
onFinishInflate()81     protected void onFinishInflate() {
82         super.onFinishInflate();
83 
84         if (mEcaView instanceof EmergencyCarrierArea) {
85             ((EmergencyCarrierArea) mEcaView).setCarrierTextVisible(true);
86         }
87     }
88 
89     @Override
startAppearAnimation()90     public void startAppearAnimation() {
91         // noop.
92     }
93 
94     @Override
startDisappearAnimation(Runnable finishRunnable)95     public boolean startDisappearAnimation(Runnable finishRunnable) {
96         return false;
97     }
98 
99     @Override
getTitle()100     public CharSequence getTitle() {
101         return getContext().getString(
102                 com.android.internal.R.string.keyguard_accessibility_sim_puk_unlock);
103     }
104 }
105 
106 
107