From 71cfc79527c812fcd334ca688477c0536f1fbee0 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Mon, 27 Apr 2020 22:40:11 +0900 Subject: [PATCH] Force reconnect in connectToWifi There is no guarantee that Wifi will automatically reconnect after enabling, especially in cases where no internet access was detected on the access point the last time it was connected. Use WifiManager#reconnect to force wifi to reconnect to the access point. The API is deprecated for general use, but system apps are documented as exempted from the deprecation. Bug: 152280218 Test: atest --rerun-until-failure 200 CtsNetTestCases:CaptivePortalTest Change-Id: Ia7d83337ee0ffad9414031711cf7e937b14f968d --- tests/cts/net/util/java/android/net/cts/util/CtsNetUtils.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/cts/net/util/java/android/net/cts/util/CtsNetUtils.java b/tests/cts/net/util/java/android/net/cts/util/CtsNetUtils.java index 6214f89e98..824146fedf 100644 --- a/tests/cts/net/util/java/android/net/cts/util/CtsNetUtils.java +++ b/tests/cts/net/util/java/android/net/cts/util/CtsNetUtils.java @@ -16,6 +16,7 @@ package android.net.cts.util; +import static android.Manifest.permission.NETWORK_SETTINGS; import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET; import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR; @@ -107,6 +108,8 @@ public final class CtsNetUtils { boolean connected = false; try { SystemUtil.runShellCommand("svc wifi enable"); + SystemUtil.runWithShellPermissionIdentity(() -> mWifiManager.reconnect(), + NETWORK_SETTINGS); // Ensure we get both an onAvailable callback and a CONNECTIVITY_ACTION. wifiNetwork = callback.waitForAvailable(); assertNotNull(wifiNetwork);