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