[NS A23] Move a synchronized block in a central place
As the calls to this apparently need to be synchronized, let's do it all in the same place instead of in all callers Test: FrameworksNetTests Change-Id: I0c097e7756fc155ba0243834b84626e86c68340e
This commit is contained in:
@@ -5596,7 +5596,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
ns, mContext, mTrackerHandler, new NetworkMisc(networkMisc), this, mNetd,
|
ns, mContext, mTrackerHandler, new NetworkMisc(networkMisc), this, mNetd,
|
||||||
mDnsResolver, mNMS, factorySerialNumber);
|
mDnsResolver, mNMS, factorySerialNumber);
|
||||||
// Make sure the network capabilities reflect what the agent info says.
|
// Make sure the network capabilities reflect what the agent info says.
|
||||||
nai.setNetworkCapabilities(mixInCapabilities(nai, nc));
|
nai.getAndSetNetworkCapabilities(mixInCapabilities(nai, nc));
|
||||||
final String extraInfo = networkInfo.getExtraInfo();
|
final String extraInfo = networkInfo.getExtraInfo();
|
||||||
final String name = TextUtils.isEmpty(extraInfo)
|
final String name = TextUtils.isEmpty(extraInfo)
|
||||||
? nai.networkCapabilities.getSSID() : extraInfo;
|
? nai.networkCapabilities.getSSID() : extraInfo;
|
||||||
@@ -5950,11 +5950,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final NetworkCapabilities prevNc;
|
final NetworkCapabilities prevNc = nai.getAndSetNetworkCapabilities(newNc);
|
||||||
synchronized (nai) {
|
|
||||||
prevNc = nai.networkCapabilities;
|
|
||||||
nai.setNetworkCapabilities(newNc);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateUids(nai, prevNc, newNc);
|
updateUids(nai, prevNc, newNc);
|
||||||
|
|
||||||
@@ -6476,6 +6472,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// before LegacyTypeTracker sends legacy broadcasts
|
// before LegacyTypeTracker sends legacy broadcasts
|
||||||
for (NetworkRequestInfo nri : addedRequests) notifyNetworkAvailable(newNetwork, nri);
|
for (NetworkRequestInfo nri : addedRequests) notifyNetworkAvailable(newNetwork, nri);
|
||||||
|
|
||||||
|
// Finally, process listen requests and update capabilities if the background state has
|
||||||
|
// changed for this network. For consistency with previous behavior, send onLost callbacks
|
||||||
|
// before onAvailable.
|
||||||
|
processNewlyLostListenRequests(newNetwork);
|
||||||
|
|
||||||
// Maybe the network changed background states. Update its capabilities.
|
// Maybe the network changed background states. Update its capabilities.
|
||||||
final boolean backgroundChanged = wasBackgroundNetwork != newNetwork.isBackgroundNetwork();
|
final boolean backgroundChanged = wasBackgroundNetwork != newNetwork.isBackgroundNetwork();
|
||||||
if (backgroundChanged) {
|
if (backgroundChanged) {
|
||||||
@@ -6492,13 +6493,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (newNetwork) {
|
newNetwork.getAndSetNetworkCapabilities(newNc);
|
||||||
newNetwork.setNetworkCapabilities(newNc);
|
notifyNetworkCallbacks(newNetwork, ConnectivityManager.CALLBACK_CAP_CHANGED);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, process listen requests.
|
processNewlySatisfiedListenRequests(newNetwork);
|
||||||
processListenRequests(newNetwork, backgroundChanged);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6683,9 +6682,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
// NetworkCapabilities need to be set before sending the private DNS config to
|
// NetworkCapabilities need to be set before sending the private DNS config to
|
||||||
// NetworkMonitor, otherwise NetworkMonitor cannot determine if validation is required.
|
// NetworkMonitor, otherwise NetworkMonitor cannot determine if validation is required.
|
||||||
synchronized (networkAgent) {
|
networkAgent.getAndSetNetworkCapabilities(networkAgent.networkCapabilities);
|
||||||
networkAgent.setNetworkCapabilities(networkAgent.networkCapabilities);
|
|
||||||
}
|
|
||||||
handlePerNetworkPrivateDnsConfig(networkAgent, mDnsManager.getPrivateDnsConfig());
|
handlePerNetworkPrivateDnsConfig(networkAgent, mDnsManager.getPrivateDnsConfig());
|
||||||
updateLinkProperties(networkAgent, new LinkProperties(networkAgent.linkProperties),
|
updateLinkProperties(networkAgent, new LinkProperties(networkAgent.linkProperties),
|
||||||
null);
|
null);
|
||||||
|
|||||||
@@ -291,13 +291,18 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
|
|||||||
*
|
*
|
||||||
* <p>If {@link NetworkMonitor#notifyNetworkCapabilitiesChanged(NetworkCapabilities)} fails,
|
* <p>If {@link NetworkMonitor#notifyNetworkCapabilitiesChanged(NetworkCapabilities)} fails,
|
||||||
* the exception is logged but not reported to callers.
|
* the exception is logged but not reported to callers.
|
||||||
|
*
|
||||||
|
* @return the old capabilities of this network.
|
||||||
*/
|
*/
|
||||||
public void setNetworkCapabilities(NetworkCapabilities nc) {
|
public synchronized NetworkCapabilities getAndSetNetworkCapabilities(
|
||||||
|
@NonNull final NetworkCapabilities nc) {
|
||||||
|
final NetworkCapabilities oldNc = networkCapabilities;
|
||||||
networkCapabilities = nc;
|
networkCapabilities = nc;
|
||||||
final NetworkMonitorManager nm = mNetworkMonitor;
|
final NetworkMonitorManager nm = mNetworkMonitor;
|
||||||
if (nm != null) {
|
if (nm != null) {
|
||||||
nm.notifyNetworkCapabilitiesChanged(nc);
|
nm.notifyNetworkCapabilitiesChanged(nc);
|
||||||
}
|
}
|
||||||
|
return oldNc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectivityService connService() {
|
public ConnectivityService connService() {
|
||||||
|
|||||||
Reference in New Issue
Block a user