From f78548d22255e0007e673b7e2a227c4977a99d7c Mon Sep 17 00:00:00 2001 From: Hugo Benichi Date: Mon, 29 Jan 2018 14:00:44 +0900 Subject: [PATCH 1/2] Prevent crash in NetworkManagementServiceTest#shutdown() The shutdown method in NetworkManagementServiceTest was trying to close the local socket on the test side, causing the NativeDaemonConnector internal to NetworkManagementService to sometime crash due to the output stream on NetworkManagementService side to throw on pending reads. The correct fix would be to shutdown the NativeDaemonConnector inside NetworkManagementService and implement NetworkManagementService's shutdown method, however there is no way to cleanly close a NativeDaemonConnector. Instead, this patch doesn't do any cleanup of the listening socket, the test local socket, and its output stream. These objects' resources get eventually collected by the system when the test process exits. Test: runtest frameworks-net Change-Id: I72c9aa43403754b55e9d23bf4f3ba8b7b4a3e10a --- .../com/android/server/NetworkManagementServiceTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/net/java/com/android/server/NetworkManagementServiceTest.java b/tests/net/java/com/android/server/NetworkManagementServiceTest.java index 2ac73dbd4f..56a075be47 100644 --- a/tests/net/java/com/android/server/NetworkManagementServiceTest.java +++ b/tests/net/java/com/android/server/NetworkManagementServiceTest.java @@ -99,8 +99,12 @@ public class NetworkManagementServiceTest { @After public void tearDown() throws Exception { - if (mSocket != null) mSocket.close(); - if (mServerSocket != null) mServerSocket.close(); + mNMService.shutdown(); + // Once NetworkManagementService#shutdown() actually does something and shutdowns + // the underlying NativeDaemonConnector, the block below should be uncommented. + // if (mOutputStream != null) mOutputStream.close(); + // if (mSocket != null) mSocket.close(); + // if (mServerSocket != null) mServerSocket.close(); } /** From 11f04e863e808cfc98c9281c261bf6f3cd5bb56b Mon Sep 17 00:00:00 2001 From: Hugo Benichi Date: Thu, 14 Dec 2017 09:56:04 +0900 Subject: [PATCH 2/2] Fix default network validation overcounting When switching from a validated default network to a new validated default network (typically because of a better score), DefaultNetworkMetrics would not reset the last validation timestamp. This would cause the new default network to have a total recorded validation time overcounted by the validation time of the previous default network. The following fix should be applied downstream for consumers of previously recorded data: validation_time = min validation_time, duration_time); Test: runtest -x frameworks/base/tests/net/../IpConnectivityMetricsTest Change-Id: I303d11023527c19435f5f5e796a0295ae3f76d9f --- .../server/connectivity/IpConnectivityMetricsTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/net/java/com/android/server/connectivity/IpConnectivityMetricsTest.java b/tests/net/java/com/android/server/connectivity/IpConnectivityMetricsTest.java index 9f2cb921ea..8359fe2a8f 100644 --- a/tests/net/java/com/android/server/connectivity/IpConnectivityMetricsTest.java +++ b/tests/net/java/com/android/server/connectivity/IpConnectivityMetricsTest.java @@ -66,7 +66,6 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -175,7 +174,6 @@ public class IpConnectivityMetricsTest { } @Test - @Ignore public void testDefaultNetworkEvents() throws Exception { final long cell = BitUtils.packBits(new int[]{NetworkCapabilities.TRANSPORT_CELLULAR}); final long wifi = BitUtils.packBits(new int[]{NetworkCapabilities.TRANSPORT_WIFI}); @@ -294,7 +292,6 @@ public class IpConnectivityMetricsTest { } @Test - @Ignore public void testEndToEndLogging() throws Exception { // TODO: instead of comparing textpb to textpb, parse textpb and compare proto to proto. IpConnectivityLog logger = new IpConnectivityLog(mService.impl); @@ -635,6 +632,7 @@ public class IpConnectivityMetricsTest { when(nai.getCurrentScore()).thenReturn(score); nai.linkProperties = new LinkProperties(); nai.networkCapabilities = new NetworkCapabilities(); + nai.lastValidated = true; for (int t : BitUtils.unpackBits(transports)) { nai.networkCapabilities.addTransportType(t); }