Add Network inspection API.

Adds getNetworksNetworkInfo.
Adds getAllNetworks.

Cleans up some synchronization issues.

Change-Id: I82c7a4b554e3c6c1adfe6027cc54b028ed6dbac9
This commit is contained in:
Robert Greenwalt 2014-06-23 11:40:00 -07:00
commit 02fe11eba3
2 changed files with 138 additions and 24 deletions

View file

@ -743,7 +743,7 @@ public class ConnectivityManager {
* network type or {@code null} if the type is not
* supported by the device.
*
* <p>This method requires the call to hold the permission
* <p>This method requires the caller to hold the permission
* {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*/
public NetworkInfo getNetworkInfo(int networkType) {
@ -754,6 +754,27 @@ public class ConnectivityManager {
}
}
/**
* Returns connection status information about a particular
* Network.
*
* @param network {@link Network} specifying which network
* in which you're interested.
* @return a {@link NetworkInfo} object for the requested
* network or {@code null} if the {@code Network}
* is not valid.
*
* <p>This method requires the caller to hold the permission
* {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*/
public NetworkInfo getNetworkInfo(Network network) {
try {
return mService.getNetworkInfoForNetwork(network);
} catch (RemoteException e) {
return null;
}
}
/**
* Returns connection status information about all network
* types supported by the device.
@ -761,7 +782,7 @@ public class ConnectivityManager {
* @return an array of {@link NetworkInfo} objects. Check each
* {@link NetworkInfo#getType} for which type each applies.
*
* <p>This method requires the call to hold the permission
* <p>This method requires the caller to hold the permission
* {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*/
public NetworkInfo[] getAllNetworkInfo() {
@ -772,6 +793,23 @@ public class ConnectivityManager {
}
}
/**
* Returns an array of all {@link Network} currently tracked by the
* framework.
*
* @return an array of {@link Network} objects.
*
* <p>This method requires the caller to hold the permission
* {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*/
public Network[] getAllNetworks() {
try {
return mService.getAllNetworks();
} catch (RemoteException e) {
return null;
}
}
/**
* Returns details about the Provisioning or currently active default data network. When
* connected, this network is the default route for outgoing connections.

View file

@ -48,7 +48,9 @@ interface IConnectivityManager
NetworkInfo getActiveNetworkInfo();
NetworkInfo getActiveNetworkInfoForUid(int uid);
NetworkInfo getNetworkInfo(int networkType);
NetworkInfo getNetworkInfoForNetwork(in Network network);
NetworkInfo[] getAllNetworkInfo();
Network[] getAllNetworks();
NetworkInfo getProvisioningOrActiveNetworkInfo();