summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2017-06-21 18:46:50 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-06-21 18:46:50 +0000
commitcebe986861bc1405afd7f333dbc6996107deb14b (patch)
tree001633d1e0cfa8190f7e867a67e4df9b3f6d539b /tests
parent7448f1e3892ff04ff05ac41d0a9fa4caa40858b0 (diff)
parenta2f60dca3aeb71d6e8a86b9e2bd856242fa797e9 (diff)
WifiScanningService: Cache only results of full single scans am: 23216ca333
am: a2f60dca3a Change-Id: Ie3d7eb1636f6c7687dc36517c8350dcc8af0b519
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java137
1 files changed, 122 insertions, 15 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
index e1e467a39..01835cdf4 100644
--- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
@@ -17,6 +17,8 @@
package com.android.server.wifi.scanner;
import static com.android.server.wifi.ScanTestUtil.*;
+import static com.android.server.wifi.scanner.WifiScanningServiceImpl.WifiSingleScanStateMachine
+ .CACHED_SCAN_RESULTS_MAX_AGE_IN_MILLIS;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
@@ -124,6 +126,7 @@ public class WifiScanningServiceTest {
mWifiAsyncChannel.setWifiLog(mLog);
when(mFrameworkFacade.makeWifiAsyncChannel(anyString())).thenReturn(mWifiAsyncChannel);
when(mWifiInjector.getFrameworkFacade()).thenReturn(mFrameworkFacade);
+ when(mWifiInjector.getClock()).thenReturn(mClock);
mWifiScanningServiceImpl = new WifiScanningServiceImpl(mContext, mLooper.getLooper(),
mWifiScannerImplFactory, mBatteryStats, mWifiInjector);
}
@@ -528,7 +531,11 @@ public class WifiScanningServiceTest {
mLooper.dispatchAll();
verifyScanResultsReceived(order, handler, requestId, results.getScanData());
verifySingleScanCompletedReceived(order, handler, requestId);
- verify(mContext).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL));
+ if (results.getScanData().isAllChannelsScanned()) {
+ verify(mContext).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL));
+ } else {
+ verify(mContext, never()).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL));
+ }
verifyNoMoreInteractions(handler);
verify(mBatteryStats).noteWifiScanStoppedFromSource(eq(workSource));
assertDumpContainsRequestLog("addSingleScanRequest", requestId);
@@ -778,13 +785,13 @@ public class WifiScanningServiceTest {
WifiScanner.ScanSettings requestSettings1 = createRequest(channelsToSpec(2400), 0,
0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN);
int requestId1 = 12;
- ScanResults results1 = ScanResults.create(0, 2400);
+ ScanResults results1 = ScanResults.create(0, true, 2400);
WifiScanner.ScanSettings requestSettings2 = createRequest(channelsToSpec(2450, 5175), 0,
0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN);
int requestId2 = 13;
- ScanResults results2 = ScanResults.create(0, 2450);
+ ScanResults results2 = ScanResults.create(0, true, 2450);
startServiceAndLoadDriver();
@@ -849,12 +856,12 @@ public class WifiScanningServiceTest {
WifiScanner.ScanSettings requestSettings1 = createRequest(channelsToSpec(2400), 0,
0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN);
int requestId1 = 12;
- ScanResults results1 = ScanResults.create(0, 2400);
+ ScanResults results1 = ScanResults.create(0, true, 2400);
WifiScanner.ScanSettings requestSettings2 = createRequest(channelsToSpec(2450, 5175), 0,
0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN);
int requestId2 = 13;
- ScanResults results2 = ScanResults.create(0, 2450);
+ ScanResults results2 = ScanResults.create(0, true, 2450);
startServiceAndLoadDriver();
@@ -919,19 +926,19 @@ public class WifiScanningServiceTest {
0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN);
int requestId1 = 12;
WorkSource workSource1 = new WorkSource(1121);
- ScanResults results1 = ScanResults.create(0, 2400);
+ ScanResults results1 = ScanResults.create(0, false, 2400);
WifiScanner.ScanSettings requestSettings2 = createRequest(channelsToSpec(2450, 5175), 0,
0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN);
int requestId2 = 13;
WorkSource workSource2 = new WorkSource(Binder.getCallingUid()); // don't explicitly set
- ScanResults results2 = ScanResults.create(0, 2450, 5175, 2450);
+ ScanResults results2 = ScanResults.create(0, false, 2450, 5175, 2450);
WifiScanner.ScanSettings requestSettings3 = createRequest(channelsToSpec(5150), 0,
0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN);
int requestId3 = 15;
WorkSource workSource3 = new WorkSource(2292);
- ScanResults results3 = ScanResults.create(0, 5150, 5150, 5150, 5150);
+ ScanResults results3 = ScanResults.create(0, false, 5150, 5150, 5150, 5150);
WifiNative.ScanSettings nativeSettings2and3 = createSingleScanNativeSettingsForChannels(
WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN, channelsToSpec(2450, 5175, 5150));
@@ -981,7 +988,7 @@ public class WifiScanningServiceTest {
mLooper.dispatchAll();
verifyScanResultsReceived(handlerOrder, handler, requestId1, results1.getScanData());
verifySingleScanCompletedReceived(handlerOrder, handler, requestId1);
- verify(mContext).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL));
+ verify(mContext, never()).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL));
verify(mBatteryStats).noteWifiScanStoppedFromSource(eq(workSource1));
verify(mBatteryStats).noteWifiScanStartedFromSource(eq(workSource2and3));
@@ -1162,7 +1169,7 @@ public class WifiScanningServiceTest {
verifyScanResultsReceived(handlerOrder, handler, requestId2, results2.getScanData());
verifySingleScanCompletedReceived(handlerOrder, handler, requestId2);
- verify(mContext, times(2)).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL));
+ verify(mContext, never()).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL));
assertEquals(mWifiMetrics.getOneshotScanCount(), 3);
assertEquals(mWifiMetrics.getScanReturnEntry(WifiMetricsProto.WifiLog.SCAN_SUCCESS), 3);
@@ -1258,10 +1265,10 @@ public class WifiScanningServiceTest {
}
/**
- * Verify that the newest scan results are returned by WifiService.getSingleScanResults.
+ * Verify that the newest full scan results are returned by WifiService.getSingleScanResults.
*/
@Test
- public void retrieveMostRecentSingleScanResults() throws Exception {
+ public void retrieveMostRecentFullSingleScanResults() throws Exception {
WifiScanner.ScanSettings requestSettings = createRequest(WifiScanner.WIFI_BAND_BOTH, 0,
0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN);
ScanResults expectedResults = ScanResults.create(0, true, 2400, 5150, 5175);
@@ -1313,6 +1320,106 @@ public class WifiScanningServiceTest {
}
/**
+ * Verify that the newest partial scan results are not returned by
+ * WifiService.getSingleScanResults.
+ */
+ @Test
+ public void doesNotRetrieveMostRecentPartialSingleScanResults() throws Exception {
+ WifiScanner.ScanSettings fullRequestSettings = createRequest(WifiScanner.WIFI_BAND_BOTH, 0,
+ 0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN);
+ ScanResults expectedFullResults = ScanResults.create(0, true, 2400, 5150, 5175);
+ doSuccessfulSingleScan(fullRequestSettings,
+ computeSingleScanNativeSettings(fullRequestSettings),
+ expectedFullResults);
+
+ Handler handler = mock(Handler.class);
+ BidirectionalAsyncChannel controlChannel = connectChannel(handler);
+ InOrder order = inOrder(handler, mWifiScannerImpl);
+
+ controlChannel.sendMessage(
+ Message.obtain(null, WifiScanner.CMD_GET_SINGLE_SCAN_RESULTS, 0));
+ mLooper.dispatchAll();
+ Message response = verifyHandleMessageAndGetMessage(order, handler);
+
+ List<ScanResult> results = Arrays.asList(
+ ((WifiScanner.ParcelableScanResults) response.obj).getResults());
+ assertEquals(results.size(), expectedFullResults.getRawScanResults().length);
+
+ // now update with a new scan that only has one result
+ int secondScanRequestId = 35;
+ WifiScanner.ScanSettings partialRequestSettings = createRequest(WifiScanner.WIFI_BAND_BOTH,
+ 0, 0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN);
+ ScanResults expectedPartialResults = ScanResults.create(0, false, 5150);
+ sendSingleScanRequest(controlChannel, secondScanRequestId, partialRequestSettings, null);
+
+ mLooper.dispatchAll();
+ WifiNative.ScanEventHandler eventHandler = verifyStartSingleScan(order,
+ computeSingleScanNativeSettings(partialRequestSettings));
+ verifySuccessfulResponse(order, handler, secondScanRequestId);
+
+ // dispatch scan 2 results
+ when(mWifiScannerImpl.getLatestSingleScanResults())
+ .thenReturn(expectedPartialResults.getScanData());
+ eventHandler.onScanStatus(WifiNative.WIFI_SCAN_RESULTS_AVAILABLE);
+
+ mLooper.dispatchAll();
+ verifyScanResultsReceived(order, handler, secondScanRequestId,
+ expectedPartialResults.getScanData());
+ verifySingleScanCompletedReceived(order, handler, secondScanRequestId);
+
+ controlChannel.sendMessage(
+ Message.obtain(null, WifiScanner.CMD_GET_SINGLE_SCAN_RESULTS, 0));
+ mLooper.dispatchAll();
+ Message response2 = verifyHandleMessageAndGetMessage(order, handler);
+
+ List<ScanResult> results2 = Arrays.asList(
+ ((WifiScanner.ParcelableScanResults) response2.obj).getResults());
+ assertEquals(results2.size(), expectedFullResults.getRawScanResults().length);
+ }
+
+ /**
+ * Verify that the scan results returned by WifiService.getSingleScanResults are not older
+ * than {@link com.android.server.wifi.scanner.WifiScanningServiceImpl
+ * .WifiSingleScanStateMachine#CACHED_SCAN_RESULTS_MAX_AGE_IN_MILLIS}.
+ */
+ @Test
+ public void doesNotRetrieveStaleScanResultsFromLastFullSingleScan() throws Exception {
+ WifiScanner.ScanSettings requestSettings = createRequest(WifiScanner.WIFI_BAND_BOTH, 0,
+ 0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN);
+ ScanResults scanResults = ScanResults.create(0, true, 2400, 5150, 5175);
+
+ // Out of the 3 scan results, modify the timestamp of 2 of them to be within the expiration
+ // age and 1 out of it.
+ long currentTimeInMillis = CACHED_SCAN_RESULTS_MAX_AGE_IN_MILLIS * 2;
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeInMillis);
+ scanResults.getRawScanResults()[0].timestamp = (currentTimeInMillis - 1) * 1000;
+ scanResults.getRawScanResults()[1].timestamp = (currentTimeInMillis - 2) * 1000;
+ scanResults.getRawScanResults()[2].timestamp =
+ (currentTimeInMillis - CACHED_SCAN_RESULTS_MAX_AGE_IN_MILLIS) * 1000;
+ List<ScanResult> expectedResults = new ArrayList<ScanResult>() {{
+ add(scanResults.getRawScanResults()[0]);
+ add(scanResults.getRawScanResults()[1]);
+ }};
+
+ doSuccessfulSingleScan(requestSettings,
+ computeSingleScanNativeSettings(requestSettings), scanResults);
+
+ Handler handler = mock(Handler.class);
+ BidirectionalAsyncChannel controlChannel = connectChannel(handler);
+ InOrder order = inOrder(handler, mWifiScannerImpl);
+
+ controlChannel.sendMessage(
+ Message.obtain(null, WifiScanner.CMD_GET_SINGLE_SCAN_RESULTS, 0));
+ mLooper.dispatchAll();
+ Message response = verifyHandleMessageAndGetMessage(order, handler);
+
+ List<ScanResult> results = Arrays.asList(
+ ((WifiScanner.ParcelableScanResults) response.obj).getResults());
+ assertScanResultsEquals(expectedResults.toArray(new ScanResult[expectedResults.size()]),
+ results.toArray(new ScanResult[results.size()]));
+ }
+
+ /**
* Cached scan results should be cleared after the driver is unloaded.
*/
@Test
@@ -1392,7 +1499,7 @@ public class WifiScanningServiceTest {
verifyScanResultsReceived(order, handler, requestId, results.getScanData());
verifySingleScanCompletedReceived(order, handler, requestId);
verifyScanResultsReceived(order, handler, listenerRequestId, results.getScanData());
- verify(mContext).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL));
+ verify(mContext, never()).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL));
verifyNoMoreInteractions(handler);
assertDumpContainsRequestLog("registerScanListener", listenerRequestId);
@@ -1443,7 +1550,7 @@ public class WifiScanningServiceTest {
mLooper.dispatchAll();
verifyScanResultsReceived(order, handler, requestId, results.getScanData());
verifySingleScanCompletedReceived(order, handler, requestId);
- verify(mContext).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL));
+ verify(mContext, never()).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL));
verifyNoMoreInteractions(handler);
assertDumpContainsRequestLog("registerScanListener", listenerRequestId);
@@ -1522,7 +1629,7 @@ public class WifiScanningServiceTest {
verifyScanResultsReceived(handlerOrder, handler, requestId1, results1.getScanData());
verifySingleScanCompletedReceived(handlerOrder, handler, requestId1);
verifyScanResultsReceived(handlerOrder, handler, listenerRequestId, results1.getScanData());
- verify(mContext).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL));
+ verify(mContext, never()).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL));
// now that the first scan completed we expect the second and third ones to start
WifiNative.ScanEventHandler eventHandler2and3 = verifyStartSingleScan(nativeOrder,