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

Commit a63c6a36 authored by Christine Hallstrom's avatar Christine Hallstrom
Browse files

Allow constructing BluetoothDevice with anonymous address type

Define private value for anonymous address type defined in Bluetooth
Core 5.4 spec.

Value added to IntDef is private in BluetoothDevice class because it should
not be allowed to be used to create BluetoothDevice object by
application, and is passed directly from native in onScanResult
callback. Package private constructor not an option as is constructed from different package in the regression being addressed by this CL.

Test: m .
Test: manual: scan anonymous advertisement and ensure scan result is
delivered to application
Flag: EXEMPT fix for unflagged regression
Bug: 296988500

Change-Id: I8168c370ec63f48acd535ea4ef05c6d5e58c2a2d
parent be229afb
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -1326,6 +1326,7 @@ public final class BluetoothDevice implements Parcelable, Attributable {
            value = {
                ADDRESS_TYPE_PUBLIC,
                ADDRESS_TYPE_RANDOM,
                ADDRESS_TYPE_ANONYMOUS,
                ADDRESS_TYPE_UNKNOWN,
            })
    public @interface AddressType {}
@@ -1339,6 +1340,9 @@ public final class BluetoothDevice implements Parcelable, Attributable {
    /** Address type is unknown or unavailable */
    public static final int ADDRESS_TYPE_UNKNOWN = 0xFFFF;

    /** Address type used to indicate an anonymous advertisement. */
    private static final int ADDRESS_TYPE_ANONYMOUS = 0xFF;

    private static final String NULL_MAC_ADDRESS = "00:00:00:00:00:00";

    private final String mAddress;
@@ -1368,10 +1372,17 @@ public final class BluetoothDevice implements Parcelable, Attributable {
            throw new IllegalArgumentException(address + " is not a valid Bluetooth address");
        }

        if (addressType != ADDRESS_TYPE_PUBLIC && addressType != ADDRESS_TYPE_RANDOM) {
        if (addressType != ADDRESS_TYPE_PUBLIC
                && addressType != ADDRESS_TYPE_RANDOM
                && addressType != ADDRESS_TYPE_ANONYMOUS) {
            throw new IllegalArgumentException(addressType + " is not a Bluetooth address type");
        }

        if (addressType == ADDRESS_TYPE_ANONYMOUS && !NULL_MAC_ADDRESS.equals(address)) {
            throw new IllegalArgumentException(
                    "Invalid address for anonymous address type: " + getAnonymizedAddress());
        }

        mAddress = address;
        mAddressType = addressType;
        mAttributionSource = AttributionSource.myAttributionSource();