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

Commit 10740295 authored by Quang Luong's avatar Quang Luong
Browse files

Add @SystemApi allowAutojoin(int, boolean) to WifiManager

WifiManager.allowAutojoin(int, boolean) lets a user toggle whether a
saved network should be allowed to be auto-joined. This "allowAutojoin"
bit is stored within the WifiConfiguration of a saved network.

Bug: 139199957
Test: atest FrameworksWifiApiTests
Change-Id: Ia8650abb59dc53a010accc44bd7b6e28facce992
parent 41a5cd6f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -4708,6 +4708,7 @@ package android.net.wifi {
    method @Deprecated public boolean hasNoInternetAccess();
    method @Deprecated public boolean isEphemeral();
    method @Deprecated public boolean isNoInternetAccessExpected();
    field @Deprecated public boolean allowAutojoin;
    field @Deprecated public String creatorName;
    field @Deprecated public int creatorUid;
    field @Deprecated public String lastUpdateName;
@@ -4730,6 +4731,7 @@ package android.net.wifi {
  public class WifiManager {
    method @RequiresPermission("android.permission.WIFI_UPDATE_USABILITY_STATS_SCORE") public void addOnWifiUsabilityStatsListener(@NonNull java.util.concurrent.Executor, @NonNull android.net.wifi.WifiManager.OnWifiUsabilityStatsListener);
    method @RequiresPermission("android.permission.NETWORK_SETTINGS") public void allowAutojoin(int, boolean);
    method @RequiresPermission(anyOf={"android.permission.NETWORK_SETTINGS", android.Manifest.permission.NETWORK_SETUP_WIZARD, "android.permission.NETWORK_STACK"}) public void connect(@NonNull android.net.wifi.WifiConfiguration, @Nullable android.net.wifi.WifiManager.ActionListener);
    method @RequiresPermission(anyOf={"android.permission.NETWORK_SETTINGS", android.Manifest.permission.NETWORK_SETUP_WIZARD, "android.permission.NETWORK_STACK"}) public void connect(int, @Nullable android.net.wifi.WifiManager.ActionListener);
    method @Deprecated @RequiresPermission(anyOf={"android.permission.NETWORK_SETTINGS", android.Manifest.permission.NETWORK_SETUP_WIZARD, "android.permission.NETWORK_STACK"}) public void disable(int, @Nullable android.net.wifi.WifiManager.ActionListener);
+2 −0
Original line number Diff line number Diff line
@@ -93,6 +93,8 @@ interface IWifiManager

    boolean disableNetwork(int netId, String packageName);

    void allowAutojoin(int netId, boolean choice);

    boolean startScan(String packageName);

    List<ScanResult> getScanResults(String callingPackage);
+12 −0
Original line number Diff line number Diff line
@@ -735,6 +735,14 @@ public class WifiConfiguration implements Parcelable {
     */
    public int userApproved = USER_UNSPECIFIED;

    /**
     * @hide
     * Auto-join is allowed by user for this network.
     * Default true.
     */
    @SystemApi
    public boolean allowAutojoin = true;

    /** The Below RSSI thresholds are used to configure AutoJoin
     *  - GOOD/LOW/BAD thresholds are used so as to calculate link score
     *  - UNWANTED_SOFT are used by the blacklisting logic so as to handle
@@ -2022,6 +2030,7 @@ public class WifiConfiguration implements Parcelable {
        if (updateIdentifier != null) sbuf.append(" updateIdentifier=" + updateIdentifier);
        sbuf.append(" lcuid=" + lastConnectUid);
        sbuf.append(" userApproved=" + userApprovedAsString(userApproved));
        sbuf.append(" allowAutojoin=" + allowAutojoin);
        sbuf.append(" noInternetAccessExpected=" + noInternetAccessExpected);
        sbuf.append(" ");

@@ -2421,6 +2430,7 @@ public class WifiConfiguration implements Parcelable {
            numScorerOverrideAndSwitchedNetwork = source.numScorerOverrideAndSwitchedNetwork;
            numAssociation = source.numAssociation;
            userApproved = source.userApproved;
            allowAutojoin = source.allowAutojoin;
            numNoInternetAccessReports = source.numNoInternetAccessReports;
            noInternetAccessExpected = source.noInternetAccessExpected;
            creationTime = source.creationTime;
@@ -2496,6 +2506,7 @@ public class WifiConfiguration implements Parcelable {
        dest.writeInt(numScorerOverrideAndSwitchedNetwork);
        dest.writeInt(numAssociation);
        dest.writeInt(userApproved);
        dest.writeBoolean(allowAutojoin);
        dest.writeInt(numNoInternetAccessReports);
        dest.writeInt(noInternetAccessExpected ? 1 : 0);
        dest.writeInt(shared ? 1 : 0);
@@ -2571,6 +2582,7 @@ public class WifiConfiguration implements Parcelable {
                config.numScorerOverrideAndSwitchedNetwork = in.readInt();
                config.numAssociation = in.readInt();
                config.userApproved = in.readInt();
                config.allowAutojoin = in.readBoolean();
                config.numNoInternetAccessReports = in.readInt();
                config.noInternetAccessExpected = in.readInt() != 0;
                config.shared = in.readInt() != 0;
+23 −0
Original line number Diff line number Diff line
@@ -3841,6 +3841,29 @@ public class WifiManager {
        }
    }

    /**
     * Sets the user choice for allowing auto-join to a network.
     * The updated choice will be made available through the updated config supplied by the
     * CONFIGURED_NETWORKS_CHANGED broadcast.
     *
     * @param netId the id of the network to allow/disallow autojoin for.
     * @param choice true to allow autojoin, false to disallow autojoin
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
    public void allowAutojoin(int netId, boolean choice) {
        try {
            IWifiManager iWifiManager = getIWifiManager();
            if (iWifiManager == null) {
                throw new RemoteException("Wifi service is not running");
            }
            iWifiManager.allowAutojoin(netId, choice);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Disable ephemeral Network
     *
+5 −0
Original line number Diff line number Diff line
@@ -166,6 +166,11 @@ public class BaseWifiService extends IWifiManager.Stub {
        throw new UnsupportedOperationException();
    }

    @Override
    public void allowAutojoin(int netId, boolean choice) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean startScan(String packageName) {
        throw new UnsupportedOperationException();
Loading