Merge changes I49a76582,Iac4b75bc into cw-f-dev
* changes: DO NOT MERGE ANYWHERE ConnectivityService: move reportNetworkConnectivity to handler DO NOT MERGE ANYWHERE ConnectivityService: safer locking
This commit is contained in:
committed by
Android (Google) Code Review
commit
f18599a15b
@@ -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;
|
||||||
@@ -1327,14 +1332,17 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
@Override
|
@Override
|
||||||
public LinkProperties getLinkProperties(Network network) {
|
public LinkProperties getLinkProperties(Network network) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
|
return getLinkProperties(getNetworkAgentInfoForNetwork(network));
|
||||||
if (nai != null) {
|
}
|
||||||
|
|
||||||
|
private LinkProperties getLinkProperties(NetworkAgentInfo nai) {
|
||||||
|
if (nai == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
synchronized (nai) {
|
synchronized (nai) {
|
||||||
return new LinkProperties(nai.linkProperties);
|
return new LinkProperties(nai.linkProperties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private NetworkCapabilities getNetworkCapabilitiesInternal(NetworkAgentInfo nai) {
|
private NetworkCapabilities getNetworkCapabilitiesInternal(NetworkAgentInfo nai) {
|
||||||
if (nai != null) {
|
if (nai != null) {
|
||||||
@@ -2996,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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3168,8 +3181,15 @@ 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));
|
||||||
|
}
|
||||||
|
|
||||||
NetworkAgentInfo nai;
|
private void handleReportNetworkConnectivity(
|
||||||
|
Network network, int uid, boolean hasConnectivity) {
|
||||||
|
final NetworkAgentInfo nai;
|
||||||
if (network == null) {
|
if (network == null) {
|
||||||
nai = getDefaultNetwork();
|
nai = getDefaultNetwork();
|
||||||
} else {
|
} else {
|
||||||
@@ -3180,21 +3200,23 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Revalidate if the app report does not match our current validated state.
|
// Revalidate if the app report does not match our current validated state.
|
||||||
if (hasConnectivity == nai.lastValidated) return;
|
if (hasConnectivity == nai.lastValidated) {
|
||||||
final int uid = Binder.getCallingUid();
|
return;
|
||||||
if (DBG) {
|
}
|
||||||
log("reportNetworkConnectivity(" + nai.network.netId + ", " + hasConnectivity +
|
if (DBG) {
|
||||||
") by " + uid);
|
int netid = nai.network.netId;
|
||||||
|
log("reportNetworkConnectivity(" + netid + ", " + hasConnectivity + ") by " + uid);
|
||||||
}
|
}
|
||||||
synchronized (nai) {
|
|
||||||
// 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.
|
||||||
if (!nai.everConnected) return;
|
if (!nai.everConnected) {
|
||||||
|
return;
|
||||||
if (isNetworkWithLinkPropertiesBlocked(nai.linkProperties, uid, false)) return;
|
|
||||||
|
|
||||||
nai.networkMonitor.sendMessage(NetworkMonitor.CMD_FORCE_REEVALUATION, uid);
|
|
||||||
}
|
}
|
||||||
|
LinkProperties lp = getLinkProperties(nai);
|
||||||
|
if (isNetworkWithLinkPropertiesBlocked(lp, uid, false)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nai.networkMonitor.sendMessage(NetworkMonitor.CMD_FORCE_REEVALUATION, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProxyInfo getDefaultProxy() {
|
private ProxyInfo getDefaultProxy() {
|
||||||
|
|||||||
Reference in New Issue
Block a user