Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 368b170a authored by Roshan Pius's avatar Roshan Pius
Browse files

WifiManager: Add API for scan throttling

Needed for moving away from using Settings.Global values as pseudo APIs.

Bug: 148514485
Test: atest android.net.wifi
Test: Verified wifi scan throttle toggle in Developer options
Change-Id: I2e6e2d1fde22baeaddab18cf558e442d49c138dd
parent d4f55edc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -31295,6 +31295,7 @@ package android.net.wifi {
    method public boolean isP2pSupported();
    method public boolean isPreferredNetworkOffloadSupported();
    method @Deprecated public boolean isScanAlwaysAvailable();
    method @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) public boolean isScanThrottleEnabled();
    method public boolean isStaApConcurrencySupported();
    method public boolean isTdlsSupported();
    method public boolean isWapiSupported();
+1 −0
Original line number Diff line number Diff line
@@ -7693,6 +7693,7 @@ package android.net.wifi {
    method @RequiresPermission(android.Manifest.permission.WIFI_SET_DEVICE_MOBILITY_STATE) public void setDeviceMobilityState(int);
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setMacRandomizationSettingPasspointEnabled(@NonNull String, boolean);
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setMeteredOverridePasspoint(@NonNull String, int);
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setScanThrottleEnabled(boolean);
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public boolean setSoftApConfiguration(@NonNull android.net.wifi.SoftApConfiguration);
    method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setVerboseLoggingEnabled(boolean);
    method @Deprecated @RequiresPermission(android.Manifest.permission.CHANGE_WIFI_STATE) public boolean setWifiApConfiguration(android.net.wifi.WifiConfiguration);
+4 −0
Original line number Diff line number Diff line
@@ -266,4 +266,8 @@ interface IWifiManager
     * Return the Map of {@link WifiNetworkSuggestion} and the list of <ScanResult>
     */
    Map getMatchingScanResults(in List<WifiNetworkSuggestion> networkSuggestions, in List<ScanResult> scanResults, String callingPackage, String callingFeatureId);

    void setScanThrottleEnabled(boolean enable);

    boolean isScanThrottleEnabled();
}
+44 −0
Original line number Diff line number Diff line
@@ -6118,4 +6118,48 @@ public class WifiManager {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Enable/disable wifi scan throttling from 3rd party apps.
     *
     * <p>
     * The throttling limits for apps are described in
     * <a href="Wi-Fi Scan Throttling">
     * https://developer.android.com/guide/topics/connectivity/wifi-scan#wifi-scan-throttling</a>
     * </p>
     *
     * @param enable true to allow scan throttling, false to disallow scan throttling.
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
    public void setScanThrottleEnabled(boolean enable) {
        try {
            mService.setScanThrottleEnabled(enable);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Get the persisted Wi-Fi scan throttle state. Defaults to true, unless changed by the user via
     * Developer options.
     *
     * <p>
     * The throttling limits for apps are described in
     * <a href="Wi-Fi Scan Throttling">
     * https://developer.android.com/guide/topics/connectivity/wifi-scan#wifi-scan-throttling</a>
     * </p>
     *
     * @return true to indicate that scan throttling is enabled, false to indicate that scan
     * throttling is disabled.
     */
    @RequiresPermission(ACCESS_WIFI_STATE)
    public boolean isScanThrottleEnabled() {
        try {
            return mService.isScanThrottleEnabled();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -2380,4 +2380,14 @@ public class WifiManagerTest {
        verify(mWifiConnectedNetworkScorer).start(0);
        verify(mWifiConnectedNetworkScorer).stop(10);
    }

    @Test
    public void testScanThrottle() throws Exception {
        mWifiManager.setScanThrottleEnabled(true);
        verify(mWifiService).setScanThrottleEnabled(true);

        when(mWifiService.isScanThrottleEnabled()).thenReturn(false);
        assertFalse(mWifiManager.isScanThrottleEnabled());
        verify(mWifiService).isScanThrottleEnabled();
    }
}