Loading core/tests/batterystatstests/BatteryStatsLoadTests/src/com/android/frameworks/core/batterystatsloadtests/ConnectivitySetupRule.java +1 −3 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import static org.junit.Assert.assertEquals; import android.app.Instrumentation; import android.content.Context; import android.net.ConnectivityManager; import android.net.LinkProperties; import android.net.Network; import android.net.NetworkCapabilities; import android.net.NetworkRequest; Loading Loading @@ -128,8 +127,7 @@ public class ConnectivitySetupRule implements TestRule { } @Override public void onAvailable(Network network, NetworkCapabilities networkCapabilities, LinkProperties linkProperties, boolean blocked) { public void onAvailable(Network network) { checkActiveNetwork(); } Loading core/tests/coretests/src/android/net/SntpClientTest.java +6 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,9 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.mockito.Mockito.CALLS_REAL_METHODS; import static org.mockito.Mockito.mock; import android.util.Log; import androidx.test.runner.AndroidJUnit4; Loading Loading @@ -73,8 +76,9 @@ public class SntpClientTest { @Before public void setUp() throws Exception { // NETID_UNSET allows the test to run, with a loopback server, even w/o external networking mNetwork = new Network(ConnectivityManager.NETID_UNSET); // A mock network has NETID_UNSET, which allows the test to run, with a loopback server, // even w/o external networking. mNetwork = mock(Network.class, CALLS_REAL_METHODS); mServer = new SntpTestServer(); mClient = new SntpClient(); } Loading services/tests/servicestests/src/com/android/server/net/IpConfigStoreTest.java +29 −12 Original line number Diff line number Diff line Loading @@ -39,6 +39,8 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.InetAddress; import java.util.ArrayList; import java.util.Arrays; /** Loading @@ -53,8 +55,8 @@ public class IpConfigStoreTest { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream outputStream = new DataOutputStream(byteStream); IpConfiguration expectedConfig = new IpConfiguration(IpAssignment.DHCP, ProxySettings.NONE, null, null); final IpConfiguration expectedConfig = newIpConfiguration(IpAssignment.DHCP, ProxySettings.NONE, null, null); // Emulate writing to old format. writeDhcpConfigV2(outputStream, KEY_CONFIG, expectedConfig); Loading @@ -78,18 +80,23 @@ public class IpConfigStoreTest { final String DNS_IP_ADDR_1 = "1.2.3.4"; final String DNS_IP_ADDR_2 = "5.6.7.8"; StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration(); staticIpConfiguration.ipAddress = new LinkAddress(IP_ADDR_1); staticIpConfiguration.dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_1)); staticIpConfiguration.dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_2)); final ArrayList<InetAddress> dnsServers = new ArrayList<>(); dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_1)); dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_2)); final StaticIpConfiguration staticIpConfiguration1 = new StaticIpConfiguration.Builder() .setIpAddress(new LinkAddress(IP_ADDR_1)) .setDnsServers(dnsServers).build(); final StaticIpConfiguration staticIpConfiguration2 = new StaticIpConfiguration.Builder() .setIpAddress(new LinkAddress(IP_ADDR_2)) .setDnsServers(dnsServers).build(); ProxyInfo proxyInfo = ProxyInfo.buildDirectProxy("10.10.10.10", 88, Arrays.asList("host1", "host2")); IpConfiguration expectedConfig1 = newIpConfiguration(IpAssignment.STATIC, ProxySettings.STATIC, staticIpConfiguration, proxyInfo); IpConfiguration expectedConfig2 = new IpConfiguration(expectedConfig1); expectedConfig2.getStaticIpConfiguration().ipAddress = new LinkAddress(IP_ADDR_2); ProxySettings.STATIC, staticIpConfiguration1, proxyInfo); IpConfiguration expectedConfig2 = newIpConfiguration(IpAssignment.STATIC, ProxySettings.STATIC, staticIpConfiguration2, proxyInfo); ArrayMap<String, IpConfiguration> expectedNetworks = new ArrayMap<>(); expectedNetworks.put(IFACE_1, expectedConfig1); Loading @@ -107,14 +114,24 @@ public class IpConfigStoreTest { assertEquals(expectedNetworks.get(IFACE_2), actualNetworks.get(IFACE_2)); } private IpConfiguration newIpConfiguration(IpAssignment ipAssignment, ProxySettings proxySettings, StaticIpConfiguration staticIpConfig, ProxyInfo info) { final IpConfiguration config = new IpConfiguration(); config.setIpAssignment(ipAssignment); config.setProxySettings(proxySettings); config.setStaticIpConfiguration(staticIpConfig); config.setHttpProxy(info); return config; } // This is simplified snapshot of code that was used to store values in V2 format (key as int). private static void writeDhcpConfigV2(DataOutputStream out, int configKey, IpConfiguration config) throws IOException { out.writeInt(2); // VERSION 2 switch (config.ipAssignment) { switch (config.getIpAssignment()) { case DHCP: out.writeUTF("ipAssignment"); out.writeUTF(config.ipAssignment.toString()); out.writeUTF(config.getIpAssignment().toString()); break; default: fail("Not supported in test environment"); Loading services/tests/servicestests/src/com/android/server/net/NetworkPolicyManagerServiceTest.java +15 −15 Original line number Diff line number Diff line Loading @@ -87,6 +87,7 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.CALLS_REAL_METHODS; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.clearInvocations; Loading Loading @@ -226,7 +227,8 @@ public class NetworkPolicyManagerServiceTest { private static final String TEST_SSID = "AndroidAP"; private static final String TEST_IMSI = "310210"; private static final int TEST_SUB_ID = 42; private static final int TEST_NET_ID = 24; private static final Network TEST_NETWORK = mock(Network.class, CALLS_REAL_METHODS); private static NetworkTemplate sTemplateWifi = buildTemplateWifi(TEST_SSID); private static NetworkTemplate sTemplateMobileAll = buildTemplateMobileAll(TEST_IMSI); Loading Loading @@ -1637,7 +1639,7 @@ public class NetworkPolicyManagerServiceTest { @Test public void testOpportunisticQuota() throws Exception { final Network net = new Network(TEST_NET_ID); final Network net = TEST_NETWORK; final NetworkPolicyManagerInternal internal = LocalServices .getService(NetworkPolicyManagerInternal.class); Loading Loading @@ -1759,11 +1761,10 @@ public class NetworkPolicyManagerServiceTest { assertNotNull(callback); expectNetworkStateSnapshot(true /* roaming */); callback.onCapabilitiesChanged( new Network(TEST_NET_ID), buildNetworkCapabilities(TEST_SUB_ID, true /* roaming */)); TEST_NETWORK, buildNetworkCapabilities(TEST_SUB_ID, true /* roaming */)); assertEquals(0, internal.getSubscriptionOpportunisticQuota( new Network(TEST_NET_ID), NetworkPolicyManagerInternal.QUOTA_TYPE_MULTIPATH)); TEST_NETWORK, NetworkPolicyManagerInternal.QUOTA_TYPE_MULTIPATH)); } } Loading Loading @@ -2013,14 +2014,14 @@ public class NetworkPolicyManagerServiceTest { } private NetworkCapabilities buildNetworkCapabilities(int subId, boolean roaming) { final NetworkCapabilities nc = new NetworkCapabilities(); nc.addTransportType(TRANSPORT_CELLULAR); final NetworkCapabilities.Builder builder = new NetworkCapabilities.Builder(); builder.addTransportType(TRANSPORT_CELLULAR); if (!roaming) { nc.addCapability(NET_CAPABILITY_NOT_ROAMING); builder.addCapability(NET_CAPABILITY_NOT_ROAMING); } nc.setNetworkSpecifier(new TelephonyNetworkSpecifier.Builder() builder.setNetworkSpecifier(new TelephonyNetworkSpecifier.Builder() .setSubscriptionId(subId).build()); return nc; return builder.build(); } private NetworkPolicy buildDefaultFakeMobilePolicy() { Loading Loading @@ -2061,10 +2062,9 @@ public class NetworkPolicyManagerServiceTest { private static NetworkStateSnapshot buildWifi() { final LinkProperties prop = new LinkProperties(); prop.setInterfaceName(TEST_IFACE); final NetworkCapabilities networkCapabilities = new NetworkCapabilities(); networkCapabilities.addTransportType(TRANSPORT_WIFI); networkCapabilities.setSSID(TEST_SSID); return new NetworkStateSnapshot(new Network(TEST_NET_ID), networkCapabilities, prop, final NetworkCapabilities networkCapabilities = new NetworkCapabilities.Builder() .addTransportType(TRANSPORT_WIFI).setSsid(TEST_SSID).build(); return new NetworkStateSnapshot(TEST_NETWORK, networkCapabilities, prop, null /*subscriberId*/, TYPE_WIFI); } Loading @@ -2086,7 +2086,7 @@ public class NetworkPolicyManagerServiceTest { when(mCarrierConfigManager.getConfigForSubId(eq(TEST_SUB_ID))) .thenReturn(mCarrierConfig); List<NetworkStateSnapshot> snapshots = List.of(new NetworkStateSnapshot( new Network(TEST_NET_ID), TEST_NETWORK, buildNetworkCapabilities(TEST_SUB_ID, roaming), buildLinkProperties(TEST_IFACE), TEST_IMSI, TYPE_MOBILE)); when(mConnManager.getAllNetworkStateSnapshot()).thenReturn(snapshots); Loading Loading
core/tests/batterystatstests/BatteryStatsLoadTests/src/com/android/frameworks/core/batterystatsloadtests/ConnectivitySetupRule.java +1 −3 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import static org.junit.Assert.assertEquals; import android.app.Instrumentation; import android.content.Context; import android.net.ConnectivityManager; import android.net.LinkProperties; import android.net.Network; import android.net.NetworkCapabilities; import android.net.NetworkRequest; Loading Loading @@ -128,8 +127,7 @@ public class ConnectivitySetupRule implements TestRule { } @Override public void onAvailable(Network network, NetworkCapabilities networkCapabilities, LinkProperties linkProperties, boolean blocked) { public void onAvailable(Network network) { checkActiveNetwork(); } Loading
core/tests/coretests/src/android/net/SntpClientTest.java +6 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,9 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.mockito.Mockito.CALLS_REAL_METHODS; import static org.mockito.Mockito.mock; import android.util.Log; import androidx.test.runner.AndroidJUnit4; Loading Loading @@ -73,8 +76,9 @@ public class SntpClientTest { @Before public void setUp() throws Exception { // NETID_UNSET allows the test to run, with a loopback server, even w/o external networking mNetwork = new Network(ConnectivityManager.NETID_UNSET); // A mock network has NETID_UNSET, which allows the test to run, with a loopback server, // even w/o external networking. mNetwork = mock(Network.class, CALLS_REAL_METHODS); mServer = new SntpTestServer(); mClient = new SntpClient(); } Loading
services/tests/servicestests/src/com/android/server/net/IpConfigStoreTest.java +29 −12 Original line number Diff line number Diff line Loading @@ -39,6 +39,8 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.InetAddress; import java.util.ArrayList; import java.util.Arrays; /** Loading @@ -53,8 +55,8 @@ public class IpConfigStoreTest { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream outputStream = new DataOutputStream(byteStream); IpConfiguration expectedConfig = new IpConfiguration(IpAssignment.DHCP, ProxySettings.NONE, null, null); final IpConfiguration expectedConfig = newIpConfiguration(IpAssignment.DHCP, ProxySettings.NONE, null, null); // Emulate writing to old format. writeDhcpConfigV2(outputStream, KEY_CONFIG, expectedConfig); Loading @@ -78,18 +80,23 @@ public class IpConfigStoreTest { final String DNS_IP_ADDR_1 = "1.2.3.4"; final String DNS_IP_ADDR_2 = "5.6.7.8"; StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration(); staticIpConfiguration.ipAddress = new LinkAddress(IP_ADDR_1); staticIpConfiguration.dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_1)); staticIpConfiguration.dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_2)); final ArrayList<InetAddress> dnsServers = new ArrayList<>(); dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_1)); dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_2)); final StaticIpConfiguration staticIpConfiguration1 = new StaticIpConfiguration.Builder() .setIpAddress(new LinkAddress(IP_ADDR_1)) .setDnsServers(dnsServers).build(); final StaticIpConfiguration staticIpConfiguration2 = new StaticIpConfiguration.Builder() .setIpAddress(new LinkAddress(IP_ADDR_2)) .setDnsServers(dnsServers).build(); ProxyInfo proxyInfo = ProxyInfo.buildDirectProxy("10.10.10.10", 88, Arrays.asList("host1", "host2")); IpConfiguration expectedConfig1 = newIpConfiguration(IpAssignment.STATIC, ProxySettings.STATIC, staticIpConfiguration, proxyInfo); IpConfiguration expectedConfig2 = new IpConfiguration(expectedConfig1); expectedConfig2.getStaticIpConfiguration().ipAddress = new LinkAddress(IP_ADDR_2); ProxySettings.STATIC, staticIpConfiguration1, proxyInfo); IpConfiguration expectedConfig2 = newIpConfiguration(IpAssignment.STATIC, ProxySettings.STATIC, staticIpConfiguration2, proxyInfo); ArrayMap<String, IpConfiguration> expectedNetworks = new ArrayMap<>(); expectedNetworks.put(IFACE_1, expectedConfig1); Loading @@ -107,14 +114,24 @@ public class IpConfigStoreTest { assertEquals(expectedNetworks.get(IFACE_2), actualNetworks.get(IFACE_2)); } private IpConfiguration newIpConfiguration(IpAssignment ipAssignment, ProxySettings proxySettings, StaticIpConfiguration staticIpConfig, ProxyInfo info) { final IpConfiguration config = new IpConfiguration(); config.setIpAssignment(ipAssignment); config.setProxySettings(proxySettings); config.setStaticIpConfiguration(staticIpConfig); config.setHttpProxy(info); return config; } // This is simplified snapshot of code that was used to store values in V2 format (key as int). private static void writeDhcpConfigV2(DataOutputStream out, int configKey, IpConfiguration config) throws IOException { out.writeInt(2); // VERSION 2 switch (config.ipAssignment) { switch (config.getIpAssignment()) { case DHCP: out.writeUTF("ipAssignment"); out.writeUTF(config.ipAssignment.toString()); out.writeUTF(config.getIpAssignment().toString()); break; default: fail("Not supported in test environment"); Loading
services/tests/servicestests/src/com/android/server/net/NetworkPolicyManagerServiceTest.java +15 −15 Original line number Diff line number Diff line Loading @@ -87,6 +87,7 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.CALLS_REAL_METHODS; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.clearInvocations; Loading Loading @@ -226,7 +227,8 @@ public class NetworkPolicyManagerServiceTest { private static final String TEST_SSID = "AndroidAP"; private static final String TEST_IMSI = "310210"; private static final int TEST_SUB_ID = 42; private static final int TEST_NET_ID = 24; private static final Network TEST_NETWORK = mock(Network.class, CALLS_REAL_METHODS); private static NetworkTemplate sTemplateWifi = buildTemplateWifi(TEST_SSID); private static NetworkTemplate sTemplateMobileAll = buildTemplateMobileAll(TEST_IMSI); Loading Loading @@ -1637,7 +1639,7 @@ public class NetworkPolicyManagerServiceTest { @Test public void testOpportunisticQuota() throws Exception { final Network net = new Network(TEST_NET_ID); final Network net = TEST_NETWORK; final NetworkPolicyManagerInternal internal = LocalServices .getService(NetworkPolicyManagerInternal.class); Loading Loading @@ -1759,11 +1761,10 @@ public class NetworkPolicyManagerServiceTest { assertNotNull(callback); expectNetworkStateSnapshot(true /* roaming */); callback.onCapabilitiesChanged( new Network(TEST_NET_ID), buildNetworkCapabilities(TEST_SUB_ID, true /* roaming */)); TEST_NETWORK, buildNetworkCapabilities(TEST_SUB_ID, true /* roaming */)); assertEquals(0, internal.getSubscriptionOpportunisticQuota( new Network(TEST_NET_ID), NetworkPolicyManagerInternal.QUOTA_TYPE_MULTIPATH)); TEST_NETWORK, NetworkPolicyManagerInternal.QUOTA_TYPE_MULTIPATH)); } } Loading Loading @@ -2013,14 +2014,14 @@ public class NetworkPolicyManagerServiceTest { } private NetworkCapabilities buildNetworkCapabilities(int subId, boolean roaming) { final NetworkCapabilities nc = new NetworkCapabilities(); nc.addTransportType(TRANSPORT_CELLULAR); final NetworkCapabilities.Builder builder = new NetworkCapabilities.Builder(); builder.addTransportType(TRANSPORT_CELLULAR); if (!roaming) { nc.addCapability(NET_CAPABILITY_NOT_ROAMING); builder.addCapability(NET_CAPABILITY_NOT_ROAMING); } nc.setNetworkSpecifier(new TelephonyNetworkSpecifier.Builder() builder.setNetworkSpecifier(new TelephonyNetworkSpecifier.Builder() .setSubscriptionId(subId).build()); return nc; return builder.build(); } private NetworkPolicy buildDefaultFakeMobilePolicy() { Loading Loading @@ -2061,10 +2062,9 @@ public class NetworkPolicyManagerServiceTest { private static NetworkStateSnapshot buildWifi() { final LinkProperties prop = new LinkProperties(); prop.setInterfaceName(TEST_IFACE); final NetworkCapabilities networkCapabilities = new NetworkCapabilities(); networkCapabilities.addTransportType(TRANSPORT_WIFI); networkCapabilities.setSSID(TEST_SSID); return new NetworkStateSnapshot(new Network(TEST_NET_ID), networkCapabilities, prop, final NetworkCapabilities networkCapabilities = new NetworkCapabilities.Builder() .addTransportType(TRANSPORT_WIFI).setSsid(TEST_SSID).build(); return new NetworkStateSnapshot(TEST_NETWORK, networkCapabilities, prop, null /*subscriberId*/, TYPE_WIFI); } Loading @@ -2086,7 +2086,7 @@ public class NetworkPolicyManagerServiceTest { when(mCarrierConfigManager.getConfigForSubId(eq(TEST_SUB_ID))) .thenReturn(mCarrierConfig); List<NetworkStateSnapshot> snapshots = List.of(new NetworkStateSnapshot( new Network(TEST_NET_ID), TEST_NETWORK, buildNetworkCapabilities(TEST_SUB_ID, roaming), buildLinkProperties(TEST_IFACE), TEST_IMSI, TYPE_MOBILE)); when(mConnManager.getAllNetworkStateSnapshot()).thenReturn(snapshots); Loading