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

Commit 6a554a54 authored by Roshan Pius's avatar Roshan Pius
Browse files

wifi(API): Send directed broadcast post connection for suggestions

Based on feedback received, moving away from using a PendingIntent for
post connection action (PendingIntent's are impossible to persist &
maybe too heavy for our use-case). We'll now send out a simple directed
broadcast to the app that added the network suggestion.

Also, added annotation indicating the permission requirement for using
the new API.

Bug: 115504887
Test: make api-stubs-docs-update-current-api -j128
Change-Id: Ide169b139ca16d43bd250de4d0447807d85a60ed
parent 5ed7b13a
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -28982,7 +28982,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>, android.app.PendingIntent);
    method public boolean 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);
@@ -29026,9 +29026,11 @@ package android.net.wifi {
    method public deprecated int updateNetwork(android.net.wifi.WifiConfiguration);
    field public static final java.lang.String ACTION_PICK_WIFI_NETWORK = "android.net.wifi.PICK_WIFI_NETWORK";
    field public static final java.lang.String ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE = "android.net.wifi.action.REQUEST_SCAN_ALWAYS_AVAILABLE";
    field public static final java.lang.String ACTION_WIFI_NETWORK_SUGGESTION_POST_CONNECTION = "android.net.wifi.action.WIFI_NETWORK_SUGGESTION_POST_CONNECTION";
    field public static final deprecated int ERROR_AUTHENTICATING = 1; // 0x1
    field public static final deprecated java.lang.String EXTRA_BSSID = "bssid";
    field public static final java.lang.String EXTRA_NETWORK_INFO = "networkInfo";
    field public static final java.lang.String EXTRA_NETWORK_SUGGESTION = "android.net.wifi.extra.NETWORK_SUGGESTION";
    field public static final java.lang.String EXTRA_NEW_RSSI = "newRssi";
    field public static final deprecated java.lang.String EXTRA_NEW_STATE = "newState";
    field public static final java.lang.String EXTRA_PREVIOUS_WIFI_STATE = "previous_wifi_state";
+1 −0
Original line number Diff line number Diff line
@@ -359,6 +359,7 @@
    <protected-broadcast android:name="android.net.wifi.action.PASSPOINT_OSU_PROVIDERS_LIST" />
    <protected-broadcast android:name="android.net.wifi.action.PASSPOINT_SUBSCRIPTION_REMEDIATION" />
    <protected-broadcast android:name="android.net.wifi.action.PASSPOINT_LAUNCH_OSU_VIEW" />
    <protected-broadcast android:name="android.net.wifi.action.WIFI_NETWORK_SUGGESTION_POST_CONNECTION" />
    <protected-broadcast android:name="android.net.wifi.supplicant.CONNECTION_CHANGE" />
    <protected-broadcast android:name="android.net.wifi.supplicant.STATE_CHANGE" />
    <protected-broadcast android:name="android.net.wifi.p2p.STATE_CHANGED" />
+37 −23
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.UnsupportedAppUsage;
import android.app.PendingIntent;
import android.content.Context;
import android.content.pm.ParceledListSlice;
import android.net.ConnectivityManager;
@@ -870,6 +869,28 @@ public class WifiManager {
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_REQUEST_DISABLE = "android.net.wifi.action.REQUEST_DISABLE";

    /**
     * Directed broadcast intent action indicating that the device has connected to one of the
     * network suggestions provided by the app. This will be sent post connection to a network
     * which was created with {@link WifiNetworkConfigBuilder#setIsAppInteractionRequired()} flag
     * set.
     * <p>
     * Note: The broadcast is sent to the app only if it holds either one of
     * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or
     * {@link android.Manifest.permission#ACCESS_FINE_LOCATION ACCESS_FINE_LOCATION} permission.
     *
     * @see #EXTRA_NETWORK_SUGGESTION
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_WIFI_NETWORK_SUGGESTION_POST_CONNECTION =
            "android.net.wifi.action.WIFI_NETWORK_SUGGESTION_POST_CONNECTION";
    /**
     * Sent as as a part of {@link #ACTION_WIFI_NETWORK_SUGGESTION_POST_CONNECTION} that holds
     * an instance of {@link WifiNetworkSuggestion} corresponding to the connected network.
     */
    public static final String EXTRA_NETWORK_SUGGESTION =
            "android.net.wifi.extra.NETWORK_SUGGESTION";

    /**
     * Internally used Wi-Fi lock mode representing the case were no locks are held.
     * @hide
@@ -1036,7 +1057,7 @@ public class WifiManager {
     * @deprecated
     * a) See {@link WifiNetworkConfigBuilder#buildNetworkSpecifier()} for new
     * mechanism to trigger connection to a Wi-Fi network.
     * b) See {@link #addNetworkSuggestions(List, PendingIntent)},
     * b) See {@link #addNetworkSuggestions(List)},
     * {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
     * when auto-connecting to wifi.
     * <b>Compatibility Note:</b> For applications targeting
@@ -1132,7 +1153,7 @@ public class WifiManager {
     * @deprecated
     * a) See {@link WifiNetworkConfigBuilder#buildNetworkSpecifier()} for new
     * mechanism to trigger connection to a Wi-Fi network.
     * b) See {@link #addNetworkSuggestions(List, PendingIntent)},
     * b) See {@link #addNetworkSuggestions(List)},
     * {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
     * when auto-connecting to wifi.
     * <b>Compatibility Note:</b> For applications targeting
@@ -1167,7 +1188,7 @@ public class WifiManager {
     * @deprecated
     * a) See {@link WifiNetworkConfigBuilder#buildNetworkSpecifier()} for new
     * mechanism to trigger connection to a Wi-Fi network.
     * b) See {@link #addNetworkSuggestions(List, PendingIntent)},
     * b) See {@link #addNetworkSuggestions(List)},
     * {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
     * when auto-connecting to wifi.
     * <b>Compatibility Note:</b> For applications targeting
@@ -1437,13 +1458,10 @@ public class WifiManager {
    /**
     * Provide a list of network suggestions to the device. See {@link WifiNetworkSuggestion}
     * for a detailed explanation of the parameters.
     *<p>
     * When the device decides to connect to one of the provided network suggestions, platform fires
     * the associated {@code pendingIntent} if
     * When the device decides to connect to one of the provided network suggestions, platform sends
     * a directed broadcast {@link #ACTION_WIFI_NETWORK_SUGGESTION_POST_CONNECTION} to the app if
     * the network was created with {@link WifiNetworkConfigBuilder#setIsAppInteractionRequired()}
     * flag set and the provided {@code pendingIntent} is non-null.
     *<p>
     * Registration of a non-null pending intent {@code pendingIntent} requires
     * flag set and the app holds either one of
     * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or
     * {@link android.Manifest.permission#ACCESS_FINE_LOCATION ACCESS_FINE_LOCATION} permission.
     *<p>
@@ -1458,17 +1476,12 @@ public class WifiManager {
     * suggestion back using this API.</li>
     *
     * @param networkSuggestions List of network suggestions provided by the app.
     * @param pendingIntent Pending intent to be fired post connection for networks. These will be
     *                      fired only when connecting to a network that was created with
     *                      {@link WifiNetworkConfigBuilder#setIsAppInteractionRequired()} flag set.
     *                      Pending intent must hold a foreground service, else will be rejected.
     * @return true on success, false if any of the suggestions match (See
     * {@link WifiNetworkSuggestion#equals(Object)} any previously provided suggestions by the app.
     * @throws {@link SecurityException} if the caller is missing required permissions.
     */
    public boolean addNetworkSuggestions(
            @NonNull List<WifiNetworkSuggestion> networkSuggestions,
            @Nullable PendingIntent pendingIntent) {
    @RequiresPermission(android.Manifest.permission.CHANGE_WIFI_STATE)
    public boolean addNetworkSuggestions(@NonNull List<WifiNetworkSuggestion> networkSuggestions) {
        // TODO(b/115504887): Implementation
        return false;
    }
@@ -1486,6 +1499,7 @@ public class WifiManager {
     * previously provided by the app. 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(
            @NonNull List<WifiNetworkSuggestion> networkSuggestions) {
        // TODO(b/115504887): Implementation
@@ -1611,7 +1625,7 @@ public class WifiManager {
     * @deprecated
     * a) See {@link WifiNetworkConfigBuilder#buildNetworkSpecifier()} for new
     * mechanism to trigger connection to a Wi-Fi network.
     * b) See {@link #addNetworkSuggestions(List, PendingIntent)},
     * b) See {@link #addNetworkSuggestions(List)},
     * {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
     * when auto-connecting to wifi.
     * <b>Compatibility Note:</b> For applications targeting
@@ -1655,7 +1669,7 @@ public class WifiManager {
     * @deprecated
     * a) See {@link WifiNetworkConfigBuilder#buildNetworkSpecifier()} for new
     * mechanism to trigger connection to a Wi-Fi network.
     * b) See {@link #addNetworkSuggestions(List, PendingIntent)},
     * b) See {@link #addNetworkSuggestions(List)},
     * {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
     * when auto-connecting to wifi.
     * <b>Compatibility Note:</b> For applications targeting
@@ -1687,7 +1701,7 @@ public class WifiManager {
     * @deprecated
     * a) See {@link WifiNetworkConfigBuilder#buildNetworkSpecifier()} for new
     * mechanism to trigger connection to a Wi-Fi network.
     * b) See {@link #addNetworkSuggestions(List, PendingIntent)},
     * b) See {@link #addNetworkSuggestions(List)},
     * {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
     * when auto-connecting to wifi.
     * <b>Compatibility Note:</b> For applications targeting
@@ -1710,7 +1724,7 @@ public class WifiManager {
     * @deprecated
     * a) See {@link WifiNetworkConfigBuilder#buildNetworkSpecifier()} for new
     * mechanism to trigger connection to a Wi-Fi network.
     * b) See {@link #addNetworkSuggestions(List, PendingIntent)},
     * b) See {@link #addNetworkSuggestions(List)},
     * {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
     * when auto-connecting to wifi.
     * <b>Compatibility Note:</b> For applications targeting
@@ -1735,7 +1749,7 @@ public class WifiManager {
     * @deprecated
     * a) See {@link WifiNetworkConfigBuilder#buildNetworkSpecifier()} for new
     * mechanism to trigger connection to a Wi-Fi network.
     * b) See {@link #addNetworkSuggestions(List, PendingIntent)},
     * b) See {@link #addNetworkSuggestions(List)},
     * {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
     * when auto-connecting to wifi.
     * <b>Compatibility Note:</b> For applications targeting
@@ -1760,7 +1774,7 @@ public class WifiManager {
     * @deprecated
     * a) See {@link WifiNetworkConfigBuilder#buildNetworkSpecifier()} for new
     * mechanism to trigger connection to a Wi-Fi network.
     * b) See {@link #addNetworkSuggestions(List, PendingIntent)},
     * b) See {@link #addNetworkSuggestions(List)},
     * {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
     * when auto-connecting to wifi.
     * <b>Compatibility Note:</b> For applications targeting
+5 −8
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static com.android.internal.util.Preconditions.checkNotNull;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.PendingIntent;
import android.net.MacAddress;
import android.net.NetworkRequest;
import android.net.NetworkSpecifier;
@@ -38,7 +37,7 @@ import java.util.List;
 * <li>See {@link #buildNetworkSpecifier()} for creating a network specifier to use in
 * {@link NetworkRequest}.</li>
 * <li>See {@link #buildNetworkSuggestion()} for creating a network suggestion to use in
 * {@link WifiManager#addNetworkSuggestions(List, PendingIntent)}.</li>
 * {@link WifiManager#addNetworkSuggestions(List)}.</li>
 */
public class WifiNetworkConfigBuilder {
    private static final String MATCH_ALL_SSID_PATTERN_PATH = ".*";
@@ -242,13 +241,11 @@ public class WifiNetworkConfigBuilder {
    /**
     * Specifies whether the app needs to log in to a captive portal to obtain Internet access.
     * <p>
     * This will dictate if the associated pending intent in
     * {@link WifiManager#addNetworkSuggestions(List, PendingIntent)} will be sent after
     * successfully connecting to the network.
     * This will dictate if the directed broadcast
     * {@link WifiManager#ACTION_WIFI_NETWORK_SUGGESTION_POST_CONNECTION} will be sent to the app
     * after successfully connecting to the network.
     * Use this for captive portal type networks where the app needs to authenticate the user
     * before the device can access the network.
     * This setting will be ignored if the {@code PendingIntent} used to add this network
     * suggestion is null.
     * <p>
     * <li>Only allowed for creating network suggestion, i.e {@link #buildNetworkSuggestion()}.</li>
     * <li>If not set, defaults to false (i.e no app interaction required).</li>
@@ -481,7 +478,7 @@ public class WifiNetworkConfigBuilder {

    /**
     * Create a network suggestion object use in
     * {@link WifiManager#addNetworkSuggestions(List, PendingIntent)}.
     * {@link WifiManager#addNetworkSuggestions(List)}.
     * See {@link WifiNetworkSuggestion}.
     *
     * @return Instance of {@link WifiNetworkSuggestion}.
+1 −5
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package android.net.wifi;

import static com.android.internal.util.Preconditions.checkNotNull;

import android.app.PendingIntent;
import android.os.Parcel;
import android.os.Parcelable;

@@ -32,7 +31,7 @@ import java.util.Objects;
 * of this object.
 *<p>
 * Apps can provide a list of such networks to the platform using
 * {@link WifiManager#addNetworkSuggestions(List, PendingIntent)}.
 * {@link WifiManager#addNetworkSuggestions(List)}.
 */
public final class WifiNetworkSuggestion implements Parcelable {
    /**
@@ -43,9 +42,6 @@ public final class WifiNetworkSuggestion implements Parcelable {

    /**
     * Whether app needs to log in to captive portal to obtain Internet access.
     * This will dictate if the associated pending intent in
     * {@link WifiManager#addNetworkSuggestions(List, PendingIntent)} needs to be sent after
     * successfully connecting to the network.
     * @hide
     */
    public final boolean isAppInteractionRequired;