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
This commit is contained in:
Remi NGUYEN VAN
2020-04-27 22:40:11 +09:00
parent ecb661016f
commit 71cfc79527

View File

@@ -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);