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

Commit f69f11c5 authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Use appropriate addresses with HID and HOGP

Pseudo address(RPA) for HID connection request does not work. Similarly,
using identity address (Public address) for HOGP connection request may
not work.
This change ensures that the HID host service uses appropriate addresses
with HID and HOGP connections.

Test: mmm packages/modules/Bluetooth
Test: Manual | Pair with device supporting both HID and HOGP, and using
RPA in bondable mode
Bug: 330655651
Bug: 320762367

Change-Id: Id1c67724a3229084a59c99f56099659ed7c16249
parent 858bc074
Loading
Loading
Loading
Loading
+41 −14
Original line number Diff line number Diff line
@@ -196,20 +196,47 @@ public class HidHostService extends ProfileService {
        setHidHostService(null);
    }

    private byte[] getByteAddress(BluetoothDevice device) {
    private byte[] getIdentityAddress(BluetoothDevice device) {
        if (Flags.identityAddressNullIfUnknown()) {
            return Utils.getByteBrEdrAddress(device);
        } else {
            return mAdapterService.getByteIdentityAddress(device);
        }
    }

    private byte[] getByteAddress(BluetoothDevice device, int transport) {
        if (!Flags.allowSwitchingHidAndHogp()) {
            if (Utils.arrayContains(device.getUuids(), BluetoothUuid.HOGP)) {
                // Use pseudo address when HOGP is available
                return Utils.getByteAddress(device);
            } else {
            // Use BR/EDR address if only HID is available
            if (Flags.identityAddressNullIfUnknown()) {
                return Utils.getByteBrEdrAddress(device);
                // Otherwise use identity address
                return getIdentityAddress(device);
            }
        }

        if (transport == BluetoothDevice.TRANSPORT_LE) {
            // Use pseudo address when HOGP is to be used
            return Utils.getByteAddress(device);
        } else if (transport == BluetoothDevice.TRANSPORT_BREDR) {
            // Use identity address if HID is to be used
            return getIdentityAddress(device);
        } else { // BluetoothDevice.TRANSPORT_AUTO
            // Prefer HID over HOGP
            if (Utils.arrayContains(device.getUuids(), BluetoothUuid.HID)) {
                // Use identity address if HID is available
                return getIdentityAddress(device);
            } else {
                return mAdapterService.getByteIdentityAddress(device);
                // Otherwise use pseudo address
                return Utils.getByteAddress(device);
            }
        }
    }

    private byte[] getByteAddress(BluetoothDevice device) {
        return getByteAddress(device, getTransport(device));
    }

    /**
     * Retrieves device address type
     *
@@ -306,7 +333,7 @@ public class HidHostService extends ProfileService {
     */
    private boolean nativeConnect(BluetoothDevice device, int transport) {
        if (!mNativeInterface.connectHid(
                getByteAddress(device), getAddressType(device), transport)) {
                getByteAddress(device, transport), getAddressType(device), transport)) {
            Log.w(
                    TAG,
                    "nativeConnect: "
@@ -336,7 +363,10 @@ public class HidHostService extends ProfileService {
    private boolean nativeDisconnect(
            BluetoothDevice device, int transport, boolean reconnectAllowed) {
        if (!mNativeInterface.disconnectHid(
                getByteAddress(device), getAddressType(device), transport, reconnectAllowed)) {
                getByteAddress(device, transport),
                getAddressType(device),
                transport,
                reconnectAllowed)) {
            Log.w(
                    TAG,
                    "nativeDisconnect: "
@@ -1323,10 +1353,7 @@ public class HidHostService extends ProfileService {
        }

        return mNativeInterface.sendData(
                getByteAddress(device),
                (byte) BluetoothDevice.ADDRESS_TYPE_PUBLIC,
                (byte) BluetoothDevice.TRANSPORT_AUTO,
                report);
                getByteAddress(device), getAddressType(device), getTransport(device), report);
    }

    boolean getIdleTime(BluetoothDevice device) {