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