Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | package com.android.systemui.statusbar.policy; |
| 17 | |
| 18 | import android.content.Context; |
| 19 | import android.content.Intent; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 20 | import android.database.ContentObserver; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 21 | import android.net.NetworkCapabilities; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 22 | import android.os.Handler; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 23 | import android.os.Looper; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 24 | import android.provider.Settings.Global; |
Jayachandran C | a6f9b6d | 2019-11-07 17:26:02 -0800 | [diff] [blame] | 25 | import android.telephony.CellSignalStrength; |
| 26 | import android.telephony.CellSignalStrengthCdma; |
Jack Yu | e27d3fd | 2019-03-15 14:49:53 -0700 | [diff] [blame] | 27 | import android.telephony.NetworkRegistrationInfo; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 28 | import android.telephony.PhoneStateListener; |
| 29 | import android.telephony.ServiceState; |
| 30 | import android.telephony.SignalStrength; |
| 31 | import android.telephony.SubscriptionInfo; |
| 32 | import android.telephony.SubscriptionManager; |
| 33 | import android.telephony.TelephonyManager; |
Jason Monk | 93fb68f | 2015-07-20 11:43:56 -0400 | [diff] [blame] | 34 | import android.text.TextUtils; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 35 | import android.util.Log; |
| 36 | import android.util.SparseArray; |
| 37 | |
| 38 | import com.android.internal.annotations.VisibleForTesting; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 39 | import com.android.internal.telephony.TelephonyIntents; |
| 40 | import com.android.internal.telephony.cdma.EriInfo; |
SongFerngWang | 8cfb4d5 | 2018-08-21 18:04:29 +0800 | [diff] [blame] | 41 | import com.android.settingslib.Utils; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 42 | import com.android.settingslib.graph.SignalDrawable; |
Antony Sargent | c026de3 | 2019-05-21 16:29:04 -0700 | [diff] [blame] | 43 | import com.android.settingslib.net.SignalStrengthUtil; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 44 | import com.android.systemui.R; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 45 | import com.android.systemui.statusbar.policy.NetworkController.IconState; |
Jason Monk | e06b065 | 2016-03-02 16:35:27 -0500 | [diff] [blame] | 46 | import com.android.systemui.statusbar.policy.NetworkController.SignalCallback; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 47 | import com.android.systemui.statusbar.policy.NetworkControllerImpl.Config; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 48 | import com.android.systemui.statusbar.policy.NetworkControllerImpl.SubscriptionDefaults; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 49 | |
| 50 | import java.io.PrintWriter; |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 51 | import java.util.BitSet; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 52 | import java.util.Objects; |
Jayachandran C | a6f9b6d | 2019-11-07 17:26:02 -0800 | [diff] [blame] | 53 | import java.util.List; |
SongFerngWang | 3cbcf75 | 2019-03-21 23:14:20 +0800 | [diff] [blame] | 54 | import java.util.regex.Matcher; |
| 55 | import java.util.regex.Pattern; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 56 | |
| 57 | |
| 58 | public class MobileSignalController extends SignalController< |
| 59 | MobileSignalController.MobileState, MobileSignalController.MobileIconGroup> { |
| 60 | private final TelephonyManager mPhone; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 61 | private final SubscriptionDefaults mDefaults; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 62 | private final String mNetworkNameDefault; |
| 63 | private final String mNetworkNameSeparator; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 64 | private final ContentObserver mObserver; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 65 | @VisibleForTesting |
| 66 | final PhoneStateListener mPhoneStateListener; |
| 67 | // Save entire info for logging, we only use the id. |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 68 | final SubscriptionInfo mSubscriptionInfo; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 69 | |
| 70 | // @VisibleForDemoMode |
| 71 | final SparseArray<MobileIconGroup> mNetworkToIconLookup; |
| 72 | |
| 73 | // Since some pieces of the phone state are interdependent we store it locally, |
| 74 | // this could potentially become part of MobileState for simplification/complication |
| 75 | // of code. |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 76 | private int mDataNetType = TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 77 | private int mDataState = TelephonyManager.DATA_DISCONNECTED; |
| 78 | private ServiceState mServiceState; |
| 79 | private SignalStrength mSignalStrength; |
| 80 | private MobileIconGroup mDefaultIcons; |
| 81 | private Config mConfig; |
andychou | b935e68 | 2019-04-11 23:40:49 +0800 | [diff] [blame] | 82 | @VisibleForTesting |
| 83 | boolean mInflateSignalStrengths = false; |
SongFerngWang | 3cbcf75 | 2019-03-21 23:14:20 +0800 | [diff] [blame] | 84 | // Some specific carriers have 5GE network which is special LTE CA network. |
| 85 | private static final int NETWORK_TYPE_LTE_CA_5GE = TelephonyManager.MAX_NETWORK_TYPE + 1; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 86 | |
| 87 | // TODO: Reduce number of vars passed in, if we have the NetworkController, probably don't |
| 88 | // need listener lists anymore. |
| 89 | public MobileSignalController(Context context, Config config, boolean hasMobileData, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 90 | TelephonyManager phone, CallbackHandler callbackHandler, |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 91 | NetworkControllerImpl networkController, SubscriptionInfo info, |
| 92 | SubscriptionDefaults defaults, Looper receiverLooper) { |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 93 | super("MobileSignalController(" + info.getSubscriptionId() + ")", context, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 94 | NetworkCapabilities.TRANSPORT_CELLULAR, callbackHandler, |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 95 | networkController); |
| 96 | mNetworkToIconLookup = new SparseArray<>(); |
| 97 | mConfig = config; |
| 98 | mPhone = phone; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 99 | mDefaults = defaults; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 100 | mSubscriptionInfo = info; |
chen xu | 84a9087 | 2019-03-28 15:44:12 -0700 | [diff] [blame] | 101 | mPhoneStateListener = new MobilePhoneStateListener(receiverLooper); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 102 | mNetworkNameSeparator = getStringIfExists(R.string.status_bar_network_name_separator); |
| 103 | mNetworkNameDefault = getStringIfExists( |
| 104 | com.android.internal.R.string.lockscreen_carrier_default); |
| 105 | |
| 106 | mapIconSets(); |
| 107 | |
Jason Monk | 00aa9d4 | 2015-08-10 10:12:02 -0400 | [diff] [blame] | 108 | String networkName = info.getCarrierName() != null ? info.getCarrierName().toString() |
| 109 | : mNetworkNameDefault; |
| 110 | mLastState.networkName = mCurrentState.networkName = networkName; |
| 111 | mLastState.networkNameData = mCurrentState.networkNameData = networkName; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 112 | mLastState.enabled = mCurrentState.enabled = hasMobileData; |
| 113 | mLastState.iconGroup = mCurrentState.iconGroup = mDefaultIcons; |
| 114 | // Get initial data sim state. |
| 115 | updateDataSim(); |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 116 | mObserver = new ContentObserver(new Handler(receiverLooper)) { |
| 117 | @Override |
| 118 | public void onChange(boolean selfChange) { |
| 119 | updateTelephony(); |
| 120 | } |
| 121 | }; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | public void setConfiguration(Config config) { |
| 125 | mConfig = config; |
andychou | 9e39628 | 2019-04-10 20:49:06 +0800 | [diff] [blame] | 126 | updateInflateSignalStrength(); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 127 | mapIconSets(); |
| 128 | updateTelephony(); |
| 129 | } |
| 130 | |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 131 | public int getDataContentDescription() { |
| 132 | return getIcons().mDataContentDescription; |
| 133 | } |
| 134 | |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 135 | public void setAirplaneMode(boolean airplaneMode) { |
| 136 | mCurrentState.airplaneMode = airplaneMode; |
| 137 | notifyListenersIfNecessary(); |
| 138 | } |
| 139 | |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 140 | public void setUserSetupComplete(boolean userSetup) { |
| 141 | mCurrentState.userSetup = userSetup; |
| 142 | notifyListenersIfNecessary(); |
| 143 | } |
| 144 | |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 145 | @Override |
| 146 | public void updateConnectivity(BitSet connectedTransports, BitSet validatedTransports) { |
| 147 | boolean isValidated = validatedTransports.get(mTransportType); |
| 148 | mCurrentState.isDefault = connectedTransports.get(mTransportType); |
| 149 | // Only show this as not having connectivity if we are default. |
| 150 | mCurrentState.inetCondition = (isValidated || !mCurrentState.isDefault) ? 1 : 0; |
| 151 | notifyListenersIfNecessary(); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 152 | } |
| 153 | |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 154 | public void setCarrierNetworkChangeMode(boolean carrierNetworkChangeMode) { |
| 155 | mCurrentState.carrierNetworkChangeMode = carrierNetworkChangeMode; |
Andrew Flynn | 2fdbe12 | 2015-06-01 16:34:21 -0400 | [diff] [blame] | 156 | updateTelephony(); |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 157 | } |
| 158 | |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 159 | /** |
| 160 | * Start listening for phone state changes. |
| 161 | */ |
| 162 | public void registerListener() { |
| 163 | mPhone.listen(mPhoneStateListener, |
| 164 | PhoneStateListener.LISTEN_SERVICE_STATE |
| 165 | | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS |
| 166 | | PhoneStateListener.LISTEN_CALL_STATE |
| 167 | | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 168 | | PhoneStateListener.LISTEN_DATA_ACTIVITY |
Fabian Kozynski | aaf7897 | 2019-07-08 10:02:08 -0400 | [diff] [blame] | 169 | | PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE |
| 170 | | PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE); |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 171 | mContext.getContentResolver().registerContentObserver(Global.getUriFor(Global.MOBILE_DATA), |
| 172 | true, mObserver); |
| 173 | mContext.getContentResolver().registerContentObserver(Global.getUriFor( |
| 174 | Global.MOBILE_DATA + mSubscriptionInfo.getSubscriptionId()), |
| 175 | true, mObserver); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Stop listening for phone state changes. |
| 180 | */ |
| 181 | public void unregisterListener() { |
| 182 | mPhone.listen(mPhoneStateListener, 0); |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 183 | mContext.getContentResolver().unregisterContentObserver(mObserver); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Produce a mapping of data network types to icon groups for simple and quick use in |
| 188 | * updateTelephony. |
| 189 | */ |
| 190 | private void mapIconSets() { |
| 191 | mNetworkToIconLookup.clear(); |
| 192 | |
| 193 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_EVDO_0, TelephonyIcons.THREE_G); |
| 194 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_EVDO_A, TelephonyIcons.THREE_G); |
| 195 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_EVDO_B, TelephonyIcons.THREE_G); |
| 196 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_EHRPD, TelephonyIcons.THREE_G); |
| 197 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_UMTS, TelephonyIcons.THREE_G); |
Wileen Chiu | 4105ab0 | 2015-09-18 15:17:54 -0700 | [diff] [blame] | 198 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_TD_SCDMA, TelephonyIcons.THREE_G); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 199 | |
| 200 | if (!mConfig.showAtLeast3G) { |
| 201 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_UNKNOWN, |
| 202 | TelephonyIcons.UNKNOWN); |
| 203 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_EDGE, TelephonyIcons.E); |
| 204 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_CDMA, TelephonyIcons.ONE_X); |
| 205 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_1xRTT, TelephonyIcons.ONE_X); |
| 206 | |
| 207 | mDefaultIcons = TelephonyIcons.G; |
| 208 | } else { |
| 209 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_UNKNOWN, |
| 210 | TelephonyIcons.THREE_G); |
| 211 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_EDGE, |
| 212 | TelephonyIcons.THREE_G); |
| 213 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_CDMA, |
| 214 | TelephonyIcons.THREE_G); |
| 215 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_1xRTT, |
| 216 | TelephonyIcons.THREE_G); |
| 217 | mDefaultIcons = TelephonyIcons.THREE_G; |
| 218 | } |
| 219 | |
| 220 | MobileIconGroup hGroup = TelephonyIcons.THREE_G; |
Amin Shaikh | f5830ca | 2018-03-09 14:06:50 -0500 | [diff] [blame] | 221 | MobileIconGroup hPlusGroup = TelephonyIcons.THREE_G; |
vagdevi | 3f2b9a5 | 2019-08-09 09:45:14 -0700 | [diff] [blame] | 222 | if (mConfig.show4gFor3g) { |
| 223 | hGroup = TelephonyIcons.FOUR_G; |
| 224 | hPlusGroup = TelephonyIcons.FOUR_G; |
| 225 | } else if (mConfig.hspaDataDistinguishable) { |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 226 | hGroup = TelephonyIcons.H; |
Amin Shaikh | f5830ca | 2018-03-09 14:06:50 -0500 | [diff] [blame] | 227 | hPlusGroup = TelephonyIcons.H_PLUS; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 228 | } |
vagdevi | 3f2b9a5 | 2019-08-09 09:45:14 -0700 | [diff] [blame] | 229 | |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 230 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_HSDPA, hGroup); |
| 231 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_HSUPA, hGroup); |
| 232 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_HSPA, hGroup); |
Amin Shaikh | f5830ca | 2018-03-09 14:06:50 -0500 | [diff] [blame] | 233 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_HSPAP, hPlusGroup); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 234 | |
| 235 | if (mConfig.show4gForLte) { |
| 236 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_LTE, TelephonyIcons.FOUR_G); |
Robert Greenwalt | 37d34ba | 2016-07-27 14:54:34 -0700 | [diff] [blame] | 237 | if (mConfig.hideLtePlus) { |
| 238 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_LTE_CA, |
| 239 | TelephonyIcons.FOUR_G); |
| 240 | } else { |
| 241 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_LTE_CA, |
| 242 | TelephonyIcons.FOUR_G_PLUS); |
| 243 | } |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 244 | } else { |
| 245 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_LTE, TelephonyIcons.LTE); |
Robert Greenwalt | 37d34ba | 2016-07-27 14:54:34 -0700 | [diff] [blame] | 246 | if (mConfig.hideLtePlus) { |
| 247 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_LTE_CA, |
| 248 | TelephonyIcons.LTE); |
| 249 | } else { |
| 250 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_LTE_CA, |
| 251 | TelephonyIcons.LTE_PLUS); |
| 252 | } |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 253 | } |
SongFerngWang | 3cbcf75 | 2019-03-21 23:14:20 +0800 | [diff] [blame] | 254 | mNetworkToIconLookup.put(NETWORK_TYPE_LTE_CA_5GE, |
| 255 | TelephonyIcons.LTE_CA_5G_E); |
Jason Monk | 7150d7f | 2015-07-09 10:14:12 -0400 | [diff] [blame] | 256 | mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_IWLAN, TelephonyIcons.WFC); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 257 | } |
| 258 | |
andychou | 9e39628 | 2019-04-10 20:49:06 +0800 | [diff] [blame] | 259 | private void updateInflateSignalStrength() { |
Antony Sargent | c026de3 | 2019-05-21 16:29:04 -0700 | [diff] [blame] | 260 | mInflateSignalStrengths = SignalStrengthUtil.shouldInflateSignalStrength(mContext, |
| 261 | mSubscriptionInfo.getSubscriptionId()); |
andychou | 9e39628 | 2019-04-10 20:49:06 +0800 | [diff] [blame] | 262 | } |
| 263 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 264 | private int getNumLevels() { |
andychou | 9e39628 | 2019-04-10 20:49:06 +0800 | [diff] [blame] | 265 | if (mInflateSignalStrengths) { |
Jason Monk | 43c14d1 | 2017-06-22 11:20:04 -0400 | [diff] [blame] | 266 | return SignalStrength.NUM_SIGNAL_STRENGTH_BINS + 1; |
| 267 | } |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 268 | return SignalStrength.NUM_SIGNAL_STRENGTH_BINS; |
| 269 | } |
| 270 | |
| 271 | @Override |
| 272 | public int getCurrentIconId() { |
| 273 | if (mCurrentState.iconGroup == TelephonyIcons.CARRIER_NETWORK_CHANGE) { |
| 274 | return SignalDrawable.getCarrierChangeState(getNumLevels()); |
| 275 | } else if (mCurrentState.connected) { |
Jason Monk | 43c14d1 | 2017-06-22 11:20:04 -0400 | [diff] [blame] | 276 | int level = mCurrentState.level; |
andychou | 9e39628 | 2019-04-10 20:49:06 +0800 | [diff] [blame] | 277 | if (mInflateSignalStrengths) { |
Jason Monk | 43c14d1 | 2017-06-22 11:20:04 -0400 | [diff] [blame] | 278 | level++; |
| 279 | } |
Amin Shaikh | af4c193 | 2018-03-08 10:29:56 -0500 | [diff] [blame] | 280 | boolean dataDisabled = mCurrentState.userSetup |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 281 | && (mCurrentState.iconGroup == TelephonyIcons.DATA_DISABLED |
| 282 | || mCurrentState.iconGroup == TelephonyIcons.NOT_DEFAULT_DATA); |
Amin Shaikh | af4c193 | 2018-03-08 10:29:56 -0500 | [diff] [blame] | 283 | boolean noInternet = mCurrentState.inetCondition == 0; |
| 284 | boolean cutOut = dataDisabled || noInternet; |
| 285 | return SignalDrawable.getState(level, getNumLevels(), cutOut); |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 286 | } else if (mCurrentState.enabled) { |
| 287 | return SignalDrawable.getEmptyState(getNumLevels()); |
| 288 | } else { |
| 289 | return 0; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | @Override |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 294 | public int getQsCurrentIconId() { |
| 295 | return getCurrentIconId(); |
| 296 | } |
| 297 | |
| 298 | @Override |
Jason Monk | e06b065 | 2016-03-02 16:35:27 -0500 | [diff] [blame] | 299 | public void notifyListeners(SignalCallback callback) { |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 300 | MobileIconGroup icons = getIcons(); |
| 301 | |
| 302 | String contentDescription = getStringIfExists(getContentDescription()); |
| 303 | String dataContentDescription = getStringIfExists(icons.mDataContentDescription); |
Amin Shaikh | 43ad7fe | 2018-03-05 14:34:44 -0500 | [diff] [blame] | 304 | if (mCurrentState.inetCondition == 0) { |
| 305 | dataContentDescription = mContext.getString(R.string.data_connection_no_internet); |
| 306 | } |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 307 | final boolean dataDisabled = (mCurrentState.iconGroup == TelephonyIcons.DATA_DISABLED |
| 308 | || mCurrentState.iconGroup == TelephonyIcons.NOT_DEFAULT_DATA) |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 309 | && mCurrentState.userSetup; |
Jeff Davidson | 5c7daaf | 2015-01-27 16:24:32 -0800 | [diff] [blame] | 310 | |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 311 | // Show icon in QS when we are connected or data is disabled. |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 312 | boolean showDataIcon = mCurrentState.dataConnected || dataDisabled; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 313 | IconState statusIcon = new IconState(mCurrentState.enabled && !mCurrentState.airplaneMode, |
| 314 | getCurrentIconId(), contentDescription); |
| 315 | |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 316 | int qsTypeIcon = 0; |
| 317 | IconState qsIcon = null; |
| 318 | String description = null; |
| 319 | // Only send data sim callbacks to QS. |
| 320 | if (mCurrentState.dataSim) { |
Evan Laird | 9dcd322 | 2017-12-04 14:31:48 -0500 | [diff] [blame] | 321 | qsTypeIcon = (showDataIcon || mConfig.alwaysShowDataRatIcon) ? icons.mQsDataType : 0; |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 322 | qsIcon = new IconState(mCurrentState.enabled |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 323 | && !mCurrentState.isEmergency, getQsCurrentIconId(), contentDescription); |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 324 | description = mCurrentState.isEmergency ? null : mCurrentState.networkName; |
| 325 | } |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 326 | boolean activityIn = mCurrentState.dataConnected |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 327 | && !mCurrentState.carrierNetworkChangeMode |
| 328 | && mCurrentState.activityIn; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 329 | boolean activityOut = mCurrentState.dataConnected |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 330 | && !mCurrentState.carrierNetworkChangeMode |
| 331 | && mCurrentState.activityOut; |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 332 | showDataIcon &= mCurrentState.isDefault || dataDisabled; |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 333 | int typeIcon = (showDataIcon || mConfig.alwaysShowDataRatIcon) ? icons.mDataType : 0; |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 334 | callback.setMobileDataIndicators(statusIcon, qsIcon, typeIcon, qsTypeIcon, |
| 335 | activityIn, activityOut, dataContentDescription, description, icons.mIsWide, |
| 336 | mSubscriptionInfo.getSubscriptionId(), mCurrentState.roaming); |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 337 | } |
| 338 | |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 339 | @Override |
| 340 | protected MobileState cleanState() { |
| 341 | return new MobileState(); |
| 342 | } |
| 343 | |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 344 | private boolean isCdma() { |
| 345 | return (mSignalStrength != null) && !mSignalStrength.isGsm(); |
| 346 | } |
| 347 | |
| 348 | public boolean isEmergencyOnly() { |
| 349 | return (mServiceState != null && mServiceState.isEmergencyOnly()); |
| 350 | } |
| 351 | |
| 352 | private boolean isRoaming() { |
Shishir Agrawal | 7ef5b88 | 2017-06-26 12:06:03 -0700 | [diff] [blame] | 353 | // During a carrier change, roaming indications need to be supressed. |
| 354 | if (isCarrierNetworkChangeActive()) { |
| 355 | return false; |
| 356 | } |
Jason Monk | e153198 | 2017-09-05 11:20:30 -0400 | [diff] [blame] | 357 | if (isCdma() && mServiceState != null) { |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 358 | final int iconMode = mServiceState.getCdmaEriIconMode(); |
| 359 | return mServiceState.getCdmaEriIconIndex() != EriInfo.ROAMING_INDICATOR_OFF |
| 360 | && (iconMode == EriInfo.ROAMING_ICON_MODE_NORMAL |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 361 | || iconMode == EriInfo.ROAMING_ICON_MODE_FLASH); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 362 | } else { |
| 363 | return mServiceState != null && mServiceState.getRoaming(); |
| 364 | } |
| 365 | } |
| 366 | |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 367 | private boolean isCarrierNetworkChangeActive() { |
Andrew Flynn | 55fc800 | 2015-05-29 08:33:46 -0400 | [diff] [blame] | 368 | return mCurrentState.carrierNetworkChangeMode; |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 369 | } |
| 370 | |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 371 | public void handleBroadcast(Intent intent) { |
| 372 | String action = intent.getAction(); |
| 373 | if (action.equals(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION)) { |
| 374 | updateNetworkName(intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, false), |
| 375 | intent.getStringExtra(TelephonyIntents.EXTRA_SPN), |
Pavel Zhamaitsiak | 5504d39 | 2015-03-27 09:24:47 -0700 | [diff] [blame] | 376 | intent.getStringExtra(TelephonyIntents.EXTRA_DATA_SPN), |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 377 | intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_PLMN, false), |
| 378 | intent.getStringExtra(TelephonyIntents.EXTRA_PLMN)); |
| 379 | notifyListenersIfNecessary(); |
| 380 | } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) { |
| 381 | updateDataSim(); |
Jason Monk | 8fcab35 | 2015-06-29 10:57:00 -0400 | [diff] [blame] | 382 | notifyListenersIfNecessary(); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
| 386 | private void updateDataSim() { |
Fabian Kozynski | ccde55d | 2019-06-26 10:06:09 -0400 | [diff] [blame] | 387 | int activeDataSubId = mDefaults.getActiveDataSubId(); |
| 388 | if (SubscriptionManager.isValidSubscriptionId(activeDataSubId)) { |
| 389 | mCurrentState.dataSim = activeDataSubId == mSubscriptionInfo.getSubscriptionId(); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 390 | } else { |
| 391 | // There doesn't seem to be a data sim selected, however if |
| 392 | // there isn't a MobileSignalController with dataSim set, then |
| 393 | // QS won't get any callbacks and will be blank. Instead |
| 394 | // lets just assume we are the data sim (which will basically |
| 395 | // show one at random) in QS until one is selected. The user |
| 396 | // should pick one soon after, so we shouldn't be in this state |
| 397 | // for long. |
| 398 | mCurrentState.dataSim = true; |
| 399 | } |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 400 | } |
| 401 | |
SongFerngWang | 3cbcf75 | 2019-03-21 23:14:20 +0800 | [diff] [blame] | 402 | private boolean isCarrierSpecificDataIcon() { |
| 403 | if (mConfig.patternOfCarrierSpecificDataIcon == null |
| 404 | || mConfig.patternOfCarrierSpecificDataIcon.length() == 0) { |
| 405 | return false; |
| 406 | } |
| 407 | |
| 408 | Pattern stringPattern = Pattern.compile(mConfig.patternOfCarrierSpecificDataIcon); |
| 409 | String[] operatorNames = new String[]{mServiceState.getOperatorAlphaLongRaw(), |
| 410 | mServiceState.getOperatorAlphaShortRaw()}; |
| 411 | for (String opName : operatorNames) { |
| 412 | if (!TextUtils.isEmpty(opName)) { |
| 413 | Matcher matcher = stringPattern.matcher(opName); |
| 414 | if (matcher.find()) { |
| 415 | return true; |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | return false; |
| 420 | } |
| 421 | |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 422 | /** |
| 423 | * Updates the network's name based on incoming spn and plmn. |
| 424 | */ |
Pavel Zhamaitsiak | 5504d39 | 2015-03-27 09:24:47 -0700 | [diff] [blame] | 425 | void updateNetworkName(boolean showSpn, String spn, String dataSpn, |
| 426 | boolean showPlmn, String plmn) { |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 427 | if (CHATTY) { |
Pavel Zhamaitsiak | 5504d39 | 2015-03-27 09:24:47 -0700 | [diff] [blame] | 428 | Log.d("CarrierLabel", "updateNetworkName showSpn=" + showSpn |
| 429 | + " spn=" + spn + " dataSpn=" + dataSpn |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 430 | + " showPlmn=" + showPlmn + " plmn=" + plmn); |
| 431 | } |
| 432 | StringBuilder str = new StringBuilder(); |
Pavel Zhamaitsiak | 5504d39 | 2015-03-27 09:24:47 -0700 | [diff] [blame] | 433 | StringBuilder strData = new StringBuilder(); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 434 | if (showPlmn && plmn != null) { |
| 435 | str.append(plmn); |
Pavel Zhamaitsiak | 5504d39 | 2015-03-27 09:24:47 -0700 | [diff] [blame] | 436 | strData.append(plmn); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 437 | } |
| 438 | if (showSpn && spn != null) { |
| 439 | if (str.length() != 0) { |
| 440 | str.append(mNetworkNameSeparator); |
| 441 | } |
| 442 | str.append(spn); |
| 443 | } |
| 444 | if (str.length() != 0) { |
| 445 | mCurrentState.networkName = str.toString(); |
| 446 | } else { |
| 447 | mCurrentState.networkName = mNetworkNameDefault; |
| 448 | } |
Pavel Zhamaitsiak | 5504d39 | 2015-03-27 09:24:47 -0700 | [diff] [blame] | 449 | if (showSpn && dataSpn != null) { |
| 450 | if (strData.length() != 0) { |
| 451 | strData.append(mNetworkNameSeparator); |
| 452 | } |
| 453 | strData.append(dataSpn); |
| 454 | } |
| 455 | if (strData.length() != 0) { |
| 456 | mCurrentState.networkNameData = strData.toString(); |
| 457 | } else { |
| 458 | mCurrentState.networkNameData = mNetworkNameDefault; |
| 459 | } |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /** |
Jayachandran C | a6f9b6d | 2019-11-07 17:26:02 -0800 | [diff] [blame] | 463 | * Extracts the CellSignalStrengthCdma from SignalStrength then returns the level |
| 464 | */ |
| 465 | private final int getCdmaLevel() { |
| 466 | List<CellSignalStrengthCdma> signalStrengthCdma = |
| 467 | mSignalStrength.getCellSignalStrengths(CellSignalStrengthCdma.class); |
| 468 | if (!signalStrengthCdma.isEmpty()) { |
| 469 | return signalStrengthCdma.get(0).getLevel(); |
| 470 | } |
| 471 | return CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
| 472 | } |
| 473 | |
| 474 | /** |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 475 | * Updates the current state based on mServiceState, mSignalStrength, mDataNetType, |
| 476 | * mDataState, and mSimState. It should be called any time one of these is updated. |
| 477 | * This will call listeners if necessary. |
| 478 | */ |
| 479 | private final void updateTelephony() { |
| 480 | if (DEBUG) { |
SongFerngWang | 8cfb4d5 | 2018-08-21 18:04:29 +0800 | [diff] [blame] | 481 | Log.d(mTag, "updateTelephonySignalStrength: hasService=" + |
| 482 | Utils.isInService(mServiceState) + " ss=" + mSignalStrength); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 483 | } |
SongFerngWang | 8cfb4d5 | 2018-08-21 18:04:29 +0800 | [diff] [blame] | 484 | mCurrentState.connected = Utils.isInService(mServiceState) |
| 485 | && mSignalStrength != null; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 486 | if (mCurrentState.connected) { |
| 487 | if (!mSignalStrength.isGsm() && mConfig.alwaysShowCdmaRssi) { |
Jayachandran C | a6f9b6d | 2019-11-07 17:26:02 -0800 | [diff] [blame] | 488 | mCurrentState.level = getCdmaLevel(); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 489 | } else { |
| 490 | mCurrentState.level = mSignalStrength.getLevel(); |
| 491 | } |
| 492 | } |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 493 | |
| 494 | // When the device is camped on a 5G Non-Standalone network, the data network type is still |
| 495 | // LTE. In this case, we first check which 5G icon should be shown. |
| 496 | MobileIconGroup nr5GIconGroup = getNr5GIconGroup(); |
| 497 | if (nr5GIconGroup != null) { |
| 498 | mCurrentState.iconGroup = nr5GIconGroup; |
| 499 | } else if (mNetworkToIconLookup.indexOfKey(mDataNetType) >= 0) { |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 500 | mCurrentState.iconGroup = mNetworkToIconLookup.get(mDataNetType); |
| 501 | } else { |
| 502 | mCurrentState.iconGroup = mDefaultIcons; |
| 503 | } |
| 504 | mCurrentState.dataConnected = mCurrentState.connected |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 505 | && mDataState == TelephonyManager.DATA_CONNECTED; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 506 | |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 507 | mCurrentState.roaming = isRoaming(); |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 508 | if (isCarrierNetworkChangeActive()) { |
| 509 | mCurrentState.iconGroup = TelephonyIcons.CARRIER_NETWORK_CHANGE; |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 510 | } else if (isDataDisabled() && !mConfig.alwaysShowDataRatIcon) { |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 511 | if (mSubscriptionInfo.getSubscriptionId() |
| 512 | != mDefaults.getDefaultDataSubId()) { |
| 513 | mCurrentState.iconGroup = TelephonyIcons.NOT_DEFAULT_DATA; |
| 514 | } else { |
| 515 | mCurrentState.iconGroup = TelephonyIcons.DATA_DISABLED; |
| 516 | } |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 517 | } |
| 518 | if (isEmergencyOnly() != mCurrentState.isEmergency) { |
| 519 | mCurrentState.isEmergency = isEmergencyOnly(); |
| 520 | mNetworkController.recalculateEmergency(); |
| 521 | } |
| 522 | // Fill in the network name if we think we have it. |
Fabian Kozynski | a909199 | 2019-03-25 11:08:32 -0400 | [diff] [blame] | 523 | if (mCurrentState.networkName.equals(mNetworkNameDefault) && mServiceState != null |
Jason Monk | 93fb68f | 2015-07-20 11:43:56 -0400 | [diff] [blame] | 524 | && !TextUtils.isEmpty(mServiceState.getOperatorAlphaShort())) { |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 525 | mCurrentState.networkName = mServiceState.getOperatorAlphaShort(); |
| 526 | } |
Fabian Kozynski | a909199 | 2019-03-25 11:08:32 -0400 | [diff] [blame] | 527 | // If this is the data subscription, update the currentState data name |
| 528 | if (mCurrentState.networkNameData.equals(mNetworkNameDefault) && mServiceState != null |
| 529 | && mCurrentState.dataSim |
| 530 | && !TextUtils.isEmpty(mServiceState.getDataOperatorAlphaShort())) { |
| 531 | mCurrentState.networkNameData = mServiceState.getDataOperatorAlphaShort(); |
| 532 | } |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 533 | |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 534 | notifyListenersIfNecessary(); |
| 535 | } |
| 536 | |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 537 | private MobileIconGroup getNr5GIconGroup() { |
| 538 | if (mServiceState == null) return null; |
| 539 | |
Jack Yu | 20d7140 | 2019-03-16 23:00:35 -0700 | [diff] [blame] | 540 | int nrState = mServiceState.getNrState(); |
| 541 | if (nrState == NetworkRegistrationInfo.NR_STATE_CONNECTED) { |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 542 | // Check if the NR 5G is using millimeter wave and the icon is config. |
| 543 | if (mServiceState.getNrFrequencyRange() == ServiceState.FREQUENCY_RANGE_MMWAVE) { |
| 544 | if (mConfig.nr5GIconMap.containsKey(Config.NR_CONNECTED_MMWAVE)) { |
| 545 | return mConfig.nr5GIconMap.get(Config.NR_CONNECTED_MMWAVE); |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | // If NR 5G is not using millimeter wave or there is no icon for millimeter wave, we |
| 550 | // check the normal 5G icon. |
| 551 | if (mConfig.nr5GIconMap.containsKey(Config.NR_CONNECTED)) { |
| 552 | return mConfig.nr5GIconMap.get(Config.NR_CONNECTED); |
| 553 | } |
Jack Yu | 20d7140 | 2019-03-16 23:00:35 -0700 | [diff] [blame] | 554 | } else if (nrState == NetworkRegistrationInfo.NR_STATE_NOT_RESTRICTED) { |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 555 | if (mConfig.nr5GIconMap.containsKey(Config.NR_NOT_RESTRICTED)) { |
| 556 | return mConfig.nr5GIconMap.get(Config.NR_NOT_RESTRICTED); |
| 557 | } |
Jack Yu | 20d7140 | 2019-03-16 23:00:35 -0700 | [diff] [blame] | 558 | } else if (nrState == NetworkRegistrationInfo.NR_STATE_RESTRICTED) { |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 559 | if (mConfig.nr5GIconMap.containsKey(Config.NR_RESTRICTED)) { |
| 560 | return mConfig.nr5GIconMap.get(Config.NR_RESTRICTED); |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | return null; |
| 565 | } |
| 566 | |
Jason Monk | 1a95c86 | 2016-01-27 15:18:41 -0500 | [diff] [blame] | 567 | private boolean isDataDisabled() { |
Malcolm Chen | 04be9d1 | 2019-06-11 19:48:38 -0700 | [diff] [blame] | 568 | return !mPhone.isDataCapable(); |
Jason Monk | 1a95c86 | 2016-01-27 15:18:41 -0500 | [diff] [blame] | 569 | } |
| 570 | |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 571 | @VisibleForTesting |
| 572 | void setActivity(int activity) { |
| 573 | mCurrentState.activityIn = activity == TelephonyManager.DATA_ACTIVITY_INOUT |
| 574 | || activity == TelephonyManager.DATA_ACTIVITY_IN; |
| 575 | mCurrentState.activityOut = activity == TelephonyManager.DATA_ACTIVITY_INOUT |
| 576 | || activity == TelephonyManager.DATA_ACTIVITY_OUT; |
| 577 | notifyListenersIfNecessary(); |
| 578 | } |
| 579 | |
| 580 | @Override |
| 581 | public void dump(PrintWriter pw) { |
| 582 | super.dump(pw); |
| 583 | pw.println(" mSubscription=" + mSubscriptionInfo + ","); |
| 584 | pw.println(" mServiceState=" + mServiceState + ","); |
| 585 | pw.println(" mSignalStrength=" + mSignalStrength + ","); |
| 586 | pw.println(" mDataState=" + mDataState + ","); |
| 587 | pw.println(" mDataNetType=" + mDataNetType + ","); |
andychou | 9e39628 | 2019-04-10 20:49:06 +0800 | [diff] [blame] | 588 | pw.println(" mInflateSignalStrengths=" + mInflateSignalStrengths + ","); |
Malcolm Chen | 04be9d1 | 2019-06-11 19:48:38 -0700 | [diff] [blame] | 589 | pw.println(" isDataDisabled=" + isDataDisabled() + ","); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | class MobilePhoneStateListener extends PhoneStateListener { |
chen xu | 84a9087 | 2019-03-28 15:44:12 -0700 | [diff] [blame] | 593 | public MobilePhoneStateListener(Looper looper) { |
| 594 | super(looper); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | @Override |
| 598 | public void onSignalStrengthsChanged(SignalStrength signalStrength) { |
| 599 | if (DEBUG) { |
| 600 | Log.d(mTag, "onSignalStrengthsChanged signalStrength=" + signalStrength + |
| 601 | ((signalStrength == null) ? "" : (" level=" + signalStrength.getLevel()))); |
| 602 | } |
| 603 | mSignalStrength = signalStrength; |
| 604 | updateTelephony(); |
| 605 | } |
| 606 | |
| 607 | @Override |
| 608 | public void onServiceStateChanged(ServiceState state) { |
| 609 | if (DEBUG) { |
| 610 | Log.d(mTag, "onServiceStateChanged voiceState=" + state.getVoiceRegState() |
| 611 | + " dataState=" + state.getDataRegState()); |
| 612 | } |
| 613 | mServiceState = state; |
SongFerngWang | 3cbcf75 | 2019-03-21 23:14:20 +0800 | [diff] [blame] | 614 | if (mServiceState != null) { |
| 615 | updateDataNetType(mServiceState.getDataNetworkType()); |
Robert Greenwalt | ea0d7139 | 2016-07-28 18:50:10 -0700 | [diff] [blame] | 616 | } |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 617 | updateTelephony(); |
| 618 | } |
| 619 | |
| 620 | @Override |
| 621 | public void onDataConnectionStateChanged(int state, int networkType) { |
| 622 | if (DEBUG) { |
| 623 | Log.d(mTag, "onDataConnectionStateChanged: state=" + state |
| 624 | + " type=" + networkType); |
| 625 | } |
| 626 | mDataState = state; |
SongFerngWang | 3cbcf75 | 2019-03-21 23:14:20 +0800 | [diff] [blame] | 627 | updateDataNetType(networkType); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 628 | updateTelephony(); |
| 629 | } |
| 630 | |
SongFerngWang | 3cbcf75 | 2019-03-21 23:14:20 +0800 | [diff] [blame] | 631 | private void updateDataNetType(int networkType) { |
| 632 | mDataNetType = networkType; |
| 633 | if (mDataNetType == TelephonyManager.NETWORK_TYPE_LTE) { |
| 634 | if (isCarrierSpecificDataIcon()) { |
| 635 | mDataNetType = NETWORK_TYPE_LTE_CA_5GE; |
| 636 | } else if (mServiceState != null && mServiceState.isUsingCarrierAggregation()) { |
| 637 | mDataNetType = TelephonyManager.NETWORK_TYPE_LTE_CA; |
| 638 | } |
| 639 | } |
| 640 | } |
| 641 | |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 642 | @Override |
| 643 | public void onDataActivity(int direction) { |
| 644 | if (DEBUG) { |
| 645 | Log.d(mTag, "onDataActivity: direction=" + direction); |
| 646 | } |
| 647 | setActivity(direction); |
| 648 | } |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 649 | |
| 650 | @Override |
| 651 | public void onCarrierNetworkChange(boolean active) { |
| 652 | if (DEBUG) { |
| 653 | Log.d(mTag, "onCarrierNetworkChange: active=" + active); |
| 654 | } |
| 655 | mCurrentState.carrierNetworkChangeMode = active; |
| 656 | |
| 657 | updateTelephony(); |
| 658 | } |
Fabian Kozynski | aaf7897 | 2019-07-08 10:02:08 -0400 | [diff] [blame] | 659 | |
| 660 | @Override |
| 661 | public void onActiveDataSubscriptionIdChanged(int subId) { |
| 662 | if (DEBUG) Log.d(mTag, "onActiveDataSubscriptionIdChanged: subId=" + subId); |
| 663 | updateDataSim(); |
| 664 | updateTelephony(); |
| 665 | } |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 666 | }; |
| 667 | |
| 668 | static class MobileIconGroup extends SignalController.IconGroup { |
| 669 | final int mDataContentDescription; // mContentDescriptionDataType |
| 670 | final int mDataType; |
| 671 | final boolean mIsWide; |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 672 | final int mQsDataType; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 673 | |
| 674 | public MobileIconGroup(String name, int[][] sbIcons, int[][] qsIcons, int[] contentDesc, |
| 675 | int sbNullState, int qsNullState, int sbDiscState, int qsDiscState, |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 676 | int discContentDesc, int dataContentDesc, int dataType, boolean isWide) { |
Andrew Flynn | 2fdbe12 | 2015-06-01 16:34:21 -0400 | [diff] [blame] | 677 | super(name, sbIcons, qsIcons, contentDesc, sbNullState, qsNullState, sbDiscState, |
| 678 | qsDiscState, discContentDesc); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 679 | mDataContentDescription = dataContentDesc; |
| 680 | mDataType = dataType; |
| 681 | mIsWide = isWide; |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 682 | mQsDataType = dataType; // TODO: remove this field |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | |
| 686 | static class MobileState extends SignalController.State { |
| 687 | String networkName; |
Pavel Zhamaitsiak | 5504d39 | 2015-03-27 09:24:47 -0700 | [diff] [blame] | 688 | String networkNameData; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 689 | boolean dataSim; |
| 690 | boolean dataConnected; |
| 691 | boolean isEmergency; |
| 692 | boolean airplaneMode; |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 693 | boolean carrierNetworkChangeMode; |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 694 | boolean isDefault; |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 695 | boolean userSetup; |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 696 | boolean roaming; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 697 | |
| 698 | @Override |
| 699 | public void copyFrom(State s) { |
| 700 | super.copyFrom(s); |
| 701 | MobileState state = (MobileState) s; |
| 702 | dataSim = state.dataSim; |
| 703 | networkName = state.networkName; |
Pavel Zhamaitsiak | 5504d39 | 2015-03-27 09:24:47 -0700 | [diff] [blame] | 704 | networkNameData = state.networkNameData; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 705 | dataConnected = state.dataConnected; |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 706 | isDefault = state.isDefault; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 707 | isEmergency = state.isEmergency; |
| 708 | airplaneMode = state.airplaneMode; |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 709 | carrierNetworkChangeMode = state.carrierNetworkChangeMode; |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 710 | userSetup = state.userSetup; |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 711 | roaming = state.roaming; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | @Override |
| 715 | protected void toString(StringBuilder builder) { |
| 716 | super.toString(builder); |
| 717 | builder.append(','); |
| 718 | builder.append("dataSim=").append(dataSim).append(','); |
| 719 | builder.append("networkName=").append(networkName).append(','); |
Pavel Zhamaitsiak | 5504d39 | 2015-03-27 09:24:47 -0700 | [diff] [blame] | 720 | builder.append("networkNameData=").append(networkNameData).append(','); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 721 | builder.append("dataConnected=").append(dataConnected).append(','); |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 722 | builder.append("roaming=").append(roaming).append(','); |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 723 | builder.append("isDefault=").append(isDefault).append(','); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 724 | builder.append("isEmergency=").append(isEmergency).append(','); |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 725 | builder.append("airplaneMode=").append(airplaneMode).append(','); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 726 | builder.append("carrierNetworkChangeMode=").append(carrierNetworkChangeMode) |
| 727 | .append(','); |
| 728 | builder.append("userSetup=").append(userSetup); |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | @Override |
| 732 | public boolean equals(Object o) { |
| 733 | return super.equals(o) |
| 734 | && Objects.equals(((MobileState) o).networkName, networkName) |
Pavel Zhamaitsiak | 5504d39 | 2015-03-27 09:24:47 -0700 | [diff] [blame] | 735 | && Objects.equals(((MobileState) o).networkNameData, networkNameData) |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 736 | && ((MobileState) o).dataSim == dataSim |
| 737 | && ((MobileState) o).dataConnected == dataConnected |
| 738 | && ((MobileState) o).isEmergency == isEmergency |
| 739 | && ((MobileState) o).airplaneMode == airplaneMode |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 740 | && ((MobileState) o).carrierNetworkChangeMode == carrierNetworkChangeMode |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 741 | && ((MobileState) o).userSetup == userSetup |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 742 | && ((MobileState) o).isDefault == isDefault |
| 743 | && ((MobileState) o).roaming == roaming; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | } |