Merge "Revert "Revert "CTS for timestamp in ScanResult""" into jb-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
87abf00d2f
@@ -26,6 +26,7 @@ import android.net.wifi.ScanResult;
|
|||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.net.wifi.WifiManager.WifiLock;
|
import android.net.wifi.WifiManager.WifiLock;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
public class ScanResultTest extends AndroidTestCase {
|
public class ScanResultTest extends AndroidTestCase {
|
||||||
private static class MySync {
|
private static class MySync {
|
||||||
@@ -39,11 +40,14 @@ public class ScanResultTest extends AndroidTestCase {
|
|||||||
private static final int STATE_NULL = 0;
|
private static final int STATE_NULL = 0;
|
||||||
private static final int STATE_WIFI_CHANGING = 1;
|
private static final int STATE_WIFI_CHANGING = 1;
|
||||||
private static final int STATE_WIFI_CHANGED = 2;
|
private static final int STATE_WIFI_CHANGED = 2;
|
||||||
|
private static final int STATE_START_SCAN = 3;
|
||||||
|
private static final int STATE_SCAN_RESULTS_AVAILABLE = 4;
|
||||||
|
|
||||||
private static final String TAG = "WifiInfoTest";
|
private static final String TAG = "WifiInfoTest";
|
||||||
private static final int TIMEOUT_MSEC = 6000;
|
private static final int TIMEOUT_MSEC = 6000;
|
||||||
private static final int WAIT_MSEC = 60;
|
private static final int WAIT_MSEC = 60;
|
||||||
private static final int DURATION = 10000;
|
private static final int ENABLE_WAIT_MSEC = 10000;
|
||||||
|
private static final int SCAN_WAIT_MSEC = 10000;
|
||||||
private IntentFilter mIntentFilter;
|
private IntentFilter mIntentFilter;
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
@@ -54,6 +58,11 @@ public class ScanResultTest extends AndroidTestCase {
|
|||||||
mMySync.expectedState = STATE_WIFI_CHANGED;
|
mMySync.expectedState = STATE_WIFI_CHANGED;
|
||||||
mMySync.notify();
|
mMySync.notify();
|
||||||
}
|
}
|
||||||
|
} else if (action.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
|
||||||
|
synchronized (mMySync) {
|
||||||
|
mMySync.expectedState = STATE_SCAN_RESULTS_AVAILABLE;
|
||||||
|
mMySync.notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -83,7 +92,7 @@ public class ScanResultTest extends AndroidTestCase {
|
|||||||
mWifiLock.acquire();
|
mWifiLock.acquire();
|
||||||
if (!mWifiManager.isWifiEnabled())
|
if (!mWifiManager.isWifiEnabled())
|
||||||
setWifiEnabled(true);
|
setWifiEnabled(true);
|
||||||
Thread.sleep(DURATION);
|
Thread.sleep(ENABLE_WAIT_MSEC);
|
||||||
assertTrue(mWifiManager.isWifiEnabled());
|
assertTrue(mWifiManager.isWifiEnabled());
|
||||||
mMySync.expectedState = STATE_NULL;
|
mMySync.expectedState = STATE_NULL;
|
||||||
}
|
}
|
||||||
@@ -99,7 +108,7 @@ public class ScanResultTest extends AndroidTestCase {
|
|||||||
mContext.unregisterReceiver(mReceiver);
|
mContext.unregisterReceiver(mReceiver);
|
||||||
if (!mWifiManager.isWifiEnabled())
|
if (!mWifiManager.isWifiEnabled())
|
||||||
setWifiEnabled(true);
|
setWifiEnabled(true);
|
||||||
Thread.sleep(DURATION);
|
Thread.sleep(ENABLE_WAIT_MSEC);
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,11 +116,15 @@ public class ScanResultTest extends AndroidTestCase {
|
|||||||
synchronized (mMySync) {
|
synchronized (mMySync) {
|
||||||
mMySync.expectedState = STATE_WIFI_CHANGING;
|
mMySync.expectedState = STATE_WIFI_CHANGING;
|
||||||
assertTrue(mWifiManager.setWifiEnabled(enable));
|
assertTrue(mWifiManager.setWifiEnabled(enable));
|
||||||
long timeout = System.currentTimeMillis() + TIMEOUT_MSEC;
|
waitForBroadcast(TIMEOUT_MSEC, STATE_WIFI_CHANGED);
|
||||||
while (System.currentTimeMillis() < timeout
|
}
|
||||||
&& mMySync.expectedState == STATE_WIFI_CHANGING)
|
}
|
||||||
mMySync.wait(WAIT_MSEC);
|
|
||||||
}
|
private void waitForBroadcast(long timeout, int expectedState) throws Exception {
|
||||||
|
long waitTime = System.currentTimeMillis() + timeout;
|
||||||
|
while (System.currentTimeMillis() < waitTime
|
||||||
|
&& mMySync.expectedState != expectedState)
|
||||||
|
mMySync.wait(WAIT_MSEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testScanResultProperties() {
|
public void testScanResultProperties() {
|
||||||
@@ -127,4 +140,49 @@ public class ScanResultTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void scanAndWait() throws Exception {
|
||||||
|
synchronized (mMySync) {
|
||||||
|
mMySync.expectedState = STATE_START_SCAN;
|
||||||
|
mWifiManager.startScan();
|
||||||
|
waitForBroadcast(SCAN_WAIT_MSEC, STATE_SCAN_RESULTS_AVAILABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testScanResultTimeStamp() throws Exception {
|
||||||
|
if (!WifiFeature.isWifiSupported(getContext())) {
|
||||||
|
// skip the test if WiFi is not supported
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long timestamp = 0;
|
||||||
|
String BSSID = null;
|
||||||
|
|
||||||
|
/* Multiple scans to ensure bssid is updated */
|
||||||
|
scanAndWait();
|
||||||
|
scanAndWait();
|
||||||
|
scanAndWait();
|
||||||
|
|
||||||
|
List<ScanResult> scanResults = mWifiManager.getScanResults();
|
||||||
|
for (ScanResult result : scanResults) {
|
||||||
|
BSSID = result.BSSID;
|
||||||
|
timestamp = result.timestamp;
|
||||||
|
assertTrue(timestamp != 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
scanAndWait();
|
||||||
|
scanAndWait();
|
||||||
|
scanAndWait();
|
||||||
|
|
||||||
|
scanResults = mWifiManager.getScanResults();
|
||||||
|
for (ScanResult result : scanResults) {
|
||||||
|
if (result.BSSID.equals(BSSID)) {
|
||||||
|
long timeDiff = (result.timestamp - timestamp) / 1000;
|
||||||
|
assertTrue (timeDiff > 0);
|
||||||
|
assertTrue (timeDiff < 6 * SCAN_WAIT_MSEC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user