summaryrefslogtreecommitdiff
path: root/wifi/java
diff options
context:
space:
mode:
Diffstat (limited to 'wifi/java')
-rw-r--r--wifi/java/android/net/wifi/IWifiManager.aidl2
-rw-r--r--wifi/java/android/net/wifi/ScanResult.java29
-rw-r--r--wifi/java/android/net/wifi/SoftApCapability.java28
-rw-r--r--wifi/java/android/net/wifi/SoftApConfiguration.java344
-rw-r--r--wifi/java/android/net/wifi/SoftApInfo.java6
-rw-r--r--wifi/java/android/net/wifi/WifiConfiguration.java163
-rw-r--r--wifi/java/android/net/wifi/WifiInfo.java42
-rw-r--r--wifi/java/android/net/wifi/WifiManager.java8
-rw-r--r--wifi/java/android/net/wifi/WifiNetworkSpecifier.java89
-rw-r--r--wifi/java/android/net/wifi/WifiNetworkSuggestion.java194
-rw-r--r--wifi/java/android/net/wifi/aware/AwareResources.java146
-rw-r--r--wifi/java/android/net/wifi/aware/Characteristics.java16
-rw-r--r--wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java10
-rw-r--r--wifi/java/android/net/wifi/aware/IWifiAwareManager.aidl4
-rw-r--r--wifi/java/android/net/wifi/aware/WifiAwareManager.java85
-rw-r--r--wifi/java/android/net/wifi/hotspot2/pps/HomeSp.java31
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pConfig.java3
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pDevice.java3
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java3
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pManager.java8
-rw-r--r--wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceInfo.java2
-rw-r--r--wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceRequest.java2
-rw-r--r--wifi/java/android/net/wifi/util/SdkLevelUtil.java68
23 files changed, 1033 insertions, 253 deletions
diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl
index a71ce2f87d97..695ddd9d304b 100644
--- a/wifi/java/android/net/wifi/IWifiManager.aidl
+++ b/wifi/java/android/net/wifi/IWifiManager.aidl
@@ -188,7 +188,7 @@ interface IWifiManager
void factoryReset(String packageName);
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
Network getCurrentNetwork();
byte[] retrieveBackupData();
diff --git a/wifi/java/android/net/wifi/ScanResult.java b/wifi/java/android/net/wifi/ScanResult.java
index bef472bc5441..78afb579674f 100644
--- a/wifi/java/android/net/wifi/ScanResult.java
+++ b/wifi/java/android/net/wifi/ScanResult.java
@@ -22,6 +22,7 @@ import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.net.wifi.WifiAnnotations.ChannelWidth;
import android.net.wifi.WifiAnnotations.WifiStandard;
+import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
@@ -386,7 +387,7 @@ public final class ScanResult implements Parcelable {
* @deprecated use is80211mcResponder() instead
* @hide
*/
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public boolean is80211McRTTResponder;
/**
@@ -777,47 +778,47 @@ public final class ScanResult implements Parcelable {
*/
public static class InformationElement {
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int EID_SSID = 0;
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int EID_SUPPORTED_RATES = 1;
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int EID_TIM = 5;
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int EID_BSS_LOAD = 11;
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int EID_ERP = 42;
/** @hide */
public static final int EID_HT_CAPABILITIES = 45;
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int EID_RSN = 48;
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int EID_EXTENDED_SUPPORTED_RATES = 50;
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int EID_HT_OPERATION = 61;
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int EID_INTERWORKING = 107;
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int EID_ROAMING_CONSORTIUM = 111;
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int EID_EXTENDED_CAPS = 127;
/** @hide */
public static final int EID_VHT_CAPABILITIES = 191;
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int EID_VHT_OPERATION = 192;
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int EID_VSA = 221;
/** @hide */
public static final int EID_EXTENSION_PRESENT = 255;
diff --git a/wifi/java/android/net/wifi/SoftApCapability.java b/wifi/java/android/net/wifi/SoftApCapability.java
index c527205a5d63..6e1c64235763 100644
--- a/wifi/java/android/net/wifi/SoftApCapability.java
+++ b/wifi/java/android/net/wifi/SoftApCapability.java
@@ -21,10 +21,11 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.net.wifi.SoftApConfiguration.BandType;
-import android.net.wifi.util.SdkLevelUtil;
import android.os.Parcel;
import android.os.Parcelable;
+import com.android.modules.utils.build.SdkLevel;
+
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
@@ -45,7 +46,7 @@ public final class SoftApCapability implements Parcelable {
* Support for automatic channel selection in driver (ACS).
* Driver will auto select best channel based on interference to optimize performance.
*
- * flag when {@link R.bool.config_wifi_softap_acs_supported)} is true.
+ * flag when {@link R.bool.config_wifi_softap_acs_supported} is true.
*
* <p>
* Use {@link WifiManager.SoftApCallback#onInfoChanged(SoftApInfo)} and
@@ -56,7 +57,7 @@ public final class SoftApCapability implements Parcelable {
/**
* Support for client force disconnect.
- * flag when {@link R.bool.config_wifi_sofap_client_force_disconnect_supported)} is true
+ * flag when {@link R.bool.config_wifiSofapClientForceDisconnectSupported} is true
*
* <p>
* Several Soft AP client control features, e.g. specifying the maximum number of
@@ -66,22 +67,32 @@ public final class SoftApCapability implements Parcelable {
*/
public static final long SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT = 1 << 1;
-
/**
* Support for WPA3 Simultaneous Authentication of Equals (WPA3-SAE).
*
- * flag when {@link config_wifi_softap_sae_supported)} is true.
+ * flag when {@link config_wifi_softap_sae_supported} is true.
*/
public static final long SOFTAP_FEATURE_WPA3_SAE = 1 << 2;
/**
+ * Support for MAC address customization.
+ * flag when {@link R.bool.config_wifiSoftapMacAddressCustomizationSupported} is true
+ *
+ * <p>
+ * Check feature support before invoking
+ * {@link SoftApConfiguration.Builder#setBssid(MadAddress)} or
+ * {@link SoftApConfiguration.Builder#setMacRandomizationSetting(int)} with
+ * {@link SoftApConfiguration.RANDOMIZATION_PERSISTENT}
+ */
+ public static final long SOFTAP_FEATURE_MAC_ADDRESS_CUSTOMIZATION = 1 << 3;
+
+ /**
* Support for WPA3 Opportunistic Wireless Encryption (WPA3-OWE).
*
* flag when {@link config_wifi_softap_owe_supported)} is true.
* @hide
*/
- public static final long SOFTAP_FEATURE_WPA3_OWE = 1 << 3;
-
+ public static final long SOFTAP_FEATURE_WPA3_OWE = 1 << 4;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@@ -89,6 +100,7 @@ public final class SoftApCapability implements Parcelable {
SOFTAP_FEATURE_ACS_OFFLOAD,
SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT,
SOFTAP_FEATURE_WPA3_SAE,
+ SOFTAP_FEATURE_MAC_ADDRESS_CUSTOMIZATION,
SOFTAP_FEATURE_WPA3_OWE,
})
public @interface HotspotFeatures {}
@@ -186,7 +198,7 @@ public final class SoftApCapability implements Parcelable {
*/
@NonNull
public int[] getSupportedChannelList(@BandType int band) {
- if (!SdkLevelUtil.isAtLeastS()) {
+ if (!SdkLevel.isAtLeastS()) {
throw new UnsupportedOperationException();
}
switch (band) {
diff --git a/wifi/java/android/net/wifi/SoftApConfiguration.java b/wifi/java/android/net/wifi/SoftApConfiguration.java
index 0d7d93509faf..4fd8decbfaa9 100644
--- a/wifi/java/android/net/wifi/SoftApConfiguration.java
+++ b/wifi/java/android/net/wifi/SoftApConfiguration.java
@@ -22,14 +22,15 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.net.MacAddress;
-import android.net.wifi.util.SdkLevelUtil;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;
+import android.util.SparseIntArray;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.Preconditions;
+import com.android.modules.utils.build.SdkLevel;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -96,6 +97,9 @@ public final class SoftApConfiguration implements Parcelable {
* Device is allowed to choose the optimal band (2Ghz, 5Ghz, 6Ghz) based on device capability,
* operating country code and current radio conditions.
* @hide
+ *
+ * @deprecated The bands are a bit mask - use any combination of {@code BAND_},
+ * for instance {@code BAND_2GHZ | BAND_5GHZ | BAND_6GHZ}.
*/
@SystemApi
public static final int BAND_ANY = BAND_2GHZ | BAND_5GHZ | BAND_6GHZ;
@@ -177,16 +181,12 @@ public final class SoftApConfiguration implements Parcelable {
private final boolean mHiddenSsid;
/**
- * The operating band of the AP.
- * One or combination of the following band type:
- * {@link #BAND_2GHZ}, {@link #BAND_5GHZ}, {@link #BAND_6GHZ}.
- */
- private final @BandType int mBand;
-
- /**
- * The operating channel of the AP.
+ * The operating channels of the dual APs.
+ *
+ * The SparseIntArray that consists the band and the channel of matching the band.
*/
- private final int mChannel;
+ @NonNull
+ private final SparseIntArray mChannels;
/**
* The maximim allowed number of clients that can associate to the AP.
@@ -299,7 +299,7 @@ public final class SoftApConfiguration implements Parcelable {
/** Private constructor for Builder and Parcelable implementation. */
private SoftApConfiguration(@Nullable String ssid, @Nullable MacAddress bssid,
- @Nullable String passphrase, boolean hiddenSsid, @BandType int band, int channel,
+ @Nullable String passphrase, boolean hiddenSsid, @NonNull SparseIntArray channels,
@SecurityType int securityType, int maxNumberOfClients, boolean shutdownTimeoutEnabled,
long shutdownTimeoutMillis, boolean clientControlByUser,
@NonNull List<MacAddress> blockedList, @NonNull List<MacAddress> allowedList,
@@ -308,8 +308,12 @@ public final class SoftApConfiguration implements Parcelable {
mBssid = bssid;
mPassphrase = passphrase;
mHiddenSsid = hiddenSsid;
- mBand = band;
- mChannel = channel;
+ if (channels.size() != 0) {
+ mChannels = channels.clone();
+ } else {
+ mChannels = new SparseIntArray(1);
+ mChannels.put(BAND_2GHZ, 0);
+ }
mSecurityType = securityType;
mMaxNumberOfClients = maxNumberOfClients;
mAutoShutdownEnabled = shutdownTimeoutEnabled;
@@ -334,8 +338,7 @@ public final class SoftApConfiguration implements Parcelable {
&& Objects.equals(mBssid, other.mBssid)
&& Objects.equals(mPassphrase, other.mPassphrase)
&& mHiddenSsid == other.mHiddenSsid
- && mBand == other.mBand
- && mChannel == other.mChannel
+ && mChannels.toString().equals(other.mChannels.toString())
&& mSecurityType == other.mSecurityType
&& mMaxNumberOfClients == other.mMaxNumberOfClients
&& mAutoShutdownEnabled == other.mAutoShutdownEnabled
@@ -350,7 +353,7 @@ public final class SoftApConfiguration implements Parcelable {
@Override
public int hashCode() {
return Objects.hash(mSsid, mBssid, mPassphrase, mHiddenSsid,
- mBand, mChannel, mSecurityType, mMaxNumberOfClients, mAutoShutdownEnabled,
+ mChannels.toString(), mSecurityType, mMaxNumberOfClients, mAutoShutdownEnabled,
mShutdownTimeoutMillis, mClientControlByUser, mBlockedClientList,
mAllowedClientList, mMacRandomizationSetting, mOweTransIfaceName);
}
@@ -358,13 +361,12 @@ public final class SoftApConfiguration implements Parcelable {
@Override
public String toString() {
StringBuilder sbuf = new StringBuilder();
- sbuf.append("ssid=").append(mSsid);
- if (mBssid != null) sbuf.append(" \n bssid=").append(mBssid.toString());
- sbuf.append(" \n Passphrase =").append(
+ sbuf.append("ssid = ").append(mSsid);
+ if (mBssid != null) sbuf.append(" \n bssid = ").append(mBssid.toString());
+ sbuf.append(" \n Passphrase = ").append(
TextUtils.isEmpty(mPassphrase) ? "<empty>" : "<non-empty>");
sbuf.append(" \n HiddenSsid =").append(mHiddenSsid);
- sbuf.append(" \n Band =").append(mBand);
- sbuf.append(" \n Channel =").append(mChannel);
+ sbuf.append(" \n Channels =").append(mChannels);
sbuf.append(" \n SecurityType=").append(getSecurityType());
sbuf.append(" \n MaxClient=").append(mMaxNumberOfClients);
sbuf.append(" \n AutoShutdownEnabled=").append(mAutoShutdownEnabled);
@@ -383,8 +385,7 @@ public final class SoftApConfiguration implements Parcelable {
dest.writeParcelable(mBssid, flags);
dest.writeString(mPassphrase);
dest.writeBoolean(mHiddenSsid);
- dest.writeInt(mBand);
- dest.writeInt(mChannel);
+ writeSparseIntArray(dest, mChannels);
dest.writeInt(mSecurityType);
dest.writeInt(mMaxNumberOfClients);
dest.writeBoolean(mAutoShutdownEnabled);
@@ -396,6 +397,42 @@ public final class SoftApConfiguration implements Parcelable {
dest.writeString(mOweTransIfaceName);
}
+ /* Reference from frameworks/base/core/java/android/os/Parcel.java */
+ private static void writeSparseIntArray(@NonNull Parcel dest,
+ @Nullable SparseIntArray val) {
+ if (val == null) {
+ dest.writeInt(-1);
+ return;
+ }
+ int n = val.size();
+ dest.writeInt(n);
+ int i = 0;
+ while (i < n) {
+ dest.writeInt(val.keyAt(i));
+ dest.writeInt(val.valueAt(i));
+ i++;
+ }
+ }
+
+
+ /* Reference from frameworks/base/core/java/android/os/Parcel.java */
+ @NonNull
+ private static SparseIntArray readSparseIntArray(@NonNull Parcel in) {
+ int n = in.readInt();
+ if (n < 0) {
+ return new SparseIntArray();
+ }
+ SparseIntArray sa = new SparseIntArray(n);
+ while (n > 0) {
+ int key = in.readInt();
+ int value = in.readInt();
+ sa.append(key, value);
+ n--;
+ }
+ return sa;
+ }
+
+
@Override
public int describeContents() {
return 0;
@@ -408,7 +445,7 @@ public final class SoftApConfiguration implements Parcelable {
return new SoftApConfiguration(
in.readString(),
in.readParcelable(MacAddress.class.getClassLoader()),
- in.readString(), in.readBoolean(), in.readInt(), in.readInt(), in.readInt(),
+ in.readString(), in.readBoolean(), readSparseIntArray(in), in.readInt(),
in.readInt(), in.readBoolean(), in.readLong(), in.readBoolean(),
in.createTypedArrayList(MacAddress.CREATOR),
in.createTypedArrayList(MacAddress.CREATOR), in.readInt(), in.readString());
@@ -422,7 +459,7 @@ public final class SoftApConfiguration implements Parcelable {
/**
* Return String set to be the SSID for the AP.
- * {@link Builder#setSsid(String)}.
+ * See also {@link Builder#setSsid(String)}.
*/
@Nullable
public String getSsid() {
@@ -431,7 +468,7 @@ public final class SoftApConfiguration implements Parcelable {
/**
* Returns MAC address set to be BSSID for the AP.
- * {@link Builder#setBssid(MacAddress)}.
+ * See also {@link Builder#setBssid(MacAddress)}.
*/
@Nullable
public MacAddress getBssid() {
@@ -440,7 +477,7 @@ public final class SoftApConfiguration implements Parcelable {
/**
* Returns String set to be passphrase for current AP.
- * {@link Builder#setPassphrase(String, int)}.
+ * See also {@link Builder#setPassphrase(String, int)}.
*/
@Nullable
public String getPassphrase() {
@@ -450,7 +487,7 @@ public final class SoftApConfiguration implements Parcelable {
/**
* Returns Boolean set to be indicate hidden (true: doesn't broadcast its SSID) or
* not (false: broadcasts its SSID) for the AP.
- * {@link Builder#setHiddenSsid(boolean)}.
+ * See also {@link Builder#setHiddenSsid(boolean)}.
*/
public boolean isHiddenSsid() {
return mHiddenSsid;
@@ -459,27 +496,75 @@ public final class SoftApConfiguration implements Parcelable {
/**
* Returns band type set to be the band for the AP.
*
- * One or combination of the following band type:
- * {@link #BAND_2GHZ}, {@link #BAND_5GHZ}, {@link #BAND_6GHZ}.
+ * One or combination of {@code BAND_}, for instance
+ * {@link #BAND_2GHZ}, {@link #BAND_5GHZ}, or {@code BAND_2GHZ | BAND_5GHZ}.
+ *
+ * Note: Returns the lowest band when more than one band is set.
+ * Use {@link #getBands()} to get dual bands setting.
*
- * {@link Builder#setBand(int)}.
+ * See also {@link Builder#setBand(int)}.
*
* @hide
*/
@SystemApi
public @BandType int getBand() {
- return mBand;
+ return mChannels.keyAt(0);
+ }
+
+ /**
+ * Returns a sorted array in ascending order that consists of the configured band types
+ * for the APs.
+ *
+ * The band type is one or combination of {@code BAND_}, for instance
+ * {@link #BAND_2GHZ}, {@link #BAND_5GHZ}, or {@code BAND_2GHZ | BAND_5GHZ}.
+ *
+ * Note: return array may only include one band when current setting is single AP mode.
+ * See also {@link Builder#setBands(int[])}.
+ *
+ * @hide
+ */
+ @SystemApi
+ public @NonNull int[] getBands() {
+ if (!SdkLevel.isAtLeastS()) {
+ throw new UnsupportedOperationException();
+ }
+ int[] bands = new int[mChannels.size()];
+ for (int i = 0; i < bands.length; i++) {
+ bands[i] = mChannels.keyAt(i);
+ }
+ return bands;
}
/**
* Returns Integer set to be the channel for the AP.
- * {@link Builder#setChannel(int)}.
+ *
+ * Note: Returns the channel which associated to the lowest band if more than one channel
+ * is set. Use {@link Builder#getChannels()} to get dual channel setting.
+ * See also {@link Builder#setChannel(int, int)}.
*
* @hide
*/
@SystemApi
public int getChannel() {
- return mChannel;
+ return mChannels.valueAt(0);
+ }
+
+
+ /**
+ * Returns SparseIntArray (key: {@code BandType} , value: channel) that consists of
+ * the configured bands and channels for the AP(s).
+ *
+ * Note: return array may only include one channel when current setting is single AP mode.
+ * See also {@link Builder#setChannels(SparseIntArray)}.
+ *
+ * @hide
+ */
+ @SystemApi
+ public @NonNull SparseIntArray getChannels() {
+ if (!SdkLevel.isAtLeastS()) {
+ throw new UnsupportedOperationException();
+ }
+ return mChannels;
}
/**
@@ -498,7 +583,7 @@ public final class SoftApConfiguration implements Parcelable {
/**
* Returns the maximum number of clients that can associate to the AP.
- * {@link Builder#setMaxNumberOfClients(int)}.
+ * See also {@link Builder#setMaxNumberOfClients(int)}.
*
* @hide
*/
@@ -510,7 +595,7 @@ public final class SoftApConfiguration implements Parcelable {
/**
* Returns whether auto shutdown is enabled or not.
* The Soft AP will shutdown when there are no devices associated to it for
- * the timeout duration. See {@link Builder#setAutoShutdownEnabled(boolean)}.
+ * the timeout duration. See also {@link Builder#setAutoShutdownEnabled(boolean)}.
*
* @hide
*/
@@ -522,7 +607,7 @@ public final class SoftApConfiguration implements Parcelable {
/**
* Returns the shutdown timeout in milliseconds.
* The Soft AP will shutdown when there are no devices associated to it for
- * the timeout duration. See {@link Builder#setShutdownTimeoutMillis(long)}.
+ * the timeout duration. See also {@link Builder#setShutdownTimeoutMillis(long)}.
*
* @hide
*/
@@ -534,7 +619,7 @@ public final class SoftApConfiguration implements Parcelable {
/**
* Returns a flag indicating whether clients need to be pre-approved by the user.
* (true: authorization required) or not (false: not required).
- * {@link Builder#setClientControlByUserEnabled(Boolean)}.
+ * See also {@link Builder#setClientControlByUserEnabled(Boolean)}.
*
* @hide
*/
@@ -570,14 +655,14 @@ public final class SoftApConfiguration implements Parcelable {
/**
* Returns the level of MAC randomization for the AP BSSID.
- * {@link Builder#setMacRandomizationSetting(int)}.
+ * See also {@link Builder#setMacRandomizationSetting(int)}.
*
* @hide
*/
@SystemApi
@MacRandomizationSetting
public int getMacRandomizationSetting() {
- if (!SdkLevelUtil.isAtLeastS()) {
+ if (!SdkLevel.isAtLeastS()) {
throw new UnsupportedOperationException();
}
return mMacRandomizationSetting;
@@ -602,7 +687,7 @@ public final class SoftApConfiguration implements Parcelable {
wifiConfig.SSID = mSsid;
wifiConfig.preSharedKey = mPassphrase;
wifiConfig.hiddenSSID = mHiddenSsid;
- wifiConfig.apChannel = mChannel;
+ wifiConfig.apChannel = getChannel();
switch (mSecurityType) {
case SECURITY_TYPE_OPEN:
wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
@@ -619,7 +704,7 @@ public final class SoftApConfiguration implements Parcelable {
return null;
}
- switch (mBand) {
+ switch (getBand()) {
case BAND_2GHZ:
wifiConfig.apBand = WifiConfiguration.AP_BAND_2GHZ;
break;
@@ -639,7 +724,7 @@ public final class SoftApConfiguration implements Parcelable {
wifiConfig.apBand = WifiConfiguration.AP_BAND_DUAL;
break;
default:
- Log.e(TAG, "Convert fail, unsupported band setting :" + mBand);
+ Log.e(TAG, "Convert fail, unsupported band setting :" + getBand());
return null;
}
return wifiConfig;
@@ -671,8 +756,7 @@ public final class SoftApConfiguration implements Parcelable {
private MacAddress mBssid;
private String mPassphrase;
private boolean mHiddenSsid;
- private int mBand;
- private int mChannel;
+ private SparseIntArray mChannels;
private int mMaxNumberOfClients;
private int mSecurityType;
private boolean mAutoShutdownEnabled;
@@ -691,8 +775,8 @@ public final class SoftApConfiguration implements Parcelable {
mBssid = null;
mPassphrase = null;
mHiddenSsid = false;
- mBand = BAND_2GHZ;
- mChannel = 0;
+ mChannels = new SparseIntArray(1);
+ mChannels.put(BAND_2GHZ, 0);
mMaxNumberOfClients = 0;
mSecurityType = SECURITY_TYPE_OPEN;
mAutoShutdownEnabled = true; // enabled by default.
@@ -714,8 +798,7 @@ public final class SoftApConfiguration implements Parcelable {
mBssid = other.mBssid;
mPassphrase = other.mPassphrase;
mHiddenSsid = other.mHiddenSsid;
- mBand = other.mBand;
- mChannel = other.mChannel;
+ mChannels = other.mChannels.clone();
mMaxNumberOfClients = other.mMaxNumberOfClients;
mSecurityType = other.mSecurityType;
mAutoShutdownEnabled = other.mAutoShutdownEnabled;
@@ -740,7 +823,7 @@ public final class SoftApConfiguration implements Parcelable {
}
}
return new SoftApConfiguration(mSsid, mBssid, mPassphrase,
- mHiddenSsid, mBand, mChannel, mSecurityType, mMaxNumberOfClients,
+ mHiddenSsid, mChannels, mSecurityType, mMaxNumberOfClients,
mAutoShutdownEnabled, mShutdownTimeoutMillis, mClientControlByUser,
mBlockedClientList, mAllowedClientList, mMacRandomizationSetting,
mOweTransIfaceName);
@@ -772,6 +855,27 @@ public final class SoftApConfiguration implements Parcelable {
* Specifies a BSSID for the AP.
* <p>
* <li>If not set, defaults to null.</li>
+ *
+ * If multiple bands are requested via {@link #setBands(int[])} or
+ * {@link #setChannels(SparseIntArray)}, HAL will derive 2 MAC addresses since framework
+ * only sends down 1 MAC address.
+ *
+ * An example (but different implementation may perform a different mapping):
+ * <li>MAC address 1: copy value of MAC address,
+ * and set byte 1 = (0xFF - BSSID[1])</li>
+ * <li>MAC address 2: copy value of MAC address,
+ * and set byte 2 = (0xFF - BSSID[2])</li>
+ *
+ * Example BSSID argument: e2:38:60:c4:0e:b7
+ * Derived MAC address 1: e2:c7:60:c4:0e:b7
+ * Derived MAC address 2: e2:38:9f:c4:0e:b7
+ *
+ * <p>
+ * Use {@link WifiManager.SoftApCallback#onCapabilityChanged(SoftApCapability)} and
+ * {@link SoftApCapability#areFeaturesSupported(long)}
+ * with {@link SoftApCapability.SOFTAP_FEATURE_MAC_ADDRESS_CUSTOMIZATION} to determine
+ * whether or not this feature is supported.
+ *
* @param bssid BSSID, or null to have the BSSID chosen by the framework. The caller is
* responsible for avoiding collisions.
* @return Builder for chaining.
@@ -858,18 +962,47 @@ public final class SoftApConfiguration implements Parcelable {
* @param band One or combination of the following band type:
* {@link #BAND_2GHZ}, {@link #BAND_5GHZ}, {@link #BAND_6GHZ}.
* @return Builder for chaining.
+ * @throws IllegalArgumentException when an invalid band type is provided.
*/
@NonNull
public Builder setBand(@BandType int band) {
if (!isBandValid(band)) {
- throw new IllegalArgumentException("Invalid band type");
+ throw new IllegalArgumentException("Invalid band type: " + band);
+ }
+ mChannels = new SparseIntArray(1);
+ mChannels.put(band, 0);
+ return this;
+ }
+
+ /**
+ * Specifies the bands for the APs.
+ * If more than 1 band is set, this will bring up concurrent APs.
+ * on the requested bands (if possible).
+ * <p>
+ *
+ * @param bands Array of the {@link #BandType}.
+ * @return Builder for chaining.
+ * @throws IllegalArgumentException when more than 2 bands are set or an invalid band type
+ * is provided.
+ */
+ @NonNull
+ public Builder setBands(@NonNull int[] bands) {
+ if (bands.length == 0 || bands.length > 2) {
+ throw new IllegalArgumentException("Unsupported number of bands("
+ + bands.length + ") configured");
}
- mBand = band;
- // Since band preference is specified, no specific channel is selected.
- mChannel = 0;
+ SparseIntArray channels = new SparseIntArray(bands.length);
+ for (int val : bands) {
+ if (!isBandValid(val)) {
+ throw new IllegalArgumentException("Invalid band type: " + val);
+ }
+ channels.put(val, 0);
+ }
+ mChannels = channels;
return this;
}
+
/**
* Specifies the channel and associated band for the AP.
*
@@ -878,36 +1011,86 @@ public final class SoftApConfiguration implements Parcelable {
* valid channels.
*
* <p>
- * The default for the channel is a the special value 0 to have the framework
- * auto-select a valid channel from the band configured with
+ * If not set, the default for the channel is the special value 0 which has the
+ * framework auto-select a valid channel from the band configured with
* {@link #setBand(int)}.
*
- * The channel auto selection will offload to driver when
- * {@link SoftApCapability#areFeaturesSupported(
- * SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD)}
- * return true. Driver will auto select best channel which based on environment
- * interference to get best performance. Check {@link SoftApCapability} to get more detail.
+ * The channel auto selection will be offloaded to driver when
+ * {@link SoftApCapability#areFeaturesSupported(long)}
+ * with {@link SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD}
+ * return true. The driver will auto select the best channel (e.g. best performance)
+ * based on environment interference. Check {@link SoftApCapability} for more detail.
*
- * Note, since 6GHz band use the same channel numbering of 2.4GHz and 5GHZ bands,
- * the caller needs to pass the band containing the selected channel.
+ * The API contains (band, channel) input since the 6GHz band uses the same channel
+ * numbering scheme as is used in the 2.4GHz and 5GHz band. Therefore, both are needed to
+ * uniquely identify individual channels.
*
* <p>
- * <li>If not set, defaults to 0.</li>
* @param channel operating channel of the AP.
* @param band containing this channel.
* @return Builder for chaining.
+ * @throws IllegalArgumentException when the invalid channel or band type is configured.
*/
@NonNull
public Builder setChannel(int channel, @BandType int band) {
if (!isChannelBandPairValid(channel, band)) {
- throw new IllegalArgumentException("Invalid band type");
+ throw new IllegalArgumentException("Invalid channel(" + channel
+ + ") & band (" + band + ") configured");
}
- mBand = band;
- mChannel = channel;
+ mChannels = new SparseIntArray(1);
+ mChannels.put(band, channel);
return this;
}
/**
+ * Specifies the channels and associated bands for the APs.
+ *
+ * When more than 1 channel is set, this will bring up concurrent APs on the requested
+ * channels and bands (if possible).
+ *
+ * Valid channels are country dependent.
+ * The {@link SoftApCapability#getSupportedChannelList(int)} can be used to obtain
+ * valid channels in each band.
+ *
+ * <p>
+ * If not set, the default for the channel is the special value 0 which has the framework
+ * auto-select a valid channel from the band configured with {@link #setBands(int[])}.
+ *
+ * The channel auto selection will be offloaded to driver when
+ * {@link SoftApCapability#areFeaturesSupported(long)}
+ * with {@link SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD}
+ * returns true. The driver will auto select the best channel (e.g. best performance)
+ * based on environment interference. Check {@link SoftApCapability} for more detail.
+ *
+ * The API contains (band, channel) input since the 6GHz band uses the same channel
+ * numbering scheme as is used in the 2.4GHz and 5GHz band. Therefore, both are needed to
+ * uniquely identify individual channels.
+ *
+ * <p>
+ * @param channels SparseIntArray (key: {@code #BandType} , value: channel) consists of
+ * {@code BAND_} and corresponding channel.
+ * @return Builder for chaining.
+ * @throws IllegalArgumentException when more than 2 channels are set or the invalid
+ * channel or band type is configured.
+ */
+ @NonNull
+ public Builder setChannels(@NonNull SparseIntArray channels) {
+ if (channels.size() == 0 || channels.size() > 2) {
+ throw new IllegalArgumentException("Unsupported number of channels("
+ + channels.size() + ") configured");
+ }
+ for (int i = 0; i < channels.size(); i++) {
+ if (!isChannelBandPairValid(channels.valueAt(i), channels.keyAt(i))) {
+ throw new IllegalArgumentException("Invalid channel(" + channels.valueAt(i)
+ + ") & band (" + channels.keyAt(i) + ") configured");
+ }
+ }
+ mChannels = channels.clone();
+ return this;
+ }
+
+
+ /**
* Specifies the maximum number of clients that can associate to the AP.
*
* The maximum number of clients (STAs) which can associate to the AP.
@@ -922,14 +1105,14 @@ public final class SoftApConfiguration implements Parcelable {
* <p>
* <li>If not set, defaults to 0.</li>
*
- * This method requires hardware support. If the method is used to set a
+ * This method requires HAL support. If the method is used to set a
* non-zero {@code maxNumberOfClients} value then
* {@link WifiManager#startTetheredHotspot} will report error code
* {@link WifiManager#SAP_START_FAILURE_UNSUPPORTED_CONFIGURATION}.
*
* <p>
* Use {@link WifiManager.SoftApCallback#onCapabilityChanged(SoftApCapability)} and
- * {@link SoftApCapability#areFeaturesSupported(int)}
+ * {@link SoftApCapability#areFeaturesSupported(long)}
* with {@link SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT} to determine whether
* or not this feature is supported.
*
@@ -1003,13 +1186,13 @@ public final class SoftApConfiguration implements Parcelable {
* {@link #setBlockedClientList(List)} and {@link #setAllowedClientList(List)}.
*
* <p>
- * This method requires hardware support. Hardware support can be determined using
+ * This method requires HAL support. HAL support can be determined using
* {@link WifiManager.SoftApCallback#onCapabilityChanged(SoftApCapability)} and
- * {@link SoftApCapability#areFeaturesSupported(int)}
+ * {@link SoftApCapability#areFeaturesSupported(long)}
* with {@link SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT}
*
* <p>
- * If the method is called on a device without hardware support then starting the soft AP
+ * If the method is called on a device without HAL support then starting the soft AP
* using {@link WifiManager#startTetheredHotspot(SoftApConfiguration)} will fail with
* {@link WifiManager#SAP_START_FAILURE_UNSUPPORTED_CONFIGURATION}.
*
@@ -1058,13 +1241,13 @@ public final class SoftApConfiguration implements Parcelable {
* to the Soft AP.
*
* <p>
- * This method requires hardware support. Hardware support can be determined using
+ * This method requires HAL support. HAL support can be determined using
* {@link WifiManager.SoftApCallback#onCapabilityChanged(SoftApCapability)} and
- * {@link SoftApCapability#areFeaturesSupported(int)}
+ * {@link SoftApCapability#areFeaturesSupported(long)}
* with {@link SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT}
*
* <p>
- * If the method is called on a device without hardware support then starting the soft AP
+ * If the method is called on a device without HAL support then starting the soft AP
* using {@link WifiManager#startTetheredHotspot(SoftApConfiguration)} will fail with
* {@link WifiManager#SAP_START_FAILURE_UNSUPPORTED_CONFIGURATION}.
*
@@ -1086,7 +1269,14 @@ public final class SoftApConfiguration implements Parcelable {
* <p>
* <li>If not set, defaults to {@link #RANDOMIZATION_PERSISTENT}</li>
*
- * @param macRandomizationSetting One of the following setting:.
+ * <p>
+ * Requires HAL support when set to {@link #RANDOMIZATION_PERSISTENT}.
+ * Use {@link WifiManager.SoftApCallback#onCapabilityChanged(SoftApCapability)} and
+ * {@link SoftApCapability#areFeaturesSupported(long)}
+ * with {@link SoftApCapability.SOFTAP_FEATURE_MAC_ADDRESS_CUSTOMIZATION} to determine
+ * whether or not this feature is supported.
+ *
+ * @param macRandomizationSetting One of the following setting:
* {@link #RANDOMIZATION_NONE} or {@link #RANDOMIZATION_PERSISTENT}.
* @return Builder for chaining.
*
@@ -1095,7 +1285,7 @@ public final class SoftApConfiguration implements Parcelable {
@NonNull
public Builder setMacRandomizationSetting(
@MacRandomizationSetting int macRandomizationSetting) {
- if (!SdkLevelUtil.isAtLeastS()) {
+ if (!SdkLevel.isAtLeastS()) {
throw new UnsupportedOperationException();
}
mMacRandomizationSetting = macRandomizationSetting;
diff --git a/wifi/java/android/net/wifi/SoftApInfo.java b/wifi/java/android/net/wifi/SoftApInfo.java
index cf61f81e6d22..9a16facfec26 100644
--- a/wifi/java/android/net/wifi/SoftApInfo.java
+++ b/wifi/java/android/net/wifi/SoftApInfo.java
@@ -20,11 +20,11 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.net.MacAddress;
-import android.net.wifi.util.SdkLevelUtil;
import android.os.Parcel;
import android.os.Parcelable;
import com.android.internal.util.Preconditions;
+import com.android.modules.utils.build.SdkLevel;
import java.util.Objects;
@@ -141,7 +141,7 @@ public final class SoftApInfo implements Parcelable {
*/
@Nullable
public MacAddress getBssid() {
- if (!SdkLevelUtil.isAtLeastS()) {
+ if (!SdkLevel.isAtLeastS()) {
throw new UnsupportedOperationException();
}
return mBssid;
@@ -180,7 +180,7 @@ public final class SoftApInfo implements Parcelable {
* @return valid values from {@link ScanResult}'s {@code WIFI_STANDARD_}
*/
public @WifiAnnotations.WifiStandard int getWifiStandard() {
- if (!SdkLevelUtil.isAtLeastS()) {
+ if (!SdkLevel.isAtLeastS()) {
throw new UnsupportedOperationException();
}
return mWifiStandard;
diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java
index 47dd99aa9791..2b54dc6af544 100644
--- a/wifi/java/android/net/wifi/WifiConfiguration.java
+++ b/wifi/java/android/net/wifi/WifiConfiguration.java
@@ -456,6 +456,8 @@ public class WifiConfiguration implements Parcelable {
public static final int SECURITY_TYPE_WAPI_PSK = 7;
/** Security type for a WAPI Certificate network. */
public static final int SECURITY_TYPE_WAPI_CERT = 8;
+ /** Security type for a WPA3-Enterprise network. */
+ public static final int SECURITY_TYPE_EAP_WPA3_ENTERPRISE = 9;
/**
* Security types we support.
@@ -471,7 +473,8 @@ public class WifiConfiguration implements Parcelable {
SECURITY_TYPE_EAP_SUITE_B,
SECURITY_TYPE_OWE,
SECURITY_TYPE_WAPI_PSK,
- SECURITY_TYPE_WAPI_CERT
+ SECURITY_TYPE_WAPI_CERT,
+ SECURITY_TYPE_EAP_WPA3_ENTERPRISE,
})
public @interface SecurityType {}
@@ -487,8 +490,9 @@ public class WifiConfiguration implements Parcelable {
* {@link #SECURITY_TYPE_SAE},
* {@link #SECURITY_TYPE_EAP_SUITE_B},
* {@link #SECURITY_TYPE_OWE},
- * {@link #SECURITY_TYPE_WAPI_PSK}, or
- * {@link #SECURITY_TYPE_WAPI_CERT}
+ * {@link #SECURITY_TYPE_WAPI_PSK},
+ * {@link #SECURITY_TYPE_WAPI_CERT},
+ * {@link #SECURITY_TYPE_EAP_WPA3_ENTERPRISE}
*/
public void setSecurityParams(@SecurityType int securityType) {
// Clear all the bitsets.
@@ -564,6 +568,16 @@ public class WifiConfiguration implements Parcelable {
allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.SMS4);
allowedGroupCiphers.set(WifiConfiguration.GroupCipher.SMS4);
break;
+ case SECURITY_TYPE_EAP_WPA3_ENTERPRISE:
+ allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
+ allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
+ allowedProtocols.set(WifiConfiguration.Protocol.RSN);
+ allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
+ allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.GCMP_256);
+ allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
+ allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GCMP_256);
+ requirePmf = true;
+ break;
default:
throw new IllegalArgumentException("unknown security type " + securityType);
}
@@ -927,7 +941,7 @@ public class WifiConfiguration implements Parcelable {
* @hide
* Number of reports indicating no Internet Access
*/
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public int numNoInternetAccessReports;
/**
@@ -947,7 +961,7 @@ public class WifiConfiguration implements Parcelable {
* this configuration and selects "don't ask again".
* @hide
*/
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public boolean noInternetAccessExpected;
/**
@@ -987,7 +1001,7 @@ public class WifiConfiguration implements Parcelable {
* @deprecated only kept for @UnsupportedAppUsage
* @hide
*/
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public boolean selfAdded;
/**
@@ -1032,6 +1046,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.
@@ -1393,36 +1418,26 @@ public class WifiConfiguration implements Parcelable {
* @hide
*/
public static final int NETWORK_SELECTION_DISABLED_STARTING_INDEX = 1;
- /**
- * The starting index for network selection temporarily disabled reasons.
- * @hide
- */
- public static final int TEMPORARILY_DISABLED_STARTING_INDEX = 1;
- /** This network is disabled because of multiple association rejections. */
+ /** This network is temporarily disabled because of multiple association rejections. */
public static final int DISABLED_ASSOCIATION_REJECTION = 1;
- /** This network is disabled because of multiple authentication failure. */
+ /** This network is temporarily disabled because of multiple authentication failure. */
public static final int DISABLED_AUTHENTICATION_FAILURE = 2;
- /** This network is disabled because of multiple DHCP failure. */
+ /** This network is temporarily disabled because of multiple DHCP failure. */
public static final int DISABLED_DHCP_FAILURE = 3;
/** This network is temporarily disabled because it has no Internet access. */
public static final int DISABLED_NO_INTERNET_TEMPORARY = 4;
- /**
- * The starting index for network selection permanently disabled reasons.
- * @hide
- */
- public static final int PERMANENTLY_DISABLED_STARTING_INDEX = 5;
- /** This network is disabled due to absence of user credentials */
+ /** This network is permanently disabled due to absence of user credentials */
public static final int DISABLED_AUTHENTICATION_NO_CREDENTIALS = 5;
/**
* This network is permanently disabled because it has no Internet access and the user does
* not want to stay connected.
*/
public static final int DISABLED_NO_INTERNET_PERMANENT = 6;
- /** This network is disabled due to WifiManager disabling it explicitly. */
+ /** This network is permanently disabled due to WifiManager disabling it explicitly. */
public static final int DISABLED_BY_WIFI_MANAGER = 7;
- /** This network is disabled due to wrong password. */
+ /** This network is permanently disabled due to wrong password. */
public static final int DISABLED_BY_WRONG_PASSWORD = 8;
- /** This network is disabled because service is not subscribed. */
+ /** This network is permanently disabled because service is not subscribed. */
public static final int DISABLED_AUTHENTICATION_NO_SUBSCRIPTION = 9;
/**
* All other disable reasons should be strictly less than this value.
@@ -1472,6 +1487,8 @@ public class WifiConfiguration implements Parcelable {
/**
* Network Selection disable timeout for the error. After the timeout milliseconds,
* enable the network again.
+ * If this is set to Integer.MAX_VALUE, the network will be permanently disabled until
+ * the next time the user manually connects to it.
*/
public final int mDisableTimeoutMillis;
@@ -1670,6 +1687,14 @@ public class WifiConfiguration implements Parcelable {
private boolean mHasEverConnected;
/**
+ * Boolean indicating if captive portal has never been detected on this network.
+ *
+ * This should be true by default, for newly created WifiConfigurations until a captive
+ * portal is detected.
+ */
+ private boolean mHasNeverDetectedCaptivePortal = true;
+
+ /**
* set whether this network is visible in latest Qualified Network Selection
* @param seen value set to candidate
* @hide
@@ -1758,6 +1783,19 @@ public class WifiConfiguration implements Parcelable {
return mHasEverConnected;
}
+ /**
+ * Set whether a captive portal has never been detected on this network.
+ * @hide
+ */
+ public void setHasNeverDetectedCaptivePortal(boolean value) {
+ mHasNeverDetectedCaptivePortal = value;
+ }
+
+ /** @hide */
+ public boolean hasNeverDetectedCaptivePortal() {
+ return mHasNeverDetectedCaptivePortal;
+ }
+
/** @hide */
public NetworkSelectionStatus() {
// previously stored configs will not have this parameter, so we default to false.
@@ -2033,6 +2071,7 @@ public class WifiConfiguration implements Parcelable {
setCandidateScore(source.getCandidateScore());
setConnectChoice(source.getConnectChoice());
setHasEverConnected(source.hasEverConnected());
+ setHasNeverDetectedCaptivePortal(source.hasNeverDetectedCaptivePortal());
}
/** @hide */
@@ -2052,6 +2091,7 @@ public class WifiConfiguration implements Parcelable {
dest.writeInt(CONNECT_CHOICE_NOT_EXISTS);
}
dest.writeInt(hasEverConnected() ? 1 : 0);
+ dest.writeInt(hasNeverDetectedCaptivePortal() ? 1 : 0);
}
/** @hide */
@@ -2070,6 +2110,7 @@ public class WifiConfiguration implements Parcelable {
setConnectChoice(null);
}
setHasEverConnected(in.readInt() != 0);
+ setHasNeverDetectedCaptivePortal(in.readInt() != 0);
}
}
@@ -2094,27 +2135,42 @@ public class WifiConfiguration implements Parcelable {
*/
@RecentFailureReason
private int mAssociationStatus = RECENT_FAILURE_NONE;
+ private long mLastUpdateTimeSinceBootMillis;
/**
* @param status the association status code for the recent failure
*/
- public void setAssociationStatus(@RecentFailureReason int status) {
+ public void setAssociationStatus(@RecentFailureReason int status,
+ long updateTimeSinceBootMs) {
mAssociationStatus = status;
+ mLastUpdateTimeSinceBootMillis = updateTimeSinceBootMs;
}
/**
* Sets the RecentFailure to NONE
*/
public void clear() {
mAssociationStatus = RECENT_FAILURE_NONE;
+ mLastUpdateTimeSinceBootMillis = 0;
}
/**
- * Get the recent failure code. One of {@link #RECENT_FAILURE_NONE} or
- * {@link #RECENT_FAILURE_AP_UNABLE_TO_HANDLE_NEW_STA}.
+ * Get the recent failure code. One of {@link #RECENT_FAILURE_NONE},
+ * {@link #RECENT_FAILURE_AP_UNABLE_TO_HANDLE_NEW_STA},
+ * {@link #RECENT_FAILURE_MBO_OCE_DISCONNECT},
+ * {@link #RECENT_FAILURE_REFUSED_TEMPORARILY},
+ * {@link #RECENT_FAILURE_POOR_CHANNEL_CONDITIONS}.
+ * {@link #RECENT_FAILURE_DISCONNECTION_AP_BUSY}
*/
@RecentFailureReason
public int getAssociationStatus() {
return mAssociationStatus;
}
+
+ /**
+ * Get the timestamp the failure status is last updated, in milliseconds since boot.
+ */
+ public long getLastUpdateTimeSinceBootMillis() {
+ return mLastUpdateTimeSinceBootMillis;
+ }
}
/**
@@ -2131,7 +2187,11 @@ public class WifiConfiguration implements Parcelable {
@IntDef(prefix = "RECENT_FAILURE_", value = {
RECENT_FAILURE_NONE,
RECENT_FAILURE_AP_UNABLE_TO_HANDLE_NEW_STA,
- RECENT_FAILURE_MBO_OCE_DISCONNECT})
+ RECENT_FAILURE_MBO_OCE_DISCONNECT,
+ RECENT_FAILURE_REFUSED_TEMPORARILY,
+ RECENT_FAILURE_POOR_CHANNEL_CONDITIONS,
+ RECENT_FAILURE_DISCONNECTION_AP_BUSY
+ })
public @interface RecentFailureReason {}
/**
@@ -2156,12 +2216,39 @@ public class WifiConfiguration implements Parcelable {
public static final int RECENT_FAILURE_MBO_OCE_DISCONNECT = 1001;
/**
+ * Failed to connect because the association is rejected by the AP.
+ * IEEE 802.11 association status code 30.
+ * @hide
+ */
+ @SystemApi
+ public static final int RECENT_FAILURE_REFUSED_TEMPORARILY = 1002;
+
+ /**
+ * Failed to connect because of excess frame loss and/or poor channel conditions.
+ * IEEE 802.11 association status code 34.
+ * @hide
+ */
+ @SystemApi
+ public static final int RECENT_FAILURE_POOR_CHANNEL_CONDITIONS = 1003;
+
+ /**
+ * Disconnected by the AP because the AP can't handle all the associated stations.
+ * IEEE 802.11 disconnection reason code 5.
+ * @hide
+ */
+ @SystemApi
+ public static final int RECENT_FAILURE_DISCONNECTION_AP_BUSY = 1004;
+
+ /**
* Get the failure reason for the most recent connection attempt, or
* {@link #RECENT_FAILURE_NONE} if there was no failure.
*
* Failure reasons include:
* {@link #RECENT_FAILURE_AP_UNABLE_TO_HANDLE_NEW_STA}
- *
+ * {@link #RECENT_FAILURE_MBO_OCE_DISCONNECT}
+ * {@link #RECENT_FAILURE_REFUSED_TEMPORARILY}
+ * {@link #RECENT_FAILURE_POOR_CHANNEL_CONDITIONS}
+ * {@link #RECENT_FAILURE_DISCONNECTION_AP_BUSY}
* @hide
*/
@RecentFailureReason
@@ -2224,6 +2311,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;
@@ -2336,6 +2424,8 @@ public class WifiConfiguration implements Parcelable {
}
sbuf.append(" hasEverConnected: ")
.append(mNetworkSelectionStatus.hasEverConnected()).append("\n");
+ sbuf.append(" hasNeverDetectedCaptivePortal: ")
+ .append(mNetworkSelectionStatus.hasNeverDetectedCaptivePortal()).append("\n");
if (this.numAssociation > 0) {
sbuf.append(" numAssociation ").append(this.numAssociation).append("\n");
@@ -2349,13 +2439,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) {
@@ -2513,7 +2604,8 @@ public class WifiConfiguration implements Parcelable {
}
}
sbuf.append("recentFailure: ").append("Association Rejection code: ")
- .append(recentFailure.getAssociationStatus()).append("\n");
+ .append(recentFailure.getAssociationStatus()).append(", last update time: ")
+ .append(recentFailure.getLastUpdateTimeSinceBootMillis()).append("\n");
sbuf.append("ShareThisAp: ").append(this.shareThisAp);
sbuf.append('\n');
@@ -2938,6 +3030,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;
@@ -2960,7 +3053,8 @@ public class WifiConfiguration implements Parcelable {
numNoInternetAccessReports = source.numNoInternetAccessReports;
noInternetAccessExpected = source.noInternetAccessExpected;
shared = source.shared;
- recentFailure.setAssociationStatus(source.recentFailure.getAssociationStatus());
+ recentFailure.setAssociationStatus(source.recentFailure.getAssociationStatus(),
+ source.recentFailure.getLastUpdateTimeSinceBootMillis());
mRandomizedMacAddress = source.mRandomizedMacAddress;
dppConnector = source.dppConnector;
dppNetAccessKey = source.dppNetAccessKey;
@@ -3024,6 +3118,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);
@@ -3043,6 +3138,7 @@ public class WifiConfiguration implements Parcelable {
dest.writeInt(shared ? 1 : 0);
dest.writeString(mPasspointManagementObjectTree);
dest.writeInt(recentFailure.getAssociationStatus());
+ dest.writeLong(recentFailure.getLastUpdateTimeSinceBootMillis());
dest.writeParcelable(mRandomizedMacAddress, flags);
dest.writeString(dppConnector);
dest.writeString(dppNetAccessKey);
@@ -3106,6 +3202,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;
@@ -3124,7 +3221,7 @@ public class WifiConfiguration implements Parcelable {
config.noInternetAccessExpected = in.readInt() != 0;
config.shared = in.readInt() != 0;
config.mPasspointManagementObjectTree = in.readString();
- config.recentFailure.setAssociationStatus(in.readInt());
+ config.recentFailure.setAssociationStatus(in.readInt(), in.readLong());
config.mRandomizedMacAddress = in.readParcelable(null);
config.dppConnector = in.readString();
config.dppNetAccessKey = in.readString();
diff --git a/wifi/java/android/net/wifi/WifiInfo.java b/wifi/java/android/net/wifi/WifiInfo.java
index 555401cd3060..18bda9b60fec 100644
--- a/wifi/java/android/net/wifi/WifiInfo.java
+++ b/wifi/java/android/net/wifi/WifiInfo.java
@@ -164,6 +164,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.
*/
private boolean mOsuAp;
@@ -331,6 +336,9 @@ public class WifiInfo implements Parcelable {
setFrequency(-1);
setMeteredHint(false);
setEphemeral(false);
+ setTrusted(false);
+ setOemPaid(false);
+ setOemPrivate(false);
setOsuAp(false);
setRequestingPackageName(null);
setFQDN(null);
@@ -369,7 +377,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;
@@ -730,7 +739,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;
}
@@ -740,12 +754,32 @@ 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;
}
@@ -1005,6 +1039,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);
@@ -1053,6 +1088,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();
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index 56fe5abb28cb..99d97850a7ae 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -44,7 +44,6 @@ import android.net.wifi.hotspot2.IProvisioningCallback;
import android.net.wifi.hotspot2.OsuProvider;
import android.net.wifi.hotspot2.PasspointConfiguration;
import android.net.wifi.hotspot2.ProvisioningCallback;
-import android.net.wifi.util.SdkLevelUtil;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
@@ -62,6 +61,7 @@ import android.util.SparseArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.modules.utils.build.SdkLevel;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -1105,7 +1105,7 @@ public class WifiManager {
* @see #ACTION_LINK_CONFIGURATION_CHANGED
* @hide
*/
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final String LINK_CONFIGURATION_CHANGED_ACTION =
"android.net.wifi.LINK_CONFIGURATION_CHANGED";
@@ -1354,7 +1354,7 @@ public class WifiManager {
* change is significant enough to change the RSSI signal level.
* @hide
*/
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int RSSI_LEVELS = 5;
//TODO (b/146346676): This needs to be removed, not used in the code.
@@ -2642,7 +2642,7 @@ public class WifiManager {
* @return true if this device supports multiple STA concurrency, false otherwise.
*/
public boolean isMultiStaConcurrencySupported() {
- if (!SdkLevelUtil.isAtLeastS()) {
+ if (!SdkLevel.isAtLeastS()) {
throw new UnsupportedOperationException();
}
return isFeatureSupported(WIFI_FEATURE_ADDITIONAL_STA);
diff --git a/wifi/java/android/net/wifi/WifiNetworkSpecifier.java b/wifi/java/android/net/wifi/WifiNetworkSpecifier.java
index e12bb9178235..f5ffd93d5fb6 100644
--- a/wifi/java/android/net/wifi/WifiNetworkSpecifier.java
+++ b/wifi/java/android/net/wifi/WifiNetworkSpecifier.java
@@ -56,6 +56,16 @@ public final class WifiNetworkSpecifier extends NetworkSpecifier implements Parc
MacAddress.BROADCAST_ADDRESS;
/**
+ * Set WPA Enterprise type according to certificate security level.
+ * This is for backward compatibility in R.
+ */
+ private static final int WPA3_ENTERPRISE_AUTO = 0;
+ /** Set WPA Enterprise type to standard mode only. */
+ private static final int WPA3_ENTERPRISE_STANDARD = 1;
+ /** Set WPA Enterprise type to 192 bit mode only. */
+ private static final int WPA3_ENTERPRISE_192_BIT = 2;
+
+ /**
* SSID pattern match specified by the app.
*/
private @Nullable PatternMatcher mSsidPatternMatcher;
@@ -87,6 +97,10 @@ public final class WifiNetworkSpecifier extends NetworkSpecifier implements Parc
*/
private @Nullable WifiEnterpriseConfig mWpa3EnterpriseConfig;
/**
+ * Indicate what type this WPA3-Enterprise network is.
+ */
+ private int mWpa3EnterpriseType = WPA3_ENTERPRISE_AUTO;
+ /**
* This is a network that does not broadcast its SSID, so an
* SSID-specific probe request must be used for scans.
*/
@@ -249,9 +263,14 @@ public final class WifiNetworkSpecifier extends NetworkSpecifier implements Parc
* sha384WithRSAEncryption (OID 1.2.840.113549.1.1.12) or ecdsa-with-SHA384
* (OID 1.2.840.10045.4.3.3).
*
+ * @deprecated use {@link #setWpa3EnterpriseStandardModeConfig(WifiEnterpriseConfig)} or
+ * {@link #setWpa3Enterprise192BitModeConfig(WifiEnterpriseConfig)} to specify
+ * WPA3-Enterprise type explicitly.
+ *
* @param enterpriseConfig Instance of {@link WifiEnterpriseConfig}.
* @return Instance of {@link Builder} to enable chaining of the builder method.
*/
+ @Deprecated
public @NonNull Builder setWpa3EnterpriseConfig(
@NonNull WifiEnterpriseConfig enterpriseConfig) {
checkNotNull(enterpriseConfig);
@@ -260,6 +279,58 @@ public final class WifiNetworkSpecifier extends NetworkSpecifier implements Parc
}
/**
+ * Set the associated enterprise configuration for this network. Needed for authenticating
+ * to standard WPA3-Enterprise networks. See {@link WifiEnterpriseConfig} for description.
+ * For WPA3-Enterprise in 192-bit security mode networks,
+ * see {@link #setWpa3Enterprise192BitModeConfig(WifiEnterpriseConfig)} for description.
+ *
+ * @param enterpriseConfig Instance of {@link WifiEnterpriseConfig}.
+ * @return Instance of {@link Builder} to enable chaining of the builder method.
+ */
+ public @NonNull Builder setWpa3EnterpriseStandardModeConfig(
+ @NonNull WifiEnterpriseConfig enterpriseConfig) {
+ checkNotNull(enterpriseConfig);
+ mWpa3EnterpriseConfig = new WifiEnterpriseConfig(enterpriseConfig);
+ mWpa3EnterpriseType = WPA3_ENTERPRISE_STANDARD;
+ return this;
+ }
+
+ /**
+ * Set the associated enterprise configuration for this network. Needed for authenticating
+ * to WPA3-Enterprise in 192-bit security mode networks. See {@link WifiEnterpriseConfig}
+ * for description. Both the client and CA certificates must be provided,
+ * and must be of type of either sha384WithRSAEncryption with key length of 3072bit or
+ * more (OID 1.2.840.113549.1.1.12), or ecdsa-with-SHA384 with key length of 384bit or
+ * more (OID 1.2.840.10045.4.3.3).
+ *
+ * @param enterpriseConfig Instance of {@link WifiEnterpriseConfig}.
+ * @return Instance of {@link Builder} to enable chaining of the builder method.
+ * @throws IllegalArgumentException if the EAP type or certificates do not
+ * meet 192-bit mode requirements.
+ */
+ public @NonNull Builder setWpa3Enterprise192BitModeConfig(
+ @NonNull WifiEnterpriseConfig enterpriseConfig) {
+ checkNotNull(enterpriseConfig);
+ if (enterpriseConfig.getEapMethod() != WifiEnterpriseConfig.Eap.TLS) {
+ throw new IllegalArgumentException("The 192-bit mode network type must be TLS");
+ }
+ if (!WifiEnterpriseConfig.isSuiteBCipherCert(
+ enterpriseConfig.getClientCertificate())) {
+ throw new IllegalArgumentException(
+ "The client certificate does not meet 192-bit mode requirements.");
+ }
+ if (!WifiEnterpriseConfig.isSuiteBCipherCert(
+ enterpriseConfig.getCaCertificate())) {
+ throw new IllegalArgumentException(
+ "The CA certificate does not meet 192-bit mode requirements.");
+ }
+
+ mWpa3EnterpriseConfig = new WifiEnterpriseConfig(enterpriseConfig);
+ mWpa3EnterpriseType = WPA3_ENTERPRISE_192_BIT;
+ return this;
+ }
+
+ /**
* Specifies whether this represents a hidden network.
* <p>
* <li>Setting this disallows the usage of {@link #setSsidPattern(PatternMatcher)} since
@@ -289,23 +360,21 @@ public final class WifiNetworkSpecifier extends NetworkSpecifier implements Parc
configuration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP);
configuration.enterpriseConfig = mWpa2EnterpriseConfig;
} else if (mWpa3EnterpriseConfig != null) { // WPA3-Enterprise
- if (mWpa3EnterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.TLS
+ if (mWpa3EnterpriseType == WPA3_ENTERPRISE_AUTO
+ && mWpa3EnterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.TLS
&& WifiEnterpriseConfig.isSuiteBCipherCert(
mWpa3EnterpriseConfig.getClientCertificate())
&& WifiEnterpriseConfig.isSuiteBCipherCert(
mWpa3EnterpriseConfig.getCaCertificate())) {
- // WPA3-Enterprise in 192-bit security mode (Suite-B)
+ // WPA3-Enterprise in 192-bit security mode
+ configuration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP_SUITE_B);
+ } else if (mWpa3EnterpriseType == WPA3_ENTERPRISE_192_BIT) {
+ // WPA3-Enterprise in 192-bit security mode
configuration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP_SUITE_B);
} else {
// WPA3-Enterprise
- configuration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP);
- configuration.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
- configuration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
- configuration.allowedPairwiseCiphers.set(
- WifiConfiguration.PairwiseCipher.GCMP_256);
- configuration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
- configuration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GCMP_256);
- configuration.requirePmf = true;
+ configuration.setSecurityParams(
+ WifiConfiguration.SECURITY_TYPE_EAP_WPA3_ENTERPRISE);
}
configuration.enterpriseConfig = mWpa3EnterpriseConfig;
} else if (mIsEnhancedOpen) { // OWE network
diff --git a/wifi/java/android/net/wifi/WifiNetworkSuggestion.java b/wifi/java/android/net/wifi/WifiNetworkSuggestion.java
index c1f900519fc5..dc5189724c25 100644
--- a/wifi/java/android/net/wifi/WifiNetworkSuggestion.java
+++ b/wifi/java/android/net/wifi/WifiNetworkSuggestion.java
@@ -25,8 +25,8 @@ 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.net.wifi.util.SdkLevelUtil;
import android.os.Parcel;
import android.os.Parcelable;
import android.telephony.SubscriptionInfo;
@@ -34,6 +34,8 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
+import com.android.modules.utils.build.SdkLevel;
+
import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
@@ -55,6 +57,16 @@ public final class WifiNetworkSuggestion implements Parcelable {
private static final int UNASSIGNED_PRIORITY = -1;
/**
+ * Set WPA Enterprise type according to certificate security level.
+ * This is for backward compatibility in R.
+ */
+ private static final int WPA3_ENTERPRISE_AUTO = 0;
+ /** Set WPA Enterprise type to standard mode only. */
+ private static final int WPA3_ENTERPRISE_STANDARD = 1;
+ /** Set WPA Enterprise type to 192 bit mode only. */
+ private static final int WPA3_ENTERPRISE_192_BIT = 2;
+
+ /**
* SSID of the network.
*/
private String mSsid;
@@ -85,6 +97,10 @@ public final class WifiNetworkSuggestion implements Parcelable {
*/
private @Nullable WifiEnterpriseConfig mWpa3EnterpriseConfig;
/**
+ * Indicate what type this WPA3-Enterprise network is.
+ */
+ private int mWpa3EnterpriseType = WPA3_ENTERPRISE_AUTO;
+ /**
* The passpoint config for use with Hotspot 2.0 network
*/
private @Nullable PasspointConfiguration mPasspointConfiguration;
@@ -165,6 +181,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.
*/
private boolean mIsEnhancedMacRandomizationEnabled;
@@ -191,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;
@@ -311,11 +334,16 @@ public final class WifiNetworkSuggestion implements Parcelable {
* sha384WithRSAEncryption (OID 1.2.840.113549.1.1.12) or ecdsa-with-SHA384
* (OID 1.2.840.10045.4.3.3).
*
+ * @deprecated use {@link #setWpa3EnterpriseStandardModeConfig(WifiEnterpriseConfig)} or
+ * {@link #setWpa3Enterprise192BitModeConfig(WifiEnterpriseConfig)} to specify
+ * WPA3-Enterprise type explicitly.
+ *
* @param enterpriseConfig Instance of {@link WifiEnterpriseConfig}.
* @return Instance of {@link Builder} to enable chaining of the builder method.
* @throws IllegalArgumentException if configuration CA certificate or
* AltSubjectMatch/DomainSuffixMatch is not set.
*/
+ @Deprecated
public @NonNull Builder setWpa3EnterpriseConfig(
@NonNull WifiEnterpriseConfig enterpriseConfig) {
checkNotNull(enterpriseConfig);
@@ -327,6 +355,63 @@ public final class WifiNetworkSuggestion implements Parcelable {
}
/**
+ * Set the associated enterprise configuration for this network. Needed for authenticating
+ * to WPA3-Enterprise standard networks. See {@link WifiEnterpriseConfig} for description.
+ * For WPA3-Enterprise in 192-bit security mode networks,
+ * see {@link #setWpa3Enterprise192BitModeConfig(WifiEnterpriseConfig)} for description.
+ *
+ * @param enterpriseConfig Instance of {@link WifiEnterpriseConfig}.
+ * @return Instance of {@link Builder} to enable chaining of the builder method.
+ * @throws IllegalArgumentException if configuration CA certificate or
+ * AltSubjectMatch/DomainSuffixMatch is not set.
+ */
+ public @NonNull Builder setWpa3EnterpriseStandardModeConfig(
+ @NonNull WifiEnterpriseConfig enterpriseConfig) {
+ checkNotNull(enterpriseConfig);
+ if (enterpriseConfig.isInsecure()) {
+ throw new IllegalArgumentException("Enterprise configuration is insecure");
+ }
+ mWpa3EnterpriseConfig = new WifiEnterpriseConfig(enterpriseConfig);
+ mWpa3EnterpriseType = WPA3_ENTERPRISE_STANDARD;
+ return this;
+ }
+
+ /**
+ * Set the associated enterprise configuration for this network. Needed for authenticating
+ * to WPA3-Enterprise in 192-bit security mode networks. See {@link WifiEnterpriseConfig}
+ * for description. Both the client and CA certificates must be provided,
+ * and must be of type of either sha384WithRSAEncryption with key length of 3072bit or
+ * more (OID 1.2.840.113549.1.1.12), or ecdsa-with-SHA384 with key length of 384bit or
+ * more (OID 1.2.840.10045.4.3.3).
+ *
+ * @param enterpriseConfig Instance of {@link WifiEnterpriseConfig}.
+ * @return Instance of {@link Builder} to enable chaining of the builder method.
+ * @throws IllegalArgumentException if the EAP type or certificates do not
+ * meet 192-bit mode requirements.
+ */
+ public @NonNull Builder setWpa3Enterprise192BitModeConfig(
+ @NonNull WifiEnterpriseConfig enterpriseConfig) {
+ checkNotNull(enterpriseConfig);
+ if (enterpriseConfig.getEapMethod() != WifiEnterpriseConfig.Eap.TLS) {
+ throw new IllegalArgumentException("The 192-bit mode network type must be TLS");
+ }
+ if (!WifiEnterpriseConfig.isSuiteBCipherCert(
+ enterpriseConfig.getClientCertificate())) {
+ throw new IllegalArgumentException(
+ "The client certificate does not meet 192-bit mode requirements.");
+ }
+ if (!WifiEnterpriseConfig.isSuiteBCipherCert(
+ enterpriseConfig.getCaCertificate())) {
+ throw new IllegalArgumentException(
+ "The CA certificate does not meet 192-bit mode requirements.");
+ }
+
+ mWpa3EnterpriseConfig = new WifiEnterpriseConfig(enterpriseConfig);
+ mWpa3EnterpriseType = WPA3_ENTERPRISE_192_BIT;
+ return this;
+ }
+
+ /**
* Set the associated Passpoint configuration for this network. Needed for authenticating
* to Hotspot 2.0 networks. See {@link PasspointConfiguration} for description.
*
@@ -375,7 +460,7 @@ public final class WifiNetworkSuggestion implements Parcelable {
* @return Instance of {@link Builder} to enable chaining of the builder method.
*/
public @NonNull Builder setSubscriptionId(int subId) {
- if (!SdkLevelUtil.isAtLeastS()) {
+ if (!SdkLevel.isAtLeastS()) {
throw new UnsupportedOperationException();
}
mSubscriptionId = subId;
@@ -390,7 +475,7 @@ public final class WifiNetworkSuggestion implements Parcelable {
* @return Instance of {@link Builder} to enable chaining of the builder method.
*/
public @NonNull Builder setPriorityGroup(int priorityGroup) {
- if (!SdkLevelUtil.isAtLeastS()) {
+ if (!SdkLevel.isAtLeastS()) {
throw new UnsupportedOperationException();
}
mPriorityGroup = priorityGroup;
@@ -590,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>
@@ -611,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).
@@ -622,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
@@ -631,13 +726,55 @@ public final class WifiNetworkSuggestion implements Parcelable {
*/
@SystemApi
public @NonNull Builder setOemPaid(boolean isOemPaid) {
- if (!SdkLevelUtil.isAtLeastS()) {
+ if (!SdkLevel.isAtLeastS()) {
throw new UnsupportedOperationException();
}
mIsNetworkOemPaid = isOemPaid;
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.
@@ -652,23 +789,21 @@ public final class WifiNetworkSuggestion implements Parcelable {
configuration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP);
configuration.enterpriseConfig = mWpa2EnterpriseConfig;
} else if (mWpa3EnterpriseConfig != null) { // WPA3-Enterprise
- if (mWpa3EnterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.TLS
+ if (mWpa3EnterpriseType == WPA3_ENTERPRISE_AUTO
+ && mWpa3EnterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.TLS
&& WifiEnterpriseConfig.isSuiteBCipherCert(
mWpa3EnterpriseConfig.getClientCertificate())
&& WifiEnterpriseConfig.isSuiteBCipherCert(
mWpa3EnterpriseConfig.getCaCertificate())) {
- // WPA3-Enterprise in 192-bit security mode (Suite-B)
+ // WPA3-Enterprise in 192-bit security mode
+ configuration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP_SUITE_B);
+ } else if (mWpa3EnterpriseType == WPA3_ENTERPRISE_192_BIT) {
+ // WPA3-Enterprise in 192-bit security mode
configuration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP_SUITE_B);
} else {
// WPA3-Enterprise
- configuration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP);
- configuration.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
- configuration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
- configuration.allowedPairwiseCiphers.set(
- WifiConfiguration.PairwiseCipher.GCMP_256);
- configuration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
- configuration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GCMP_256);
- configuration.requirePmf = true;
+ configuration.setSecurityParams(
+ WifiConfiguration.SECURITY_TYPE_EAP_WPA3_ENTERPRISE);
}
configuration.enterpriseConfig = mWpa3EnterpriseConfig;
} else if (mIsEnhancedOpen) { // OWE network
@@ -705,6 +840,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;
@@ -738,6 +874,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);
@@ -857,6 +994,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,
@@ -1024,6 +1169,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();
@@ -1124,13 +1270,25 @@ public final class WifiNetworkSuggestion implements Parcelable {
*/
@SystemApi
public boolean isOemPaid() {
- if (!SdkLevelUtil.isAtLeastS()) {
+ if (!SdkLevel.isAtLeastS()) {
throw new UnsupportedOperationException();
}
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)
* @see Builder#setWpa2EnterpriseConfig(WifiEnterpriseConfig)
@@ -1162,7 +1320,7 @@ public final class WifiNetworkSuggestion implements Parcelable {
* @see Builder#setPriorityGroup(int)
*/
public int getPriorityGroup() {
- if (!SdkLevelUtil.isAtLeastS()) {
+ if (!SdkLevel.isAtLeastS()) {
throw new UnsupportedOperationException();
}
return priorityGroup;
@@ -1172,7 +1330,7 @@ public final class WifiNetworkSuggestion implements Parcelable {
* @see Builder#setSubscriptionId(int)
*/
public int getSubscriptionId() {
- if (!SdkLevelUtil.isAtLeastS()) {
+ if (!SdkLevel.isAtLeastS()) {
throw new UnsupportedOperationException();
}
return wifiConfiguration.subscriptionId;
diff --git a/wifi/java/android/net/wifi/aware/AwareResources.java b/wifi/java/android/net/wifi/aware/AwareResources.java
new file mode 100644
index 000000000000..cee1f40c05cd
--- /dev/null
+++ b/wifi/java/android/net/wifi/aware/AwareResources.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.aware;
+
+import android.annotation.NonNull;
+import android.os.Handler;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * The resources of the Aware service.
+ */
+public final class AwareResources implements Parcelable {
+ /**
+ * Number of the NDPs are available.
+ */
+ private int mNumOfAvailableNdps;
+
+ /**
+ * Number of the publish sessions are available.
+ */
+ private int mNumOfAvailablePublishSessions;
+
+ /**
+ * Number of the subscribe sessions are available.
+ */
+ private int mNumOfAvailableSubscribeSessions;
+
+ /**
+ * @hide : should not be created by apps
+ */
+ public AwareResources() {
+ }
+
+ /**
+ * Return the number of Aware data-paths (also known as NDPs - NAN Data Paths) which an app
+ * could create. Please refer to the {@link WifiAwareNetworkSpecifier} to create
+ * a Network Specifier and request a data-path.
+ * <p>
+ * Note that these resources aren't reserved - other apps could use them by the time you
+ * attempt to create a data-path.
+ * </p>
+ * @return A Non-negative integer, number of data-paths that could be created.
+ */
+ public int getNumOfAvailableDataPaths() {
+ return mNumOfAvailableNdps;
+ }
+
+ /**
+ * Return the number of Aware publish sessions which an app could create. Please refer to the
+ * {@link WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, Handler)}
+ * to create a publish session.
+ * <p>
+ * Note that these resources aren't reserved - other apps could use them by the time you
+ * attempt to create a publish session.
+ * </p>
+ * @return A Non-negative integer, number of publish sessions that could be created.
+ */
+ public int getNumOfAvailablePublishSessions() {
+ return mNumOfAvailablePublishSessions;
+ }
+
+ /**
+ * Return the number of Aware subscribe sessions which an app could create. Please refer to the
+ * {@link WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, Handler)}
+ * to create a publish session.
+ * <p>
+ * Note that these resources aren't reserved - other apps could use them by the time you
+ * attempt to create a subscribe session.
+ * </p>
+ * @return A Non-negative integer, number of subscribe sessions that could be created.
+ */
+ public int getNumOfAvailableSubscribeSessions() {
+ return mNumOfAvailableSubscribeSessions;
+ }
+
+ /**
+ * Set the number of the available NDPs.
+ * @hide
+ * @param numOfAvailableNdps Number of available NDPs.
+ */
+ public void setNumOfAvailableDataPaths(int numOfAvailableNdps) {
+ mNumOfAvailableNdps = numOfAvailableNdps;
+ }
+
+ /**
+ * Set the number of the available publish sessions.
+ * @hide
+ * @param numOfAvailablePublishSessions Number of available publish sessions.
+ */
+ public void setNumOfAvailablePublishSessions(int numOfAvailablePublishSessions) {
+ mNumOfAvailablePublishSessions = numOfAvailablePublishSessions;
+ }
+
+ /**
+ * Set the number of the available subscribe sessions.
+ * @hide
+ * @param numOfAvailableSubscribeSessions Number of available subscribe sessions.
+ */
+ public void setNumOfAvailableSubscribeSessions(int numOfAvailableSubscribeSessions) {
+ mNumOfAvailableSubscribeSessions = numOfAvailableSubscribeSessions;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
+ dest.writeInt(mNumOfAvailableNdps);
+ dest.writeInt(mNumOfAvailablePublishSessions);
+ dest.writeInt(mNumOfAvailableSubscribeSessions);
+ }
+
+ public static final @android.annotation.NonNull Creator<AwareResources> CREATOR =
+ new Creator<AwareResources>() {
+ @Override
+ public AwareResources createFromParcel(Parcel in) {
+ AwareResources awareResources = new AwareResources();
+ awareResources.setNumOfAvailableDataPaths(in.readInt());
+ awareResources.setNumOfAvailablePublishSessions(in.readInt());
+ awareResources.setNumOfAvailableSubscribeSessions(in.readInt());
+ return awareResources;
+ }
+
+ @Override
+ public AwareResources[] newArray(int size) {
+ return new AwareResources[size];
+ }
+ };
+}
diff --git a/wifi/java/android/net/wifi/aware/Characteristics.java b/wifi/java/android/net/wifi/aware/Characteristics.java
index d5fd48e9e7b3..9bdda7f7d323 100644
--- a/wifi/java/android/net/wifi/aware/Characteristics.java
+++ b/wifi/java/android/net/wifi/aware/Characteristics.java
@@ -21,6 +21,8 @@ import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
+import com.android.modules.utils.build.SdkLevel;
+
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -37,6 +39,9 @@ public final class Characteristics implements Parcelable {
public static final String KEY_MAX_MATCH_FILTER_LENGTH = "key_max_match_filter_length";
/** @hide */
public static final String KEY_SUPPORTED_CIPHER_SUITES = "key_supported_cipher_suites";
+ /** @hide */
+ public static final String KEY_IS_INSTANT_COMMUNICATION_MODE_SUPPORTED =
+ "key_is_instant_communication_mode_supported";
private Bundle mCharacteristics = new Bundle();
@@ -83,6 +88,17 @@ public final class Characteristics implements Parcelable {
return mCharacteristics.getInt(KEY_MAX_MATCH_FILTER_LENGTH);
}
+ /**
+ * Check if instant communication mode is supported by device.
+ * @return True if supported, false otherwise.
+ */
+ public boolean isInstantCommunicationModeSupported() {
+ if (!SdkLevel.isAtLeastS()) {
+ throw new UnsupportedOperationException();
+ }
+ return mCharacteristics.getBoolean(KEY_IS_INSTANT_COMMUNICATION_MODE_SUPPORTED);
+ }
+
/** @hide */
@IntDef(flag = true, prefix = { "WIFI_AWARE_CIPHER_SUITE_" }, value = {
WIFI_AWARE_CIPHER_SUITE_NCS_SK_128,
diff --git a/wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java b/wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java
index e3800ad6ef36..da8e17e2f41a 100644
--- a/wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java
+++ b/wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java
@@ -191,14 +191,18 @@ public class DiscoverySessionCallback {
}
/**
- * Called when the discovered peer is no longer visible. All further operations on this
- * discovery session will fail. If the peer is visible again,
+ * Called when the discovered service is not available. All further operations on this
+ * discovery session will fail. If the service is available again,
* {@link #onServiceDiscovered(PeerHandle, byte[], List)} or
* {@link #onServiceDiscoveredWithinRange(PeerHandle, byte[], List, int)} will be called.
*
* @param peerHandle An opaque handle to the peer matching our discovery operation.
+ * @param reason Discovered service lost reason code. One of
+ * {@link WifiAwareManager#WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE},
+ * {@link WifiAwareManager#WIFI_AWARE_DISCOVERY_LOST_REASON_UNKNOWN
*/
- public void onServiceLost(@NonNull PeerHandle peerHandle) {
+ public void onServiceLost(@NonNull PeerHandle peerHandle,
+ @WifiAwareManager.DiscoveryLostReasonCode int reason) {
/* empty */
}
}
diff --git a/wifi/java/android/net/wifi/aware/IWifiAwareManager.aidl b/wifi/java/android/net/wifi/aware/IWifiAwareManager.aidl
index f5b1edce1d69..c90c4d8a27b2 100644
--- a/wifi/java/android/net/wifi/aware/IWifiAwareManager.aidl
+++ b/wifi/java/android/net/wifi/aware/IWifiAwareManager.aidl
@@ -25,6 +25,7 @@ import android.net.wifi.aware.IWifiAwareMacAddressProvider;
import android.net.wifi.aware.PublishConfig;
import android.net.wifi.aware.SubscribeConfig;
import android.net.wifi.aware.Characteristics;
+import android.net.wifi.aware.AwareResources;
/**
* Interface that WifiAwareService implements
@@ -36,7 +37,10 @@ interface IWifiAwareManager
// Aware API
boolean isUsageEnabled();
Characteristics getCharacteristics();
+ AwareResources getAvailableAwareResources();
boolean isDeviceAttached();
+ void enableInstantCommunicationMode(in String callingPackage, boolean enable);
+ boolean isInstantCommunicationModeEnabled();
// client API
void connect(in IBinder binder, in String callingPackage, in String callingFeatureId,
diff --git a/wifi/java/android/net/wifi/aware/WifiAwareManager.java b/wifi/java/android/net/wifi/aware/WifiAwareManager.java
index d6e46fd52caf..e19b095b27eb 100644
--- a/wifi/java/android/net/wifi/aware/WifiAwareManager.java
+++ b/wifi/java/android/net/wifi/aware/WifiAwareManager.java
@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
+import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.content.Context;
import android.net.ConnectivityManager;
@@ -37,6 +38,8 @@ import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
+import com.android.modules.utils.build.SdkLevel;
+
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
@@ -151,6 +154,27 @@ public class WifiAwareManager {
*/
public static final int WIFI_AWARE_DATA_PATH_ROLE_RESPONDER = 1;
+ /** @hide */
+ @IntDef({
+ WIFI_AWARE_DISCOVERY_LOST_REASON_UNKNOWN,
+ WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE})
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface DiscoveryLostReasonCode {
+ }
+
+ /**
+ * Reason code provided in {@link DiscoverySessionCallback#onServiceLost(PeerHandle, int)}
+ * indicating that the service was lost for unknown reason.
+ */
+ public static final int WIFI_AWARE_DISCOVERY_LOST_REASON_UNKNOWN = 0;
+
+ /**
+ * Reason code provided in {@link DiscoverySessionCallback#onServiceLost(PeerHandle, int)}
+ * indicating that the service advertised by the peer is no longer visible. This may be because
+ * the peer is out of range or because the peer stopped advertising this service.
+ */
+ public static final int WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE = 1;
+
private final Context mContext;
private final IWifiAwareManager mService;
@@ -187,6 +211,9 @@ public class WifiAwareManager {
* or not (false).
*/
public boolean isDeviceAttached() {
+ if (!SdkLevel.isAtLeastS()) {
+ throw new UnsupportedOperationException();
+ }
try {
return mService.isDeviceAttached();
} catch (RemoteException e) {
@@ -195,12 +222,48 @@ public class WifiAwareManager {
}
/**
+ * Enable the Wifi Aware Instant communication mode. If the device doesn't support this feature
+ * calling this API will result no action.
+ * @see Characteristics#isInstantCommunicationModeSupported()
+ * @param enable true for enable, false otherwise.
+ * @hide
+ */
+ @SystemApi
+ public void enableInstantCommunicationMode(boolean enable) {
+ if (!SdkLevel.isAtLeastS()) {
+ throw new UnsupportedOperationException();
+ }
+ try {
+ mService.enableInstantCommunicationMode(mContext.getOpPackageName(), enable);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Return the current status of the Wifi Aware instant communication mode.
+ * If the device doesn't support this feature, return will always be false.
+ * @see Characteristics#isInstantCommunicationModeSupported()
+ * @return true if it is enabled, false otherwise.
+ */
+ public boolean isInstantCommunicationModeEnabled() {
+ if (!SdkLevel.isAtLeastS()) {
+ throw new UnsupportedOperationException();
+ }
+ try {
+ return mService.isInstantCommunicationModeEnabled();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Returns the characteristics of the Wi-Fi Aware interface: a set of parameters which specify
* limitations on configurations, e.g. the maximum service name length.
*
* @return An object specifying configuration limitations of Aware.
*/
- public Characteristics getCharacteristics() {
+ public @Nullable Characteristics getCharacteristics() {
try {
return mService.getCharacteristics();
} catch (RemoteException e) {
@@ -209,6 +272,23 @@ public class WifiAwareManager {
}
/**
+ * Return the available resources of the Wi-Fi aware service: a set of parameters which specify
+ * limitations on service usage, e.g the number of data-paths which could be created..
+ *
+ * @return An object specifying the currently available resource of the Wi-Fi Aware service.
+ */
+ public @Nullable AwareResources getAvailableAwareResources() {
+ if (!SdkLevel.isAtLeastS()) {
+ throw new UnsupportedOperationException();
+ }
+ try {
+ return mService.getAvailableAwareResources();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Attach to the Wi-Fi Aware service - enabling the application to create discovery sessions or
* create connections to peers. The device will attach to an existing cluster if it can find
* one or create a new cluster (if it is the first to enable Aware in its vicinity). Results
@@ -695,7 +775,8 @@ public class WifiAwareManager {
break;
case CALLBACK_MATCH_EXPIRED:
mOriginalCallback
- .onServiceLost(new PeerHandle(msg.arg1));
+ .onServiceLost(new PeerHandle(msg.arg1),
+ WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE);
}
}
};
diff --git a/wifi/java/android/net/wifi/hotspot2/pps/HomeSp.java b/wifi/java/android/net/wifi/hotspot2/pps/HomeSp.java
index 35a8ff6095e0..64aad613c8b2 100644
--- a/wifi/java/android/net/wifi/hotspot2/pps/HomeSp.java
+++ b/wifi/java/android/net/wifi/hotspot2/pps/HomeSp.java
@@ -16,6 +16,7 @@
package android.net.wifi.hotspot2.pps;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;
@@ -24,6 +25,7 @@ import android.util.Log;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -214,23 +216,52 @@ public final class HomeSp implements Parcelable {
*
* @param otherHomePartners Array of Strings containing the FQDNs of other Home partner
* providers
+ * @hide
*/
public void setOtherHomePartners(@Nullable String[] otherHomePartners) {
mOtherHomePartners = otherHomePartners;
}
/**
+ * Set the list of FQDN (Fully Qualified Domain Name) of other Home partner providers.
+ *
+ * @param otherHomePartners Collection of Strings containing the FQDNs of other Home partner
+ * providers
+ */
+ public void setOtherHomePartnersList(@NonNull Collection<String> otherHomePartners) {
+ if (otherHomePartners == null) {
+ return;
+ }
+ mOtherHomePartners = otherHomePartners.toArray(new String[otherHomePartners.size()]);
+ }
+
+ /**
* Get the list of FQDN (Fully Qualified Domain Name) of other Home partner providers set in
* the profile.
*
* @return Array of Strings containing the FQDNs of other Home partner providers set in the
* profile
+ * @hide
*/
public @Nullable String[] getOtherHomePartners() {
return mOtherHomePartners;
}
/**
+ * Get the list of FQDN (Fully Qualified Domain Name) of other Home partner providers set in
+ * the profile.
+ *
+ * @return Collection of Strings containing the FQDNs of other Home partner providers set in the
+ * profile
+ */
+ public @NonNull Collection<String> getOtherHomePartnersList() {
+ if (mOtherHomePartners == null) {
+ return Collections.emptyList();
+ }
+ return Arrays.asList(mOtherHomePartners);
+ }
+
+ /**
* List of Organization Identifiers (OIs) identifying a roaming consortium of
* which this provider is a member.
*/
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java b/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java
index d47989235f0b..d3a6bac2513f 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java
@@ -23,6 +23,7 @@ import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.net.MacAddress;
import android.net.wifi.WpsInfo;
+import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
@@ -138,7 +139,7 @@ public class WifiP2pConfig implements Parcelable {
public int groupOwnerIntent = GROUP_OWNER_INTENT_AUTO;
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public int netId = WifiP2pGroup.NETWORK_ID_PERSISTENT;
/**
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java b/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java
index 02ed05fa83b9..685b6b32de44 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java
@@ -19,6 +19,7 @@ package android.net.wifi.p2p;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
+import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
@@ -186,7 +187,7 @@ public class WifiP2pDevice implements Parcelable {
* Note: The events formats can be looked up in the wpa_supplicant code
* @hide
*/
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public WifiP2pDevice(String string) throws IllegalArgumentException {
String[] tokens = string.split("[ \n]");
Matcher match;
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java
index ededf67fec7f..e7866e618089 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java
@@ -17,6 +17,7 @@
package android.net.wifi.p2p;
import android.compat.annotation.UnsupportedAppUsage;
+import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
@@ -83,7 +84,7 @@ public class WifiP2pDeviceList implements Parcelable {
* @param device to be updated
* @hide
*/
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public void update(WifiP2pDevice device) {
updateSupplicantDetails(device);
mDevices.get(device.deviceAddress).status = device.status;
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
index f433488b4292..cccbd86e52f6 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
@@ -399,7 +399,7 @@ public class WifiP2pManager {
public static final int CANCEL_CONNECT_SUCCEEDED = BASE + 12;
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int CREATE_GROUP = BASE + 13;
/** @hide */
public static final int CREATE_GROUP_FAILED = BASE + 14;
@@ -1114,7 +1114,7 @@ public class WifiP2pManager {
}
}
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
private int putListener(Object listener) {
if (listener == null) return INVALID_LISTENER_KEY;
int key;
@@ -1426,7 +1426,7 @@ public class WifiP2pManager {
* {@link ActionListener#onSuccess} or {@link ActionListener#onFailure}.
* @hide
*/
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public void startWps(Channel c, WpsInfo wps, ActionListener listener) {
checkChannel(c);
c.mAsyncChannel.sendMessage(START_WPS, 0, c.putListener(listener), wps);
@@ -1707,7 +1707,7 @@ public class WifiP2pManager {
}
/** @hide */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
@RequiresPermission(android.Manifest.permission.CONFIGURE_WIFI_DISPLAY)
public void setWFDInfo(@NonNull Channel c, @NonNull WifiP2pWfdInfo wfdInfo,
@Nullable ActionListener listener) {
diff --git a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceInfo.java b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceInfo.java
index 37b442baeb3f..5d018e75488e 100644
--- a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceInfo.java
+++ b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceInfo.java
@@ -170,7 +170,7 @@ public class WifiP2pServiceInfo implements Parcelable {
}
/** Implement the Parcelable interface {@hide} */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final @android.annotation.NonNull Creator<WifiP2pServiceInfo> CREATOR =
new Creator<WifiP2pServiceInfo>() {
public WifiP2pServiceInfo createFromParcel(Parcel in) {
diff --git a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceRequest.java b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceRequest.java
index 68cbb88037b0..dea0477cf09b 100644
--- a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceRequest.java
+++ b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceRequest.java
@@ -265,7 +265,7 @@ public class WifiP2pServiceRequest implements Parcelable {
}
/** Implement the Parcelable interface {@hide} */
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final @android.annotation.NonNull Creator<WifiP2pServiceRequest> CREATOR =
new Creator<WifiP2pServiceRequest>() {
public WifiP2pServiceRequest createFromParcel(Parcel in) {
diff --git a/wifi/java/android/net/wifi/util/SdkLevelUtil.java b/wifi/java/android/net/wifi/util/SdkLevelUtil.java
deleted file mode 100644
index d08d4fd742b7..000000000000
--- a/wifi/java/android/net/wifi/util/SdkLevelUtil.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.net.wifi.util;
-
-import android.os.Build;
-
-/**
- * Utility to check the SDK version of the device that the code is running on.
- *
- * This can be used to disable new Wifi APIs added in Mainline updates on older SDK versions.
- *
- * Note: if certain functionality is gated with SdkLevelUtil, its corresponding unit tests should
- * also be gated by the same condition. Then, those unit tests will only be exercised on a base
- * system image satisfying that condition.
- * Alternatively, it can be tested via static mocking.
- *
- * @hide
- */
-public class SdkLevelUtil {
-
- /** This class is not instantiable. */
- private SdkLevelUtil() {}
-
- /** Returns true if the Android platform SDK is at least "S", false otherwise. */
- public static boolean isAtLeastS() {
- // TODO(b/167575586): after S SDK finalization, this method should just be
- // `return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S;`
-
- // at least S: return true
- // this condition only evaluates to true after S SDK finalization when VERSION_CODES.S
- // is set to something like "31", before SDK finalization the value is "10000"
- // Note that Build.VERSION_CODES.S is inlined at compile time. If it's inlined to 10000,
- // this condition never evaluates to true.
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
- return true;
- }
-
- // Assume for now that S = R + 1
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) {
- return true;
- }
-
- // R: check CODENAME
- // Before S SDK finalization, SDK_INT = R = 30 i.e. remains on the previous version
- if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) {
- // CODENAME = "REL" on R release builds
- // CODENAME = "S" on S development builds
- return "S".equals(Build.VERSION.CODENAME);
- }
-
- // older than R: return false
- return false;
- }
-}