Merge "Add polling for WifiManager#getConnectionInfo"
This commit is contained in:
@@ -2856,7 +2856,7 @@ public class ConnectivityManagerTest {
|
|||||||
// Wifi will not automatically reconnect to the network. ensureWifiDisconnected cannot
|
// Wifi will not automatically reconnect to the network. ensureWifiDisconnected cannot
|
||||||
// apply here. Thus, turn off wifi first and restart to restore.
|
// apply here. Thus, turn off wifi first and restart to restore.
|
||||||
mTestValidationConfigRule.runAfterNextCleanup(() -> {
|
mTestValidationConfigRule.runAfterNextCleanup(() -> {
|
||||||
runShellCommand("svc wifi disable");
|
mCtsNetUtils.disableWifi();
|
||||||
mCtsNetUtils.ensureWifiConnected();
|
mCtsNetUtils.ensureWifiConnected();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -2898,7 +2898,7 @@ public class ConnectivityManagerTest {
|
|||||||
/// Wifi will not automatically reconnect to the network. ensureWifiDisconnected cannot
|
/// Wifi will not automatically reconnect to the network. ensureWifiDisconnected cannot
|
||||||
// apply here. Thus, turn off wifi first and restart to restore.
|
// apply here. Thus, turn off wifi first and restart to restore.
|
||||||
mTestValidationConfigRule.runAfterNextCleanup(() -> {
|
mTestValidationConfigRule.runAfterNextCleanup(() -> {
|
||||||
runShellCommand("svc wifi disable");
|
mCtsNetUtils.disableWifi();
|
||||||
mCtsNetUtils.ensureWifiConnected();
|
mCtsNetUtils.ensureWifiConnected();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ import android.system.OsConstants;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.compatibility.common.util.PollingCheck;
|
||||||
|
import com.android.compatibility.common.util.ShellIdentityUtils;
|
||||||
import com.android.compatibility.common.util.SystemUtil;
|
import com.android.compatibility.common.util.SystemUtil;
|
||||||
import com.android.net.module.util.ConnectivitySettingsUtils;
|
import com.android.net.module.util.ConnectivitySettingsUtils;
|
||||||
import com.android.testutils.ConnectUtil;
|
import com.android.testutils.ConnectUtil;
|
||||||
@@ -267,6 +269,19 @@ public final class CtsNetUtils {
|
|||||||
disconnectFromWifi(wifiNetworkToCheck, false /* expectLegacyBroadcast */);
|
disconnectFromWifi(wifiNetworkToCheck, false /* expectLegacyBroadcast */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable WiFi and wait for the connection info to be cleared.
|
||||||
|
*/
|
||||||
|
public void disableWifi() throws Exception {
|
||||||
|
SystemUtil.runShellCommand("svc wifi disable");
|
||||||
|
PollingCheck.check(
|
||||||
|
"Wifi not disconnected! Current network is not null "
|
||||||
|
+ mWifiManager.getConnectionInfo().getNetworkId(),
|
||||||
|
TimeUnit.SECONDS.toMillis(CONNECTIVITY_CHANGE_TIMEOUT_SECS),
|
||||||
|
() -> ShellIdentityUtils.invokeWithShellPermissions(
|
||||||
|
() -> mWifiManager.getConnectionInfo().getNetworkId()) == -1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable WiFi and wait for it to become disconnected from the network.
|
* Disable WiFi and wait for it to become disconnected from the network.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -478,7 +478,9 @@ public final class CtsTetheringUtils {
|
|||||||
waitForWifiEnabled(ctx);
|
waitForWifiEnabled(ctx);
|
||||||
return runAsShell(ACCESS_WIFI_STATE, () -> wm.isPortableHotspotSupported());
|
return runAsShell(ACCESS_WIFI_STATE, () -> wm.isPortableHotspotSupported());
|
||||||
} finally {
|
} finally {
|
||||||
if (!previousWifiEnabledState) SystemUtil.runShellCommand("svc wifi disable");
|
if (!previousWifiEnabledState) {
|
||||||
|
new CtsNetUtils(ctx).disableWifi();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user