blob: 5b0f1c39f74ba4397fadf71cfa87f238ae7336e2 [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 {
Amin Shaikh0e003312018-03-08 11:39:01 -050046 /** Do not show missing sim message. */
47 public static final int FLAG_HIDE_MISSING_SIM = 1 << 0;
48 /** Do not show airplane mode message. */
49 public static final int FLAG_HIDE_AIRPLANE_MODE = 1 << 1;
50
Jason Monk9ff69bd2014-12-02 16:43:17 -050051 private static final boolean DEBUG = KeyguardConstants.DEBUG;
52 private static final String TAG = "CarrierText";
53
Jim Millere9be1402012-11-01 16:14:20 -070054 private static CharSequence mSeparator;
55
Adrian Roosc2e01682015-01-15 23:20:20 +010056 private final boolean mIsEmergencyCallCapable;
57
Jason Monk9ff69bd2014-12-02 16:43:17 -050058 private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
Jim Millerf9cb7ba2012-09-17 22:31:56 -070059
Etan Cohen47051d82015-07-06 16:19:04 -070060 private WifiManager mWifiManager;
61
Wileen Chiu6b8b22e2014-10-29 22:48:21 +053062 private boolean[] mSimErrorState = new boolean[TelephonyManager.getDefault().getPhoneCount()];
63
Amin Shaikh0e003312018-03-08 11:39:01 -050064 private int mFlags;
65
Jim Millerf9cb7ba2012-09-17 22:31:56 -070066 private KeyguardUpdateMonitorCallback mCallback = new KeyguardUpdateMonitorCallback() {
Jim Millerf9cb7ba2012-09-17 22:31:56 -070067 @Override
Jason Monk9ff69bd2014-12-02 16:43:17 -050068 public void onRefreshCarrierInfo() {
69 updateCarrierText();
Jim Millerf9cb7ba2012-09-17 22:31:56 -070070 }
Jim Miller20daffd2013-10-07 14:59:53 -070071
Jorim Jaggi0d210f62015-07-10 14:24:44 -070072 public void onFinishedGoingToSleep(int why) {
Jim Miller20daffd2013-10-07 14:59:53 -070073 setSelected(false);
74 };
75
Jorim Jaggi0d210f62015-07-10 14:24:44 -070076 public void onStartedWakingUp() {
Jim Miller20daffd2013-10-07 14:59:53 -070077 setSelected(true);
78 };
Wileen Chiu6b8b22e2014-10-29 22:48:21 +053079
80 public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) {
81 if (slotId < 0) {
82 Log.d(TAG, "onSimStateChanged() - slotId invalid: " + slotId);
83 return;
84 }
85
86 if (DEBUG) Log.d(TAG,"onSimStateChanged: " + getStatusForIccState(simState));
87 if (getStatusForIccState(simState) == StatusMode.SimIoError) {
88 mSimErrorState[slotId] = true;
89 updateCarrierText();
90 } else if (mSimErrorState[slotId]) {
91 mSimErrorState[slotId] = false;
92 updateCarrierText();
93 }
94 };
Jim Millerf9cb7ba2012-09-17 22:31:56 -070095 };
Amin Shaikh0e003312018-03-08 11:39:01 -050096
97 public void setDisplayFlags(int flags) {
98 mFlags = flags;
99 }
100
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700101 /**
102 * The status of this lock screen. Primarily used for widgets on LockScreen.
103 */
Jim Miller109f1fd2012-09-19 20:44:16 -0700104 private static enum StatusMode {
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700105 Normal, // Normal case (sim card present, it's not locked)
106 NetworkLocked, // SIM card is 'network locked'.
107 SimMissing, // SIM card is missing.
108 SimMissingLocked, // SIM card is missing, and device isn't provisioned; don't allow access
109 SimPukLocked, // SIM card is PUK locked because SIM entered wrong too many times
110 SimLocked, // SIM card is currently locked
Jim Miller109f1fd2012-09-19 20:44:16 -0700111 SimPermDisabled, // SIM card is permanently disabled due to PUK unlock failure
Wileen Chiu6b8b22e2014-10-29 22:48:21 +0530112 SimNotReady, // SIM is not ready yet. May never be on devices w/o a SIM.
113 SimIoError; // SIM card is faulty
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700114 }
115
116 public CarrierText(Context context) {
117 this(context, null);
118 }
119
120 public CarrierText(Context context, AttributeSet attrs) {
121 super(context, attrs);
Adrian Roosc2e01682015-01-15 23:20:20 +0100122 mIsEmergencyCallCapable = context.getResources().getBoolean(
123 com.android.internal.R.bool.config_voice_capable);
Jorim Jaggi25807932014-04-24 23:29:46 +0200124 boolean useAllCaps;
125 TypedArray a = context.getTheme().obtainStyledAttributes(
126 attrs, R.styleable.CarrierText, 0, 0);
127 try {
128 useAllCaps = a.getBoolean(R.styleable.CarrierText_allCaps, false);
129 } finally {
130 a.recycle();
131 }
Victoria Lease1d80e972013-11-01 16:34:03 -0700132 setTransformationMethod(new CarrierTextTransformationMethod(mContext, useAllCaps));
Etan Cohen47051d82015-07-06 16:19:04 -0700133
134 mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700135 }
136
Wileen Chiu6b8b22e2014-10-29 22:48:21 +0530137 /**
138 * Checks if there are faulty cards. Adds the text depending on the slot of the card
139 * @param text: current carrier text based on the sim state
140 * @param noSims: whether a valid sim card is inserted
141 * @return text
142 */
143 private CharSequence updateCarrierTextWithSimIoError(CharSequence text, boolean noSims) {
144 final CharSequence carrier = "";
145 CharSequence carrierTextForSimIOError = getCarrierTextForSimState(
146 IccCardConstants.State.CARD_IO_ERROR, carrier);
147 for (int index = 0; index < mSimErrorState.length; index++) {
148 if (mSimErrorState[index]) {
149 // In the case when no sim cards are detected but a faulty card is inserted
150 // overwrite the text and only show "Invalid card"
151 if (noSims) {
152 return concatenate(carrierTextForSimIOError,
153 getContext().getText(com.android.internal.R.string.emergency_calls_only));
154 } else if (index == 0) {
155 // prepend "Invalid card" when faulty card is inserted in slot 0
156 text = concatenate(carrierTextForSimIOError, text);
157 } else {
158 // concatenate "Invalid card" when faulty card is inserted in slot 1
159 text = concatenate(text, carrierTextForSimIOError);
160 }
161 }
162 }
163 return text;
164 }
165
Jason Monk9ff69bd2014-12-02 16:43:17 -0500166 protected void updateCarrierText() {
167 boolean allSimsMissing = true;
Etan Cohen47051d82015-07-06 16:19:04 -0700168 boolean anySimReadyAndInService = false;
Jason Monk9ff69bd2014-12-02 16:43:17 -0500169 CharSequence displayText = null;
170
171 List<SubscriptionInfo> subs = mKeyguardUpdateMonitor.getSubscriptionInfo(false);
172 final int N = subs.size();
173 if (DEBUG) Log.d(TAG, "updateCarrierText(): " + N);
174 for (int i = 0; i < N; i++) {
Etan Cohen47051d82015-07-06 16:19:04 -0700175 int subId = subs.get(i).getSubscriptionId();
176 State simState = mKeyguardUpdateMonitor.getSimState(subId);
Jason Monk9ff69bd2014-12-02 16:43:17 -0500177 CharSequence carrierName = subs.get(i).getCarrierName();
178 CharSequence carrierTextForSimState = getCarrierTextForSimState(simState, carrierName);
Etan Cohen47051d82015-07-06 16:19:04 -0700179 if (DEBUG) {
180 Log.d(TAG, "Handling (subId=" + subId + "): " + simState + " " + carrierName);
181 }
Jason Monk9ff69bd2014-12-02 16:43:17 -0500182 if (carrierTextForSimState != null) {
183 allSimsMissing = false;
184 displayText = concatenate(displayText, carrierTextForSimState);
185 }
Etan Cohen47051d82015-07-06 16:19:04 -0700186 if (simState == IccCardConstants.State.READY) {
187 ServiceState ss = mKeyguardUpdateMonitor.mServiceStates.get(subId);
188 if (ss != null && ss.getDataRegState() == ServiceState.STATE_IN_SERVICE) {
189 // hack for WFC (IWLAN) not turning off immediately once
190 // Wi-Fi is disassociated or disabled
191 if (ss.getRilDataRadioTechnology() != ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN
192 || (mWifiManager.isWifiEnabled()
193 && mWifiManager.getConnectionInfo() != null
194 && mWifiManager.getConnectionInfo().getBSSID() != null)) {
195 if (DEBUG) {
196 Log.d(TAG, "SIM ready and in service: subId=" + subId + ", ss=" + ss);
197 }
198 anySimReadyAndInService = true;
199 }
200 }
201 }
Jason Monk9ff69bd2014-12-02 16:43:17 -0500202 }
203 if (allSimsMissing) {
204 if (N != 0) {
205 // Shows "No SIM card | Emergency calls only" on devices that are voice-capable.
206 // This depends on mPlmn containing the text "Emergency calls only" when the radio
207 // has some connectivity. Otherwise, it should be null or empty and just show
208 // "No SIM card"
209 // Grab the first subscripton, because they all should contain the emergency text,
210 // described above.
211 displayText = makeCarrierStringOnEmergencyCapable(
Amin Shaikh0e003312018-03-08 11:39:01 -0500212 getMissingSimMessage(), subs.get(0).getCarrierName());
Jason Monk9ff69bd2014-12-02 16:43:17 -0500213 } else {
214 // We don't have a SubscriptionInfo to get the emergency calls only from.
Jason Monkde3260b2015-02-24 08:55:26 -0500215 // Grab it from the old sticky broadcast if possible instead. We can use it
216 // here because no subscriptions are active, so we don't have
217 // to worry about MSIM clashing.
218 CharSequence text =
219 getContext().getText(com.android.internal.R.string.emergency_calls_only);
220 Intent i = getContext().registerReceiver(null,
221 new IntentFilter(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION));
222 if (i != null) {
223 String spn = "";
224 String plmn = "";
225 if (i.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, false)) {
226 spn = i.getStringExtra(TelephonyIntents.EXTRA_SPN);
227 }
228 if (i.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_PLMN, false)) {
229 plmn = i.getStringExtra(TelephonyIntents.EXTRA_PLMN);
230 }
231 if (DEBUG) Log.d(TAG, "Getting plmn/spn sticky brdcst " + plmn + "/" + spn);
Sanket Padaweb8726b72015-04-01 14:02:16 -0700232 if (Objects.equals(plmn, spn)) {
233 text = plmn;
234 } else {
235 text = concatenate(plmn, spn);
236 }
Jason Monkde3260b2015-02-24 08:55:26 -0500237 }
Amin Shaikh0e003312018-03-08 11:39:01 -0500238 displayText = makeCarrierStringOnEmergencyCapable(getMissingSimMessage(), text);
Jason Monk9ff69bd2014-12-02 16:43:17 -0500239 }
240 }
Etan Cohen47051d82015-07-06 16:19:04 -0700241
Wileen Chiu6b8b22e2014-10-29 22:48:21 +0530242 displayText = updateCarrierTextWithSimIoError(displayText, allSimsMissing);
Etan Cohen47051d82015-07-06 16:19:04 -0700243 // APM (airplane mode) != no carrier state. There are carrier services
244 // (e.g. WFC = Wi-Fi calling) which may operate in APM.
245 if (!anySimReadyAndInService && WirelessUtils.isAirplaneModeOn(mContext)) {
Amin Shaikh0e003312018-03-08 11:39:01 -0500246 displayText = getAirplaneModeMessage();
Jason Monk726fb282015-03-31 12:56:11 -0400247 }
Jason Monk9ff69bd2014-12-02 16:43:17 -0500248 setText(displayText);
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700249 }
250
Amin Shaikh0e003312018-03-08 11:39:01 -0500251 private String getMissingSimMessage() {
252 return (mFlags & FLAG_HIDE_MISSING_SIM) == 0
253 ? getContext().getString(R.string.keyguard_missing_sim_message_short) : "";
254 }
255
256 private String getAirplaneModeMessage() {
257 return (mFlags & FLAG_HIDE_AIRPLANE_MODE) == 0
258 ? getContext().getString(R.string.airplane_mode) : "";
259 }
260
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700261 @Override
262 protected void onFinishInflate() {
263 super.onFinishInflate();
Jason Monk9ff69bd2014-12-02 16:43:17 -0500264 mSeparator = getResources().getString(
265 com.android.internal.R.string.kg_text_message_separator);
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700266 boolean shouldMarquee = KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive();
267 setSelected(shouldMarquee); // Allow marquee to work.
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700268 }
269
Jim Miller0928e012012-11-06 18:43:22 -0800270 @Override
271 protected void onAttachedToWindow() {
272 super.onAttachedToWindow();
Jason Monk83bc2aaf2014-12-05 10:16:24 -0500273 if (ConnectivityManager.from(mContext).isNetworkSupported(
274 ConnectivityManager.TYPE_MOBILE)) {
275 mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
276 mKeyguardUpdateMonitor.registerCallback(mCallback);
277 } else {
278 // Don't listen and clear out the text when the device isn't a phone.
279 mKeyguardUpdateMonitor = null;
280 setText("");
281 }
Jim Miller0928e012012-11-06 18:43:22 -0800282 }
283
284 @Override
285 protected void onDetachedFromWindow() {
286 super.onDetachedFromWindow();
Jason Monk83bc2aaf2014-12-05 10:16:24 -0500287 if (mKeyguardUpdateMonitor != null) {
288 mKeyguardUpdateMonitor.removeCallback(mCallback);
289 }
Jim Miller0928e012012-11-06 18:43:22 -0800290 }
291
Matthew Ng3a6db672017-11-28 14:35:25 -0800292 @Override
293 protected void onVisibilityChanged(View changedView, int visibility) {
294 super.onVisibilityChanged(changedView, visibility);
295
296 // Only show marquee when visible
297 if (visibility == VISIBLE) {
298 setEllipsize(TextUtils.TruncateAt.MARQUEE);
299 } else {
300 setEllipsize(TextUtils.TruncateAt.END);
301 }
302 }
303
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700304 /**
305 * Top-level function for creating carrier text. Makes text based on simState, PLMN
306 * and SPN as well as device capabilities, such as being emergency call capable.
307 *
308 * @param simState
Jason Monk9ff69bd2014-12-02 16:43:17 -0500309 * @param text
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700310 * @param spn
Jason Monk9ff69bd2014-12-02 16:43:17 -0500311 * @return Carrier text if not in missing state, null otherwise.
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700312 */
313 private CharSequence getCarrierTextForSimState(IccCardConstants.State simState,
Jason Monk9ff69bd2014-12-02 16:43:17 -0500314 CharSequence text) {
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700315 CharSequence carrierText = null;
316 StatusMode status = getStatusForIccState(simState);
317 switch (status) {
318 case Normal:
Jason Monk9ff69bd2014-12-02 16:43:17 -0500319 carrierText = text;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700320 break;
321
Jim Miller109f1fd2012-09-19 20:44:16 -0700322 case SimNotReady:
Jason Monk9ff69bd2014-12-02 16:43:17 -0500323 // Null is reserved for denoting missing, in this case we have nothing to display.
324 carrierText = ""; // nothing to display yet.
Jim Miller109f1fd2012-09-19 20:44:16 -0700325 break;
326
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700327 case NetworkLocked:
328 carrierText = makeCarrierStringOnEmergencyCapable(
Jason Monk9ff69bd2014-12-02 16:43:17 -0500329 mContext.getText(R.string.keyguard_network_locked_message), text);
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700330 break;
331
332 case SimMissing:
Jason Monk9ff69bd2014-12-02 16:43:17 -0500333 carrierText = null;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700334 break;
335
336 case SimPermDisabled:
337 carrierText = getContext().getText(
Jim Miller5ecd8112013-01-09 18:50:26 -0800338 R.string.keyguard_permanent_disabled_sim_message_short);
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700339 break;
340
341 case SimMissingLocked:
Jason Monk9ff69bd2014-12-02 16:43:17 -0500342 carrierText = null;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700343 break;
344
345 case SimLocked:
346 carrierText = makeCarrierStringOnEmergencyCapable(
Jim Miller5ecd8112013-01-09 18:50:26 -0800347 getContext().getText(R.string.keyguard_sim_locked_message),
Jason Monk9ff69bd2014-12-02 16:43:17 -0500348 text);
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700349 break;
350
351 case SimPukLocked:
352 carrierText = makeCarrierStringOnEmergencyCapable(
Jim Miller5ecd8112013-01-09 18:50:26 -0800353 getContext().getText(R.string.keyguard_sim_puk_locked_message),
Jason Monk9ff69bd2014-12-02 16:43:17 -0500354 text);
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700355 break;
Wileen Chiu6b8b22e2014-10-29 22:48:21 +0530356 case SimIoError:
357 carrierText = makeCarrierStringOnEmergencyCapable(
358 getContext().getText(R.string.keyguard_sim_error_message_short),
359 text);
360 break;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700361 }
362
363 return carrierText;
364 }
365
366 /*
367 * Add emergencyCallMessage to carrier string only if phone supports emergency calls.
368 */
369 private CharSequence makeCarrierStringOnEmergencyCapable(
370 CharSequence simMessage, CharSequence emergencyCallMessage) {
Adrian Roosc2e01682015-01-15 23:20:20 +0100371 if (mIsEmergencyCallCapable) {
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700372 return concatenate(simMessage, emergencyCallMessage);
373 }
374 return simMessage;
375 }
376
377 /**
378 * Determine the current status of the lock screen given the SIM state and other stuff.
379 */
380 private StatusMode getStatusForIccState(IccCardConstants.State simState) {
381 // Since reading the SIM may take a while, we assume it is present until told otherwise.
382 if (simState == null) {
383 return StatusMode.Normal;
384 }
385
386 final boolean missingAndNotProvisioned =
387 !KeyguardUpdateMonitor.getInstance(mContext).isDeviceProvisioned()
388 && (simState == IccCardConstants.State.ABSENT ||
389 simState == IccCardConstants.State.PERM_DISABLED);
390
391 // Assume we're NETWORK_LOCKED if not provisioned
392 simState = missingAndNotProvisioned ? IccCardConstants.State.NETWORK_LOCKED : simState;
393 switch (simState) {
394 case ABSENT:
395 return StatusMode.SimMissing;
396 case NETWORK_LOCKED:
397 return StatusMode.SimMissingLocked;
398 case NOT_READY:
Jim Miller109f1fd2012-09-19 20:44:16 -0700399 return StatusMode.SimNotReady;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700400 case PIN_REQUIRED:
401 return StatusMode.SimLocked;
402 case PUK_REQUIRED:
403 return StatusMode.SimPukLocked;
404 case READY:
405 return StatusMode.Normal;
406 case PERM_DISABLED:
407 return StatusMode.SimPermDisabled;
408 case UNKNOWN:
409 return StatusMode.SimMissing;
Wileen Chiu6b8b22e2014-10-29 22:48:21 +0530410 case CARD_IO_ERROR:
411 return StatusMode.SimIoError;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700412 }
413 return StatusMode.SimMissing;
414 }
415
416 private static CharSequence concatenate(CharSequence plmn, CharSequence spn) {
417 final boolean plmnValid = !TextUtils.isEmpty(plmn);
418 final boolean spnValid = !TextUtils.isEmpty(spn);
419 if (plmnValid && spnValid) {
Sanket Padaweb8726b72015-04-01 14:02:16 -0700420 return new StringBuilder().append(plmn).append(mSeparator).append(spn).toString();
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700421 } else if (plmnValid) {
422 return plmn;
423 } else if (spnValid) {
424 return spn;
425 } else {
426 return "";
427 }
428 }
429
430 private CharSequence getCarrierHelpTextForSimState(IccCardConstants.State simState,
431 String plmn, String spn) {
432 int carrierHelpTextId = 0;
433 StatusMode status = getStatusForIccState(simState);
434 switch (status) {
435 case NetworkLocked:
Jim Miller5ecd8112013-01-09 18:50:26 -0800436 carrierHelpTextId = R.string.keyguard_instructions_when_pattern_disabled;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700437 break;
438
439 case SimMissing:
Jim Miller5ecd8112013-01-09 18:50:26 -0800440 carrierHelpTextId = R.string.keyguard_missing_sim_instructions_long;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700441 break;
442
443 case SimPermDisabled:
Jim Miller5ecd8112013-01-09 18:50:26 -0800444 carrierHelpTextId = R.string.keyguard_permanent_disabled_sim_instructions;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700445 break;
446
447 case SimMissingLocked:
Jim Miller5ecd8112013-01-09 18:50:26 -0800448 carrierHelpTextId = R.string.keyguard_missing_sim_instructions;
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700449 break;
450
451 case Normal:
452 case SimLocked:
453 case SimPukLocked:
454 break;
455 }
456
457 return mContext.getText(carrierHelpTextId);
458 }
Victoria Lease1d80e972013-11-01 16:34:03 -0700459
460 private class CarrierTextTransformationMethod extends SingleLineTransformationMethod {
461 private final Locale mLocale;
462 private final boolean mAllCaps;
463
464 public CarrierTextTransformationMethod(Context context, boolean allCaps) {
465 mLocale = context.getResources().getConfiguration().locale;
466 mAllCaps = allCaps;
467 }
468
469 @Override
470 public CharSequence getTransformation(CharSequence source, View view) {
471 source = super.getTransformation(source, view);
472
473 if (mAllCaps && source != null) {
474 source = source.toString().toUpperCase(mLocale);
475 }
476
477 return source;
478 }
479 }
Jim Millerf9cb7ba2012-09-17 22:31:56 -0700480}