Add ConnectivityManager.getActiveNetwork().
Rework NetID allocation in ConnectivityService so registerNetworkAgent() can return the allocated NetID. Bug: 19416463 Change-Id: I68e395552cf27422c80b4dfae5db5d56a0d68f5d
This commit is contained in:
@@ -601,6 +601,27 @@ public class ConnectivityManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Network} object corresponding to the currently active
|
||||
* default data network. In the event that the current active default data
|
||||
* network disconnects, the returned {@code Network} object will no longer
|
||||
* be usable. This will return {@code null} when there is no default
|
||||
* network.
|
||||
*
|
||||
* @return a {@link Network} object for the current default network or
|
||||
* {@code null} if no default network is currently active
|
||||
*
|
||||
* <p>This method requires the caller to hold the permission
|
||||
* {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
|
||||
*/
|
||||
public Network getActiveNetwork() {
|
||||
try {
|
||||
return mService.getActiveNetwork();
|
||||
} catch (RemoteException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns details about the currently active default data network
|
||||
* for a given uid. This is for internal use only to avoid spying
|
||||
@@ -1927,12 +1948,18 @@ public class ConnectivityManager {
|
||||
} catch (RemoteException e) { }
|
||||
}
|
||||
|
||||
/** {@hide} */
|
||||
public void registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
|
||||
/**
|
||||
* @hide
|
||||
* Register a NetworkAgent with ConnectivityService.
|
||||
* @return NetID corresponding to NetworkAgent.
|
||||
*/
|
||||
public int registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
|
||||
NetworkCapabilities nc, int score, NetworkMisc misc) {
|
||||
try {
|
||||
mService.registerNetworkAgent(messenger, ni, lp, nc, score, misc);
|
||||
} catch (RemoteException e) { }
|
||||
return mService.registerNetworkAgent(messenger, ni, lp, nc, score, misc);
|
||||
} catch (RemoteException e) {
|
||||
return NETID_UNSET;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,6 +42,7 @@ import com.android.internal.net.VpnProfile;
|
||||
/** {@hide} */
|
||||
interface IConnectivityManager
|
||||
{
|
||||
Network getActiveNetwork();
|
||||
NetworkInfo getActiveNetworkInfo();
|
||||
NetworkInfo getActiveNetworkInfoForUid(int uid);
|
||||
NetworkInfo getNetworkInfo(int networkType);
|
||||
@@ -132,7 +133,7 @@ interface IConnectivityManager
|
||||
|
||||
void unregisterNetworkFactory(in Messenger messenger);
|
||||
|
||||
void registerNetworkAgent(in Messenger messenger, in NetworkInfo ni, in LinkProperties lp,
|
||||
int registerNetworkAgent(in Messenger messenger, in NetworkInfo ni, in LinkProperties lp,
|
||||
in NetworkCapabilities nc, int score, in NetworkMisc misc);
|
||||
|
||||
NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities,
|
||||
|
||||
@@ -42,6 +42,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
* @hide
|
||||
*/
|
||||
public abstract class NetworkAgent extends Handler {
|
||||
// Guaranteed to be valid (not NETID_UNSET), otherwise registerNetworkAgent() would have thrown
|
||||
// an exception.
|
||||
public final int netId;
|
||||
|
||||
private volatile AsyncChannel mAsyncChannel;
|
||||
private final String LOG_TAG;
|
||||
private static final boolean DBG = true;
|
||||
@@ -142,7 +146,7 @@ public abstract class NetworkAgent extends Handler {
|
||||
if (VDBG) log("Registering NetworkAgent");
|
||||
ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(
|
||||
Context.CONNECTIVITY_SERVICE);
|
||||
cm.registerNetworkAgent(new Messenger(this), new NetworkInfo(ni),
|
||||
netId = cm.registerNetworkAgent(new Messenger(this), new NetworkInfo(ni),
|
||||
new LinkProperties(lp), new NetworkCapabilities(nc), score, misc);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user