summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/ScanRequestProxy.java9
-rw-r--r--service/java/com/android/server/wifi/util/WifiPermissionsUtil.java9
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java32
-rw-r--r--tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java20
4 files changed, 67 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/ScanRequestProxy.java b/service/java/com/android/server/wifi/ScanRequestProxy.java
index b9e48ea56..646fa5858 100644
--- a/service/java/com/android/server/wifi/ScanRequestProxy.java
+++ b/service/java/com/android/server/wifi/ScanRequestProxy.java
@@ -349,9 +349,12 @@ public class ScanRequestProxy {
sendScanResultFailureBroadcastToPackage(packageName);
return false;
}
- boolean fromSettings = mWifiPermissionsUtil.checkNetworkSettingsPermission(callingUid);
+ boolean fromSettingsOrSetupWizard =
+ mWifiPermissionsUtil.checkNetworkSettingsPermission(callingUid)
+ || mWifiPermissionsUtil.checkNetworkSetupWizardPermission(callingUid);
// Check and throttle scan request from apps without NETWORK_SETTINGS permission.
- if (!fromSettings && shouldScanRequestBeThrottledForApp(callingUid, packageName)) {
+ if (!fromSettingsOrSetupWizard
+ && shouldScanRequestBeThrottledForApp(callingUid, packageName)) {
Log.i(TAG, "Scan request from " + packageName + " throttled");
sendScanResultFailureBroadcastToPackage(packageName);
return false;
@@ -362,7 +365,7 @@ public class ScanRequestProxy {
// Create the scan settings.
WifiScanner.ScanSettings settings = new WifiScanner.ScanSettings();
// Scan requests from apps with network settings will be of high accuracy type.
- if (fromSettings) {
+ if (fromSettingsOrSetupWizard) {
settings.type = WifiScanner.TYPE_HIGH_ACCURACY;
}
// always do full scans
diff --git a/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java b/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java
index 3d838645d..cf43eb36f 100644
--- a/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java
+++ b/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java
@@ -287,4 +287,13 @@ public class WifiPermissionsUtil {
android.Manifest.permission.NETWORK_SETTINGS, uid)
== PackageManager.PERMISSION_GRANTED;
}
+
+ /**
+ * Returns true if the |uid| holds NETWORK_SETUP_WIZARD permission.
+ */
+ public boolean checkNetworkSetupWizardPermission(int uid) {
+ return mWifiPermissionsWrapper.getUidPermission(
+ android.Manifest.permission.NETWORK_SETUP_WIZARD, uid)
+ == PackageManager.PERMISSION_GRANTED;
+ }
}
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
*/