WifiScanner: Create @hide API's with executor

Add/Modify @hide versions of the following API's which accept an executor
along with the listener:
a) startSingleScan
b) startDisconnectedPnoScan
c) staryConnectedPnoScan

These new @hide API's will be used by wifi service to ensure that the
listener callbacks happen on the wifi service thread.

Note: This uses the infra support added in WifiScanner class recently
for the public registerScanListener API which accepts an executor.

Bug: 145746458
Test: Device boots up and connects to wifi networks.
Change-Id: I6feaf4614153dabe2f493dcfcbbbf2dc8cf7b71e
This commit is contained in:
Roshan Pius
2020-01-10 13:01:17 -08:00
parent ce03848dce
commit c34c2bfab1
2 changed files with 34 additions and 12 deletions

View File

@@ -833,6 +833,7 @@ public class WifiScanner {
* delivered to the listener. It is possible that onFullResult will not be called for all
* results of the first scan if the listener was registered during the scan.
*
* @param executor the Executor on which to run the callback.
* @param listener specifies the object to report events to. This object is also treated as a
* key for this request, and must also be specified to cancel the request.
* Multiple requests should also not share this object.
@@ -955,15 +956,32 @@ public class WifiScanner {
* starts a single scan and reports results asynchronously
* @param settings specifies various parameters for the scan; for more information look at
* {@link ScanSettings}
* @param workSource WorkSource to blame for power usage
* @param listener specifies the object to report events to. This object is also treated as a
* key for this scan, and must also be specified to cancel the scan. Multiple
* scans should also not share this object.
* @param workSource WorkSource to blame for power usage
*/
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
public void startScan(ScanSettings settings, ScanListener listener, WorkSource workSource) {
startScan(settings, null, listener, workSource);
}
/**
* starts a single scan and reports results asynchronously
* @param settings specifies various parameters for the scan; for more information look at
* {@link ScanSettings}
* @param executor the Executor on which to run the callback.
* @param listener specifies the object to report events to. This object is also treated as a
* key for this scan, and must also be specified to cancel the scan. Multiple
* scans should also not share this object.
* @param workSource WorkSource to blame for power usage
* @hide
*/
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
public void startScan(ScanSettings settings, @Nullable @CallbackExecutor Executor executor,
ScanListener listener, WorkSource workSource) {
Objects.requireNonNull(listener, "listener cannot be null");
int key = addListener(listener);
int key = addListener(listener, executor);
if (key == INVALID_KEY) return;
validateChannel();
Bundle scanParams = new Bundle();
@@ -1029,16 +1047,17 @@ public class WifiScanner {
* {@link ScanSettings}
* @param pnoSettings specifies various parameters for PNO; for more information look at
* {@link PnoSettings}
* @param executor the Executor on which to run the callback.
* @param listener specifies the object to report events to. This object is also treated as a
* key for this scan, and must also be specified to cancel the scan. Multiple
* scans should also not share this object.
* {@hide}
*/
public void startConnectedPnoScan(ScanSettings scanSettings, PnoSettings pnoSettings,
PnoScanListener listener) {
@NonNull @CallbackExecutor Executor executor, PnoScanListener listener) {
Objects.requireNonNull(listener, "listener cannot be null");
Objects.requireNonNull(pnoSettings, "pnoSettings cannot be null");
int key = addListener(listener);
int key = addListener(listener, executor);
if (key == INVALID_KEY) return;
validateChannel();
pnoSettings.isConnected = true;
@@ -1057,10 +1076,10 @@ public class WifiScanner {
*/
@RequiresPermission(android.Manifest.permission.NETWORK_STACK)
public void startDisconnectedPnoScan(ScanSettings scanSettings, PnoSettings pnoSettings,
PnoScanListener listener) {
@NonNull @CallbackExecutor Executor executor, PnoScanListener listener) {
Objects.requireNonNull(listener, "listener cannot be null");
Objects.requireNonNull(pnoSettings, "pnoSettings cannot be null");
int key = addListener(listener);
int key = addListener(listener, executor);
if (key == INVALID_KEY) return;
validateChannel();
pnoSettings.isConnected = false;

View File

@@ -366,7 +366,7 @@ public class WifiScannerTest {
/**
* Test behavior of {@link WifiScanner#startDisconnectedPnoScan(ScanSettings, PnoSettings,
* WifiScanner.PnoScanListener)}
* Executor, WifiScanner.PnoScanListener)}
* @throws Exception
*/
@Test
@@ -375,7 +375,8 @@ public class WifiScannerTest {
PnoSettings pnoSettings = new PnoSettings();
WifiScanner.PnoScanListener pnoScanListener = mock(WifiScanner.PnoScanListener.class);
mWifiScanner.startDisconnectedPnoScan(scanSettings, pnoSettings, pnoScanListener);
mWifiScanner.startDisconnectedPnoScan(
scanSettings, pnoSettings, mock(Executor.class), pnoScanListener);
mLooper.dispatchAll();
ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
@@ -396,7 +397,7 @@ public class WifiScannerTest {
/**
* Test behavior of {@link WifiScanner#startConnectedPnoScan(ScanSettings, PnoSettings,
* WifiScanner.PnoScanListener)}
* Executor, WifiScanner.PnoScanListener)}
* @throws Exception
*/
@Test
@@ -405,7 +406,8 @@ public class WifiScannerTest {
PnoSettings pnoSettings = new PnoSettings();
WifiScanner.PnoScanListener pnoScanListener = mock(WifiScanner.PnoScanListener.class);
mWifiScanner.startConnectedPnoScan(scanSettings, pnoSettings, pnoScanListener);
mWifiScanner.startConnectedPnoScan(
scanSettings, pnoSettings, mock(Executor.class), pnoScanListener);
mLooper.dispatchAll();
ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
@@ -426,7 +428,7 @@ public class WifiScannerTest {
/**
* Test behavior of {@link WifiScanner#stopPnoScan(ScanListener)}
* WifiScanner.PnoScanListener)}
* Executor, WifiScanner.PnoScanListener)}
* @throws Exception
*/
@Test
@@ -435,7 +437,8 @@ public class WifiScannerTest {
PnoSettings pnoSettings = new PnoSettings();
WifiScanner.PnoScanListener pnoScanListener = mock(WifiScanner.PnoScanListener.class);
mWifiScanner.startDisconnectedPnoScan(scanSettings, pnoSettings, pnoScanListener);
mWifiScanner.startDisconnectedPnoScan(
scanSettings, pnoSettings, mock(Executor.class), pnoScanListener);
mLooper.dispatchAll();
mWifiScanner.stopPnoScan(pnoScanListener);
mLooper.dispatchAll();