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