From 0a8b73a22306e8644d4ca3afdb42f9d94a9efc8d Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Tue, 24 Apr 2018 10:27:30 -0700 Subject: 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 --- .../android/server/wifi/ScanRequestProxyTest.java | 32 ++++++++++++++++++++++ .../server/wifi/util/WifiPermissionsUtilTest.java | 20 ++++++++++++++ 2 files changed, 52 insertions(+) (limited to 'tests') 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. @@ -528,6 +540,26 @@ public class ScanRequestProxyTest { mInOrder.verify(mWifiScanner).startScan(any(), any(), any()); } + /** + * 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. */ 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 @@ -473,6 +473,26 @@ public class WifiPermissionsUtilTest { codeUnderTest.enforceLocationPermission(TEST_PACKAGE_NAME, mUid); } + /** + * 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 -- cgit v1.2.3