Merge "Have registerNetworkAgent return a Network."
This commit is contained in:
@@ -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, NetworkAgentConfig config) {
|
NetworkCapabilities nc, int score, NetworkAgentConfig config) {
|
||||||
return registerNetworkAgent(messenger, ni, lp, nc, score, config, NetworkProvider.ID_NONE);
|
return registerNetworkAgent(messenger, ni, lp, nc, score, config, 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, NetworkAgentConfig config, int providerId) {
|
NetworkCapabilities nc, int score, NetworkAgentConfig config, int providerId) {
|
||||||
try {
|
try {
|
||||||
return mService.registerNetworkAgent(messenger, ni, lp, nc, score, config, providerId);
|
return mService.registerNetworkAgent(messenger, ni, lp, nc, score, config, 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 NetworkAgentConfig config,
|
in NetworkCapabilities nc, int score, in NetworkAgentConfig config,
|
||||||
in int factorySerialNumber);
|
in int factorySerialNumber);
|
||||||
|
|
||||||
|
|||||||
@@ -44,9 +44,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public abstract class NetworkAgent {
|
public abstract class NetworkAgent {
|
||||||
// Guaranteed to be valid (not NETID_UNSET), otherwise registerNetworkAgent() would have thrown
|
// Guaranteed to be non-null, otherwise registerNetworkAgent() would have thrown
|
||||||
// an exception.
|
// an exception. Be careful in tests when mocking though.
|
||||||
public final int netId;
|
@NonNull
|
||||||
|
public final Network network;
|
||||||
|
|
||||||
private final Handler mHandler;
|
private final Handler mHandler;
|
||||||
private volatile AsyncChannel mAsyncChannel;
|
private volatile AsyncChannel mAsyncChannel;
|
||||||
@@ -246,7 +247,7 @@ public abstract class NetworkAgent {
|
|||||||
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(mHandler), new NetworkInfo(ni),
|
network = cm.registerNetworkAgent(new Messenger(mHandler), new NetworkInfo(ni),
|
||||||
new LinkProperties(lp), new NetworkCapabilities(nc), score, config,
|
new LinkProperties(lp), new NetworkCapabilities(nc), score, config,
|
||||||
providerId);
|
providerId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5505,7 +5505,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, NetworkAgentConfig networkAgentConfig) {
|
int currentScore, NetworkAgentConfig networkAgentConfig) {
|
||||||
return registerNetworkAgent(messenger, networkInfo, linkProperties, networkCapabilities,
|
return registerNetworkAgent(messenger, networkInfo, linkProperties, networkCapabilities,
|
||||||
@@ -5526,8 +5529,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
* {@link NetworkAgentInfo#getCurrentScore}.
|
* {@link NetworkAgentInfo#getCurrentScore}.
|
||||||
* @param networkAgentConfig metadata about the network. This is never updated.
|
* @param networkAgentConfig 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, NetworkAgentConfig networkAgentConfig, int providerId) {
|
int currentScore, NetworkAgentConfig networkAgentConfig, int providerId) {
|
||||||
enforceNetworkFactoryPermission();
|
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
|
// 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) {
|
||||||
|
|||||||
@@ -218,7 +218,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -337,7 +337,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