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

Commit 102e083d authored by Roshan Pius's avatar Roshan Pius
Browse files

WifiNetworkSuggestion: Add setOemPaid flag

Also, plumb the flag to WifiInfo.

Bug: 169413079
Test: atest android.net.wifi
Change-Id: Ic38dae4e2436937db0fb682bf204785cd181d159
parent 1a2667f8
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -7565,10 +7565,12 @@ package android.net.wifi {
  public final class WifiNetworkSuggestion implements android.os.Parcelable {
    method @NonNull public android.net.wifi.WifiConfiguration getWifiConfiguration();
    method public boolean isOemPaid();
  }
  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);
  }
  public class WifiScanner {
+2 −0
Original line number Diff line number Diff line
@@ -608,10 +608,12 @@ package android.net.wifi {

  public final class WifiNetworkSuggestion implements android.os.Parcelable {
    method @NonNull public android.net.wifi.WifiConfiguration getWifiConfiguration();
    method public boolean isOemPaid();
  }

  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);
  }

  public class WifiScanner {
+16 −1
Original line number Diff line number Diff line
@@ -991,6 +991,16 @@ public class WifiConfiguration implements Parcelable {
     */
    public boolean trusted;

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

    /**
     * True if this Wifi configuration is created from a {@link WifiNetworkSuggestion},
     * false otherwise.
@@ -2158,6 +2168,7 @@ public class WifiConfiguration implements Parcelable {
        ephemeral = false;
        osu = false;
        trusted = true; // Networks are considered trusted by default.
        oemPaid = false;
        fromWifiNetworkSuggestion = false;
        fromWifiNetworkSpecifier = false;
        meteredHint = false;
@@ -2278,11 +2289,12 @@ public class WifiConfiguration implements Parcelable {
        if (this.ephemeral) sbuf.append(" ephemeral");
        if (this.osu) sbuf.append(" osu");
        if (this.trusted) sbuf.append(" trusted");
        if (this.oemPaid) sbuf.append(" oemPaid");
        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
        if (this.validatedInternetAccess || this.ephemeral || this.trusted || this.oemPaid
                || this.fromWifiNetworkSuggestion || this.fromWifiNetworkSpecifier
                || this.meteredHint || this.useExternalScores) {
            sbuf.append("\n");
@@ -2828,6 +2840,7 @@ public class WifiConfiguration implements Parcelable {
            ephemeral = source.ephemeral;
            osu = source.osu;
            trusted = source.trusted;
            oemPaid = source.oemPaid;
            fromWifiNetworkSuggestion = source.fromWifiNetworkSuggestion;
            fromWifiNetworkSpecifier = source.fromWifiNetworkSpecifier;
            meteredHint = source.meteredHint;
@@ -2906,6 +2919,7 @@ public class WifiConfiguration implements Parcelable {
        dest.writeInt(isLegacyPasspointConfig ? 1 : 0);
        dest.writeInt(ephemeral ? 1 : 0);
        dest.writeInt(trusted ? 1 : 0);
        dest.writeInt(oemPaid ? 1 : 0);
        dest.writeInt(fromWifiNetworkSuggestion ? 1 : 0);
        dest.writeInt(fromWifiNetworkSpecifier ? 1 : 0);
        dest.writeInt(meteredHint ? 1 : 0);
@@ -2981,6 +2995,7 @@ public class WifiConfiguration implements Parcelable {
                config.isLegacyPasspointConfig = in.readInt() != 0;
                config.ephemeral = in.readInt() != 0;
                config.trusted = in.readInt() != 0;
                config.oemPaid = in.readInt() != 0;
                config.fromWifiNetworkSuggestion =  in.readInt() != 0;
                config.fromWifiNetworkSpecifier =  in.readInt() != 0;
                config.meteredHint = in.readInt() != 0;
+18 −0
Original line number Diff line number Diff line
@@ -158,6 +158,11 @@ public class WifiInfo implements Parcelable {
     */
    private boolean mTrusted;

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

    /**
     * OSU (Online Sign Up) AP for Passpoint R2.
     */
@@ -358,6 +363,7 @@ public class WifiInfo implements Parcelable {
            mMeteredHint = source.mMeteredHint;
            mEphemeral = source.mEphemeral;
            mTrusted = source.mTrusted;
            mTrusted = source.mOemPaid;
            mRequestingPackageName =
                    source.mRequestingPackageName;
            mOsuAp = source.mOsuAp;
@@ -721,6 +727,16 @@ public class WifiInfo implements Parcelable {
        return mTrusted;
    }

    /** {@hide} */
    public void setOemPaid(boolean oemPaid) {
        mOemPaid = oemPaid;
    }

    /** {@hide} */
    public boolean isOemPaid() {
        return mOemPaid;
    }

    /** {@hide} */
    public void setOsuAp(boolean osuAp) {
        mOsuAp = osuAp;
@@ -958,6 +974,7 @@ public class WifiInfo implements Parcelable {
        dest.writeInt(mMeteredHint ? 1 : 0);
        dest.writeInt(mEphemeral ? 1 : 0);
        dest.writeInt(mTrusted ? 1 : 0);
        dest.writeInt(mOemPaid ? 1 : 0);
        dest.writeInt(score);
        dest.writeLong(txSuccess);
        dest.writeDouble(mSuccessfulTxPacketsPerSecond);
@@ -1003,6 +1020,7 @@ public class WifiInfo implements Parcelable {
                info.mMeteredHint = in.readInt() != 0;
                info.mEphemeral = in.readInt() != 0;
                info.mTrusted = in.readInt() != 0;
                info.mOemPaid = in.readInt() != 0;
                info.score = in.readInt();
                info.txSuccess = in.readLong();
                info.mSuccessfulTxPacketsPerSecond = in.readDouble();
+68 −2
Original line number Diff line number Diff line
@@ -24,7 +24,9 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.net.MacAddress;
import android.net.NetworkCapabilities;
import android.net.wifi.hotspot2.PasspointConfiguration;
import android.net.wifi.util.SdkLevelUtil;
import android.os.Parcel;
import android.os.Parcelable;
import android.telephony.TelephonyManager;
@@ -149,6 +151,11 @@ public final class WifiNetworkSuggestion implements Parcelable {
         */
        private boolean mIsNetworkUntrusted;

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

        /**
         * Whether this network will use enhanced MAC randomization.
         */
@@ -175,6 +182,7 @@ public final class WifiNetworkSuggestion implements Parcelable {
            mWapiPskPassphrase = null;
            mWapiEnterpriseConfig = null;
            mIsNetworkUntrusted = false;
            mIsNetworkOemPaid = false;
            mPriorityGroup = 0;
            mIsEnhancedMacRandomizationEnabled = false;
        }
@@ -543,7 +551,7 @@ public final class WifiNetworkSuggestion implements Parcelable {

        /**
         * Specifies whether the system will bring up the network (if selected) as untrusted. An
         * untrusted network has its {@link android.net.NetworkCapabilities#NET_CAPABILITY_TRUSTED}
         * untrusted network has its {@link NetworkCapabilities#NET_CAPABILITY_TRUSTED}
         * capability removed. The 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). The connectivity service may use this information to influence the overall
@@ -562,6 +570,41 @@ public final class WifiNetworkSuggestion implements Parcelable {
            return this;
        }

        /**
         * Specifies whether the system will bring up the network (if selected) as OEM paid. An
         * OEM paid network has {@link NetworkCapabilities#NET_CAPABILITY_OEM_PAID} 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 support only 1 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 paid 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 paid 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 not OEM paid).</li>
         *
         * @param isOemPaid Boolean indicating whether the network should be brought up as OEM paid
         *                  (if true) or not OEM paid (if false).
         * @return Instance of {@link Builder} to enable chaining of the builder method.
         * @hide
         */
        @SystemApi
        public @NonNull Builder setOemPaid(boolean isOemPaid) {
            if (!SdkLevelUtil.isAtLeastS()) {
                throw new UnsupportedOperationException();
            }
            mIsNetworkOemPaid = isOemPaid;
            return this;
        }

        private void setSecurityParamsInWifiConfiguration(
                @NonNull WifiConfiguration configuration) {
            if (!TextUtils.isEmpty(mWpa2PskPassphrase)) { // WPA-PSK network.
@@ -628,6 +671,7 @@ public final class WifiNetworkSuggestion implements Parcelable {
            wifiConfiguration.meteredOverride = mMeteredOverride;
            wifiConfiguration.carrierId = mCarrierId;
            wifiConfiguration.trusted = !mIsNetworkUntrusted;
            wifiConfiguration.oemPaid = mIsNetworkOemPaid;
            wifiConfiguration.macRandomizationSetting = mIsEnhancedMacRandomizationEnabled
                    ? WifiConfiguration.RANDOMIZATION_ENHANCED
                    : WifiConfiguration.RANDOMIZATION_PERSISTENT;
@@ -659,6 +703,7 @@ public final class WifiNetworkSuggestion implements Parcelable {
            wifiConfiguration.priority = mPriority;
            wifiConfiguration.meteredOverride = mMeteredOverride;
            wifiConfiguration.trusted = !mIsNetworkUntrusted;
            wifiConfiguration.oemPaid = mIsNetworkOemPaid;
            mPasspointConfiguration.setCarrierId(mCarrierId);
            mPasspointConfiguration.setMeteredOverride(wifiConfiguration.meteredOverride);
            wifiConfiguration.macRandomizationSetting = mIsEnhancedMacRandomizationEnabled
@@ -764,7 +809,15 @@ public final class WifiNetworkSuggestion implements Parcelable {
                if (mIsSharedWithUserSet && mIsSharedWithUser) {
                    throw new IllegalStateException("Should not be both"
                            + "setCredentialSharedWithUser and +"
                            + "setIsNetworkAsUntrusted to true");
                            + "setUntrusted to true");
                }
                mIsSharedWithUser = false;
            }
            if (mIsNetworkOemPaid) {
                if (mIsSharedWithUserSet && mIsSharedWithUser) {
                    throw new IllegalStateException("Should not be both"
                            + "setCredentialSharedWithUser and +"
                            + "setOemPaid to true");
                }
                mIsSharedWithUser = false;
            }
@@ -931,6 +984,7 @@ public final class WifiNetworkSuggestion implements Parcelable {
                .append(", isCredentialSharedWithUser=").append(isUserAllowedToManuallyConnect)
                .append(", isInitialAutoJoinEnabled=").append(isInitialAutoJoinEnabled)
                .append(", isUnTrusted=").append(!wifiConfiguration.trusted)
                .append(", isOemPaid=").append(wifiConfiguration.oemPaid)
                .append(", priorityGroup=").append(priorityGroup)
                .append(" ]");
        return sb.toString();
@@ -1025,6 +1079,18 @@ public final class WifiNetworkSuggestion implements Parcelable {
        return !wifiConfiguration.trusted;
    }

    /**
     * @see Builder#setOemPaid(boolean)
     * @hide
     */
    @SystemApi
    public boolean isOemPaid() {
        if (!SdkLevelUtil.isAtLeastS()) {
            throw new UnsupportedOperationException();
        }
        return wifiConfiguration.oemPaid;
    }

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