Merge "Have registerNetworkAgent return a Network."

This commit is contained in:
Chalard Jean
2020-01-14 07:06:37 +00:00
committed by Android (Google) Code Review
7 changed files with 21 additions and 16 deletions

View File

@@ -3169,10 +3169,10 @@ public class ConnectivityManager {
/**
* @hide
* Register a NetworkAgent with ConnectivityService.
* @return NetID corresponding to NetworkAgent.
* @return Network corresponding to NetworkAgent.
*/
@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, NetworkAgentConfig config) {
return registerNetworkAgent(messenger, ni, lp, nc, score, config, NetworkProvider.ID_NONE);
}
@@ -3180,10 +3180,10 @@ public class ConnectivityManager {
/**
* @hide
* Register a NetworkAgent with ConnectivityService.
* @return NetID corresponding to NetworkAgent.
* @return Network corresponding to NetworkAgent.
*/
@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, NetworkAgentConfig config, int providerId) {
try {
return mService.registerNetworkAgent(messenger, ni, lp, nc, score, config, providerId);

View File

@@ -152,7 +152,7 @@ interface IConnectivityManager
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 NetworkAgentConfig config,
in int factorySerialNumber);

View File

@@ -44,9 +44,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
* @hide
*/
public abstract class NetworkAgent {
// Guaranteed to be valid (not NETID_UNSET), otherwise registerNetworkAgent() would have thrown
// an exception.
public final int netId;
// Guaranteed to be non-null, otherwise registerNetworkAgent() would have thrown
// an exception. Be careful in tests when mocking though.
@NonNull
public final Network network;
private final Handler mHandler;
private volatile AsyncChannel mAsyncChannel;
@@ -246,7 +247,7 @@ public abstract class NetworkAgent {
if (VDBG) log("Registering NetworkAgent");
ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(
Context.CONNECTIVITY_SERVICE);
netId = cm.registerNetworkAgent(new Messenger(mHandler), new NetworkInfo(ni),
network = cm.registerNetworkAgent(new Messenger(mHandler), new NetworkInfo(ni),
new LinkProperties(lp), new NetworkCapabilities(nc), score, config,
providerId);
}

View File

@@ -5505,7 +5505,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
// 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
// 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,
int currentScore, NetworkAgentConfig networkAgentConfig) {
return registerNetworkAgent(messenger, networkInfo, linkProperties, networkCapabilities,
@@ -5526,8 +5529,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
* {@link NetworkAgentInfo#getCurrentScore}.
* @param networkAgentConfig metadata about the network. This is never updated.
* @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,
int currentScore, NetworkAgentConfig networkAgentConfig, int providerId) {
enforceNetworkFactoryPermission();
@@ -5560,7 +5564,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
// 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
// registration.
return nai.network.netId;
return nai.network;
}
private void handleRegisterNetworkAgent(NetworkAgentInfo nai, INetworkMonitor networkMonitor) {

View File

@@ -218,7 +218,7 @@ class TestNetworkService extends ITestNetworkManager.Stub {
// Has to be in TestNetworkAgent to ensure all teardown codepaths properly clean up
// resources, even for binder death or unwanted calls.
synchronized (mTestNetworkTracker) {
mTestNetworkTracker.remove(netId);
mTestNetworkTracker.remove(network.netId);
}
}
}
@@ -337,7 +337,7 @@ class TestNetworkService extends ITestNetworkManager.Stub {
callingUid,
binder);
mTestNetworkTracker.put(agent.netId, agent);
mTestNetworkTracker.put(agent.network.netId, agent);
}
} catch (SocketException e) {
throw new UncheckedIOException(e);

View File

@@ -222,7 +222,7 @@ public class NetworkAgentWrapper implements TestableNetworkCallback.HasNetwork {
@Override
public Network getNetwork() {
return new Network(mNetworkAgent.netId);
return mNetworkAgent.network;
}
public void expectPreventReconnectReceived(long timeoutMs) {

View File

@@ -575,7 +575,7 @@ public class ConnectivityServiceTest {
}
};
assertEquals(na.netId, nmNetworkCaptor.getValue().netId);
assertEquals(na.network.netId, nmNetworkCaptor.getValue().netId);
mNmCallbacks = nmCbCaptor.getValue();
mNmCallbacks.onNetworkMonitorCreated(mNetworkMonitor);