Remove WifiManager CTS test using TxPacketCountListener

TxPacketCountListener is @hide and only used for
CTS. Remove the test using this altogether.

Bug: 144036594
Test: atest android.net.wifi.cts.WifiManagerTest
Change-Id: Iac42c7dca4ca5cbbae6c464530319975e8d1571e
This commit is contained in:
David Su
2020-01-10 17:08:25 -08:00
parent 656e4768c3
commit 47a4a384c4

View File

@@ -32,7 +32,6 @@ import android.net.wifi.ScanResult;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.TxPacketCountListener;
import android.net.wifi.WifiManager.WifiLock;
import android.os.Process;
import android.os.SystemClock;
@@ -49,15 +48,11 @@ import androidx.test.platform.app.InstrumentationRegistry;
import com.android.compatibility.common.util.SystemUtil;
import java.lang.StringBuilder;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@AppModeFull(reason = "Cannot get WifiManager in instant app mode")
@@ -428,90 +423,6 @@ public class WifiManagerTest extends AndroidTestCase {
assertTrue(WifiManager.compareSignalLevel(rssiA, rssiB) > 0);
}
private int getTxPacketCount() throws Exception {
final AtomicInteger ret = new AtomicInteger(-1);
mWifiManager.getTxPacketCount(new TxPacketCountListener() {
@Override
public void onSuccess(int count) {
ret.set(count);
}
@Override
public void onFailure(int reason) {
ret.set(0);
}
});
long timeout = System.currentTimeMillis() + TIMEOUT_MSEC;
while (ret.get() < 0 && System.currentTimeMillis() < timeout)
Thread.sleep(WAIT_MSEC);
assertTrue(ret.get() >= 0);
return ret.get();
}
/**
* The new WiFi watchdog requires kernel/driver to export some packet loss
* counters. This CTS tests whether those counters are correctly exported.
* To pass this CTS test, a connected WiFi link is required.
*/
public void testWifiWatchdog() throws Exception {
if (!WifiFeature.isWifiSupported(getContext())) {
// skip the test if WiFi is not supported
return;
}
// Make sure WiFi is enabled
if (!mWifiManager.isWifiEnabled()) {
setWifiEnabled(true);
Thread.sleep(DURATION);
}
assertTrue(mWifiManager.isWifiEnabled());
// give the test a chance to autoconnect
Thread.sleep(DURATION);
if (mNetworkInfo.getState() != NetworkInfo.State.CONNECTED) {
// this test requires a connectable network be configured
fail("This test requires a wifi network connection.");
}
// This will generate a distinct stack trace if the initial connection fails.
connectWifi();
int i = 0;
for (; i < 15; i++) {
// Wait for a WiFi connection
connectWifi();
// Read TX packet counter
int txcount1 = getTxPacketCount();
// Do some network operations
HttpURLConnection connection = null;
try {
URL url = new URL("http://www.google.com/");
connection = (HttpURLConnection) url.openConnection();
connection.setInstanceFollowRedirects(false);
connection.setConnectTimeout(TIMEOUT_MSEC);
connection.setReadTimeout(TIMEOUT_MSEC);
connection.setUseCaches(false);
connection.getInputStream();
} catch (Exception e) {
// ignore
} finally {
if (connection != null) connection.disconnect();
}
// Read TX packet counter again and make sure it increases
int txcount2 = getTxPacketCount();
if (txcount2 > txcount1) {
break;
} else {
Thread.sleep(DURATION);
}
}
assertTrue(i < 15);
}
private static class TestLocalOnlyHotspotCallback extends WifiManager.LocalOnlyHotspotCallback {
Object hotspotLock;
WifiManager.LocalOnlyHotspotReservation reservation = null;