Merge "Have registerNetworkAgent return a Network." am: 061d68a40c am: 59b776a9e5

Change-Id: I6460295b5c7c045a3d60f5c281295f3a0cf83110
This commit is contained in:
Automerger Merge Worker
2020-01-21 02:21:35 +00:00
7 changed files with 18 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, NetworkMisc misc) {
return registerNetworkAgent(messenger, ni, lp, nc, score, misc, 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, NetworkMisc misc, int providerId) {
try {
return mService.registerNetworkAgent(messenger, ni, lp, nc, score, misc, 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 NetworkMisc misc, in int factorySerialNumber);
NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities,

View File

@@ -44,9 +44,7 @@ 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;
public final Network network;
private volatile AsyncChannel mAsyncChannel;
private final String LOG_TAG;
@@ -245,7 +243,7 @@ public abstract class NetworkAgent extends Handler {
if (VDBG) log("Registering NetworkAgent");
ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(
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);
}

View File

@@ -5496,7 +5496,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, NetworkMisc networkMisc) {
return registerNetworkAgent(messenger, networkInfo, linkProperties, networkCapabilities,
@@ -5517,8 +5520,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
* {@link NetworkAgentInfo#getCurrentScore}.
* @param networkMisc 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, NetworkMisc networkMisc, int providerId) {
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
// 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

@@ -219,7 +219,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);
}
}
}
@@ -338,7 +338,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);