DO NOT MERGE ANYWHERE ConnectivityService: move reportNetworkConnectivity to handler
This patch moves reportNetworkConnectivity onto the handler of
ConnectivityService.
This allows:
- to inspect NetworkAgentInfo on the ConnectivityService handler,
which is always more correct than doing so on a Binder thread.
- to improve locking policies around NetworkAgentInfo.
Test: $ runtest frameworks-net
Bug: 37119619, 36902662
Change-Id: I49a765826e65c29a1995242290e5e7544112c94e
This commit is contained in:
committed by
Andriy Naborskyy
parent
57af1a02a6
commit
1681f064ff
@@ -372,11 +372,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
*/
|
*/
|
||||||
private static final int EVENT_SET_ACCEPT_UNVALIDATED = 28;
|
private static final int EVENT_SET_ACCEPT_UNVALIDATED = 28;
|
||||||
|
|
||||||
/**
|
|
||||||
* used to specify whether a network should not be penalized when it becomes unvalidated.
|
|
||||||
*/
|
|
||||||
private static final int EVENT_SET_AVOID_UNVALIDATED = 35;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used to ask the user to confirm a connection to an unvalidated network.
|
* used to ask the user to confirm a connection to an unvalidated network.
|
||||||
* obj = network
|
* obj = network
|
||||||
@@ -404,6 +399,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
private static final int EVENT_REQUEST_LINKPROPERTIES = 32;
|
private static final int EVENT_REQUEST_LINKPROPERTIES = 32;
|
||||||
private static final int EVENT_REQUEST_NETCAPABILITIES = 33;
|
private static final int EVENT_REQUEST_NETCAPABILITIES = 33;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* used to specify whether a network should not be penalized when it becomes unvalidated.
|
||||||
|
*/
|
||||||
|
private static final int EVENT_SET_AVOID_UNVALIDATED = 35;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* used to trigger revalidation of a network.
|
||||||
|
*/
|
||||||
|
private static final int EVENT_REVALIDATE_NETWORK = 36;
|
||||||
|
|
||||||
/** Handler thread used for both of the handlers below. */
|
/** Handler thread used for both of the handlers below. */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected final HandlerThread mHandlerThread;
|
protected final HandlerThread mHandlerThread;
|
||||||
@@ -2999,6 +3004,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case EVENT_REVALIDATE_NETWORK: {
|
||||||
|
boolean hasConnectivity = (msg.arg2 == 1);
|
||||||
|
handleReportNetworkConnectivity((Network) msg.obj, msg.arg1, hasConnectivity);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3171,8 +3181,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
public void reportNetworkConnectivity(Network network, boolean hasConnectivity) {
|
public void reportNetworkConnectivity(Network network, boolean hasConnectivity) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
enforceInternetPermission();
|
enforceInternetPermission();
|
||||||
|
final int uid = Binder.getCallingUid();
|
||||||
|
final int connectivityInfo = hasConnectivity ? 1 : 0;
|
||||||
|
mHandler.sendMessage(
|
||||||
|
mHandler.obtainMessage(EVENT_REVALIDATE_NETWORK, uid, connectivityInfo, network));
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: execute this logic on ConnectivityService handler.
|
private void handleReportNetworkConnectivity(
|
||||||
|
Network network, int uid, boolean hasConnectivity) {
|
||||||
final NetworkAgentInfo nai;
|
final NetworkAgentInfo nai;
|
||||||
if (network == null) {
|
if (network == null) {
|
||||||
nai = getDefaultNetwork();
|
nai = getDefaultNetwork();
|
||||||
@@ -3187,10 +3203,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (hasConnectivity == nai.lastValidated) {
|
if (hasConnectivity == nai.lastValidated) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int uid = Binder.getCallingUid();
|
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
log("reportNetworkConnectivity(" + nai.network.netId + ", " + hasConnectivity +
|
int netid = nai.network.netId;
|
||||||
") by " + uid);
|
log("reportNetworkConnectivity(" + netid + ", " + hasConnectivity + ") by " + uid);
|
||||||
}
|
}
|
||||||
// Validating a network that has not yet connected could result in a call to
|
// Validating a network that has not yet connected could result in a call to
|
||||||
// rematchNetworkAndRequests() which is not meant to work on such networks.
|
// rematchNetworkAndRequests() which is not meant to work on such networks.
|
||||||
|
|||||||
Reference in New Issue
Block a user