John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
| 17 | package com.android.systemui.statusbar.policy; |
| 18 | |
Roshan Pius | 80fb137 | 2018-07-16 15:43:03 -0700 | [diff] [blame] | 19 | import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED; |
| 20 | import static android.net.wifi.WifiManager.TrafficStateCallback.DATA_ACTIVITY_IN; |
| 21 | import static android.net.wifi.WifiManager.TrafficStateCallback.DATA_ACTIVITY_INOUT; |
| 22 | import static android.net.wifi.WifiManager.TrafficStateCallback.DATA_ACTIVITY_NONE; |
| 23 | import static android.net.wifi.WifiManager.TrafficStateCallback.DATA_ACTIVITY_OUT; |
Malcolm Chen | 50ba963 | 2019-02-26 16:49:56 -0800 | [diff] [blame] | 24 | import static android.telephony.PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE; |
Roshan Pius | 80fb137 | 2018-07-16 15:43:03 -0700 | [diff] [blame] | 25 | |
Malcolm Chen | 50ba963 | 2019-02-26 16:49:56 -0800 | [diff] [blame] | 26 | import static com.android.internal.telephony.PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM; |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 27 | import static com.android.systemui.Dependency.BG_LOOPER_NAME; |
| 28 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 29 | import android.content.BroadcastReceiver; |
| 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
| 32 | import android.content.IntentFilter; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 33 | import android.content.res.Configuration; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 34 | import android.content.res.Resources; |
| 35 | import android.net.ConnectivityManager; |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 36 | import android.net.Network; |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 37 | import android.net.NetworkCapabilities; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 38 | import android.net.wifi.WifiManager; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 39 | import android.os.AsyncTask; |
| 40 | import android.os.Bundle; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 41 | import android.os.Handler; |
Jason Monk | 30d8004 | 2015-05-08 16:54:18 -0400 | [diff] [blame] | 42 | import android.os.Looper; |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 43 | import android.os.PersistableBundle; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 44 | import android.provider.Settings; |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 45 | import android.telephony.CarrierConfigManager; |
Malcolm Chen | 50ba963 | 2019-02-26 16:49:56 -0800 | [diff] [blame] | 46 | import android.telephony.PhoneStateListener; |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 47 | import android.telephony.ServiceState; |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 48 | import android.telephony.SignalStrength; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 49 | import android.telephony.SubscriptionInfo; |
| 50 | import android.telephony.SubscriptionManager; |
| 51 | import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 52 | import android.telephony.TelephonyManager; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 53 | import android.text.TextUtils; |
Bill Lin | 767c0db | 2019-08-15 20:42:06 +0800 | [diff] [blame] | 54 | import android.text.format.DateUtils; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 55 | import android.util.Log; |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 56 | import android.util.MathUtils; |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 57 | import android.util.SparseArray; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 58 | |
Evan Laird | 470ae84 | 2019-04-09 16:24:27 -0400 | [diff] [blame] | 59 | import com.android.internal.annotations.GuardedBy; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 60 | import com.android.internal.annotations.VisibleForTesting; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 61 | import com.android.internal.telephony.PhoneConstants; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 62 | import com.android.internal.telephony.TelephonyIntents; |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 63 | import com.android.settingslib.net.DataUsageController; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 64 | import com.android.systemui.ConfigurationChangedReceiver; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 65 | import com.android.systemui.DemoMode; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 66 | import com.android.systemui.Dumpable; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 67 | import com.android.systemui.R; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 68 | import com.android.systemui.settings.CurrentUserTracker; |
| 69 | import com.android.systemui.statusbar.policy.DeviceProvisionedController.DeviceProvisionedListener; |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 70 | import com.android.systemui.statusbar.policy.MobileSignalController.MobileIconGroup; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 71 | |
| 72 | import java.io.FileDescriptor; |
| 73 | import java.io.PrintWriter; |
| 74 | import java.util.ArrayList; |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 75 | import java.util.BitSet; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 76 | import java.util.Collections; |
| 77 | import java.util.Comparator; |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 78 | import java.util.HashMap; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 79 | import java.util.List; |
| 80 | import java.util.Locale; |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 81 | import java.util.Map; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 82 | |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 83 | import javax.inject.Inject; |
| 84 | import javax.inject.Named; |
| 85 | import javax.inject.Singleton; |
| 86 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 87 | /** Platform implementation of the network controller. **/ |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 88 | @Singleton |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 89 | public class NetworkControllerImpl extends BroadcastReceiver |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 90 | implements NetworkController, DemoMode, DataUsageController.NetworkNameProvider, |
| 91 | ConfigurationChangedReceiver, Dumpable { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 92 | // debug |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 93 | static final String TAG = "NetworkController"; |
| 94 | static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
| 95 | // additional diagnostics, but not logspew |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 96 | static final boolean CHATTY = Log.isLoggable(TAG + "Chat", Log.DEBUG); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 97 | |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 98 | private static final int EMERGENCY_NO_CONTROLLERS = 0; |
| 99 | private static final int EMERGENCY_FIRST_CONTROLLER = 100; |
| 100 | private static final int EMERGENCY_VOICE_CONTROLLER = 200; |
| 101 | private static final int EMERGENCY_NO_SUB = 300; |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 102 | private static final int EMERGENCY_ASSUMED_VOICE_CONTROLLER = 400; |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 103 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 104 | private final Context mContext; |
| 105 | private final TelephonyManager mPhone; |
| 106 | private final WifiManager mWifiManager; |
| 107 | private final ConnectivityManager mConnectivityManager; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 108 | private final SubscriptionManager mSubscriptionManager; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 109 | private final boolean mHasMobileDataFeature; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 110 | private final SubscriptionDefaults mSubDefaults; |
Jason Monk | 9a4ce13 | 2016-01-21 15:27:17 -0500 | [diff] [blame] | 111 | private final DataSaverController mDataSaverController; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 112 | private final CurrentUserTracker mUserTracker; |
Evan Laird | 470ae84 | 2019-04-09 16:24:27 -0400 | [diff] [blame] | 113 | private final Object mLock = new Object(); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 114 | private Config mConfig; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 115 | |
Evan Laird | 470ae84 | 2019-04-09 16:24:27 -0400 | [diff] [blame] | 116 | private PhoneStateListener mPhoneStateListener; |
Malcolm Chen | 50ba963 | 2019-02-26 16:49:56 -0800 | [diff] [blame] | 117 | private int mActiveMobileDataSubscription = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
| 118 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 119 | // Subcontrollers. |
| 120 | @VisibleForTesting |
| 121 | final WifiSignalController mWifiSignalController; |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 122 | |
| 123 | @VisibleForTesting |
| 124 | final EthernetSignalController mEthernetSignalController; |
| 125 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 126 | @VisibleForTesting |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 127 | final SparseArray<MobileSignalController> mMobileSignalControllers = new SparseArray<>(); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 128 | // When no SIMs are around at setup, and one is added later, it seems to default to the first |
| 129 | // SIM for most actions. This may be null if there aren't any SIMs around. |
| 130 | private MobileSignalController mDefaultSignalController; |
Jason Monk | 0e2400f | 2014-11-21 11:08:55 -0500 | [diff] [blame] | 131 | private final AccessPointControllerImpl mAccessPoints; |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 132 | private final DataUsageController mDataUsageController; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 133 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 134 | private boolean mInetCondition; // Used for Logging and demo. |
Lorenzo Colitti | 23dd176 | 2014-09-10 22:58:54 +0900 | [diff] [blame] | 135 | |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 136 | // BitSets indicating which network transport types (e.g., TRANSPORT_WIFI, TRANSPORT_MOBILE) are |
| 137 | // connected and validated, respectively. |
| 138 | private final BitSet mConnectedTransports = new BitSet(); |
| 139 | private final BitSet mValidatedTransports = new BitSet(); |
| 140 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 141 | // States that don't belong to a subcontroller. |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 142 | private boolean mAirplaneMode = false; |
Jason Monk | 1ff7766 | 2017-09-29 11:17:05 -0400 | [diff] [blame] | 143 | private boolean mHasNoSubs; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 144 | private Locale mLocale = null; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 145 | // This list holds our ordering. |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 146 | private List<SubscriptionInfo> mCurrentSubscriptions = new ArrayList<>(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 147 | |
Jason Monk | c014dec | 2014-12-12 11:49:55 -0500 | [diff] [blame] | 148 | @VisibleForTesting |
| 149 | boolean mListening; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 150 | |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 151 | // The current user ID. |
| 152 | private int mCurrentUserId; |
| 153 | |
Jason Monk | 8fcab35 | 2015-06-29 10:57:00 -0400 | [diff] [blame] | 154 | private OnSubscriptionsChangedListener mSubscriptionListener; |
| 155 | |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 156 | // Handler that all broadcasts are received on. |
| 157 | private final Handler mReceiverHandler; |
| 158 | // Handler that all callbacks are made on. |
| 159 | private final CallbackHandler mCallbackHandler; |
| 160 | |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 161 | private int mEmergencySource; |
| 162 | private boolean mIsEmergency; |
| 163 | |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 164 | @VisibleForTesting |
| 165 | ServiceState mLastServiceState; |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 166 | private boolean mUserSetup; |
Jason Monk | 1ff7766 | 2017-09-29 11:17:05 -0400 | [diff] [blame] | 167 | private boolean mSimDetected; |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 168 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 169 | /** |
| 170 | * Construct this controller object and register for updates. |
| 171 | */ |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 172 | @Inject |
| 173 | public NetworkControllerImpl(Context context, @Named(BG_LOOPER_NAME) Looper bgLooper, |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 174 | DeviceProvisionedController deviceProvisionedController) { |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 175 | this(context, (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE), |
| 176 | (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE), |
Jason Monk | 29f7a7b | 2014-11-17 14:40:56 -0500 | [diff] [blame] | 177 | (WifiManager) context.getSystemService(Context.WIFI_SERVICE), |
Sundeep Ghuman | 9d10a3c | 2017-06-16 00:05:16 +0000 | [diff] [blame] | 178 | SubscriptionManager.from(context), Config.readConfig(context), bgLooper, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 179 | new CallbackHandler(), |
Tony Mantler | 0edf09b | 2017-09-28 15:03:37 -0700 | [diff] [blame] | 180 | new AccessPointControllerImpl(context), |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 181 | new DataUsageController(context), |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 182 | new SubscriptionDefaults(), |
| 183 | deviceProvisionedController); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 184 | mReceiverHandler.post(mRegisterListeners); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | @VisibleForTesting |
| 188 | NetworkControllerImpl(Context context, ConnectivityManager connectivityManager, |
Sundeep Ghuman | 9d10a3c | 2017-06-16 00:05:16 +0000 | [diff] [blame] | 189 | TelephonyManager telephonyManager, WifiManager wifiManager, |
| 190 | SubscriptionManager subManager, Config config, Looper bgLooper, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 191 | CallbackHandler callbackHandler, |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 192 | AccessPointControllerImpl accessPointController, |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 193 | DataUsageController dataUsageController, |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 194 | SubscriptionDefaults defaultsHandler, |
| 195 | DeviceProvisionedController deviceProvisionedController) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 196 | mContext = context; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 197 | mConfig = config; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 198 | mReceiverHandler = new Handler(bgLooper); |
| 199 | mCallbackHandler = callbackHandler; |
Jason Monk | 9abca5e | 2016-11-11 16:18:14 -0500 | [diff] [blame] | 200 | mDataSaverController = new DataSaverControllerImpl(context); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 201 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 202 | mSubscriptionManager = subManager; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 203 | mSubDefaults = defaultsHandler; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 204 | mConnectivityManager = connectivityManager; |
| 205 | mHasMobileDataFeature = |
| 206 | mConnectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 207 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 208 | // telephony |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 209 | mPhone = telephonyManager; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 210 | |
| 211 | // wifi |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 212 | mWifiManager = wifiManager; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 213 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 214 | mLocale = mContext.getResources().getConfiguration().locale; |
Jason Monk | 29f7a7b | 2014-11-17 14:40:56 -0500 | [diff] [blame] | 215 | mAccessPoints = accessPointController; |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 216 | mDataUsageController = dataUsageController; |
| 217 | mDataUsageController.setNetworkController(this); |
| 218 | // TODO: Find a way to move this into DataUsageController. |
| 219 | mDataUsageController.setCallback(new DataUsageController.Callback() { |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 220 | @Override |
| 221 | public void onMobileDataEnabled(boolean enabled) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 222 | mCallbackHandler.setMobileDataEnabled(enabled); |
Evan Laird | 2ea99c1 | 2019-09-19 16:52:58 -0400 | [diff] [blame] | 223 | notifyControllersMobileDataChanged(); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 224 | } |
| 225 | }); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 226 | mWifiSignalController = new WifiSignalController(mContext, mHasMobileDataFeature, |
Amin Shaikh | c7593b1 | 2018-03-09 16:07:09 -0500 | [diff] [blame] | 227 | mCallbackHandler, this, mWifiManager); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 228 | |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 229 | mEthernetSignalController = new EthernetSignalController(mContext, mCallbackHandler, this); |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 230 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 231 | // AIRPLANE_MODE_CHANGED is sent at boot; we've probably already missed it |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 232 | updateAirplaneMode(true /* force callback */); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 233 | mUserTracker = new CurrentUserTracker(mContext) { |
| 234 | @Override |
| 235 | public void onUserSwitched(int newUserId) { |
| 236 | NetworkControllerImpl.this.onUserSwitched(newUserId); |
| 237 | } |
| 238 | }; |
| 239 | mUserTracker.startTracking(); |
| 240 | deviceProvisionedController.addCallback(new DeviceProvisionedListener() { |
| 241 | @Override |
| 242 | public void onUserSetupChanged() { |
| 243 | setUserSetupComplete(deviceProvisionedController.isUserSetup( |
| 244 | deviceProvisionedController.getCurrentUser())); |
| 245 | } |
| 246 | }); |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 247 | |
| 248 | ConnectivityManager.NetworkCallback callback = new ConnectivityManager.NetworkCallback(){ |
| 249 | private Network mLastNetwork; |
| 250 | private NetworkCapabilities mLastNetworkCapabilities; |
| 251 | |
| 252 | @Override |
| 253 | public void onCapabilitiesChanged( |
| 254 | Network network, NetworkCapabilities networkCapabilities) { |
| 255 | boolean lastValidated = (mLastNetworkCapabilities != null) && |
| 256 | mLastNetworkCapabilities.hasCapability(NET_CAPABILITY_VALIDATED); |
| 257 | boolean validated = |
| 258 | networkCapabilities.hasCapability(NET_CAPABILITY_VALIDATED); |
| 259 | |
| 260 | // This callback is invoked a lot (i.e. when RSSI changes), so avoid updating |
| 261 | // icons when connectivity state has remained the same. |
| 262 | if (network.equals(mLastNetwork) && |
| 263 | networkCapabilities.equalsTransportTypes(mLastNetworkCapabilities) && |
| 264 | validated == lastValidated) { |
| 265 | return; |
| 266 | } |
| 267 | mLastNetwork = network; |
| 268 | mLastNetworkCapabilities = networkCapabilities; |
| 269 | updateConnectivity(); |
| 270 | } |
| 271 | }; |
| 272 | // Even though this callback runs on the receiver handler thread which also processes the |
| 273 | // CONNECTIVITY_ACTION broadcasts, the broadcast and callback might come in at different |
| 274 | // times. This is safe since updateConnectivity() builds the list of transports from |
| 275 | // scratch. |
| 276 | // TODO: Move off of the deprecated CONNECTIVITY_ACTION broadcast and rely on callbacks |
| 277 | // exclusively for status bar icons. |
| 278 | mConnectivityManager.registerDefaultNetworkCallback(callback, mReceiverHandler); |
Evan Laird | 470ae84 | 2019-04-09 16:24:27 -0400 | [diff] [blame] | 279 | // Register the listener on our bg looper |
| 280 | mPhoneStateListener = new PhoneStateListener(bgLooper) { |
| 281 | @Override |
| 282 | public void onActiveDataSubscriptionIdChanged(int subId) { |
| 283 | mActiveMobileDataSubscription = subId; |
| 284 | doUpdateMobileControllers(); |
| 285 | } |
| 286 | }; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 287 | } |
| 288 | |
Jason Monk | 9a4ce13 | 2016-01-21 15:27:17 -0500 | [diff] [blame] | 289 | public DataSaverController getDataSaverController() { |
| 290 | return mDataSaverController; |
| 291 | } |
| 292 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 293 | private void registerListeners() { |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 294 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 295 | MobileSignalController mobileSignalController = mMobileSignalControllers.valueAt(i); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 296 | mobileSignalController.registerListener(); |
| 297 | } |
Jason Monk | 8fcab35 | 2015-06-29 10:57:00 -0400 | [diff] [blame] | 298 | if (mSubscriptionListener == null) { |
| 299 | mSubscriptionListener = new SubListener(); |
| 300 | } |
Wink Saville | 071743f | 2015-01-12 17:11:04 -0800 | [diff] [blame] | 301 | mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener); |
Malcolm Chen | 50ba963 | 2019-02-26 16:49:56 -0800 | [diff] [blame] | 302 | mPhone.listen(mPhoneStateListener, LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 303 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 304 | // broadcasts |
| 305 | IntentFilter filter = new IntentFilter(); |
| 306 | filter.addAction(WifiManager.RSSI_CHANGED_ACTION); |
| 307 | filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); |
| 308 | filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); |
| 309 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 310 | filter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); |
| 311 | filter.addAction(TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED); |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 312 | filter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 313 | filter.addAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION); |
Erik Kline | 32830cc | 2015-04-21 13:09:15 +0900 | [diff] [blame] | 314 | filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 315 | filter.addAction(ConnectivityManager.INET_CONDITION_ACTION); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 316 | filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 317 | filter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 318 | mContext.registerReceiver(this, filter, null, mReceiverHandler); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 319 | mListening = true; |
| 320 | |
| 321 | updateMobileControllers(); |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 322 | } |
| 323 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 324 | private void unregisterListeners() { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 325 | mListening = false; |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 326 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 327 | MobileSignalController mobileSignalController = mMobileSignalControllers.valueAt(i); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 328 | mobileSignalController.unregisterListener(); |
| 329 | } |
Wink Saville | 071743f | 2015-01-12 17:11:04 -0800 | [diff] [blame] | 330 | mSubscriptionManager.removeOnSubscriptionsChangedListener(mSubscriptionListener); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 331 | mContext.unregisterReceiver(this); |
Jason Monk | 5d32507 | 2014-10-27 11:38:47 -0400 | [diff] [blame] | 332 | } |
| 333 | |
Jason Monk | 0e2400f | 2014-11-21 11:08:55 -0500 | [diff] [blame] | 334 | public int getConnectedWifiLevel() { |
| 335 | return mWifiSignalController.getState().level; |
| 336 | } |
| 337 | |
Jason Monk | 5d32507 | 2014-10-27 11:38:47 -0400 | [diff] [blame] | 338 | @Override |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 339 | public AccessPointController getAccessPointController() { |
| 340 | return mAccessPoints; |
| 341 | } |
| 342 | |
| 343 | @Override |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 344 | public DataUsageController getMobileDataController() { |
| 345 | return mDataUsageController; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | public void addEmergencyListener(EmergencyListener listener) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 349 | mCallbackHandler.setListening(listener, true); |
| 350 | mCallbackHandler.setEmergencyCallsOnly(isEmergencyOnly()); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 351 | } |
| 352 | |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 353 | public void removeEmergencyListener(EmergencyListener listener) { |
| 354 | mCallbackHandler.setListening(listener, false); |
| 355 | } |
| 356 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 357 | public boolean hasMobileDataFeature() { |
| 358 | return mHasMobileDataFeature; |
| 359 | } |
| 360 | |
| 361 | public boolean hasVoiceCallingFeature() { |
| 362 | return mPhone.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE; |
| 363 | } |
| 364 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 365 | private MobileSignalController getDataController() { |
Fabian Kozynski | ccde55d | 2019-06-26 10:06:09 -0400 | [diff] [blame] | 366 | int dataSubId = mSubDefaults.getActiveDataSubId(); |
Wink Saville | a54bf65 | 2014-12-11 13:37:50 -0800 | [diff] [blame] | 367 | if (!SubscriptionManager.isValidSubscriptionId(dataSubId)) { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 368 | if (DEBUG) Log.e(TAG, "No data sim selected"); |
| 369 | return mDefaultSignalController; |
| 370 | } |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 371 | if (mMobileSignalControllers.indexOfKey(dataSubId) >= 0) { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 372 | return mMobileSignalControllers.get(dataSubId); |
| 373 | } |
Dan Sandler | c846632 | 2014-12-08 15:42:52 -0500 | [diff] [blame] | 374 | if (DEBUG) Log.e(TAG, "Cannot find controller for data sub: " + dataSubId); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 375 | return mDefaultSignalController; |
| 376 | } |
| 377 | |
Amin Shaikh | 329c828 | 2018-03-09 14:50:59 -0500 | [diff] [blame] | 378 | @Override |
Pavel Zhamaitsiak | 5504d39 | 2015-03-27 09:24:47 -0700 | [diff] [blame] | 379 | public String getMobileDataNetworkName() { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 380 | MobileSignalController controller = getDataController(); |
Pavel Zhamaitsiak | 5504d39 | 2015-03-27 09:24:47 -0700 | [diff] [blame] | 381 | return controller != null ? controller.getState().networkNameData : ""; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 382 | } |
| 383 | |
Fabian Kozynski | f1c32a0 | 2019-03-22 15:09:30 -0400 | [diff] [blame] | 384 | @Override |
| 385 | public int getNumberSubscriptions() { |
| 386 | return mMobileSignalControllers.size(); |
| 387 | } |
| 388 | |
Evan Laird | 2ea99c1 | 2019-09-19 16:52:58 -0400 | [diff] [blame] | 389 | boolean isDataControllerDisabled() { |
| 390 | MobileSignalController dataController = getDataController(); |
| 391 | if (dataController == null) { |
| 392 | return false; |
| 393 | } |
| 394 | |
| 395 | return dataController.isDataDisabled(); |
| 396 | } |
| 397 | |
| 398 | private void notifyControllersMobileDataChanged() { |
| 399 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 400 | MobileSignalController mobileSignalController = mMobileSignalControllers.valueAt(i); |
| 401 | mobileSignalController.onMobileDataChanged(); |
| 402 | } |
| 403 | } |
| 404 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 405 | public boolean isEmergencyOnly() { |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 406 | if (mMobileSignalControllers.size() == 0) { |
| 407 | // When there are no active subscriptions, determine emengency state from last |
| 408 | // broadcast. |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 409 | mEmergencySource = EMERGENCY_NO_CONTROLLERS; |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 410 | return mLastServiceState != null && mLastServiceState.isEmergencyOnly(); |
| 411 | } |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 412 | int voiceSubId = mSubDefaults.getDefaultVoiceSubId(); |
Wink Saville | a54bf65 | 2014-12-11 13:37:50 -0800 | [diff] [blame] | 413 | if (!SubscriptionManager.isValidSubscriptionId(voiceSubId)) { |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 414 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 415 | MobileSignalController mobileSignalController = mMobileSignalControllers.valueAt(i); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 416 | if (!mobileSignalController.getState().isEmergency) { |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 417 | mEmergencySource = EMERGENCY_FIRST_CONTROLLER |
| 418 | + mobileSignalController.mSubscriptionInfo.getSubscriptionId(); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 419 | if (DEBUG) Log.d(TAG, "Found emergency " + mobileSignalController.mTag); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 420 | return false; |
| 421 | } |
| 422 | } |
| 423 | } |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 424 | if (mMobileSignalControllers.indexOfKey(voiceSubId) >= 0) { |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 425 | mEmergencySource = EMERGENCY_VOICE_CONTROLLER + voiceSubId; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 426 | if (DEBUG) Log.d(TAG, "Getting emergency from " + voiceSubId); |
| 427 | return mMobileSignalControllers.get(voiceSubId).getState().isEmergency; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 428 | } |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 429 | // If we have the wrong subId but there is only one sim anyway, assume it should be the |
| 430 | // default. |
| 431 | if (mMobileSignalControllers.size() == 1) { |
| 432 | mEmergencySource = EMERGENCY_ASSUMED_VOICE_CONTROLLER |
| 433 | + mMobileSignalControllers.keyAt(0); |
| 434 | if (DEBUG) Log.d(TAG, "Getting assumed emergency from " |
| 435 | + mMobileSignalControllers.keyAt(0)); |
| 436 | return mMobileSignalControllers.valueAt(0).getState().isEmergency; |
| 437 | } |
Dan Sandler | c846632 | 2014-12-08 15:42:52 -0500 | [diff] [blame] | 438 | if (DEBUG) Log.e(TAG, "Cannot find controller for voice sub: " + voiceSubId); |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 439 | mEmergencySource = EMERGENCY_NO_SUB + voiceSubId; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 440 | // Something is wrong, better assume we can't make calls... |
| 441 | return true; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 442 | } |
| 443 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 444 | /** |
| 445 | * Emergency status may have changed (triggered by MobileSignalController), |
| 446 | * so we should recheck and send out the state to listeners. |
| 447 | */ |
| 448 | void recalculateEmergency() { |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 449 | mIsEmergency = isEmergencyOnly(); |
| 450 | mCallbackHandler.setEmergencyCallsOnly(mIsEmergency); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 451 | } |
| 452 | |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 453 | public void addCallback(SignalCallback cb) { |
Jason Monk | e06b065 | 2016-03-02 16:35:27 -0500 | [diff] [blame] | 454 | cb.setSubs(mCurrentSubscriptions); |
| 455 | cb.setIsAirplaneMode(new IconState(mAirplaneMode, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 456 | TelephonyIcons.FLIGHT_MODE_ICON, R.string.accessibility_airplane_mode, mContext)); |
Jason Monk | 1ff7766 | 2017-09-29 11:17:05 -0400 | [diff] [blame] | 457 | cb.setNoSims(mHasNoSubs, mSimDetected); |
Jason Monk | e06b065 | 2016-03-02 16:35:27 -0500 | [diff] [blame] | 458 | mWifiSignalController.notifyListeners(cb); |
| 459 | mEthernetSignalController.notifyListeners(cb); |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 460 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 461 | MobileSignalController mobileSignalController = mMobileSignalControllers.valueAt(i); |
Jason Monk | e06b065 | 2016-03-02 16:35:27 -0500 | [diff] [blame] | 462 | mobileSignalController.notifyListeners(cb); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 463 | } |
Jason Monk | e06b065 | 2016-03-02 16:35:27 -0500 | [diff] [blame] | 464 | mCallbackHandler.setListening(cb, true); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 465 | } |
| 466 | |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 467 | @Override |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 468 | public void removeCallback(SignalCallback cb) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 469 | mCallbackHandler.setListening(cb, false); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | @Override |
| 473 | public void setWifiEnabled(final boolean enabled) { |
| 474 | new AsyncTask<Void, Void, Void>() { |
| 475 | @Override |
| 476 | protected Void doInBackground(Void... args) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 477 | mWifiManager.setWifiEnabled(enabled); |
| 478 | return null; |
| 479 | } |
| 480 | }.execute(); |
| 481 | } |
| 482 | |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 483 | private void onUserSwitched(int newUserId) { |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 484 | mCurrentUserId = newUserId; |
| 485 | mAccessPoints.onUserSwitched(newUserId); |
| 486 | updateConnectivity(); |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 490 | public void onReceive(Context context, Intent intent) { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 491 | if (CHATTY) { |
| 492 | Log.d(TAG, "onReceive: intent=" + intent); |
| 493 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 494 | final String action = intent.getAction(); |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 495 | switch (action) { |
| 496 | case ConnectivityManager.CONNECTIVITY_ACTION: |
| 497 | case ConnectivityManager.INET_CONDITION_ACTION: |
| 498 | updateConnectivity(); |
| 499 | break; |
| 500 | case Intent.ACTION_AIRPLANE_MODE_CHANGED: |
| 501 | refreshLocale(); |
| 502 | updateAirplaneMode(false); |
| 503 | break; |
| 504 | case TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED: |
| 505 | // We are using different subs now, we might be able to make calls. |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 506 | recalculateEmergency(); |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 507 | break; |
| 508 | case TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED: |
| 509 | // Notify every MobileSignalController so they can know whether they are the |
| 510 | // data sim or not. |
| 511 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 512 | MobileSignalController controller = mMobileSignalControllers.valueAt(i); |
| 513 | controller.handleBroadcast(intent); |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 514 | } |
Niklas Lindgren | a02964d | 2018-09-21 14:01:57 +0200 | [diff] [blame] | 515 | mConfig = Config.readConfig(mContext); |
| 516 | mReceiverHandler.post(this::handleConfigurationChanged); |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 517 | break; |
| 518 | case TelephonyIntents.ACTION_SIM_STATE_CHANGED: |
| 519 | // Avoid rebroadcast because SysUI is direct boot aware. |
| 520 | if (intent.getBooleanExtra(TelephonyIntents.EXTRA_REBROADCAST_ON_UNLOCK, false)) { |
| 521 | break; |
| 522 | } |
| 523 | // Might have different subscriptions now. |
| 524 | updateMobileControllers(); |
| 525 | break; |
| 526 | case TelephonyIntents.ACTION_SERVICE_STATE_CHANGED: |
| 527 | mLastServiceState = ServiceState.newFromBundle(intent.getExtras()); |
| 528 | if (mMobileSignalControllers.size() == 0) { |
| 529 | // If none of the subscriptions are active, we might need to recalculate |
| 530 | // emergency state. |
| 531 | recalculateEmergency(); |
| 532 | } |
| 533 | break; |
| 534 | case CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED: |
| 535 | mConfig = Config.readConfig(mContext); |
| 536 | mReceiverHandler.post(this::handleConfigurationChanged); |
| 537 | break; |
| 538 | default: |
| 539 | int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, |
| 540 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
| 541 | if (SubscriptionManager.isValidSubscriptionId(subId)) { |
| 542 | if (mMobileSignalControllers.indexOfKey(subId) >= 0) { |
| 543 | mMobileSignalControllers.get(subId).handleBroadcast(intent); |
| 544 | } else { |
| 545 | // Can't find this subscription... We must be out of date. |
| 546 | updateMobileControllers(); |
| 547 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 548 | } else { |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 549 | // No sub id, must be for the wifi. |
| 550 | mWifiSignalController.handleBroadcast(intent); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 551 | } |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 552 | break; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 553 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 554 | } |
| 555 | |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 556 | public void onConfigurationChanged(Configuration newConfig) { |
Sungmin Choi | 6be4f6b | 2015-07-07 13:06:59 +0900 | [diff] [blame] | 557 | mConfig = Config.readConfig(mContext); |
Jason Monk | 1c040db | 2015-07-20 09:45:54 -0400 | [diff] [blame] | 558 | mReceiverHandler.post(new Runnable() { |
| 559 | @Override |
| 560 | public void run() { |
| 561 | handleConfigurationChanged(); |
| 562 | } |
| 563 | }); |
| 564 | } |
| 565 | |
| 566 | @VisibleForTesting |
| 567 | void handleConfigurationChanged() { |
Malcolm Chen | 50ba963 | 2019-02-26 16:49:56 -0800 | [diff] [blame] | 568 | updateMobileControllers(); |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 569 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 570 | MobileSignalController controller = mMobileSignalControllers.valueAt(i); |
| 571 | controller.setConfiguration(mConfig); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 572 | } |
| 573 | refreshLocale(); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 574 | } |
| 575 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 576 | private void updateMobileControllers() { |
| 577 | if (!mListening) { |
| 578 | return; |
| 579 | } |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 580 | doUpdateMobileControllers(); |
| 581 | } |
| 582 | |
Malcolm Chen | 50ba963 | 2019-02-26 16:49:56 -0800 | [diff] [blame] | 583 | private void filterMobileSubscriptionInSameGroup(List<SubscriptionInfo> subscriptions) { |
| 584 | if (subscriptions.size() == MAX_PHONE_COUNT_DUAL_SIM) { |
| 585 | SubscriptionInfo info1 = subscriptions.get(0); |
| 586 | SubscriptionInfo info2 = subscriptions.get(1); |
| 587 | if (info1.getGroupUuid() != null && info1.getGroupUuid().equals(info2.getGroupUuid())) { |
| 588 | // If both subscriptions are primary, show both. |
| 589 | if (!info1.isOpportunistic() && !info2.isOpportunistic()) return; |
| 590 | |
| 591 | // If carrier required, always show signal bar of primary subscription. |
| 592 | // Otherwise, show whichever subscription is currently active for Internet. |
| 593 | boolean alwaysShowPrimary = CarrierConfigManager.getDefaultConfig() |
| 594 | .getBoolean(CarrierConfigManager |
| 595 | .KEY_ALWAYS_SHOW_PRIMARY_SIGNAL_BAR_IN_OPPORTUNISTIC_NETWORK_BOOLEAN); |
| 596 | if (alwaysShowPrimary) { |
| 597 | subscriptions.remove(info1.isOpportunistic() ? info1 : info2); |
| 598 | } else { |
| 599 | subscriptions.remove(info1.getSubscriptionId() == mActiveMobileDataSubscription |
| 600 | ? info2 : info1); |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 606 | @VisibleForTesting |
| 607 | void doUpdateMobileControllers() { |
Malcolm Chen | d2d400cb | 2018-12-21 17:11:10 -0800 | [diff] [blame] | 608 | List<SubscriptionInfo> subscriptions = mSubscriptionManager |
Malcolm Chen | 50ba963 | 2019-02-26 16:49:56 -0800 | [diff] [blame] | 609 | .getActiveSubscriptionInfoList(false); |
Jason Monk | c9f0571 | 2014-12-15 12:24:10 -0500 | [diff] [blame] | 610 | if (subscriptions == null) { |
| 611 | subscriptions = Collections.emptyList(); |
| 612 | } |
Malcolm Chen | 50ba963 | 2019-02-26 16:49:56 -0800 | [diff] [blame] | 613 | |
| 614 | filterMobileSubscriptionInSameGroup(subscriptions); |
| 615 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 616 | // If there have been no relevant changes to any of the subscriptions, we can leave as is. |
| 617 | if (hasCorrectMobileControllers(subscriptions)) { |
| 618 | // Even if the controllers are correct, make sure we have the right no sims state. |
| 619 | // Such as on boot, don't need any controllers, because there are no sims, |
| 620 | // but we still need to update the no sim state. |
| 621 | updateNoSims(); |
| 622 | return; |
| 623 | } |
Evan Laird | 470ae84 | 2019-04-09 16:24:27 -0400 | [diff] [blame] | 624 | synchronized (mLock) { |
| 625 | setCurrentSubscriptionsLocked(subscriptions); |
| 626 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 627 | updateNoSims(); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 628 | recalculateEmergency(); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 629 | } |
| 630 | |
Jason Monk | 21d05a0 | 2014-12-02 12:46:58 -0500 | [diff] [blame] | 631 | @VisibleForTesting |
| 632 | protected void updateNoSims() { |
Jason Monk | 1ff7766 | 2017-09-29 11:17:05 -0400 | [diff] [blame] | 633 | boolean hasNoSubs = mHasMobileDataFeature && mMobileSignalControllers.size() == 0; |
| 634 | boolean simDetected = hasAnySim(); |
| 635 | if (hasNoSubs != mHasNoSubs || simDetected != mSimDetected) { |
| 636 | mHasNoSubs = hasNoSubs; |
| 637 | mSimDetected = simDetected; |
| 638 | mCallbackHandler.setNoSims(mHasNoSubs, mSimDetected); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | |
Jason Monk | 1ff7766 | 2017-09-29 11:17:05 -0400 | [diff] [blame] | 642 | private boolean hasAnySim() { |
| 643 | int simCount = mPhone.getSimCount(); |
| 644 | for (int i = 0; i < simCount; i++) { |
| 645 | int state = mPhone.getSimState(i); |
| 646 | if (state != TelephonyManager.SIM_STATE_ABSENT |
| 647 | && state != TelephonyManager.SIM_STATE_UNKNOWN) { |
| 648 | return true; |
| 649 | } |
| 650 | } |
| 651 | return false; |
| 652 | } |
| 653 | |
Evan Laird | 470ae84 | 2019-04-09 16:24:27 -0400 | [diff] [blame] | 654 | @GuardedBy("mLock") |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 655 | @VisibleForTesting |
Evan Laird | 470ae84 | 2019-04-09 16:24:27 -0400 | [diff] [blame] | 656 | public void setCurrentSubscriptionsLocked(List<SubscriptionInfo> subscriptions) { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 657 | Collections.sort(subscriptions, new Comparator<SubscriptionInfo>() { |
| 658 | @Override |
| 659 | public int compare(SubscriptionInfo lhs, SubscriptionInfo rhs) { |
| 660 | return lhs.getSimSlotIndex() == rhs.getSimSlotIndex() |
| 661 | ? lhs.getSubscriptionId() - rhs.getSubscriptionId() |
| 662 | : lhs.getSimSlotIndex() - rhs.getSimSlotIndex(); |
| 663 | } |
| 664 | }); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 665 | mCurrentSubscriptions = subscriptions; |
| 666 | |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 667 | SparseArray<MobileSignalController> cachedControllers = |
| 668 | new SparseArray<MobileSignalController>(); |
| 669 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 670 | cachedControllers.put(mMobileSignalControllers.keyAt(i), |
| 671 | mMobileSignalControllers.valueAt(i)); |
| 672 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 673 | mMobileSignalControllers.clear(); |
| 674 | final int num = subscriptions.size(); |
| 675 | for (int i = 0; i < num; i++) { |
| 676 | int subId = subscriptions.get(i).getSubscriptionId(); |
| 677 | // If we have a copy of this controller already reuse it, otherwise make a new one. |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 678 | if (cachedControllers.indexOfKey(subId) >= 0) { |
| 679 | mMobileSignalControllers.put(subId, cachedControllers.get(subId)); |
| 680 | cachedControllers.remove(subId); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 681 | } else { |
| 682 | MobileSignalController controller = new MobileSignalController(mContext, mConfig, |
chen xu | 84a9087 | 2019-03-28 15:44:12 -0700 | [diff] [blame] | 683 | mHasMobileDataFeature, mPhone.createForSubscriptionId(subId), |
| 684 | mCallbackHandler, this, subscriptions.get(i), |
| 685 | mSubDefaults, mReceiverHandler.getLooper()); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 686 | controller.setUserSetupComplete(mUserSetup); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 687 | mMobileSignalControllers.put(subId, controller); |
| 688 | if (subscriptions.get(i).getSimSlotIndex() == 0) { |
| 689 | mDefaultSignalController = controller; |
| 690 | } |
| 691 | if (mListening) { |
| 692 | controller.registerListener(); |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | if (mListening) { |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 697 | for (int i = 0; i < cachedControllers.size(); i++) { |
| 698 | int key = cachedControllers.keyAt(i); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 699 | if (cachedControllers.get(key) == mDefaultSignalController) { |
| 700 | mDefaultSignalController = null; |
| 701 | } |
| 702 | cachedControllers.get(key).unregisterListener(); |
| 703 | } |
| 704 | } |
Jason Monk | 8fcab35 | 2015-06-29 10:57:00 -0400 | [diff] [blame] | 705 | mCallbackHandler.setSubs(subscriptions); |
| 706 | notifyAllListeners(); |
| 707 | |
Jason Monk | 25d8a48 | 2014-12-09 12:27:24 -0500 | [diff] [blame] | 708 | // There may be new MobileSignalControllers around, make sure they get the current |
| 709 | // inet condition and airplane mode. |
| 710 | pushConnectivityToSignals(); |
| 711 | updateAirplaneMode(true /* force */); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 712 | } |
| 713 | |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 714 | private void setUserSetupComplete(final boolean userSetup) { |
| 715 | mReceiverHandler.post(() -> handleSetUserSetupComplete(userSetup)); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 716 | } |
| 717 | |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 718 | private void handleSetUserSetupComplete(boolean userSetup) { |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 719 | mUserSetup = userSetup; |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 720 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 721 | MobileSignalController controller = mMobileSignalControllers.valueAt(i); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 722 | controller.setUserSetupComplete(mUserSetup); |
| 723 | } |
| 724 | } |
| 725 | |
Jason Monk | c014dec | 2014-12-12 11:49:55 -0500 | [diff] [blame] | 726 | @VisibleForTesting |
| 727 | boolean hasCorrectMobileControllers(List<SubscriptionInfo> allSubscriptions) { |
Jason Monk | c9f0571 | 2014-12-15 12:24:10 -0500 | [diff] [blame] | 728 | if (allSubscriptions.size() != mMobileSignalControllers.size()) { |
| 729 | return false; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 730 | } |
| 731 | for (SubscriptionInfo info : allSubscriptions) { |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 732 | if (mMobileSignalControllers.indexOfKey(info.getSubscriptionId()) < 0) { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 733 | return false; |
| 734 | } |
| 735 | } |
| 736 | return true; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 737 | } |
| 738 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 739 | private void updateAirplaneMode(boolean force) { |
| 740 | boolean airplaneMode = (Settings.Global.getInt(mContext.getContentResolver(), |
| 741 | Settings.Global.AIRPLANE_MODE_ON, 0) == 1); |
| 742 | if (airplaneMode != mAirplaneMode || force) { |
| 743 | mAirplaneMode = airplaneMode; |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 744 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 745 | MobileSignalController mobileSignalController = mMobileSignalControllers.valueAt(i); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 746 | mobileSignalController.setAirplaneMode(mAirplaneMode); |
| 747 | } |
| 748 | notifyListeners(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 749 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | private void refreshLocale() { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 753 | Locale current = mContext.getResources().getConfiguration().locale; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 754 | if (!current.equals(mLocale)) { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 755 | mLocale = current; |
Fabian Kozynski | d9cb384 | 2018-09-28 13:34:14 -0400 | [diff] [blame] | 756 | mWifiSignalController.refreshLocale(); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 757 | notifyAllListeners(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 761 | /** |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 762 | * Forces update of all callbacks on both SignalClusters and |
| 763 | * NetworkSignalChangedCallbacks. |
| 764 | */ |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 765 | private void notifyAllListeners() { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 766 | notifyListeners(); |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 767 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 768 | MobileSignalController mobileSignalController = mMobileSignalControllers.valueAt(i); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 769 | mobileSignalController.notifyListeners(); |
| 770 | } |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 771 | mWifiSignalController.notifyListeners(); |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 772 | mEthernetSignalController.notifyListeners(); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 773 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 774 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 775 | /** |
| 776 | * Notifies listeners of changes in state of to the NetworkController, but |
| 777 | * does not notify for any info on SignalControllers, for that call |
| 778 | * notifyAllListeners. |
| 779 | */ |
| 780 | private void notifyListeners() { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 781 | mCallbackHandler.setIsAirplaneMode(new IconState(mAirplaneMode, |
| 782 | TelephonyIcons.FLIGHT_MODE_ICON, R.string.accessibility_airplane_mode, mContext)); |
Jason Monk | 1ff7766 | 2017-09-29 11:17:05 -0400 | [diff] [blame] | 783 | mCallbackHandler.setNoSims(mHasNoSubs, mSimDetected); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 784 | } |
| 785 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 786 | /** |
| 787 | * Update the Inet conditions and what network we are connected to. |
| 788 | */ |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 789 | private void updateConnectivity() { |
| 790 | mConnectedTransports.clear(); |
| 791 | mValidatedTransports.clear(); |
| 792 | for (NetworkCapabilities nc : |
| 793 | mConnectivityManager.getDefaultNetworkCapabilitiesForUser(mCurrentUserId)) { |
| 794 | for (int transportType : nc.getTransportTypes()) { |
| 795 | mConnectedTransports.set(transportType); |
| 796 | if (nc.hasCapability(NET_CAPABILITY_VALIDATED)) { |
| 797 | mValidatedTransports.set(transportType); |
| 798 | } |
| 799 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 800 | } |
| 801 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 802 | if (CHATTY) { |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 803 | Log.d(TAG, "updateConnectivity: mConnectedTransports=" + mConnectedTransports); |
| 804 | Log.d(TAG, "updateConnectivity: mValidatedTransports=" + mValidatedTransports); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 805 | } |
| 806 | |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 807 | mInetCondition = !mValidatedTransports.isEmpty(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 808 | |
Jason Monk | 25d8a48 | 2014-12-09 12:27:24 -0500 | [diff] [blame] | 809 | pushConnectivityToSignals(); |
| 810 | } |
| 811 | |
| 812 | /** |
| 813 | * Pushes the current connectivity state to all SignalControllers. |
| 814 | */ |
| 815 | private void pushConnectivityToSignals() { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 816 | // We want to update all the icons, all at once, for any condition change |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 817 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 818 | MobileSignalController mobileSignalController = mMobileSignalControllers.valueAt(i); |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 819 | mobileSignalController.updateConnectivity(mConnectedTransports, mValidatedTransports); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 820 | } |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 821 | mWifiSignalController.updateConnectivity(mConnectedTransports, mValidatedTransports); |
| 822 | mEthernetSignalController.updateConnectivity(mConnectedTransports, mValidatedTransports); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 823 | } |
| 824 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 825 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 826 | pw.println("NetworkController state:"); |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 827 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 828 | pw.println(" - telephony ------"); |
| 829 | pw.print(" hasVoiceCallingFeature()="); |
| 830 | pw.println(hasVoiceCallingFeature()); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 831 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 832 | pw.println(" - connectivity ------"); |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 833 | pw.print(" mConnectedTransports="); |
| 834 | pw.println(mConnectedTransports); |
| 835 | pw.print(" mValidatedTransports="); |
| 836 | pw.println(mValidatedTransports); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 837 | pw.print(" mInetCondition="); |
| 838 | pw.println(mInetCondition); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 839 | pw.print(" mAirplaneMode="); |
| 840 | pw.println(mAirplaneMode); |
| 841 | pw.print(" mLocale="); |
| 842 | pw.println(mLocale); |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 843 | pw.print(" mLastServiceState="); |
| 844 | pw.println(mLastServiceState); |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 845 | pw.print(" mIsEmergency="); |
| 846 | pw.println(mIsEmergency); |
| 847 | pw.print(" mEmergencySource="); |
| 848 | pw.println(emergencyToString(mEmergencySource)); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 849 | |
Bill Lin | 767c0db | 2019-08-15 20:42:06 +0800 | [diff] [blame] | 850 | pw.println(" - config ------"); |
| 851 | pw.print(" patternOfCarrierSpecificDataIcon="); |
| 852 | pw.println(mConfig.patternOfCarrierSpecificDataIcon); |
| 853 | pw.print(" nr5GIconMap="); |
| 854 | pw.println(mConfig.nr5GIconMap.toString()); |
| 855 | pw.print(" nrIconDisplayGracePeriodMs="); |
| 856 | pw.println(mConfig.nrIconDisplayGracePeriodMs); |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 857 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 858 | MobileSignalController mobileSignalController = mMobileSignalControllers.valueAt(i); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 859 | mobileSignalController.dump(pw); |
| 860 | } |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 861 | mWifiSignalController.dump(pw); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 862 | |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 863 | mEthernetSignalController.dump(pw); |
| 864 | |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 865 | mAccessPoints.dump(pw); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 866 | } |
| 867 | |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 868 | private static final String emergencyToString(int emergencySource) { |
| 869 | if (emergencySource > EMERGENCY_NO_SUB) { |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 870 | return "ASSUMED_VOICE_CONTROLLER(" + (emergencySource - EMERGENCY_VOICE_CONTROLLER) |
| 871 | + ")"; |
| 872 | } else if (emergencySource > EMERGENCY_NO_SUB) { |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 873 | return "NO_SUB(" + (emergencySource - EMERGENCY_NO_SUB) + ")"; |
| 874 | } else if (emergencySource > EMERGENCY_VOICE_CONTROLLER) { |
| 875 | return "VOICE_CONTROLLER(" + (emergencySource - EMERGENCY_VOICE_CONTROLLER) + ")"; |
| 876 | } else if (emergencySource > EMERGENCY_FIRST_CONTROLLER) { |
| 877 | return "FIRST_CONTROLLER(" + (emergencySource - EMERGENCY_FIRST_CONTROLLER) + ")"; |
| 878 | } else if (emergencySource == EMERGENCY_NO_CONTROLLERS) { |
| 879 | return "NO_CONTROLLERS"; |
| 880 | } |
| 881 | return "UNKNOWN_SOURCE"; |
| 882 | } |
| 883 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 884 | private boolean mDemoMode; |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 885 | private boolean mDemoInetCondition; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 886 | private WifiSignalController.WifiState mDemoWifiState; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 887 | |
| 888 | @Override |
| 889 | public void dispatchDemoCommand(String command, Bundle args) { |
| 890 | if (!mDemoMode && command.equals(COMMAND_ENTER)) { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 891 | if (DEBUG) Log.d(TAG, "Entering demo mode"); |
| 892 | unregisterListeners(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 893 | mDemoMode = true; |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 894 | mDemoInetCondition = mInetCondition; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 895 | mDemoWifiState = mWifiSignalController.getState(); |
Kenneth Westin | 5c88ffb | 2013-11-28 16:29:40 +0100 | [diff] [blame] | 896 | mDemoWifiState.ssid = "DemoMode"; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 897 | } else if (mDemoMode && command.equals(COMMAND_EXIT)) { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 898 | if (DEBUG) Log.d(TAG, "Exiting demo mode"); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 899 | mDemoMode = false; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 900 | // Update what MobileSignalControllers, because they may change |
| 901 | // to set the number of sim slots. |
| 902 | updateMobileControllers(); |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 903 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 904 | MobileSignalController controller = mMobileSignalControllers.valueAt(i); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 905 | controller.resetLastState(); |
| 906 | } |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 907 | mWifiSignalController.resetLastState(); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 908 | mReceiverHandler.post(mRegisterListeners); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 909 | notifyAllListeners(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 910 | } else if (mDemoMode && command.equals(COMMAND_NETWORK)) { |
| 911 | String airplane = args.getString("airplane"); |
| 912 | if (airplane != null) { |
| 913 | boolean show = airplane.equals("show"); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 914 | mCallbackHandler.setIsAirplaneMode(new IconState(show, |
| 915 | TelephonyIcons.FLIGHT_MODE_ICON, R.string.accessibility_airplane_mode, |
| 916 | mContext)); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 917 | } |
| 918 | String fully = args.getString("fully"); |
| 919 | if (fully != null) { |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 920 | mDemoInetCondition = Boolean.parseBoolean(fully); |
| 921 | BitSet connected = new BitSet(); |
| 922 | |
| 923 | if (mDemoInetCondition) { |
| 924 | connected.set(mWifiSignalController.mTransportType); |
| 925 | } |
| 926 | mWifiSignalController.updateConnectivity(connected, connected); |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 927 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 928 | MobileSignalController controller = mMobileSignalControllers.valueAt(i); |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 929 | if (mDemoInetCondition) { |
| 930 | connected.set(controller.mTransportType); |
| 931 | } |
| 932 | controller.updateConnectivity(connected, connected); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 933 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 934 | } |
| 935 | String wifi = args.getString("wifi"); |
| 936 | if (wifi != null) { |
| 937 | boolean show = wifi.equals("show"); |
| 938 | String level = args.getString("level"); |
| 939 | if (level != null) { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 940 | mDemoWifiState.level = level.equals("null") ? -1 |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 941 | : Math.min(Integer.parseInt(level), WifiIcons.WIFI_LEVEL_COUNT - 1); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 942 | mDemoWifiState.connected = mDemoWifiState.level >= 0; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 943 | } |
Kenneth Westin | 5c88ffb | 2013-11-28 16:29:40 +0100 | [diff] [blame] | 944 | String activity = args.getString("activity"); |
| 945 | if (activity != null) { |
| 946 | switch (activity) { |
| 947 | case "inout": |
Roshan Pius | 80fb137 | 2018-07-16 15:43:03 -0700 | [diff] [blame] | 948 | mWifiSignalController.setActivity(DATA_ACTIVITY_INOUT); |
Kenneth Westin | 5c88ffb | 2013-11-28 16:29:40 +0100 | [diff] [blame] | 949 | break; |
| 950 | case "in": |
Roshan Pius | 80fb137 | 2018-07-16 15:43:03 -0700 | [diff] [blame] | 951 | mWifiSignalController.setActivity(DATA_ACTIVITY_IN); |
Kenneth Westin | 5c88ffb | 2013-11-28 16:29:40 +0100 | [diff] [blame] | 952 | break; |
| 953 | case "out": |
Roshan Pius | 80fb137 | 2018-07-16 15:43:03 -0700 | [diff] [blame] | 954 | mWifiSignalController.setActivity(DATA_ACTIVITY_OUT); |
Kenneth Westin | 5c88ffb | 2013-11-28 16:29:40 +0100 | [diff] [blame] | 955 | break; |
| 956 | default: |
Roshan Pius | 80fb137 | 2018-07-16 15:43:03 -0700 | [diff] [blame] | 957 | mWifiSignalController.setActivity(DATA_ACTIVITY_NONE); |
Kenneth Westin | 5c88ffb | 2013-11-28 16:29:40 +0100 | [diff] [blame] | 958 | break; |
| 959 | } |
| 960 | } else { |
Roshan Pius | 80fb137 | 2018-07-16 15:43:03 -0700 | [diff] [blame] | 961 | mWifiSignalController.setActivity(DATA_ACTIVITY_NONE); |
Kenneth Westin | 5c88ffb | 2013-11-28 16:29:40 +0100 | [diff] [blame] | 962 | } |
Evan Laird | 27a9957 | 2017-09-27 14:09:30 -0400 | [diff] [blame] | 963 | String ssid = args.getString("ssid"); |
| 964 | if (ssid != null) { |
| 965 | mDemoWifiState.ssid = ssid; |
| 966 | } |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 967 | mDemoWifiState.enabled = show; |
| 968 | mWifiSignalController.notifyListeners(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 969 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 970 | String sims = args.getString("sims"); |
| 971 | if (sims != null) { |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 972 | int num = MathUtils.constrain(Integer.parseInt(sims), 1, 8); |
| 973 | List<SubscriptionInfo> subs = new ArrayList<>(); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 974 | if (num != mMobileSignalControllers.size()) { |
| 975 | mMobileSignalControllers.clear(); |
| 976 | int start = mSubscriptionManager.getActiveSubscriptionInfoCountMax(); |
| 977 | for (int i = start /* get out of normal index range */; i < start + num; i++) { |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 978 | subs.add(addSignalController(i, i)); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 979 | } |
Jason Monk | 33b60bb | 2015-07-13 10:42:23 -0400 | [diff] [blame] | 980 | mCallbackHandler.setSubs(subs); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 981 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 982 | int key = mMobileSignalControllers.keyAt(i); |
| 983 | MobileSignalController controller = mMobileSignalControllers.get(key); |
| 984 | controller.notifyListeners(); |
| 985 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 986 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 987 | } |
| 988 | String nosim = args.getString("nosim"); |
| 989 | if (nosim != null) { |
Jason Monk | 1ff7766 | 2017-09-29 11:17:05 -0400 | [diff] [blame] | 990 | mHasNoSubs = nosim.equals("show"); |
| 991 | mCallbackHandler.setNoSims(mHasNoSubs, mSimDetected); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 992 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 993 | String mobile = args.getString("mobile"); |
| 994 | if (mobile != null) { |
| 995 | boolean show = mobile.equals("show"); |
| 996 | String datatype = args.getString("datatype"); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 997 | String slotString = args.getString("slot"); |
| 998 | int slot = TextUtils.isEmpty(slotString) ? 0 : Integer.parseInt(slotString); |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 999 | slot = MathUtils.constrain(slot, 0, 8); |
| 1000 | // Ensure we have enough sim slots |
| 1001 | List<SubscriptionInfo> subs = new ArrayList<>(); |
| 1002 | while (mMobileSignalControllers.size() <= slot) { |
| 1003 | int nextSlot = mMobileSignalControllers.size(); |
| 1004 | subs.add(addSignalController(nextSlot, nextSlot)); |
| 1005 | } |
| 1006 | if (!subs.isEmpty()) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 1007 | mCallbackHandler.setSubs(subs); |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 1008 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 1009 | // Hack to index linearly for easy use. |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 1010 | MobileSignalController controller = mMobileSignalControllers.valueAt(slot); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 1011 | controller.getState().dataSim = datatype != null; |
Jason Monk | b595098 | 2017-01-24 15:53:53 -0500 | [diff] [blame] | 1012 | controller.getState().isDefault = datatype != null; |
| 1013 | controller.getState().dataConnected = datatype != null; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 1014 | if (datatype != null) { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 1015 | controller.getState().iconGroup = |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 1016 | datatype.equals("1x") ? TelephonyIcons.ONE_X : |
| 1017 | datatype.equals("3g") ? TelephonyIcons.THREE_G : |
| 1018 | datatype.equals("4g") ? TelephonyIcons.FOUR_G : |
Ajay Nambi | 7965fa4 | 2015-05-14 18:48:33 -0700 | [diff] [blame] | 1019 | datatype.equals("4g+") ? TelephonyIcons.FOUR_G_PLUS : |
Bill Lin | 767c0db | 2019-08-15 20:42:06 +0800 | [diff] [blame] | 1020 | datatype.equals("5g") ? TelephonyIcons.NR_5G : |
Evan Laird | 83c87e5 | 2019-09-24 19:14:05 -0400 | [diff] [blame] | 1021 | datatype.equals("5ge") ? TelephonyIcons.LTE_CA_5G_E : |
Bill Lin | 767c0db | 2019-08-15 20:42:06 +0800 | [diff] [blame] | 1022 | datatype.equals("5g+") ? TelephonyIcons.NR_5G_PLUS : |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 1023 | datatype.equals("e") ? TelephonyIcons.E : |
| 1024 | datatype.equals("g") ? TelephonyIcons.G : |
| 1025 | datatype.equals("h") ? TelephonyIcons.H : |
Amin Shaikh | f5830ca | 2018-03-09 14:06:50 -0500 | [diff] [blame] | 1026 | datatype.equals("h+") ? TelephonyIcons.H_PLUS : |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 1027 | datatype.equals("lte") ? TelephonyIcons.LTE : |
Jason Monk | aa730be | 2016-07-13 14:22:52 -0400 | [diff] [blame] | 1028 | datatype.equals("lte+") ? TelephonyIcons.LTE_PLUS : |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 1029 | datatype.equals("dis") ? TelephonyIcons.DATA_DISABLED : |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 1030 | datatype.equals("not") ? TelephonyIcons.NOT_DEFAULT_DATA : |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 1031 | TelephonyIcons.UNKNOWN; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 1032 | } |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 1033 | if (args.containsKey("roam")) { |
| 1034 | controller.getState().roaming = "show".equals(args.getString("roam")); |
| 1035 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 1036 | String level = args.getString("level"); |
| 1037 | if (level != null) { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 1038 | controller.getState().level = level.equals("null") ? -1 |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 1039 | : Math.min(Integer.parseInt(level), |
| 1040 | SignalStrength.NUM_SIGNAL_STRENGTH_BINS); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 1041 | controller.getState().connected = controller.getState().level >= 0; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 1042 | } |
Amin Shaikh | 0ad7e51 | 2019-04-29 07:36:34 -0400 | [diff] [blame] | 1043 | if (args.containsKey("inflate")) { |
| 1044 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 1045 | mMobileSignalControllers.valueAt(i).mInflateSignalStrengths = |
| 1046 | "true".equals(args.getString("inflate")); |
| 1047 | } |
| 1048 | } |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 1049 | String activity = args.getString("activity"); |
| 1050 | if (activity != null) { |
Kenneth Westin | 5c88ffb | 2013-11-28 16:29:40 +0100 | [diff] [blame] | 1051 | controller.getState().dataConnected = true; |
| 1052 | switch (activity) { |
| 1053 | case "inout": |
| 1054 | controller.setActivity(TelephonyManager.DATA_ACTIVITY_INOUT); |
| 1055 | break; |
| 1056 | case "in": |
| 1057 | controller.setActivity(TelephonyManager.DATA_ACTIVITY_IN); |
| 1058 | break; |
| 1059 | case "out": |
| 1060 | controller.setActivity(TelephonyManager.DATA_ACTIVITY_OUT); |
| 1061 | break; |
| 1062 | default: |
| 1063 | controller.setActivity(TelephonyManager.DATA_ACTIVITY_NONE); |
| 1064 | break; |
| 1065 | } |
| 1066 | } else { |
| 1067 | controller.setActivity(TelephonyManager.DATA_ACTIVITY_NONE); |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 1068 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 1069 | controller.getState().enabled = show; |
| 1070 | controller.notifyListeners(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 1071 | } |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 1072 | String carrierNetworkChange = args.getString("carriernetworkchange"); |
| 1073 | if (carrierNetworkChange != null) { |
| 1074 | boolean show = carrierNetworkChange.equals("show"); |
Jason Monk | 8996b94 | 2017-03-02 13:58:19 -0500 | [diff] [blame] | 1075 | for (int i = 0; i < mMobileSignalControllers.size(); i++) { |
| 1076 | MobileSignalController controller = mMobileSignalControllers.valueAt(i); |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 1077 | controller.setCarrierNetworkChangeMode(show); |
| 1078 | } |
| 1079 | } |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 1083 | private SubscriptionInfo addSignalController(int id, int simSlotIndex) { |
| 1084 | SubscriptionInfo info = new SubscriptionInfo(id, "", simSlotIndex, "", "", 0, 0, "", 0, |
Malcolm Chen | e89e0ce | 2018-08-09 17:01:35 -0700 | [diff] [blame] | 1085 | null, null, null, "", false, null, null); |
Jason Monk | b595098 | 2017-01-24 15:53:53 -0500 | [diff] [blame] | 1086 | MobileSignalController controller = new MobileSignalController(mContext, |
chen xu | 84a9087 | 2019-03-28 15:44:12 -0700 | [diff] [blame] | 1087 | mConfig, mHasMobileDataFeature, |
| 1088 | mPhone.createForSubscriptionId(info.getSubscriptionId()), mCallbackHandler, this, info, |
Jason Monk | b595098 | 2017-01-24 15:53:53 -0500 | [diff] [blame] | 1089 | mSubDefaults, mReceiverHandler.getLooper()); |
| 1090 | mMobileSignalControllers.put(id, controller); |
| 1091 | controller.getState().userSetup = true; |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 1092 | return info; |
| 1093 | } |
| 1094 | |
Adrian Roos | 316bf54 | 2016-08-23 17:53:07 +0200 | [diff] [blame] | 1095 | public boolean hasEmergencyCryptKeeperText() { |
| 1096 | return EncryptionHelper.IS_DATA_ENCRYPTED; |
| 1097 | } |
| 1098 | |
| 1099 | public boolean isRadioOn() { |
| 1100 | return !mAirplaneMode; |
| 1101 | } |
| 1102 | |
Jason Monk | 8fcab35 | 2015-06-29 10:57:00 -0400 | [diff] [blame] | 1103 | private class SubListener extends OnSubscriptionsChangedListener { |
Jason Monk | c9f0571 | 2014-12-15 12:24:10 -0500 | [diff] [blame] | 1104 | @Override |
| 1105 | public void onSubscriptionsChanged() { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 1106 | updateMobileControllers(); |
Jason Monk | 8fcab35 | 2015-06-29 10:57:00 -0400 | [diff] [blame] | 1107 | } |
| 1108 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 1109 | |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 1110 | /** |
| 1111 | * Used to register listeners from the BG Looper, this way the PhoneStateListeners that |
| 1112 | * get created will also run on the BG Looper. |
| 1113 | */ |
| 1114 | private final Runnable mRegisterListeners = new Runnable() { |
| 1115 | @Override |
| 1116 | public void run() { |
| 1117 | registerListeners(); |
| 1118 | } |
| 1119 | }; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 1120 | |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 1121 | public static class SubscriptionDefaults { |
| 1122 | public int getDefaultVoiceSubId() { |
Shishir Agrawal | 7ea3e8b | 2016-01-25 13:03:07 -0800 | [diff] [blame] | 1123 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | public int getDefaultDataSubId() { |
Shishir Agrawal | 7ea3e8b | 2016-01-25 13:03:07 -0800 | [diff] [blame] | 1127 | return SubscriptionManager.getDefaultDataSubscriptionId(); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 1128 | } |
Fabian Kozynski | ccde55d | 2019-06-26 10:06:09 -0400 | [diff] [blame] | 1129 | |
| 1130 | public int getActiveDataSubId() { |
| 1131 | return SubscriptionManager.getActiveDataSubscriptionId(); |
| 1132 | } |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 1133 | } |
| 1134 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 1135 | @VisibleForTesting |
| 1136 | static class Config { |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 1137 | static final int NR_CONNECTED_MMWAVE = 1; |
| 1138 | static final int NR_CONNECTED = 2; |
SongFerngWang | 52dada7 | 2019-08-14 16:59:29 +0800 | [diff] [blame] | 1139 | static final int NR_NOT_RESTRICTED_RRC_IDLE = 3; |
| 1140 | static final int NR_NOT_RESTRICTED_RRC_CON = 4; |
| 1141 | static final int NR_RESTRICTED = 5; |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 1142 | |
| 1143 | Map<Integer, MobileIconGroup> nr5GIconMap = new HashMap<>(); |
| 1144 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 1145 | boolean showAtLeast3G = false; |
vagdevi | 3f2b9a5 | 2019-08-09 09:45:14 -0700 | [diff] [blame] | 1146 | boolean show4gFor3g = false; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 1147 | boolean alwaysShowCdmaRssi = false; |
| 1148 | boolean show4gForLte = false; |
Robert Greenwalt | 37d34ba | 2016-07-27 14:54:34 -0700 | [diff] [blame] | 1149 | boolean hideLtePlus = false; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 1150 | boolean hspaDataDistinguishable; |
Jason Monk | 43c14d1 | 2017-06-22 11:20:04 -0400 | [diff] [blame] | 1151 | boolean inflateSignalStrengths = false; |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 1152 | boolean alwaysShowDataRatIcon = false; |
SongFerngWang | 3cbcf75 | 2019-03-21 23:14:20 +0800 | [diff] [blame] | 1153 | public String patternOfCarrierSpecificDataIcon = ""; |
Bill Lin | 767c0db | 2019-08-15 20:42:06 +0800 | [diff] [blame] | 1154 | public long nrIconDisplayGracePeriodMs; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 1155 | |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 1156 | /** |
| 1157 | * Mapping from NR 5G status string to an integer. The NR 5G status string should match |
| 1158 | * those in carrier config. |
| 1159 | */ |
| 1160 | private static final Map<String, Integer> NR_STATUS_STRING_TO_INDEX; |
| 1161 | static { |
SongFerngWang | 52dada7 | 2019-08-14 16:59:29 +0800 | [diff] [blame] | 1162 | NR_STATUS_STRING_TO_INDEX = new HashMap<>(5); |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 1163 | NR_STATUS_STRING_TO_INDEX.put("connected_mmwave", NR_CONNECTED_MMWAVE); |
| 1164 | NR_STATUS_STRING_TO_INDEX.put("connected", NR_CONNECTED); |
SongFerngWang | 52dada7 | 2019-08-14 16:59:29 +0800 | [diff] [blame] | 1165 | NR_STATUS_STRING_TO_INDEX.put("not_restricted_rrc_idle", NR_NOT_RESTRICTED_RRC_IDLE); |
| 1166 | NR_STATUS_STRING_TO_INDEX.put("not_restricted_rrc_con", NR_NOT_RESTRICTED_RRC_CON); |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 1167 | NR_STATUS_STRING_TO_INDEX.put("restricted", NR_RESTRICTED); |
| 1168 | } |
| 1169 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 1170 | static Config readConfig(Context context) { |
| 1171 | Config config = new Config(); |
| 1172 | Resources res = context.getResources(); |
| 1173 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 1174 | config.showAtLeast3G = res.getBoolean(R.bool.config_showMin3G); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 1175 | config.alwaysShowCdmaRssi = |
| 1176 | res.getBoolean(com.android.internal.R.bool.config_alwaysUseCdmaRssi); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 1177 | config.hspaDataDistinguishable = |
| 1178 | res.getBoolean(R.bool.config_hspa_data_distinguishable); |
Antony Sargent | c026de3 | 2019-05-21 16:29:04 -0700 | [diff] [blame] | 1179 | config.inflateSignalStrengths = res.getBoolean( |
| 1180 | com.android.internal.R.bool.config_inflateSignalStrength); |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 1181 | |
| 1182 | CarrierConfigManager configMgr = (CarrierConfigManager) |
| 1183 | context.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Niklas Lindgren | a02964d | 2018-09-21 14:01:57 +0200 | [diff] [blame] | 1184 | // Handle specific carrier config values for the default data SIM |
| 1185 | int defaultDataSubId = SubscriptionManager.from(context) |
| 1186 | .getDefaultDataSubscriptionId(); |
| 1187 | PersistableBundle b = configMgr.getConfigForSubId(defaultDataSubId); |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 1188 | if (b != null) { |
| 1189 | config.alwaysShowDataRatIcon = b.getBoolean( |
| 1190 | CarrierConfigManager.KEY_ALWAYS_SHOW_DATA_RAT_ICON_BOOL); |
Niklas Lindgren | a02964d | 2018-09-21 14:01:57 +0200 | [diff] [blame] | 1191 | config.show4gForLte = b.getBoolean( |
| 1192 | CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL); |
vagdevi | 3f2b9a5 | 2019-08-09 09:45:14 -0700 | [diff] [blame] | 1193 | config.show4gFor3g = b.getBoolean( |
| 1194 | CarrierConfigManager.KEY_SHOW_4G_FOR_3G_DATA_ICON_BOOL); |
Niklas Lindgren | a02964d | 2018-09-21 14:01:57 +0200 | [diff] [blame] | 1195 | config.hideLtePlus = b.getBoolean( |
| 1196 | CarrierConfigManager.KEY_HIDE_LTE_PLUS_DATA_ICON_BOOL); |
SongFerngWang | 3cbcf75 | 2019-03-21 23:14:20 +0800 | [diff] [blame] | 1197 | config.patternOfCarrierSpecificDataIcon = b.getString( |
| 1198 | CarrierConfigManager.KEY_SHOW_CARRIER_DATA_ICON_PATTERN_STRING); |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 1199 | String nr5GIconConfiguration = |
| 1200 | b.getString(CarrierConfigManager.KEY_5G_ICON_CONFIGURATION_STRING); |
| 1201 | if (!TextUtils.isEmpty(nr5GIconConfiguration)) { |
| 1202 | String[] nr5GIconConfigPairs = nr5GIconConfiguration.trim().split(","); |
| 1203 | for (String pair : nr5GIconConfigPairs) { |
| 1204 | add5GIconMapping(pair, config); |
| 1205 | } |
| 1206 | } |
Bill Lin | 767c0db | 2019-08-15 20:42:06 +0800 | [diff] [blame] | 1207 | setDisplayGraceTime( |
| 1208 | b.getInt(CarrierConfigManager.KEY_5G_ICON_DISPLAY_GRACE_PERIOD_SEC_INT), |
| 1209 | config); |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 1210 | } |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 1211 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 1212 | return config; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 1213 | } |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 1214 | |
| 1215 | /** |
| 1216 | * Add a mapping from NR 5G status to the 5G icon. All the icon resources come from |
| 1217 | * {@link TelephonyIcons}. |
| 1218 | * |
| 1219 | * @param keyValuePair the NR 5G status and icon name separated by a colon. |
| 1220 | * @param config container that used to store the parsed configs. |
| 1221 | */ |
| 1222 | @VisibleForTesting |
| 1223 | static void add5GIconMapping(String keyValuePair, Config config) { |
| 1224 | String[] kv = (keyValuePair.trim().toLowerCase()).split(":"); |
| 1225 | |
| 1226 | if (kv.length != 2) { |
| 1227 | if (DEBUG) Log.e(TAG, "Invalid 5G icon configuration, config = " + keyValuePair); |
| 1228 | return; |
| 1229 | } |
| 1230 | |
| 1231 | String key = kv[0], value = kv[1]; |
| 1232 | |
| 1233 | // There is no icon config for the specific 5G status. |
| 1234 | if (value.equals("none")) return; |
| 1235 | |
| 1236 | if (NR_STATUS_STRING_TO_INDEX.containsKey(key) |
| 1237 | && TelephonyIcons.ICON_NAME_TO_ICON.containsKey(value)) { |
| 1238 | config.nr5GIconMap.put( |
| 1239 | NR_STATUS_STRING_TO_INDEX.get(key), |
| 1240 | TelephonyIcons.ICON_NAME_TO_ICON.get(value)); |
| 1241 | } |
| 1242 | } |
Bill Lin | 767c0db | 2019-08-15 20:42:06 +0800 | [diff] [blame] | 1243 | |
| 1244 | /** |
| 1245 | * Set display gracefully period time(MS) depend on carrierConfig KEY |
| 1246 | * KEY_5G_ICON_DISPLAY_GRACE_PERIOD_SEC_INT, and this function will convert to ms. |
| 1247 | * {@link CarrierConfigManager}. |
| 1248 | * |
| 1249 | * @param time showing 5G icon gracefully in the period of the time(SECOND) |
| 1250 | * @param config container that used to store the parsed configs. |
| 1251 | */ |
| 1252 | @VisibleForTesting |
| 1253 | static void setDisplayGraceTime(int time, Config config) { |
| 1254 | config.nrIconDisplayGracePeriodMs = time * DateUtils.SECOND_IN_MILLIS; |
| 1255 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 1256 | } |
| 1257 | } |