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 | |
| 19 | import android.content.BroadcastReceiver; |
| 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.content.IntentFilter; |
| 23 | import android.content.res.Resources; |
| 24 | import android.net.ConnectivityManager; |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 25 | import android.net.NetworkCapabilities; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 26 | import android.net.wifi.WifiManager; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 27 | import android.os.AsyncTask; |
| 28 | import android.os.Bundle; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 29 | import android.os.Handler; |
Jason Monk | 30d8004 | 2015-05-08 16:54:18 -0400 | [diff] [blame] | 30 | import android.os.Looper; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 31 | import android.provider.Settings; |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 32 | import android.telephony.ServiceState; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 33 | import android.telephony.SubscriptionInfo; |
| 34 | import android.telephony.SubscriptionManager; |
| 35 | import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 36 | import android.telephony.TelephonyManager; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 37 | import android.text.TextUtils; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 38 | import android.util.Log; |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 39 | import android.util.MathUtils; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 40 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 41 | import com.android.internal.annotations.VisibleForTesting; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 42 | import com.android.internal.telephony.PhoneConstants; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 43 | import com.android.internal.telephony.TelephonyIntents; |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 44 | import com.android.settingslib.net.DataUsageController; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 45 | import com.android.systemui.DemoMode; |
| 46 | import com.android.systemui.R; |
| 47 | |
| 48 | import java.io.FileDescriptor; |
| 49 | import java.io.PrintWriter; |
| 50 | import java.util.ArrayList; |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 51 | import java.util.BitSet; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 52 | import java.util.Collections; |
| 53 | import java.util.Comparator; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 54 | import java.util.HashMap; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 55 | import java.util.List; |
| 56 | import java.util.Locale; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 57 | import java.util.Map; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 58 | |
Jason Monk | 4cf95ae | 2015-11-16 15:59:53 -0500 | [diff] [blame] | 59 | import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED; |
| 60 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 61 | /** Platform implementation of the network controller. **/ |
| 62 | public class NetworkControllerImpl extends BroadcastReceiver |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 63 | implements NetworkController, DemoMode, DataUsageController.NetworkNameProvider { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 64 | // debug |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 65 | static final String TAG = "NetworkController"; |
| 66 | static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
| 67 | // additional diagnostics, but not logspew |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 68 | static final boolean CHATTY = Log.isLoggable(TAG + "Chat", Log.DEBUG); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 69 | |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 70 | private static final int EMERGENCY_NO_CONTROLLERS = 0; |
| 71 | private static final int EMERGENCY_FIRST_CONTROLLER = 100; |
| 72 | private static final int EMERGENCY_VOICE_CONTROLLER = 200; |
| 73 | private static final int EMERGENCY_NO_SUB = 300; |
| 74 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 75 | private final Context mContext; |
| 76 | private final TelephonyManager mPhone; |
| 77 | private final WifiManager mWifiManager; |
| 78 | private final ConnectivityManager mConnectivityManager; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 79 | private final SubscriptionManager mSubscriptionManager; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 80 | private final boolean mHasMobileDataFeature; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 81 | private final SubscriptionDefaults mSubDefaults; |
Jason Monk | 9a4ce13 | 2016-01-21 15:27:17 -0500 | [diff] [blame] | 82 | private final DataSaverController mDataSaverController; |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 83 | private Config mConfig; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 84 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 85 | // Subcontrollers. |
| 86 | @VisibleForTesting |
| 87 | final WifiSignalController mWifiSignalController; |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 88 | |
| 89 | @VisibleForTesting |
| 90 | final EthernetSignalController mEthernetSignalController; |
| 91 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 92 | @VisibleForTesting |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 93 | final Map<Integer, MobileSignalController> mMobileSignalControllers = |
| 94 | new HashMap<Integer, MobileSignalController>(); |
| 95 | // When no SIMs are around at setup, and one is added later, it seems to default to the first |
| 96 | // SIM for most actions. This may be null if there aren't any SIMs around. |
| 97 | private MobileSignalController mDefaultSignalController; |
Jason Monk | 0e2400f | 2014-11-21 11:08:55 -0500 | [diff] [blame] | 98 | private final AccessPointControllerImpl mAccessPoints; |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 99 | private final DataUsageController mDataUsageController; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 100 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 101 | private boolean mInetCondition; // Used for Logging and demo. |
Lorenzo Colitti | 23dd176 | 2014-09-10 22:58:54 +0900 | [diff] [blame] | 102 | |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 103 | // BitSets indicating which network transport types (e.g., TRANSPORT_WIFI, TRANSPORT_MOBILE) are |
| 104 | // connected and validated, respectively. |
| 105 | private final BitSet mConnectedTransports = new BitSet(); |
| 106 | private final BitSet mValidatedTransports = new BitSet(); |
| 107 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 108 | // States that don't belong to a subcontroller. |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 109 | private boolean mAirplaneMode = false; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 110 | private boolean mHasNoSims; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 111 | private Locale mLocale = null; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 112 | // This list holds our ordering. |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 113 | private List<SubscriptionInfo> mCurrentSubscriptions = new ArrayList<>(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 114 | |
Jason Monk | c014dec | 2014-12-12 11:49:55 -0500 | [diff] [blame] | 115 | @VisibleForTesting |
| 116 | boolean mListening; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 117 | |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 118 | // The current user ID. |
| 119 | private int mCurrentUserId; |
| 120 | |
Jason Monk | 8fcab35 | 2015-06-29 10:57:00 -0400 | [diff] [blame] | 121 | private OnSubscriptionsChangedListener mSubscriptionListener; |
| 122 | |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 123 | // Handler that all broadcasts are received on. |
| 124 | private final Handler mReceiverHandler; |
| 125 | // Handler that all callbacks are made on. |
| 126 | private final CallbackHandler mCallbackHandler; |
| 127 | |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 128 | private int mEmergencySource; |
| 129 | private boolean mIsEmergency; |
| 130 | |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 131 | @VisibleForTesting |
| 132 | ServiceState mLastServiceState; |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 133 | private boolean mUserSetup; |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 134 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 135 | /** |
| 136 | * Construct this controller object and register for updates. |
| 137 | */ |
Jason Monk | 30d8004 | 2015-05-08 16:54:18 -0400 | [diff] [blame] | 138 | public NetworkControllerImpl(Context context, Looper bgLooper) { |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 139 | this(context, (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE), |
| 140 | (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE), |
Jason Monk | 29f7a7b | 2014-11-17 14:40:56 -0500 | [diff] [blame] | 141 | (WifiManager) context.getSystemService(Context.WIFI_SERVICE), |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 142 | SubscriptionManager.from(context), Config.readConfig(context), bgLooper, |
| 143 | new CallbackHandler(), |
Jason Monk | 30d8004 | 2015-05-08 16:54:18 -0400 | [diff] [blame] | 144 | new AccessPointControllerImpl(context, bgLooper), |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 145 | new DataUsageController(context), |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 146 | new SubscriptionDefaults()); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 147 | mReceiverHandler.post(mRegisterListeners); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | @VisibleForTesting |
| 151 | NetworkControllerImpl(Context context, ConnectivityManager connectivityManager, |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 152 | TelephonyManager telephonyManager, WifiManager wifiManager, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 153 | SubscriptionManager subManager, Config config, Looper bgLooper, |
| 154 | CallbackHandler callbackHandler, |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 155 | AccessPointControllerImpl accessPointController, |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 156 | DataUsageController dataUsageController, |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 157 | SubscriptionDefaults defaultsHandler) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 158 | mContext = context; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 159 | mConfig = config; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 160 | mReceiverHandler = new Handler(bgLooper); |
| 161 | mCallbackHandler = callbackHandler; |
Jason Monk | 9abca5e | 2016-11-11 16:18:14 -0500 | [diff] [blame] | 162 | mDataSaverController = new DataSaverControllerImpl(context); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 163 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 164 | mSubscriptionManager = subManager; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 165 | mSubDefaults = defaultsHandler; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 166 | mConnectivityManager = connectivityManager; |
| 167 | mHasMobileDataFeature = |
| 168 | mConnectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 169 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 170 | // telephony |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 171 | mPhone = telephonyManager; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 172 | |
| 173 | // wifi |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 174 | mWifiManager = wifiManager; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 175 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 176 | mLocale = mContext.getResources().getConfiguration().locale; |
Jason Monk | 29f7a7b | 2014-11-17 14:40:56 -0500 | [diff] [blame] | 177 | mAccessPoints = accessPointController; |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 178 | mDataUsageController = dataUsageController; |
| 179 | mDataUsageController.setNetworkController(this); |
| 180 | // TODO: Find a way to move this into DataUsageController. |
| 181 | mDataUsageController.setCallback(new DataUsageController.Callback() { |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 182 | @Override |
| 183 | public void onMobileDataEnabled(boolean enabled) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 184 | mCallbackHandler.setMobileDataEnabled(enabled); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 185 | } |
| 186 | }); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 187 | mWifiSignalController = new WifiSignalController(mContext, mHasMobileDataFeature, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 188 | mCallbackHandler, this); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 189 | |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 190 | mEthernetSignalController = new EthernetSignalController(mContext, mCallbackHandler, this); |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 191 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 192 | // 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] | 193 | updateAirplaneMode(true /* force callback */); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 194 | } |
| 195 | |
Jason Monk | 9a4ce13 | 2016-01-21 15:27:17 -0500 | [diff] [blame] | 196 | public DataSaverController getDataSaverController() { |
| 197 | return mDataSaverController; |
| 198 | } |
| 199 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 200 | private void registerListeners() { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 201 | for (MobileSignalController mobileSignalController : mMobileSignalControllers.values()) { |
| 202 | mobileSignalController.registerListener(); |
| 203 | } |
Jason Monk | 8fcab35 | 2015-06-29 10:57:00 -0400 | [diff] [blame] | 204 | if (mSubscriptionListener == null) { |
| 205 | mSubscriptionListener = new SubListener(); |
| 206 | } |
Wink Saville | 071743f | 2015-01-12 17:11:04 -0800 | [diff] [blame] | 207 | mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 208 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 209 | // broadcasts |
| 210 | IntentFilter filter = new IntentFilter(); |
| 211 | filter.addAction(WifiManager.RSSI_CHANGED_ACTION); |
| 212 | filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); |
| 213 | filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); |
| 214 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 215 | filter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); |
| 216 | filter.addAction(TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED); |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 217 | filter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 218 | filter.addAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION); |
Erik Kline | 32830cc | 2015-04-21 13:09:15 +0900 | [diff] [blame] | 219 | filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 220 | filter.addAction(ConnectivityManager.INET_CONDITION_ACTION); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 221 | filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 222 | mContext.registerReceiver(this, filter, null, mReceiverHandler); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 223 | mListening = true; |
| 224 | |
| 225 | updateMobileControllers(); |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 226 | } |
| 227 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 228 | private void unregisterListeners() { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 229 | mListening = false; |
| 230 | for (MobileSignalController mobileSignalController : mMobileSignalControllers.values()) { |
| 231 | mobileSignalController.unregisterListener(); |
| 232 | } |
Wink Saville | 071743f | 2015-01-12 17:11:04 -0800 | [diff] [blame] | 233 | mSubscriptionManager.removeOnSubscriptionsChangedListener(mSubscriptionListener); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 234 | mContext.unregisterReceiver(this); |
Jason Monk | 5d32507 | 2014-10-27 11:38:47 -0400 | [diff] [blame] | 235 | } |
| 236 | |
Jason Monk | 0e2400f | 2014-11-21 11:08:55 -0500 | [diff] [blame] | 237 | public int getConnectedWifiLevel() { |
| 238 | return mWifiSignalController.getState().level; |
| 239 | } |
| 240 | |
Jason Monk | 5d32507 | 2014-10-27 11:38:47 -0400 | [diff] [blame] | 241 | @Override |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 242 | public AccessPointController getAccessPointController() { |
| 243 | return mAccessPoints; |
| 244 | } |
| 245 | |
| 246 | @Override |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 247 | public DataUsageController getMobileDataController() { |
| 248 | return mDataUsageController; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | public void addEmergencyListener(EmergencyListener listener) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 252 | mCallbackHandler.setListening(listener, true); |
| 253 | mCallbackHandler.setEmergencyCallsOnly(isEmergencyOnly()); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 254 | } |
| 255 | |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 256 | public void removeEmergencyListener(EmergencyListener listener) { |
| 257 | mCallbackHandler.setListening(listener, false); |
| 258 | } |
| 259 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 260 | public boolean hasMobileDataFeature() { |
| 261 | return mHasMobileDataFeature; |
| 262 | } |
| 263 | |
| 264 | public boolean hasVoiceCallingFeature() { |
| 265 | return mPhone.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE; |
| 266 | } |
| 267 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 268 | private MobileSignalController getDataController() { |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 269 | int dataSubId = mSubDefaults.getDefaultDataSubId(); |
Wink Saville | a54bf65 | 2014-12-11 13:37:50 -0800 | [diff] [blame] | 270 | if (!SubscriptionManager.isValidSubscriptionId(dataSubId)) { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 271 | if (DEBUG) Log.e(TAG, "No data sim selected"); |
| 272 | return mDefaultSignalController; |
| 273 | } |
| 274 | if (mMobileSignalControllers.containsKey(dataSubId)) { |
| 275 | return mMobileSignalControllers.get(dataSubId); |
| 276 | } |
Dan Sandler | c846632 | 2014-12-08 15:42:52 -0500 | [diff] [blame] | 277 | if (DEBUG) Log.e(TAG, "Cannot find controller for data sub: " + dataSubId); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 278 | return mDefaultSignalController; |
| 279 | } |
| 280 | |
Pavel Zhamaitsiak | 5504d39 | 2015-03-27 09:24:47 -0700 | [diff] [blame] | 281 | public String getMobileDataNetworkName() { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 282 | MobileSignalController controller = getDataController(); |
Pavel Zhamaitsiak | 5504d39 | 2015-03-27 09:24:47 -0700 | [diff] [blame] | 283 | return controller != null ? controller.getState().networkNameData : ""; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 284 | } |
| 285 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 286 | public boolean isEmergencyOnly() { |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 287 | if (mMobileSignalControllers.size() == 0) { |
| 288 | // When there are no active subscriptions, determine emengency state from last |
| 289 | // broadcast. |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 290 | mEmergencySource = EMERGENCY_NO_CONTROLLERS; |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 291 | return mLastServiceState != null && mLastServiceState.isEmergencyOnly(); |
| 292 | } |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 293 | int voiceSubId = mSubDefaults.getDefaultVoiceSubId(); |
Wink Saville | a54bf65 | 2014-12-11 13:37:50 -0800 | [diff] [blame] | 294 | if (!SubscriptionManager.isValidSubscriptionId(voiceSubId)) { |
| 295 | for (MobileSignalController mobileSignalController : |
| 296 | mMobileSignalControllers.values()) { |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 297 | if (!mobileSignalController.getState().isEmergency) { |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 298 | mEmergencySource = EMERGENCY_FIRST_CONTROLLER |
| 299 | + mobileSignalController.mSubscriptionInfo.getSubscriptionId(); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 300 | if (DEBUG) Log.d(TAG, "Found emergency " + mobileSignalController.mTag); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 301 | return false; |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | if (mMobileSignalControllers.containsKey(voiceSubId)) { |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 306 | mEmergencySource = EMERGENCY_VOICE_CONTROLLER + voiceSubId; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 307 | if (DEBUG) Log.d(TAG, "Getting emergency from " + voiceSubId); |
| 308 | return mMobileSignalControllers.get(voiceSubId).getState().isEmergency; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 309 | } |
Dan Sandler | c846632 | 2014-12-08 15:42:52 -0500 | [diff] [blame] | 310 | if (DEBUG) Log.e(TAG, "Cannot find controller for voice sub: " + voiceSubId); |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 311 | mEmergencySource = EMERGENCY_NO_SUB + voiceSubId; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 312 | // Something is wrong, better assume we can't make calls... |
| 313 | return true; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 314 | } |
| 315 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 316 | /** |
| 317 | * Emergency status may have changed (triggered by MobileSignalController), |
| 318 | * so we should recheck and send out the state to listeners. |
| 319 | */ |
| 320 | void recalculateEmergency() { |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 321 | mIsEmergency = isEmergencyOnly(); |
| 322 | mCallbackHandler.setEmergencyCallsOnly(mIsEmergency); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 323 | } |
| 324 | |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 325 | public void addCallback(SignalCallback cb) { |
Jason Monk | e06b065 | 2016-03-02 16:35:27 -0500 | [diff] [blame] | 326 | cb.setSubs(mCurrentSubscriptions); |
| 327 | cb.setIsAirplaneMode(new IconState(mAirplaneMode, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 328 | TelephonyIcons.FLIGHT_MODE_ICON, R.string.accessibility_airplane_mode, mContext)); |
Jason Monk | e06b065 | 2016-03-02 16:35:27 -0500 | [diff] [blame] | 329 | cb.setNoSims(mHasNoSims); |
| 330 | mWifiSignalController.notifyListeners(cb); |
| 331 | mEthernetSignalController.notifyListeners(cb); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 332 | for (MobileSignalController mobileSignalController : mMobileSignalControllers.values()) { |
Jason Monk | e06b065 | 2016-03-02 16:35:27 -0500 | [diff] [blame] | 333 | mobileSignalController.notifyListeners(cb); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 334 | } |
Jason Monk | e06b065 | 2016-03-02 16:35:27 -0500 | [diff] [blame] | 335 | mCallbackHandler.setListening(cb, true); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 336 | } |
| 337 | |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 338 | @Override |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 339 | public void removeCallback(SignalCallback cb) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 340 | mCallbackHandler.setListening(cb, false); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | @Override |
| 344 | public void setWifiEnabled(final boolean enabled) { |
| 345 | new AsyncTask<Void, Void, Void>() { |
| 346 | @Override |
| 347 | protected Void doInBackground(Void... args) { |
| 348 | // Disable tethering if enabling Wifi |
| 349 | final int wifiApState = mWifiManager.getWifiApState(); |
| 350 | if (enabled && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) || |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 351 | (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED))) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 352 | mWifiManager.setWifiApEnabled(null, false); |
| 353 | } |
| 354 | |
| 355 | mWifiManager.setWifiEnabled(enabled); |
| 356 | return null; |
| 357 | } |
| 358 | }.execute(); |
| 359 | } |
| 360 | |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 361 | @Override |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 362 | public void onUserSwitched(int newUserId) { |
| 363 | mCurrentUserId = newUserId; |
| 364 | mAccessPoints.onUserSwitched(newUserId); |
| 365 | updateConnectivity(); |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 369 | public void onReceive(Context context, Intent intent) { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 370 | if (CHATTY) { |
| 371 | Log.d(TAG, "onReceive: intent=" + intent); |
| 372 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 373 | final String action = intent.getAction(); |
Erik Kline | 32830cc | 2015-04-21 13:09:15 +0900 | [diff] [blame] | 374 | if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION) || |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 375 | action.equals(ConnectivityManager.INET_CONDITION_ACTION)) { |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 376 | updateConnectivity(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 377 | } else if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) { |
| 378 | refreshLocale(); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 379 | updateAirplaneMode(false); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 380 | } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED)) { |
| 381 | // We are using different subs now, we might be able to make calls. |
| 382 | recalculateEmergency(); |
| 383 | } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) { |
| 384 | // Notify every MobileSignalController so they can know whether they are the |
| 385 | // data sim or not. |
| 386 | for (MobileSignalController controller : mMobileSignalControllers.values()) { |
| 387 | controller.handleBroadcast(intent); |
| 388 | } |
| 389 | } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { |
| 390 | // Might have different subscriptions now. |
| 391 | updateMobileControllers(); |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 392 | } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) { |
| 393 | mLastServiceState = ServiceState.newFromBundle(intent.getExtras()); |
| 394 | if (mMobileSignalControllers.size() == 0) { |
| 395 | // If none of the subscriptions are active, we might need to recalculate |
| 396 | // emergency state. |
| 397 | recalculateEmergency(); |
| 398 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 399 | } else { |
| 400 | int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, |
| 401 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
Wink Saville | a54bf65 | 2014-12-11 13:37:50 -0800 | [diff] [blame] | 402 | if (SubscriptionManager.isValidSubscriptionId(subId)) { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 403 | if (mMobileSignalControllers.containsKey(subId)) { |
| 404 | mMobileSignalControllers.get(subId).handleBroadcast(intent); |
| 405 | } else { |
| 406 | // Can't find this subscription... We must be out of date. |
| 407 | updateMobileControllers(); |
| 408 | } |
| 409 | } else { |
| 410 | // No sub id, must be for the wifi. |
| 411 | mWifiSignalController.handleBroadcast(intent); |
| 412 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 413 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 414 | } |
| 415 | |
Jason Monk | 1c040db | 2015-07-20 09:45:54 -0400 | [diff] [blame] | 416 | public void onConfigurationChanged() { |
Sungmin Choi | 6be4f6b | 2015-07-07 13:06:59 +0900 | [diff] [blame] | 417 | mConfig = Config.readConfig(mContext); |
Jason Monk | 1c040db | 2015-07-20 09:45:54 -0400 | [diff] [blame] | 418 | mReceiverHandler.post(new Runnable() { |
| 419 | @Override |
| 420 | public void run() { |
| 421 | handleConfigurationChanged(); |
| 422 | } |
| 423 | }); |
| 424 | } |
| 425 | |
| 426 | @VisibleForTesting |
| 427 | void handleConfigurationChanged() { |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 428 | for (MobileSignalController mobileSignalController : mMobileSignalControllers.values()) { |
| 429 | mobileSignalController.setConfiguration(mConfig); |
| 430 | } |
| 431 | refreshLocale(); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 432 | } |
| 433 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 434 | private void updateMobileControllers() { |
| 435 | if (!mListening) { |
| 436 | return; |
| 437 | } |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 438 | doUpdateMobileControllers(); |
| 439 | } |
| 440 | |
| 441 | @VisibleForTesting |
| 442 | void doUpdateMobileControllers() { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 443 | List<SubscriptionInfo> subscriptions = mSubscriptionManager.getActiveSubscriptionInfoList(); |
Jason Monk | c9f0571 | 2014-12-15 12:24:10 -0500 | [diff] [blame] | 444 | if (subscriptions == null) { |
| 445 | subscriptions = Collections.emptyList(); |
| 446 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 447 | // If there have been no relevant changes to any of the subscriptions, we can leave as is. |
| 448 | if (hasCorrectMobileControllers(subscriptions)) { |
| 449 | // Even if the controllers are correct, make sure we have the right no sims state. |
| 450 | // Such as on boot, don't need any controllers, because there are no sims, |
| 451 | // but we still need to update the no sim state. |
| 452 | updateNoSims(); |
| 453 | return; |
| 454 | } |
| 455 | setCurrentSubscriptions(subscriptions); |
| 456 | updateNoSims(); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 457 | recalculateEmergency(); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 458 | } |
| 459 | |
Jason Monk | 21d05a0 | 2014-12-02 12:46:58 -0500 | [diff] [blame] | 460 | @VisibleForTesting |
| 461 | protected void updateNoSims() { |
| 462 | boolean hasNoSims = mHasMobileDataFeature && mMobileSignalControllers.size() == 0; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 463 | if (hasNoSims != mHasNoSims) { |
| 464 | mHasNoSims = hasNoSims; |
Jason Monk | 259e06f | 2015-06-18 14:07:26 -0400 | [diff] [blame] | 465 | mCallbackHandler.setNoSims(mHasNoSims); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | |
| 469 | @VisibleForTesting |
| 470 | void setCurrentSubscriptions(List<SubscriptionInfo> subscriptions) { |
| 471 | Collections.sort(subscriptions, new Comparator<SubscriptionInfo>() { |
| 472 | @Override |
| 473 | public int compare(SubscriptionInfo lhs, SubscriptionInfo rhs) { |
| 474 | return lhs.getSimSlotIndex() == rhs.getSimSlotIndex() |
| 475 | ? lhs.getSubscriptionId() - rhs.getSubscriptionId() |
| 476 | : lhs.getSimSlotIndex() - rhs.getSimSlotIndex(); |
| 477 | } |
| 478 | }); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 479 | mCurrentSubscriptions = subscriptions; |
| 480 | |
| 481 | HashMap<Integer, MobileSignalController> cachedControllers = |
| 482 | new HashMap<Integer, MobileSignalController>(mMobileSignalControllers); |
| 483 | mMobileSignalControllers.clear(); |
| 484 | final int num = subscriptions.size(); |
| 485 | for (int i = 0; i < num; i++) { |
| 486 | int subId = subscriptions.get(i).getSubscriptionId(); |
| 487 | // If we have a copy of this controller already reuse it, otherwise make a new one. |
| 488 | if (cachedControllers.containsKey(subId)) { |
Jason Monk | c014dec | 2014-12-12 11:49:55 -0500 | [diff] [blame] | 489 | mMobileSignalControllers.put(subId, cachedControllers.remove(subId)); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 490 | } else { |
| 491 | MobileSignalController controller = new MobileSignalController(mContext, mConfig, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 492 | mHasMobileDataFeature, mPhone, mCallbackHandler, |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 493 | this, subscriptions.get(i), mSubDefaults, mReceiverHandler.getLooper()); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 494 | controller.setUserSetupComplete(mUserSetup); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 495 | mMobileSignalControllers.put(subId, controller); |
| 496 | if (subscriptions.get(i).getSimSlotIndex() == 0) { |
| 497 | mDefaultSignalController = controller; |
| 498 | } |
| 499 | if (mListening) { |
| 500 | controller.registerListener(); |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | if (mListening) { |
| 505 | for (Integer key : cachedControllers.keySet()) { |
| 506 | if (cachedControllers.get(key) == mDefaultSignalController) { |
| 507 | mDefaultSignalController = null; |
| 508 | } |
| 509 | cachedControllers.get(key).unregisterListener(); |
| 510 | } |
| 511 | } |
Jason Monk | 8fcab35 | 2015-06-29 10:57:00 -0400 | [diff] [blame] | 512 | mCallbackHandler.setSubs(subscriptions); |
| 513 | notifyAllListeners(); |
| 514 | |
Jason Monk | 25d8a48 | 2014-12-09 12:27:24 -0500 | [diff] [blame] | 515 | // There may be new MobileSignalControllers around, make sure they get the current |
| 516 | // inet condition and airplane mode. |
| 517 | pushConnectivityToSignals(); |
| 518 | updateAirplaneMode(true /* force */); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 519 | } |
| 520 | |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 521 | public void setUserSetupComplete(final boolean userSetup) { |
| 522 | mReceiverHandler.post(new Runnable() { |
| 523 | @Override |
| 524 | public void run() { |
| 525 | handleSetUserSetupComplete(userSetup); |
| 526 | } |
| 527 | }); |
| 528 | } |
| 529 | |
| 530 | @VisibleForTesting |
| 531 | void handleSetUserSetupComplete(boolean userSetup) { |
| 532 | mUserSetup = userSetup; |
| 533 | for (MobileSignalController controller : mMobileSignalControllers.values()) { |
| 534 | controller.setUserSetupComplete(mUserSetup); |
| 535 | } |
| 536 | } |
| 537 | |
Jason Monk | c014dec | 2014-12-12 11:49:55 -0500 | [diff] [blame] | 538 | @VisibleForTesting |
| 539 | boolean hasCorrectMobileControllers(List<SubscriptionInfo> allSubscriptions) { |
Jason Monk | c9f0571 | 2014-12-15 12:24:10 -0500 | [diff] [blame] | 540 | if (allSubscriptions.size() != mMobileSignalControllers.size()) { |
| 541 | return false; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 542 | } |
| 543 | for (SubscriptionInfo info : allSubscriptions) { |
| 544 | if (!mMobileSignalControllers.containsKey(info.getSubscriptionId())) { |
| 545 | return false; |
| 546 | } |
| 547 | } |
| 548 | return true; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 549 | } |
| 550 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 551 | private void updateAirplaneMode(boolean force) { |
| 552 | boolean airplaneMode = (Settings.Global.getInt(mContext.getContentResolver(), |
| 553 | Settings.Global.AIRPLANE_MODE_ON, 0) == 1); |
| 554 | if (airplaneMode != mAirplaneMode || force) { |
| 555 | mAirplaneMode = airplaneMode; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 556 | for (MobileSignalController mobileSignalController : mMobileSignalControllers.values()) { |
| 557 | mobileSignalController.setAirplaneMode(mAirplaneMode); |
| 558 | } |
| 559 | notifyListeners(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 560 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | private void refreshLocale() { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 564 | Locale current = mContext.getResources().getConfiguration().locale; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 565 | if (!current.equals(mLocale)) { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 566 | mLocale = current; |
| 567 | notifyAllListeners(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 571 | /** |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 572 | * Forces update of all callbacks on both SignalClusters and |
| 573 | * NetworkSignalChangedCallbacks. |
| 574 | */ |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 575 | private void notifyAllListeners() { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 576 | notifyListeners(); |
| 577 | for (MobileSignalController mobileSignalController : mMobileSignalControllers.values()) { |
| 578 | mobileSignalController.notifyListeners(); |
| 579 | } |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 580 | mWifiSignalController.notifyListeners(); |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 581 | mEthernetSignalController.notifyListeners(); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 582 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 583 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 584 | /** |
| 585 | * Notifies listeners of changes in state of to the NetworkController, but |
| 586 | * does not notify for any info on SignalControllers, for that call |
| 587 | * notifyAllListeners. |
| 588 | */ |
| 589 | private void notifyListeners() { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 590 | mCallbackHandler.setIsAirplaneMode(new IconState(mAirplaneMode, |
| 591 | TelephonyIcons.FLIGHT_MODE_ICON, R.string.accessibility_airplane_mode, mContext)); |
| 592 | mCallbackHandler.setNoSims(mHasNoSims); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 593 | } |
| 594 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 595 | /** |
| 596 | * Update the Inet conditions and what network we are connected to. |
| 597 | */ |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 598 | private void updateConnectivity() { |
| 599 | mConnectedTransports.clear(); |
| 600 | mValidatedTransports.clear(); |
| 601 | for (NetworkCapabilities nc : |
| 602 | mConnectivityManager.getDefaultNetworkCapabilitiesForUser(mCurrentUserId)) { |
| 603 | for (int transportType : nc.getTransportTypes()) { |
| 604 | mConnectedTransports.set(transportType); |
| 605 | if (nc.hasCapability(NET_CAPABILITY_VALIDATED)) { |
| 606 | mValidatedTransports.set(transportType); |
| 607 | } |
| 608 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 609 | } |
| 610 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 611 | if (CHATTY) { |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 612 | Log.d(TAG, "updateConnectivity: mConnectedTransports=" + mConnectedTransports); |
| 613 | Log.d(TAG, "updateConnectivity: mValidatedTransports=" + mValidatedTransports); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 614 | } |
| 615 | |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 616 | mInetCondition = !mValidatedTransports.isEmpty(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 617 | |
Jason Monk | 25d8a48 | 2014-12-09 12:27:24 -0500 | [diff] [blame] | 618 | pushConnectivityToSignals(); |
| 619 | } |
| 620 | |
| 621 | /** |
| 622 | * Pushes the current connectivity state to all SignalControllers. |
| 623 | */ |
| 624 | private void pushConnectivityToSignals() { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 625 | // We want to update all the icons, all at once, for any condition change |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 626 | for (MobileSignalController mobileSignalController : mMobileSignalControllers.values()) { |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 627 | mobileSignalController.updateConnectivity(mConnectedTransports, mValidatedTransports); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 628 | } |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 629 | mWifiSignalController.updateConnectivity(mConnectedTransports, mValidatedTransports); |
| 630 | mEthernetSignalController.updateConnectivity(mConnectedTransports, mValidatedTransports); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 631 | } |
| 632 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 633 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 634 | pw.println("NetworkController state:"); |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 635 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 636 | pw.println(" - telephony ------"); |
| 637 | pw.print(" hasVoiceCallingFeature()="); |
| 638 | pw.println(hasVoiceCallingFeature()); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 639 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 640 | pw.println(" - connectivity ------"); |
Lorenzo Colitti | 403aa26 | 2014-11-28 11:21:30 +0900 | [diff] [blame] | 641 | pw.print(" mConnectedTransports="); |
| 642 | pw.println(mConnectedTransports); |
| 643 | pw.print(" mValidatedTransports="); |
| 644 | pw.println(mValidatedTransports); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 645 | pw.print(" mInetCondition="); |
| 646 | pw.println(mInetCondition); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 647 | pw.print(" mAirplaneMode="); |
| 648 | pw.println(mAirplaneMode); |
| 649 | pw.print(" mLocale="); |
| 650 | pw.println(mLocale); |
Jason Monk | b0808aa | 2015-07-22 16:34:36 -0400 | [diff] [blame] | 651 | pw.print(" mLastServiceState="); |
| 652 | pw.println(mLastServiceState); |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 653 | pw.print(" mIsEmergency="); |
| 654 | pw.println(mIsEmergency); |
| 655 | pw.print(" mEmergencySource="); |
| 656 | pw.println(emergencyToString(mEmergencySource)); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 657 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 658 | for (MobileSignalController mobileSignalController : mMobileSignalControllers.values()) { |
| 659 | mobileSignalController.dump(pw); |
| 660 | } |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 661 | mWifiSignalController.dump(pw); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 662 | |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 663 | mEthernetSignalController.dump(pw); |
| 664 | |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 665 | mAccessPoints.dump(pw); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 666 | } |
| 667 | |
Jason Monk | 66845a3 | 2015-08-03 11:09:41 -0400 | [diff] [blame] | 668 | private static final String emergencyToString(int emergencySource) { |
| 669 | if (emergencySource > EMERGENCY_NO_SUB) { |
| 670 | return "NO_SUB(" + (emergencySource - EMERGENCY_NO_SUB) + ")"; |
| 671 | } else if (emergencySource > EMERGENCY_VOICE_CONTROLLER) { |
| 672 | return "VOICE_CONTROLLER(" + (emergencySource - EMERGENCY_VOICE_CONTROLLER) + ")"; |
| 673 | } else if (emergencySource > EMERGENCY_FIRST_CONTROLLER) { |
| 674 | return "FIRST_CONTROLLER(" + (emergencySource - EMERGENCY_FIRST_CONTROLLER) + ")"; |
| 675 | } else if (emergencySource == EMERGENCY_NO_CONTROLLERS) { |
| 676 | return "NO_CONTROLLERS"; |
| 677 | } |
| 678 | return "UNKNOWN_SOURCE"; |
| 679 | } |
| 680 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 681 | private boolean mDemoMode; |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 682 | private boolean mDemoInetCondition; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 683 | private WifiSignalController.WifiState mDemoWifiState; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 684 | |
| 685 | @Override |
| 686 | public void dispatchDemoCommand(String command, Bundle args) { |
| 687 | if (!mDemoMode && command.equals(COMMAND_ENTER)) { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 688 | if (DEBUG) Log.d(TAG, "Entering demo mode"); |
| 689 | unregisterListeners(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 690 | mDemoMode = true; |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 691 | mDemoInetCondition = mInetCondition; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 692 | mDemoWifiState = mWifiSignalController.getState(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 693 | } else if (mDemoMode && command.equals(COMMAND_EXIT)) { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 694 | if (DEBUG) Log.d(TAG, "Exiting demo mode"); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 695 | mDemoMode = false; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 696 | // Update what MobileSignalControllers, because they may change |
| 697 | // to set the number of sim slots. |
| 698 | updateMobileControllers(); |
| 699 | for (MobileSignalController controller : mMobileSignalControllers.values()) { |
| 700 | controller.resetLastState(); |
| 701 | } |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 702 | mWifiSignalController.resetLastState(); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 703 | mReceiverHandler.post(mRegisterListeners); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 704 | notifyAllListeners(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 705 | } else if (mDemoMode && command.equals(COMMAND_NETWORK)) { |
| 706 | String airplane = args.getString("airplane"); |
| 707 | if (airplane != null) { |
| 708 | boolean show = airplane.equals("show"); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 709 | mCallbackHandler.setIsAirplaneMode(new IconState(show, |
| 710 | TelephonyIcons.FLIGHT_MODE_ICON, R.string.accessibility_airplane_mode, |
| 711 | mContext)); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 712 | } |
| 713 | String fully = args.getString("fully"); |
| 714 | if (fully != null) { |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 715 | mDemoInetCondition = Boolean.parseBoolean(fully); |
| 716 | BitSet connected = new BitSet(); |
| 717 | |
| 718 | if (mDemoInetCondition) { |
| 719 | connected.set(mWifiSignalController.mTransportType); |
| 720 | } |
| 721 | mWifiSignalController.updateConnectivity(connected, connected); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 722 | for (MobileSignalController controller : mMobileSignalControllers.values()) { |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 723 | if (mDemoInetCondition) { |
| 724 | connected.set(controller.mTransportType); |
| 725 | } |
| 726 | controller.updateConnectivity(connected, connected); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 727 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 728 | } |
| 729 | String wifi = args.getString("wifi"); |
| 730 | if (wifi != null) { |
| 731 | boolean show = wifi.equals("show"); |
| 732 | String level = args.getString("level"); |
| 733 | if (level != null) { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 734 | mDemoWifiState.level = level.equals("null") ? -1 |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 735 | : Math.min(Integer.parseInt(level), WifiIcons.WIFI_LEVEL_COUNT - 1); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 736 | mDemoWifiState.connected = mDemoWifiState.level >= 0; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 737 | } |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 738 | mDemoWifiState.enabled = show; |
| 739 | mWifiSignalController.notifyListeners(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 740 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 741 | String sims = args.getString("sims"); |
| 742 | if (sims != null) { |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 743 | int num = MathUtils.constrain(Integer.parseInt(sims), 1, 8); |
| 744 | List<SubscriptionInfo> subs = new ArrayList<>(); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 745 | if (num != mMobileSignalControllers.size()) { |
| 746 | mMobileSignalControllers.clear(); |
| 747 | int start = mSubscriptionManager.getActiveSubscriptionInfoCountMax(); |
| 748 | 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] | 749 | subs.add(addSignalController(i, i)); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 750 | } |
Jason Monk | 33b60bb | 2015-07-13 10:42:23 -0400 | [diff] [blame] | 751 | mCallbackHandler.setSubs(subs); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 752 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 753 | } |
| 754 | String nosim = args.getString("nosim"); |
| 755 | if (nosim != null) { |
Jason Monk | 259e06f | 2015-06-18 14:07:26 -0400 | [diff] [blame] | 756 | mHasNoSims = nosim.equals("show"); |
| 757 | mCallbackHandler.setNoSims(mHasNoSims); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 758 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 759 | String mobile = args.getString("mobile"); |
| 760 | if (mobile != null) { |
| 761 | boolean show = mobile.equals("show"); |
| 762 | String datatype = args.getString("datatype"); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 763 | String slotString = args.getString("slot"); |
| 764 | int slot = TextUtils.isEmpty(slotString) ? 0 : Integer.parseInt(slotString); |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 765 | slot = MathUtils.constrain(slot, 0, 8); |
| 766 | // Ensure we have enough sim slots |
| 767 | List<SubscriptionInfo> subs = new ArrayList<>(); |
| 768 | while (mMobileSignalControllers.size() <= slot) { |
| 769 | int nextSlot = mMobileSignalControllers.size(); |
| 770 | subs.add(addSignalController(nextSlot, nextSlot)); |
| 771 | } |
| 772 | if (!subs.isEmpty()) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 773 | mCallbackHandler.setSubs(subs); |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 774 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 775 | // Hack to index linearly for easy use. |
| 776 | MobileSignalController controller = mMobileSignalControllers |
| 777 | .values().toArray(new MobileSignalController[0])[slot]; |
| 778 | controller.getState().dataSim = datatype != null; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 779 | if (datatype != null) { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 780 | controller.getState().iconGroup = |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 781 | datatype.equals("1x") ? TelephonyIcons.ONE_X : |
| 782 | datatype.equals("3g") ? TelephonyIcons.THREE_G : |
| 783 | datatype.equals("4g") ? TelephonyIcons.FOUR_G : |
Ajay Nambi | 7965fa4 | 2015-05-14 18:48:33 -0700 | [diff] [blame] | 784 | datatype.equals("4g+") ? TelephonyIcons.FOUR_G_PLUS : |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 785 | datatype.equals("e") ? TelephonyIcons.E : |
| 786 | datatype.equals("g") ? TelephonyIcons.G : |
| 787 | datatype.equals("h") ? TelephonyIcons.H : |
| 788 | datatype.equals("lte") ? TelephonyIcons.LTE : |
Jason Monk | aa730be | 2016-07-13 14:22:52 -0400 | [diff] [blame] | 789 | datatype.equals("lte+") ? TelephonyIcons.LTE_PLUS : |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 790 | datatype.equals("roam") ? TelephonyIcons.ROAMING : |
| 791 | TelephonyIcons.UNKNOWN; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 792 | } |
| 793 | int[][] icons = TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH; |
| 794 | String level = args.getString("level"); |
| 795 | if (level != null) { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 796 | controller.getState().level = level.equals("null") ? -1 |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 797 | : Math.min(Integer.parseInt(level), icons[0].length - 1); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 798 | controller.getState().connected = controller.getState().level >= 0; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 799 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 800 | controller.getState().enabled = show; |
| 801 | controller.notifyListeners(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 802 | } |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 803 | String carrierNetworkChange = args.getString("carriernetworkchange"); |
| 804 | if (carrierNetworkChange != null) { |
| 805 | boolean show = carrierNetworkChange.equals("show"); |
| 806 | for (MobileSignalController controller : mMobileSignalControllers.values()) { |
| 807 | controller.setCarrierNetworkChangeMode(show); |
| 808 | } |
| 809 | } |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 810 | } |
| 811 | } |
| 812 | |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 813 | private SubscriptionInfo addSignalController(int id, int simSlotIndex) { |
| 814 | SubscriptionInfo info = new SubscriptionInfo(id, "", simSlotIndex, "", "", 0, 0, "", 0, |
fionaxu | 1bf6ec2 | 2016-05-23 16:33:16 -0700 | [diff] [blame] | 815 | null, 0, 0, ""); |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 816 | mMobileSignalControllers.put(id, new MobileSignalController(mContext, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 817 | mConfig, mHasMobileDataFeature, mPhone, mCallbackHandler, this, info, |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 818 | mSubDefaults, mReceiverHandler.getLooper())); |
John Spurlock | cf053c1 | 2015-05-14 16:33:59 -0400 | [diff] [blame] | 819 | return info; |
| 820 | } |
| 821 | |
Adrian Roos | 316bf54 | 2016-08-23 17:53:07 +0200 | [diff] [blame] | 822 | public boolean hasEmergencyCryptKeeperText() { |
| 823 | return EncryptionHelper.IS_DATA_ENCRYPTED; |
| 824 | } |
| 825 | |
| 826 | public boolean isRadioOn() { |
| 827 | return !mAirplaneMode; |
| 828 | } |
| 829 | |
Jason Monk | 8fcab35 | 2015-06-29 10:57:00 -0400 | [diff] [blame] | 830 | private class SubListener extends OnSubscriptionsChangedListener { |
Jason Monk | c9f0571 | 2014-12-15 12:24:10 -0500 | [diff] [blame] | 831 | @Override |
| 832 | public void onSubscriptionsChanged() { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 833 | updateMobileControllers(); |
Jason Monk | 8fcab35 | 2015-06-29 10:57:00 -0400 | [diff] [blame] | 834 | } |
| 835 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 836 | |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 837 | /** |
| 838 | * Used to register listeners from the BG Looper, this way the PhoneStateListeners that |
| 839 | * get created will also run on the BG Looper. |
| 840 | */ |
| 841 | private final Runnable mRegisterListeners = new Runnable() { |
| 842 | @Override |
| 843 | public void run() { |
| 844 | registerListeners(); |
| 845 | } |
| 846 | }; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 847 | |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 848 | public static class SubscriptionDefaults { |
| 849 | public int getDefaultVoiceSubId() { |
Shishir Agrawal | 7ea3e8b | 2016-01-25 13:03:07 -0800 | [diff] [blame] | 850 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | public int getDefaultDataSubId() { |
Shishir Agrawal | 7ea3e8b | 2016-01-25 13:03:07 -0800 | [diff] [blame] | 854 | return SubscriptionManager.getDefaultDataSubscriptionId(); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 855 | } |
| 856 | } |
| 857 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 858 | @VisibleForTesting |
| 859 | static class Config { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 860 | boolean showAtLeast3G = false; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 861 | boolean alwaysShowCdmaRssi = false; |
| 862 | boolean show4gForLte = false; |
Robert Greenwalt | 37d34ba | 2016-07-27 14:54:34 -0700 | [diff] [blame] | 863 | boolean hideLtePlus = false; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 864 | boolean hspaDataDistinguishable; |
| 865 | |
| 866 | static Config readConfig(Context context) { |
| 867 | Config config = new Config(); |
| 868 | Resources res = context.getResources(); |
| 869 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 870 | config.showAtLeast3G = res.getBoolean(R.bool.config_showMin3G); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 871 | config.alwaysShowCdmaRssi = |
| 872 | res.getBoolean(com.android.internal.R.bool.config_alwaysUseCdmaRssi); |
| 873 | config.show4gForLte = res.getBoolean(R.bool.config_show4GForLTE); |
| 874 | config.hspaDataDistinguishable = |
| 875 | res.getBoolean(R.bool.config_hspa_data_distinguishable); |
Robert Greenwalt | 37d34ba | 2016-07-27 14:54:34 -0700 | [diff] [blame] | 876 | config.hideLtePlus = res.getBoolean(R.bool.config_hideLtePlus); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 877 | return config; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 878 | } |
| 879 | } |
| 880 | } |