summaryrefslogtreecommitdiff
path: root/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukView.java
blob: a1adcd32c6db211b47fc99baf915eaf3ba2f47fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.keyguard;

import android.content.Context;
import android.telephony.SubscriptionInfo;
import android.util.AttributeSet;
import android.util.Log;

import com.android.systemui.Dependency;
import com.android.systemui.R;

import java.util.HashMap;
import java.util.Map;

/**
 * Displays a PIN pad for entering a PUK (Pin Unlock Kode) provided by a carrier.
 */
public class KeyguardSimPukView extends KeyguardPinBasedInputView {
    private static final boolean DEBUG = KeyguardConstants.DEBUG;
    public static final String TAG = "KeyguardSimPukView";
    private Map<String, String> mWrongPukCodeMessageMap =  new HashMap<>(4);

    public KeyguardSimPukView(Context context) {
        this(context, null);
    }

    public KeyguardSimPukView(Context context, AttributeSet attrs) {
        super(context, attrs);
        updateWrongPukMessageMap(context);
    }

    void updateWrongPukMessageMap(Context context) {
        String[] customizationConfigs = context.getResources().
                getStringArray(R.array.kg_wrong_puk_code_message_list);
        if ( customizationConfigs.length == 0 ){
            Log.d(TAG, "There is no customization PUK prompt");
            return;
        }
        for(String config : customizationConfigs ) {
            String[] kv = config.trim().split(":");
            if ( kv.length != 2) {
                Log.e(TAG, "invalid key value config " + config);
                continue;
            }
            mWrongPukCodeMessageMap.put(kv[0], kv[1]);
        }
    }

    private String getMessageTextForWrongPukCode(int subId) {
        String message = null;
        SubscriptionInfo info = Dependency.get(KeyguardUpdateMonitor.class)
                    .getSubscriptionInfoForSubId(subId);
        if ( info != null ) {
            String mccMNC = info.getMccString()+info.getMncString();
            message = mWrongPukCodeMessageMap.get(mccMNC);
        }
        return message;
    }

    @Override
    protected int getPromptReasonStringRes(int reason) {
        // No message on SIM Puk
        return 0;
    }

    String getPukPasswordErrorMessage(
            int attemptsRemaining, boolean isDefault, boolean isEsimLocked, int subId) {
        String displayMessage;

        if (attemptsRemaining == 0) {
            String message = getMessageTextForWrongPukCode(subId);
            if ( message == null ) {
                displayMessage = getContext().getString(R.string.kg_password_wrong_puk_code_dead);
            }else {
                displayMessage = message;
            }
        } else if (attemptsRemaining > 0) {
            int msgId = isDefault ? R.plurals.kg_password_default_puk_message :
                    R.plurals.kg_password_wrong_puk_code;
            displayMessage = getContext().getResources()
                    .getQuantityString(msgId, attemptsRemaining, attemptsRemaining);
        } else {
            int msgId = isDefault ? R.string.kg_puk_enter_puk_hint :
                    R.string.kg_password_puk_failed;
            displayMessage = getContext().getString(msgId);
        }
        if (isEsimLocked) {
            displayMessage = getResources()
                    .getString(R.string.kg_sim_lock_esim_instructions, displayMessage);
        }
        if (DEBUG) {
            Log.d(TAG, "getPukPasswordErrorMessage:"
                    + " attemptsRemaining=" + attemptsRemaining
                    + " displayMessage=" + displayMessage);
        }
        return displayMessage;
    }

    @Override
    protected int getPasswordTextViewId() {
        return R.id.pukEntry;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

        if (mEcaView instanceof EmergencyCarrierArea) {
            ((EmergencyCarrierArea) mEcaView).setCarrierTextVisible(true);
        }
    }

    @Override
    public void startAppearAnimation() {
        // noop.
    }

    @Override
    public boolean startDisappearAnimation(Runnable finishRunnable) {
        return false;
    }

    @Override
    public CharSequence getTitle() {
        return getContext().getString(
                com.android.internal.R.string.keyguard_accessibility_sim_puk_unlock);
    }
}