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

Commit b98c570d authored by Myles Watson's avatar Myles Watson
Browse files

Add getRemoteLeDevice to specify ADDRESS_TYPE

Bug: 215724286
Test: cts
Tag: #feature
Change-Id: Id6415cf5f0236a82cb294538c22b5dc22555a6ff
Merged-In: Id6415cf5f0236a82cb294538c22b5dc22555a6ff
parent 22c1d198
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ package android.bluetooth {
    method public boolean getProfileProxy(android.content.Context, android.bluetooth.BluetoothProfile.ServiceListener, int);
    method public android.bluetooth.BluetoothDevice getRemoteDevice(String);
    method public android.bluetooth.BluetoothDevice getRemoteDevice(byte[]);
    method @NonNull public android.bluetooth.BluetoothDevice getRemoteLeDevice(@NonNull String, int);
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN) public int getScanMode();
    method public int getState();
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN) public boolean isDiscovering();
+23 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SuppressLint;
import android.annotation.SystemApi; //import android.app.PropertyInvalidatedCache;
import android.app.PendingIntent;
import android.bluetooth.BluetoothDevice.AddressType;
import android.bluetooth.BluetoothDevice.Transport;
import android.bluetooth.BluetoothProfile.ConnectionPolicy;
import android.bluetooth.annotations.RequiresBluetoothAdvertisePermission;
@@ -862,6 +863,28 @@ public final class BluetoothAdapter {
        return res;
    }

    /**
     * Get a {@link BluetoothDevice} object for the given Bluetooth hardware
     * address and addressType.
     * <p>Valid Bluetooth hardware addresses must be upper case, in a format
     * such as "00:11:22:33:AA:BB". The helper {@link #checkBluetoothAddress} is
     * available to validate a Bluetooth address.
     * <p>A {@link BluetoothDevice} will always be returned for a valid
     * hardware address and type, even if this adapter has never seen that device.
     *
     * @param address valid Bluetooth MAC address
     * @param addressType Bluetooth address type
     * @throws IllegalArgumentException if address is invalid
     */
    @RequiresNoPermission
    public
    @NonNull BluetoothDevice getRemoteLeDevice(@NonNull String address,
            @AddressType int addressType) {
        final BluetoothDevice res = new BluetoothDevice(address, addressType);
        res.setAttributionSource(mAttributionSource);
        return res;
    }

    /**
     * Get a {@link BluetoothDevice} object for the given Bluetooth hardware
     * address.
+24 −6
Original line number Diff line number Diff line
@@ -1194,28 +1194,46 @@ public final class BluetoothDevice implements Parcelable, Attributable {
    };

    /**
     * Create a new BluetoothDevice
     * Create a new BluetoothDevice.
     * Bluetooth MAC address must be upper case, such as "00:11:22:33:AA:BB",
     * and is validated in this constructor.
     *
     * @param address valid Bluetooth MAC address
     * @param attributionSource attribution for permission-protected calls
     * @param addressType valid address type
     * @throws RuntimeException Bluetooth is not available on this platform
     * @throws IllegalArgumentException address is invalid
     * @throws IllegalArgumentException address or addressType is invalid
     * @hide
     */
    @UnsupportedAppUsage
    /*package*/ BluetoothDevice(String address) {
    /*package*/ BluetoothDevice(String address, int addressType) {
        getService();  // ensures sService is initialized
        if (!BluetoothAdapter.checkBluetoothAddress(address)) {
            throw new IllegalArgumentException(address + " is not a valid Bluetooth address");
        }

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

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

    /**
     * Create a new BluetoothDevice.
     * Bluetooth MAC address must be upper case, such as "00:11:22:33:AA:BB",
     * and is validated in this constructor.
     *
     * @param address valid Bluetooth MAC address
     * @throws RuntimeException Bluetooth is not available on this platform
     * @throws IllegalArgumentException address is invalid
     * @hide
     */
    @UnsupportedAppUsage
    /*package*/ BluetoothDevice(String address) {
        this(address, ADDRESS_TYPE_PUBLIC);
    }

    /** {@hide} */
    public void setAttributionSource(@NonNull AttributionSource attributionSource) {
        mAttributionSource = attributionSource;