am d99cd44f: am dc99c504: Merge "Make StatusBar display all default networks." into lmp-mr1-dev

* commit 'd99cd44f317a0e1b188a0033ebe4948f13c32491':
  Make StatusBar display all default networks.
This commit is contained in:
Lorenzo Colitti
2014-12-03 20:41:10 +00:00
committed by Android Git Automerger
7 changed files with 158 additions and 57 deletions

View File

@@ -720,6 +720,19 @@ public class ConnectivityManager {
} }
} }
/**
* Returns an array of of {@link NetworkCapabilities} objects, representing
* the Networks that applications run by the given user will use by default.
* @hide
*/
public NetworkCapabilities[] getDefaultNetworkCapabilitiesForUser(int userId) {
try {
return mService.getDefaultNetworkCapabilitiesForUser(userId);
} catch (RemoteException e) {
return null;
}
}
/** /**
* Returns details about the Provisioning or currently active default data network. When * Returns details about the Provisioning or currently active default data network. When
* connected, this network is the default route for outgoing connections. * connected, this network is the default route for outgoing connections.

View File

@@ -49,6 +49,7 @@ interface IConnectivityManager
NetworkInfo[] getAllNetworkInfo(); NetworkInfo[] getAllNetworkInfo();
Network getNetworkForType(int networkType); Network getNetworkForType(int networkType);
Network[] getAllNetworks(); Network[] getAllNetworks();
NetworkCapabilities[] getDefaultNetworkCapabilitiesForUser(int userId);
NetworkInfo getProvisioningOrActiveNetworkInfo(); NetworkInfo getProvisioningOrActiveNetworkInfo();

View File

@@ -154,9 +154,16 @@ public final class NetworkCapabilities implements Parcelable {
*/ */
public static final int NET_CAPABILITY_NOT_VPN = 15; public static final int NET_CAPABILITY_NOT_VPN = 15;
/**
* Indicates that connectivity on this network was successfully validated. For example, for a
* network with NET_CAPABILITY_INTERNET, it means that Internet connectivity was successfully
* detected.
* @hide
*/
public static final int NET_CAPABILITY_VALIDATED = 16;
private static final int MIN_NET_CAPABILITY = NET_CAPABILITY_MMS; private static final int MIN_NET_CAPABILITY = NET_CAPABILITY_MMS;
private static final int MAX_NET_CAPABILITY = NET_CAPABILITY_NOT_VPN; private static final int MAX_NET_CAPABILITY = NET_CAPABILITY_VALIDATED;
/** /**
* Adds the given capability to this {@code NetworkCapability} instance. * Adds the given capability to this {@code NetworkCapability} instance.

View File

@@ -122,7 +122,7 @@ public class QSTileHost implements QSTile.Host {
tile.userSwitch(newUserId); tile.userSwitch(newUserId);
} }
mSecurity.onUserSwitched(newUserId); mSecurity.onUserSwitched(newUserId);
mNetwork.getAccessPointController().onUserSwitched(newUserId); mNetwork.onUserSwitched(newUserId);
mObserver.register(); mObserver.register();
} }
}; };

View File

@@ -22,6 +22,7 @@ public interface NetworkController {
void addNetworkSignalChangedCallback(NetworkSignalChangedCallback cb); void addNetworkSignalChangedCallback(NetworkSignalChangedCallback cb);
void removeNetworkSignalChangedCallback(NetworkSignalChangedCallback cb); void removeNetworkSignalChangedCallback(NetworkSignalChangedCallback cb);
void setWifiEnabled(boolean enabled); void setWifiEnabled(boolean enabled);
void onUserSwitched(int newUserId);
AccessPointController getAccessPointController(); AccessPointController getAccessPointController();
MobileDataController getMobileDataController(); MobileDataController getMobileDataController();
@@ -49,7 +50,6 @@ public interface NetworkController {
void scanForAccessPoints(); void scanForAccessPoints();
boolean connect(AccessPoint ap); boolean connect(AccessPoint ap);
boolean canConfigWifi(); boolean canConfigWifi();
void onUserSwitched(int newUserId);
public interface AccessPointCallback { public interface AccessPointCallback {
void onAccessPointsChanged(AccessPoint[] accessPoints); void onAccessPointsChanged(AccessPoint[] accessPoints);

View File

@@ -16,12 +16,19 @@
package com.android.systemui.statusbar.policy; package com.android.systemui.statusbar.policy;
import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
import static android.net.NetworkCapabilities.TRANSPORT_BLUETOOTH;
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET;
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo;
@@ -55,6 +62,7 @@ import com.android.systemui.R;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
@@ -98,16 +106,19 @@ public class NetworkControllerImpl extends BroadcastReceiver
private final AccessPointControllerImpl mAccessPoints; private final AccessPointControllerImpl mAccessPoints;
private final MobileDataControllerImpl mMobileDataController; private final MobileDataControllerImpl mMobileDataController;
// bluetooth // Network types that replace the carrier label if the device does not support mobile data.
private boolean mBluetoothTethered = false; private boolean mBluetoothTethered = false;
private boolean mEthernetConnected = false;
// data connectivity (regardless of state, can we access the internet?) // state of inet connection
// state of inet connection - 0 not connected, 100 connected
private boolean mConnected = false; private boolean mConnected = false;
private int mConnectedNetworkType = ConnectivityManager.TYPE_NONE;
private String mConnectedNetworkTypeName;
private boolean mInetCondition; // Used for Logging and demo. private boolean mInetCondition; // Used for Logging and demo.
// BitSets indicating which network transport types (e.g., TRANSPORT_WIFI, TRANSPORT_MOBILE) are
// connected and validated, respectively.
private final BitSet mConnectedTransports = new BitSet();
private final BitSet mValidatedTransports = new BitSet();
// States that don't belong to a subcontroller. // States that don't belong to a subcontroller.
private boolean mAirplaneMode = false; private boolean mAirplaneMode = false;
private boolean mHasNoSims; private boolean mHasNoSims;
@@ -125,6 +136,9 @@ public class NetworkControllerImpl extends BroadcastReceiver
new ArrayList<NetworkSignalChangedCallback>(); new ArrayList<NetworkSignalChangedCallback>();
private boolean mListening; private boolean mListening;
// The current user ID.
private int mCurrentUserId;
/** /**
* Construct this controller object and register for updates. * Construct this controller object and register for updates.
*/ */
@@ -343,6 +357,14 @@ public class NetworkControllerImpl extends BroadcastReceiver
}.execute(); }.execute();
} }
@Override
public void onUserSwitched(int newUserId) {
mCurrentUserId = newUserId;
mAccessPoints.onUserSwitched(newUserId);
updateConnectivity();
refreshCarrierLabel();
}
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (CHATTY) { if (CHATTY) {
@@ -351,7 +373,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
final String action = intent.getAction(); final String action = intent.getAction();
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE) || if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE) ||
action.equals(ConnectivityManager.INET_CONDITION_ACTION)) { action.equals(ConnectivityManager.INET_CONDITION_ACTION)) {
updateConnectivity(intent); updateConnectivity();
refreshCarrierLabel(); refreshCarrierLabel();
} else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) { } else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
refreshLocale(); refreshLocale();
@@ -497,14 +519,6 @@ public class NetworkControllerImpl extends BroadcastReceiver
} }
} }
/**
* Turns inet condition into a boolean indexing for a specific network.
* @return 0 for bad connectivity on this network, 1 for good connectivity
*/
private int inetConditionForNetwork(int networkType, boolean inetCondition) {
return (inetCondition && mConnectedNetworkType == networkType) ? 1 : 0;
}
/** /**
* Forces update of all callbacks on both SignalClusters and * Forces update of all callbacks on both SignalClusters and
* NetworkSignalChangedCallbacks. * NetworkSignalChangedCallbacks.
@@ -539,41 +553,37 @@ public class NetworkControllerImpl extends BroadcastReceiver
/** /**
* Update the Inet conditions and what network we are connected to. * Update the Inet conditions and what network we are connected to.
*/ */
private void updateConnectivity(Intent intent) { private void updateConnectivity() {
final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo(); mConnectedTransports.clear();
mValidatedTransports.clear();
// Are we connected at all, by any interface? for (NetworkCapabilities nc :
mConnected = info != null && info.isConnected(); mConnectivityManager.getDefaultNetworkCapabilitiesForUser(mCurrentUserId)) {
if (mConnected) { for (int transportType : nc.getTransportTypes()) {
mConnectedNetworkType = info.getType(); mConnectedTransports.set(transportType);
mConnectedNetworkTypeName = info.getTypeName(); if (nc.hasCapability(NET_CAPABILITY_VALIDATED)) {
} else { mValidatedTransports.set(transportType);
mConnectedNetworkType = ConnectivityManager.TYPE_NONE; }
mConnectedNetworkTypeName = null; }
} }
int connectionStatus = intent.getIntExtra(ConnectivityManager.EXTRA_INET_CONDITION, 0);
if (CHATTY) { if (CHATTY) {
Log.d(TAG, "updateConnectivity: networkInfo=" + info); Log.d(TAG, "updateConnectivity: mConnectedTransports=" + mConnectedTransports);
Log.d(TAG, "updateConnectivity: connectionStatus=" + connectionStatus); Log.d(TAG, "updateConnectivity: mValidatedTransports=" + mValidatedTransports);
} }
mInetCondition = connectionStatus > INET_CONDITION_THRESHOLD; mConnected = !mConnectedTransports.isEmpty();
mInetCondition = !mValidatedTransports.isEmpty();
if (info != null && info.getType() == ConnectivityManager.TYPE_BLUETOOTH) { mBluetoothTethered = mConnectedTransports.get(TRANSPORT_BLUETOOTH);
mBluetoothTethered = info.isConnected(); mEthernetConnected = mConnectedTransports.get(TRANSPORT_ETHERNET);
} else {
mBluetoothTethered = false;
}
// We want to update all the icons, all at once, for any condition change // We want to update all the icons, all at once, for any condition change
for (MobileSignalController mobileSignalController : mMobileSignalControllers.values()) { for (MobileSignalController mobileSignalController : mMobileSignalControllers.values()) {
mobileSignalController.setInetCondition(mInetCondition ? 1 : 0, inetConditionForNetwork( mobileSignalController.setInetCondition(
mobileSignalController.getNetworkType(), mInetCondition)); mInetCondition ? 1 : 0,
mValidatedTransports.get(mobileSignalController.getTransportType()) ? 1 : 0);
} }
mWifiSignalController.setInetCondition( mWifiSignalController.setInetCondition(
inetConditionForNetwork(mWifiSignalController.getNetworkType(), mInetCondition)); mValidatedTransports.get(mWifiSignalController.getTransportType()) ? 1 : 0);
} }
/** /**
@@ -594,9 +604,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
label = mContext.getString(R.string.bluetooth_tethered); label = mContext.getString(R.string.bluetooth_tethered);
} }
final boolean ethernetConnected = if (mEthernetConnected && !mHasMobileDataFeature) {
(mConnectedNetworkType == ConnectivityManager.TYPE_ETHERNET);
if (ethernetConnected && !mHasMobileDataFeature) {
label = context.getString(R.string.ethernet_label); label = context.getString(R.string.ethernet_label);
} }
@@ -612,7 +620,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
} }
} }
} else if (!isMobileDataConnected() && !wifiState.connected && !mBluetoothTethered && } else if (!isMobileDataConnected() && !wifiState.connected && !mBluetoothTethered &&
!ethernetConnected && !mHasMobileDataFeature) { !mEthernetConnected && !mHasMobileDataFeature) {
// Pretty much no connection. // Pretty much no connection.
label = context.getString(R.string.status_bar_settings_signal_meter_disconnected); label = context.getString(R.string.status_bar_settings_signal_meter_disconnected);
} }
@@ -633,9 +641,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println("NetworkController state:"); pw.println("NetworkController state:");
pw.println(String.format(" %s network type %d (%s)",
mConnected ? "CONNECTED" : "DISCONNECTED",
mConnectedNetworkType, mConnectedNetworkTypeName));
pw.println(" - telephony ------"); pw.println(" - telephony ------");
pw.print(" hasVoiceCallingFeature()="); pw.print(" hasVoiceCallingFeature()=");
pw.println(hasVoiceCallingFeature()); pw.println(hasVoiceCallingFeature());
@@ -645,6 +651,10 @@ public class NetworkControllerImpl extends BroadcastReceiver
pw.println(mBluetoothTethered); pw.println(mBluetoothTethered);
pw.println(" - connectivity ------"); pw.println(" - connectivity ------");
pw.print(" mConnectedTransports=");
pw.println(mConnectedTransports);
pw.print(" mValidatedTransports=");
pw.println(mValidatedTransports);
pw.print(" mInetCondition="); pw.print(" mInetCondition=");
pw.println(mInetCondition); pw.println(mInetCondition);
pw.print(" mAirplaneMode="); pw.print(" mAirplaneMode=");
@@ -795,8 +805,8 @@ public class NetworkControllerImpl extends BroadcastReceiver
public WifiSignalController(Context context, boolean hasMobileData, public WifiSignalController(Context context, boolean hasMobileData,
List<NetworkSignalChangedCallback> signalCallbacks, List<NetworkSignalChangedCallback> signalCallbacks,
List<SignalCluster> signalClusters, NetworkControllerImpl networkController) { List<SignalCluster> signalClusters, NetworkControllerImpl networkController) {
super("WifiSignalController", context, ConnectivityManager.TYPE_WIFI, signalCallbacks, super("WifiSignalController", context, NetworkCapabilities.TRANSPORT_WIFI,
signalClusters, networkController); signalCallbacks, signalClusters, networkController);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mHasMobileData = hasMobileData; mHasMobileData = hasMobileData;
Handler handler = new WifiHandler(); Handler handler = new WifiHandler();
@@ -989,7 +999,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
List<SignalCluster> signalClusters, NetworkControllerImpl networkController, List<SignalCluster> signalClusters, NetworkControllerImpl networkController,
SubscriptionInfo info) { SubscriptionInfo info) {
super("MobileSignalController(" + info.getSubscriptionId() + ")", context, super("MobileSignalController(" + info.getSubscriptionId() + ")", context,
ConnectivityManager.TYPE_MOBILE, signalCallbacks, signalClusters, NetworkCapabilities.TRANSPORT_CELLULAR, signalCallbacks, signalClusters,
networkController); networkController);
mConfig = config; mConfig = config;
mPhone = phone; mPhone = phone;
@@ -1460,7 +1470,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
protected final String mTag; protected final String mTag;
protected final T mCurrentState; protected final T mCurrentState;
protected final T mLastState; protected final T mLastState;
protected final int mNetworkType; protected final int mTransportType;
protected final Context mContext; protected final Context mContext;
// The owner of the SignalController (i.e. NetworkController will maintain the following // The owner of the SignalController (i.e. NetworkController will maintain the following
// lists and call notifyListeners whenever the list has changed to ensure everyone // lists and call notifyListeners whenever the list has changed to ensure everyone
@@ -1479,7 +1489,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
List<SignalCluster> signalClusters, NetworkControllerImpl networkController) { List<SignalCluster> signalClusters, NetworkControllerImpl networkController) {
mTag = TAG + "." + tag; mTag = TAG + "." + tag;
mNetworkController = networkController; mNetworkController = networkController;
mNetworkType = type; mTransportType = type;
mContext = context; mContext = context;
mSignalsChangedCallbacks = signalCallbacks; mSignalsChangedCallbacks = signalCallbacks;
mSignalClusters = signalClusters; mSignalClusters = signalClusters;
@@ -1497,8 +1507,8 @@ public class NetworkControllerImpl extends BroadcastReceiver
return mCurrentState; return mCurrentState;
} }
public int getNetworkType() { public int getTransportType() {
return mNetworkType; return mTransportType;
} }
public void setInetCondition(int inetCondition) { public void setInetCondition(int inetCondition) {

View File

@@ -1065,6 +1065,72 @@ public class ConnectivityService extends IConnectivityManager.Stub
return result.toArray(new Network[result.size()]); return result.toArray(new Network[result.size()]);
} }
private NetworkCapabilities getNetworkCapabilitiesAndValidation(NetworkAgentInfo nai) {
if (nai != null) {
synchronized (nai) {
if (nai.created) {
NetworkCapabilities nc = new NetworkCapabilities(nai.networkCapabilities);
if (nai.validated) {
nc.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
} else {
nc.removeCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
}
return nc;
}
}
}
return null;
}
@Override
public NetworkCapabilities[] getDefaultNetworkCapabilitiesForUser(int userId) {
// The basic principle is: if an app's traffic could possibly go over a
// network, without the app doing anything multinetwork-specific,
// (hence, by "default"), then include that network's capabilities in
// the array.
//
// In the normal case, app traffic only goes over the system's default
// network connection, so that's the only network returned.
//
// With a VPN in force, some app traffic may go into the VPN, and thus
// over whatever underlying networks the VPN specifies, while other app
// traffic may go over the system default network (e.g.: a split-tunnel
// VPN, or an app disallowed by the VPN), so the set of networks
// returned includes the VPN's underlying networks and the system
// default.
enforceAccessPermission();
HashMap<Network, NetworkCapabilities> result = new HashMap<Network, NetworkCapabilities>();
NetworkAgentInfo nai = getDefaultNetwork();
NetworkCapabilities nc = getNetworkCapabilitiesAndValidation(getDefaultNetwork());
if (nc != null) {
result.put(nai.network, nc);
}
if (!mLockdownEnabled) {
synchronized (mVpns) {
Vpn vpn = mVpns.get(userId);
if (vpn != null) {
Network[] networks = vpn.getUnderlyingNetworks();
if (networks != null) {
for (Network network : networks) {
nai = getNetworkAgentInfoForNetwork(network);
nc = getNetworkCapabilitiesAndValidation(nai);
if (nc != null) {
result.put(nai.network, nc);
}
}
}
}
}
}
NetworkCapabilities[] out = new NetworkCapabilities[result.size()];
out = result.values().toArray(out);
return out;
}
@Override @Override
public boolean isNetworkSupported(int networkType) { public boolean isNetworkSupported(int networkType) {
enforceAccessPermission(); enforceAccessPermission();
@@ -3544,8 +3610,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
// Note: if mDefaultRequest is changed, NetworkMonitor needs to be updated. // Note: if mDefaultRequest is changed, NetworkMonitor needs to be updated.
private final NetworkRequest mDefaultRequest; private final NetworkRequest mDefaultRequest;
private NetworkAgentInfo getDefaultNetwork() {
return mNetworkForRequestId.get(mDefaultRequest.requestId);
}
private boolean isDefaultNetwork(NetworkAgentInfo nai) { private boolean isDefaultNetwork(NetworkAgentInfo nai) {
return mNetworkForRequestId.get(mDefaultRequest.requestId) == nai; return nai == getDefaultNetwork();
} }
public void registerNetworkAgent(Messenger messenger, NetworkInfo networkInfo, public void registerNetworkAgent(Messenger messenger, NetworkInfo networkInfo,