Have registerNetworkAgent return a Network.
This is more useful. Bug: 135998869 Test: FrameworkNetTests FrameworksWifiTests Change-Id: I74710b396fa3cec6fbae08d3dcab5bc90dc2e669 Merged-In: I74710b396fa3cec6fbae08d3dcab5bc90dc2e669
This commit is contained in:
committed by
Chiachang Wang
parent
b2ff467a3a
commit
f78c964538
@@ -3169,10 +3169,10 @@ public class ConnectivityManager {
|
|||||||
/**
|
/**
|
||||||
* @hide
|
* @hide
|
||||||
* Register a NetworkAgent with ConnectivityService.
|
* Register a NetworkAgent with ConnectivityService.
|
||||||
* @return NetID corresponding to NetworkAgent.
|
* @return Network corresponding to NetworkAgent.
|
||||||
*/
|
*/
|
||||||
@RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
|
@RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
|
||||||
public int registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
|
public Network registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
|
||||||
NetworkCapabilities nc, int score, NetworkMisc misc) {
|
NetworkCapabilities nc, int score, NetworkMisc misc) {
|
||||||
return registerNetworkAgent(messenger, ni, lp, nc, score, misc, NetworkProvider.ID_NONE);
|
return registerNetworkAgent(messenger, ni, lp, nc, score, misc, NetworkProvider.ID_NONE);
|
||||||
}
|
}
|
||||||
@@ -3180,10 +3180,10 @@ public class ConnectivityManager {
|
|||||||
/**
|
/**
|
||||||
* @hide
|
* @hide
|
||||||
* Register a NetworkAgent with ConnectivityService.
|
* Register a NetworkAgent with ConnectivityService.
|
||||||
* @return NetID corresponding to NetworkAgent.
|
* @return Network corresponding to NetworkAgent.
|
||||||
*/
|
*/
|
||||||
@RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
|
@RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
|
||||||
public int registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
|
public Network registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
|
||||||
NetworkCapabilities nc, int score, NetworkMisc misc, int providerId) {
|
NetworkCapabilities nc, int score, NetworkMisc misc, int providerId) {
|
||||||
try {
|
try {
|
||||||
return mService.registerNetworkAgent(messenger, ni, lp, nc, score, misc, providerId);
|
return mService.registerNetworkAgent(messenger, ni, lp, nc, score, misc, providerId);
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ interface IConnectivityManager
|
|||||||
|
|
||||||
void declareNetworkRequestUnfulfillable(in NetworkRequest request);
|
void declareNetworkRequestUnfulfillable(in NetworkRequest request);
|
||||||
|
|
||||||
int registerNetworkAgent(in Messenger messenger, in NetworkInfo ni, in LinkProperties lp,
|
Network registerNetworkAgent(in Messenger messenger, in NetworkInfo ni, in LinkProperties lp,
|
||||||
in NetworkCapabilities nc, int score, in NetworkMisc misc, in int factorySerialNumber);
|
in NetworkCapabilities nc, int score, in NetworkMisc misc, in int factorySerialNumber);
|
||||||
|
|
||||||
NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities,
|
NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities,
|
||||||
|
|||||||
@@ -44,9 +44,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public abstract class NetworkAgent extends Handler {
|
public abstract class NetworkAgent extends Handler {
|
||||||
// Guaranteed to be valid (not NETID_UNSET), otherwise registerNetworkAgent() would have thrown
|
public final Network network;
|
||||||
// an exception.
|
|
||||||
public final int netId;
|
|
||||||
|
|
||||||
private volatile AsyncChannel mAsyncChannel;
|
private volatile AsyncChannel mAsyncChannel;
|
||||||
private final String LOG_TAG;
|
private final String LOG_TAG;
|
||||||
@@ -245,7 +243,7 @@ public abstract class NetworkAgent extends Handler {
|
|||||||
if (VDBG) log("Registering NetworkAgent");
|
if (VDBG) log("Registering NetworkAgent");
|
||||||
ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(
|
ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(
|
||||||
Context.CONNECTIVITY_SERVICE);
|
Context.CONNECTIVITY_SERVICE);
|
||||||
netId = cm.registerNetworkAgent(new Messenger(this), new NetworkInfo(ni),
|
network = cm.registerNetworkAgent(new Messenger(this), new NetworkInfo(ni),
|
||||||
new LinkProperties(lp), new NetworkCapabilities(nc), score, misc, providerId);
|
new LinkProperties(lp), new NetworkCapabilities(nc), score, misc, providerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5496,7 +5496,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// changes that would conflict throughout the automerger graph. Having this method temporarily
|
// changes that would conflict throughout the automerger graph. Having this method temporarily
|
||||||
// helps with the process of going through with all these dependent changes across the entire
|
// helps with the process of going through with all these dependent changes across the entire
|
||||||
// tree.
|
// tree.
|
||||||
public int registerNetworkAgent(Messenger messenger, NetworkInfo networkInfo,
|
/**
|
||||||
|
* Register a new agent. {@see #registerNetworkAgent} below.
|
||||||
|
*/
|
||||||
|
public Network registerNetworkAgent(Messenger messenger, NetworkInfo networkInfo,
|
||||||
LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
|
LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
|
||||||
int currentScore, NetworkMisc networkMisc) {
|
int currentScore, NetworkMisc networkMisc) {
|
||||||
return registerNetworkAgent(messenger, networkInfo, linkProperties, networkCapabilities,
|
return registerNetworkAgent(messenger, networkInfo, linkProperties, networkCapabilities,
|
||||||
@@ -5517,8 +5520,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
* {@link NetworkAgentInfo#getCurrentScore}.
|
* {@link NetworkAgentInfo#getCurrentScore}.
|
||||||
* @param networkMisc metadata about the network. This is never updated.
|
* @param networkMisc metadata about the network. This is never updated.
|
||||||
* @param providerId the ID of the provider owning this NetworkAgent.
|
* @param providerId the ID of the provider owning this NetworkAgent.
|
||||||
|
* @return the network created for this agent.
|
||||||
*/
|
*/
|
||||||
public int registerNetworkAgent(Messenger messenger, NetworkInfo networkInfo,
|
public Network registerNetworkAgent(Messenger messenger, NetworkInfo networkInfo,
|
||||||
LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
|
LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
|
||||||
int currentScore, NetworkMisc networkMisc, int providerId) {
|
int currentScore, NetworkMisc networkMisc, int providerId) {
|
||||||
enforceNetworkFactoryPermission();
|
enforceNetworkFactoryPermission();
|
||||||
@@ -5551,7 +5555,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// If the network disconnects or sends any other event before that, messages are deferred by
|
// If the network disconnects or sends any other event before that, messages are deferred by
|
||||||
// NetworkAgent until nai.asyncChannel.connect(), which will be called when finalizing the
|
// NetworkAgent until nai.asyncChannel.connect(), which will be called when finalizing the
|
||||||
// registration.
|
// registration.
|
||||||
return nai.network.netId;
|
return nai.network;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleRegisterNetworkAgent(NetworkAgentInfo nai, INetworkMonitor networkMonitor) {
|
private void handleRegisterNetworkAgent(NetworkAgentInfo nai, INetworkMonitor networkMonitor) {
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ class TestNetworkService extends ITestNetworkManager.Stub {
|
|||||||
// Has to be in TestNetworkAgent to ensure all teardown codepaths properly clean up
|
// Has to be in TestNetworkAgent to ensure all teardown codepaths properly clean up
|
||||||
// resources, even for binder death or unwanted calls.
|
// resources, even for binder death or unwanted calls.
|
||||||
synchronized (mTestNetworkTracker) {
|
synchronized (mTestNetworkTracker) {
|
||||||
mTestNetworkTracker.remove(netId);
|
mTestNetworkTracker.remove(network.netId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -338,7 +338,7 @@ class TestNetworkService extends ITestNetworkManager.Stub {
|
|||||||
callingUid,
|
callingUid,
|
||||||
binder);
|
binder);
|
||||||
|
|
||||||
mTestNetworkTracker.put(agent.netId, agent);
|
mTestNetworkTracker.put(agent.network.netId, agent);
|
||||||
}
|
}
|
||||||
} catch (SocketException e) {
|
} catch (SocketException e) {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ public class NetworkAgentWrapper implements TestableNetworkCallback.HasNetwork {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Network getNetwork() {
|
public Network getNetwork() {
|
||||||
return new Network(mNetworkAgent.netId);
|
return mNetworkAgent.network;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void expectPreventReconnectReceived(long timeoutMs) {
|
public void expectPreventReconnectReceived(long timeoutMs) {
|
||||||
|
|||||||
@@ -575,7 +575,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
assertEquals(na.netId, nmNetworkCaptor.getValue().netId);
|
assertEquals(na.network.netId, nmNetworkCaptor.getValue().netId);
|
||||||
mNmCallbacks = nmCbCaptor.getValue();
|
mNmCallbacks = nmCbCaptor.getValue();
|
||||||
|
|
||||||
mNmCallbacks.onNetworkMonitorCreated(mNetworkMonitor);
|
mNmCallbacks.onNetworkMonitorCreated(mNetworkMonitor);
|
||||||
|
|||||||
Reference in New Issue
Block a user