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; |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 42 | |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 43 | import android.telephony.TelephonyManager; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 44 | |
| 45 | public class CarrierText extends TextView { |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 46 | private static final boolean DEBUG = KeyguardConstants.DEBUG; |
| 47 | private static final String TAG = "CarrierText"; |
| 48 | |
Jim Miller | e9be140 | 2012-11-01 16:14:20 -0700 | [diff] [blame] | 49 | private static CharSequence mSeparator; |
| 50 | |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 51 | private final boolean mIsEmergencyCallCapable; |
| 52 | |
Bill Lin | 6c7ccab | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 53 | private boolean mTelephonyCapable; |
| 54 | |
| 55 | private boolean mShowMissingSim; |
| 56 | |
| 57 | private boolean mShowAirplaneMode; |
| 58 | |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 59 | private KeyguardUpdateMonitor mKeyguardUpdateMonitor; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 60 | |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 61 | private WifiManager mWifiManager; |
| 62 | |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 63 | private boolean[] mSimErrorState = new boolean[TelephonyManager.getDefault().getPhoneCount()]; |
| 64 | |
Bill Lin | 6c7ccab | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 65 | private final KeyguardUpdateMonitorCallback mCallback = new KeyguardUpdateMonitorCallback() { |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 66 | @Override |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 67 | public void onRefreshCarrierInfo() { |
Bill Lin | 6c7ccab | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 68 | if (DEBUG) Log.d(TAG, "onRefreshCarrierInfo(), mTelephonyCapable: " |
| 69 | + Boolean.toString(mTelephonyCapable)); |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 70 | updateCarrierText(); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 71 | } |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 72 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 73 | public void onFinishedGoingToSleep(int why) { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 74 | setSelected(false); |
| 75 | }; |
| 76 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 77 | public void onStartedWakingUp() { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 78 | setSelected(true); |
| 79 | }; |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 80 | |
Bill Lin | 6c7ccab | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 81 | @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 Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 89 | public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) { |
| 90 | if (slotId < 0) { |
Bill Lin | 6c7ccab | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 91 | Log.d(TAG, "onSimStateChanged() - slotId invalid: " + slotId |
| 92 | + " mTelephonyCapable: " + Boolean.toString(mTelephonyCapable)); |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 93 | 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 Lin | 6c7ccab | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 104 | } |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 105 | }; |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 106 | |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 107 | /** |
| 108 | * The status of this lock screen. Primarily used for widgets on LockScreen. |
| 109 | */ |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 110 | private static enum StatusMode { |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 111 | 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 Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 117 | SimPermDisabled, // SIM card is permanently disabled due to PUK unlock failure |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 118 | SimNotReady, // SIM is not ready yet. May never be on devices w/o a SIM. |
Bill Lin | 6c7ccab | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 119 | SimIoError, // SIM card is faulty |
| 120 | SimUnknown // SIM card is unknown |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | public CarrierText(Context context) { |
| 124 | this(context, null); |
| 125 | } |
| 126 | |
| 127 | public CarrierText(Context context, AttributeSet attrs) { |
| 128 | super(context, attrs); |
Adrian Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 129 | mIsEmergencyCallCapable = context.getResources().getBoolean( |
| 130 | com.android.internal.R.bool.config_voice_capable); |
Jorim Jaggi | 2580793 | 2014-04-24 23:29:46 +0200 | [diff] [blame] | 131 | 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 Lin | 6c7ccab | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 136 | mShowAirplaneMode = a.getBoolean(R.styleable.CarrierText_showAirplaneMode, false); |
| 137 | mShowMissingSim = a.getBoolean(R.styleable.CarrierText_showMissingSim, false); |
Jorim Jaggi | 2580793 | 2014-04-24 23:29:46 +0200 | [diff] [blame] | 138 | } finally { |
| 139 | a.recycle(); |
| 140 | } |
Victoria Lease | 1d80e97 | 2013-11-01 16:34:03 -0700 | [diff] [blame] | 141 | setTransformationMethod(new CarrierTextTransformationMethod(mContext, useAllCaps)); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 142 | |
| 143 | mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 146 | /** |
| 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 Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 175 | protected void updateCarrierText() { |
| 176 | boolean allSimsMissing = true; |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 177 | boolean anySimReadyAndInService = false; |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 178 | 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 Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 184 | int subId = subs.get(i).getSubscriptionId(); |
| 185 | State simState = mKeyguardUpdateMonitor.getSimState(subId); |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 186 | CharSequence carrierName = subs.get(i).getCarrierName(); |
| 187 | CharSequence carrierTextForSimState = getCarrierTextForSimState(simState, carrierName); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 188 | if (DEBUG) { |
| 189 | Log.d(TAG, "Handling (subId=" + subId + "): " + simState + " " + carrierName); |
| 190 | } |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 191 | if (carrierTextForSimState != null) { |
| 192 | allSimsMissing = false; |
| 193 | displayText = concatenate(displayText, carrierTextForSimState); |
| 194 | } |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 195 | 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 Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 211 | } |
| 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 Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 221 | getMissingSimMessage(), subs.get(0).getCarrierName()); |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 222 | } else { |
| 223 | // 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] | 224 | // 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 Padawe | b8726b7 | 2015-04-01 14:02:16 -0700 | [diff] [blame] | 241 | if (Objects.equals(plmn, spn)) { |
| 242 | text = plmn; |
| 243 | } else { |
| 244 | text = concatenate(plmn, spn); |
| 245 | } |
Jason Monk | de3260b | 2015-02-24 08:55:26 -0500 | [diff] [blame] | 246 | } |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 247 | displayText = makeCarrierStringOnEmergencyCapable(getMissingSimMessage(), text); |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 248 | } |
| 249 | } |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 250 | |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 251 | displayText = updateCarrierTextWithSimIoError(displayText, allSimsMissing); |
Etan Cohen | 47051d8 | 2015-07-06 16:19:04 -0700 | [diff] [blame] | 252 | // 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 Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 255 | displayText = getAirplaneModeMessage(); |
Jason Monk | 726fb28 | 2015-03-31 12:56:11 -0400 | [diff] [blame] | 256 | } |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 257 | setText(displayText); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 260 | private String getMissingSimMessage() { |
Bill Lin | 6c7ccab | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 261 | return mShowMissingSim && mTelephonyCapable |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 262 | ? getContext().getString(R.string.keyguard_missing_sim_message_short) : ""; |
| 263 | } |
| 264 | |
| 265 | private String getAirplaneModeMessage() { |
Bill Lin | 6c7ccab | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 266 | return mShowAirplaneMode |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 267 | ? getContext().getString(R.string.airplane_mode) : ""; |
| 268 | } |
| 269 | |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 270 | @Override |
| 271 | protected void onFinishInflate() { |
| 272 | super.onFinishInflate(); |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 273 | mSeparator = getResources().getString( |
| 274 | com.android.internal.R.string.kg_text_message_separator); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 275 | boolean shouldMarquee = KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive(); |
| 276 | setSelected(shouldMarquee); // Allow marquee to work. |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Jim Miller | 0928e01 | 2012-11-06 18:43:22 -0800 | [diff] [blame] | 279 | @Override |
| 280 | protected void onAttachedToWindow() { |
| 281 | super.onAttachedToWindow(); |
Jason Monk | 83bc2aaf | 2014-12-05 10:16:24 -0500 | [diff] [blame] | 282 | 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 Miller | 0928e01 | 2012-11-06 18:43:22 -0800 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | @Override |
| 294 | protected void onDetachedFromWindow() { |
| 295 | super.onDetachedFromWindow(); |
Jason Monk | 83bc2aaf | 2014-12-05 10:16:24 -0500 | [diff] [blame] | 296 | if (mKeyguardUpdateMonitor != null) { |
| 297 | mKeyguardUpdateMonitor.removeCallback(mCallback); |
| 298 | } |
Jim Miller | 0928e01 | 2012-11-06 18:43:22 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Matthew Ng | 3a6db67 | 2017-11-28 14:35:25 -0800 | [diff] [blame] | 301 | @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 Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 313 | /** |
| 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 Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 318 | * @param text |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 319 | * @param spn |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 320 | * @return Carrier text if not in missing state, null otherwise. |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 321 | */ |
| 322 | private CharSequence getCarrierTextForSimState(IccCardConstants.State simState, |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 323 | CharSequence text) { |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 324 | CharSequence carrierText = null; |
| 325 | StatusMode status = getStatusForIccState(simState); |
| 326 | switch (status) { |
| 327 | case Normal: |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 328 | carrierText = text; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 329 | break; |
| 330 | |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 331 | case SimNotReady: |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 332 | // Null is reserved for denoting missing, in this case we have nothing to display. |
| 333 | carrierText = ""; // nothing to display yet. |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 334 | break; |
| 335 | |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 336 | case NetworkLocked: |
| 337 | carrierText = makeCarrierStringOnEmergencyCapable( |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 338 | mContext.getText(R.string.keyguard_network_locked_message), text); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 339 | break; |
| 340 | |
| 341 | case SimMissing: |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 342 | carrierText = null; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 343 | break; |
| 344 | |
| 345 | case SimPermDisabled: |
Dan Sandler | f058cc6 | 2018-06-08 15:34:52 -0400 | [diff] [blame] | 346 | carrierText = makeCarrierStringOnEmergencyCapable( |
| 347 | getContext().getText( |
| 348 | R.string.keyguard_permanent_disabled_sim_message_short), |
| 349 | text); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 350 | break; |
| 351 | |
| 352 | case SimMissingLocked: |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 353 | carrierText = null; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 354 | break; |
| 355 | |
| 356 | case SimLocked: |
| 357 | carrierText = makeCarrierStringOnEmergencyCapable( |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 358 | getContext().getText(R.string.keyguard_sim_locked_message), |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 359 | text); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 360 | break; |
| 361 | |
| 362 | case SimPukLocked: |
| 363 | carrierText = makeCarrierStringOnEmergencyCapable( |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 364 | getContext().getText(R.string.keyguard_sim_puk_locked_message), |
Jason Monk | 9ff69bd | 2014-12-02 16:43:17 -0500 | [diff] [blame] | 365 | text); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 366 | break; |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 367 | case SimIoError: |
| 368 | carrierText = makeCarrierStringOnEmergencyCapable( |
| 369 | getContext().getText(R.string.keyguard_sim_error_message_short), |
| 370 | text); |
| 371 | break; |
Bill Lin | 6c7ccab | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 372 | case SimUnknown: |
| 373 | carrierText = null; |
| 374 | break; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 375 | } |
| 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 Roos | c2e0168 | 2015-01-15 23:20:20 +0100 | [diff] [blame] | 385 | if (mIsEmergencyCallCapable) { |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 386 | 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 Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 413 | return StatusMode.SimNotReady; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 414 | 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 Lin | 6c7ccab | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 423 | return StatusMode.SimUnknown; |
Wileen Chiu | 6b8b22e | 2014-10-29 22:48:21 +0530 | [diff] [blame] | 424 | case CARD_IO_ERROR: |
| 425 | return StatusMode.SimIoError; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 426 | } |
Bill Lin | 6c7ccab | 2018-07-05 17:48:49 +0800 | [diff] [blame] | 427 | return StatusMode.SimUnknown; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 428 | } |
| 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 Padawe | b8726b7 | 2015-04-01 14:02:16 -0700 | [diff] [blame] | 434 | return new StringBuilder().append(plmn).append(mSeparator).append(spn).toString(); |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 435 | } 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 Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 450 | carrierHelpTextId = R.string.keyguard_instructions_when_pattern_disabled; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 451 | break; |
| 452 | |
| 453 | case SimMissing: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 454 | carrierHelpTextId = R.string.keyguard_missing_sim_instructions_long; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 455 | break; |
| 456 | |
| 457 | case SimPermDisabled: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 458 | carrierHelpTextId = R.string.keyguard_permanent_disabled_sim_instructions; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 459 | break; |
| 460 | |
| 461 | case SimMissingLocked: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 462 | carrierHelpTextId = R.string.keyguard_missing_sim_instructions; |
Jim Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 463 | break; |
| 464 | |
| 465 | case Normal: |
| 466 | case SimLocked: |
| 467 | case SimPukLocked: |
| 468 | break; |
| 469 | } |
| 470 | |
| 471 | return mContext.getText(carrierHelpTextId); |
| 472 | } |
Victoria Lease | 1d80e97 | 2013-11-01 16:34:03 -0700 | [diff] [blame] | 473 | |
| 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 Miller | f9cb7ba | 2012-09-17 22:31:56 -0700 | [diff] [blame] | 494 | } |