diff options
Diffstat (limited to 'wifi/java/android/net')
61 files changed, 2144 insertions, 780 deletions
diff --git a/wifi/java/android/net/wifi/ILocalOnlyHotspotCallback.aidl b/wifi/java/android/net/wifi/ILocalOnlyHotspotCallback.aidl index b83b594c8cb9..b567f29660a7 100644 --- a/wifi/java/android/net/wifi/ILocalOnlyHotspotCallback.aidl +++ b/wifi/java/android/net/wifi/ILocalOnlyHotspotCallback.aidl @@ -16,7 +16,7 @@ package android.net.wifi; -import android.net.wifi.WifiConfiguration; +import android.net.wifi.SoftApConfiguration; /** * Communicates LOHS status back to the application process. @@ -24,7 +24,7 @@ import android.net.wifi.WifiConfiguration; * @hide */ oneway interface ILocalOnlyHotspotCallback { - void onHotspotStarted(in WifiConfiguration config); + void onHotspotStarted(in SoftApConfiguration config); void onHotspotStopped(); void onHotspotFailed(int reason); } diff --git a/wifi/java/android/net/wifi/INetworkRequestMatchCallback.aidl b/wifi/java/android/net/wifi/INetworkRequestMatchCallback.aidl index d14ec57ea07a..51d74f0fcfa9 100644 --- a/wifi/java/android/net/wifi/INetworkRequestMatchCallback.aidl +++ b/wifi/java/android/net/wifi/INetworkRequestMatchCallback.aidl @@ -17,7 +17,6 @@ package android.net.wifi; import android.net.wifi.INetworkRequestUserSelectionCallback; -import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; /** @@ -31,7 +30,7 @@ oneway interface INetworkRequestMatchCallback void onAbort(); - void onMatch(in List<ScanResult> scanResults); + void onMatch(in List<android.net.wifi.ScanResult> scanResults); void onUserSelectionConnectSuccess(in WifiConfiguration wificonfiguration); diff --git a/wifi/java/android/net/wifi/WifiClient.aidl b/wifi/java/android/net/wifi/IScoreChangeCallback.aidl index accdaddfc848..fd236107bc6e 100644 --- a/wifi/java/android/net/wifi/WifiClient.aidl +++ b/wifi/java/android/net/wifi/IScoreChangeCallback.aidl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * 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. @@ -16,4 +16,14 @@ package android.net.wifi; -@JavaOnlyStableParcelable parcelable WifiClient;
\ No newline at end of file +/** + * Interface for Wi-Fi network score callback. + * + * @hide + */ +oneway interface IScoreChangeCallback +{ + void onStatusChange(int sessionId, boolean exiting); + + void onTriggerUpdateOfWifiUsabilityStats(int sessionId); +} diff --git a/wifi/java/android/net/wifi/ISoftApCallback.aidl b/wifi/java/android/net/wifi/ISoftApCallback.aidl index a4ad5b728506..57418cf402ed 100644 --- a/wifi/java/android/net/wifi/ISoftApCallback.aidl +++ b/wifi/java/android/net/wifi/ISoftApCallback.aidl @@ -55,13 +55,21 @@ oneway interface ISoftApCallback /** - * Service to manager callback providing information of softap. + * Service to manager callback providing capability of softap. * * @param capability is the softap capability. {@link SoftApCapability} */ void onCapabilityChanged(in SoftApCapability capability); /** + * Service to manager callback providing blocked client of softap with specific reason code. + * + * @param client the currently blocked client. + * @param blockedReason one of blocked reason from {@link WifiManager.SapClientBlockedReason} + */ + void onBlockedClientConnecting(in WifiClient client, int blockedReason); + + /** * Service to manager callback providing Macaddress of connected stations. * * @param Macaddr Mac Address of connected clients diff --git a/wifi/java/android/net/wifi/WifiUsabilityStatsEntry.aidl b/wifi/java/android/net/wifi/IWifiConnectedNetworkScorer.aidl index 839af54b81ba..d9a3b0109a09 100644 --- a/wifi/java/android/net/wifi/WifiUsabilityStatsEntry.aidl +++ b/wifi/java/android/net/wifi/IWifiConnectedNetworkScorer.aidl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * 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. @@ -16,4 +16,18 @@ package android.net.wifi; -parcelable WifiUsabilityStatsEntry; +import android.net.wifi.IScoreChangeCallback; + +/** + * Interface for Wi-Fi connected network scorer. + * + * @hide + */ +oneway interface IWifiConnectedNetworkScorer +{ + void start(int sessionId); + + void stop(int sessionId); + + void setScoreChangeCallback(IScoreChangeCallback cbImpl); +} diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl index ea5687531be8..fdf9ca7fa708 100644 --- a/wifi/java/android/net/wifi/IWifiManager.aidl +++ b/wifi/java/android/net/wifi/IWifiManager.aidl @@ -35,7 +35,7 @@ import android.net.wifi.ISoftApCallback; import android.net.wifi.ISuggestionConnectionStatusListener; import android.net.wifi.ITrafficStateCallback; import android.net.wifi.ITxPacketCountListener; -import android.net.wifi.ScanResult; +import android.net.wifi.IWifiConnectedNetworkScorer; import android.net.wifi.SoftApConfiguration; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; @@ -61,9 +61,9 @@ interface IWifiManager ParceledListSlice getPrivilegedConfiguredNetworks(String packageName, String featureId); - Map getAllMatchingFqdnsForScanResults(in List<ScanResult> scanResult); + Map getAllMatchingFqdnsForScanResults(in List<android.net.wifi.ScanResult> scanResult); - Map getMatchingOsuProviders(in List<ScanResult> scanResult); + Map getMatchingOsuProviders(in List<android.net.wifi.ScanResult> scanResult); Map getMatchingPasspointConfigsForOsuProviders(in List<OsuProvider> osuProviders); @@ -91,9 +91,13 @@ interface IWifiManager void allowAutojoin(int netId, boolean choice); + void allowAutojoinPasspoint(String fqdn, boolean enableAutoJoin); + + void setMacRandomizationSettingPasspointEnabled(String fqdn, boolean enable); + boolean startScan(String packageName, String featureId); - List<ScanResult> getScanResults(String callingPackage, String callingFeatureId); + List<android.net.wifi.ScanResult> getScanResults(String callingPackage, String callingFeatureId); boolean disconnect(String packageName); @@ -113,6 +117,8 @@ interface IWifiManager boolean is6GHzBandSupported(); + boolean isWifiStandardSupported(int standard); + boolean needs5GHzToAnyApBandConversion(); DhcpInfo getDhcpInfo(); @@ -278,5 +284,11 @@ interface IWifiManager int calculateSignalLevel(int rssi); + List<WifiConfiguration> getWifiConfigForMatchedNetworkSuggestionsSharedWithUser(in List<android.net.wifi.ScanResult> scanResults); + + boolean setWifiConnectedNetworkScorer(in IBinder binder, in IWifiConnectedNetworkScorer scorer); + + void clearWifiConnectedNetworkScorer(); + int getSoftApWifiGeneration(); } diff --git a/wifi/java/android/net/wifi/ScanResult.aidl b/wifi/java/android/net/wifi/ScanResult.aidl deleted file mode 100644 index bb66722e4a13..000000000000 --- a/wifi/java/android/net/wifi/ScanResult.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2008, 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; - -parcelable ScanResult; diff --git a/wifi/java/android/net/wifi/ScanResult.java b/wifi/java/android/net/wifi/ScanResult.java index af21a81e7401..3c7ccce76684 100644 --- a/wifi/java/android/net/wifi/ScanResult.java +++ b/wifi/java/android/net/wifi/ScanResult.java @@ -17,16 +17,21 @@ package android.net.wifi; import android.annotation.IntDef; +import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; +import com.android.internal.annotations.VisibleForTesting; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -82,16 +87,19 @@ public class ScanResult implements Parcelable { * @hide * No security protocol. */ + @SystemApi public static final int PROTOCOL_NONE = 0; /** * @hide * Security protocol type: WPA version 1. */ + @SystemApi public static final int PROTOCOL_WPA = 1; /** * @hide * Security protocol type: RSN, for WPA version 2, and version 3. */ + @SystemApi public static final int PROTOCOL_RSN = 2; /** * @hide @@ -99,79 +107,94 @@ public class ScanResult implements Parcelable { * OSU Server-only authenticated layer 2 Encryption Network. * Used for Hotspot 2.0. */ + @SystemApi public static final int PROTOCOL_OSEN = 3; /** * @hide * Security protocol type: WAPI. */ + @SystemApi public static final int PROTOCOL_WAPI = 4; /** * @hide * No security key management scheme. */ + @SystemApi public static final int KEY_MGMT_NONE = 0; /** * @hide * Security key management scheme: PSK. */ + @SystemApi public static final int KEY_MGMT_PSK = 1; /** * @hide * Security key management scheme: EAP. */ + @SystemApi public static final int KEY_MGMT_EAP = 2; /** * @hide * Security key management scheme: FT_PSK. */ + @SystemApi public static final int KEY_MGMT_FT_PSK = 3; /** * @hide * Security key management scheme: FT_EAP. */ + @SystemApi public static final int KEY_MGMT_FT_EAP = 4; /** * @hide * Security key management scheme: PSK_SHA256 */ + @SystemApi public static final int KEY_MGMT_PSK_SHA256 = 5; /** * @hide * Security key management scheme: EAP_SHA256. */ + @SystemApi public static final int KEY_MGMT_EAP_SHA256 = 6; /** * @hide * Security key management scheme: OSEN. * Used for Hotspot 2.0. */ + @SystemApi public static final int KEY_MGMT_OSEN = 7; /** * @hide * Security key management scheme: SAE. */ + @SystemApi public static final int KEY_MGMT_SAE = 8; /** * @hide * Security key management scheme: OWE. */ + @SystemApi public static final int KEY_MGMT_OWE = 9; /** * @hide * Security key management scheme: SUITE_B_192. */ + @SystemApi public static final int KEY_MGMT_EAP_SUITE_B_192 = 10; /** * @hide * Security key management scheme: FT_SAE. */ + @SystemApi public static final int KEY_MGMT_FT_SAE = 11; /** * @hide * Security key management scheme: OWE in transition mode. */ + @SystemApi public static final int KEY_MGMT_OWE_TRANSITION = 12; /** * @hide @@ -185,6 +208,7 @@ public class ScanResult implements Parcelable { */ @SystemApi public static final int KEY_MGMT_WAPI_CERT = 14; + /** * @hide * Security key management scheme: DPP. @@ -204,31 +228,37 @@ public class ScanResult implements Parcelable { * @hide * No cipher suite. */ + @SystemApi public static final int CIPHER_NONE = 0; /** * @hide * No group addressed, only used for group data cipher. */ + @SystemApi public static final int CIPHER_NO_GROUP_ADDRESSED = 1; /** * @hide * Cipher suite: TKIP */ + @SystemApi public static final int CIPHER_TKIP = 2; /** * @hide * Cipher suite: CCMP */ + @SystemApi public static final int CIPHER_CCMP = 3; /** * @hide * Cipher suite: GCMP */ + @SystemApi public static final int CIPHER_GCMP_256 = 4; /** * @hide * Cipher suite: SMS4 */ + @SystemApi public static final int CIPHER_SMS4 = 5; /** @@ -579,67 +609,120 @@ public class ScanResult implements Parcelable { @UnsupportedAppUsage public List<String> anqpLines; - /** information elements from beacon - * @hide + /** + * information elements from beacon. */ public static class InformationElement { + /** @hide */ @UnsupportedAppUsage public static final int EID_SSID = 0; + /** @hide */ @UnsupportedAppUsage public static final int EID_SUPPORTED_RATES = 1; + /** @hide */ @UnsupportedAppUsage public static final int EID_TIM = 5; + /** @hide */ @UnsupportedAppUsage public static final int EID_BSS_LOAD = 11; + /** @hide */ @UnsupportedAppUsage public static final int EID_ERP = 42; + /** @hide */ public static final int EID_HT_CAPABILITIES = 45; + /** @hide */ @UnsupportedAppUsage public static final int EID_RSN = 48; + /** @hide */ @UnsupportedAppUsage public static final int EID_EXTENDED_SUPPORTED_RATES = 50; + /** @hide */ @UnsupportedAppUsage public static final int EID_HT_OPERATION = 61; + /** @hide */ @UnsupportedAppUsage public static final int EID_INTERWORKING = 107; + /** @hide */ @UnsupportedAppUsage public static final int EID_ROAMING_CONSORTIUM = 111; + /** @hide */ @UnsupportedAppUsage public static final int EID_EXTENDED_CAPS = 127; + /** @hide */ public static final int EID_VHT_CAPABILITIES = 191; + /** @hide */ @UnsupportedAppUsage public static final int EID_VHT_OPERATION = 192; + /** @hide */ @UnsupportedAppUsage public static final int EID_VSA = 221; + /** @hide */ public static final int EID_EXTENSION_PRESENT = 255; - /** - * Extension IDs - */ + // Extension IDs + /** @hide */ public static final int EID_EXT_HE_CAPABILITIES = 35; + /** @hide */ public static final int EID_EXT_HE_OPERATION = 36; + /** @hide */ @UnsupportedAppUsage public int id; + /** @hide */ public int idExt; + + /** @hide */ @UnsupportedAppUsage public byte[] bytes; + /** @hide */ public InformationElement() { } - public InformationElement(InformationElement rhs) { + public InformationElement(@NonNull InformationElement rhs) { this.id = rhs.id; this.idExt = rhs.idExt; this.bytes = rhs.bytes.clone(); } + + /** + * The element ID of the information element. Defined in the IEEE 802.11-2016 spec + * Table 9-77. + */ + public int getId() { + return id; + } + + /** + * The element ID Extension of the information element. Defined in the IEEE 802.11-2016 spec + * Table 9-77. + */ + public int getIdExt() { + return idExt; + } + + /** + * Get the specific content of the information element. + */ + @NonNull + public ByteBuffer getBytes() { + return ByteBuffer.wrap(bytes).asReadOnlyBuffer(); + } } - /** information elements found in the beacon + /** + * information elements found in the beacon. * @hide */ @UnsupportedAppUsage public InformationElement[] informationElements; + /** + * Get all information elements found in the beacon. + */ + @NonNull + public List<InformationElement> getInformationElements() { + return Collections.unmodifiableList(Arrays.asList(informationElements)); + } /** ANQP response elements. * @hide @@ -765,8 +848,8 @@ public class ScanResult implements Parcelable { this.wifiSsid = wifiSsid; } - /** copy constructor {@hide} */ - public ScanResult(ScanResult source) { + /** copy constructor */ + public ScanResult(@NonNull ScanResult source) { if (source != null) { wifiSsid = source.wifiSsid; SSID = source.SSID; @@ -798,10 +881,19 @@ public class ScanResult implements Parcelable { } } - /** empty scan result + /** + * Construct an empty scan result. * - * {@hide} - * */ + * Test code has a need to construct a ScanResult in a specific state. + * (Note that mocking using Mockito does not work if the object needs to be parceled and + * unparceled.) + * Export a @SystemApi default constructor to allow tests to construct an empty ScanResult + * object. The test can then directly set the fields it cares about. + * + * @hide + */ + @SystemApi + @VisibleForTesting public ScanResult() { } @@ -923,9 +1015,8 @@ public class ScanResult implements Parcelable { } } - /** Implement the Parcelable interface {@hide} */ - @UnsupportedAppUsage - public static final @android.annotation.NonNull Creator<ScanResult> CREATOR = + /** Implement the Parcelable interface */ + public static final @NonNull Creator<ScanResult> CREATOR = new Creator<ScanResult>() { public ScanResult createFromParcel(Parcel in) { WifiSsid wifiSsid = null; diff --git a/wifi/java/android/net/wifi/SoftApCapability.aidl b/wifi/java/android/net/wifi/SoftApCapability.aidl deleted file mode 100644 index bf30709f15d1..000000000000 --- a/wifi/java/android/net/wifi/SoftApCapability.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2019, 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; - -parcelable SoftApCapability; diff --git a/wifi/java/android/net/wifi/SoftApCapability.java b/wifi/java/android/net/wifi/SoftApCapability.java index c4474e2bc9cc..2bbe7d2aa4ec 100644 --- a/wifi/java/android/net/wifi/SoftApCapability.java +++ b/wifi/java/android/net/wifi/SoftApCapability.java @@ -61,11 +61,20 @@ public final class SoftApCapability implements Parcelable { */ public static final int 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. + */ + public static final int SOFTAP_FEATURE_WPA3_SAE = 1 << 2; + /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(flag = true, prefix = { "SOFTAP_FEATURE_" }, value = { SOFTAP_FEATURE_ACS_OFFLOAD, SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT, + SOFTAP_FEATURE_WPA3_SAE, }) public @interface HotspotFeatures {} diff --git a/wifi/java/android/net/wifi/SoftApConfiguration.aidl b/wifi/java/android/net/wifi/SoftApConfiguration.aidl deleted file mode 100644 index 1d06f458318f..000000000000 --- a/wifi/java/android/net/wifi/SoftApConfiguration.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2019 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; - -parcelable SoftApConfiguration;
\ No newline at end of file diff --git a/wifi/java/android/net/wifi/SoftApConfiguration.java b/wifi/java/android/net/wifi/SoftApConfiguration.java index 800639ddefe6..22fa407957c5 100644 --- a/wifi/java/android/net/wifi/SoftApConfiguration.java +++ b/wifi/java/android/net/wifi/SoftApConfiguration.java @@ -24,15 +24,19 @@ import android.net.MacAddress; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; +import android.util.Log; +import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.Preconditions; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.nio.charset.CharsetEncoder; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import java.util.Objects; -import java.util.concurrent.Executor; /** * Configuration for a soft access point (a.k.a. Soft AP, SAP, Hotspot). @@ -41,20 +45,26 @@ import java.util.concurrent.Executor; * framework how it should configure a hotspot. * * System apps can use this to configure a tethered hotspot using - * {@link WifiManager#startTetheredHotspot(SoftApConfiguration)} and - * {@link WifiManager#setSoftApConfiguration(SoftApConfiguration)} + * {@code WifiManager#startTetheredHotspot(SoftApConfiguration)} and + * {@code WifiManager#setSoftApConfiguration(SoftApConfiguration)} * or local-only hotspot using - * {@link WifiManager#startLocalOnlyHotspot(SoftApConfiguration, Executor, + * {@code WifiManager#startLocalOnlyHotspot(SoftApConfiguration, Executor, * WifiManager.LocalOnlyHotspotCallback)}. * * Instances of this class are immutable; use {@link SoftApConfiguration.Builder} and its methods to * create a new instance. * - * @hide */ -@SystemApi public final class SoftApConfiguration implements Parcelable { + private static final String TAG = "SoftApConfiguration"; + + @VisibleForTesting + static final int PSK_MIN_LEN = 8; + + @VisibleForTesting + static final int PSK_MAX_LEN = 63; + /** * 2GHz band. * @hide @@ -142,9 +152,10 @@ public final class SoftApConfiguration implements Parcelable { private final @Nullable MacAddress mBssid; /** - * Pre-shared key for WPA2-PSK encryption (non-null enables WPA2-PSK). + * Pre-shared key for WPA2-PSK or WPA3-SAE-Transition or WPA3-SAE encryption which depends on + * the security type. */ - private final @Nullable String mWpa2Passphrase; + private final @Nullable String mPassphrase; /** * This is a network that does not broadcast its SSID, so an @@ -175,29 +186,62 @@ public final class SoftApConfiguration implements Parcelable { private final @SecurityType int mSecurityType; /** - * Security types we support. + * The flag to indicate client need to authorize by user + * when client is connecting to AP. + */ + private final boolean mClientControlByUser; + + /** + * The list of blocked client that can't associate to the AP. + */ + private final List<MacAddress> mBlockedClientList; + + /** + * The list of allowed client that can associate to the AP. + */ + private final List<MacAddress> mAllowedClientList; + + /** + * Delay in milliseconds before shutting down soft AP when + * there are no connected devices. + */ + private final int mShutdownTimeoutMillis; + + /** + * THe definition of security type OPEN. */ - /** @hide */ - @SystemApi public static final int SECURITY_TYPE_OPEN = 0; - /** @hide */ - @SystemApi + /** + * The definition of security type WPA2-PSK. + */ public static final int SECURITY_TYPE_WPA2_PSK = 1; + /** + * The definition of security type WPA3-SAE Transition mode. + */ + public static final int SECURITY_TYPE_WPA3_SAE_TRANSITION = 2; + + /** + * The definition of security type WPA3-SAE. + */ + public static final int SECURITY_TYPE_WPA3_SAE = 3; + /** @hide */ @SystemApi - public static final int SECURITY_TYPE_OWE = 2; + public static final int SECURITY_TYPE_OWE = 4; /** @hide */ @SystemApi - public static final int SECURITY_TYPE_SAE = 3; + public static final int SECURITY_TYPE_SAE = 5; /** @hide */ @Retention(RetentionPolicy.SOURCE) - @IntDef(prefix = { "SECURITY_TYPE" }, value = { + @IntDef(prefix = { "SECURITY_TYPE_" }, value = { SECURITY_TYPE_OPEN, SECURITY_TYPE_WPA2_PSK, + SECURITY_TYPE_WPA3_SAE_TRANSITION, + SECURITY_TYPE_WPA3_SAE, SECURITY_TYPE_OWE, SECURITY_TYPE_SAE, }) @@ -210,16 +254,22 @@ public final class SoftApConfiguration implements Parcelable { /** Private constructor for Builder and Parcelable implementation. */ private SoftApConfiguration(@Nullable String ssid, @Nullable MacAddress bssid, - @Nullable String wpa2Passphrase, boolean hiddenSsid, @BandType int band, int channel, - @SecurityType int securityType, int maxNumberOfClients, @Nullable String oweTransIfaceName) { + @Nullable String passphrase, boolean hiddenSsid, @BandType int band, int channel, + @SecurityType int securityType, int maxNumberOfClients, int shutdownTimeoutMillis, + boolean clientControlByUser, @NonNull List<MacAddress> blockedList, + @NonNull List<MacAddress> allowedList, @Nullable String oweTransIfaceName) { mSsid = ssid; mBssid = bssid; - mWpa2Passphrase = wpa2Passphrase; + mPassphrase = passphrase; mHiddenSsid = hiddenSsid; mBand = band; mChannel = channel; mSecurityType = securityType; mMaxNumberOfClients = maxNumberOfClients; + mShutdownTimeoutMillis = shutdownTimeoutMillis; + mClientControlByUser = clientControlByUser; + mBlockedClientList = new ArrayList<>(blockedList); + mAllowedClientList = new ArrayList<>(allowedList); mOweTransIfaceName = oweTransIfaceName; } @@ -234,19 +284,24 @@ public final class SoftApConfiguration implements Parcelable { SoftApConfiguration other = (SoftApConfiguration) otherObj; return Objects.equals(mSsid, other.mSsid) && Objects.equals(mBssid, other.mBssid) - && Objects.equals(mWpa2Passphrase, other.mWpa2Passphrase) + && Objects.equals(mPassphrase, other.mPassphrase) && mHiddenSsid == other.mHiddenSsid && mBand == other.mBand && mChannel == other.mChannel && mSecurityType == other.mSecurityType && mMaxNumberOfClients == other.mMaxNumberOfClients + && mShutdownTimeoutMillis == other.mShutdownTimeoutMillis + && mClientControlByUser == other.mClientControlByUser + && Objects.equals(mBlockedClientList, other.mBlockedClientList) + && Objects.equals(mAllowedClientList, other.mAllowedClientList) && mOweTransIfaceName == other.mOweTransIfaceName; } @Override public int hashCode() { - return Objects.hash(mSsid, mBssid, mWpa2Passphrase, mHiddenSsid, - mBand, mChannel, mSecurityType, mMaxNumberOfClients, mOweTransIfaceName); + return Objects.hash(mSsid, mBssid, mPassphrase, mHiddenSsid, + mBand, mChannel, mSecurityType, mMaxNumberOfClients, mShutdownTimeoutMillis, + mClientControlByUser, mBlockedClientList, mAllowedClientList, mOweTransIfaceName); } @Override @@ -254,13 +309,17 @@ public final class SoftApConfiguration implements Parcelable { StringBuilder sbuf = new StringBuilder(); sbuf.append("ssid=").append(mSsid); if (mBssid != null) sbuf.append(" \n bssid=").append(mBssid.toString()); - sbuf.append(" \n Wpa2Passphrase =").append( - TextUtils.isEmpty(mWpa2Passphrase) ? "<empty>" : "<non-empty>"); + 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 SecurityType=").append(getSecurityType()); sbuf.append(" \n MaxClient=").append(mMaxNumberOfClients); + sbuf.append(" \n ShutdownTimeoutMillis=").append(mShutdownTimeoutMillis); + sbuf.append(" \n ClientControlByUser=").append(mClientControlByUser); + sbuf.append(" \n BlockedClientList=").append(mBlockedClientList); + sbuf.append(" \n AllowedClientList=").append(mAllowedClientList); sbuf.append(" \n OWE Transition mode Iface =").append(mOweTransIfaceName); return sbuf.toString(); } @@ -269,12 +328,16 @@ public final class SoftApConfiguration implements Parcelable { public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeString(mSsid); dest.writeParcelable(mBssid, flags); - dest.writeString(mWpa2Passphrase); + dest.writeString(mPassphrase); dest.writeBoolean(mHiddenSsid); dest.writeInt(mBand); dest.writeInt(mChannel); dest.writeInt(mSecurityType); dest.writeInt(mMaxNumberOfClients); + dest.writeInt(mShutdownTimeoutMillis); + dest.writeBoolean(mClientControlByUser); + dest.writeTypedList(mBlockedClientList); + dest.writeTypedList(mAllowedClientList); dest.writeString(mOweTransIfaceName); } @@ -291,7 +354,9 @@ public final class SoftApConfiguration implements Parcelable { in.readString(), in.readParcelable(MacAddress.class.getClassLoader()), in.readString(), in.readBoolean(), in.readInt(), in.readInt(), in.readInt(), - in.readInt(), in.readString()); + in.readInt(), in.readInt(), in.readBoolean(), + in.createTypedArrayList(MacAddress.CREATOR), + in.createTypedArrayList(MacAddress.CREATOR), in.readString()); } @Override @@ -302,7 +367,7 @@ public final class SoftApConfiguration implements Parcelable { /** * Return String set to be the SSID for the AP. - * {@link #setSsid(String)}. + * {@link Builder#setSsid(String)}. */ @Nullable public String getSsid() { @@ -319,12 +384,12 @@ public final class SoftApConfiguration implements Parcelable { } /** - * Returns String set to be passphrase for the WPA2-PSK AP. - * {@link Builder#setWpa2Passphrase(String)}. + * Returns String set to be passphrase for current AP. + * {@link Builder#setPassphrase(String, int)}. */ @Nullable - public String getWpa2Passphrase() { - return mWpa2Passphrase; + public String getPassphrase() { + return mPassphrase; } /** @@ -339,7 +404,10 @@ public final class SoftApConfiguration implements Parcelable { /** * Returns {@link BandType} set to be the band for the AP. * {@link Builder#setBand(@BandType int)}. + * + * @hide */ + @SystemApi public @BandType int getBand() { return mBand; } @@ -347,7 +415,10 @@ public final class SoftApConfiguration implements Parcelable { /** * Returns Integer set to be the channel for the AP. * {@link Builder#setChannel(int)}. + * + * @hide */ + @SystemApi public int getChannel() { return mChannel; } @@ -355,7 +426,11 @@ public final class SoftApConfiguration implements Parcelable { /** * Get security type params which depends on which security passphrase to set. * - * @return One of the security types from {@link SecurityType}. + * @return One of: + * {@link #SECURITY_TYPE_OPEN}, + * {@link #SECURITY_TYPE_WPA2_PSK}, + * {@link #SECURITY_TYPE_WPA3_SAE_TRANSITION}, + * {@link #SECURITY_TYPE_WPA3_SAE} */ public @SecurityType int getSecurityType() { return mSecurityType; @@ -364,12 +439,116 @@ public final class SoftApConfiguration implements Parcelable { /** * Returns the maximum number of clients that can associate to the AP. * {@link Builder#setMaxNumberOfClients(int)}. + * + * @hide */ + @SystemApi public int getMaxNumberOfClients() { return mMaxNumberOfClients; } /** + * 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(int)}. + * + * @hide + */ + @SystemApi + public int getShutdownTimeoutMillis() { + return mShutdownTimeoutMillis; + } + + /** + * Returns a flag indicating whether clients need to be pre-approved by the user. + * (true: authorization required) or not (false: not required). + * {@link Builder#enableClientControlByUser(Boolean)}. + * + * @hide + */ + @SystemApi + public boolean isClientControlByUserEnabled() { + return mClientControlByUser; + } + + /** + * Returns List of clients which aren't allowed to associate to the AP. + * + * Clients are configured using {@link Builder#setClientList(List, List)} + * + * @hide + */ + @NonNull + @SystemApi + public List<MacAddress> getBlockedClientList() { + return mBlockedClientList; + } + + /** + * List of clients which are allowed to associate to the AP. + * Clients are configured using {@link Builder#setClientList(List, List)} + * + * @hide + */ + @NonNull + @SystemApi + public List<MacAddress> getAllowedClientList() { + return mAllowedClientList; + } + + /** + * Returns a {@link WifiConfiguration} representation of this {@link SoftApConfiguration}. + * Note that SoftApConfiguration may contain configuration which is cannot be represented + * by the legacy WifiConfiguration, in such cases a null will be returned. + * + * <li> SoftAp band in {@link WifiConfiguration.apBand} only supports + * 2GHz, 5GHz, 2GHz+5GHz bands, so conversion is limited to these bands. </li> + * + * <li> SoftAp security type in {@link WifiConfiguration.KeyMgmt} only supports + * NONE, WPA2_PSK, so conversion is limited to these security type.</li> + * @hide + */ + @Nullable + @SystemApi + public WifiConfiguration toWifiConfiguration() { + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.SSID = mSsid; + if (mBssid != null) { + wifiConfig.BSSID = mBssid.toString(); + } + wifiConfig.preSharedKey = mPassphrase; + wifiConfig.hiddenSSID = mHiddenSsid; + wifiConfig.apChannel = mChannel; + switch (mSecurityType) { + case SECURITY_TYPE_OPEN: + wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); + break; + case SECURITY_TYPE_WPA2_PSK: + wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK); + break; + default: + Log.e(TAG, "Convert fail, unsupported security type :" + mSecurityType); + return null; + } + + switch (mBand) { + case BAND_2GHZ: + wifiConfig.apBand = WifiConfiguration.AP_BAND_2GHZ; + break; + case BAND_5GHZ: + wifiConfig.apBand = WifiConfiguration.AP_BAND_5GHZ; + break; + case BAND_ANY: + wifiConfig.apBand = WifiConfiguration.AP_BAND_ANY; + break; + default: + Log.e(TAG, "Convert fail, unsupported band setting :" + mBand); + return null; + } + return wifiConfig; + } + + /** * Return the iface name for OWE transition mode for the AP. * {@link #setOweTransIfaceName(String)}. * @@ -386,40 +565,41 @@ public final class SoftApConfiguration implements Parcelable { * * All fields are optional. By default, SSID and BSSID are automatically chosen by the * framework, and an open network is created. + * + * @hide */ + @SystemApi public static final class Builder { private String mSsid; private MacAddress mBssid; - private String mWpa2Passphrase; + private String mPassphrase; private boolean mHiddenSsid; private int mBand; private int mChannel; private int mMaxNumberOfClients; + private int mSecurityType; + private int mShutdownTimeoutMillis; + private boolean mClientControlByUser; + private List<MacAddress> mBlockedClientList; + private List<MacAddress> mAllowedClientList; private String mOweTransIfaceName; - private int setSecurityType() { - int securityType = SECURITY_TYPE_OPEN; - if (!TextUtils.isEmpty(mWpa2Passphrase)) { // WPA2-PSK network. - securityType = SECURITY_TYPE_WPA2_PSK; - } - return securityType; - } - - private void clearAllPassphrase() { - mWpa2Passphrase = null; - } - /** * Constructs a Builder with default values (see {@link Builder}). */ public Builder() { mSsid = null; mBssid = null; - mWpa2Passphrase = null; + mPassphrase = null; mHiddenSsid = false; mBand = BAND_2GHZ; mChannel = 0; mMaxNumberOfClients = 0; + mSecurityType = SECURITY_TYPE_OPEN; + mShutdownTimeoutMillis = 0; + mClientControlByUser = false; + mBlockedClientList = new ArrayList<>(); + mAllowedClientList = new ArrayList<>(); mOweTransIfaceName = null; } @@ -431,11 +611,16 @@ public final class SoftApConfiguration implements Parcelable { mSsid = other.mSsid; mBssid = other.mBssid; - mWpa2Passphrase = other.mWpa2Passphrase; + mPassphrase = other.mPassphrase; mHiddenSsid = other.mHiddenSsid; mBand = other.mBand; mChannel = other.mChannel; mMaxNumberOfClients = other.mMaxNumberOfClients; + mSecurityType = other.mSecurityType; + mShutdownTimeoutMillis = other.mShutdownTimeoutMillis; + mClientControlByUser = other.mClientControlByUser; + mBlockedClientList = new ArrayList<>(other.mBlockedClientList); + mAllowedClientList = new ArrayList<>(other.mAllowedClientList); mOweTransIfaceName = other.mOweTransIfaceName; } @@ -446,8 +631,10 @@ public final class SoftApConfiguration implements Parcelable { */ @NonNull public SoftApConfiguration build() { - return new SoftApConfiguration(mSsid, mBssid, mWpa2Passphrase, - mHiddenSsid, mBand, mChannel, setSecurityType(), mMaxNumberOfClients, mOweTransIfaceName); + return new SoftApConfiguration(mSsid, mBssid, mPassphrase, + mHiddenSsid, mBand, mChannel, mSecurityType, mMaxNumberOfClients, + mShutdownTimeoutMillis, mClientControlByUser, mBlockedClientList, + mAllowedClientList, mOweTransIfaceName); } /** @@ -495,26 +682,43 @@ public final class SoftApConfiguration implements Parcelable { } /** - * Specifies that this AP should use WPA2-PSK with the given ASCII WPA2 passphrase. - * When set to null, an open network is created. - * <p> + * Specifies that this AP should use specific security type with the given ASCII passphrase. + * + * @param securityType one of the security types from {@link @SecurityType}. + * @param passphrase The passphrase to use for sepcific {@link @SecurityType} configuration + * or null with {@link @SecurityType#SECURITY_TYPE_OPEN}. * - * @param passphrase The passphrase to use, or null to unset a previously-set WPA2-PSK - * configuration. * @return Builder for chaining. - * @throws IllegalArgumentException when the passphrase is the empty string + * @throws IllegalArgumentException when the passphrase length is invalid and + * {@code securityType} is not {@link @SecurityType#SECURITY_TYPE_OPEN} + * or non-null passphrase and {@code securityType} is + * {@link @SecurityType#SECURITY_TYPE_OPEN}. */ @NonNull - public Builder setWpa2Passphrase(@Nullable String passphrase) { - if (passphrase != null) { + public Builder setPassphrase(@Nullable String passphrase, @SecurityType int securityType) { + if (securityType == SECURITY_TYPE_OPEN) { + if (passphrase != null) { + throw new IllegalArgumentException( + "passphrase should be null when security type is open"); + } + } else { + Preconditions.checkStringNotEmpty(passphrase); final CharsetEncoder asciiEncoder = StandardCharsets.US_ASCII.newEncoder(); if (!asciiEncoder.canEncode(passphrase)) { throw new IllegalArgumentException("passphrase not ASCII encodable"); } - Preconditions.checkStringNotEmpty(passphrase); + if (securityType == SECURITY_TYPE_WPA2_PSK + || securityType == SECURITY_TYPE_WPA3_SAE_TRANSITION) { + if (passphrase.length() < PSK_MIN_LEN || passphrase.length() > PSK_MAX_LEN) { + throw new IllegalArgumentException( + "Password size must be at least " + PSK_MIN_LEN + + " and no more than " + PSK_MAX_LEN + + " for WPA2_PSK and WPA3_SAE_TRANSITION Mode"); + } + } } - clearAllPassphrase(); - mWpa2Passphrase = passphrase; + mSecurityType = securityType; + mPassphrase = passphrase; return this; } @@ -624,6 +828,108 @@ public final class SoftApConfiguration implements Parcelable { } /** + * Specifies the shutdown timeout in milliseconds. + * The Soft AP will shut down when there are no devices connected to it for + * the timeout duration. + * + * Specify a value of 0 to have the framework automatically use default timeout + * setting which defined in {@link R.integer.config_wifi_framework_soft_ap_timeout_delay} + * + * <p> + * <li>If not set, defaults to 0</li> + * <li>The shut down timout will apply when + * {@link Settings.Global.SOFT_AP_TIMEOUT_ENABLED} is true</li> + * + * @param timeoutMillis milliseconds of the timeout delay. + * @return Builder for chaining. + */ + @NonNull + public Builder setShutdownTimeoutMillis(int timeoutMillis) { + if (timeoutMillis < 0) { + throw new IllegalArgumentException("Invalid timeout value"); + } + mShutdownTimeoutMillis = timeoutMillis; + return this; + } + + /** + * Configure the Soft AP to require manual user control of client association. + * If disabled (the default) then any client can associate to this Soft AP using the + * correct credentials until the Soft AP capacity is reached (capacity is hardware, carrier, + * or user limited - using {@link #setMaxNumberOfClients(int)}). + * + * If manual user control is enabled then clients will be accepted, rejected, or require + * a user approval based on the configuration provided by + * {@link #setClientList(List, List)}. + * + * <p> + * This method requires hardware support. Hardware support can be determined using + * {@link WifiManager.SoftApCallback#onCapabilityChanged(SoftApCapability)} and + * {@link SoftApCapability#isFeatureSupported(int)} + * 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 + * using {@link WifiManager#startTetheredHotspot(SoftApConfiguration)} will fail with + * {@link WifiManager#SAP_START_FAILURE_UNSUPPORTED_CONFIGURATION}. + * + * <p> + * <li>If not set, defaults to false (i.e The authoriztion is not required).</li> + * + * @param enabled true for enabling the control by user, false otherwise. + * @return Builder for chaining. + */ + @NonNull + public Builder enableClientControlByUser(boolean enabled) { + mClientControlByUser = enabled; + return this; + } + + + /** + * This method together with {@link enableClientControlByUser(boolean)} control client + * connections to the AP. If {@link enableClientControlByUser(false)} is configured than + * this API has no effect and clients are allowed to associate to the AP (within limit of + * max number of clients). + * + * If {@link enableClientControlByUser(true)} is configured then this API configures + * 2 lists: + * <ul> + * <li>List of clients which are blocked. These are rejected.</li> + * <li>List of clients which are explicitly allowed. These are auto-accepted.</li> + * </ul> + * + * <p> + * All other clients which attempt to associate, whose MAC addresses are on neither list, + * are: + * <ul> + * <li>Rejected</li> + * <li>A callback {@link WifiManager.SoftApCallback#onBlockedClientConnecting(WifiClient)} + * is issued (which allows the user to add them to the allowed client list if desired).<li> + * </ul> + * + * @param blockedClientList list of clients which are not allowed to associate to the AP. + * @param allowedClientList list of clients which are allowed to associate to the AP + * without user pre-approval. + * @return Builder for chaining. + */ + @NonNull + public Builder setClientList(@NonNull List<MacAddress> blockedClientList, + @NonNull List<MacAddress> allowedClientList) { + mBlockedClientList = new ArrayList<>(blockedClientList); + mAllowedClientList = new ArrayList<>(allowedClientList); + Iterator<MacAddress> iterator = mAllowedClientList.iterator(); + while (iterator.hasNext()) { + MacAddress client = iterator.next(); + int index = mBlockedClientList.indexOf(client); + if (index != -1) { + throw new IllegalArgumentException("A MacAddress exist in both list"); + } + } + return this; + } + + /** * Specifies an iface name for OWE transition mode for the AP. * <p> * <li>If not set, defaults to null.</li> diff --git a/wifi/java/android/net/wifi/SoftApInfo.aidl b/wifi/java/android/net/wifi/SoftApInfo.aidl deleted file mode 100644 index d4551cfac044..000000000000 --- a/wifi/java/android/net/wifi/SoftApInfo.aidl +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) 2019, 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; - -parcelable SoftApInfo; - diff --git a/wifi/java/android/net/wifi/WifiAnnotations.java b/wifi/java/android/net/wifi/WifiAnnotations.java index 9223d28836b6..05e5b1d45684 100644 --- a/wifi/java/android/net/wifi/WifiAnnotations.java +++ b/wifi/java/android/net/wifi/WifiAnnotations.java @@ -60,4 +60,45 @@ public final class WifiAnnotations { }) @Retention(RetentionPolicy.SOURCE) public @interface Bandwidth {} + + @IntDef(prefix = { "PROTOCOL_" }, value = { + ScanResult.PROTOCOL_NONE, + ScanResult.PROTOCOL_WPA, + ScanResult.PROTOCOL_RSN, + ScanResult.PROTOCOL_OSEN, + ScanResult.PROTOCOL_WAPI + }) + @Retention(RetentionPolicy.SOURCE) + public @interface Protocol {} + + @IntDef(prefix = { "KEY_MGMT_" }, value = { + ScanResult.KEY_MGMT_NONE, + ScanResult.KEY_MGMT_PSK, + ScanResult.KEY_MGMT_EAP, + ScanResult.KEY_MGMT_FT_PSK, + ScanResult.KEY_MGMT_FT_EAP, + ScanResult.KEY_MGMT_PSK_SHA256, + ScanResult.KEY_MGMT_EAP_SHA256, + ScanResult.KEY_MGMT_OSEN, + ScanResult.KEY_MGMT_SAE, + ScanResult.KEY_MGMT_OWE, + ScanResult.KEY_MGMT_EAP_SUITE_B_192, + ScanResult.KEY_MGMT_FT_SAE, + ScanResult.KEY_MGMT_OWE_TRANSITION, + ScanResult.KEY_MGMT_WAPI_PSK, + ScanResult.KEY_MGMT_WAPI_CERT + }) + @Retention(RetentionPolicy.SOURCE) + public @interface KeyMgmt {} + + @IntDef(prefix = { "CIPHER_" }, value = { + ScanResult.CIPHER_NONE, + ScanResult.CIPHER_NO_GROUP_ADDRESSED, + ScanResult.CIPHER_TKIP, + ScanResult.CIPHER_CCMP, + ScanResult.CIPHER_GCMP_256, + ScanResult.CIPHER_SMS4 + }) + @Retention(RetentionPolicy.SOURCE) + public @interface Cipher {} } diff --git a/wifi/java/android/net/wifi/WifiConfiguration.aidl b/wifi/java/android/net/wifi/WifiConfiguration.aidl deleted file mode 100644 index 237a74da3052..000000000000 --- a/wifi/java/android/net/wifi/WifiConfiguration.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2008, 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; - -parcelable WifiConfiguration; diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java index 9d0288c9c9e0..a77440963c53 100644 --- a/wifi/java/android/net/wifi/WifiConfiguration.java +++ b/wifi/java/android/net/wifi/WifiConfiguration.java @@ -20,7 +20,7 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.content.pm.PackageManager; import android.net.IpConfiguration; import android.net.IpConfiguration.ProxySettings; @@ -29,6 +29,7 @@ import android.net.NetworkSpecifier; import android.net.ProxyInfo; import android.net.StaticIpConfiguration; import android.net.Uri; +import android.net.util.MacAddressUtils; import android.os.Build; import android.os.Parcel; import android.os.Parcelable; @@ -39,6 +40,8 @@ import android.text.TextUtils; import android.util.Log; import android.util.SparseArray; +import com.android.internal.annotations.VisibleForTesting; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Arrays; @@ -272,9 +275,12 @@ public class WifiConfiguration implements Parcelable { /** LEAP/Network EAP (only used with LEAP) */ public static final int LEAP = 2; + /** SAE (Used only for WPA3-Personal) */ + public static final int SAE = 3; + public static final String varName = "auth_alg"; - public static final String[] strings = { "OPEN", "SHARED", "LEAP" }; + public static final String[] strings = { "OPEN", "SHARED", "LEAP", "SAE" }; } /** @@ -386,7 +392,6 @@ public class WifiConfiguration implements Parcelable { * ECDHE_ECDSA * ECDHE_RSA * </pre> - * @hide */ public static class SuiteBCipher { private SuiteBCipher() { } @@ -416,33 +421,33 @@ public class WifiConfiguration implements Parcelable { public static final String[] strings = { "current", "disabled", "enabled" }; } - /** - * Security types we support. - */ - /** @hide */ + /** Security type for an open network. */ public static final int SECURITY_TYPE_OPEN = 0; - /** @hide */ + /** Security type for a WEP network. */ public static final int SECURITY_TYPE_WEP = 1; - /** @hide */ + /** Security type for a PSK network. */ public static final int SECURITY_TYPE_PSK = 2; - /** @hide */ + /** Security type for an EAP network. */ public static final int SECURITY_TYPE_EAP = 3; - /** @hide */ + /** Security type for an SAE network. */ public static final int SECURITY_TYPE_SAE = 4; - /** @hide */ + /** Security type for an EAP Suite B network. */ public static final int SECURITY_TYPE_EAP_SUITE_B = 5; - /** @hide */ + /** Security type for an OWE network. */ public static final int SECURITY_TYPE_OWE = 6; - /** @hide */ + /** Security type for a WAPI PSK network. */ public static final int SECURITY_TYPE_WAPI_PSK = 7; - /** @hide */ + /** Security type for a WAPI Certificate network. */ public static final int SECURITY_TYPE_WAPI_CERT = 8; /** @hide */ public static final int SECURITY_TYPE_FILS_SHA256 = 9; /** @hide */ public static final int SECURITY_TYPE_FILS_SHA384 = 10; - /** @hide */ + /** + * Security types we support. + * @hide + */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = { "SECURITY_TYPE_" }, value = { SECURITY_TYPE_OPEN, @@ -460,10 +465,19 @@ public class WifiConfiguration implements Parcelable { public @interface SecurityType {} /** - * @hide - * Set security params (sets the various bitsets exposed in WifiConfiguration). + * Set the various security params to correspond to the provided security type. + * This is accomplished by setting the various BitSets exposed in WifiConfiguration. * - * @param securityType One of the security types from {@link SecurityType}. + * @param securityType One of the following security types: + * {@link #SECURITY_TYPE_OPEN}, + * {@link #SECURITY_TYPE_WEP}, + * {@link #SECURITY_TYPE_PSK}, + * {@link #SECURITY_TYPE_EAP}, + * {@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} */ public void setSecurityParams(@SecurityType int securityType) { // Clear all the bitsets. @@ -493,10 +507,13 @@ public class WifiConfiguration implements Parcelable { break; case SECURITY_TYPE_SAE: allowedKeyManagement.set(WifiConfiguration.KeyMgmt.SAE); + allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); + allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); requirePMF = true; break; case SECURITY_TYPE_EAP_SUITE_B: allowedKeyManagement.set(WifiConfiguration.KeyMgmt.SUITE_B_192); + allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.GCMP_256); allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GCMP_256); allowedGroupManagementCiphers.set(WifiConfiguration.GroupMgmtCipher.BIP_GMAC_256); // Note: allowedSuiteBCiphers bitset will be set by the service once the @@ -505,6 +522,8 @@ public class WifiConfiguration implements Parcelable { break; case SECURITY_TYPE_OWE: allowedKeyManagement.set(WifiConfiguration.KeyMgmt.OWE); + allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); + allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); requirePMF = true; break; case SECURITY_TYPE_WAPI_PSK: @@ -895,18 +914,6 @@ public class WifiConfiguration implements Parcelable { /** * @hide - * For debug: date at which the config was last updated - */ - public String updateTime; - - /** - * @hide - * For debug: date at which the config was last updated - */ - public String creationTime; - - /** - * @hide * The WiFi configuration is considered to have no internet access for purpose of autojoining * if there has been a report of it having no internet access, and, it never have had * internet access in the past. @@ -989,8 +996,10 @@ public class WifiConfiguration implements Parcelable { } /** - * Indicate whther the network is trusted or not. Networks are considered trusted + * Indicate whether the network is trusted or not. Networks are considered trusted * if the user explicitly allowed this network connection. + * This bit can be used by suggestion network, see + * {@link WifiNetworkSuggestion.Builder#setUnTrusted(boolean)} * @hide */ public boolean trusted; @@ -1205,7 +1214,7 @@ public class WifiConfiguration implements Parcelable { * @return true if mac is good to use */ public static boolean isValidMacAddressForRandomization(MacAddress mac) { - return mac != null && !mac.isMulticastAddress() && mac.isLocallyAssigned() + return mac != null && !MacAddressUtils.isMulticastAddress(mac) && mac.isLocallyAssigned() && !MacAddress.fromString(WifiInfo.DEFAULT_MAC_ADDRESS).equals(mac); } @@ -1272,22 +1281,27 @@ public class WifiConfiguration implements Parcelable { */ @SystemApi public static class NetworkSelectionStatus { - // Quality Network Selection Status enable, temporary disabled, permanently disabled + /** @hide */ + @Retention(RetentionPolicy.SOURCE) + @IntDef(prefix = "NETWORK_SELECTION_", + value = { + NETWORK_SELECTION_ENABLED, + NETWORK_SELECTION_TEMPORARY_DISABLED, + NETWORK_SELECTION_PERMANENTLY_DISABLED}) + public @interface NetworkEnabledStatus {} /** - * This network is allowed to join Quality Network Selection - * @hide + * This network will be considered as a potential candidate to connect to during network + * selection. */ public static final int NETWORK_SELECTION_ENABLED = 0; /** - * network was temporary disabled. Can be re-enabled after a time period expire - * @hide + * This network was temporary disabled. May be re-enabled after a time out. */ - public static final int NETWORK_SELECTION_TEMPORARY_DISABLED = 1; + public static final int NETWORK_SELECTION_TEMPORARY_DISABLED = 1; /** - * network was permanently disabled. - * @hide + * This network was permanently disabled. */ - public static final int NETWORK_SELECTION_PERMANENTLY_DISABLED = 2; + public static final int NETWORK_SELECTION_PERMANENTLY_DISABLED = 2; /** * Maximum Network selection status * @hide @@ -1519,6 +1533,7 @@ public class WifiConfiguration implements Parcelable { * Network selection status, should be in one of three status: enable, temporaily disabled * or permanently disabled */ + @NetworkEnabledStatus private int mStatus; /** @@ -1549,12 +1564,6 @@ public class WifiConfiguration implements Parcelable { private String mConnectChoice; /** - * The system timestamp when we records the connectChoice. This value is obtained from - * System.currentTimeMillis - */ - private long mConnectChoiceTimestamp = INVALID_NETWORK_SELECTION_DISABLE_TIMESTAMP; - - /** * Used to cache the temporary candidate during the network selection procedure. It will be * kept updating once a new scan result has a higher score than current one */ @@ -1657,25 +1666,6 @@ public class WifiConfiguration implements Parcelable { mConnectChoice = newConnectChoice; } - /** - * get the timeStamp when user select a choice over this configuration - * @return returns when current connectChoice is set (time from System.currentTimeMillis) - * @hide - */ - public long getConnectChoiceTimestamp() { - return mConnectChoiceTimestamp; - } - - /** - * set the timeStamp when user select a choice over this configuration - * @param timeStamp, the timestamp set to connectChoiceTimestamp, expected timestamp should - * be obtained from System.currentTimeMillis - * @hide - */ - public void setConnectChoiceTimestamp(long timeStamp) { - mConnectChoiceTimestamp = timeStamp; - } - /** Get the current Quality network selection status as a String (for debugging). */ @NonNull public String getNetworkStatusString() { @@ -1699,6 +1689,58 @@ public class WifiConfiguration implements Parcelable { } /** + * NetworkSelectionStatus exports an immutable public API. + * However, test code has a need to construct a NetworkSelectionStatus in a specific state. + * (Note that mocking using Mockito does not work if the object needs to be parceled and + * unparceled.) + * Export a @SystemApi Builder to allow tests to construct a NetworkSelectionStatus object + * in the desired state, without sacrificing NetworkSelectionStatus's immutability. + */ + @VisibleForTesting + public static final class Builder { + private final NetworkSelectionStatus mNetworkSelectionStatus = + new NetworkSelectionStatus(); + + /** + * Set the current network selection status. + * One of: + * {@link #NETWORK_SELECTION_ENABLED}, + * {@link #NETWORK_SELECTION_TEMPORARY_DISABLED}, + * {@link #NETWORK_SELECTION_PERMANENTLY_DISABLED} + * @see NetworkSelectionStatus#getNetworkSelectionStatus() + */ + @NonNull + public Builder setNetworkSelectionStatus(@NetworkEnabledStatus int status) { + mNetworkSelectionStatus.setNetworkSelectionStatus(status); + return this; + } + + /** + * + * Set the current network's disable reason. + * One of the {@link #NETWORK_SELECTION_ENABLE} or DISABLED_* constants. + * e.g. {@link #DISABLED_ASSOCIATION_REJECTION}. + * @see NetworkSelectionStatus#getNetworkSelectionDisableReason() + */ + @NonNull + public Builder setNetworkSelectionDisableReason( + @NetworkSelectionDisableReason int reason) { + mNetworkSelectionStatus.setNetworkSelectionDisableReason(reason); + return this; + } + + /** + * Build a NetworkSelectionStatus object. + */ + @NonNull + public NetworkSelectionStatus build() { + NetworkSelectionStatus status = new NetworkSelectionStatus(); + status.copy(mNetworkSelectionStatus); + return status; + } + } + + /** * Get the network disable reason string for a reason code (for debugging). * @param reason specific error reason. One of the {@link #NETWORK_SELECTION_ENABLE} or * DISABLED_* constants e.g. {@link #DISABLED_ASSOCIATION_REJECTION}. @@ -1724,10 +1766,13 @@ public class WifiConfiguration implements Parcelable { } /** - * get current network network selection status - * @return return current network network selection status - * @hide + * Get the current network network selection status. + * One of: + * {@link #NETWORK_SELECTION_ENABLED}, + * {@link #NETWORK_SELECTION_TEMPORARY_DISABLED}, + * {@link #NETWORK_SELECTION_PERMANENTLY_DISABLED} */ + @NetworkEnabledStatus public int getNetworkSelectionStatus() { return mStatus; } @@ -1905,7 +1950,6 @@ public class WifiConfiguration implements Parcelable { setCandidate(source.getCandidate()); setCandidateScore(source.getCandidateScore()); setConnectChoice(source.getConnectChoice()); - setConnectChoiceTimestamp(source.getConnectChoiceTimestamp()); setHasEverConnected(source.getHasEverConnected()); } @@ -1922,7 +1966,6 @@ public class WifiConfiguration implements Parcelable { if (getConnectChoice() != null) { dest.writeInt(CONNECT_CHOICE_EXISTS); dest.writeString(getConnectChoice()); - dest.writeLong(getConnectChoiceTimestamp()); } else { dest.writeInt(CONNECT_CHOICE_NOT_EXISTS); } @@ -1941,10 +1984,8 @@ public class WifiConfiguration implements Parcelable { setNetworkSelectionBSSID(in.readString()); if (in.readInt() == CONNECT_CHOICE_EXISTS) { setConnectChoice(in.readString()); - setConnectChoiceTimestamp(in.readLong()); } else { setConnectChoice(null); - setConnectChoiceTimestamp(INVALID_NETWORK_SELECTION_DISABLE_TIMESTAMP); } setHasEverConnected(in.readInt() != 0); } @@ -2029,10 +2070,11 @@ public class WifiConfiguration implements Parcelable { } /** - * Set the network selection status + * Set the network selection status. * @hide */ - public void setNetworkSelectionStatus(NetworkSelectionStatus status) { + @SystemApi + public void setNetworkSelectionStatus(@NonNull NetworkSelectionStatus status) { mNetworkSelectionStatus = status; } @@ -2172,9 +2214,6 @@ public class WifiConfiguration implements Parcelable { } if (mNetworkSelectionStatus.getConnectChoice() != null) { sbuf.append(" connect choice: ").append(mNetworkSelectionStatus.getConnectChoice()); - sbuf.append(" connect choice set time: ") - .append(logTimeOfDay( - mNetworkSelectionStatus.getConnectChoiceTimestamp())); } sbuf.append(" hasEverConnected: ") .append(mNetworkSelectionStatus.getHasEverConnected()).append("\n"); @@ -2186,12 +2225,6 @@ public class WifiConfiguration implements Parcelable { sbuf.append(" numNoInternetAccessReports "); sbuf.append(this.numNoInternetAccessReports).append("\n"); } - if (this.updateTime != null) { - sbuf.append(" update ").append(this.updateTime).append("\n"); - } - if (this.creationTime != null) { - sbuf.append(" creation ").append(this.creationTime).append("\n"); - } if (this.validatedInternetAccess) sbuf.append(" validatedInternetAccess"); if (this.ephemeral) sbuf.append(" ephemeral"); if (this.osu) sbuf.append(" osu"); @@ -2521,7 +2554,8 @@ public class WifiConfiguration implements Parcelable { } else if (allowedKeyManagement.get(KeyMgmt.WPA_EAP) || allowedKeyManagement.get(KeyMgmt.IEEE8021X)) { key = SSID + KeyMgmt.strings[KeyMgmt.WPA_EAP]; - } else if (wepKeys[0] != null) { + } else if (wepTxKeyIndex >= 0 && wepTxKeyIndex < wepKeys.length + && wepKeys[wepTxKeyIndex] != null) { key = SSID + "WEP"; } else if (allowedKeyManagement.get(KeyMgmt.OWE)) { key = SSID + KeyMgmt.strings[KeyMgmt.OWE]; @@ -2685,9 +2719,8 @@ public class WifiConfiguration implements Parcelable { return mPasspointManagementObjectTree; } - /** copy constructor {@hide} */ - @UnsupportedAppUsage - public WifiConfiguration(WifiConfiguration source) { + /** Copy constructor */ + public WifiConfiguration(@NonNull WifiConfiguration source) { if (source != null) { networkId = source.networkId; status = source.status; @@ -2757,8 +2790,6 @@ public class WifiConfiguration implements Parcelable { allowAutojoin = source.allowAutojoin; numNoInternetAccessReports = source.numNoInternetAccessReports; noInternetAccessExpected = source.noInternetAccessExpected; - creationTime = source.creationTime; - updateTime = source.updateTime; shared = source.shared; recentFailure.setAssociationStatus(source.recentFailure.getAssociationStatus()); mRandomizedMacAddress = source.mRandomizedMacAddress; diff --git a/wifi/java/android/net/wifi/WifiEnterpriseConfig.aidl b/wifi/java/android/net/wifi/WifiEnterpriseConfig.aidl deleted file mode 100644 index b0f5f849c7ec..000000000000 --- a/wifi/java/android/net/wifi/WifiEnterpriseConfig.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2013, 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; - -parcelable WifiEnterpriseConfig; diff --git a/wifi/java/android/net/wifi/WifiEnterpriseConfig.java b/wifi/java/android/net/wifi/WifiEnterpriseConfig.java index c2888d06f39c..abcd6c0a7e97 100644 --- a/wifi/java/android/net/wifi/WifiEnterpriseConfig.java +++ b/wifi/java/android/net/wifi/WifiEnterpriseConfig.java @@ -19,7 +19,7 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; @@ -1042,8 +1042,10 @@ public class WifiEnterpriseConfig implements Parcelable { } /** - * @hide + * Get the client private key as supplied in {@link #setClientKeyEntryWithCertificateChain}, or + * null if unset. */ + @Nullable public PrivateKey getClientPrivateKey() { return mClientPrivateKey; } @@ -1350,20 +1352,18 @@ public class WifiEnterpriseConfig implements Parcelable { } /** - * If the current authentication method needs SIM card. - * @return true if the credential information require SIM card for current authentication + * Utility method to determine whether the configuration's authentication method is SIM-based. + * + * @return true if the credential information requires SIM card for current authentication * method, otherwise it returns false. - * @hide */ - public boolean requireSimCredential() { + public boolean isAuthenticationSimBased() { if (mEapMethod == Eap.SIM || mEapMethod == Eap.AKA || mEapMethod == Eap.AKA_PRIME) { return true; } if (mEapMethod == Eap.PEAP) { - if (mPhase2Method == Phase2.SIM || mPhase2Method == Phase2.AKA - || mPhase2Method == Phase2.AKA_PRIME) { - return true; - } + return mPhase2Method == Phase2.SIM || mPhase2Method == Phase2.AKA + || mPhase2Method == Phase2.AKA_PRIME; } return false; } diff --git a/wifi/java/android/net/wifi/WifiInfo.aidl b/wifi/java/android/net/wifi/WifiInfo.aidl deleted file mode 100644 index db47f0b5aa31..000000000000 --- a/wifi/java/android/net/wifi/WifiInfo.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2008, 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; - -parcelable WifiInfo; diff --git a/wifi/java/android/net/wifi/WifiInfo.java b/wifi/java/android/net/wifi/WifiInfo.java index c0ec8e9ded32..dc4c86284fe0 100644 --- a/wifi/java/android/net/wifi/WifiInfo.java +++ b/wifi/java/android/net/wifi/WifiInfo.java @@ -17,9 +17,10 @@ package android.net.wifi; import android.annotation.IntRange; +import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.net.NetworkInfo.DetailedState; import android.net.shared.Inet4AddressUtils; import android.os.Build; @@ -27,6 +28,8 @@ import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; +import com.android.internal.annotations.VisibleForTesting; + import java.net.Inet4Address; import java.net.InetAddress; import java.net.UnknownHostException; @@ -121,11 +124,21 @@ public class WifiInfo implements Parcelable { private int mTxLinkSpeed; /** + * Max supported Tx(transmit) link speed in Mbps + */ + private int mMaxSupportedTxLinkSpeed; + + /** * Rx(receive) Link speed in Mbps */ private int mRxLinkSpeed; /** + * Max supported Rx(receive) link speed in Mbps + */ + private int mMaxSupportedRxLinkSpeed; + + /** * Frequency in MHz */ public static final String FREQUENCY_UNITS = "MHz"; @@ -309,6 +322,8 @@ public class WifiInfo implements Parcelable { setLinkSpeed(LINK_SPEED_UNKNOWN); setTxLinkSpeedMbps(LINK_SPEED_UNKNOWN); setRxLinkSpeedMbps(LINK_SPEED_UNKNOWN); + setMaxSupportedTxLinkSpeedMbps(LINK_SPEED_UNKNOWN); + setMaxSupportedRxLinkSpeedMbps(LINK_SPEED_UNKNOWN); setFrequency(-1); setMeteredHint(false); setEphemeral(false); @@ -368,6 +383,74 @@ public class WifiInfo implements Parcelable { mRxSuccessRate = source.mRxSuccessRate; score = source.score; mWifiStandard = source.mWifiStandard; + mMaxSupportedTxLinkSpeed = source.mMaxSupportedTxLinkSpeed; + mMaxSupportedRxLinkSpeed = source.mMaxSupportedRxLinkSpeed; + } + } + + /** + * WifiInfo exports an immutable public API. + * However, test code has a need to construct a WifiInfo in a specific state. + * (Note that mocking using Mockito does not work if the object needs to be parceled and + * unparceled.) + * Export a @SystemApi Builder to allow tests to construct a WifiInfo object + * in the desired state, without sacrificing WifiInfo's immutability. + * + * @hide + */ + // This builder was not made public to reduce confusion for external developers as there are + // no legitimate uses for this builder except for testing. + @SystemApi + @VisibleForTesting + public static final class Builder { + private final WifiInfo mWifiInfo = new WifiInfo(); + + /** + * Set the SSID, in the form of a raw byte array. + * @see WifiInfo#getSSID() + */ + @NonNull + public Builder setSsid(@NonNull byte[] ssid) { + mWifiInfo.setSSID(WifiSsid.createFromByteArray(ssid)); + return this; + } + + /** + * Set the BSSID. + * @see WifiInfo#getBSSID() + */ + @NonNull + public Builder setBssid(@NonNull String bssid) { + mWifiInfo.setBSSID(bssid); + return this; + } + + /** + * Set the RSSI, in dBm. + * @see WifiInfo#getRssi() + */ + @NonNull + public Builder setRssi(int rssi) { + mWifiInfo.setRssi(rssi); + return this; + } + + /** + * Set the network ID. + * @see WifiInfo#getNetworkId() + */ + @NonNull + public Builder setNetworkId(int networkId) { + mWifiInfo.setNetworkId(networkId); + return this; + } + + /** + * Build a WifiInfo object. + */ + @NonNull + public WifiInfo build() { + return new WifiInfo(mWifiInfo); } } @@ -498,6 +581,15 @@ public class WifiInfo implements Parcelable { } /** + * Returns the maximum supported transmit link speed in Mbps + * @return the max supported tx link speed or {@link #LINK_SPEED_UNKNOWN} if link speed is + * unknown. @see #LINK_SPEED_UNKNOWN + */ + public int getMaxSupportedTxLinkSpeedMbps() { + return mMaxSupportedTxLinkSpeed; + } + + /** * Update the last transmitted packet bit rate in Mbps. * @hide */ @@ -506,6 +598,14 @@ public class WifiInfo implements Parcelable { } /** + * Set the maximum supported transmit link speed in Mbps + * @hide + */ + public void setMaxSupportedTxLinkSpeedMbps(int maxSupportedTxLinkSpeed) { + mMaxSupportedTxLinkSpeed = maxSupportedTxLinkSpeed; + } + + /** * Returns the current receive link speed in Mbps. * @return the Rx link speed or {@link #LINK_SPEED_UNKNOWN} if link speed is unknown. * @see #LINK_SPEED_UNKNOWN @@ -516,6 +616,15 @@ public class WifiInfo implements Parcelable { } /** + * Returns the maximum supported receive link speed in Mbps + * @return the max supported Rx link speed or {@link #LINK_SPEED_UNKNOWN} if link speed is + * unknown. @see #LINK_SPEED_UNKNOWN + */ + public int getMaxSupportedRxLinkSpeedMbps() { + return mMaxSupportedRxLinkSpeed; + } + + /** * Update the last received packet bit rate in Mbps. * @hide */ @@ -524,6 +633,14 @@ public class WifiInfo implements Parcelable { } /** + * Set the maximum supported receive link speed in Mbps + * @hide + */ + public void setMaxSupportedRxLinkSpeedMbps(int maxSupportedRxLinkSpeed) { + mMaxSupportedRxLinkSpeed = maxSupportedRxLinkSpeed; + } + + /** * Returns the current frequency in {@link #FREQUENCY_UNITS}. * @return the frequency. * @see #FREQUENCY_UNITS @@ -646,6 +763,11 @@ public class WifiInfo implements Parcelable { /** * Returns the Fully Qualified Domain Name of the network if it is a Passpoint network. + * <p> + * The FQDN may be + * <lt>{@code null} if no network currently connected, currently connected network is not + * passpoint network or the caller has insufficient permissions to access the FQDN.</lt> + * </p> */ public @Nullable String getPasspointFqdn() { return mFqdn; @@ -658,6 +780,12 @@ public class WifiInfo implements Parcelable { /** * Returns the Provider Friendly Name of the network if it is a Passpoint network. + * <p> + * The Provider Friendly Name may be + * <lt>{@code null} if no network currently connected, currently connected network is not + * passpoint network or the caller has insufficient permissions to access the Provider Friendly + * Name. </lt> + * </p> */ public @Nullable String getPasspointProviderFriendlyName() { return mProviderFriendlyName; @@ -832,7 +960,11 @@ public class WifiInfo implements Parcelable { .append(", RSSI: ").append(mRssi) .append(", Link speed: ").append(mLinkSpeed).append(LINK_SPEED_UNITS) .append(", Tx Link speed: ").append(mTxLinkSpeed).append(LINK_SPEED_UNITS) + .append(", Max Supported Tx Link speed: ") + .append(mMaxSupportedTxLinkSpeed).append(LINK_SPEED_UNITS) .append(", Rx Link speed: ").append(mRxLinkSpeed).append(LINK_SPEED_UNITS) + .append(", Max Supported Rx Link speed: ") + .append(mMaxSupportedRxLinkSpeed).append(LINK_SPEED_UNITS) .append(", Frequency: ").append(mFrequency).append(FREQUENCY_UNITS) .append(", Net ID: ").append(mNetworkId) .append(", Metered hint: ").append(mMeteredHint) @@ -888,6 +1020,8 @@ public class WifiInfo implements Parcelable { dest.writeInt(mVhtMax8SpatialStreamsSupport ? 1 : 0); dest.writeInt(mTwtSupport ? 1 : 0); dest.writeInt(mWifiStandard); + dest.writeInt(mMaxSupportedTxLinkSpeed); + dest.writeInt(mMaxSupportedRxLinkSpeed); } /** Implement the Parcelable interface {@hide} */ @@ -933,6 +1067,8 @@ public class WifiInfo implements Parcelable { info.mVhtMax8SpatialStreamsSupport = in.readInt() != 0; info.mTwtSupport = in.readInt() != 0; info.mWifiStandard = in.readInt(); + info.mMaxSupportedTxLinkSpeed = in.readInt(); + info.mMaxSupportedRxLinkSpeed = in.readInt(); return info; } diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index 4677a02b210c..0b5df0598cf8 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -29,8 +29,8 @@ import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SystemApi; import android.annotation.SystemService; -import android.annotation.UnsupportedAppUsage; import android.app.ActivityManager; +import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.pm.ParceledListSlice; import android.net.ConnectivityManager; @@ -193,6 +193,21 @@ public class WifiManager { */ public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID = 5; + /** + * Reason code if one or more of the network suggestions added is not allowed. + * + * This error may be caused by suggestion is using SIM-based encryption method, but calling app + * is not carrier privileged. + */ + public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_NOT_ALLOWED = 6; + + /** + * Reason code if one or more of the network suggestions added is invalid. + * + * Please user {@link WifiNetworkSuggestion.Builder} to create network suggestions. + */ + public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_INVALID = 7; + /** @hide */ @IntDef(prefix = { "STATUS_NETWORK_SUGGESTIONS_" }, value = { STATUS_NETWORK_SUGGESTIONS_SUCCESS, @@ -201,6 +216,8 @@ public class WifiManager { STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE, STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_EXCEEDS_MAX_PER_APP, STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID, + STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_NOT_ALLOWED, + STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_INVALID, }) @Retention(RetentionPolicy.SOURCE) public @interface NetworkSuggestionsStatusCode {} @@ -233,16 +250,20 @@ public class WifiManager { public @interface SuggestionConnectionStatusCode {} /** - * Broadcast intent action indicating whether Wi-Fi scanning is allowed currently - * @hide + * Broadcast intent action indicating whether Wi-Fi scanning is currently available. + * Available extras: + * - {@link #EXTRA_SCAN_AVAILABLE} */ - public static final String WIFI_SCAN_AVAILABLE = "wifi_scan_available"; + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_WIFI_SCAN_AVAILABLE = + "android.net.wifi.action.WIFI_SCAN_AVAILABLE"; /** - * Extra int indicating scan availability, WIFI_STATE_ENABLED and WIFI_STATE_DISABLED - * @hide + * A boolean extra indicating whether scanning is currently available. + * Sent in the broadcast {@link #ACTION_WIFI_SCAN_AVAILABLE}. + * Its value is true if scanning is currently available, false otherwise. */ - public static final String EXTRA_SCAN_AVAILABLE = "scan_enabled"; + public static final String EXTRA_SCAN_AVAILABLE = "android.net.wifi.extra.SCAN_AVAILABLE"; /** * @@ -558,15 +579,22 @@ public class WifiManager { public static final String EXTRA_WIFI_AP_STATE = "wifi_state"; /** - * The look up key for an int that indicates why softAP started failed - * currently support general and no_channel - * @see #SAP_START_FAILURE_GENERAL - * @see #SAP_START_FAILURE_NO_CHANNEL - * @see #SAP_START_FAILURE_UNSUPPORTED_CONFIGURATION + * An extra containing the int error code for Soft AP start failure. + * Can be obtained from the {@link #WIFI_AP_STATE_CHANGED_ACTION} using + * {@link android.content.Intent#getIntExtra}. + * This extra will only be attached if {@link #EXTRA_WIFI_AP_STATE} is + * attached and is equal to {@link #WIFI_AP_STATE_FAILED}. + * + * The error code will be one of: + * {@link #SAP_START_FAILURE_GENERAL}, + * {@link #SAP_START_FAILURE_NO_CHANNEL}, + * {@link #SAP_START_FAILURE_UNSUPPORTED_CONFIGURATION} * * @hide */ - public static final String EXTRA_WIFI_AP_FAILURE_REASON = "wifi_ap_error_code"; + @SystemApi + public static final String EXTRA_WIFI_AP_FAILURE_REASON = + "android.net.wifi.extra.WIFI_AP_FAILURE_REASON"; /** * The look up key for a string that gives additonal info about EXTRA_WIFI_AP_FAILURE_REASON * currently support no_5ghz_support @@ -687,7 +715,8 @@ public class WifiManager { public @interface SapStartFailure {} /** - * All other reasons for AP start failure besides {@link #SAP_START_FAILURE_NO_CHANNEL}. + * All other reasons for AP start failure besides {@link #SAP_START_FAILURE_NO_CHANNEL} and + * {@link #SAP_START_FAILURE_UNSUPPORTED_CONFIGURATION}. * * @hide */ @@ -712,6 +741,37 @@ public class WifiManager { @SystemApi public static final int SAP_START_FAILURE_UNSUPPORTED_CONFIGURATION = 2; + + /** @hide */ + @IntDef(flag = false, prefix = { "SAP_CLIENT_BLOCKED_REASON_" }, value = { + SAP_CLIENT_BLOCK_REASON_CODE_BLOCKED_BY_USER, + SAP_CLIENT_BLOCK_REASON_CODE_NO_MORE_STAS, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface SapClientBlockedReason {} + + /** + * If Soft Ap client is blocked, this reason code means that client doesn't exist in the + * specified configuration {@link SoftApConfiguration.Builder#setClientList(List, List)} + * and the {@link SoftApConfiguration.Builder#enableClientControlByUser(true)} + * is configured as well. + * @hide + */ + @SystemApi + public static final int SAP_CLIENT_BLOCK_REASON_CODE_BLOCKED_BY_USER = 0; + + /** + * If Soft Ap client is blocked, this reason code means that no more clients can be + * associated to this AP since it reached maximum capacity. The maximum capacity is + * the minimum of {@link SoftApConfiguration.Builder#setMaxNumberOfClients(int)} and + * {@link SoftApCapability#getMaxSupportedClients} which get from + * {@link WifiManager.SoftApCallback#onCapabilityChanged(SoftApCapability)}. + * + * @hide + */ + @SystemApi + public static final int SAP_CLIENT_BLOCK_REASON_CODE_NO_MORE_STAS = 1; + /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"IFACE_IP_MODE_"}, value = { @@ -1445,6 +1505,36 @@ public class WifiManager { } /** + * Retrieve a list of {@link WifiConfiguration} for available {@link WifiNetworkSuggestion} + * matching the given list of {@link ScanResult}. + * + * An available {@link WifiNetworkSuggestion} must satisfy: + * <ul> + * <li> Matching one of the {@link ScanResult} from the given list. + * <li> and {@link WifiNetworkSuggestion.Builder#setIsUserAllowedToManuallyConnect(boolean)} set + * to true. + * </ul> + * + * @param scanResults a list of scanResult. + * @return a list of @link WifiConfiguration} for available {@link WifiNetworkSuggestion} + * @hide + */ + @SystemApi + @RequiresPermission(anyOf = { + android.Manifest.permission.NETWORK_SETTINGS, + android.Manifest.permission.NETWORK_SETUP_WIZARD + }) + @NonNull + public List<WifiConfiguration> getWifiConfigForMatchedNetworkSuggestionsSharedWithUser( + @NonNull List<ScanResult> scanResults) { + try { + return mService.getWifiConfigForMatchedNetworkSuggestionsSharedWithUser(scanResults); + } catch (RemoteException e) { + throw e.rethrowAsRuntimeException(); + } + } + + /** * Returns a list of unique Hotspot 2.0 OSU (Online Sign-Up) providers associated with a given * list of ScanResult. * @@ -2021,6 +2111,15 @@ public class WifiManager { * @param config The Passpoint configuration to be added * @throws IllegalArgumentException if configuration is invalid or Passpoint is not enabled on * the device. + * + * Deprecated for general app usage - except DO/PO apps. + * See {@link WifiNetworkSuggestion.Builder#setPasspointConfig(PasspointConfiguration)} to + * create a passpoint suggestion. + * See {@link #addNetworkSuggestions(List)}, {@link #removeNetworkSuggestions(List)} for new + * API to add Wi-Fi networks for consideration when auto-connecting to wifi. + * <b>Compatibility Note:</b> For applications targeting + * {@link android.os.Build.VERSION_CODES#R} or above, except for system of DO/PO apps, this API + * will throw {@link IllegalArgumentException} */ public void addOrUpdatePasspointConfiguration(PasspointConfiguration config) { try { @@ -2442,6 +2541,15 @@ public class WifiManager { } /** + * Query whether the device supports Station (STA) + Access point (AP) concurrency or not. + * + * @return true if this device supports STA + AP concurrency, false otherwise. + */ + public boolean isStaApConcurrencySupported() { + return isFeatureSupported(WIFI_FEATURE_AP_STA); + } + + /** * @deprecated Please use {@link android.content.pm.PackageManager#hasSystemFeature(String)} * with {@link android.content.pm.PackageManager#FEATURE_WIFI_RTT} and * {@link android.content.pm.PackageManager#FEATURE_WIFI_AWARE}. @@ -2546,6 +2654,20 @@ public class WifiManager { } /** + * Check if the chipset supports a certain Wi-Fi standard. + * @param standard the IEEE 802.11 standard to check on. + * valid values from {@link ScanResult}'s {@code WIFI_STANDARD_} + * @return {@code true} if supported, {@code false} otherwise. + */ + public boolean isWifiStandardSupported(@ScanResult.WifiStandard int standard) { + try { + return mService.isWifiStandardSupported(standard); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** * Interface for Wi-Fi activity energy info listener. Should be implemented by applications and * set when calling {@link WifiManager#getWifiActivityEnergyInfoAsync}. * @@ -2679,6 +2801,8 @@ public class WifiManager { * the same permissions as {@link #getScanResults}. If such access is not allowed, * {@link WifiInfo#getSSID} will return {@link #UNKNOWN_SSID} and * {@link WifiInfo#getBSSID} will return {@code "02:00:00:00:00:00"}. + * {@link WifiInfo#getPasspointFqdn()} will return null. + * {@link WifiInfo#getPasspointProviderFriendlyName()} will return null. * * @return the Wi-Fi information, contained in {@link WifiInfo}. */ @@ -2698,7 +2822,6 @@ public class WifiManager { * in order to get valid results. */ public List<ScanResult> getScanResults() { - android.util.SeempLog.record(55); try { return mService.getScanResults(mContext.getOpPackageName(), mContext.getFeatureId()); @@ -3034,7 +3157,7 @@ public class WifiManager { * Each application can make a single active call to this method. The {@link * LocalOnlyHotspotCallback#onStarted(LocalOnlyHotspotReservation)} callback supplies the * requestor with a {@link LocalOnlyHotspotReservation} that contains a - * {@link WifiConfiguration} with the SSID, security type and credentials needed to connect + * {@link SoftApConfiguration} with the SSID, security type and credentials needed to connect * to the hotspot. Communicating this information is up to the application. * <p> * If the LocalOnlyHotspot cannot be created, the {@link LocalOnlyHotspotCallback#onFailed(int)} @@ -3199,7 +3322,7 @@ public class WifiManager { * Allow callers (Settings UI) to watch LocalOnlyHotspot state changes. Callers will * receive a {@link LocalOnlyHotspotSubscription} object as a parameter of the * {@link LocalOnlyHotspotObserver#onRegistered(LocalOnlyHotspotSubscription)}. The registered - * callers will receive the {@link LocalOnlyHotspotObserver#onStarted(WifiConfiguration)} and + * callers will receive the {@link LocalOnlyHotspotObserver#onStarted(SoftApConfiguration)} and * {@link LocalOnlyHotspotObserver#onStopped()} callbacks. * <p> * Applications should have the @@ -3286,9 +3409,13 @@ public class WifiManager { * Gets the Wi-Fi AP Configuration. * @return AP details in WifiConfiguration * + * Note that AP detail may contain configuration which is cannot be represented + * by the legacy WifiConfiguration, in such cases a null will be returned. + * * @deprecated This API is deprecated. Use {@link #getSoftApConfiguration()} instead. * @hide */ + @Nullable @SystemApi @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) @Deprecated @@ -3339,8 +3466,17 @@ public class WifiManager { /** * Sets the Wi-Fi AP Configuration. * + * If the API is called while the soft AP is enabled, the configuration will apply to + * the current soft AP if the new configuration only includes + * {@link SoftApConfiguration.Builder#setMaxNumberOfClients(int)} + * or {@link SoftApConfiguration.Builder#setShutdownTimeoutMillis(int)} + * or {@link SoftApConfiguration.Builder#enableClientControlByUser(boolean)} + * or {@link SoftApConfiguration.Builder#setClientList(List, List)}. + * + * Otherwise, the configuration changes will be applied when the Soft AP is next started + * (the framework will not stop/start the AP). + * * @param softApConfig A valid SoftApConfiguration specifying the configuration of the SAP. - * @return {@code true} if the operation succeeded, {@code false} otherwise * * @hide @@ -3570,7 +3706,8 @@ public class WifiManager { * {@link #WIFI_AP_STATE_ENABLING}, {@link #WIFI_AP_STATE_FAILED} * @param failureReason reason when in failed state. One of * {@link #SAP_START_FAILURE_GENERAL}, - * {@link #SAP_START_FAILURE_NO_CHANNEL} + * {@link #SAP_START_FAILURE_NO_CHANNEL}, + * {@link #SAP_START_FAILURE_UNSUPPORTED_CONFIGURATION} */ default void onStateChanged(@WifiApState int state, @SapStartFailure int failureReason) {} @@ -3601,6 +3738,22 @@ public class WifiManager { } /** + * Called when client trying to connect but device blocked the client with specific reason. + * + * Can be used to ask user to update client to allowed list or blocked list + * when reason is {@link SAP_CLIENT_BLOCK_REASON_CODE_BLOCKED_BY_USER}, or + * indicate the block due to maximum supported client number limitation when reason is + * {@link SAP_CLIENT_BLOCK_REASON_CODE_NO_MORE_STAS}. + * + * @param client the currently blocked client. + * @param blockedReason one of blocked reason from {@link SapClientBlockedReason} + */ + default void onBlockedClientConnecting(@NonNull WifiClient client, + @SapClientBlockedReason int blockedReason) { + // Do nothing: can be used to ask user to update client to allowed list or blocked list. + } + + /** * Called when Stations connected to soft AP. * * @param Macaddr Mac Address of connected Stations to soft AP @@ -3683,6 +3836,19 @@ public class WifiManager { } @Override + public void onBlockedClientConnecting(@NonNull WifiClient client, int blockedReason) { + if (mVerboseLoggingEnabled) { + Log.v(TAG, "SoftApCallbackProxy: onBlockedClientConnecting: client=" + client + + " with reason = " + blockedReason); + } + + Binder.clearCallingIdentity(); + mExecutor.execute(() -> { + mCallback.onBlockedClientConnecting(client, blockedReason); + }); + } + + @Override public void onStaConnected(String Macaddr, int numClients) throws RemoteException { Log.v(TAG, "SoftApCallbackProxy: [" + numClients + "]onStaConnected Macaddr =" + Macaddr); Binder.clearCallingIdentity(); @@ -3769,13 +3935,13 @@ public class WifiManager { } /** - * LocalOnlyHotspotReservation that contains the {@link WifiConfiguration} for the active + * LocalOnlyHotspotReservation that contains the {@link SoftApConfiguration} for the active * LocalOnlyHotspot request. * <p> * Applications requesting LocalOnlyHotspot for sharing will receive an instance of the * LocalOnlyHotspotReservation in the * {@link LocalOnlyHotspotCallback#onStarted(LocalOnlyHotspotReservation)} call. This - * reservation contains the relevant {@link WifiConfiguration}. + * reservation contains the relevant {@link SoftApConfiguration}. * When an application is done with the LocalOnlyHotspot, they should call {@link * LocalOnlyHotspotReservation#close()}. Once this happens, the application will not receive * any further callbacks. If the LocalOnlyHotspot is stopped due to a @@ -3785,18 +3951,38 @@ public class WifiManager { public class LocalOnlyHotspotReservation implements AutoCloseable { private final CloseGuard mCloseGuard = new CloseGuard(); - private final WifiConfiguration mConfig; + private final SoftApConfiguration mSoftApConfig; + private final WifiConfiguration mWifiConfig; private boolean mClosed = false; /** @hide */ @VisibleForTesting - public LocalOnlyHotspotReservation(WifiConfiguration config) { - mConfig = config; + public LocalOnlyHotspotReservation(SoftApConfiguration config) { + mSoftApConfig = config; + mWifiConfig = config.toWifiConfiguration(); mCloseGuard.open("close"); } + /** + * Returns the {@link WifiConfiguration} of the current Local Only Hotspot (LOHS). + * May be null if hotspot enabled and security type is not + * {@code WifiConfiguration.KeyMgmt.None} or {@code WifiConfiguration.KeyMgmt.WPA2_PSK}. + * + * @deprecated Use {@code WifiManager#getSoftApConfiguration()} to get the + * LOHS configuration. + */ + @Deprecated + @Nullable public WifiConfiguration getWifiConfiguration() { - return mConfig; + return mWifiConfig; + } + + /** + * Returns the {@link SoftApConfiguration} of the current Local Only Hotspot (LOHS). + */ + @NonNull + public SoftApConfiguration getSoftApConfiguration() { + return mSoftApConfig; } @Override @@ -3893,7 +4079,7 @@ public class WifiManager { } @Override - public void onHotspotStarted(WifiConfiguration config) { + public void onHotspotStarted(SoftApConfiguration config) { WifiManager manager = mWifiManager.get(); if (manager == null) return; @@ -3985,7 +4171,7 @@ public class WifiManager { /** * LocalOnlyHotspot started with the supplied config. */ - public void onStarted(WifiConfiguration config) {}; + public void onStarted(SoftApConfiguration config) {}; /** * LocalOnlyHotspot stopped. @@ -4025,7 +4211,7 @@ public class WifiManager { } @Override - public void onHotspotStarted(WifiConfiguration config) { + public void onHotspotStarted(SoftApConfiguration config) { WifiManager manager = mWifiManager.get(); if (manager == null) return; @@ -4284,6 +4470,41 @@ public class WifiManager { } /** + * Configure auto-join settings for a Passpoint profile. + * + * @param fqdn the FQDN (fully qualified domain name) of the passpoint profile. + * @param enableAutoJoin true to enable autojoin, false to disable autojoin. + * @hide + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) + public void allowAutojoinPasspoint(@NonNull String fqdn, boolean enableAutoJoin) { + try { + mService.allowAutojoinPasspoint(fqdn, enableAutoJoin); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * Configure MAC randomization setting for a Passpoint profile. + * MAC randomization is enabled by default. + * + * @param fqdn the FQDN (fully qualified domain name) of the passpoint profile. + * @param enable true to enable MAC randomization, false to disable MAC randomization. + * @hide + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) + public void setMacRandomizationSettingPasspointEnabled(@NonNull String fqdn, boolean enable) { + try { + mService.setMacRandomizationSettingPasspointEnabled(fqdn, enable); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** * Disable an ephemeral network. * * @param ssid in the format of WifiConfiguration's SSID. @@ -6013,4 +6234,186 @@ public class WifiManager { return new SparseArray<>(); } } + + /** + * Callback interface for framework to receive network status changes and trigger of updating + * {@link WifiUsabilityStatsEntry}. + * + * @hide + */ + @SystemApi + public interface ScoreChangeCallback { + /** + * Called by applications to indicate network status. + * + * @param sessionId The ID to indicate current Wi-Fi network connection obtained from + * {@link WifiConnectedNetworkScorer#start(int)}. + * @param isUsable The bit to indicate whether current Wi-Fi network is usable or not. + * Populated by connected network scorer in applications. + */ + void onStatusChange(int sessionId, boolean isUsable); + + /** + * Called by applications to trigger an update of {@link WifiUsabilityStatsEntry}. + * To receive update applications need to add WifiUsabilityStatsEntry listener. See + * {@link addOnWifiUsabilityStatsListener(Executor, OnWifiUsabilityStatsListener)}. + * + * @param sessionId The ID to indicate current Wi-Fi network connection obtained from + * {@link WifiConnectedNetworkScorer#start(int)}. + */ + void onTriggerUpdateOfWifiUsabilityStats(int sessionId); + } + + /** + * Callback proxy for {@link ScoreChangeCallback} objects. + * + * @hide + */ + private class ScoreChangeCallbackProxy implements ScoreChangeCallback { + private final IScoreChangeCallback mScoreChangeCallback; + + private ScoreChangeCallbackProxy(IScoreChangeCallback callback) { + mScoreChangeCallback = callback; + } + + @Override + public void onStatusChange(int sessionId, boolean isUsable) { + try { + mScoreChangeCallback.onStatusChange(sessionId, isUsable); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + @Override + public void onTriggerUpdateOfWifiUsabilityStats(int sessionId) { + try { + mScoreChangeCallback.onTriggerUpdateOfWifiUsabilityStats(sessionId); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + } + + /** + * Interface for Wi-Fi connected network scorer. Should be implemented by applications and set + * when calling + * {@link WifiManager#setWifiConnectedNetworkScorer(Executor, WifiConnectedNetworkScorer)}. + * + * @hide + */ + @SystemApi + public interface WifiConnectedNetworkScorer { + /** + * Called by framework to indicate the start of a network connection. + * @param sessionId The ID to indicate current Wi-Fi network connection. + */ + void start(int sessionId); + + /** + * Called by framework to indicate the end of a network connection. + * @param sessionId The ID to indicate current Wi-Fi network connection obtained from + * {@link WifiConnectedNetworkScorer#start(int)}. + */ + void stop(int sessionId); + + /** + * Framework sets callback for score change events after application sets its scorer. + * @param cbImpl The instance for {@link WifiManager#ScoreChangeCallback}. Should be + * implemented and instantiated by framework. + */ + void setScoreChangeCallback(@NonNull ScoreChangeCallback cbImpl); + } + + /** + * Callback proxy for {@link WifiConnectedNetworkScorer} objects. + * + * @hide + */ + private class WifiConnectedNetworkScorerProxy extends IWifiConnectedNetworkScorer.Stub { + private Executor mExecutor; + private WifiConnectedNetworkScorer mScorer; + + WifiConnectedNetworkScorerProxy(Executor executor, WifiConnectedNetworkScorer scorer) { + mExecutor = executor; + mScorer = scorer; + } + + @Override + public void start(int sessionId) { + if (mVerboseLoggingEnabled) { + Log.v(TAG, "WifiConnectedNetworkScorer: " + "start: sessionId=" + sessionId); + } + Binder.clearCallingIdentity(); + mExecutor.execute(() -> mScorer.start(sessionId)); + } + + @Override + public void stop(int sessionId) { + if (mVerboseLoggingEnabled) { + Log.v(TAG, "WifiConnectedNetworkScorer: " + "stop: sessionId=" + sessionId); + } + Binder.clearCallingIdentity(); + mExecutor.execute(() -> mScorer.stop(sessionId)); + } + + @Override + public void setScoreChangeCallback(IScoreChangeCallback cbImpl) { + if (mVerboseLoggingEnabled) { + Log.v(TAG, "WifiConnectedNetworkScorer: " + + "setScoreChangeCallback: cbImpl=" + cbImpl); + } + Binder.clearCallingIdentity(); + mExecutor.execute(() -> mScorer.setScoreChangeCallback( + new ScoreChangeCallbackProxy(cbImpl))); + } + } + + /** + * Set a callback for Wi-Fi connected network scorer. See {@link WifiConnectedNetworkScorer}. + * Only a single scorer can be set. Caller will be invoked periodically by framework to inform + * client about start and stop of Wi-Fi connection. Caller can clear a previously set scorer + * using {@link clearWifiConnectedNetworkScorer()}. + * + * @param executor The executor on which callback will be invoked. + * @param scorer Scorer for Wi-Fi network implemented by application. + * @return true Scorer is set successfully. + * + * @hide + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.WIFI_UPDATE_USABILITY_STATS_SCORE) + public boolean setWifiConnectedNetworkScorer(@NonNull @CallbackExecutor Executor executor, + @NonNull WifiConnectedNetworkScorer scorer) { + if (executor == null) throw new IllegalArgumentException("executor cannot be null"); + if (scorer == null) throw new IllegalArgumentException("scorer cannot be null"); + if (mVerboseLoggingEnabled) { + Log.v(TAG, "setWifiConnectedNetworkScorer: scorer=" + scorer); + } + try { + return mService.setWifiConnectedNetworkScorer(new Binder(), + new WifiConnectedNetworkScorerProxy(executor, scorer)); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * Allow caller to clear a previously set scorer. After calling this method, + * client will no longer receive information about start and stop of Wi-Fi connection. + * + * @hide + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.WIFI_UPDATE_USABILITY_STATS_SCORE) + public void clearWifiConnectedNetworkScorer() { + if (mVerboseLoggingEnabled) { + Log.v(TAG, "clearWifiConnectedNetworkScorer"); + } + try { + mService.clearWifiConnectedNetworkScorer(); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } } diff --git a/wifi/java/android/net/wifi/WifiNetworkConnectionStatistics.aidl b/wifi/java/android/net/wifi/WifiNetworkConnectionStatistics.aidl deleted file mode 100644 index 5f497e2796d8..000000000000 --- a/wifi/java/android/net/wifi/WifiNetworkConnectionStatistics.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2014, 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; - -parcelable WifiNetworkConnectionStatistics; diff --git a/wifi/java/android/net/wifi/WifiNetworkSpecifier.java b/wifi/java/android/net/wifi/WifiNetworkSpecifier.java index 07afd7fb6714..444e1ef041e8 100644 --- a/wifi/java/android/net/wifi/WifiNetworkSpecifier.java +++ b/wifi/java/android/net/wifi/WifiNetworkSpecifier.java @@ -20,7 +20,7 @@ import static com.android.internal.util.Preconditions.checkNotNull; import android.annotation.NonNull; import android.annotation.Nullable; -import android.app.ActivityThread; +import android.app.Application; import android.net.MacAddress; import android.net.MatchAllNetworkSpecifier; import android.net.NetworkRequest; @@ -30,8 +30,11 @@ import android.os.Parcelable; import android.os.PatternMatcher; import android.os.Process; import android.text.TextUtils; +import android.util.Log; import android.util.Pair; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.nio.charset.CharsetEncoder; import java.nio.charset.StandardCharsets; import java.util.Objects; @@ -41,6 +44,7 @@ import java.util.Objects; * {@link WifiNetworkSpecifier.Builder} class to create an instance. */ public final class WifiNetworkSpecifier extends NetworkSpecifier implements Parcelable { + private static final String TAG = "WifiNetworkSpecifier"; /** * Builder used to create {@link WifiNetworkSpecifier} objects. @@ -436,7 +440,22 @@ public final class WifiNetworkSpecifier extends NetworkSpecifier implements Parc mBssidPatternMatcher, buildWifiConfiguration(), Process.myUid(), - ActivityThread.currentApplication().getApplicationContext().getOpPackageName()); + getCurrentApplicationReflectively().getApplicationContext().getOpPackageName()); + } + + // TODO(b/144102365): Remove once refactor is complete + private static Application getCurrentApplicationReflectively() { + try { + // reflection for static method android.app.ActivityThread#currentApplication() + Class<?> klass = Class.forName("android.app.ActivityThread"); + Method currentApplicationMethod = klass.getDeclaredMethod("currentApplication"); + Object result = currentApplicationMethod.invoke(null); + return (Application) result; + } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException + | InvocationTargetException e) { + Log.e(TAG, "Failed to call ActivityThread#currentApplication() reflectively!", e); + throw new RuntimeException(e); + } } } diff --git a/wifi/java/android/net/wifi/WifiNetworkSuggestion.aidl b/wifi/java/android/net/wifi/WifiNetworkSuggestion.aidl deleted file mode 100644 index eb6995f561de..000000000000 --- a/wifi/java/android/net/wifi/WifiNetworkSuggestion.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2018, 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; - -parcelable WifiNetworkSuggestion; diff --git a/wifi/java/android/net/wifi/WifiNetworkSuggestion.java b/wifi/java/android/net/wifi/WifiNetworkSuggestion.java index 9c1475ffc8cd..6085eae252ef 100644 --- a/wifi/java/android/net/wifi/WifiNetworkSuggestion.java +++ b/wifi/java/android/net/wifi/WifiNetworkSuggestion.java @@ -116,12 +116,18 @@ public final class WifiNetworkSuggestion implements Parcelable { /** * Whether this network is shared credential with user to allow user manually connect. */ - private boolean mIsUserAllowed; + private boolean mIsSharedWithUser; /** - * Whether the setIsUserAllowedToManuallyConnect have been called. + * Whether the setCredentialSharedWithUser have been called. */ - private boolean mIsUserAllowedBeenSet; + private boolean mIsSharedWithUserSet; + + /** + * Whether this network is initialized with auto-join enabled (the default) or not. + */ + private boolean mIsInitialAutoJoinEnabled; + /** * Pre-shared key for use with WAPI-PSK networks. */ @@ -133,6 +139,11 @@ public final class WifiNetworkSuggestion implements Parcelable { */ private @Nullable WifiEnterpriseConfig mWapiEnterpriseConfig; + /** + * Whether this network will be brought up as untrusted (TRUSTED capability bit removed). + */ + private boolean mIsNetworkUntrusted; + public Builder() { mSsid = null; mBssid = null; @@ -146,12 +157,14 @@ public final class WifiNetworkSuggestion implements Parcelable { mIsAppInteractionRequired = false; mIsUserInteractionRequired = false; mIsMetered = false; - mIsUserAllowed = true; - mIsUserAllowedBeenSet = false; + mIsSharedWithUser = true; + mIsSharedWithUserSet = false; + mIsInitialAutoJoinEnabled = true; mPriority = UNASSIGNED_PRIORITY; mCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID; mWapiPskPassphrase = null; mWapiEnterpriseConfig = null; + mIsNetworkUntrusted = false; } /** @@ -430,13 +443,55 @@ public final class WifiNetworkSuggestion implements Parcelable { * <li>If not set, defaults to true (i.e. allow user to manually connect) for secure * networks and false for open networks.</li> * - * @param isAllowed {@code true} to indicate that the credentials may be used by the user to + * @param isShared {@code true} to indicate that the credentials may be used by the user to * manually connect to the network, {@code false} otherwise. * @return Instance of {@link Builder} to enable chaining of the builder method. */ - public @NonNull Builder setIsUserAllowedToManuallyConnect(boolean isAllowed) { - mIsUserAllowed = isAllowed; - mIsUserAllowedBeenSet = true; + public @NonNull Builder setCredentialSharedWithUser(boolean isShared) { + mIsSharedWithUser = isShared; + mIsSharedWithUserSet = true; + return this; + } + + /** + * Specifies whether the suggestion is created with auto-join enabled or disabled. The + * user may modify the auto-join configuration of a suggestion directly once the device + * associates to the network. + * <p> + * If auto-join is initialized as disabled the user may still be able to manually connect + * to the network. Therefore, disabling auto-join only makes sense if + * {@link #setCredentialSharedWithUser(boolean)} is set to true (the default) which + * itself implies a secure (non-open) network. + * <p> + * If not set, defaults to true (i.e. auto-join is initialized as enabled). + * + * @param enabled true for initializing with auto-join enabled (the default), false to + * initializing with auto-join disabled. + * @return Instance of (@link {@link Builder} to enable chaining of the builder method. + */ + public @NonNull Builder setIsInitialAutoJoinEnabled(boolean enabled) { + mIsInitialAutoJoinEnabled = enabled; + return this; + } + + /** + * Specifies whether the system will bring up the network (if selected) as untrusted. An + * untrusted network has its {@link android.net.NetworkCapabilities#NET_CAPABILITY_TRUSTED} + * capability removed. The Wi-Fi network selection process may use this information to + * influence priority of the suggested network for Wi-Fi network selection (most likely to + * reduce it). The connectivity service may use this information to influence the overall + * network configuration of the device. + * <p> + * <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> + * + * @param isUntrusted Boolean indicating whether the network should be brought up untrusted + * (if true) or trusted (if false). + * @return Instance of {@link Builder} to enable chaining of the builder method. + */ + public @NonNull Builder setUntrusted(boolean isUntrusted) { + mIsNetworkUntrusted = isUntrusted; return this; } @@ -518,6 +573,7 @@ public final class WifiNetworkSuggestion implements Parcelable { wifiConfiguration.meteredOverride = mIsMetered ? WifiConfiguration.METERED_OVERRIDE_METERED : WifiConfiguration.METERED_OVERRIDE_NONE; + wifiConfiguration.trusted = !mIsNetworkUntrusted; mPasspointConfiguration.setCarrierId(mCarrierId); return wifiConfiguration; } @@ -587,7 +643,6 @@ public final class WifiNetworkSuggestion implements Parcelable { + "suggestion with Passpoint configuration"); } wifiConfiguration = buildWifiConfigurationForPasspoint(); - } else { if (mSsid == null) { throw new IllegalStateException("setSsid should be invoked for suggestion"); @@ -602,20 +657,34 @@ public final class WifiNetworkSuggestion implements Parcelable { } wifiConfiguration = buildWifiConfiguration(); if (wifiConfiguration.isOpenNetwork()) { - if (mIsUserAllowedBeenSet && mIsUserAllowed) { + if (mIsSharedWithUserSet && mIsSharedWithUser) { throw new IllegalStateException("Open network should not be " - + "setIsUserAllowedToManuallyConnect to true"); + + "setCredentialSharedWithUser to true"); } - mIsUserAllowed = false; + mIsSharedWithUser = false; } } - + if (!mIsSharedWithUser && !mIsInitialAutoJoinEnabled) { + throw new IllegalStateException("Should have not a network with both " + + "setCredentialSharedWithUser and " + + "setIsAutoJoinEnabled set to false"); + } + if (mIsNetworkUntrusted) { + if (mIsSharedWithUserSet && mIsSharedWithUser) { + throw new IllegalStateException("Should not be both" + + "setCredentialSharedWithUser and +" + + "setIsNetworkAsUntrusted to true"); + } + mIsSharedWithUser = false; + } return new WifiNetworkSuggestion( wifiConfiguration, mPasspointConfiguration, mIsAppInteractionRequired, mIsUserInteractionRequired, - mIsUserAllowed); + mIsSharedWithUser, + mIsInitialAutoJoinEnabled, + mIsNetworkUntrusted); } } @@ -623,12 +692,14 @@ public final class WifiNetworkSuggestion implements Parcelable { * Network configuration for the provided network. * @hide */ + @NonNull public final WifiConfiguration wifiConfiguration; /** * Passpoint configuration for the provided network. * @hide */ + @Nullable public final PasspointConfiguration passpointConfiguration; /** @@ -642,6 +713,7 @@ public final class WifiNetworkSuggestion implements Parcelable { * @hide */ public final boolean isUserInteractionRequired; + /** * Whether app share credential with the user, allow user use provided credential to * connect network manually. @@ -649,13 +721,28 @@ public final class WifiNetworkSuggestion implements Parcelable { */ public final boolean isUserAllowedToManuallyConnect; + /** + * Whether the suggestion will be initialized as auto-joined or not. + * @hide + */ + public final boolean isInitialAutoJoinEnabled; + + /** + * Whether this network will be brought up as untrusted (TRUSTED capability bit removed). + * @hide + */ + public final boolean isNetworkUntrusted; + + /** @hide */ public WifiNetworkSuggestion() { - this.wifiConfiguration = null; + this.wifiConfiguration = new WifiConfiguration(); this.passpointConfiguration = null; this.isAppInteractionRequired = false; this.isUserInteractionRequired = false; this.isUserAllowedToManuallyConnect = true; + this.isInitialAutoJoinEnabled = true; + this.isNetworkUntrusted = false; } /** @hide */ @@ -663,7 +750,9 @@ public final class WifiNetworkSuggestion implements Parcelable { @Nullable PasspointConfiguration passpointConfiguration, boolean isAppInteractionRequired, boolean isUserInteractionRequired, - boolean isUserAllowedToManuallyConnect) { + boolean isUserAllowedToManuallyConnect, + boolean isInitialAutoJoinEnabled, + boolean isNetworkUntrusted) { checkNotNull(networkConfiguration); this.wifiConfiguration = networkConfiguration; this.passpointConfiguration = passpointConfiguration; @@ -671,6 +760,8 @@ public final class WifiNetworkSuggestion implements Parcelable { this.isAppInteractionRequired = isAppInteractionRequired; this.isUserInteractionRequired = isUserInteractionRequired; this.isUserAllowedToManuallyConnect = isUserAllowedToManuallyConnect; + this.isInitialAutoJoinEnabled = isInitialAutoJoinEnabled; + this.isNetworkUntrusted = isNetworkUntrusted; } public static final @NonNull Creator<WifiNetworkSuggestion> CREATOR = @@ -682,7 +773,9 @@ public final class WifiNetworkSuggestion implements Parcelable { in.readParcelable(null), // PasspointConfiguration in.readBoolean(), // isAppInteractionRequired in.readBoolean(), // isUserInteractionRequired - in.readBoolean() // isSharedCredentialWithUser + in.readBoolean(), // isSharedCredentialWithUser + in.readBoolean(), // isAutoJoinEnabled + in.readBoolean() ); } @@ -704,6 +797,8 @@ public final class WifiNetworkSuggestion implements Parcelable { dest.writeBoolean(isAppInteractionRequired); dest.writeBoolean(isUserInteractionRequired); dest.writeBoolean(isUserAllowedToManuallyConnect); + dest.writeBoolean(isInitialAutoJoinEnabled); + dest.writeBoolean(isNetworkUntrusted); } @Override @@ -743,8 +838,31 @@ public final class WifiNetworkSuggestion implements Parcelable { .append(", FQDN=").append(wifiConfiguration.FQDN) .append(", isAppInteractionRequired=").append(isAppInteractionRequired) .append(", isUserInteractionRequired=").append(isUserInteractionRequired) - .append(", isUserAllowedToManuallyConnect=").append(isUserAllowedToManuallyConnect) + .append(", isCredentialSharedWithUser=").append(isUserAllowedToManuallyConnect) + .append(", isInitialAutoJoinEnabled=").append(isInitialAutoJoinEnabled) + .append(", isUnTrusted=").append(isNetworkUntrusted) .append(" ]"); return sb.toString(); } + + /** + * Get the {@link WifiConfiguration} associated with this Suggestion. + * @hide + */ + @SystemApi + @NonNull + public WifiConfiguration getWifiConfiguration() { + return wifiConfiguration; + } + + /** + * Get the {@link PasspointConfiguration} associated with this Suggestion, or null if this + * Suggestion is not for a Passpoint network. + * @hide + */ + @SystemApi + @Nullable + public PasspointConfiguration getPasspointConfiguration() { + return passpointConfiguration; + } } diff --git a/wifi/java/android/net/wifi/WifiOemConfigStoreMigrationHook.java b/wifi/java/android/net/wifi/WifiOemConfigStoreMigrationHook.java new file mode 100755 index 000000000000..642dcb9211ae --- /dev/null +++ b/wifi/java/android/net/wifi/WifiOemConfigStoreMigrationHook.java @@ -0,0 +1,180 @@ +/* + * 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; + +import static com.android.internal.util.Preconditions.checkNotNull; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.SystemApi; +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.List; + +/** + * Class used to provide one time hooks for existing OEM devices to migrate their config store + * data to the wifi mainline module. + * <p> + * Note: + * <li> OEM's need to implement {@link #load()} only if their + * existing config store format or file locations differs from the vanilla AOSP implementation ( + * which is what the wifi mainline module understands). + * </li> + * <li> The wifi mainline module will invoke {@link #load()} method on every bootup, its + * the responsibility of the OEM implementation to ensure that this method returns non-null data + * only on the first bootup. Once the migration is done, the OEM can safely delete their config + * store files and then return null on any subsequent reboots. The first & only relevant invocation + * of {@link #load()} occurs when a previously released device upgrades to the wifi + * mainline module from an OEM implementation of the wifi stack. + * </li> + * @hide + */ +@SystemApi +public final class WifiOemConfigStoreMigrationHook { + /** + * Container for all the wifi config data to migrate. + */ + public static final class MigrationData implements Parcelable { + /** + * Builder to create instance of {@link MigrationData}. + */ + public static final class Builder { + private List<WifiConfiguration> mUserSavedNetworkConfigurations; + private SoftApConfiguration mUserSoftApConfiguration; + + public Builder() { + mUserSavedNetworkConfigurations = null; + mUserSoftApConfiguration = null; + } + + /** + * Sets the list of all user's saved network configurations parsed from OEM config + * store files. + * + * @param userSavedNetworkConfigurations List of {@link WifiConfiguration} representing + * the list of user's saved networks + * @return Instance of {@link Builder} to enable chaining of the builder method. + */ + public @NonNull Builder setUserSavedNetworkConfigurations( + @NonNull List<WifiConfiguration> userSavedNetworkConfigurations) { + checkNotNull(userSavedNetworkConfigurations); + mUserSavedNetworkConfigurations = userSavedNetworkConfigurations; + return this; + } + + /** + * Sets the user's softap configuration parsed from OEM config store files. + * + * @param userSoftApConfiguration {@link SoftApConfiguration} representing user's + * SoftAp configuration + * @return Instance of {@link Builder} to enable chaining of the builder method. + */ + public @NonNull Builder setUserSoftApConfiguration( + @NonNull SoftApConfiguration userSoftApConfiguration) { + checkNotNull(userSoftApConfiguration); + mUserSoftApConfiguration = userSoftApConfiguration; + return this; + } + + /** + * Build an instance of {@link MigrationData}. + * + * @return Instance of {@link MigrationData}. + */ + public @NonNull MigrationData build() { + return new MigrationData(mUserSavedNetworkConfigurations, mUserSoftApConfiguration); + } + } + + private final List<WifiConfiguration> mUserSavedNetworkConfigurations; + private final SoftApConfiguration mUserSoftApConfiguration; + + private MigrationData( + @Nullable List<WifiConfiguration> userSavedNetworkConfigurations, + @Nullable SoftApConfiguration userSoftApConfiguration) { + mUserSavedNetworkConfigurations = userSavedNetworkConfigurations; + mUserSoftApConfiguration = userSoftApConfiguration; + } + + public static final @NonNull Parcelable.Creator<MigrationData> CREATOR = + new Parcelable.Creator<MigrationData>() { + @Override + public MigrationData createFromParcel(Parcel in) { + List<WifiConfiguration> userSavedNetworkConfigurations = + in.readArrayList(null); + SoftApConfiguration userSoftApConfiguration = in.readParcelable(null); + return new MigrationData( + userSavedNetworkConfigurations, userSoftApConfiguration); + } + + @Override + public MigrationData[] newArray(int size) { + return new MigrationData[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeList(mUserSavedNetworkConfigurations); + dest.writeParcelable(mUserSoftApConfiguration, flags); + } + + /** + * Returns list of all user's saved network configurations. + * + * Note: Only to be returned if there is any format change in how OEM persisted this info. + * @return List of {@link WifiConfiguration} representing the list of user's saved networks, + * or null if no migration necessary. + */ + @Nullable + public List<WifiConfiguration> getUserSavedNetworkConfigurations() { + return mUserSavedNetworkConfigurations; + } + + /** + * Returns user's softap configuration. + * + * Note: Only to be returned if there is any format change in how OEM persisted this info. + * @return {@link SoftApConfiguration} representing user's SoftAp configuration, + * or null if no migration necessary. + */ + @Nullable + public SoftApConfiguration getUserSoftApConfiguration() { + return mUserSoftApConfiguration; + } + } + + private WifiOemConfigStoreMigrationHook() { } + + /** + * Load data from OEM's config store. + * + * @return Instance of {@link MigrationData} for migrating data, null if no + * migration is necessary. + */ + @Nullable + public static MigrationData load() { + // Note: OEM's should add code to parse data from their config store format here! + return null; + } +} diff --git a/wifi/java/android/net/wifi/WifiScanner.java b/wifi/java/android/net/wifi/WifiScanner.java index 2c39c32ac81e..18533ef5b117 100644 --- a/wifi/java/android/net/wifi/WifiScanner.java +++ b/wifi/java/android/net/wifi/WifiScanner.java @@ -291,28 +291,46 @@ public class WifiScanner { @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_STACK) public final List<HiddenNetwork> hiddenNetworks = new ArrayList<>(); - /** period of background scan; in millisecond, 0 => single shot scan */ + /** + * period of background scan; in millisecond, 0 => single shot scan + * @deprecated Background scan support is removed. + */ + @Deprecated public int periodInMs; - /** must have a valid REPORT_EVENT value */ + /** + * must have a valid REPORT_EVENT value + * @deprecated Background scan support is removed. + */ + @Deprecated public int reportEvents; - /** defines number of bssids to cache from each scan */ + /** + * defines number of bssids to cache from each scan + * @deprecated Background scan support is removed. + */ + @Deprecated public int numBssidsPerScan; /** * defines number of scans to cache; use it with REPORT_EVENT_AFTER_BUFFER_FULL * to wake up at fixed interval + * @deprecated Background scan support is removed. */ + @Deprecated public int maxScansToCache; /** * if maxPeriodInMs is non zero or different than period, then this bucket is * a truncated binary exponential backoff bucket and the scan period will grow * exponentially as per formula: actual_period(N) = period * (2 ^ (N/stepCount)) * to maxPeriodInMs + * @deprecated Background scan support is removed. */ + @Deprecated public int maxPeriodInMs; /** * for truncated binary exponential back off bucket, number of scans to perform * for a given period + * @deprecated Background scan support is removed. */ + @Deprecated public int stepCount; /** * Flag to indicate if the scan settings are targeted for PNO scan. @@ -788,7 +806,9 @@ public class WifiScanner { /** * Framework co-ordinates scans across multiple apps; so it may not give exactly the * same period requested. If period of a scan is changed; it is reported by this event. + * @deprecated Background scan support is removed. */ + @Deprecated public void onPeriodChanged(int periodInMs); /** * reports results retrieved from background scan and single shot scans @@ -833,6 +853,7 @@ public class WifiScanner { * delivered to the listener. It is possible that onFullResult will not be called for all * results of the first scan if the listener was registered during the scan. * + * @param executor the Executor on which to run the callback. * @param listener specifies the object to report events to. This object is also treated as a * key for this request, and must also be specified to cancel the request. * Multiple requests should also not share this object. @@ -890,7 +911,9 @@ public class WifiScanner { * @param listener specifies the object to report events to. This object is also treated as a * key for this scan, and must also be specified to cancel the scan. Multiple * scans should also not share this object. + * @deprecated Background scan support is removed. */ + @Deprecated @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void startBackgroundScan(ScanSettings settings, ScanListener listener, WorkSource workSource) { @@ -910,7 +933,9 @@ public class WifiScanner { * stop an ongoing wifi scan * @param listener specifies which scan to cancel; must be same object as passed in {@link * #startBackgroundScan} + * @deprecated Background scan support is removed. */ + @Deprecated @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void stopBackgroundScan(ScanListener listener) { Objects.requireNonNull(listener, "listener cannot be null"); @@ -926,7 +951,9 @@ public class WifiScanner { /** * reports currently available scan results on appropriate listeners * @return true if all scan results were reported correctly + * @deprecated Background scan support is removed. */ + @Deprecated @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public boolean getScanResults() { validateChannel(); @@ -955,15 +982,32 @@ public class WifiScanner { * starts a single scan and reports results asynchronously * @param settings specifies various parameters for the scan; for more information look at * {@link ScanSettings} - * @param workSource WorkSource to blame for power usage * @param listener specifies the object to report events to. This object is also treated as a * key for this scan, and must also be specified to cancel the scan. Multiple * scans should also not share this object. + * @param workSource WorkSource to blame for power usage */ @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void startScan(ScanSettings settings, ScanListener listener, WorkSource workSource) { + startScan(settings, null, listener, workSource); + } + + /** + * starts a single scan and reports results asynchronously + * @param settings specifies various parameters for the scan; for more information look at + * {@link ScanSettings} + * @param executor the Executor on which to run the callback. + * @param listener specifies the object to report events to. This object is also treated as a + * key for this scan, and must also be specified to cancel the scan. Multiple + * scans should also not share this object. + * @param workSource WorkSource to blame for power usage + * @hide + */ + @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) + public void startScan(ScanSettings settings, @Nullable @CallbackExecutor Executor executor, + ScanListener listener, WorkSource workSource) { Objects.requireNonNull(listener, "listener cannot be null"); - int key = addListener(listener); + int key = addListener(listener, executor); if (key == INVALID_KEY) return; validateChannel(); Bundle scanParams = new Bundle(); @@ -1029,16 +1073,17 @@ public class WifiScanner { * {@link ScanSettings} * @param pnoSettings specifies various parameters for PNO; for more information look at * {@link PnoSettings} + * @param executor the Executor on which to run the callback. * @param listener specifies the object to report events to. This object is also treated as a * key for this scan, and must also be specified to cancel the scan. Multiple * scans should also not share this object. * {@hide} */ public void startConnectedPnoScan(ScanSettings scanSettings, PnoSettings pnoSettings, - PnoScanListener listener) { + @NonNull @CallbackExecutor Executor executor, PnoScanListener listener) { Objects.requireNonNull(listener, "listener cannot be null"); Objects.requireNonNull(pnoSettings, "pnoSettings cannot be null"); - int key = addListener(listener); + int key = addListener(listener, executor); if (key == INVALID_KEY) return; validateChannel(); pnoSettings.isConnected = true; @@ -1057,10 +1102,10 @@ public class WifiScanner { */ @RequiresPermission(android.Manifest.permission.NETWORK_STACK) public void startDisconnectedPnoScan(ScanSettings scanSettings, PnoSettings pnoSettings, - PnoScanListener listener) { + @NonNull @CallbackExecutor Executor executor, PnoScanListener listener) { Objects.requireNonNull(listener, "listener cannot be null"); Objects.requireNonNull(pnoSettings, "pnoSettings cannot be null"); - int key = addListener(listener); + int key = addListener(listener, executor); if (key == INVALID_KEY) return; validateChannel(); pnoSettings.isConnected = false; diff --git a/wifi/java/android/net/wifi/WifiSsid.java b/wifi/java/android/net/wifi/WifiSsid.java index 90756d860a21..704ae81f71aa 100644 --- a/wifi/java/android/net/wifi/WifiSsid.java +++ b/wifi/java/android/net/wifi/WifiSsid.java @@ -18,7 +18,7 @@ package android.net.wifi; import android.annotation.NonNull; import android.annotation.Nullable; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; diff --git a/wifi/java/android/net/wifi/WpsInfo.aidl b/wifi/java/android/net/wifi/WpsInfo.aidl deleted file mode 100644 index f5e4ebe4f1af..000000000000 --- a/wifi/java/android/net/wifi/WpsInfo.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2011, 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; - -parcelable WpsInfo; diff --git a/wifi/java/android/net/wifi/aware/Characteristics.aidl b/wifi/java/android/net/wifi/aware/Characteristics.aidl deleted file mode 100644 index 77305e9dae0a..000000000000 --- a/wifi/java/android/net/wifi/aware/Characteristics.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2016 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; - -parcelable Characteristics; diff --git a/wifi/java/android/net/wifi/aware/PublishConfig.aidl b/wifi/java/android/net/wifi/aware/PublishConfig.aidl deleted file mode 100644 index 2e6dd00b245a..000000000000 --- a/wifi/java/android/net/wifi/aware/PublishConfig.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2016 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; - -parcelable PublishConfig; diff --git a/wifi/java/android/net/wifi/aware/SubscribeConfig.aidl b/wifi/java/android/net/wifi/aware/SubscribeConfig.aidl deleted file mode 100644 index bd73d5ee5ecc..000000000000 --- a/wifi/java/android/net/wifi/aware/SubscribeConfig.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2016 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; - -parcelable SubscribeConfig; diff --git a/wifi/java/android/net/wifi/hotspot2/OsuProvider.aidl b/wifi/java/android/net/wifi/hotspot2/OsuProvider.aidl deleted file mode 100644 index 23d0f22e866b..000000000000 --- a/wifi/java/android/net/wifi/hotspot2/OsuProvider.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2017 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.hotspot2; - -parcelable OsuProvider; diff --git a/wifi/java/android/net/wifi/hotspot2/PasspointConfiguration.aidl b/wifi/java/android/net/wifi/hotspot2/PasspointConfiguration.aidl deleted file mode 100644 index 6b1cea8edb5a..000000000000 --- a/wifi/java/android/net/wifi/hotspot2/PasspointConfiguration.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2016, 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.hotspot2; - -parcelable PasspointConfiguration; diff --git a/wifi/java/android/net/wifi/hotspot2/PasspointConfiguration.java b/wifi/java/android/net/wifi/hotspot2/PasspointConfiguration.java index 5befb54ce50a..7c335fc323f5 100644 --- a/wifi/java/android/net/wifi/hotspot2/PasspointConfiguration.java +++ b/wifi/java/android/net/wifi/hotspot2/PasspointConfiguration.java @@ -17,6 +17,7 @@ package android.net.wifi.hotspot2; import android.annotation.Nullable; +import android.annotation.SystemApi; import android.net.wifi.hotspot2.pps.Credential; import android.net.wifi.hotspot2.pps.HomeSp; import android.net.wifi.hotspot2.pps.Policy; @@ -423,6 +424,73 @@ public final class PasspointConfiguration implements Parcelable { } /** + * The auto-join configuration specifies whether or not the Passpoint Configuration is + * considered for auto-connection. If true then yes, if false then it isn't considered as part + * of auto-connection - but can still be manually connected to. + */ + private boolean mIsAutoJoinEnabled = true; + + /** + * The mac randomization setting specifies whether a randomized or device MAC address will + * be used to connect to the passpoint network. If true, a randomized MAC will be used. + * Otherwise, the device MAC address will be used. + */ + private boolean mIsMacRandomizationEnabled = true; + + /** + * Configures the auto-association status of this Passpoint configuration. A value of true + * indicates that the configuration will be considered for auto-connection, a value of false + * indicates that only manual connection will work - the framework will not auto-associate to + * this Passpoint network. + * + * @param autoJoinEnabled true to be considered for framework auto-connection, false otherwise. + * @hide + */ + public void setAutoJoinEnabled(boolean autoJoinEnabled) { + mIsAutoJoinEnabled = autoJoinEnabled; + } + + /** + * Configures the MAC randomization setting for this Passpoint configuration. + * If set to true, the framework will use a randomized MAC address to connect to this Passpoint + * network. Otherwise, the framework will use the device MAC address. + * + * @param enabled true to use randomized MAC address, false to use device MAC address. + * @hide + */ + public void setMacRandomizationEnabled(boolean enabled) { + mIsMacRandomizationEnabled = enabled; + } + + /** + * Indicates whether the Passpoint configuration may be auto-connected to by the framework. A + * value of true indicates that auto-connection can happen, a value of false indicates that it + * cannot. However, even when auto-connection is not possible manual connection by the user is + * possible. + * + * @return the auto-join configuration: true for auto-connection (or join) enabled, false + * otherwise. + * @hide + */ + @SystemApi + public boolean isAutoJoinEnabled() { + return mIsAutoJoinEnabled; + } + + /** + * Indicates whether a randomized MAC address or device MAC address will be used for + * connections to this Passpoint network. If true, a randomized MAC address will be used. + * Otherwise, the device MAC address will be used. + * + * @return true for MAC randomization enabled. False for disabled. + * @hide + */ + @SystemApi + public boolean isMacRandomizationEnabled() { + return mIsMacRandomizationEnabled; + } + + /** * Constructor for creating PasspointConfiguration with default values. */ public PasspointConfiguration() {} @@ -464,6 +532,8 @@ public final class PasspointConfiguration implements Parcelable { mServiceFriendlyNames = source.mServiceFriendlyNames; mAaaServerTrustedNames = source.mAaaServerTrustedNames; mCarrierId = source.mCarrierId; + mIsAutoJoinEnabled = source.mIsAutoJoinEnabled; + mIsMacRandomizationEnabled = source.mIsMacRandomizationEnabled; } @Override @@ -493,6 +563,8 @@ public final class PasspointConfiguration implements Parcelable { (HashMap<String, String>) mServiceFriendlyNames); dest.writeBundle(bundle); dest.writeInt(mCarrierId); + dest.writeBoolean(mIsAutoJoinEnabled); + dest.writeBoolean(mIsMacRandomizationEnabled); } @Override @@ -523,6 +595,8 @@ public final class PasspointConfiguration implements Parcelable { && mUsageLimitDataLimit == that.mUsageLimitDataLimit && mUsageLimitTimeLimitInMinutes == that.mUsageLimitTimeLimitInMinutes && mCarrierId == that.mCarrierId + && mIsAutoJoinEnabled == that.mIsAutoJoinEnabled + && mIsMacRandomizationEnabled == that.mIsMacRandomizationEnabled && (mServiceFriendlyNames == null ? that.mServiceFriendlyNames == null : mServiceFriendlyNames.equals(that.mServiceFriendlyNames)); } @@ -533,7 +607,7 @@ public final class PasspointConfiguration implements Parcelable { mUpdateIdentifier, mCredentialPriority, mSubscriptionCreationTimeInMillis, mSubscriptionExpirationTimeInMillis, mUsageLimitUsageTimePeriodInMinutes, mUsageLimitStartTimeInMillis, mUsageLimitDataLimit, mUsageLimitTimeLimitInMinutes, - mServiceFriendlyNames, mCarrierId); + mServiceFriendlyNames, mCarrierId, mIsAutoJoinEnabled, mIsMacRandomizationEnabled); } @Override @@ -587,6 +661,8 @@ public final class PasspointConfiguration implements Parcelable { builder.append("ServiceFriendlyNames: ").append(mServiceFriendlyNames); } builder.append("CarrierId:" + mCarrierId); + builder.append("IsAutoJoinEnabled:" + mIsAutoJoinEnabled); + builder.append("mIsMacRandomizationEnabled:" + mIsMacRandomizationEnabled); return builder.toString(); } @@ -692,6 +768,8 @@ public final class PasspointConfiguration implements Parcelable { "serviceFriendlyNames"); config.setServiceFriendlyNames(friendlyNamesMap); config.mCarrierId = in.readInt(); + config.mIsAutoJoinEnabled = in.readBoolean(); + config.mIsMacRandomizationEnabled = in.readBoolean(); return config; } diff --git a/wifi/java/android/net/wifi/hotspot2/pps/Credential.aidl b/wifi/java/android/net/wifi/hotspot2/pps/Credential.aidl deleted file mode 100644 index 3d8e8330c2c4..000000000000 --- a/wifi/java/android/net/wifi/hotspot2/pps/Credential.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2016, 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.hotspot2.pps; - -parcelable Credential; diff --git a/wifi/java/android/net/wifi/hotspot2/pps/HomeSp.aidl b/wifi/java/android/net/wifi/hotspot2/pps/HomeSp.aidl deleted file mode 100644 index 6d343bde7081..000000000000 --- a/wifi/java/android/net/wifi/hotspot2/pps/HomeSp.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2016, 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.hotspot2.pps; - -parcelable HomeSp; diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pConfig.aidl b/wifi/java/android/net/wifi/p2p/WifiP2pConfig.aidl deleted file mode 100644 index ea3b2803d514..000000000000 --- a/wifi/java/android/net/wifi/p2p/WifiP2pConfig.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2011, 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.p2p; - -parcelable WifiP2pConfig; diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java b/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java index c9bca4f20f03..8fa9c3d6f1a6 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java @@ -19,7 +19,7 @@ package android.net.wifi.p2p; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.net.MacAddress; import android.net.wifi.WpsInfo; import android.os.Parcel; diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDevice.aidl b/wifi/java/android/net/wifi/p2p/WifiP2pDevice.aidl deleted file mode 100644 index 8790c6ffe903..000000000000 --- a/wifi/java/android/net/wifi/p2p/WifiP2pDevice.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2011, 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.p2p; - -parcelable WifiP2pDevice; diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java b/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java index 665c28ceea7c..02ed05fa83b9 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java @@ -18,7 +18,7 @@ package android.net.wifi.p2p; import android.annotation.NonNull; import android.annotation.Nullable; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.aidl b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.aidl deleted file mode 100644 index 6c79009315b5..000000000000 --- a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2011, 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.p2p; - -parcelable WifiP2pDeviceList; diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java index acf06fbac681..ededf67fec7f 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java @@ -16,10 +16,9 @@ package android.net.wifi.p2p; -import android.annotation.UnsupportedAppUsage; -import android.os.Parcelable; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; -import android.net.wifi.p2p.WifiP2pDevice; +import android.os.Parcelable; import android.text.TextUtils; import java.util.ArrayList; diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pGroup.aidl b/wifi/java/android/net/wifi/p2p/WifiP2pGroup.aidl deleted file mode 100644 index 403f2b19bfda..000000000000 --- a/wifi/java/android/net/wifi/p2p/WifiP2pGroup.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2011, 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.p2p; - -parcelable WifiP2pGroup; diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java b/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java index d8c50f2ed5f8..21f6704be0bb 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java @@ -17,7 +17,7 @@ package android.net.wifi.p2p; import android.annotation.Nullable; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pGroupList.java b/wifi/java/android/net/wifi/p2p/WifiP2pGroupList.java index 10fd09aa638f..cdb2806af0b1 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pGroupList.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pGroupList.java @@ -17,7 +17,7 @@ package android.net.wifi.p2p; import android.annotation.NonNull; import android.annotation.SystemApi; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; import android.util.LruCache; diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pInfo.aidl b/wifi/java/android/net/wifi/p2p/WifiP2pInfo.aidl deleted file mode 100644 index a347148622ff..000000000000 --- a/wifi/java/android/net/wifi/p2p/WifiP2pInfo.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2011, 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.p2p; - -parcelable WifiP2pInfo; diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java index 1f791f058dde..da9705f0461e 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java @@ -24,7 +24,7 @@ import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SystemApi; import android.annotation.SystemService; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.net.NetworkInfo; import android.net.wifi.WpsInfo; diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pProvDiscEvent.java b/wifi/java/android/net/wifi/p2p/WifiP2pProvDiscEvent.java index 153e03cc4d9d..d0fe92d5249d 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pProvDiscEvent.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pProvDiscEvent.java @@ -16,7 +16,7 @@ package android.net.wifi.p2p; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; /** * A class representing a Wi-Fi p2p provisional discovery request/response diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pWfdInfo.java b/wifi/java/android/net/wifi/p2p/WifiP2pWfdInfo.java index 4700b4a85508..1668c565ef9e 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pWfdInfo.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pWfdInfo.java @@ -19,7 +19,7 @@ package android.net.wifi.p2p; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; @@ -63,6 +63,9 @@ public final class WifiP2pWfdInfo implements Parcelable { * {@link #mDeviceInfo} & {@link #DEVICE_TYPE} is one of {@link #DEVICE_TYPE_WFD_SOURCE}, * {@link #DEVICE_TYPE_PRIMARY_SINK}, {@link #DEVICE_TYPE_SECONDARY_SINK} or * {@link #DEVICE_TYPE_SOURCE_OR_PRIMARY_SINK}. + * + * The bit definition is listed in 5.1.2 WFD Device Information Subelement in + * Wi-Fi Display Technical Specification. */ private static final int DEVICE_TYPE = 1 << 1 | 1 << 0; private static final int COUPLED_SINK_SUPPORT_AT_SOURCE = 1 << 2; @@ -71,6 +74,8 @@ public final class WifiP2pWfdInfo implements Parcelable { private static final int SESSION_AVAILABLE_BIT2 = 1 << 5; private static final int SESSION_AVAILABLE = SESSION_AVAILABLE_BIT2 | SESSION_AVAILABLE_BIT1; + /* The support of Content Protection using the HDCP system 2.0/2.1. */ + private static final int CONTENT_PROTECTION_SUPPORT = 1 << 8; private int mCtrlPort; @@ -159,6 +164,26 @@ public final class WifiP2pWfdInfo implements Parcelable { } } + /** + * @return true if Content Protection using the HDCP system 2.0/2.1 is supported. + */ + public boolean isContentProtectionSupported() { + return (mDeviceInfo & CONTENT_PROTECTION_SUPPORT) != 0; + } + + /** + * Sets whether Content Protection using the HDCP system 2.0/2.1 is supported. + * + * @param enabled true to indicate that Content Protection is supported, false otherwise. + */ + public void setContentProtectionSupported(boolean enabled) { + if (enabled) { + mDeviceInfo |= CONTENT_PROTECTION_SUPPORT; + } else { + mDeviceInfo &= ~CONTENT_PROTECTION_SUPPORT; + } + } + /** Returns the TCP port at which the WFD Device listens for RTSP messages. */ public int getControlPort() { return mCtrlPort; diff --git a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pDnsSdServiceInfo.java b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pDnsSdServiceInfo.java index e32c8e80ad1c..dad431c1ca2c 100644 --- a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pDnsSdServiceInfo.java +++ b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pDnsSdServiceInfo.java @@ -16,8 +16,8 @@ package android.net.wifi.p2p.nsd; -import android.annotation.UnsupportedAppUsage; -import android.net.nsd.DnsSdTxtRecord; +import android.compat.annotation.UnsupportedAppUsage; +import android.net.util.nsd.DnsSdTxtRecord; import android.os.Build; import android.text.TextUtils; diff --git a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceInfo.aidl b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceInfo.aidl deleted file mode 100644 index cf2cb4ae5eb4..000000000000 --- a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceInfo.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2012 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.p2p.servicediscovery; - -parcelable WifiP2pServiceInfo; diff --git a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceInfo.java b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceInfo.java index db0bdb81fef3..37b442baeb3f 100644 --- a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceInfo.java +++ b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceInfo.java @@ -16,7 +16,7 @@ package android.net.wifi.p2p.nsd; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Build; import android.os.Parcel; import android.os.Parcelable; diff --git a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceRequest.aidl b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceRequest.aidl deleted file mode 100644 index d5a1e8f505a9..000000000000 --- a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceRequest.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2012 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.p2p.servicediscovery; - -parcelable WifiP2pServiceRequest; diff --git a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceRequest.java b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceRequest.java index 87528c4180af..68cbb88037b0 100644 --- a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceRequest.java +++ b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pServiceRequest.java @@ -16,7 +16,7 @@ package android.net.wifi.p2p.nsd; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.net.wifi.p2p.WifiP2pManager; import android.os.Build; import android.os.Parcel; diff --git a/wifi/java/android/net/wifi/rtt/RangingRequest.aidl b/wifi/java/android/net/wifi/rtt/RangingRequest.aidl deleted file mode 100644 index 8053c9416aeb..000000000000 --- a/wifi/java/android/net/wifi/rtt/RangingRequest.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2017 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.rtt; - -parcelable RangingRequest; diff --git a/wifi/java/android/net/wifi/rtt/RangingResult.aidl b/wifi/java/android/net/wifi/rtt/RangingResult.aidl deleted file mode 100644 index ae295a610afa..000000000000 --- a/wifi/java/android/net/wifi/rtt/RangingResult.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2017 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.rtt; - -parcelable RangingResult; diff --git a/wifi/java/android/net/wifi/rtt/ResponderConfig.aidl b/wifi/java/android/net/wifi/rtt/ResponderConfig.aidl deleted file mode 100644 index fd3988aca06c..000000000000 --- a/wifi/java/android/net/wifi/rtt/ResponderConfig.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2017 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.rtt; - -parcelable ResponderConfig; diff --git a/wifi/java/android/net/wifi/rtt/ResponderLocation.java b/wifi/java/android/net/wifi/rtt/ResponderLocation.java index 970a75d7c418..218b2dcae71d 100644 --- a/wifi/java/android/net/wifi/rtt/ResponderLocation.java +++ b/wifi/java/android/net/wifi/rtt/ResponderLocation.java @@ -21,6 +21,7 @@ import static java.lang.annotation.RetentionPolicy.SOURCE; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.location.Address; import android.location.Location; @@ -1367,7 +1368,8 @@ public final class ResponderLocation implements Parcelable { * */ @Nullable - public SparseArray toCivicLocationSparseArray() { + @SuppressLint("ChangedType") + public SparseArray<String> toCivicLocationSparseArray() { if (mCivicLocation != null && mCivicLocation.isValid()) { return mCivicLocation.toSparseArray(); } else { diff --git a/wifi/java/android/net/wifi/wificond/DeviceWiphyCapabilities.java b/wifi/java/android/net/wifi/wificond/DeviceWiphyCapabilities.java new file mode 100644 index 000000000000..13ae3b322841 --- /dev/null +++ b/wifi/java/android/net/wifi/wificond/DeviceWiphyCapabilities.java @@ -0,0 +1,272 @@ +/* + * 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.wificond; + +import android.annotation.NonNull; +import android.annotation.SystemApi; +import android.net.wifi.ScanResult; +import android.os.Parcel; +import android.os.Parcelable; +import android.util.Log; + +import java.util.Objects; + +/** + * DeviceWiphyCapabilities for wificond + * + * @hide + */ +@SystemApi +public final class DeviceWiphyCapabilities implements Parcelable { + private static final String TAG = "DeviceWiphyCapabilities"; + + private boolean m80211nSupported; + private boolean m80211acSupported; + private boolean m80211axSupported; + private boolean mChannelWidth160MhzSupported; + private boolean mChannelWidth80p80MhzSupported; + private int mMaxNumberTxSpatialStreams; + private int mMaxNumberRxSpatialStreams; + + + /** public constructor */ + public DeviceWiphyCapabilities() { + m80211nSupported = false; + m80211acSupported = false; + m80211axSupported = false; + mChannelWidth160MhzSupported = false; + mChannelWidth80p80MhzSupported = false; + mMaxNumberTxSpatialStreams = 1; + mMaxNumberRxSpatialStreams = 1; + } + + /** + * Get the IEEE 802.11 standard support + * + * @param standard the IEEE 802.11 standard to check on its support. + * valid values from {@link ScanResult}'s {@code WIFI_STANDARD_} + * @return {@code true} if supported, {@code false} otherwise. + */ + public boolean isWifiStandardSupported(int standard) { + switch (standard) { + case ScanResult.WIFI_STANDARD_LEGACY: + return true; + case ScanResult.WIFI_STANDARD_11N: + return m80211nSupported; + case ScanResult.WIFI_STANDARD_11AC: + return m80211acSupported; + case ScanResult.WIFI_STANDARD_11AX: + return m80211axSupported; + default: + Log.e(TAG, "isWifiStandardSupported called with invalid standard: " + standard); + return false; + } + } + + /** + * Set the IEEE 802.11 standard support + * + * @param standard the IEEE 802.11 standard to set its support. + * valid values from {@link ScanResult}'s {@code WIFI_STANDARD_} + * @param support {@code true} if supported, {@code false} otherwise. + */ + public void setWifiStandardSupport(int standard, boolean support) { + switch (standard) { + case ScanResult.WIFI_STANDARD_11N: + m80211nSupported = support; + break; + case ScanResult.WIFI_STANDARD_11AC: + m80211acSupported = support; + break; + case ScanResult.WIFI_STANDARD_11AX: + m80211axSupported = support; + break; + default: + Log.e(TAG, "setWifiStandardSupport called with invalid standard: " + standard); + } + } + + /** + * Get the support for channel bandwidth + * + * @param chWidth valid values from {@link ScanResult}'s {@code CHANNEL_WIDTH_} + * + * @return {@code true} if supported, {@code false} otherwise. + */ + public boolean isChannelWidthSupported(int chWidth) { + switch (chWidth) { + case ScanResult.CHANNEL_WIDTH_20MHZ: + return true; + case ScanResult.CHANNEL_WIDTH_40MHZ: + return (m80211nSupported || m80211acSupported || m80211axSupported); + case ScanResult.CHANNEL_WIDTH_80MHZ: + return (m80211acSupported || m80211axSupported); + case ScanResult.CHANNEL_WIDTH_160MHZ: + return mChannelWidth160MhzSupported; + case ScanResult.CHANNEL_WIDTH_80MHZ_PLUS_MHZ: + return mChannelWidth80p80MhzSupported; + default: + Log.e(TAG, "isChannelWidthSupported called with invalid channel width: " + chWidth); + } + return false; + } + + /** + * Set support for channel bandwidth + * + * @param chWidth valid values are {@link ScanResult#CHANNEL_WIDTH_160MHZ} and + * {@link ScanResult#CHANNEL_WIDTH_80MHZ_PLUS_MHZ} + * @param support {@code true} if supported, {@code false} otherwise. + */ + public void setChannelWidthSupported(int chWidth, boolean support) { + switch (chWidth) { + case ScanResult.CHANNEL_WIDTH_160MHZ: + mChannelWidth160MhzSupported = support; + break; + case ScanResult.CHANNEL_WIDTH_80MHZ_PLUS_MHZ: + mChannelWidth80p80MhzSupported = support; + break; + default: + Log.e(TAG, "setChannelWidthSupported called with Invalid channel width: " + + chWidth); + } + } + + /** + * Get maximum number of transmit spatial streams + * + * @return number of spatial streams + */ + public int getMaxNumberTxSpatialStreams() { + return mMaxNumberTxSpatialStreams; + } + + /** + * Set maximum number of transmit spatial streams + * + * @param streams number of spatial streams + */ + public void setMaxNumberTxSpatialStreams(int streams) { + mMaxNumberTxSpatialStreams = streams; + } + + /** + * Get maximum number of receive spatial streams + * + * @return number of streams + */ + public int getMaxNumberRxSpatialStreams() { + return mMaxNumberRxSpatialStreams; + } + + /** + * Set maximum number of receive spatial streams + * + * @param streams number of streams + */ + public void setMaxNumberRxSpatialStreams(int streams) { + mMaxNumberRxSpatialStreams = streams; + } + + /** override comparator */ + @Override + public boolean equals(Object rhs) { + if (this == rhs) return true; + if (!(rhs instanceof DeviceWiphyCapabilities)) { + return false; + } + DeviceWiphyCapabilities capa = (DeviceWiphyCapabilities) rhs; + + return m80211nSupported == capa.m80211nSupported + && m80211acSupported == capa.m80211acSupported + && m80211axSupported == capa.m80211axSupported + && mChannelWidth160MhzSupported == capa.mChannelWidth160MhzSupported + && mChannelWidth80p80MhzSupported == capa.mChannelWidth80p80MhzSupported + && mMaxNumberTxSpatialStreams == capa.mMaxNumberTxSpatialStreams + && mMaxNumberRxSpatialStreams == capa.mMaxNumberRxSpatialStreams; + } + + /** override hash code */ + @Override + public int hashCode() { + return Objects.hash(m80211nSupported, m80211acSupported, m80211axSupported, + mChannelWidth160MhzSupported, mChannelWidth80p80MhzSupported, + mMaxNumberTxSpatialStreams, mMaxNumberRxSpatialStreams); + } + + /** implement Parcelable interface */ + @Override + public int describeContents() { + return 0; + } + + /** + * implement Parcelable interface + * |flags| is ignored. + */ + @Override + public void writeToParcel(@NonNull Parcel out, int flags) { + out.writeBoolean(m80211nSupported); + out.writeBoolean(m80211acSupported); + out.writeBoolean(m80211axSupported); + out.writeBoolean(mChannelWidth160MhzSupported); + out.writeBoolean(mChannelWidth80p80MhzSupported); + out.writeInt(mMaxNumberTxSpatialStreams); + out.writeInt(mMaxNumberRxSpatialStreams); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("m80211nSupported:").append(m80211nSupported ? "Yes" : "No"); + sb.append("m80211acSupported:").append(m80211acSupported ? "Yes" : "No"); + sb.append("m80211axSupported:").append(m80211axSupported ? "Yes" : "No"); + sb.append("mChannelWidth160MhzSupported: ") + .append(mChannelWidth160MhzSupported ? "Yes" : "No"); + sb.append("mChannelWidth80p80MhzSupported: ") + .append(mChannelWidth80p80MhzSupported ? "Yes" : "No"); + sb.append("mMaxNumberTxSpatialStreams: ").append(mMaxNumberTxSpatialStreams); + sb.append("mMaxNumberRxSpatialStreams: ").append(mMaxNumberRxSpatialStreams); + + return sb.toString(); + } + + /** implement Parcelable interface */ + public static final @NonNull Parcelable.Creator<DeviceWiphyCapabilities> CREATOR = + new Parcelable.Creator<DeviceWiphyCapabilities>() { + /** + * Caller is responsible for providing a valid parcel. + */ + @Override + public DeviceWiphyCapabilities createFromParcel(Parcel in) { + DeviceWiphyCapabilities capabilities = new DeviceWiphyCapabilities(); + capabilities.m80211nSupported = in.readBoolean(); + capabilities.m80211acSupported = in.readBoolean(); + capabilities.m80211axSupported = in.readBoolean(); + capabilities.mChannelWidth160MhzSupported = in.readBoolean(); + capabilities.mChannelWidth80p80MhzSupported = in.readBoolean(); + capabilities.mMaxNumberTxSpatialStreams = in.readInt(); + capabilities.mMaxNumberRxSpatialStreams = in.readInt(); + return capabilities; + } + + @Override + public DeviceWiphyCapabilities[] newArray(int size) { + return new DeviceWiphyCapabilities[size]; + } + }; +} diff --git a/wifi/java/android/net/wifi/wificond/WifiCondManager.java b/wifi/java/android/net/wifi/wificond/WifiCondManager.java index 237f326d0200..3b587f69cf91 100644 --- a/wifi/java/android/net/wifi/wificond/WifiCondManager.java +++ b/wifi/java/android/net/wifi/wificond/WifiCondManager.java @@ -1097,6 +1097,22 @@ public class WifiCondManager { } /** + * Get the device phy capabilities for a given interface + */ + @Nullable public DeviceWiphyCapabilities getDeviceWiphyCapabilities(@NonNull String ifaceName) { + if (mWificond == null) { + Log.e(TAG, "Can not query for device wiphy capabilities at this time"); + return null; + } + + try { + return mWificond.getDeviceWiphyCapabilities(ifaceName); + } catch (RemoteException e) { + return null; + } + } + + /** * Register the provided callback handler for SoftAp events. Note that the Soft AP itself is * configured using {@link #setupInterfaceForSoftApMode(String)}. * @@ -1200,6 +1216,70 @@ public class WifiCondManager { mSendMgmtFrameInProgress.set(false); } + /** + * OEM parsed security type + */ + public static class OemSecurityType { + /** The protocol defined in {@link android.net.wifi.WifiAnnotations.Protocol}. */ + public final @WifiAnnotations.Protocol int protocol; + /** + * Supported key management types defined + * in {@link android.net.wifi.WifiAnnotations.KeyMgmt}. + */ + @NonNull public final List<Integer> keyManagement; + /** + * Supported pairwise cipher types defined + * in {@link android.net.wifi.WifiAnnotations.Cipher}. + */ + @NonNull public final List<Integer> pairwiseCipher; + /** The group cipher type defined in {@link android.net.wifi.WifiAnnotations.Cipher}. */ + public final @WifiAnnotations.Cipher int groupCipher; + /** + * Default constructor for OemSecurityType + * + * @param protocol The protocol defined in + * {@link android.net.wifi.WifiAnnotations.Protocol}. + * @param keyManagement Supported key management types defined + * in {@link android.net.wifi.WifiAnnotations.KeyMgmt}. + * @param pairwiseCipher Supported pairwise cipher types defined + * in {@link android.net.wifi.WifiAnnotations.Cipher}. + * @param groupCipher The group cipher type defined + * in {@link android.net.wifi.WifiAnnotations.Cipher}. + */ + public OemSecurityType( + @WifiAnnotations.Protocol int protocol, + @NonNull List<Integer> keyManagement, + @NonNull List<Integer> pairwiseCipher, + @WifiAnnotations.Cipher int groupCipher) { + this.protocol = protocol; + this.keyManagement = (keyManagement != null) + ? keyManagement : new ArrayList<Integer>(); + this.pairwiseCipher = (pairwiseCipher != null) + ? pairwiseCipher : new ArrayList<Integer>(); + this.groupCipher = groupCipher; + } + } + + /** + * OEM information element parser for security types not parsed by the framework. + * + * The OEM method should use the method inputs {@code id}, {@code idExt}, and {@code bytes} + * to perform the parsing. The method should place the results in an OemSecurityType objct. + * + * @param id The information element id. + * @param idExt The information element extension id. This is valid only when id is + * the extension id, {@code 255}. + * @param bytes The raw bytes of information element data, 'Element ID' and 'Length' are + * stripped off already. + * @return an OemSecurityType object if this IE is parsed successfully, null otherwise. + */ + @Nullable public static OemSecurityType parseOemSecurityTypeElement( + int id, + int idExt, + @NonNull byte[] bytes) { + return null; + } + /** @hide **/ public static class WifiGenerationCapabilities { |