summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2020-02-28 06:04:47 -0800
committerRoshan Pius <rpius@google.com>2020-02-28 06:07:35 -0800
commit3f30bd7a618d462c10fb2bc5c2c2358adf1951ca (patch)
tree81496a8adff6edfa59523e533ece2536047d3827 /tests
parent6569955c0a0699ceae00edea39de514c9a1d34af (diff)
WifiScanningService: Handle getAvailableChannels() when scanner is off
Add a null check for channel helper to avoid a crash when we get the call from the app when scanner is off (i.e when wifi & location is off). Bug: 150334212 Test: Tested with ag/10433983 (with both wifi off & on) Test: atest com.android.server.wifi.scanner Change-Id: Id178bf5badebe8e7ee5695d1f8884409fb86a6e3
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java25
1 files changed, 25 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 137680c4b..bf70af312 100644
--- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
@@ -3537,4 +3537,29 @@ public class WifiScanningServiceTest extends WifiBaseTest {
List<Integer> expected = Arrays.asList(2400, 2450);
assertEquals(expected, actual);
}
+
+ /**
+ * Tests that {@link WifiScanningServiceImpl#getAvailableChannels(int, String)} returns
+ * an empty array when wifi is off.
+ */
+ @Test
+ public void getAvailableChannels_DoesNotCrashWhenWifiDisabled() throws Exception {
+ // Don't enable wifi.
+
+ // Client doesn't have NETWORK_STACK permission.
+ doThrow(new SecurityException()).when(mContext).enforcePermission(
+ eq(Manifest.permission.NETWORK_STACK), anyInt(), eq(Binder.getCallingUid()), any());
+
+ // has access scan results permission
+ doNothing().when(mWifiPermissionsUtil).enforceCanAccessScanResultsForWifiScanner(
+ TEST_PACKAGE_NAME, TEST_FEATURE_ID, Binder.getCallingUid(), false, false);
+
+ mLooper.startAutoDispatch();
+ Bundle bundle = mWifiScanningServiceImpl.getAvailableChannels(
+ WifiScanner.WIFI_BAND_24_GHZ, TEST_PACKAGE_NAME, TEST_FEATURE_ID);
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
+ List<Integer> actual = bundle.getIntegerArrayList(GET_AVAILABLE_CHANNELS_EXTRA);
+
+ assertTrue(actual.isEmpty());
+ }
}