CTS: Test PNO Scanning

Test that PNO scans reconnects us to a saved network
when Wifi is disconnected and screen is off.

This also adds coverage for
WifiNl80211Manager.startPnoScan.

Bug: 150978929
Test: atest android.net.wifi.cts.WifiManagerTest
Change-Id: Id0487f4df48ea013d67e19faecd96b5a469f09da
This commit is contained in:
David Su
2020-03-17 17:39:35 -07:00
parent 65031e4d9f
commit a4a48ef759

View File

@@ -81,9 +81,11 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executor;
@@ -1212,8 +1214,12 @@ public class WifiManagerTest extends AndroidTestCase {
Thread.sleep(DURATION_SCREEN_TOGGLE);
}
private void turnScreenOff() throws Exception {
private void turnScreenOffNoDelay() throws Exception {
mUiDevice.executeShellCommand("input keyevent KEYCODE_SLEEP");
}
private void turnScreenOff() throws Exception {
turnScreenOffNoDelay();
// Since the screen on/off intent is ordered, they will not be sent right now.
Thread.sleep(DURATION_SCREEN_TOGGLE);
}
@@ -1799,6 +1805,59 @@ public class WifiManagerTest extends AndroidTestCase {
mWifiManager.isPreferredNetworkOffloadSupported();
}
/** Test that PNO scans reconnects us when the device is disconnected and the screen is off. */
public void testPnoScan() throws Exception {
if (!WifiFeature.isWifiSupported(getContext())) {
// skip the test if WiFi is not supported
return;
}
if (!mWifiManager.isPreferredNetworkOffloadSupported()) {
// skip the test if PNO scanning is not supported
return;
}
// make sure we're connected
waitForConnection();
WifiInfo currentNetwork = ShellIdentityUtils.invokeWithShellPermissions(
mWifiManager::getConnectionInfo);
// disable all networks that aren't already disabled
List<WifiConfiguration> savedNetworks = ShellIdentityUtils.invokeWithShellPermissions(
mWifiManager::getConfiguredNetworks);
Set<Integer> disabledNetworkIds = new HashSet<>();
for (WifiConfiguration config : savedNetworks) {
if (config.getNetworkSelectionStatus().getNetworkSelectionDisableReason()
== WifiConfiguration.NetworkSelectionStatus.DISABLED_NONE) {
ShellIdentityUtils.invokeWithShellPermissions(
() -> mWifiManager.disableNetwork(config.networkId));
disabledNetworkIds.add(config.networkId);
}
}
try {
// wait for disconnection from current network
waitForDisconnection();
// turn screen off
turnScreenOffNoDelay();
// re-enable the current network - this will trigger PNO
ShellIdentityUtils.invokeWithShellPermissions(
() -> mWifiManager.enableNetwork(currentNetwork.getNetworkId(), false));
disabledNetworkIds.remove(currentNetwork.getNetworkId());
// PNO should reconnect us back to the network we disconnected from
waitForConnection();
} finally {
// re-enable disabled networks
for (int disabledNetworkId : disabledNetworkIds) {
ShellIdentityUtils.invokeWithShellPermissions(
() -> mWifiManager.enableNetwork(disabledNetworkId, false));
}
}
}
/**
* Tests {@link WifiManager#isTdlsSupported()} does not crash.
*/