summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xapi/system-current.txt24
-rw-r--r--wifi/java/android/net/wifi/wificond/NativeScanResult.java134
-rw-r--r--wifi/java/android/net/wifi/wificond/NativeWifiClient.java31
-rw-r--r--wifi/java/android/net/wifi/wificond/WifiCondManager.java2
-rw-r--r--wifi/tests/src/android/net/wifi/wificond/WifiCondManagerTest.java4
5 files changed, 153 insertions, 42 deletions
diff --git a/api/system-current.txt b/api/system-current.txt
index 00878308bdcd..c87f462e8193 100755
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -8242,8 +8242,8 @@ package android.net.wifi.wificond {
public final class NativeScanResult implements android.os.Parcelable {
ctor public NativeScanResult();
method public int describeContents();
- method @NonNull public byte[] getBssid();
- method @NonNull public int getCapabilities();
+ method @Nullable public android.net.MacAddress getBssid();
+ method public int getCapabilities();
method public int getFrequencyMhz();
method @NonNull public byte[] getInformationElements();
method @NonNull public java.util.List<android.net.wifi.wificond.RadioChainInfo> getRadioChainInfos();
@@ -8252,15 +8252,31 @@ package android.net.wifi.wificond {
method public long getTsf();
method public boolean isAssociated();
method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field public static final int BSS_CAPABILITY_APSD = 2048; // 0x800
+ field public static final int BSS_CAPABILITY_CF_POLLABLE = 4; // 0x4
+ field public static final int BSS_CAPABILITY_CF_POLL_REQUEST = 8; // 0x8
+ field public static final int BSS_CAPABILITY_CHANNEL_AGILITY = 128; // 0x80
+ field public static final int BSS_CAPABILITY_DELAYED_BLOCK_ACK = 16384; // 0x4000
+ field public static final int BSS_CAPABILITY_DSSS_OFDM = 8192; // 0x2000
+ field public static final int BSS_CAPABILITY_ESS = 1; // 0x1
+ field public static final int BSS_CAPABILITY_IBSS = 2; // 0x2
+ field public static final int BSS_CAPABILITY_IMMEDIATE_BLOCK_ACK = 32768; // 0x8000
+ field public static final int BSS_CAPABILITY_PBCC = 64; // 0x40
+ field public static final int BSS_CAPABILITY_PRIVACY = 16; // 0x10
+ field public static final int BSS_CAPABILITY_QOS = 512; // 0x200
+ field public static final int BSS_CAPABILITY_RADIO_MANAGEMENT = 4096; // 0x1000
+ field public static final int BSS_CAPABILITY_SHORT_PREAMBLE = 32; // 0x20
+ field public static final int BSS_CAPABILITY_SHORT_SLOT_TIME = 1024; // 0x400
+ field public static final int BSS_CAPABILITY_SPECTRUM_MANAGEMENT = 256; // 0x100
field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.wificond.NativeScanResult> CREATOR;
}
public final class NativeWifiClient implements android.os.Parcelable {
- ctor public NativeWifiClient(@NonNull byte[]);
+ ctor public NativeWifiClient(@Nullable android.net.MacAddress);
method public int describeContents();
+ method @Nullable public android.net.MacAddress getMacAddress();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.wificond.NativeWifiClient> CREATOR;
- field @NonNull public final byte[] macAddress;
}
public final class PnoNetwork implements android.os.Parcelable {
diff --git a/wifi/java/android/net/wifi/wificond/NativeScanResult.java b/wifi/java/android/net/wifi/wificond/NativeScanResult.java
index 7cc617d61b00..bd99476afe43 100644
--- a/wifi/java/android/net/wifi/wificond/NativeScanResult.java
+++ b/wifi/java/android/net/wifi/wificond/NativeScanResult.java
@@ -16,14 +16,21 @@
package android.net.wifi.wificond;
+import android.annotation.IntDef;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.annotation.SystemApi;
+import android.net.MacAddress;
import android.os.Parcel;
import android.os.Parcelable;
+import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
@@ -33,6 +40,8 @@ import java.util.List;
*/
@SystemApi
public final class NativeScanResult implements Parcelable {
+ private static final String TAG = "NativeScanResult";
+
/** @hide */
@VisibleForTesting
public byte[] ssid;
@@ -53,7 +62,7 @@ public final class NativeScanResult implements Parcelable {
public long tsf;
/** @hide */
@VisibleForTesting
- public int capability;
+ @BssCapabilityBits public int capability;
/** @hide */
@VisibleForTesting
public boolean associated;
@@ -71,14 +80,17 @@ public final class NativeScanResult implements Parcelable {
}
/**
- * Returns raw bytes representing the MAC address (BSSID) of the AP represented by this scan
- * result.
+ * Returns the MAC address (BSSID) of the AP represented by this scan result.
*
- * @return a byte array, possibly null or containing the incorrect number of bytes for a MAC
- * address.
+ * @return a MacAddress or null on error.
*/
- @NonNull public byte[] getBssid() {
- return bssid;
+ @Nullable public MacAddress getBssid() {
+ try {
+ return MacAddress.fromBytes(bssid);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + Arrays.toString(bssid), e);
+ return null;
+ }
}
/**
@@ -127,31 +139,103 @@ public final class NativeScanResult implements Parcelable {
return associated;
}
+ /** @hide */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef(flag = true, prefix = {"BSS_CAPABILITY_"},
+ value = {BSS_CAPABILITY_ESS,
+ BSS_CAPABILITY_IBSS,
+ BSS_CAPABILITY_CF_POLLABLE,
+ BSS_CAPABILITY_CF_POLL_REQUEST,
+ BSS_CAPABILITY_PRIVACY,
+ BSS_CAPABILITY_SHORT_PREAMBLE,
+ BSS_CAPABILITY_PBCC,
+ BSS_CAPABILITY_CHANNEL_AGILITY,
+ BSS_CAPABILITY_SPECTRUM_MANAGEMENT,
+ BSS_CAPABILITY_QOS,
+ BSS_CAPABILITY_SHORT_SLOT_TIME,
+ BSS_CAPABILITY_APSD,
+ BSS_CAPABILITY_RADIO_MANAGEMENT,
+ BSS_CAPABILITY_DSSS_OFDM,
+ BSS_CAPABILITY_DELAYED_BLOCK_ACK,
+ BSS_CAPABILITY_IMMEDIATE_BLOCK_ACK
+ })
+ public @interface BssCapabilityBits { }
+
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): ESS.
+ */
+ public static final int BSS_CAPABILITY_ESS = 0x1 << 0;
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): IBSS.
+ */
+ public static final int BSS_CAPABILITY_IBSS = 0x1 << 1;
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): CF Pollable.
+ */
+ public static final int BSS_CAPABILITY_CF_POLLABLE = 0x1 << 2;
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): CF-Poll Request.
+ */
+ public static final int BSS_CAPABILITY_CF_POLL_REQUEST = 0x1 << 3;
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): Privacy.
+ */
+ public static final int BSS_CAPABILITY_PRIVACY = 0x1 << 4;
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): Short Preamble.
+ */
+ public static final int BSS_CAPABILITY_SHORT_PREAMBLE = 0x1 << 5;
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): PBCC.
+ */
+ public static final int BSS_CAPABILITY_PBCC = 0x1 << 6;
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): Channel Agility.
+ */
+ public static final int BSS_CAPABILITY_CHANNEL_AGILITY = 0x1 << 7;
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): Spectrum Management.
+ */
+ public static final int BSS_CAPABILITY_SPECTRUM_MANAGEMENT = 0x1 << 8;
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): QoS.
+ */
+ public static final int BSS_CAPABILITY_QOS = 0x1 << 9;
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): Short Slot Time.
+ */
+ public static final int BSS_CAPABILITY_SHORT_SLOT_TIME = 0x1 << 10;
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): APSD.
+ */
+ public static final int BSS_CAPABILITY_APSD = 0x1 << 11;
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): Radio Management.
+ */
+ public static final int BSS_CAPABILITY_RADIO_MANAGEMENT = 0x1 << 12;
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): DSSS-OFDM.
+ */
+ public static final int BSS_CAPABILITY_DSSS_OFDM = 0x1 << 13;
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): Delayed Block Ack.
+ */
+ public static final int BSS_CAPABILITY_DELAYED_BLOCK_ACK = 0x1 << 14;
+ /**
+ * BSS capability bit (see IEEE Std 802.11: 9.4.1.4): Immediate Block Ack.
+ */
+ public static final int BSS_CAPABILITY_IMMEDIATE_BLOCK_ACK = 0x1 << 15;
+
/**
* Returns the capabilities of the AP repseresented by this scan result as advertised in the
* received probe response or beacon.
*
- * This is a bit mask describing the capabilities of a BSS. See IEEE Std 802.11: 9.4.1.4:
- * Bit 0 - ESS
- * Bit 1 - IBSS
- * Bit 2 - CF Pollable
- * Bit 3 - CF-Poll Request
- * Bit 4 - Privacy
- * Bit 5 - Short Preamble
- * Bit 6 - PBCC
- * Bit 7 - Channel Agility
- * Bit 8 - Spectrum Management
- * Bit 9 - QoS
- * Bit 10 - Short Slot Time
- * Bit 11 - APSD
- * Bit 12 - Radio Measurement
- * Bit 13 - DSSS-OFDM
- * Bit 14 - Delayed Block Ack
- * Bit 15 - Immediate Block Ack
+ * This is a bit mask describing the capabilities of a BSS. See IEEE Std 802.11: 9.4.1.4: one
+ * of the {@code BSS_CAPABILITY_*} flags.
*
* @return a bit mask of capabilities.
*/
- @NonNull public int getCapabilities() {
+ @BssCapabilityBits public int getCapabilities() {
return capability;
}
diff --git a/wifi/java/android/net/wifi/wificond/NativeWifiClient.java b/wifi/java/android/net/wifi/wificond/NativeWifiClient.java
index 916c11579075..9ad2a2769add 100644
--- a/wifi/java/android/net/wifi/wificond/NativeWifiClient.java
+++ b/wifi/java/android/net/wifi/wificond/NativeWifiClient.java
@@ -17,11 +17,13 @@
package android.net.wifi.wificond;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.annotation.SystemApi;
+import android.net.MacAddress;
import android.os.Parcel;
import android.os.Parcelable;
-import java.util.Arrays;
+import java.util.Objects;
/**
* Structure providing information about clients (STAs) associated with a SoftAp.
@@ -30,16 +32,21 @@ import java.util.Arrays;
*/
@SystemApi
public final class NativeWifiClient implements Parcelable {
+ private final MacAddress mMacAddress;
+
/**
- * The raw bytes of the MAC address of the client (STA) represented by this object.
+ * The MAC address of the client (STA) represented by this object. The MAC address may be null
+ * in case of an error.
*/
- @NonNull public final byte[] macAddress;
+ @Nullable public MacAddress getMacAddress() {
+ return mMacAddress;
+ }
/**
* Construct a native Wi-Fi client.
*/
- public NativeWifiClient(@NonNull byte[] macAddress) {
- this.macAddress = macAddress;
+ public NativeWifiClient(@Nullable MacAddress macAddress) {
+ this.mMacAddress = macAddress;
}
/** override comparator */
@@ -50,13 +57,13 @@ public final class NativeWifiClient implements Parcelable {
return false;
}
NativeWifiClient other = (NativeWifiClient) rhs;
- return Arrays.equals(macAddress, other.macAddress);
+ return Objects.equals(mMacAddress, other.mMacAddress);
}
/** override hash code */
@Override
public int hashCode() {
- return Arrays.hashCode(macAddress);
+ return mMacAddress.hashCode();
}
/** implement Parcelable interface */
@@ -71,7 +78,7 @@ public final class NativeWifiClient implements Parcelable {
*/
@Override
public void writeToParcel(@NonNull Parcel out, int flags) {
- out.writeByteArray(macAddress);
+ out.writeByteArray(mMacAddress.toByteArray());
}
/** implement Parcelable interface */
@@ -79,9 +86,11 @@ public final class NativeWifiClient implements Parcelable {
new Parcelable.Creator<NativeWifiClient>() {
@Override
public NativeWifiClient createFromParcel(Parcel in) {
- byte[] macAddress = in.createByteArray();
- if (macAddress == null) {
- macAddress = new byte[0];
+ MacAddress macAddress;
+ try {
+ macAddress = MacAddress.fromBytes(in.createByteArray());
+ } catch (IllegalArgumentException e) {
+ macAddress = null;
}
return new NativeWifiClient(macAddress);
}
diff --git a/wifi/java/android/net/wifi/wificond/WifiCondManager.java b/wifi/java/android/net/wifi/wificond/WifiCondManager.java
index d542e64d496d..61f18e0b7191 100644
--- a/wifi/java/android/net/wifi/wificond/WifiCondManager.java
+++ b/wifi/java/android/net/wifi/wificond/WifiCondManager.java
@@ -368,7 +368,7 @@ public class WifiCondManager {
public void onConnectedClientsChanged(NativeWifiClient client, boolean isConnected) {
if (mVerboseLoggingEnabled) {
Log.d(TAG, "onConnectedClientsChanged called with "
- + client.macAddress + " isConnected: " + isConnected);
+ + client.getMacAddress() + " isConnected: " + isConnected);
}
Binder.clearCallingIdentity();
diff --git a/wifi/tests/src/android/net/wifi/wificond/WifiCondManagerTest.java b/wifi/tests/src/android/net/wifi/wificond/WifiCondManagerTest.java
index 603cec695e1d..b745a341b459 100644
--- a/wifi/tests/src/android/net/wifi/wificond/WifiCondManagerTest.java
+++ b/wifi/tests/src/android/net/wifi/wificond/WifiCondManagerTest.java
@@ -38,6 +38,7 @@ import static org.mockito.Mockito.when;
import android.app.AlarmManager;
import android.app.test.TestAlarmManager;
import android.content.Context;
+import android.net.MacAddress;
import android.net.wifi.ScanResult;
import android.net.wifi.SoftApInfo;
import android.net.wifi.WifiConfiguration;
@@ -119,7 +120,8 @@ public class WifiCondManagerTest {
private static final String TEST_QUOTED_SSID_2 = "\"testSsid2\"";
private static final int[] TEST_FREQUENCIES_1 = {};
private static final int[] TEST_FREQUENCIES_2 = {2500, 5124};
- private static final byte[] TEST_RAW_MAC_BYTES = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
+ private static final MacAddress TEST_RAW_MAC_BYTES = MacAddress.fromBytes(
+ new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05});
private static final List<byte[]> SCAN_HIDDEN_NETWORK_SSID_LIST =
new ArrayList<byte[]>() {{