Extract logging of default network events
This patch extracts the logging of DefaultNetworkEvent from inside ConnectivityService and move it to a new DefaultNetworkMetrics class. The DefaultNetworkMetrics is a singleton owned by the IpConnectivityMetrics singleton implementing the metrics service for core networking. ConnectivityService has access to this singleton via LocalServices. This class layout will allow to remove the Parcelable interface of DefaultNetworkEvent and will instead let the IpConnectivityMetrics service grab metrics from the DefaultNetworkMetrics directly. Bug: 34901696 Test: runtest frameworks-net Change-Id: I55694d89124272732aba114198776462372de18b
This commit is contained in:
@@ -71,7 +71,6 @@ import android.net.ProxyInfo;
|
||||
import android.net.RouteInfo;
|
||||
import android.net.UidRange;
|
||||
import android.net.Uri;
|
||||
import android.net.metrics.DefaultNetworkEvent;
|
||||
import android.net.metrics.IpConnectivityLog;
|
||||
import android.net.metrics.NetworkEvent;
|
||||
import android.net.util.MultinetworkPolicyTracker;
|
||||
@@ -129,6 +128,7 @@ import com.android.internal.util.XmlUtils;
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.am.BatteryStatsService;
|
||||
import com.android.server.connectivity.DataConnectionStats;
|
||||
import com.android.server.connectivity.IpConnectivityMetrics;
|
||||
import com.android.server.connectivity.KeepaliveTracker;
|
||||
import com.android.server.connectivity.LingerMonitor;
|
||||
import com.android.server.connectivity.MockableSystemProperties;
|
||||
@@ -2283,7 +2283,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
// Let rematchAllNetworksAndRequests() below record a new default network event
|
||||
// if there is a fallback. Taken together, the two form a X -> 0, 0 -> Y sequence
|
||||
// whose timestamps tell how long it takes to recover a default network.
|
||||
logDefaultNetworkEvent(null, nai);
|
||||
metricsLogger().defaultNetworkMetrics().logDefaultNetworkEvent(null, nai);
|
||||
}
|
||||
notifyIfacesChangedForNetworkStats();
|
||||
// TODO - we shouldn't send CALLBACK_LOST to requests that can be satisfied
|
||||
@@ -5012,7 +5012,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
// Notify system services that this network is up.
|
||||
makeDefault(newNetwork);
|
||||
// Log 0 -> X and Y -> X default network transitions, where X is the new default.
|
||||
logDefaultNetworkEvent(newNetwork, oldDefaultNetwork);
|
||||
metricsLogger().defaultNetworkMetrics().logDefaultNetworkEvent(
|
||||
newNetwork, oldDefaultNetwork);
|
||||
// Have a new default network, release the transition wakelock in
|
||||
scheduleReleaseNetworkTransitionWakelock();
|
||||
}
|
||||
@@ -5571,25 +5572,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
return ServiceManager.checkService(name) != null;
|
||||
}
|
||||
|
||||
private void logDefaultNetworkEvent(NetworkAgentInfo newNai, NetworkAgentInfo prevNai) {
|
||||
int newNetid = NETID_UNSET;
|
||||
int prevNetid = NETID_UNSET;
|
||||
int[] transports = new int[0];
|
||||
boolean hadIPv4 = false;
|
||||
boolean hadIPv6 = false;
|
||||
|
||||
if (newNai != null) {
|
||||
newNetid = newNai.network.netId;
|
||||
transports = newNai.networkCapabilities.getTransportTypes();
|
||||
}
|
||||
if (prevNai != null) {
|
||||
prevNetid = prevNai.network.netId;
|
||||
final LinkProperties lp = prevNai.linkProperties;
|
||||
hadIPv4 = lp.hasIPv4Address() && lp.hasIPv4DefaultRoute();
|
||||
hadIPv6 = lp.hasGlobalIPv6Address() && lp.hasIPv6DefaultRoute();
|
||||
}
|
||||
|
||||
mMetricsLog.log(new DefaultNetworkEvent(newNetid, transports, prevNetid, hadIPv4, hadIPv6));
|
||||
@VisibleForTesting
|
||||
protected IpConnectivityMetrics.Logger metricsLogger() {
|
||||
return checkNotNull(LocalServices.getService(IpConnectivityMetrics.Logger.class),
|
||||
"no IpConnectivityMetrics service");
|
||||
}
|
||||
|
||||
private void logNetworkEvent(NetworkAgentInfo nai, int evtype) {
|
||||
|
||||
@@ -104,6 +104,8 @@ import android.util.LogPrinter;
|
||||
import com.android.internal.util.WakeupMessage;
|
||||
import com.android.internal.util.test.BroadcastInterceptingContext;
|
||||
import com.android.internal.util.test.FakeSettingsProvider;
|
||||
import com.android.server.connectivity.DefaultNetworkMetrics;
|
||||
import com.android.server.connectivity.IpConnectivityMetrics;
|
||||
import com.android.server.connectivity.MockableSystemProperties;
|
||||
import com.android.server.connectivity.NetworkAgentInfo;
|
||||
import com.android.server.connectivity.NetworkMonitor;
|
||||
@@ -156,6 +158,9 @@ public class ConnectivityServiceTest {
|
||||
private MockNetworkAgent mEthernetNetworkAgent;
|
||||
private Context mContext;
|
||||
|
||||
@Mock IpConnectivityMetrics.Logger mMetricsService;
|
||||
@Mock DefaultNetworkMetrics mDefaultNetworkMetrics;
|
||||
|
||||
// This class exists to test bindProcessToNetwork and getBoundNetworkForProcess. These methods
|
||||
// do not go through ConnectivityService but talk to netd directly, so they don't automatically
|
||||
// reflect the state of our test ConnectivityService.
|
||||
@@ -805,6 +810,11 @@ public class ConnectivityServiceTest {
|
||||
return Context.ETHERNET_SERVICE.equals(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IpConnectivityMetrics.Logger metricsLogger() {
|
||||
return mMetricsService;
|
||||
}
|
||||
|
||||
public WrappedNetworkMonitor getLastCreatedWrappedNetworkMonitor() {
|
||||
return mLastCreatedNetworkMonitor;
|
||||
}
|
||||
@@ -833,6 +843,9 @@ public class ConnectivityServiceTest {
|
||||
public void setUp() throws Exception {
|
||||
mContext = InstrumentationRegistry.getContext();
|
||||
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mMetricsService.defaultNetworkMetrics()).thenReturn(mDefaultNetworkMetrics);
|
||||
|
||||
// InstrumentationTestRunner prepares a looper, but AndroidJUnitRunner does not.
|
||||
// http://b/25897652 .
|
||||
if (Looper.myLooper() == null) {
|
||||
|
||||
Reference in New Issue
Block a user