summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2018-04-27 17:32:38 -0700
committerandroid-build-merger <android-build-merger@google.com>2018-04-27 17:32:38 -0700
commited094e0de54afdfae423ddf63d653c5af2f385ae (patch)
treeef47e559968cde702c5038191471e6e8172b3d83
parent3d5988fb82c91975e206068588525be99f5bbad0 (diff)
parent7d8f472a86f2d2dee7719c1e467d808608fcfe0a (diff)
Merge "Revert "Revert "WifiService: Return status from startScan()""" into pi-dev
am: 7d8f472a86 Change-Id: I71b6becfe79db4cab8b448cdfc44d4f38083e2d7
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java28
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java30
2 files changed, 43 insertions, 15 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 3f566c355..4d9dbf7e7 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -600,15 +600,14 @@ public class WifiServiceImpl extends IWifiManager.Stub {
}
/**
- * see {@link android.net.wifi.WifiManager#startScan}
- * and {@link android.net.wifi.WifiManager#startCustomizedScan}
+ * See {@link android.net.wifi.WifiManager#startScan}
*
* @param packageName Package name of the app that requests wifi scan.
*/
@Override
- public void startScan(String packageName) {
+ public boolean startScan(String packageName) {
if (enforceChangePermission(packageName) != MODE_ALLOWED) {
- return;
+ return false;
}
int callingUid = Binder.getCallingUid();
@@ -624,19 +623,24 @@ public class WifiServiceImpl extends IWifiManager.Stub {
// be sent directly until b/31398592 is fixed.
sendFailedScanBroadcast();
mScanPending = true;
- return;
+ return false;
}
}
- boolean success = mWifiInjector.getWifiStateMachineHandler().runWithScissors(() -> {
- if (!mScanRequestProxy.startScan(callingUid, packageName)) {
- Log.e(TAG, "Failed to start scan");
- }
- }, RUN_WITH_SCISSORS_TIMEOUT_MILLIS);
- if (!success) {
- // TODO: should return false here
+ Mutable<Boolean> scanSuccess = new Mutable<>();
+ boolean runWithScissorsSuccess = mWifiInjector.getWifiStateMachineHandler()
+ .runWithScissors(() -> {
+ scanSuccess.value = mScanRequestProxy.startScan(callingUid, packageName);
+ }, RUN_WITH_SCISSORS_TIMEOUT_MILLIS);
+ if (!runWithScissorsSuccess) {
Log.e(TAG, "Failed to post runnable to start scan");
sendFailedScanBroadcast();
+ return false;
}
+ if (!scanSuccess.value) {
+ Log.e(TAG, "Failed to start scan");
+ return false;
+ }
+ return true;
}
// Send a failed scan broadcast to indicate the current scan request failed.
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 25be0980f..f64ce59e5 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -314,6 +314,7 @@ public class WifiServiceImplTest {
when(mContext.getOpPackageName()).thenReturn(TEST_PACKAGE_NAME);
when(mContext.checkPermission(eq(android.Manifest.permission.NETWORK_SETTINGS),
anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_DENIED);
+ when(mScanRequestProxy.startScan(anyInt(), anyString())).thenReturn(true);
ArgumentCaptor<SoftApCallback> softApCallbackCaptor =
ArgumentCaptor.forClass(SoftApCallback.class);
@@ -1025,6 +1026,18 @@ public class WifiServiceImplTest {
}
/**
+ * Ensure that we handle app ops check failure when handling scan request.
+ */
+ @Test
+ public void testStartScanFailureAppOpsIgnored() {
+ setupWifiStateMachineHandlerForRunWithScissors();
+ doReturn(AppOpsManager.MODE_IGNORED).when(mAppOpsManager)
+ .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), SCAN_PACKAGE_NAME);
+ assertFalse(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME));
+ verify(mScanRequestProxy, never()).startScan(Process.myUid(), SCAN_PACKAGE_NAME);
+ }
+
+ /**
* Ensure that we handle scan request failure when posting the runnable to handler fails.
*/
@Ignore
@@ -1033,10 +1046,21 @@ public class WifiServiceImplTest {
setupWifiStateMachineHandlerForRunWithScissors();
doReturn(false).when(mHandlerSpyForWsmRunWithScissors)
.runWithScissors(any(), anyLong());
- mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME);
+ assertFalse(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME));
verify(mScanRequestProxy, never()).startScan(Process.myUid(), SCAN_PACKAGE_NAME);
}
+ /**
+ * Ensure that we handle scan request failure from ScanRequestProxy fails.
+ */
+ @Test
+ public void testStartScanFailureFromScanRequestProxy() {
+ setupWifiStateMachineHandlerForRunWithScissors();
+ when(mScanRequestProxy.startScan(anyInt(), anyString())).thenReturn(false);
+ assertFalse(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME));
+ verify(mScanRequestProxy).startScan(Process.myUid(), SCAN_PACKAGE_NAME);
+ }
+
static final String TEST_SSID = "Sid's Place";
static final String TEST_SSID_WITH_QUOTES = "\"" + TEST_SSID + "\"";
static final String TEST_BSSID = "01:02:03:04:05:06";
@@ -2528,7 +2552,7 @@ public class WifiServiceImplTest {
TestUtil.sendIdleModeChanged(mBroadcastReceiverCaptor.getValue(), mContext);
// Send a scan request while the device is idle.
- mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME);
+ assertFalse(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME));
// No scans must be made yet as the device is idle.
verify(mScanRequestProxy, never()).startScan(Process.myUid(), SCAN_PACKAGE_NAME);
@@ -2545,7 +2569,7 @@ public class WifiServiceImplTest {
// Send another scan request. The device is not idle anymore, so it must be executed
// immediately.
- mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME);
+ assertTrue(mWifiServiceImpl.startScan(SCAN_PACKAGE_NAME));
verify(mScanRequestProxy).startScan(Process.myUid(), SCAN_PACKAGE_NAME);
}