diff options
author | Xiao Ma <xiaom@google.com> | 2020-04-02 23:16:04 +0900 |
---|---|---|
committer | Xiao Ma <xiaom@google.com> | 2020-04-07 11:36:06 +0900 |
commit | 12cbeff3c68c4c62ebaaf966c3628105489489db (patch) | |
tree | da54a6d9edebf68203ea885aa35c2f9c432a855a /common/moduleutils/src | |
parent | 7d3fbd8b33327f9d12ea48b3b4f88332e0b5f379 (diff) |
Add bssid field in the ScanResultInfo class.
This change adds a new filed: bssid in the ScanResultInfo class
which are encapsulated by WiFi when connecting to AP successfully,
using current connected AP's bssid as a hint to determine whether
L2 roaming happened or not. Also adding @NonNull annotation for
fields, methods and constructor params.
Bug: 131797393
Test: atest NetworkStackIntegrationTests NetworkStackTests
Test: atest FrameworksNetTests
Change-Id: Ia11f1954124f45f9586495f6be7fb7fb3430ae97
Diffstat (limited to 'common/moduleutils/src')
-rw-r--r-- | common/moduleutils/src/android/net/shared/ProvisioningConfiguration.java | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/common/moduleutils/src/android/net/shared/ProvisioningConfiguration.java b/common/moduleutils/src/android/net/shared/ProvisioningConfiguration.java index 17b3ded..c349fa7 100644 --- a/common/moduleutils/src/android/net/shared/ProvisioningConfiguration.java +++ b/common/moduleutils/src/android/net/shared/ProvisioningConfiguration.java @@ -231,7 +231,11 @@ public class ProvisioningConfiguration { * InformationElements fields of ScanResult. */ public static class ScanResultInfo { + @NonNull private final String mSsid; + @NonNull + private final String mBssid; + @NonNull private final List<InformationElement> mInformationElements; /** @@ -240,6 +244,7 @@ public class ProvisioningConfiguration { */ public static class InformationElement { private final int mId; + @NonNull private final byte[] mPayload; public InformationElement(int id, @NonNull ByteBuffer payload) { @@ -257,6 +262,7 @@ public class ProvisioningConfiguration { /** * Get the specific content of the information element. */ + @NonNull public ByteBuffer getPayload() { return ByteBuffer.wrap(mPayload).asReadOnlyBuffer(); } @@ -293,6 +299,7 @@ public class ProvisioningConfiguration { * Create an instance of {@link InformationElement} based on the contents of the * specified {@link InformationElementParcelable}. */ + @Nullable public static InformationElement fromStableParcelable(InformationElementParcelable p) { if (p == null) return null; return new InformationElement(p.id, @@ -300,8 +307,12 @@ public class ProvisioningConfiguration { } } - public ScanResultInfo(String ssid, @NonNull List<InformationElement> informationElements) { + public ScanResultInfo(@NonNull String ssid, @NonNull String bssid, + @NonNull List<InformationElement> informationElements) { + Objects.requireNonNull(ssid, "ssid must not be null."); + Objects.requireNonNull(bssid, "bssid must not be null."); mSsid = ssid; + mBssid = bssid; mInformationElements = Collections.unmodifiableList(new ArrayList<>(informationElements)); } @@ -309,13 +320,23 @@ public class ProvisioningConfiguration { /** * Get the scanned network name. */ + @NonNull public String getSsid() { return mSsid; } /** + * Get the address of the access point. + */ + @NonNull + public String getBssid() { + return mBssid; + } + + /** * Get all information elements found in the beacon. */ + @NonNull public List<InformationElement> getInformationElements() { return mInformationElements; } @@ -324,6 +345,7 @@ public class ProvisioningConfiguration { public String toString() { StringBuffer str = new StringBuffer(); str.append("SSID: ").append(mSsid); + str.append(", BSSID: ").append(mBssid); str.append(", Information Elements: {"); for (InformationElement ie : mInformationElements) { str.append("[").append(ie.toString()).append("]"); @@ -338,12 +360,13 @@ public class ProvisioningConfiguration { if (!(o instanceof ScanResultInfo)) return false; ScanResultInfo other = (ScanResultInfo) o; return Objects.equals(mSsid, other.mSsid) + && Objects.equals(mBssid, other.mBssid) && mInformationElements.equals(other.mInformationElements); } @Override public int hashCode() { - return Objects.hash(mSsid, mInformationElements); + return Objects.hash(mSsid, mBssid, mInformationElements); } /** @@ -352,6 +375,7 @@ public class ProvisioningConfiguration { public ScanResultInfoParcelable toStableParcelable() { final ScanResultInfoParcelable p = new ScanResultInfoParcelable(); p.ssid = mSsid; + p.bssid = mBssid; p.informationElements = toParcelableArray(mInformationElements, InformationElement::toStableParcelable, InformationElementParcelable.class); return p; @@ -366,11 +390,10 @@ public class ProvisioningConfiguration { final List<InformationElement> ies = new ArrayList<InformationElement>(); ies.addAll(fromParcelableArray(p.informationElements, InformationElement::fromStableParcelable)); - return new ScanResultInfo(p.ssid, ies); + return new ScanResultInfo(p.ssid, p.bssid, ies); } - private static byte[] convertToByteArray(final ByteBuffer buffer) { - if (buffer == null) return null; + private static byte[] convertToByteArray(@NonNull final ByteBuffer buffer) { final byte[] bytes = new byte[buffer.limit()]; final ByteBuffer copy = buffer.asReadOnlyBuffer(); try { |