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