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