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