diff options
author | Rebecca Silberstein <silberst@google.com> | 2016-09-12 14:13:43 -0700 |
---|---|---|
committer | Rebecca Silberstein <silberst@google.com> | 2016-09-14 08:55:06 -0700 |
commit | 6c11cd5d6ff04afdf1bbbc99a850025d46c7bdc9 (patch) | |
tree | e006e406d33757d013f77ebab30c427cb5fac128 /tests | |
parent | 09ab1afb011f891166ac34368ef61b88a1250ed9 (diff) |
WifiScanningService: Move scan results bcast
A WifiManager.SCAN_RESULTS_AVIALABLE_ACTION broadcast is sent when scan results
are returned for an app/user initiated scan. This broadcast is now
located in the WifiScanningService instead of WifiStateMachine. Further
cleanup will move retrieval of the scan results from WifiStateMachine to
WifiScanningService. Tests were added to WifiScanningServiceTest to
verify the broadcast is sent in both scanning success and failure cases.
BUG: 31347837
TEST: frameworks/opt/net/wifi/tests/wifitests/runtests.sh on angler
Change-Id: I7c11d571552090057593539b0ed736bc2cedeb00
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java | 21 |
1 files changed, 20 insertions, 1 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 1b0d04d93..bbcb33310 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java @@ -26,6 +26,7 @@ import android.app.test.MockAnswerUtil.AnswerWithArguments; import android.app.test.TestAlarmManager; import android.content.BroadcastReceiver; import android.content.Context; +import android.content.Intent; import android.content.IntentFilter; import android.net.wifi.ScanResult; import android.net.wifi.WifiManager; @@ -36,6 +37,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.RemoteException; +import android.os.UserHandle; import android.os.WorkSource; import android.os.test.TestLooper; import android.test.suitebuilder.annotation.SmallTest; @@ -495,6 +497,7 @@ public class WifiScanningServiceTest { mLooper.dispatchAll(); verifyScanResultsRecieved(order, handler, requestId, results.getScanData()); verifySingleScanCompletedRecieved(order, handler, requestId); + verify(mContext).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL)); verifyNoMoreInteractions(handler); verify(mBatteryStats).noteWifiScanStoppedFromSource(eq(workSource)); assertDumpContainsRequestLog("addSingleScanRequest", requestId); @@ -639,6 +642,7 @@ public class WifiScanningServiceTest { assertEquals(mWifiMetrics.getOneshotScanCount(), 1); assertEquals(mWifiMetrics.getScanReturnEntry(WifiMetricsProto.WifiLog.SCAN_UNKNOWN), 1); verify(mBatteryStats).noteWifiScanStoppedFromSource(eq(workSource)); + verify(mContext).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL)); } /** @@ -755,7 +759,7 @@ public class WifiScanningServiceTest { Handler handler = mock(Handler.class); BidirectionalAsyncChannel controlChannel = connectChannel(handler); - InOrder order = inOrder(handler, mWifiScannerImpl); + InOrder order = inOrder(handler, mWifiScannerImpl, mContext); // Run scan 1 sendSingleScanRequest(controlChannel, requestId1, requestSettings1, null); @@ -771,6 +775,13 @@ public class WifiScanningServiceTest { eventHandler1.onScanStatus(WifiNative.WIFI_SCAN_RESULTS_AVAILABLE); mLooper.dispatchAll(); + // Note: The order of the following verification calls looks out of order if you compare to + // the source code of WifiScanningServiceImpl WifiSingleScanStateMachine.reportScanResults. + // This is due to the fact that verifyScanResultsReceived and + // verifySingleScanCompletedReceived require an additional call to handle the message that + // is created in reportScanResults. This handling is done in the two verify*Received calls + // that is run AFTER the reportScanResults method in WifiScanningServiceImpl completes. + order.verify(mContext).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL)); verifyScanResultsRecieved(order, handler, requestId1, results1.getScanData()); verifySingleScanCompletedRecieved(order, handler, requestId1); @@ -788,6 +799,7 @@ public class WifiScanningServiceTest { eventHandler2.onScanStatus(WifiNative.WIFI_SCAN_RESULTS_AVAILABLE); mLooper.dispatchAll(); + order.verify(mContext).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL)); verifyScanResultsRecieved(order, handler, requestId2, results2.getScanData()); verifySingleScanCompletedRecieved(order, handler, requestId2); } @@ -840,6 +852,7 @@ public class WifiScanningServiceTest { mLooper.dispatchAll(); verifyScanResultsRecieved(handlerOrder, handler, requestId1, results1.getScanData()); verifySingleScanCompletedRecieved(handlerOrder, handler, requestId1); + verify(mContext).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL)); // now that the first scan completed we expect the second one to start WifiNative.ScanEventHandler eventHandler2 = verifyStartSingleScan(nativeOrder, @@ -853,6 +866,7 @@ public class WifiScanningServiceTest { mLooper.dispatchAll(); verifyScanResultsRecieved(handlerOrder, handler, requestId2, results2.getScanData()); verifySingleScanCompletedRecieved(handlerOrder, handler, requestId2); + verify(mContext, times(2)).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL)); assertEquals(mWifiMetrics.getOneshotScanCount(), 2); assertEquals(mWifiMetrics.getScanReturnEntry(WifiMetricsProto.WifiLog.SCAN_SUCCESS), 2); } @@ -929,6 +943,7 @@ public class WifiScanningServiceTest { mLooper.dispatchAll(); verifyScanResultsRecieved(handlerOrder, handler, requestId1, results1.getScanData()); verifySingleScanCompletedRecieved(handlerOrder, handler, requestId1); + verify(mContext).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL)); verify(mBatteryStats).noteWifiScanStoppedFromSource(eq(workSource1)); verify(mBatteryStats).noteWifiScanStartedFromSource(eq(workSource2and3)); @@ -1107,6 +1122,7 @@ public class WifiScanningServiceTest { verifyScanResultsRecieved(handlerOrder, handler, requestId2, results2.getScanData()); verifySingleScanCompletedRecieved(handlerOrder, handler, requestId2); + verify(mContext, times(2)).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL)); assertEquals(mWifiMetrics.getOneshotScanCount(), 3); assertEquals(mWifiMetrics.getScanReturnEntry(WifiMetricsProto.WifiLog.SCAN_SUCCESS), 3); @@ -1163,6 +1179,7 @@ public class WifiScanningServiceTest { verifyScanResultsRecieved(order, handler, requestId, results.getScanData()); verifySingleScanCompletedRecieved(order, handler, requestId); verifyScanResultsRecieved(order, handler, listenerRequestId, results.getScanData()); + verify(mContext).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL)); verifyNoMoreInteractions(handler); assertDumpContainsRequestLog("registerScanListener", listenerRequestId); @@ -1212,6 +1229,7 @@ public class WifiScanningServiceTest { mLooper.dispatchAll(); verifyScanResultsRecieved(order, handler, requestId, results.getScanData()); verifySingleScanCompletedRecieved(order, handler, requestId); + verify(mContext).sendBroadcastAsUser(any(Intent.class), eq(UserHandle.ALL)); verifyNoMoreInteractions(handler); assertDumpContainsRequestLog("registerScanListener", listenerRequestId); @@ -1289,6 +1307,7 @@ public class WifiScanningServiceTest { verifyScanResultsRecieved(handlerOrder, handler, requestId1, results1.getScanData()); verifySingleScanCompletedRecieved(handlerOrder, handler, requestId1); verifyScanResultsRecieved(handlerOrder, handler, listenerRequestId, results1.getScanData()); + verify(mContext).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, |