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