Merge "Convert booleans in NAI to timestamps"
This commit is contained in:
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -47,6 +48,7 @@ import android.net.metrics.RaEvent;
|
||||
import android.net.metrics.ValidationProbeEvent;
|
||||
import android.os.Build;
|
||||
import android.os.Parcelable;
|
||||
import android.os.SystemClock;
|
||||
import android.system.OsConstants;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.util.Base64;
|
||||
@@ -138,7 +140,7 @@ public class IpConnectivityMetricsTest {
|
||||
private void logDefaultNetworkEvent(long timeMs, NetworkAgentInfo nai,
|
||||
NetworkAgentInfo oldNai) {
|
||||
final Network network = (nai != null) ? nai.network() : null;
|
||||
final boolean validated = (nai != null) ? nai.lastValidated : false;
|
||||
final boolean validated = (nai != null) ? nai.isValidated() : false;
|
||||
final LinkProperties lp = (nai != null) ? nai.linkProperties : null;
|
||||
final NetworkCapabilities nc = (nai != null) ? nai.networkCapabilities : null;
|
||||
|
||||
@@ -614,7 +616,10 @@ public class IpConnectivityMetricsTest {
|
||||
when(nai.network()).thenReturn(new Network(netId));
|
||||
nai.linkProperties = new LinkProperties();
|
||||
nai.networkCapabilities = new NetworkCapabilities();
|
||||
nai.lastValidated = true;
|
||||
nai.setValidated(true);
|
||||
doReturn(true).when(nai).isValidated();
|
||||
doReturn(SystemClock.elapsedRealtime()).when(nai).getFirstValidationTime();
|
||||
doReturn(SystemClock.elapsedRealtime()).when(nai).getCurrentValidationTime();
|
||||
for (int t : BitUtils.unpackBits(transports)) {
|
||||
nai.networkCapabilities.addTransportType(t);
|
||||
}
|
||||
@@ -629,8 +634,6 @@ public class IpConnectivityMetricsTest {
|
||||
return nai;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void verifySerialization(String want, String output) {
|
||||
try {
|
||||
byte[] got = Base64.decode(output, Base64.DEFAULT);
|
||||
|
||||
@@ -272,9 +272,8 @@ public class LingerMonitorTest {
|
||||
public void testIgnoreNeverValidatedNetworks() {
|
||||
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
|
||||
setNotificationSwitch(transition(WIFI, CELLULAR));
|
||||
NetworkAgentInfo from = wifiNai(100);
|
||||
NetworkAgentInfo from = wifiNai(100, false /* setEverValidated */);
|
||||
NetworkAgentInfo to = cellNai(101);
|
||||
from.everValidated = false;
|
||||
|
||||
mMonitor.noteLingerDefaultNetwork(from, to);
|
||||
verifyNoNotifications();
|
||||
@@ -286,7 +285,7 @@ public class LingerMonitorTest {
|
||||
setNotificationSwitch(transition(WIFI, CELLULAR));
|
||||
NetworkAgentInfo from = wifiNai(100);
|
||||
NetworkAgentInfo to = cellNai(101);
|
||||
from.lastValidated = true;
|
||||
from.setValidated(true);
|
||||
|
||||
mMonitor.noteLingerDefaultNetwork(from, to);
|
||||
verifyNoNotifications();
|
||||
@@ -363,7 +362,8 @@ public class LingerMonitorTest {
|
||||
eq(NotificationType.NETWORK_SWITCH), eq(from), eq(to), any(), eq(true));
|
||||
}
|
||||
|
||||
NetworkAgentInfo nai(int netId, int transport, int networkType, String networkTypeName) {
|
||||
NetworkAgentInfo nai(int netId, int transport, int networkType, String networkTypeName,
|
||||
boolean setEverValidated) {
|
||||
NetworkInfo info = new NetworkInfo(networkType, 0, networkTypeName, "");
|
||||
NetworkCapabilities caps = new NetworkCapabilities();
|
||||
caps.addCapability(0);
|
||||
@@ -373,18 +373,32 @@ public class LingerMonitorTest {
|
||||
mCtx, null, new NetworkAgentConfig.Builder().build(), mConnService, mNetd,
|
||||
mDnsResolver, NetworkProvider.ID_NONE, Binder.getCallingUid(), TEST_LINGER_DELAY_MS,
|
||||
mQosCallbackTracker, new ConnectivityService.Dependencies());
|
||||
nai.everValidated = true;
|
||||
if (setEverValidated) {
|
||||
// As tests in this class deal with testing lingering, most tests are interested
|
||||
// in networks that can be lingered, and therefore must have validated in the past.
|
||||
// Thus, pretend the network validated once, then became invalidated.
|
||||
nai.setValidated(true);
|
||||
nai.setValidated(false);
|
||||
}
|
||||
return nai;
|
||||
}
|
||||
|
||||
NetworkAgentInfo wifiNai(int netId) {
|
||||
return wifiNai(netId, true /* setEverValidated */);
|
||||
}
|
||||
|
||||
NetworkAgentInfo wifiNai(int netId, boolean setEverValidated) {
|
||||
return nai(netId, NetworkCapabilities.TRANSPORT_WIFI,
|
||||
ConnectivityManager.TYPE_WIFI, WIFI);
|
||||
ConnectivityManager.TYPE_WIFI, WIFI, setEverValidated);
|
||||
}
|
||||
|
||||
NetworkAgentInfo cellNai(int netId) {
|
||||
return cellNai(netId, true /* setEverValidated */);
|
||||
}
|
||||
|
||||
NetworkAgentInfo cellNai(int netId, boolean setEverValidated) {
|
||||
return nai(netId, NetworkCapabilities.TRANSPORT_CELLULAR,
|
||||
ConnectivityManager.TYPE_MOBILE, CELLULAR);
|
||||
ConnectivityManager.TYPE_MOBILE, CELLULAR, setEverValidated);
|
||||
}
|
||||
|
||||
public static class TestableLingerMonitor extends LingerMonitor {
|
||||
|
||||
Reference in New Issue
Block a user