summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2018-04-23 10:59:31 -0700
committerRoshan Pius <rpius@google.com>2018-04-25 10:05:32 -0700
commit7daee3fabb13a50a788fb2eb7aaec1f9ebc62efc (patch)
tree55bc8be5a38a10be40f8be3b59a93ce9d0c660fd /tests
parent404c4bc4a2b5b662d5d796f4085e33f0f7aeb5b8 (diff)
WifiService: Return status from startScan()
Bug: 77297012 Test: Unit tests Test: Ensured that scans from settings are still running. Change-Id: I54f8fa6c33d5c1a27f777bfc90eb829a0b501d29
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java30
1 files changed, 27 insertions, 3 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 136d029d3..6280ae1da 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -311,6 +311,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);
@@ -1022,6 +1023,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
@@ -1030,10 +1043,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";
@@ -2525,7 +2549,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);
@@ -2542,7 +2566,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);
}