summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java48
1 files changed, 48 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 c61ceb4a9..ea1fb51d5 100644
--- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
@@ -18,6 +18,7 @@ package com.android.server.wifi.scanner;
import static android.content.pm.PackageManager.PERMISSION_DENIED;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
+import static android.net.wifi.WifiScanner.GET_AVAILABLE_CHANNELS_EXTRA;
import static com.android.server.wifi.ScanTestUtil.NativeScanSettingsBuilder;
import static com.android.server.wifi.ScanTestUtil.assertNativePnoSettingsEquals;
@@ -3490,4 +3491,51 @@ public class WifiScanningServiceTest extends WifiBaseTest {
verifyPnoNetworkFoundReceived(order, handler, requestId, scanResults.getRawScanResults());
}
+
+ /**
+ * Tests that {@link WifiScanningServiceImpl#getAvailableChannels(int, String)} throws a
+ * {@link SecurityException} if the caller doesn't hold the required permissions.
+ */
+ @Test(expected = SecurityException.class)
+ public void getAvailableChannels_noPermission_throwsException() throws Exception {
+ startServiceAndLoadDriver();
+
+ // no MAINLINE_WIFI_STACK permission
+ doThrow(new SecurityException()).when(mContext).enforcePermission(
+ eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), anyInt(),
+ eq(Binder.getCallingUid()), any());
+
+ // Location permission or mode check fail.
+ doThrow(new SecurityException())
+ .when(mWifiPermissionsUtil).enforceCanAccessScanResultsForWifiScanner(
+ TEST_PACKAGE_NAME, Binder.getCallingUid(), false, false);
+
+ mWifiScanningServiceImpl.getAvailableChannels(WifiScanner.WIFI_BAND_24_GHZ,
+ TEST_PACKAGE_NAME);
+ }
+
+ /**
+ * Tests that {@link WifiScanningServiceImpl#getAvailableChannels(int, String)} returns
+ * the expected result if the caller does hold the required permissions.
+ */
+ @Test
+ public void getAvailableChannels_hasPermission_returnsSuccessfully() throws Exception {
+ startServiceAndLoadDriver();
+
+ // has MAINLINE_WIFI_STACK permission
+ doNothing().when(mContext).enforcePermission(
+ eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), anyInt(),
+ eq(Binder.getCallingUid()), any());
+
+ // has access scan results permission
+ doNothing().when(mWifiPermissionsUtil).enforceCanAccessScanResultsForWifiScanner(
+ TEST_PACKAGE_NAME, Binder.getCallingUid(), false, false);
+
+ Bundle bundle = mWifiScanningServiceImpl.getAvailableChannels(
+ WifiScanner.WIFI_BAND_24_GHZ, TEST_PACKAGE_NAME);
+ List<Integer> actual = bundle.getIntegerArrayList(GET_AVAILABLE_CHANNELS_EXTRA);
+
+ List<Integer> expected = Arrays.asList(2400, 2450);
+ assertEquals(expected, actual);
+ }
}