[CTS][WIFI] Replace deprecated calls to WifiManager#setWifiEnabled() with shell command
The WifiManager#setWifiEnabled() is deprecated and no longer functions for non-Settings apps. Replace that call with the equivalent shell command which can be spawned from the CTS test. Bug: 121284726 Test: atest android.net.cts.ConnectivityManagerTest Test: atest SingleDeviceTest Test: atest WifiRttTest Test: atest ConcurrencyTest Test: atest ScanResultTest Test: atest WifiInfoTest Test: atest WifiEnterpriseConfigTest Change-Id: Ib9b5e05e51f9369a045e13f02cd78c979ba807b3
This commit is contained in:
@@ -57,6 +57,7 @@ import android.test.AndroidTestCase;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.compatibility.common.util.SystemUtil;
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.telephony.PhoneConstants;
|
||||
|
||||
@@ -670,7 +671,7 @@ public class ConnectivityManagerTest extends AndroidTestCase {
|
||||
|
||||
boolean connected = false;
|
||||
try {
|
||||
assertTrue(mWifiManager.setWifiEnabled(true));
|
||||
SystemUtil.runShellCommand("svc wifi enable");
|
||||
// Ensure we get both an onAvailable callback and a CONNECTIVITY_ACTION.
|
||||
wifiNetwork = callback.waitForAvailable();
|
||||
assertNotNull(wifiNetwork);
|
||||
@@ -736,7 +737,7 @@ public class ConnectivityManagerTest extends AndroidTestCase {
|
||||
|
||||
boolean disconnected = false;
|
||||
try {
|
||||
assertTrue(mWifiManager.setWifiEnabled(false));
|
||||
SystemUtil.runShellCommand("svc wifi disable");
|
||||
// Ensure we get both an onLost callback and a CONNECTIVITY_ACTION.
|
||||
lostWifiNetwork = callback.waitForLost();
|
||||
assertNotNull(lostWifiNetwork);
|
||||
|
||||
@@ -41,6 +41,8 @@ import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import com.android.compatibility.common.util.SystemUtil;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@@ -363,7 +365,7 @@ public class SingleDeviceTest extends AndroidTestCase {
|
||||
mWifiLock = mWifiManager.createWifiLock(TAG);
|
||||
mWifiLock.acquire();
|
||||
if (!mWifiManager.isWifiEnabled()) {
|
||||
mWifiManager.setWifiEnabled(true);
|
||||
SystemUtil.runShellCommand("svc wifi enable");
|
||||
}
|
||||
|
||||
mConnectivityManager = (ConnectivityManager) getContext().getSystemService(
|
||||
@@ -433,7 +435,7 @@ public class SingleDeviceTest extends AndroidTestCase {
|
||||
// 1. Disable Wi-Fi
|
||||
WifiAwareBroadcastReceiver receiver1 = new WifiAwareBroadcastReceiver();
|
||||
mContext.registerReceiver(receiver1, intentFilter);
|
||||
mWifiManager.setWifiEnabled(false);
|
||||
SystemUtil.runShellCommand("svc wifi disable");
|
||||
|
||||
assertTrue("Timeout waiting for Wi-Fi Aware to change status",
|
||||
receiver1.waitForStateChange());
|
||||
@@ -442,7 +444,7 @@ public class SingleDeviceTest extends AndroidTestCase {
|
||||
// 2. Enable Wi-Fi
|
||||
WifiAwareBroadcastReceiver receiver2 = new WifiAwareBroadcastReceiver();
|
||||
mContext.registerReceiver(receiver2, intentFilter);
|
||||
mWifiManager.setWifiEnabled(true);
|
||||
SystemUtil.runShellCommand("svc wifi enable");
|
||||
|
||||
assertTrue("Timeout waiting for Wi-Fi Aware to change status",
|
||||
receiver2.waitForStateChange());
|
||||
|
||||
@@ -31,6 +31,8 @@ import static android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_STATE_DISABLED;
|
||||
import static android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_STATE_ENABLED;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import com.android.compatibility.common.util.SystemUtil;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -84,7 +86,7 @@ public class ConcurrencyTest extends AndroidTestCase {
|
||||
mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
|
||||
assertNotNull(mWifiManager);
|
||||
if (mWifiManager.isWifiEnabled()) {
|
||||
assertTrue(mWifiManager.setWifiEnabled(false));
|
||||
SystemUtil.runShellCommand("svc wifi disable");
|
||||
Thread.sleep(DURATION);
|
||||
}
|
||||
assertTrue(!mWifiManager.isWifiEnabled());
|
||||
@@ -124,7 +126,7 @@ public class ConcurrencyTest extends AndroidTestCase {
|
||||
*/
|
||||
private void enableWifi() throws InterruptedException {
|
||||
if (!mWifiManager.isWifiEnabled()) {
|
||||
assertTrue(mWifiManager.setWifiEnabled(true));
|
||||
SystemUtil.runShellCommand("svc wifi enable");
|
||||
}
|
||||
|
||||
ConnectivityManager cm =
|
||||
@@ -159,7 +161,7 @@ public class ConcurrencyTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
// Enable wifi
|
||||
assertTrue(mWifiManager.setWifiEnabled(true));
|
||||
SystemUtil.runShellCommand("svc wifi enable");
|
||||
|
||||
waitForBroadcasts();
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ import android.net.wifi.WifiManager.WifiLock;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.compatibility.common.util.SystemUtil;
|
||||
|
||||
public class ScanResultTest extends AndroidTestCase {
|
||||
private static class MySync {
|
||||
int expectedState = STATE_NULL;
|
||||
@@ -121,7 +123,11 @@ public class ScanResultTest extends AndroidTestCase {
|
||||
private void setWifiEnabled(boolean enable) throws Exception {
|
||||
synchronized (mMySync) {
|
||||
mMySync.expectedState = STATE_WIFI_CHANGING;
|
||||
assertTrue(mWifiManager.setWifiEnabled(enable));
|
||||
if (enable) {
|
||||
SystemUtil.runShellCommand("svc wifi enable");
|
||||
} else {
|
||||
SystemUtil.runShellCommand("svc wifi disable");
|
||||
}
|
||||
waitForBroadcast(TIMEOUT_MSEC, STATE_WIFI_CHANGED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import android.net.wifi.WifiEnterpriseConfig.Phase2;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import com.android.compatibility.common.util.SystemUtil;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.PrivateKey;
|
||||
@@ -687,7 +689,7 @@ public class WifiEnterpriseConfigTest extends AndroidTestCase {
|
||||
mWifiManager = (WifiManager) mContext
|
||||
.getSystemService(Context.WIFI_SERVICE);
|
||||
assertNotNull(mWifiManager);
|
||||
mWifiManager.setWifiEnabled(true);
|
||||
SystemUtil.runShellCommand("svc wifi enable");
|
||||
Thread.sleep(ENABLE_DELAY);
|
||||
if (hasWifi()) {
|
||||
assertTrue(mWifiManager.isWifiEnabled());
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.net.wifi.WifiSsid;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import com.android.compatibility.common.util.PollingCheck;
|
||||
import com.android.compatibility.common.util.SystemUtil;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@@ -104,7 +105,11 @@ public class WifiInfoTest extends AndroidTestCase {
|
||||
private void setWifiEnabled(boolean enable) throws Exception {
|
||||
synchronized (mMySync) {
|
||||
mMySync.expectedState = STATE_WIFI_CHANGING;
|
||||
assertTrue(mWifiManager.setWifiEnabled(enable));
|
||||
if (enable) {
|
||||
SystemUtil.runShellCommand("svc wifi enable");
|
||||
} else {
|
||||
SystemUtil.runShellCommand("svc wifi disable");
|
||||
}
|
||||
long timeout = System.currentTimeMillis() + TIMEOUT_MSEC;
|
||||
while (System.currentTimeMillis() < timeout
|
||||
&& mMySync.expectedState == STATE_WIFI_CHANGING)
|
||||
|
||||
@@ -32,6 +32,8 @@ import android.os.HandlerExecutor;
|
||||
import android.os.HandlerThread;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import com.android.compatibility.common.util.SystemUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -93,7 +95,7 @@ public class TestBase extends AndroidTestCase {
|
||||
mWifiLock = mWifiManager.createWifiLock(TAG);
|
||||
mWifiLock.acquire();
|
||||
if (!mWifiManager.isWifiEnabled()) {
|
||||
mWifiManager.setWifiEnabled(true);
|
||||
SystemUtil.runShellCommand("svc wifi enable");
|
||||
}
|
||||
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
|
||||
Reference in New Issue
Block a user