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

Commit eca3d568 authored by Roshan Pius's avatar Roshan Pius
Browse files

WifiNetworkSuggestion: Add setOemPrivate flag

Also, plumb the flag to WifiInfo.

Bug: 169413079
Test: atest android.net.wifi
Change-Id: I4985c3a2544684fe067e3e5aaaa612a62c611880
parent a16a0a96
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -7676,8 +7676,11 @@ package android.net.wifi {
    method public double getSuccessfulRxPacketsPerSecond();
    method public double getSuccessfulTxPacketsPerSecond();
    method public boolean isEphemeral();
    method public boolean isOemPaid();
    method public boolean isOemPrivate();
    method public boolean isOsuAp();
    method public boolean isPasspointAp();
    method public boolean isTrusted();
    method @Nullable public static String sanitizeSsid(@Nullable String);
    field public static final String DEFAULT_MAC_ADDRESS = "02:00:00:00:00:00";
    field public static final int INVALID_RSSI = -127; // 0xffffff81
@@ -7903,11 +7906,13 @@ package android.net.wifi {
  public final class WifiNetworkSuggestion implements android.os.Parcelable {
    method @NonNull public android.net.wifi.WifiConfiguration getWifiConfiguration();
    method public boolean isOemPaid();
    method public boolean isOemPrivate();
  }
  public static final class WifiNetworkSuggestion.Builder {
    method @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_CARRIER_PROVISIONING) public android.net.wifi.WifiNetworkSuggestion.Builder setCarrierId(int);
    method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setOemPaid(boolean);
    method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setOemPrivate(boolean);
  }
  public class WifiScanner {
+5 −0
Original line number Diff line number Diff line
@@ -428,8 +428,11 @@ package android.net.wifi {
    method public double getSuccessfulRxPacketsPerSecond();
    method public double getSuccessfulTxPacketsPerSecond();
    method public boolean isEphemeral();
    method public boolean isOemPaid();
    method public boolean isOemPrivate();
    method public boolean isOsuAp();
    method public boolean isPasspointAp();
    method public boolean isTrusted();
    method @Nullable public static String sanitizeSsid(@Nullable String);
    field public static final String DEFAULT_MAC_ADDRESS = "02:00:00:00:00:00";
    field public static final int INVALID_RSSI = -127; // 0xffffff81
@@ -618,11 +621,13 @@ package android.net.wifi {
  public final class WifiNetworkSuggestion implements android.os.Parcelable {
    method @NonNull public android.net.wifi.WifiConfiguration getWifiConfiguration();
    method public boolean isOemPaid();
    method public boolean isOemPrivate();
  }

  public static final class WifiNetworkSuggestion.Builder {
    method @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_CARRIER_PROVISIONING) public android.net.wifi.WifiNetworkSuggestion.Builder setCarrierId(int);
    method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setOemPaid(boolean);
    method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setOemPrivate(boolean);
  }

  public class WifiScanner {
+18 −2
Original line number Diff line number Diff line
@@ -1011,6 +1011,17 @@ public class WifiConfiguration implements Parcelable {
     */
    public boolean oemPaid;


    /**
     * Indicate whether the network is oem private or not. Networks are considered oem private
     * if the corresponding connection is only available to system apps.
     *
     * This bit can only be used by suggestion network, see
     * {@link WifiNetworkSuggestion.Builder#setOemPrivate(boolean)}
     * @hide
     */
    public boolean oemPrivate;

    /**
     * True if this Wifi configuration is created from a {@link WifiNetworkSuggestion},
     * false otherwise.
@@ -2249,6 +2260,7 @@ public class WifiConfiguration implements Parcelable {
        osu = false;
        trusted = true; // Networks are considered trusted by default.
        oemPaid = false;
        oemPrivate = false;
        fromWifiNetworkSuggestion = false;
        fromWifiNetworkSpecifier = false;
        meteredHint = false;
@@ -2372,13 +2384,14 @@ public class WifiConfiguration implements Parcelable {
        if (this.osu) sbuf.append(" osu");
        if (this.trusted) sbuf.append(" trusted");
        if (this.oemPaid) sbuf.append(" oemPaid");
        if (this.oemPrivate) sbuf.append(" oemPrivate");
        if (this.fromWifiNetworkSuggestion) sbuf.append(" fromWifiNetworkSuggestion");
        if (this.fromWifiNetworkSpecifier) sbuf.append(" fromWifiNetworkSpecifier");
        if (this.meteredHint) sbuf.append(" meteredHint");
        if (this.useExternalScores) sbuf.append(" useExternalScores");
        if (this.validatedInternetAccess || this.ephemeral || this.trusted || this.oemPaid
                || this.fromWifiNetworkSuggestion || this.fromWifiNetworkSpecifier
                || this.meteredHint || this.useExternalScores) {
                || this.oemPrivate || this.fromWifiNetworkSuggestion
                || this.fromWifiNetworkSpecifier || this.meteredHint || this.useExternalScores) {
            sbuf.append("\n");
        }
        if (this.meteredOverride != METERED_OVERRIDE_NONE) {
@@ -2943,6 +2956,7 @@ public class WifiConfiguration implements Parcelable {
            osu = source.osu;
            trusted = source.trusted;
            oemPaid = source.oemPaid;
            oemPrivate = source.oemPrivate;
            fromWifiNetworkSuggestion = source.fromWifiNetworkSuggestion;
            fromWifiNetworkSpecifier = source.fromWifiNetworkSpecifier;
            meteredHint = source.meteredHint;
@@ -3024,6 +3038,7 @@ public class WifiConfiguration implements Parcelable {
        dest.writeInt(ephemeral ? 1 : 0);
        dest.writeInt(trusted ? 1 : 0);
        dest.writeInt(oemPaid ? 1 : 0);
        dest.writeInt(oemPrivate ? 1 : 0);
        dest.writeInt(fromWifiNetworkSuggestion ? 1 : 0);
        dest.writeInt(fromWifiNetworkSpecifier ? 1 : 0);
        dest.writeInt(meteredHint ? 1 : 0);
@@ -3102,6 +3117,7 @@ public class WifiConfiguration implements Parcelable {
                config.ephemeral = in.readInt() != 0;
                config.trusted = in.readInt() != 0;
                config.oemPaid = in.readInt() != 0;
                config.oemPrivate = in.readInt() != 0;
                config.fromWifiNetworkSuggestion =  in.readInt() != 0;
                config.fromWifiNetworkSpecifier =  in.readInt() != 0;
                config.meteredHint = in.readInt() != 0;
+39 −3
Original line number Diff line number Diff line
@@ -163,6 +163,11 @@ public class WifiInfo implements Parcelable {
     */
    private boolean mOemPaid;

    /**
     * Whether the network is oem private or not.
     */
    private boolean mOemPrivate;

    /**
     * OSU (Online Sign Up) AP for Passpoint R2.
     */
@@ -327,6 +332,9 @@ public class WifiInfo implements Parcelable {
        setFrequency(-1);
        setMeteredHint(false);
        setEphemeral(false);
        setTrusted(false);
        setOemPaid(false);
        setOemPrivate(false);
        setOsuAp(false);
        setRequestingPackageName(null);
        setFQDN(null);
@@ -363,7 +371,8 @@ public class WifiInfo implements Parcelable {
            mMeteredHint = source.mMeteredHint;
            mEphemeral = source.mEphemeral;
            mTrusted = source.mTrusted;
            mTrusted = source.mOemPaid;
            mOemPaid = source.mOemPaid;
            mOemPrivate = source.mOemPrivate;
            mRequestingPackageName =
                    source.mRequestingPackageName;
            mOsuAp = source.mOsuAp;
@@ -722,7 +731,12 @@ public class WifiInfo implements Parcelable {
        mTrusted = trusted;
    }

    /** {@hide} */
    /**
     * Returns true if the current Wifi network is a trusted network, false otherwise.
     * @see WifiNetworkSuggestion.Builder#setUntrusted(boolean).
     * {@hide}
     */
    @SystemApi
    public boolean isTrusted() {
        return mTrusted;
    }
@@ -732,11 +746,31 @@ public class WifiInfo implements Parcelable {
        mOemPaid = oemPaid;
    }

    /** {@hide} */
    /**
     * Returns true if the current Wifi network is an oem paid network, false otherwise.
     * @see WifiNetworkSuggestion.Builder#setOemPaid(boolean).
     * {@hide}
     */
    @SystemApi
    public boolean isOemPaid() {
        return mOemPaid;
    }

    /** {@hide} */
    public void setOemPrivate(boolean oemPrivate) {
        mOemPrivate = oemPrivate;
    }

    /**
     * Returns true if the current Wifi network is an oem private network, false otherwise.
     * @see WifiNetworkSuggestion.Builder#setOemPrivate(boolean).
     * {@hide}
     */
    @SystemApi
    public boolean isOemPrivate() {
        return mOemPrivate;
    }

    /** {@hide} */
    public void setOsuAp(boolean osuAp) {
        mOsuAp = osuAp;
@@ -975,6 +1009,7 @@ public class WifiInfo implements Parcelable {
        dest.writeInt(mEphemeral ? 1 : 0);
        dest.writeInt(mTrusted ? 1 : 0);
        dest.writeInt(mOemPaid ? 1 : 0);
        dest.writeInt(mOemPrivate ? 1 : 0);
        dest.writeInt(score);
        dest.writeLong(txSuccess);
        dest.writeDouble(mSuccessfulTxPacketsPerSecond);
@@ -1021,6 +1056,7 @@ public class WifiInfo implements Parcelable {
                info.mEphemeral = in.readInt() != 0;
                info.mTrusted = in.readInt() != 0;
                info.mOemPaid = in.readInt() != 0;
                info.mOemPrivate = in.readInt() != 0;
                info.score = in.readInt();
                info.txSuccess = in.readLong();
                info.mSuccessfulTxPacketsPerSecond = in.readDouble();
+84 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.net.MacAddress;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.net.wifi.hotspot2.PasspointConfiguration;
import android.os.Parcel;
import android.os.Parcelable;
@@ -179,6 +180,12 @@ public final class WifiNetworkSuggestion implements Parcelable {
         */
        private boolean mIsNetworkOemPaid;

        /**
         * Whether this network will be brought up as OEM private (OEM_PRIVATE capability bit
         * added).
         */
        private boolean mIsNetworkOemPrivate;

        /**
         * Whether this network will use enhanced MAC randomization.
         */
@@ -206,6 +213,7 @@ public final class WifiNetworkSuggestion implements Parcelable {
            mWapiEnterpriseConfig = null;
            mIsNetworkUntrusted = false;
            mIsNetworkOemPaid = false;
            mIsNetworkOemPrivate = false;
            mPriorityGroup = 0;
            mIsEnhancedMacRandomizationEnabled = false;
            mSubscriptionId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
@@ -667,6 +675,9 @@ public final class WifiNetworkSuggestion implements Parcelable {
         * reduce it). The connectivity service may use this information to influence the overall
         * network configuration of the device.
         * <p>
         * <li> These suggestions are only considered for network selection if a
         * {@link NetworkRequest} without {@link NetworkCapabilities#NET_CAPABILITY_TRUSTED}
         * capability is filed.
         * <li> An untrusted network's credentials may not be shared with the user using
         * {@link #setCredentialSharedWithUser(boolean)}.</li>
         * <li> If not set, defaults to false (i.e. network is trusted).</li>
@@ -688,7 +699,7 @@ public final class WifiNetworkSuggestion implements Parcelable {
         * <li>The connectivity service may use this information to influence the overall
         * network configuration of the device. This network is typically only available to system
         * apps.
         * <li>On devices which support only 1 concurrent connection (indicated via
         * <li>On devices which do not support concurrent connection (indicated via
         * {@link WifiManager#isMultiStaConcurrencySupported()}, Wi-Fi network selection process may
         * use this information to influence priority of the suggested network for Wi-Fi network
         * selection (most likely to reduce it).
@@ -699,6 +710,13 @@ public final class WifiNetworkSuggestion implements Parcelable {
         * <p>
         * <li> An OEM paid network's credentials may not be shared with the user using
         * {@link #setCredentialSharedWithUser(boolean)}.</li>
         * <li> These suggestions are only considered for network selection if a
         * {@link NetworkRequest} with {@link NetworkCapabilities#NET_CAPABILITY_OEM_PAID}
         * capability is filed.
         * <li> Each suggestion can have both {@link #setOemPaid(boolean)} and
         * {@link #setOemPrivate(boolean)} set if the app wants these suggestions considered
         * for creating either an OEM paid network or OEM private network determined based on
         * the {@link NetworkRequest} that is active.
         * <li> If not set, defaults to false (i.e. network is not OEM paid).</li>
         *
         * @param isOemPaid Boolean indicating whether the network should be brought up as OEM paid
@@ -715,6 +733,48 @@ public final class WifiNetworkSuggestion implements Parcelable {
            return this;
        }

        /**
         * Specifies whether the system will bring up the network (if selected) as OEM private. An
         * OEM private network has {@link NetworkCapabilities#NET_CAPABILITY_OEM_PRIVATE} capability
         * added.
         * Note:
         * <li>The connectivity service may use this information to influence the overall
         * network configuration of the device. This network is typically only available to system
         * apps.
         * <li>On devices which do not support concurrent connection (indicated via
         * {@link WifiManager#isMultiStaConcurrencySupported()}, Wi-Fi network selection process may
         * use this information to influence priority of the suggested network for Wi-Fi network
         * selection (most likely to reduce it).
         * <li>On devices which support more than 1 concurrent connections (indicated via
         * {@link WifiManager#isMultiStaConcurrencySupported()}, these OEM private networks will be
         * brought up as a secondary concurrent connection (primary connection will be used
         * for networks available to the user and all apps.
         * <p>
         * <li> An OEM private network's credentials may not be shared with the user using
         * {@link #setCredentialSharedWithUser(boolean)}.</li>
         * <li> These suggestions are only considered for network selection if a
         * {@link NetworkRequest} with {@link NetworkCapabilities#NET_CAPABILITY_OEM_PRIVATE}
         * capability is filed.
         * <li> Each suggestion can have both {@link #setOemPaid(boolean)} and
         * {@link #setOemPrivate(boolean)} set if the app wants these suggestions considered
         * for creating either an OEM paid network or OEM private network determined based on
         * the {@link NetworkRequest} that is active.
         * <li> If not set, defaults to false (i.e. network is not OEM private).</li>
         *
         * @param isOemPrivate Boolean indicating whether the network should be brought up as OEM
         *                     private (if true) or not OEM private (if false).
         * @return Instance of {@link Builder} to enable chaining of the builder method.
         * @hide
         */
        @SystemApi
        public @NonNull Builder setOemPrivate(boolean isOemPrivate) {
            if (!SdkLevel.isAtLeastS()) {
                throw new UnsupportedOperationException();
            }
            mIsNetworkOemPrivate = isOemPrivate;
            return this;
        }

        private void setSecurityParamsInWifiConfiguration(
                @NonNull WifiConfiguration configuration) {
            if (!TextUtils.isEmpty(mWpa2PskPassphrase)) { // WPA-PSK network.
@@ -786,6 +846,7 @@ public final class WifiNetworkSuggestion implements Parcelable {
            wifiConfiguration.carrierId = mCarrierId;
            wifiConfiguration.trusted = !mIsNetworkUntrusted;
            wifiConfiguration.oemPaid = mIsNetworkOemPaid;
            wifiConfiguration.oemPrivate = mIsNetworkOemPrivate;
            wifiConfiguration.macRandomizationSetting = mIsEnhancedMacRandomizationEnabled
                    ? WifiConfiguration.RANDOMIZATION_ENHANCED
                    : WifiConfiguration.RANDOMIZATION_PERSISTENT;
@@ -819,6 +880,7 @@ public final class WifiNetworkSuggestion implements Parcelable {
            wifiConfiguration.meteredOverride = mMeteredOverride;
            wifiConfiguration.trusted = !mIsNetworkUntrusted;
            wifiConfiguration.oemPaid = mIsNetworkOemPaid;
            wifiConfiguration.oemPrivate = mIsNetworkOemPrivate;
            wifiConfiguration.subscriptionId = mSubscriptionId;
            mPasspointConfiguration.setCarrierId(mCarrierId);
            mPasspointConfiguration.setSubscriptionId(mSubscriptionId);
@@ -938,6 +1000,14 @@ public final class WifiNetworkSuggestion implements Parcelable {
                }
                mIsSharedWithUser = false;
            }
            if (mIsNetworkOemPrivate) {
                if (mIsSharedWithUserSet && mIsSharedWithUser) {
                    throw new IllegalStateException("Should not be both"
                            + "setCredentialSharedWithUser and +"
                            + "setOemPrivate to true");
                }
                mIsSharedWithUser = false;
            }
            return new WifiNetworkSuggestion(
                    wifiConfiguration,
                    mPasspointConfiguration,
@@ -1105,6 +1175,7 @@ public final class WifiNetworkSuggestion implements Parcelable {
                .append(", isInitialAutoJoinEnabled=").append(isInitialAutoJoinEnabled)
                .append(", isUnTrusted=").append(!wifiConfiguration.trusted)
                .append(", isOemPaid=").append(wifiConfiguration.oemPaid)
                .append(", isOemPrivate=").append(wifiConfiguration.oemPrivate)
                .append(", priorityGroup=").append(priorityGroup)
                .append(" ]");
        return sb.toString();
@@ -1211,6 +1282,18 @@ public final class WifiNetworkSuggestion implements Parcelable {
        return wifiConfiguration.oemPaid;
    }

    /**
     * @see Builder#setOemPrivate(boolean)
     * @hide
     */
    @SystemApi
    public boolean isOemPrivate() {
        if (!SdkLevel.isAtLeastS()) {
            throw new UnsupportedOperationException();
        }
        return wifiConfiguration.oemPrivate;
    }

    /**
     * Get the WifiEnterpriseConfig, or null if unset.
     * @see Builder#setWapiEnterpriseConfig(WifiEnterpriseConfig)
Loading