From 5764173a9f3f15bbcfd671908aae7edcf0f15fbe Mon Sep 17 00:00:00 2001 From: junyulai Date: Fri, 5 Jul 2019 09:37:58 +0800 Subject: [PATCH 1/4] Resolve resource ID at runtime to stabilize tests This change also remove some unused references. Bug: 136638851 Test: atest android.net.cts.ConnectivityManagerTest Change-Id: Ic44b31ed9acc48b9bcba7e1e70cc18a65bc0a8f6 --- .../net/cts/ConnectivityManagerTest.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java index e9deec9f1e..ca1f77145c 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java @@ -44,6 +44,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; +import android.content.res.Resources; import android.net.ConnectivityManager; import android.net.ConnectivityManager.NetworkCallback; import android.net.IpSecManager; @@ -75,9 +76,6 @@ import android.util.Pair; import androidx.test.InstrumentationRegistry; -import com.android.internal.R; -import com.android.internal.telephony.PhoneConstants; - import libcore.io.Streams; import java.io.FileDescriptor; @@ -129,6 +127,13 @@ public class ConnectivityManagerTest extends AndroidTestCase { public static final int MIN_SUPPORTED_CELLULAR_KEEPALIVE_COUNT = 1; public static final int MIN_SUPPORTED_WIFI_KEEPALIVE_COUNT = 3; + private static final String NETWORK_METERED_MULTIPATH_PREFERENCE_RES_NAME = + "config_networkMeteredMultipathPreference"; + private static final String KEEPALIVE_ALLOWED_UNPRIVILEGED_RES_NAME = + "config_allowedUnprivilegedKeepalivePerUid"; + private static final String KEEPALIVE_RESERVED_PER_SLOT_RES_NAME = + "config_reservedPrivilegedKeepaliveSlots"; + private Context mContext; private Instrumentation mInstrumentation; private ConnectivityManager mCm; @@ -376,9 +381,6 @@ public class ConnectivityManagerTest extends AndroidTestCase { final String invalidateFeature = "invalidateFeature"; final String mmsFeature = "enableMMS"; - final int failureCode = -1; - final int wifiOnlyStartFailureCode = PhoneConstants.APN_REQUEST_FAILED; - final int wifiOnlyStopFailureCode = -1; assertStartUsingNetworkFeatureUnsupported(TYPE_MOBILE, invalidateFeature); assertStopUsingNetworkFeatureUnsupported(TYPE_MOBILE, invalidateFeature); @@ -672,7 +674,7 @@ public class ConnectivityManagerTest extends AndroidTestCase { final String rawMeteredPref = Settings.Global.getString(resolver, NETWORK_METERED_MULTIPATH_PREFERENCE); return TextUtils.isEmpty(rawMeteredPref) - ? mContext.getResources().getInteger(R.integer.config_networkMeteredMultipathPreference) + ? getIntResourceForName(NETWORK_METERED_MULTIPATH_PREFERENCE_RES_NAME) : Integer.parseInt(rawMeteredPref); } @@ -1216,6 +1218,12 @@ public class ConnectivityManagerTest extends AndroidTestCase { dropShellPermissionIdentity(); } + private int getIntResourceForName(@NonNull String resName) { + final Resources r = mContext.getResources(); + final int resId = r.getIdentifier(resName, "integer", "android"); + return r.getInteger(resId); + } + /** * Verifies that the keepalive slots are limited as customized for unprivileged requests. */ @@ -1233,10 +1241,12 @@ public class ConnectivityManagerTest extends AndroidTestCase { return; } - final int allowedUnprivilegedPerUid = mContext.getResources().getInteger( - R.integer.config_allowedUnprivilegedKeepalivePerUid); - final int reservedPrivilegedSlots = mContext.getResources().getInteger( - R.integer.config_reservedPrivilegedKeepaliveSlots); + // Resource ID might be shifted on devices that compiled with different symbols. + // Thus, resolve ID at runtime is needed. + final int allowedUnprivilegedPerUid = + getIntResourceForName(KEEPALIVE_ALLOWED_UNPRIVILEGED_RES_NAME); + final int reservedPrivilegedSlots = + getIntResourceForName(KEEPALIVE_RESERVED_PER_SLOT_RES_NAME); // Verifies that unprivileged request per uid cannot exceed the limit customized in the // resource. Currently, unprivileged keepalive slots are limited to Nat-T only, this test // does not apply to TCP. From 9c97c58656a168568e2a7dd784bb9919ac4997c5 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Tue, 6 Aug 2019 13:02:28 +0900 Subject: [PATCH 2/4] Add test for WifiInfo#getFrequency() Add getFrequency() to WifiInfoTest (along with other missing getters), and test that it is consistent with ScanResult in ScanResultTest. Test: atest android.net.wifi.cts.ScanResultTest Fixes: b/138929469 Merged-In: I070b16661bc72a5c5035b0b227821b680d7d71ba (cherry picked from commit 2d504956e63eefb0a6a90844d1d00b99c097891b) Change-Id: Ie99011acbbe66e9088f73964fd0c39d640594011 --- .../android/net/wifi/cts/ScanResultTest.java | 30 +++++++++++++++++++ .../android/net/wifi/cts/WifiInfoTest.java | 3 ++ 2 files changed, 33 insertions(+) diff --git a/tests/cts/net/src/android/net/wifi/cts/ScanResultTest.java b/tests/cts/net/src/android/net/wifi/cts/ScanResultTest.java index ccf5fe2241..9bd1226f52 100644 --- a/tests/cts/net/src/android/net/wifi/cts/ScanResultTest.java +++ b/tests/cts/net/src/android/net/wifi/cts/ScanResultTest.java @@ -23,6 +23,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.wifi.ScanResult; +import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.net.wifi.WifiManager.WifiLock; import android.platform.test.annotations.AppModeFull; @@ -54,6 +55,8 @@ public class ScanResultTest extends AndroidTestCase { private static final int ENABLE_WAIT_MSEC = 10000; private static final int SCAN_WAIT_MSEC = 10000; private static final int SCAN_MAX_RETRY_COUNT = 6; + private static final int SCAN_FIND_BSSID_MAX_RETRY_COUNT = 5; + private static final long SCAN_FIND_BSSID_WAIT_MSEC = 5_000L; private IntentFilter mIntentFilter; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override @@ -200,4 +203,31 @@ public class ScanResultTest extends AndroidTestCase { } + public void testScanResultMatchesWifiInfo() throws Exception { + if (!WifiFeature.isWifiSupported(getContext())) { + // skip the test if WiFi is not supported + return; + } + + // This test case should run while connected to Wifi + final WifiInfo wifiInfo = mWifiManager.getConnectionInfo(); + assertNotNull(wifiInfo); + + ScanResult currentNetwork = null; + for (int i = 0; i < SCAN_FIND_BSSID_MAX_RETRY_COUNT; i++) { + scanAndWait(); + final List scanResults = mWifiManager.getScanResults(); + currentNetwork = scanResults.stream().filter(r -> r.BSSID.equals(wifiInfo.getBSSID())) + .findAny().orElse(null); + + if (currentNetwork != null) { + break; + } + Thread.sleep(SCAN_FIND_BSSID_WAIT_MSEC); + } + assertNotNull("Current network not found in scan results", currentNetwork); + + assertEquals(wifiInfo.getWifiSsid(), currentNetwork.wifiSsid); + assertEquals(wifiInfo.getFrequency(), currentNetwork.frequency); + } } diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiInfoTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiInfoTest.java index 5367722b36..9d9b2a3902 100644 --- a/tests/cts/net/src/android/net/wifi/cts/WifiInfoTest.java +++ b/tests/cts/net/src/android/net/wifi/cts/WifiInfoTest.java @@ -139,8 +139,11 @@ public class WifiInfoTest extends AndroidTestCase { } wifiInfo.getBSSID(); + wifiInfo.getFrequency(); wifiInfo.getIpAddress(); wifiInfo.getLinkSpeed(); + wifiInfo.getPasspointFqdn(); + wifiInfo.getPasspointProviderFriendlyName(); wifiInfo.getTxLinkSpeedMbps(); wifiInfo.getRxLinkSpeedMbps(); wifiInfo.getRssi(); From 8ce68f1310fbd968b922d3faa5e64df702458178 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Tue, 20 Aug 2019 19:09:35 +0900 Subject: [PATCH 3/4] Attempt "fix" the broken QUIC packet to be slightly less broken Bug: 139403355 Signed-off-by: Erik Kline Merged-In: I9c938998b5e30f7d3994b410878b2af6a75f9b5a Test: in I9c938998b5e30f7d3994b410878b2af6a75f9b5a (cherry picked from commit b5e98a971a73693740a784e8bd355df41df6faa2) Change-Id: I329c06395d63500ff20c77cee670566d83c3ac8a --- tests/cts/net/jni/NativeMultinetworkJni.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/cts/net/jni/NativeMultinetworkJni.c b/tests/cts/net/jni/NativeMultinetworkJni.c index ad56b510c3..4531f822eb 100644 --- a/tests/cts/net/jni/NativeMultinetworkJni.c +++ b/tests/cts/net/jni/NativeMultinetworkJni.c @@ -177,13 +177,17 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck( setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo)); // For reference see: - // https://tools.ietf.org/html/draft-tsvwg-quic-protocol-01#section-6.1 - uint8_t quic_packet[] = { - 0x0c, // public flags: 64bit conn ID, 8bit sequence number + // https://tools.ietf.org/html/draft-tsvwg-quic-protocol#section-6.1 + uint8_t quic_packet[1200] = { + 0x0d, // public flags: + // - version present (0x01), + // - 64bit connection ID (0x0c), + // - 1 byte packet number (0x00) 0, 0, 0, 0, 0, 0, 0, 0, // 64bit connection ID - 0x01, // sequence number + 0xaa, 0xda, 0xca, 0xaa, // reserved-space version number + 1, // 1 byte packet number 0x00, // private flags - 0x07, // type: regular frame type "PING" + 0x07, // PING frame (cuz why not) }; arc4random_buf(quic_packet + 1, 8); // random connection ID @@ -211,7 +215,7 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck( i + 1, MAX_RETRIES, rcvd, errnum); } } - if (rcvd < sent) { + if (rcvd < 9) { ALOGD("QUIC UDP %s: sent=%zd but rcvd=%zd, errno=%d", kPort, sent, rcvd, errnum); if (rcvd <= 0) { ALOGD("Does this network block UDP port %s?", kPort); @@ -227,8 +231,7 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck( return -EPROTO; } - // TODO: log, and compare to the IP address encoded in the - // response, since this should be a public reset packet. + // TODO: Replace this quick 'n' dirty test with proper QUIC-capable code. close(fd); return 0; From 6ee1049428b80f8813d31f5453200f379691d58d Mon Sep 17 00:00:00 2001 From: Erik Kline Date: Fri, 16 Aug 2019 19:51:54 -0700 Subject: [PATCH 4/4] Attempt "fix" the broken QUIC packet to be slightly less broken Bug: 139403355 Merged-In: I372c0730c9bd5329761b5a74b38e0f743bfd8230 (cherry picked from commit d6af2b5225249b178ee69dc5bac9b40c46f08d76) Change-Id: I2955a3f9e733a5e39813a26e4cd630f79ae144a0 --- tests/cts/net/jni/NativeMultinetworkJni.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/cts/net/jni/NativeMultinetworkJni.cpp b/tests/cts/net/jni/NativeMultinetworkJni.cpp index a6b5e90b1d..5bd3013819 100644 --- a/tests/cts/net/jni/NativeMultinetworkJni.cpp +++ b/tests/cts/net/jni/NativeMultinetworkJni.cpp @@ -455,13 +455,17 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck( setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo)); // For reference see: - // https://tools.ietf.org/html/draft-tsvwg-quic-protocol-01#section-6.1 - uint8_t quic_packet[] = { - 0x0c, // public flags: 64bit conn ID, 8bit sequence number + // https://tools.ietf.org/html/draft-tsvwg-quic-protocol#section-6.1 + uint8_t quic_packet[1200] = { + 0x0d, // public flags: + // - version present (0x01), + // - 64bit connection ID (0x0c), + // - 1 byte packet number (0x00) 0, 0, 0, 0, 0, 0, 0, 0, // 64bit connection ID - 0x01, // sequence number + 0xaa, 0xda, 0xca, 0xaa, // reserved-space version number + 1, // 1 byte packet number 0x00, // private flags - 0x07, // type: regular frame type "PING" + 0x07, // PING frame (cuz why not) }; arc4random_buf(quic_packet + 1, 8); // random connection ID @@ -489,7 +493,7 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck( i + 1, MAX_RETRIES, rcvd, errnum); } } - if (rcvd < sent) { + if (rcvd < 9) { ALOGD("QUIC UDP %s: sent=%zd but rcvd=%zd, errno=%d", kPort, sent, rcvd, errnum); if (rcvd <= 0) { ALOGD("Does this network block UDP port %s?", kPort); @@ -505,8 +509,7 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck( return -EPROTO; } - // TODO: log, and compare to the IP address encoded in the - // response, since this should be a public reset packet. + // TODO: Replace this quick 'n' dirty test with proper QUIC-capable code. close(fd); return 0;