blob: a0a36878634a9a140b6238b46a692c1b981c85c9 [file] [log] [blame]
Jim Miller109f1fd2012-09-19 20:44:16 -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 */
16
Jim Miller5ecd8112013-01-09 18:50:26 -080017package com.android.keyguard;
Jim Millerf9cb7ba2012-09-17 22:31:56 -070018
Jason Monk9ff69bd2014-12-02 16:43:17 -050019import java.util.List;
20import java.util.Locale;
Sanket Padaweb8726b72015-04-01 14:02:16 -070021import java.util.Objects;
Jason Monk9ff69bd2014-12-02 16:43:17 -050022
Jim Millerf9cb7ba2012-09-17 22:31:56 -070023import android.content.Context;
Jason Monkde3260b2015-02-24 08:55:26 -050024import android.content.Intent;
25import android.content.IntentFilter;
Jorim Jaggi25807932014-04-24 23:29:46 +020026import android.content.res.TypedArray;
Jason Monk83bc2aaf2014-12-05 10:16:24 -050027import android.net.ConnectivityManager;
Etan Cohen47051d82015-07-06 16:19:04 -070028import android.net.wifi.WifiManager;
29import android.telephony.ServiceState;
Jason Monk9ff69bd2014-12-02 16:43:17 -050030import android.telephony.SubscriptionInfo;
Jim Millerf9cb7ba2012-09-17 22:31:56 -070031import android.text.TextUtils;
Jason Monk9ff69bd2014-12-02 16:43:17 -050032import android.text.method.SingleLineTransformationMethod;
Jim Millerf9cb7ba2012-09-17 22:31:56 -070033import android.util.AttributeSet;
Jason Monk9ff69bd2014-12-02 16:43:17 -050034import android.util.Log;
Victoria Lease1d80e972013-11-01 16:34:03 -070035import android.view.View;
Jim Millerf9cb7ba2012-09-17 22:31:56 -070036import android.widget.TextView;
37
Jim Millerf9cb7ba2012-09-17 22:31:56 -070038import com.android.internal.telephony.IccCardConstants;
39import com.android.internal.telephony.IccCardConstants.State;
Jason Monkde3260b2015-02-24 08:55:26 -050040import com.android.internal.telephony.TelephonyIntents;
Jason Monk726fb282015-03-31 12:56:11 -040041import com.android.settingslib.WirelessUtils;
Amin Shaikh0e003312018-03-08 11:39:01 -050042
Wileen Chiu6b8b22e2014-10-29 22:48:21 +053043import android.telephony.TelephonyManager;
Jim Millerf9cb7ba2012-09-17 22:31:56 -070044
45public class CarrierText extends TextView {
Jason Monk9ff69bd2014-12-02 16:43:17 -050046 private static final boolean DEBUG = KeyguardConstants.DEBUG;
47 private static final String TAG = "CarrierText";
48
Jim Millere9be1402012-11-01 16:14:20 -070049 private static CharSequence mSeparator;
50
Adrian Roosc2e01682015-01-15 23:20:20 +010051 private final boolean mIsEmergencyCallCapable;
52
Bill Linef81cbd2018-07-05 17:48:49 +080053 private boolean mTelephonyCapable;
54
55 private boolean mShowMissingSim;
56
57 private boolean mShowAirplaneMode;
58
Jason Monk9ff69bd2014-12-02 16:43:17 -050059 private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
Jim Millerf9cb7ba2012-09-17 22:31:56 -070060
Etan Cohen47051d82015-07-06 16:19:04 -070061 private WifiManager mWifiManager;
62
Wileen Chiu6b8b22e2014-10-29 22:48:21 +053063 private boolean[] mSimErrorState = new boolean[TelephonyManager.getDefault().getPhoneCount()];
64
Bill Linef81cbd2018-07-05 17:48:49 +080065 private final KeyguardUpdateMonitorCallback mCallback = new KeyguardUpdateMonitorCallback() {
Jim Millerf9cb7ba2012-09-17 22:31:56 -070066 @Override
Jason Monk9ff69bd2014-12-02 16:43:17 -050067 public void onRefreshCarrierInfo() {
Bill Linef81cbd2018-07-05 17:48:49 +080068 if (DEBUG) Log.d(TAG, "onRefreshCarrierInfo(), mTelephonyCapable: "
69 + Boolean.toString(mTelephonyCapable));
Jason Monk9ff69bd2014-12-02 16:43:17 -050070 updateCarrierText();
Jim Millerf9cb7ba2012-09-17 22:31:56 -070071 }
Jim Miller20daffd2013-10-07 14:59:53 -070072
Jorim Jaggi0d210f62015-07-10 14:24:44 -070073 public void onFinishedGoingToSleep(int why) {
Jim Miller20daffd2013-10-07 14:59:53 -070074 setSelected(false);
75 };
76
Jorim Jaggi0d210f62015-07-10 14:24:44 -070077 public void onStartedWakingUp() {
Jim Miller20daffd2013-10-07 14:59:53 -070078 setSelected(true);
79 };
Wileen Chiu6b8b22e2014-10-29 22:48:21 +053080
Bill Linef81cbd2018-07-05 17:48:49 +080081 @Override
82 public void onTelephonyCapable(boolean capable) {
83 if (DEBUG) Log.d(TAG, "onTelephonyCapable() mTelephonyCapable: "
84 + Boolean.toString(capable));
85 mTelephonyCapable = capable;
86 updateCarrierText();
87 }
88
Wileen Chiu6b8b22e2014-10-29 22:48:21 +053089 public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) {
90 if (slotId < 0) {
Bill Linef81cbd2018-07-05 17:48:49 +080091 Log.d(TAG, "onSimStateChanged() - slotId invalid: " + slotId
92 + " mTelephonyCapable: " + Boolean.toString(mTelephonyCapable));
Wileen Chiu6b8b22e2014-10-29 22:48:21 +053093 return;
94 }
95
96 if (DEBUG) Log.d(TAG,"onSimStateChanged: " + getStatusForIccState(simState));
97 if (getStatusForIccState(simState) == StatusMode.SimIoError) {
98 mSimErrorState[slotId] = true;
99 updateCarrierText();
100 } else if (mSimErrorState[slotId]) {
101 mSimErrorState[slotId] = false;
102 updateCarrierText();
103 }
Bill Linef81cbd2018-07-05 17:48:49 +0800104 }
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700105 };
Amin Shaikh0e003312018-03-08 11:39:01 -0500106
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700107 /**
108 * The status of this lock screen. Primarily used for widgets on LockScreen.
109 */
Jim Miller109f1fd2012-09-19 20:44:16 -0700110 private static enum StatusMode {
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700111 Normal, // Normal case (sim card present, it's not locked)
112 NetworkLocked, // SIM card is 'network locked'.
113 SimMissing, // SIM card is missing.
114 SimMissingLocked, // SIM card is missing, and device isn't provisioned; don't allow access
115 SimPukLocked, // SIM card is PUK locked because SIM entered wrong too many times
116 SimLocked, // SIM card is currently locked
Jim Miller109f1fd2012-09-19 20:44:16 -0700117 SimPermDisabled, // SIM card is permanently disabled due to PUK unlock failure
Wileen Chiu6b8b22e2014-10-29 22:48:21 +0530118 SimNotReady, // SIM is not ready yet. May never be on devices w/o a SIM.
Bill Linef81cbd2018-07-05 17:48:49 +0800119 SimIoError, // SIM card is faulty
120 SimUnknown // SIM card is unknown
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700121 }
122
123 public CarrierText(Context context) {
124 this(context, null);
125 }
126
127 public CarrierText(Context context, AttributeSet attrs) {
128 super(context, attrs);
Adrian Roosc2e01682015-01-15 23:20:20 +0100129 mIsEmergencyCallCapable = context.getResources().getBoolean(
130 com.android.internal.R.bool.config_voice_capable);
Jorim Jaggi25807932014-04-24 23:29:46 +0200131 boolean useAllCaps;
132 TypedArray a = context.getTheme().obtainStyledAttributes(
133 attrs, R.styleable.CarrierText, 0, 0);
134 try {
135 useAllCaps = a.getBoolean(R.styleable.CarrierText_allCaps, false);
Bill Linef81cbd2018-07-05 17:48:49 +0800136 mShowAirplaneMode = a.getBoolean(R.styleable.CarrierText_showAirplaneMode, false);
137 mShowMissingSim = a.getBoolean(R.styleable.CarrierText_showMissingSim, false);
Jorim Jaggi25807932014-04-24 23:29:46 +0200138 } finally {
139 a.recycle();
140 }
Victoria Lease1d80e972013-11-01 16:34:03 -0700141 setTransformationMethod(new CarrierTextTransformationMethod(mContext, useAllCaps));
Etan Cohen47051d82015-07-06 16:19:04 -0700142
143 mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700144 }
145
Wileen Chiu6b8b22e2014-10-29 22:48:21 +0530146 /**
147 * Checks if there are faulty cards. Adds the text depending on the slot of the card
148 * @param text: current carrier text based on the sim state
149 * @param noSims: whether a valid sim card is inserted
150 * @return text
151 */
152 private CharSequence updateCarrierTextWithSimIoError(CharSequence text, boolean noSims) {
153 final CharSequence carrier = "";
154 CharSequence carrierTextForSimIOError = getCarrierTextForSimState(
155 IccCardConstants.State.CARD_IO_ERROR, carrier);
156 for (int index = 0; index < mSimErrorState.length; index++) {
157 if (mSimErrorState[index]) {
158 // In the case when no sim cards are detected but a faulty card is inserted
159 // overwrite the text and only show "Invalid card"
160 if (noSims) {
161 return concatenate(carrierTextForSimIOError,
162 getContext().getText(com.android.internal.R.string.emergency_calls_only));
163 } else if (index == 0) {
164 // prepend "Invalid card" when faulty card is inserted in slot 0
165 text = concatenate(carrierTextForSimIOError, text);
166 } else {
167 // concatenate "Invalid card" when faulty card is inserted in slot 1
168 text = concatenate(text, carrierTextForSimIOError);
169 }
170 }
171 }
172 return text;
173 }
174
Jason Monk9ff69bd2014-12-02 16:43:17 -0500175 protected void updateCarrierText() {
176 boolean allSimsMissing = true;
Etan Cohen47051d82015-07-06 16:19:04 -0700177 boolean anySimReadyAndInService = false;
Jason Monk9ff69bd2014-12-02 16:43:17 -0500178 CharSequence displayText = null;
179
180 List<SubscriptionInfo> subs = mKeyguardUpdateMonitor.getSubscriptionInfo(false);
181 final int N = subs.size();
182 if (DEBUG) Log.d(TAG, "updateCarrierText(): " + N);
183 for (int i = 0; i < N; i++) {
Etan Cohen47051d82015-07-06 16:19:04 -0700184 int subId = subs.get(i).getSubscriptionId();
185 State simState = mKeyguardUpdateMonitor.getSimState(subId);
Jason Monk9ff69bd2014-12-02 16:43:17 -0500186 CharSequence carrierName = subs.get(i).getCarrierName();
187 CharSequence carrierTextForSimState = getCarrierTextForSimState(simState, carrierName);
Etan Cohen47051d82015-07-06 16:19:04 -0700188 if (DEBUG) {
189 Log.d(TAG, "Handling (subId=" + subId + "): " + simState + " " + carrierName);
190 }
Jason Monk9ff69bd2014-12-02 16:43:17 -0500191 if (carrierTextForSimState != null) {
192 allSimsMissing = false;
193 displayText = concatenate(displayText, carrierTextForSimState);
194 }
Etan Cohen47051d82015-07-06 16:19:04 -0700195 if (simState == IccCardConstants.State.READY) {
196 ServiceState ss = mKeyguardUpdateMonitor.mServiceStates.get(subId);
197 if (ss != null && ss.getDataRegState() == ServiceState.STATE_IN_SERVICE) {
198 // hack for WFC (IWLAN) not turning off immediately once
199 // Wi-Fi is disassociated or disabled
200 if (ss.getRilDataRadioTechnology() != ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN
201 || (mWifiManager.isWifiEnabled()
202 && mWifiManager.getConnectionInfo() != null
203 && mWifiManager.getConnectionInfo().getBSSID() != null)) {
204 if (DEBUG) {
205 Log.d(TAG, "SIM ready and in service: subId=" + subId + ", ss=" + ss);
206 }
207 anySimReadyAndInService = true;
208 }
209 }
210 }
Jason Monk9ff69bd2014-12-02 16:43:17 -0500211 }
212 if (allSimsMissing) {
213 if (N != 0) {
214 // Shows "No SIM card | Emergency calls only" on devices that are voice-capable.
215 // This depends on mPlmn containing the text "Emergency calls only" when the radio
216 // has some connectivity. Otherwise, it should be null or empty and just show
217 // "No SIM card"
218 // Grab the first subscripton, because they all should contain the emergency text,
219 // described above.
220 displayText = makeCarrierStringOnEmergencyCapable(
Amin Shaikh0e003312018-03-08 11:39:01 -0500221 getMissingSimMessage(), subs.get(0).getCarrierName());
Jason Monk9ff69bd2014-12-02 16:43:17 -0500222 } else {
223 // We don't have a SubscriptionInfo to get the emergency calls only from.
Jason Monkde3260b2015-02-24 08:55:26 -0500224 // Grab it from the old sticky broadcast if possible instead. We can use it
225 // here because no subscriptions are active, so we don't have
226 // to worry about MSIM clashing.
227 CharSequence text =
228 getContext().getText(com.android.internal.R.string.emergency_calls_only);
229 Intent i = getContext().registerReceiver(null,
230 new IntentFilter(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION));
231 if (i != null) {
232 String spn = "";
233 String plmn = "";
234 if (i.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, false)) {
235 spn = i.getStringExtra(TelephonyIntents.EXTRA_SPN);
236 }
237 if (i.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_PLMN, false)) {
238 plmn = i.getStringExtra(TelephonyIntents.EXTRA_PLMN);
239 }
240 if (DEBUG) Log.d(TAG, "Getting plmn/spn sticky brdcst " + plmn + "/" + spn);
Sanket Padaweb8726b72015-04-01 14:02:16 -0700241 if (Objects.equals(plmn, spn)) {
242 text = plmn;
243 } else {
244 text = concatenate(plmn, spn);
245 }
Jason Monkde3260b2015-02-24 08:55:26 -0500246 }
Amin Shaikh0e003312018-03-08 11:39:01 -0500247 displayText = makeCarrierStringOnEmergencyCapable(getMissingSimMessage(), text);
Jason Monk9ff69bd2014-12-02 16:43:17 -0500248 }
249 }
Etan Cohen47051d82015-07-06 16:19:04 -0700250
Wileen Chiu6b8b22e2014-10-29 22:48:21 +0530251 displayText = updateCarrierTextWithSimIoError(displayText, allSimsMissing);
Etan Cohen47051d82015-07-06 16:19:04 -0700252 // APM (airplane mode) != no carrier state. There are carrier services
253 // (e.g. WFC = Wi-Fi calling) which may operate in APM.
254 if (!anySimReadyAndInService && WirelessUtils.isAirplaneModeOn(mContext)) {
Amin Shaikh0e003312018-03-08 11:39:01 -0500255 displayText = getAirplaneModeMessage();
Jason Monk726fb282015-03-31 12:56:11 -0400256 }
Jason Monk9ff69bd2014-12-02 16:43:17 -0500257 setText(displayText);
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700258 }
259
Amin Shaikh0e003312018-03-08 11:39:01 -0500260 private String getMissingSimMessage() {
Bill Linef81cbd2018-07-05 17:48:49 +0800261 return mShowMissingSim && mTelephonyCapable
Amin Shaikh0e003312018-03-08 11:39:01 -0500262 ? getContext().getString(R.string.keyguard_missing_sim_message_short) : "";
263 }
264
265 private String getAirplaneModeMessage() {
Bill Linef81cbd2018-07-05 17:48:49 +0800266 return mShowAirplaneMode
Amin Shaikh0e003312018-03-08 11:39:01 -0500267 ? getContext().getString(R.string.airplane_mode) : "";
268 }
269
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700270 @Override
271 protected void onFinishInflate() {
272 super.onFinishInflate();
Jason Monk9ff69bd2014-12-02 16:43:17 -0500273 mSeparator = getResources().getString(
274 com.android.internal.R.string.kg_text_message_separator);
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700275 boolean shouldMarquee = KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive();
276 setSelected(shouldMarquee); // Allow marquee to work.
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700277 }
278
Jim Miller0928e012012-11-06 18:43:22 -0800279 @Override
280 protected void onAttachedToWindow() {
281 super.onAttachedToWindow();
Jason Monk83bc2aaf2014-12-05 10:16:24 -0500282 if (ConnectivityManager.from(mContext).isNetworkSupported(
283 ConnectivityManager.TYPE_MOBILE)) {
284 mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
285 mKeyguardUpdateMonitor.registerCallback(mCallback);
286 } else {
287 // Don't listen and clear out the text when the device isn't a phone.
288 mKeyguardUpdateMonitor = null;
289 setText("");
290 }
Jim Miller0928e012012-11-06 18:43:22 -0800291 }
292
293 @Override
294 protected void onDetachedFromWindow() {
295 super.onDetachedFromWindow();
Jason Monk83bc2aaf2014-12-05 10:16:24 -0500296 if (mKeyguardUpdateMonitor != null) {
297 mKeyguardUpdateMonitor.removeCallback(mCallback);
298 }
Jim Miller0928e012012-11-06 18:43:22 -0800299 }
300
Matthew Ng3a6db672017-11-28 14:35:25 -0800301 @Override
302 protected void onVisibilityChanged(View changedView, int visibility) {
303 super.onVisibilityChanged(changedView, visibility);
304
305 // Only show marquee when visible
306 if (visibility == VISIBLE) {
307 setEllipsize(TextUtils.TruncateAt.MARQUEE);
308 } else {
309 setEllipsize(TextUtils.TruncateAt.END);
310 }
311 }
312
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700313 /**
314 * Top-level function for creating carrier text. Makes text based on simState, PLMN
315 * and SPN as well as device capabilities, such as being emergency call capable.
316 *
317 * @param simState
Jason Monk9ff69bd2014-12-02 16:43:17 -0500318 * @param text
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700319 * @param spn
Jason Monk9ff69bd2014-12-02 16:43:17 -0500320 * @return Carrier text if not in missing state, null otherwise.
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700321 */
322 private CharSequence getCarrierTextForSimState(IccCardConstants.State simState,
Jason Monk9ff69bd2014-12-02 16:43:17 -0500323 CharSequence text) {
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700324 CharSequence carrierText = null;
325 StatusMode status = getStatusForIccState(simState);
326 switch (status) {
327 case Normal:
Jason Monk9ff69bd2014-12-02 16:43:17 -0500328 carrierText = text;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700329 break;
330
Jim Miller109f1fd2012-09-19 20:44:16 -0700331 case SimNotReady:
Jason Monk9ff69bd2014-12-02 16:43:17 -0500332 // Null is reserved for denoting missing, in this case we have nothing to display.
333 carrierText = ""; // nothing to display yet.
Jim Miller109f1fd2012-09-19 20:44:16 -0700334 break;
335
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700336 case NetworkLocked:
337 carrierText = makeCarrierStringOnEmergencyCapable(
Jason Monk9ff69bd2014-12-02 16:43:17 -0500338 mContext.getText(R.string.keyguard_network_locked_message), text);
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700339 break;
340
341 case SimMissing:
Jason Monk9ff69bd2014-12-02 16:43:17 -0500342 carrierText = null;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700343 break;
344
345 case SimPermDisabled:
Dan Sandlerf058cc62018-06-08 15:34:52 -0400346 carrierText = makeCarrierStringOnEmergencyCapable(
347 getContext().getText(
348 R.string.keyguard_permanent_disabled_sim_message_short),
349 text);
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700350 break;
351
352 case SimMissingLocked:
Jason Monk9ff69bd2014-12-02 16:43:17 -0500353 carrierText = null;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700354 break;
355
356 case SimLocked:
357 carrierText = makeCarrierStringOnEmergencyCapable(
Jim Miller5ecd8112013-01-09 18:50:26 -0800358 getContext().getText(R.string.keyguard_sim_locked_message),
Jason Monk9ff69bd2014-12-02 16:43:17 -0500359 text);
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700360 break;
361
362 case SimPukLocked:
363 carrierText = makeCarrierStringOnEmergencyCapable(
Jim Miller5ecd8112013-01-09 18:50:26 -0800364 getContext().getText(R.string.keyguard_sim_puk_locked_message),
Jason Monk9ff69bd2014-12-02 16:43:17 -0500365 text);
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700366 break;
Wileen Chiu6b8b22e2014-10-29 22:48:21 +0530367 case SimIoError:
368 carrierText = makeCarrierStringOnEmergencyCapable(
369 getContext().getText(R.string.keyguard_sim_error_message_short),
370 text);
371 break;
Bill Linef81cbd2018-07-05 17:48:49 +0800372 case SimUnknown:
373 carrierText = null;
374 break;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700375 }
376
377 return carrierText;
378 }
379
380 /*
381 * Add emergencyCallMessage to carrier string only if phone supports emergency calls.
382 */
383 private CharSequence makeCarrierStringOnEmergencyCapable(
384 CharSequence simMessage, CharSequence emergencyCallMessage) {
Adrian Roosc2e01682015-01-15 23:20:20 +0100385 if (mIsEmergencyCallCapable) {
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700386 return concatenate(simMessage, emergencyCallMessage);
387 }
388 return simMessage;
389 }
390
391 /**
392 * Determine the current status of the lock screen given the SIM state and other stuff.
393 */
394 private StatusMode getStatusForIccState(IccCardConstants.State simState) {
395 // Since reading the SIM may take a while, we assume it is present until told otherwise.
396 if (simState == null) {
397 return StatusMode.Normal;
398 }
399
400 final boolean missingAndNotProvisioned =
401 !KeyguardUpdateMonitor.getInstance(mContext).isDeviceProvisioned()
402 && (simState == IccCardConstants.State.ABSENT ||
403 simState == IccCardConstants.State.PERM_DISABLED);
404
405 // Assume we're NETWORK_LOCKED if not provisioned
406 simState = missingAndNotProvisioned ? IccCardConstants.State.NETWORK_LOCKED : simState;
407 switch (simState) {
408 case ABSENT:
409 return StatusMode.SimMissing;
410 case NETWORK_LOCKED:
411 return StatusMode.SimMissingLocked;
412 case NOT_READY:
Jim Miller109f1fd2012-09-19 20:44:16 -0700413 return StatusMode.SimNotReady;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700414 case PIN_REQUIRED:
415 return StatusMode.SimLocked;
416 case PUK_REQUIRED:
417 return StatusMode.SimPukLocked;
418 case READY:
419 return StatusMode.Normal;
420 case PERM_DISABLED:
421 return StatusMode.SimPermDisabled;
422 case UNKNOWN:
Bill Linef81cbd2018-07-05 17:48:49 +0800423 return StatusMode.SimUnknown;
Wileen Chiu6b8b22e2014-10-29 22:48:21 +0530424 case CARD_IO_ERROR:
425 return StatusMode.SimIoError;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700426 }
Bill Linef81cbd2018-07-05 17:48:49 +0800427 return StatusMode.SimUnknown;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700428 }
429
430 private static CharSequence concatenate(CharSequence plmn, CharSequence spn) {
431 final boolean plmnValid = !TextUtils.isEmpty(plmn);
432 final boolean spnValid = !TextUtils.isEmpty(spn);
433 if (plmnValid && spnValid) {
Sanket Padaweb8726b72015-04-01 14:02:16 -0700434 return new StringBuilder().append(plmn).append(mSeparator).append(spn).toString();
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700435 } else if (plmnValid) {
436 return plmn;
437 } else if (spnValid) {
438 return spn;
439 } else {
440 return "";
441 }
442 }
443
444 private CharSequence getCarrierHelpTextForSimState(IccCardConstants.State simState,
445 String plmn, String spn) {
446 int carrierHelpTextId = 0;
447 StatusMode status = getStatusForIccState(simState);
448 switch (status) {
449 case NetworkLocked:
Jim Miller5ecd8112013-01-09 18:50:26 -0800450 carrierHelpTextId = R.string.keyguard_instructions_when_pattern_disabled;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700451 break;
452
453 case SimMissing:
Jim Miller5ecd8112013-01-09 18:50:26 -0800454 carrierHelpTextId = R.string.keyguard_missing_sim_instructions_long;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700455 break;
456
457 case SimPermDisabled:
Jim Miller5ecd8112013-01-09 18:50:26 -0800458 carrierHelpTextId = R.string.keyguard_permanent_disabled_sim_instructions;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700459 break;
460
461 case SimMissingLocked:
Jim Miller5ecd8112013-01-09 18:50:26 -0800462 carrierHelpTextId = R.string.keyguard_missing_sim_instructions;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700463 break;
464
465 case Normal:
466 case SimLocked:
467 case SimPukLocked:
468 break;
469 }
470
471 return mContext.getText(carrierHelpTextId);
472 }
Victoria Lease1d80e972013-11-01 16:34:03 -0700473
474 private class CarrierTextTransformationMethod extends SingleLineTransformationMethod {
475 private final Locale mLocale;
476 private final boolean mAllCaps;
477
478 public CarrierTextTransformationMethod(Context context, boolean allCaps) {
479 mLocale = context.getResources().getConfiguration().locale;
480 mAllCaps = allCaps;
481 }
482
483 @Override
484 public CharSequence getTransformation(CharSequence source, View view) {
485 source = super.getTransformation(source, view);
486
487 if (mAllCaps && source != null) {
488 source = source.toString().toUpperCase(mLocale);
489 }
490
491 return source;
492 }
493 }
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700494}