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

Commit 0232a03b authored by Christine Hallstrom's avatar Christine Hallstrom Committed by Gerrit Code Review
Browse files

Merge "Allow constructing BluetoothDevice with anonymous address type" into main

parents 1069beb1 a63c6a36
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();