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

Commit 796b2dba authored by David Su's avatar David Su
Browse files

Scan Optimization: expose API to update device mobility state

Exposed API in WifiManager to allow device mobility state to
be updated, so that Wifi scan interval can be increased when the
device is stationary in order to save power. Also added a new
permission to protect this API from being used by unauthorized
applications.

Bug: 120097108
Test: Call new API method using test app
Change-Id: Iee59dba711c23add5d4b2affafeac2c009407c7f
parent 66f04be1
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -3707,6 +3707,7 @@ package android.net.wifi {
    method public boolean isWifiScannerSupported();
    method public boolean isWifiScannerSupported();
    method public void registerNetworkRequestMatchCallback(android.net.wifi.WifiManager.NetworkRequestMatchCallback, android.os.Handler);
    method public void registerNetworkRequestMatchCallback(android.net.wifi.WifiManager.NetworkRequestMatchCallback, android.os.Handler);
    method public void save(android.net.wifi.WifiConfiguration, android.net.wifi.WifiManager.ActionListener);
    method public void save(android.net.wifi.WifiConfiguration, android.net.wifi.WifiManager.ActionListener);
    method public void setDeviceMobilityState(int);
    method public boolean setWifiApConfiguration(android.net.wifi.WifiConfiguration);
    method public boolean setWifiApConfiguration(android.net.wifi.WifiConfiguration);
    method public boolean startScan(android.os.WorkSource);
    method public boolean startScan(android.os.WorkSource);
    method public void unregisterNetworkRequestMatchCallback(android.net.wifi.WifiManager.NetworkRequestMatchCallback);
    method public void unregisterNetworkRequestMatchCallback(android.net.wifi.WifiManager.NetworkRequestMatchCallback);
@@ -3714,6 +3715,10 @@ package android.net.wifi {
    field public static final int CHANGE_REASON_CONFIG_CHANGE = 2; // 0x2
    field public static final int CHANGE_REASON_CONFIG_CHANGE = 2; // 0x2
    field public static final int CHANGE_REASON_REMOVED = 1; // 0x1
    field public static final int CHANGE_REASON_REMOVED = 1; // 0x1
    field public static final java.lang.String CONFIGURED_NETWORKS_CHANGED_ACTION = "android.net.wifi.CONFIGURED_NETWORKS_CHANGE";
    field public static final java.lang.String CONFIGURED_NETWORKS_CHANGED_ACTION = "android.net.wifi.CONFIGURED_NETWORKS_CHANGE";
    field public static final int DEVICE_MOBILITY_STATE_HIGH_MVMT = 1; // 0x1
    field public static final int DEVICE_MOBILITY_STATE_LOW_MVMT = 2; // 0x2
    field public static final int DEVICE_MOBILITY_STATE_STATIONARY = 3; // 0x3
    field public static final int DEVICE_MOBILITY_STATE_UNKNOWN = 0; // 0x0
    field public static final java.lang.String EXTRA_CHANGE_REASON = "changeReason";
    field public static final java.lang.String EXTRA_CHANGE_REASON = "changeReason";
    field public static final java.lang.String EXTRA_MULTIPLE_NETWORKS_CHANGED = "multipleChanges";
    field public static final java.lang.String EXTRA_MULTIPLE_NETWORKS_CHANGED = "multipleChanges";
    field public static final java.lang.String EXTRA_PREVIOUS_WIFI_AP_STATE = "previous_wifi_state";
    field public static final java.lang.String EXTRA_PREVIOUS_WIFI_AP_STATE = "previous_wifi_state";
+6 −0
Original line number Original line Diff line number Diff line
@@ -1642,6 +1642,12 @@
    <permission android:name="android.permission.NETWORK_BYPASS_PRIVATE_DNS"
    <permission android:name="android.permission.NETWORK_BYPASS_PRIVATE_DNS"
        android:protectionLevel="signature" />
        android:protectionLevel="signature" />


    <!-- #SystemApi @hide Allows device mobility state to be set so that Wifi scan interval can be increased
         when the device is stationary in order to save power.
         <p>Not for use by third-party applications. -->
    <permission android:name="android.permission.WIFI_SET_DEVICE_MOBILITY_STATE"
        android:protectionLevel="signature|privileged" />

    <!-- ======================================= -->
    <!-- ======================================= -->
    <!-- Permissions for short range, peripheral networks -->
    <!-- Permissions for short range, peripheral networks -->
    <!-- ======================================= -->
    <!-- ======================================= -->
+2 −0
Original line number Original line Diff line number Diff line
@@ -195,5 +195,7 @@ interface IWifiManager
    int removeNetworkSuggestions(in List<WifiNetworkSuggestion> networkSuggestions, in String packageName);
    int removeNetworkSuggestions(in List<WifiNetworkSuggestion> networkSuggestions, in String packageName);


    String[] getFactoryMacAddresses();
    String[] getFactoryMacAddresses();

    void setDeviceMobilityState(int state);
}
}
+65 −0
Original line number Original line Diff line number Diff line
@@ -4449,4 +4449,69 @@ public class WifiManager {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
    }
    }

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = {"DEVICE_MOBILITY_STATE_"}, value = {
            DEVICE_MOBILITY_STATE_UNKNOWN,
            DEVICE_MOBILITY_STATE_HIGH_MVMT,
            DEVICE_MOBILITY_STATE_LOW_MVMT,
            DEVICE_MOBILITY_STATE_STATIONARY})
    public @interface DeviceMobilityState {}

    /**
     * Unknown device mobility state
     *
     * @see #setDeviceMobilityState(int)
     *
     * @hide
     */
    @SystemApi
    public static final int DEVICE_MOBILITY_STATE_UNKNOWN = 0;

    /**
     * High movement device mobility state
     *
     * @see #setDeviceMobilityState(int)
     *
     * @hide
     */
    @SystemApi
    public static final int DEVICE_MOBILITY_STATE_HIGH_MVMT = 1;

    /**
     * Low movement device mobility state
     *
     * @see #setDeviceMobilityState(int)
     *
     * @hide
     */
    @SystemApi
    public static final int DEVICE_MOBILITY_STATE_LOW_MVMT = 2;

    /**
     * Stationary device mobility state
     *
     * @see #setDeviceMobilityState(int)
     *
     * @hide
     */
    @SystemApi
    public static final int DEVICE_MOBILITY_STATE_STATIONARY = 3;

    /**
     * Updates the device mobility state. Wifi uses this information to adjust the interval between
     * Wifi scans in order to balance power consumption with scan accuracy.
     * @param state the updated device mobility state
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.WIFI_SET_DEVICE_MOBILITY_STATE)
    public void setDeviceMobilityState(@DeviceMobilityState int state) {
        try {
            mService.setDeviceMobilityState(state);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}
}