Merge "Fix race when starting NetworkMonitor" am: ef8485cc65 am: ea71c49a0e

am: 3a8102ab8e

Change-Id: I595ecdbf0b8e91fec4287c3476239a1e6c9c80a7
This commit is contained in:
Remi NGUYEN VAN
2019-03-31 21:35:25 -07:00
committed by android-build-merger
3 changed files with 32 additions and 20 deletions

View File

@@ -5385,7 +5385,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
mContext, mTrackerHandler, new NetworkMisc(networkMisc), this, mNetd, mDnsResolver,
mNMS, factorySerialNumber);
// Make sure the network capabilities reflect what the agent info says.
nai.networkCapabilities = mixInCapabilities(nai, nc);
nai.setNetworkCapabilities(mixInCapabilities(nai, nc));
final String extraInfo = networkInfo.getExtraInfo();
final String name = TextUtils.isEmpty(extraInfo)
? nai.networkCapabilities.getSSID() : extraInfo;
@@ -5478,12 +5478,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
// Start or stop DNS64 detection and 464xlat according to network state.
networkAgent.clatd.update();
notifyIfacesChangedForNetworkStats();
try {
networkAgent.networkMonitor().notifyLinkPropertiesChanged(newLp);
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
if (networkAgent.everConnected) {
try {
networkAgent.networkMonitor().notifyLinkPropertiesChanged();
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
notifyNetworkCallbacks(networkAgent, ConnectivityManager.CALLBACK_IP_CHANGED);
}
}
@@ -5711,7 +5711,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
final NetworkCapabilities prevNc;
synchronized (nai) {
prevNc = nai.networkCapabilities;
nai.networkCapabilities = newNc;
nai.setNetworkCapabilities(newNc);
}
updateUids(nai, prevNc, newNc);
@@ -5726,11 +5726,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
// If the requestable capabilities have changed or the score changed, we can't have been
// called by rematchNetworkAndRequests, so it's safe to start a rematch.
rematchAllNetworksAndRequests(nai, oldScore);
try {
nai.networkMonitor().notifyNetworkCapabilitiesChanged();
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
notifyNetworkCallbacks(nai, ConnectivityManager.CALLBACK_CAP_CHANGED);
}
@@ -5989,11 +5984,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
if (capabilitiesChanged) {
try {
nai.networkMonitor().notifyNetworkCapabilitiesChanged();
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
notifyNetworkCallbacks(nai, ConnectivityManager.CALLBACK_CAP_CHANGED);
}
@@ -6402,7 +6392,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
if (networkAgent.networkMisc.acceptPartialConnectivity) {
networkAgent.networkMonitor().setAcceptPartialConnectivity();
}
networkAgent.networkMonitor().notifyNetworkConnected();
networkAgent.networkMonitor().notifyNetworkConnected(
networkAgent.linkProperties, networkAgent.networkCapabilities);
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}

View File

@@ -30,6 +30,7 @@ import android.net.NetworkState;
import android.os.Handler;
import android.os.INetworkManagementService;
import android.os.Messenger;
import android.os.RemoteException;
import android.os.SystemClock;
import android.util.Log;
import android.util.SparseArray;
@@ -121,7 +122,8 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
// This Network object is always valid.
public final Network network;
public LinkProperties linkProperties;
// This should only be modified via ConnectivityService.updateCapabilities().
// This should only be modified by ConnectivityService, via setNetworkCapabilities().
// TODO: make this private with a getter.
public NetworkCapabilities networkCapabilities;
public final NetworkMisc networkMisc;
// Indicates if netd has been told to create this Network. From this point on the appropriate
@@ -279,6 +281,25 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
mNetworkMonitor = networkMonitor;
}
/**
* Set the NetworkCapabilities on this NetworkAgentInfo. Also attempts to notify NetworkMonitor
* of the new capabilities, if NetworkMonitor has been created.
*
* <p>If {@link NetworkMonitor#notifyNetworkCapabilitiesChanged(NetworkCapabilities)} fails,
* the exception is logged but not reported to callers.
*/
public void setNetworkCapabilities(NetworkCapabilities nc) {
networkCapabilities = nc;
final INetworkMonitor nm = mNetworkMonitor;
if (nm != null) {
try {
nm.notifyNetworkCapabilitiesChanged(nc);
} catch (RemoteException e) {
Log.e(TAG, "Error notifying NetworkMonitor of updated NetworkCapabilities", e);
}
}
}
public ConnectivityService connService() {
return mConnService;
}

View File

@@ -499,7 +499,7 @@ public class ConnectivityServiceTest {
};
try {
doAnswer(validateAnswer).when(mNetworkMonitor).notifyNetworkConnected();
doAnswer(validateAnswer).when(mNetworkMonitor).notifyNetworkConnected(any(), any());
doAnswer(validateAnswer).when(mNetworkMonitor).forceReevaluation(anyInt());
} catch (RemoteException e) {
fail(e.getMessage());