diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2018-05-07 13:32:16 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-05-07 13:32:16 +0000 |
commit | 430be97a7c41bfa7538ebeec1d5667281a8edf73 (patch) | |
tree | 8ba1f1ce1f89da757df18c1b53eea24b45df4efc /tests | |
parent | 1d9f9c5e9759f140355bcd7520442580339b4298 (diff) | |
parent | 72024817b555c872ef21cfbcca3b33851a406d29 (diff) |
Merge "WifiScanningServiceImpl: Ignore duplicate scan available" into pi-dev
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java | 130 |
1 files changed, 130 insertions, 0 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 08eca85f7..85f1bede0 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java @@ -497,6 +497,23 @@ public class WifiScanningServiceTest { assertDumpContainsRequestLog("addBackgroundScanRequest", 192); } + /** + * Verifies that duplicate SCAN_AVAILABLE broadcast with |WIFI_STATE_ENABLED| is ignored. + */ + @Test + public void duplicateScanAvailableBroadcastIsIgnored() throws RemoteException { + startServiceAndLoadDriver(); + + // Send scan available again. + TestUtil.sendWifiScanAvailable(mBroadcastReceiver, mContext, + WifiManager.WIFI_STATE_ENABLED); + mLooper.dispatchAll(); + + // Ensure we didn't create scanner instance twice. + verify(mWifiScannerImplFactory, times(1)) + .create(any(), any(), any()); + } + @Test public void disconnectClientAfterStartingWifi() throws Exception { mWifiScanningServiceImpl.startService(); @@ -2293,4 +2310,117 @@ public class WifiScanningServiceTest { messenger.send(message); verify(mFrameworkFacade, never()).makeWifiAsyncChannel(anyString()); } + + /** + * Verifies that background scan works after duplicate SCAN_AVAILABLE broadcast with + * |WIFI_STATE_ENABLED|. + */ + @Test + public void backgroundScanAfterDuplicateScanAvailableBroadcast() throws RemoteException { + startServiceAndLoadDriver(); + + // Send scan available again. + TestUtil.sendWifiScanAvailable(mBroadcastReceiver, mContext, + WifiManager.WIFI_STATE_ENABLED); + mLooper.dispatchAll(); + + // Ensure we didn't create scanner instance twice. + verify(mWifiScannerImplFactory, times(1)) + .create(any(), any(), any()); + + Handler handler = mock(Handler.class); + BidirectionalAsyncChannel controlChannel = connectChannel(handler); + InOrder order = inOrder(handler); + when(mWifiScannerImpl.startBatchedScan(any(WifiNative.ScanSettings.class), + any(WifiNative.ScanEventHandler.class))).thenReturn(true); + sendBackgroundScanRequest(controlChannel, 192, generateValidScanSettings(), null); + mLooper.dispatchAll(); + verifySuccessfulResponse(order, handler, 192); + assertDumpContainsRequestLog("addBackgroundScanRequest", 192); + } + + /** + * Verifies that single scan works after duplicate SCAN_AVAILABLE broadcast with + * |WIFI_STATE_ENABLED|. + */ + @Test + public void singleScanScanAfterDuplicateScanAvailableBroadcast() throws RemoteException { + startServiceAndLoadDriver(); + + // Send scan available again. + TestUtil.sendWifiScanAvailable(mBroadcastReceiver, mContext, + WifiManager.WIFI_STATE_ENABLED); + mLooper.dispatchAll(); + + // Ensure we didn't create scanner instance twice. + verify(mWifiScannerImplFactory, times(1)) + .create(any(), any(), any()); + + Handler handler = mock(Handler.class); + BidirectionalAsyncChannel controlChannel = connectChannel(handler); + InOrder order = inOrder(handler, mWifiScannerImpl); + + int requestId = 12; + WorkSource workSource = new WorkSource(2292); + WifiScanner.ScanSettings requestSettings = createRequest(channelsToSpec(2400, 5150, 5175), + 0, 0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN); + ScanResults results = ScanResults.create(0, true, 2400, 5150, 5175); + + when(mWifiScannerImpl.startSingleScan(any(WifiNative.ScanSettings.class), + any(WifiNative.ScanEventHandler.class))).thenReturn(true); + + sendSingleScanRequest(controlChannel, requestId, requestSettings, workSource); + + mLooper.dispatchAll(); + WifiNative.ScanEventHandler eventHandler = + verifyStartSingleScan(order, computeSingleScanNativeSettings(requestSettings)); + verifySuccessfulResponse(order, handler, requestId); + verify(mBatteryStats).noteWifiScanStartedFromSource(eq(workSource)); + + when(mWifiScannerImpl.getLatestSingleScanResults()) + .thenReturn(results.getRawScanData()); + eventHandler.onScanStatus(WifiNative.WIFI_SCAN_RESULTS_AVAILABLE); + + mLooper.dispatchAll(); + verifyScanResultsReceived(order, handler, requestId, results.getScanData()); + verifySingleScanCompletedReceived(order, handler, requestId); + verifyNoMoreInteractions(handler); + verify(mBatteryStats).noteWifiScanStoppedFromSource(eq(workSource)); + assertDumpContainsRequestLog("addSingleScanRequest", requestId); + assertDumpContainsCallbackLog("singleScanResults", requestId, + "results=" + results.getScanData().getResults().length); + } + + /** + * Verifies that pno scan works after duplicate SCAN_AVAILABLE broadcast with + * |WIFI_STATE_ENABLED|. + */ + @Test + public void hwPnoScanScanAfterDuplicateScanAvailableBroadcast() throws Exception { + startServiceAndLoadDriver(); + + // Send scan available again. + TestUtil.sendWifiScanAvailable(mBroadcastReceiver, mContext, + WifiManager.WIFI_STATE_ENABLED); + mLooper.dispatchAll(); + + // Ensure we didn't create scanner instance twice. + verify(mWifiScannerImplFactory, times(1)) + .create(any(), any(), any()); + + Handler handler = mock(Handler.class); + BidirectionalAsyncChannel controlChannel = connectChannel(handler); + InOrder order = inOrder(handler, mWifiScannerImpl); + int requestId = 12; + + ScanResults scanResults = createScanResultsForPno(); + Pair<WifiScanner.ScanSettings, WifiNative.ScanSettings> scanSettings = + createScanSettingsForHwPno(); + Pair<WifiScanner.PnoSettings, WifiNative.PnoSettings> pnoSettings = + createPnoSettings(scanResults); + + sendPnoScanRequest(controlChannel, requestId, scanSettings.first, pnoSettings.first); + expectHwPnoScan(order, handler, requestId, pnoSettings.second, scanResults); + verifyPnoNetworkFoundReceived(order, handler, requestId, scanResults.getRawScanResults()); + } } |