Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 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 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 17 | package com.android.keyguard; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 18 | |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 19 | import java.util.List; |
| 20 | import java.util.Locale; |
Sanket Padawe | b8726b7 | 2015-04-01 14:02:16 -0700 | [diff] [blame] | 21 | import java.util.Objects; |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 22 | |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 23 | import android.content.Context; |
Jason Monk | de3260b | 2015-02-24 08:55:26 -0500 | [diff] [blame] | 24 | import android.content.Intent; |
| 25 | import android.content.IntentFilter; |
Jorim Jaggi | 2580793 | 2014-04-24 23:29:46 +0200 | [diff] [blame] | 26 | import android.content.res.TypedArray; |
Jason Monk | 83bc2aaf | 2014-12-05 10:16:24 -0500 | [diff] [blame] | 27 | import android.net.ConnectivityManager; |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 28 | import android.net.wifi.WifiManager; |
| 29 | import android.telephony.ServiceState; |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 30 | import android.telephony.SubscriptionInfo; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 31 | import android.text.TextUtils; |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 32 | import android.text.method.SingleLineTransformationMethod; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 33 | import android.util.AttributeSet; |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 34 | import android.util.Log; |
Victoria Lease | 1d80e97 | 2013-11-01 16:34:03 -0700 | [diff] [blame] | 35 | import android.view.View; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 36 | import android.widget.TextView; |
| 37 | |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 38 | import com.android.internal.telephony.IccCardConstants; |
| 39 | import com.android.internal.telephony.IccCardConstants.State; |
Jason Monk | de3260b | 2015-02-24 08:55:26 -0500 | [diff] [blame] | 40 | import com.android.internal.telephony.TelephonyIntents; |
Jason Monk | 726fb28 | 2015-03-31 12:56:11 -0400 | [diff] [blame] | 41 | import com.android.settingslib.WirelessUtils; |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 42 | import android.telephony.TelephonyManager; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 43 | |
| 44 | public class CarrierText extends TextView { |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 45 | private static final boolean DEBUG = KeyguardConstants.DEBUG; |
| 46 | private static final String TAG = "CarrierText"; |
| 47 | |
Jim Miller | e9be140 | 2012-11-01 16:14:20 -0700 | [diff] [blame] | 48 | private static CharSequence mSeparator; |
| 49 | |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 50 | private final boolean mIsEmergencyCallCapable; |
| 51 | |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 52 | private KeyguardUpdateMonitor mKeyguardUpdateMonitor; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 53 | |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 54 | private WifiManager mWifiManager; |
| 55 | |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 56 | private boolean[] mSimErrorState = new boolean[TelephonyManager.getDefault().getPhoneCount()]; |
| 57 | |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 58 | private KeyguardUpdateMonitorCallback mCallback = new KeyguardUpdateMonitorCallback() { |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 59 | @Override |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 60 | public void onRefreshCarrierInfo() { |
| 61 | updateCarrierText(); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 62 | } |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 63 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 64 | public void onFinishedGoingToSleep(int why) { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 65 | setSelected(false); |
| 66 | }; |
| 67 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 68 | public void onStartedWakingUp() { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 69 | setSelected(true); |
| 70 | }; |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 71 | |
| 72 | public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) { |
| 73 | if (slotId < 0) { |
| 74 | Log.d(TAG, "onSimStateChanged() - slotId invalid: " + slotId); |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | if (DEBUG) Log.d(TAG,"onSimStateChanged: " + getStatusForIccState(simState)); |
| 79 | if (getStatusForIccState(simState) == StatusMode.SimIoError) { |
| 80 | mSimErrorState[slotId] = true; |
| 81 | updateCarrierText(); |
| 82 | } else if (mSimErrorState[slotId]) { |
| 83 | mSimErrorState[slotId] = false; |
| 84 | updateCarrierText(); |
| 85 | } |
| 86 | }; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 87 | }; |
| 88 | /** |
| 89 | * The status of this lock screen. Primarily used for widgets on LockScreen. |
| 90 | */ |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 91 | private static enum StatusMode { |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 92 | Normal, // Normal case (sim card present, it's not locked) |
| 93 | NetworkLocked, // SIM card is 'network locked'. |
| 94 | SimMissing, // SIM card is missing. |
| 95 | SimMissingLocked, // SIM card is missing, and device isn't provisioned; don't allow access |
| 96 | SimPukLocked, // SIM card is PUK locked because SIM entered wrong too many times |
| 97 | SimLocked, // SIM card is currently locked |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 98 | SimPermDisabled, // SIM card is permanently disabled due to PUK unlock failure |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 99 | SimNotReady, // SIM is not ready yet. May never be on devices w/o a SIM. |
| 100 | SimIoError; // SIM card is faulty |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | public CarrierText(Context context) { |
| 104 | this(context, null); |
| 105 | } |
| 106 | |
| 107 | public CarrierText(Context context, AttributeSet attrs) { |
| 108 | super(context, attrs); |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 109 | mIsEmergencyCallCapable = context.getResources().getBoolean( |
| 110 | com.android.internal.R.bool.config_voice_capable); |
Jorim Jaggi | 2580793 | 2014-04-24 23:29:46 +0200 | [diff] [blame] | 111 | boolean useAllCaps; |
| 112 | TypedArray a = context.getTheme().obtainStyledAttributes( |
| 113 | attrs, R.styleable.CarrierText, 0, 0); |
| 114 | try { |
| 115 | useAllCaps = a.getBoolean(R.styleable.CarrierText_allCaps, false); |
| 116 | } finally { |
| 117 | a.recycle(); |
| 118 | } |
Victoria Lease | 1d80e97 | 2013-11-01 16:34:03 -0700 | [diff] [blame] | 119 | setTransformationMethod(new CarrierTextTransformationMethod(mContext, useAllCaps)); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 120 | |
| 121 | mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 124 | /** |
| 125 | * Checks if there are faulty cards. Adds the text depending on the slot of the card |
| 126 | * @param text: current carrier text based on the sim state |
| 127 | * @param noSims: whether a valid sim card is inserted |
| 128 | * @return text |
| 129 | */ |
| 130 | private CharSequence updateCarrierTextWithSimIoError(CharSequence text, boolean noSims) { |
| 131 | final CharSequence carrier = ""; |
| 132 | CharSequence carrierTextForSimIOError = getCarrierTextForSimState( |
| 133 | IccCardConstants.State.CARD_IO_ERROR, carrier); |
| 134 | for (int index = 0; index < mSimErrorState.length; index++) { |
| 135 | if (mSimErrorState[index]) { |
| 136 | // In the case when no sim cards are detected but a faulty card is inserted |
| 137 | // overwrite the text and only show "Invalid card" |
| 138 | if (noSims) { |
| 139 | return concatenate(carrierTextForSimIOError, |
| 140 | getContext().getText(com.android.internal.R.string.emergency_calls_only)); |
| 141 | } else if (index == 0) { |
| 142 | // prepend "Invalid card" when faulty card is inserted in slot 0 |
| 143 | text = concatenate(carrierTextForSimIOError, text); |
| 144 | } else { |
| 145 | // concatenate "Invalid card" when faulty card is inserted in slot 1 |
| 146 | text = concatenate(text, carrierTextForSimIOError); |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | return text; |
| 151 | } |
| 152 | |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 153 | protected void updateCarrierText() { |
| 154 | boolean allSimsMissing = true; |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 155 | boolean anySimReadyAndInService = false; |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 156 | CharSequence displayText = null; |
| 157 | |
| 158 | List<SubscriptionInfo> subs = mKeyguardUpdateMonitor.getSubscriptionInfo(false); |
| 159 | final int N = subs.size(); |
| 160 | if (DEBUG) Log.d(TAG, "updateCarrierText(): " + N); |
| 161 | for (int i = 0; i < N; i++) { |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 162 | int subId = subs.get(i).getSubscriptionId(); |
| 163 | State simState = mKeyguardUpdateMonitor.getSimState(subId); |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 164 | CharSequence carrierName = subs.get(i).getCarrierName(); |
| 165 | CharSequence carrierTextForSimState = getCarrierTextForSimState(simState, carrierName); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 166 | if (DEBUG) { |
| 167 | Log.d(TAG, "Handling (subId=" + subId + "): " + simState + " " + carrierName); |
| 168 | } |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 169 | if (carrierTextForSimState != null) { |
| 170 | allSimsMissing = false; |
| 171 | displayText = concatenate(displayText, carrierTextForSimState); |
| 172 | } |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 173 | if (simState == IccCardConstants.State.READY) { |
| 174 | ServiceState ss = mKeyguardUpdateMonitor.mServiceStates.get(subId); |
| 175 | if (ss != null && ss.getDataRegState() == ServiceState.STATE_IN_SERVICE) { |
| 176 | // hack for WFC (IWLAN) not turning off immediately once |
| 177 | // Wi-Fi is disassociated or disabled |
| 178 | if (ss.getRilDataRadioTechnology() != ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN |
| 179 | || (mWifiManager.isWifiEnabled() |
| 180 | && mWifiManager.getConnectionInfo() != null |
| 181 | && mWifiManager.getConnectionInfo().getBSSID() != null)) { |
| 182 | if (DEBUG) { |
| 183 | Log.d(TAG, "SIM ready and in service: subId=" + subId + ", ss=" + ss); |
| 184 | } |
| 185 | anySimReadyAndInService = true; |
| 186 | } |
| 187 | } |
| 188 | } |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 189 | } |
| 190 | if (allSimsMissing) { |
| 191 | if (N != 0) { |
| 192 | // Shows "No SIM card | Emergency calls only" on devices that are voice-capable. |
| 193 | // This depends on mPlmn containing the text "Emergency calls only" when the radio |
| 194 | // has some connectivity. Otherwise, it should be null or empty and just show |
| 195 | // "No SIM card" |
| 196 | // Grab the first subscripton, because they all should contain the emergency text, |
| 197 | // described above. |
| 198 | displayText = makeCarrierStringOnEmergencyCapable( |
| 199 | getContext().getText(R.string.keyguard_missing_sim_message_short), |
| 200 | subs.get(0).getCarrierName()); |
| 201 | } else { |
| 202 | // We don't have a SubscriptionInfo to get the emergency calls only from. |
Jason Monk | de3260b | 2015-02-24 08:55:26 -0500 | [diff] [blame] | 203 | // Grab it from the old sticky broadcast if possible instead. We can use it |
| 204 | // here because no subscriptions are active, so we don't have |
| 205 | // to worry about MSIM clashing. |
| 206 | CharSequence text = |
| 207 | getContext().getText(com.android.internal.R.string.emergency_calls_only); |
| 208 | Intent i = getContext().registerReceiver(null, |
| 209 | new IntentFilter(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION)); |
| 210 | if (i != null) { |
| 211 | String spn = ""; |
| 212 | String plmn = ""; |
| 213 | if (i.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, false)) { |
| 214 | spn = i.getStringExtra(TelephonyIntents.EXTRA_SPN); |
| 215 | } |
| 216 | if (i.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_PLMN, false)) { |
| 217 | plmn = i.getStringExtra(TelephonyIntents.EXTRA_PLMN); |
| 218 | } |
| 219 | if (DEBUG) Log.d(TAG, "Getting plmn/spn sticky brdcst " + plmn + "/" + spn); |
Sanket Padawe | b8726b7 | 2015-04-01 14:02:16 -0700 | [diff] [blame] | 220 | if (Objects.equals(plmn, spn)) { |
| 221 | text = plmn; |
| 222 | } else { |
| 223 | text = concatenate(plmn, spn); |
| 224 | } |
Jason Monk | de3260b | 2015-02-24 08:55:26 -0500 | [diff] [blame] | 225 | } |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 226 | displayText = makeCarrierStringOnEmergencyCapable( |
Jason Monk | de3260b | 2015-02-24 08:55:26 -0500 | [diff] [blame] | 227 | getContext().getText(R.string.keyguard_missing_sim_message_short), text); |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 228 | } |
| 229 | } |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 230 | |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 231 | displayText = updateCarrierTextWithSimIoError(displayText, allSimsMissing); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 232 | // APM (airplane mode) != no carrier state. There are carrier services |
| 233 | // (e.g. WFC = Wi-Fi calling) which may operate in APM. |
| 234 | if (!anySimReadyAndInService && WirelessUtils.isAirplaneModeOn(mContext)) { |
Jason Monk | 726fb28 | 2015-03-31 12:56:11 -0400 | [diff] [blame] | 235 | displayText = getContext().getString(R.string.airplane_mode); |
| 236 | } |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 237 | setText(displayText); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | @Override |
| 241 | protected void onFinishInflate() { |
| 242 | super.onFinishInflate(); |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 243 | mSeparator = getResources().getString( |
| 244 | com.android.internal.R.string.kg_text_message_separator); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 245 | boolean shouldMarquee = KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive(); |
| 246 | setSelected(shouldMarquee); // Allow marquee to work. |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Jim Miller | 0928e01 | 2012-11-06 18:43:22 -0800 | [diff] [blame] | 249 | @Override |
| 250 | protected void onAttachedToWindow() { |
| 251 | super.onAttachedToWindow(); |
Jason Monk | 83bc2aaf | 2014-12-05 10:16:24 -0500 | [diff] [blame] | 252 | if (ConnectivityManager.from(mContext).isNetworkSupported( |
| 253 | ConnectivityManager.TYPE_MOBILE)) { |
| 254 | mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
| 255 | mKeyguardUpdateMonitor.registerCallback(mCallback); |
| 256 | } else { |
| 257 | // Don't listen and clear out the text when the device isn't a phone. |
| 258 | mKeyguardUpdateMonitor = null; |
| 259 | setText(""); |
| 260 | } |
Jim Miller | 0928e01 | 2012-11-06 18:43:22 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | @Override |
| 264 | protected void onDetachedFromWindow() { |
| 265 | super.onDetachedFromWindow(); |
Jason Monk | 83bc2aaf | 2014-12-05 10:16:24 -0500 | [diff] [blame] | 266 | if (mKeyguardUpdateMonitor != null) { |
| 267 | mKeyguardUpdateMonitor.removeCallback(mCallback); |
| 268 | } |
Jim Miller | 0928e01 | 2012-11-06 18:43:22 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Matthew Ng | 3a6db67 | 2017-11-28 14:35:25 -0800 | [diff] [blame^] | 271 | @Override |
| 272 | protected void onVisibilityChanged(View changedView, int visibility) { |
| 273 | super.onVisibilityChanged(changedView, visibility); |
| 274 | |
| 275 | // Only show marquee when visible |
| 276 | if (visibility == VISIBLE) { |
| 277 | setEllipsize(TextUtils.TruncateAt.MARQUEE); |
| 278 | } else { |
| 279 | setEllipsize(TextUtils.TruncateAt.END); |
| 280 | } |
| 281 | } |
| 282 | |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 283 | /** |
| 284 | * Top-level function for creating carrier text. Makes text based on simState, PLMN |
| 285 | * and SPN as well as device capabilities, such as being emergency call capable. |
| 286 | * |
| 287 | * @param simState |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 288 | * @param text |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 289 | * @param spn |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 290 | * @return Carrier text if not in missing state, null otherwise. |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 291 | */ |
| 292 | private CharSequence getCarrierTextForSimState(IccCardConstants.State simState, |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 293 | CharSequence text) { |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 294 | CharSequence carrierText = null; |
| 295 | StatusMode status = getStatusForIccState(simState); |
| 296 | switch (status) { |
| 297 | case Normal: |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 298 | carrierText = text; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 299 | break; |
| 300 | |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 301 | case SimNotReady: |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 302 | // Null is reserved for denoting missing, in this case we have nothing to display. |
| 303 | carrierText = ""; // nothing to display yet. |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 304 | break; |
| 305 | |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 306 | case NetworkLocked: |
| 307 | carrierText = makeCarrierStringOnEmergencyCapable( |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 308 | mContext.getText(R.string.keyguard_network_locked_message), text); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 309 | break; |
| 310 | |
| 311 | case SimMissing: |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 312 | carrierText = null; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 313 | break; |
| 314 | |
| 315 | case SimPermDisabled: |
| 316 | carrierText = getContext().getText( |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 317 | R.string.keyguard_permanent_disabled_sim_message_short); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 318 | break; |
| 319 | |
| 320 | case SimMissingLocked: |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 321 | carrierText = null; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 322 | break; |
| 323 | |
| 324 | case SimLocked: |
| 325 | carrierText = makeCarrierStringOnEmergencyCapable( |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 326 | getContext().getText(R.string.keyguard_sim_locked_message), |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 327 | text); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 328 | break; |
| 329 | |
| 330 | case SimPukLocked: |
| 331 | carrierText = makeCarrierStringOnEmergencyCapable( |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 332 | getContext().getText(R.string.keyguard_sim_puk_locked_message), |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 333 | text); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 334 | break; |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 335 | case SimIoError: |
| 336 | carrierText = makeCarrierStringOnEmergencyCapable( |
| 337 | getContext().getText(R.string.keyguard_sim_error_message_short), |
| 338 | text); |
| 339 | break; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | return carrierText; |
| 343 | } |
| 344 | |
| 345 | /* |
| 346 | * Add emergencyCallMessage to carrier string only if phone supports emergency calls. |
| 347 | */ |
| 348 | private CharSequence makeCarrierStringOnEmergencyCapable( |
| 349 | CharSequence simMessage, CharSequence emergencyCallMessage) { |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 350 | if (mIsEmergencyCallCapable) { |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 351 | return concatenate(simMessage, emergencyCallMessage); |
| 352 | } |
| 353 | return simMessage; |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * Determine the current status of the lock screen given the SIM state and other stuff. |
| 358 | */ |
| 359 | private StatusMode getStatusForIccState(IccCardConstants.State simState) { |
| 360 | // Since reading the SIM may take a while, we assume it is present until told otherwise. |
| 361 | if (simState == null) { |
| 362 | return StatusMode.Normal; |
| 363 | } |
| 364 | |
| 365 | final boolean missingAndNotProvisioned = |
| 366 | !KeyguardUpdateMonitor.getInstance(mContext).isDeviceProvisioned() |
| 367 | && (simState == IccCardConstants.State.ABSENT || |
| 368 | simState == IccCardConstants.State.PERM_DISABLED); |
| 369 | |
| 370 | // Assume we're NETWORK_LOCKED if not provisioned |
| 371 | simState = missingAndNotProvisioned ? IccCardConstants.State.NETWORK_LOCKED : simState; |
| 372 | switch (simState) { |
| 373 | case ABSENT: |
| 374 | return StatusMode.SimMissing; |
| 375 | case NETWORK_LOCKED: |
| 376 | return StatusMode.SimMissingLocked; |
| 377 | case NOT_READY: |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 378 | return StatusMode.SimNotReady; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 379 | case PIN_REQUIRED: |
| 380 | return StatusMode.SimLocked; |
| 381 | case PUK_REQUIRED: |
| 382 | return StatusMode.SimPukLocked; |
| 383 | case READY: |
| 384 | return StatusMode.Normal; |
| 385 | case PERM_DISABLED: |
| 386 | return StatusMode.SimPermDisabled; |
| 387 | case UNKNOWN: |
| 388 | return StatusMode.SimMissing; |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 389 | case CARD_IO_ERROR: |
| 390 | return StatusMode.SimIoError; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 391 | } |
| 392 | return StatusMode.SimMissing; |
| 393 | } |
| 394 | |
| 395 | private static CharSequence concatenate(CharSequence plmn, CharSequence spn) { |
| 396 | final boolean plmnValid = !TextUtils.isEmpty(plmn); |
| 397 | final boolean spnValid = !TextUtils.isEmpty(spn); |
| 398 | if (plmnValid && spnValid) { |
Sanket Padawe | b8726b7 | 2015-04-01 14:02:16 -0700 | [diff] [blame] | 399 | return new StringBuilder().append(plmn).append(mSeparator).append(spn).toString(); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 400 | } else if (plmnValid) { |
| 401 | return plmn; |
| 402 | } else if (spnValid) { |
| 403 | return spn; |
| 404 | } else { |
| 405 | return ""; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | private CharSequence getCarrierHelpTextForSimState(IccCardConstants.State simState, |
| 410 | String plmn, String spn) { |
| 411 | int carrierHelpTextId = 0; |
| 412 | StatusMode status = getStatusForIccState(simState); |
| 413 | switch (status) { |
| 414 | case NetworkLocked: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 415 | carrierHelpTextId = R.string.keyguard_instructions_when_pattern_disabled; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 416 | break; |
| 417 | |
| 418 | case SimMissing: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 419 | carrierHelpTextId = R.string.keyguard_missing_sim_instructions_long; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 420 | break; |
| 421 | |
| 422 | case SimPermDisabled: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 423 | carrierHelpTextId = R.string.keyguard_permanent_disabled_sim_instructions; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 424 | break; |
| 425 | |
| 426 | case SimMissingLocked: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 427 | carrierHelpTextId = R.string.keyguard_missing_sim_instructions; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 428 | break; |
| 429 | |
| 430 | case Normal: |
| 431 | case SimLocked: |
| 432 | case SimPukLocked: |
| 433 | break; |
| 434 | } |
| 435 | |
| 436 | return mContext.getText(carrierHelpTextId); |
| 437 | } |
Victoria Lease | 1d80e97 | 2013-11-01 16:34:03 -0700 | [diff] [blame] | 438 | |
| 439 | private class CarrierTextTransformationMethod extends SingleLineTransformationMethod { |
| 440 | private final Locale mLocale; |
| 441 | private final boolean mAllCaps; |
| 442 | |
| 443 | public CarrierTextTransformationMethod(Context context, boolean allCaps) { |
| 444 | mLocale = context.getResources().getConfiguration().locale; |
| 445 | mAllCaps = allCaps; |
| 446 | } |
| 447 | |
| 448 | @Override |
| 449 | public CharSequence getTransformation(CharSequence source, View view) { |
| 450 | source = super.getTransformation(source, view); |
| 451 | |
| 452 | if (mAllCaps && source != null) { |
| 453 | source = source.toString().toUpperCase(mLocale); |
| 454 | } |
| 455 | |
| 456 | return source; |
| 457 | } |
| 458 | } |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 459 | } |