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

Commit 4762f45b authored by Roshan Pius's avatar Roshan Pius Committed by Android (Google) Code Review
Browse files

Merge "WifiManager: Set a max limit on num of suggestions"

parents ae39b387 d1a4a56b
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -29054,7 +29054,7 @@ package android.net.wifi {
  public class WifiManager {
    method public deprecated int addNetwork(android.net.wifi.WifiConfiguration);
    method public boolean addNetworkSuggestions(java.util.List<android.net.wifi.WifiNetworkSuggestion>);
    method public int addNetworkSuggestions(java.util.List<android.net.wifi.WifiNetworkSuggestion>);
    method public void addOrUpdatePasspointConfiguration(android.net.wifi.hotspot2.PasspointConfiguration);
    method public static int calculateSignalLevel(int, int);
    method public deprecated void cancelWps(android.net.wifi.WifiManager.WpsCallback);
@@ -29068,6 +29068,7 @@ package android.net.wifi {
    method public deprecated java.util.List<android.net.wifi.WifiConfiguration> getConfiguredNetworks();
    method public android.net.wifi.WifiInfo getConnectionInfo();
    method public android.net.DhcpInfo getDhcpInfo();
    method public int getMaxNumberOfNetworkSuggestionsPerApp();
    method public java.util.List<android.net.wifi.hotspot2.PasspointConfiguration> getPasspointConfigurations();
    method public java.util.List<android.net.wifi.ScanResult> getScanResults();
    method public int getWifiState();
@@ -29086,7 +29087,7 @@ package android.net.wifi {
    method public deprecated boolean reassociate();
    method public deprecated boolean reconnect();
    method public deprecated boolean removeNetwork(int);
    method public boolean removeNetworkSuggestions(java.util.List<android.net.wifi.WifiNetworkSuggestion>);
    method public int removeNetworkSuggestions(java.util.List<android.net.wifi.WifiNetworkSuggestion>);
    method public void removePasspointConfiguration(java.lang.String);
    method public deprecated boolean saveConfiguration();
    method public void setTdlsEnabled(java.net.InetAddress, boolean);
@@ -29115,6 +29116,11 @@ package android.net.wifi {
    field public static final java.lang.String NETWORK_STATE_CHANGED_ACTION = "android.net.wifi.STATE_CHANGE";
    field public static final java.lang.String RSSI_CHANGED_ACTION = "android.net.wifi.RSSI_CHANGED";
    field public static final java.lang.String SCAN_RESULTS_AVAILABLE_ACTION = "android.net.wifi.SCAN_RESULTS";
    field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE = 2; // 0x2
    field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_EXCEEDS_MAX_PER_APP = 3; // 0x3
    field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_INTERNAL = 1; // 0x1
    field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID = 4; // 0x4
    field public static final int STATUS_NETWORK_SUGGESTIONS_SUCCESS = 0; // 0x0
    field public static final deprecated java.lang.String SUPPLICANT_CONNECTION_CHANGE_ACTION = "android.net.wifi.supplicant.CONNECTION_CHANGE";
    field public static final deprecated java.lang.String SUPPLICANT_STATE_CHANGED_ACTION = "android.net.wifi.supplicant.STATE_CHANGE";
    field public static final int WIFI_MODE_FULL = 1; // 0x1
@@ -29156,6 +29162,9 @@ package android.net.wifi {
    method public void setReferenceCounted(boolean);
  }
  public static abstract class WifiManager.NetworkSuggestionsStatusCode implements java.lang.annotation.Annotation {
  }
  public class WifiManager.WifiLock {
    method public void acquire();
    method public boolean isHeld();
+2 −2
Original line number Diff line number Diff line
@@ -190,8 +190,8 @@ interface IWifiManager

    void unregisterNetworkRequestMatchCallback(int callbackIdentifier);

    boolean addNetworkSuggestions(in List<WifiNetworkSuggestion> networkSuggestions, in String packageName);
    int addNetworkSuggestions(in List<WifiNetworkSuggestion> networkSuggestions, in String packageName);

    boolean removeNetworkSuggestions(in List<WifiNetworkSuggestion> networkSuggestions, in String packageName);
    int removeNetworkSuggestions(in List<WifiNetworkSuggestion> networkSuggestions, in String packageName);
}
+68 −9
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.UnsupportedAppUsage;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ParceledListSlice;
import android.net.ConnectivityManager;
@@ -136,6 +137,55 @@ public class WifiManager {
    @Deprecated
    public static final int ERROR_AUTH_FAILURE_EAP_FAILURE = 3;

    /**
     * Maximum number of active network suggestions allowed per app.
     * @hide
     */
    public static final int NETWORK_SUGGESTIONS_MAX_PER_APP =
            ActivityManager.isLowRamDeviceStatic() ? 256 : 1024;

    /**
     * Reason code if all of the network suggestions were successfully added or removed.
     */
    public static final int STATUS_NETWORK_SUGGESTIONS_SUCCESS = 0;

    /**
     * Reason code if there was an internal error in the platform while processing the addition or
     * removal of suggestions.
     */
    public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_INTERNAL = 1;

    /**
     * Reason code if one or more of the network suggestions added already exists in platform's
     * database.
     * @see WifiNetworkSuggestion#equals(Object)
     */
    public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE = 2;

    /**
     * Reason code if the number of network suggestions provided by the app crosses the max
     * threshold set per app.
     * @see #getMaxNumberOfNetworkSuggestionsPerApp()
     */
    public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_EXCEEDS_MAX_PER_APP = 3;

    /**
     * Reason code if one or more of the network suggestions removed does not exist in platform's
     * database.
     */
    public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID = 4;

    @IntDef(prefix = { "STATUS_NETWORK_SUGGESTIONS_" }, value = {
            STATUS_NETWORK_SUGGESTIONS_SUCCESS,
            STATUS_NETWORK_SUGGESTIONS_ERROR_INTERNAL,
            STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE,
            STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_EXCEEDS_MAX_PER_APP,
            STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID,
    })

    @Retention(RetentionPolicy.SOURCE)
    public @interface NetworkSuggestionsStatusCode {}

    /**
     * Broadcast intent action indicating whether Wi-Fi scanning is allowed currently
     * @hide
@@ -1497,12 +1547,13 @@ public class WifiManager {
     * suggestion back using this API.</li>
     *
     * @param networkSuggestions List of network suggestions provided by the app.
     * @return true on success, false if any of the suggestions match (See
     * @return Status code corresponding to the values in {@link NetworkSuggestionsStatusCode}.
     * {@link WifiNetworkSuggestion#equals(Object)} any previously provided suggestions by the app.
     * @throws {@link SecurityException} if the caller is missing required permissions.
     */
    @RequiresPermission(android.Manifest.permission.CHANGE_WIFI_STATE)
    public boolean addNetworkSuggestions(@NonNull List<WifiNetworkSuggestion> networkSuggestions) {
    public @NetworkSuggestionsStatusCode int addNetworkSuggestions(
            @NonNull List<WifiNetworkSuggestion> networkSuggestions) {
        try {
            return mService.addNetworkSuggestions(networkSuggestions, mContext.getOpPackageName());
        } catch (RemoteException e) {
@@ -1510,21 +1561,20 @@ public class WifiManager {
        }
    }


    /**
     * Remove a subset of or all of networks from previously provided suggestions by the app to the
     * device.
     * Remove some or all of the network suggestions that were previously provided by the app.
     * See {@link WifiNetworkSuggestion} for a detailed explanation of the parameters.
     * See {@link WifiNetworkSuggestion#equals(Object)} for the equivalence evaluation used.
     *
     * @param networkSuggestions List of network suggestions to be removed. Pass an empty list
     *                           to remove all the previous suggestions provided by the app.
     * @return true on success, false if any of the suggestions do not match any suggestions
     * previously provided by the app. Any matching suggestions are removed from the device and
     * will not be considered for any further connection attempts.
     * @return Status code corresponding to the values in
     * {@link NetworkSuggestionsStatusCode}.
     * Any matching suggestions are removed from the device and will not be considered for any
     * further connection attempts.
     */
    @RequiresPermission(android.Manifest.permission.CHANGE_WIFI_STATE)
    public boolean removeNetworkSuggestions(
    public @NetworkSuggestionsStatusCode int removeNetworkSuggestions(
            @NonNull List<WifiNetworkSuggestion> networkSuggestions) {
        try {
            return mService.removeNetworkSuggestions(
@@ -1534,6 +1584,15 @@ public class WifiManager {
        }
    }

    /**
     * Returns the max number of network suggestions that are allowed per app on the device.
     * @see #addNetworkSuggestions(List)
     * @see #removeNetworkSuggestions(List)
     */
    public int getMaxNumberOfNetworkSuggestionsPerApp() {
        return NETWORK_SUGGESTIONS_MAX_PER_APP;
    }

    /**
     * Add or update a Passpoint configuration.  The configuration provides a credential
     * for connecting to Passpoint networks that are operated by the Passpoint
+2 −2
Original line number Diff line number Diff line
@@ -442,13 +442,13 @@ public abstract class AbstractWifiService extends IWifiManager.Stub {
    }

    @Override
    public boolean addNetworkSuggestions(
    public int addNetworkSuggestions(
            List<WifiNetworkSuggestion> networkSuggestions, String callingPackageName) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean removeNetworkSuggestions(
    public int removeNetworkSuggestions(
            List<WifiNetworkSuggestion> networkSuggestions, String callingPackageName) {
        throw new UnsupportedOperationException();
    }
+17 −4
Original line number Diff line number Diff line
@@ -1298,13 +1298,26 @@ i * Verify that a call to cancel WPS immediately returns a failure.
     */
    @Test
    public void addRemoveNetworkSuggestions() throws Exception {
        when(mWifiService.addNetworkSuggestions(any(List.class), anyString())).thenReturn(true);
        when(mWifiService.removeNetworkSuggestions(any(List.class), anyString())).thenReturn(true);
        when(mWifiService.addNetworkSuggestions(any(List.class), anyString()))
                .thenReturn(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS);
        when(mWifiService.removeNetworkSuggestions(any(List.class), anyString()))
                .thenReturn(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS);

        assertTrue(mWifiManager.addNetworkSuggestions(new ArrayList<>()));
        assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
                mWifiManager.addNetworkSuggestions(new ArrayList<>()));
        verify(mWifiService).addNetworkSuggestions(anyList(), eq(TEST_PACKAGE_NAME));

        assertTrue(mWifiManager.removeNetworkSuggestions(new ArrayList<>()));
        assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
                mWifiManager.removeNetworkSuggestions(new ArrayList<>()));
        verify(mWifiService).removeNetworkSuggestions(anyList(), eq(TEST_PACKAGE_NAME));
    }

    /**
     * Verify call to {@link WifiManager#getMaxNumberOfNetworkSuggestionsPerApp()}.
     */
    @Test
    public void getMaxNumberOfNetworkSuggestionsPerApp() {
        assertEquals(WifiManager.NETWORK_SUGGESTIONS_MAX_PER_APP,
                mWifiManager.getMaxNumberOfNetworkSuggestionsPerApp());
    }
}