diff options
author | Roshan Pius <rpius@google.com> | 2018-04-24 10:27:30 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2018-04-24 14:12:23 -0700 |
commit | 0a8b73a22306e8644d4ca3afdb42f9d94a9efc8d (patch) | |
tree | c1a41adc6679f4c34d04c1570eb91ac5a3757213 /tests | |
parent | 61b3c8fc8d4af0ed5283520dcd7b40723721d720 (diff) |
ScanRequestProxy: Bypass scan throttling for setup wizard
Use the newly added |NETWORK_SETUP_WIZARD| permission to bypass scan
throttling for setup wizard.
Bug: 77924407
Test: Unit tests
Test: Verified setup wizard scan requests are not throttled.
Change-Id: Id39824b3543bbdb5b9df6923f6c0775993c377fd
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java | 32 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java | 20 |
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java b/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java index b42f53648..e18429599 100644 --- a/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java @@ -147,6 +147,18 @@ public class ScanRequestProxyTest { validateScanSettings(mScanSettingsArgumentCaptor.getValue(), false, true); } + /** + * Verify scan request will forwarded to wifiscanner if wifiscanner is present. + */ + @Test + public void testStartScanSuccessFromAppWithNetworkSetupWizard() { + when(mWifiPermissionsUtil.checkNetworkSetupWizardPermission(TEST_UID)).thenReturn(true); + assertTrue(mScanRequestProxy.startScan(TEST_UID, TEST_PACKAGE_NAME_1)); + mInOrder.verify(mWifiScanner).startScan(any(), any(), any()); + + assertTrue(mWorkSourceArgumentCaptor.getValue().equals(new WorkSource(TEST_UID))); + validateScanSettings(mScanSettingsArgumentCaptor.getValue(), false, true); + } /** * Verify that hidden network list is not retrieved when hidden network scanning is disabled. @@ -529,6 +541,26 @@ public class ScanRequestProxyTest { } /** + * Ensure new scan requests from the same app with NETWORK_SETUP_WIZARD permission are not + * throttled. + */ + @Test + public void testSuccessiveScanRequestFromSameAppWithNetworkSetupWizardPermissionNotThrottled() { + when(mWifiPermissionsUtil.checkNetworkSetupWizardPermission(TEST_UID)).thenReturn(true); + + long firstRequestMs = 782; + when(mClock.getElapsedSinceBootMillis()).thenReturn(firstRequestMs); + for (int i = 0; i < SCAN_REQUEST_THROTTLE_MAX_IN_TIME_WINDOW_FG_APPS; i++) { + when(mClock.getElapsedSinceBootMillis()).thenReturn(firstRequestMs + i); + assertTrue(mScanRequestProxy.startScan(TEST_UID, TEST_PACKAGE_NAME_1)); + mInOrder.verify(mWifiScanner).startScan(any(), any(), any()); + } + // Make next scan request from the same package name & ensure that it is not throttled. + assertTrue(mScanRequestProxy.startScan(TEST_UID, TEST_PACKAGE_NAME_1)); + mInOrder.verify(mWifiScanner).startScan(any(), any(), any()); + } + + /** * Ensure new scan requests from different apps are not throttled. */ @Test diff --git a/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java index bfe660c9d..1e7bbd284 100644 --- a/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java +++ b/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java @@ -474,6 +474,26 @@ public class WifiPermissionsUtilTest { } /** + * Verifies the helper method exposed for checking NETWORK_SETUP_WIZARD permission. + */ + @Test + public void testCheckNetworkSetupWizard() throws Exception { + setupMocks(); + WifiPermissionsUtil wifiPermissionsUtil = new WifiPermissionsUtil(mMockPermissionsWrapper, + mMockContext, mMockWifiSettingsStore, mMockUserManager, mWifiInjector); + + when(mMockPermissionsWrapper.getUidPermission( + android.Manifest.permission.NETWORK_SETUP_WIZARD, MANAGED_PROFILE_UID)) + .thenReturn(PackageManager.PERMISSION_DENIED); + assertFalse(wifiPermissionsUtil.checkNetworkSetupWizardPermission(MANAGED_PROFILE_UID)); + + when(mMockPermissionsWrapper.getUidPermission( + android.Manifest.permission.NETWORK_SETUP_WIZARD, MANAGED_PROFILE_UID)) + .thenReturn(PackageManager.PERMISSION_GRANTED); + assertTrue(wifiPermissionsUtil.checkNetworkSetupWizardPermission(MANAGED_PROFILE_UID)); + } + + /** * Test case setting: caller does not have Location permission. * Expect a SecurityException */ |