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

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

Add support for Android Headtracker Service in HidHostService

Treat Android Headtracker Service as HOGP in HidHostService

Test: mmm packages/modules/Bluetooth
Test: Manual | Pair with buds supporting Android Headtracker service
Bug: 332590397
Bug: 335708774
Flag: com.android.bluetooth.flags.android_headtracker_service
Change-Id: I7dc4f8235edc00cbfcfe8c6cb3b4a01687355d21
parent a6f8e3f6
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -1633,7 +1633,10 @@ public class AdapterService extends Service {
        }
        if (profile == BluetoothProfile.HID_HOST) {
            return Utils.arrayContains(remoteDeviceUuids, BluetoothUuid.HID)
                    || Utils.arrayContains(remoteDeviceUuids, BluetoothUuid.HOGP);
                    || Utils.arrayContains(remoteDeviceUuids, BluetoothUuid.HOGP)
                    || (Flags.androidHeadtrackerService()
                            && Utils.arrayContains(
                                    remoteDeviceUuids, HidHostService.ANDROID_HEADTRACKER_UUID));
        }
        if (profile == BluetoothProfile.HID_DEVICE) {
            return mHidDeviceService.getConnectionState(device)
+4 −1
Original line number Diff line number Diff line
@@ -331,7 +331,10 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback {
        // This avoids needless auto-connect attempts to profiles non-existent on the remote device
        if ((hidService != null)
                && (Utils.arrayContains(uuids, BluetoothUuid.HID)
                        || Utils.arrayContains(uuids, BluetoothUuid.HOGP))
                        || Utils.arrayContains(uuids, BluetoothUuid.HOGP)
                        || (Flags.androidHeadtrackerService()
                                && Utils.arrayContains(
                                        uuids, HidHostService.ANDROID_HEADTRACKER_UUID)))
                && (hidService.getConnectionPolicy(device)
                        == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) {
            if (mAutoConnectProfilesSupported) {
+25 −5
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.ParcelUuid;
import android.os.UserHandle;
import android.sysprop.BluetoothProperties;
import android.util.Log;
@@ -63,6 +64,12 @@ import java.util.stream.Collectors;
public class HidHostService extends ProfileService {
    private static final String TAG = "BluetoothHidHostService";

    public static final String ANDROID_HEADTRACKER_UUID_STR =
            "109b862f-50e3-45cc-8ea1-ac62de4846d1";

    public static final ParcelUuid ANDROID_HEADTRACKER_UUID =
            ParcelUuid.fromString(ANDROID_HEADTRACKER_UUID_STR);

    private static class InputDevice {
        int mSelectedTransport = BluetoothDevice.TRANSPORT_AUTO;
        int mHidState = BluetoothProfile.STATE_DISCONNECTED;
@@ -201,8 +208,15 @@ public class HidHostService extends ProfileService {
    }

    private byte[] getByteAddress(BluetoothDevice device, int transport) {
        ParcelUuid[] uuids = device.getUuids();

        if (!Flags.allowSwitchingHidAndHogp()) {
            if (Utils.arrayContains(device.getUuids(), BluetoothUuid.HOGP)) {
            boolean hogpSupported = Utils.arrayContains(uuids, BluetoothUuid.HOGP);
            boolean headtrackerSupported =
                    Flags.androidHeadtrackerService()
                            && Utils.arrayContains(uuids, HidHostService.ANDROID_HEADTRACKER_UUID);

            if (hogpSupported || headtrackerSupported) {
                // Use pseudo address when HOGP is available
                return Utils.getByteAddress(device);
            } else {
@@ -218,8 +232,9 @@ public class HidHostService extends ProfileService {
            // Use identity address if HID is to be used
            return getIdentityAddress(device);
        } else { // BluetoothDevice.TRANSPORT_AUTO
            boolean hidSupported = Utils.arrayContains(uuids, BluetoothUuid.HID);
            // Prefer HID over HOGP
            if (Utils.arrayContains(device.getUuids(), BluetoothUuid.HID)) {
            if (hidSupported) {
                // Use identity address if HID is available
                return getIdentityAddress(device);
            } else {
@@ -1128,12 +1143,17 @@ public class HidHostService extends ProfileService {
            return false;
        }

        boolean hidSupported = Utils.arrayContains(device.getUuids(), BluetoothUuid.HID);
        boolean hogpSupported = Utils.arrayContains(device.getUuids(), BluetoothUuid.HOGP);
        ParcelUuid[] uuids = device.getUuids();
        boolean hidSupported = Utils.arrayContains(uuids, BluetoothUuid.HID);
        boolean hogpSupported = Utils.arrayContains(uuids, BluetoothUuid.HOGP);
        boolean headtrackerSupported =
                Flags.androidHeadtrackerService()
                        && Utils.arrayContains(uuids, HidHostService.ANDROID_HEADTRACKER_UUID);
        if (transport == BluetoothDevice.TRANSPORT_BREDR && !hidSupported) {
            Log.w(TAG, "HID not supported: " + device);
            return false;
        } else if (transport == BluetoothDevice.TRANSPORT_LE && !hogpSupported) {
        } else if (transport == BluetoothDevice.TRANSPORT_LE
                && !(hogpSupported || headtrackerSupported)) {
            Log.w(TAG, "HOGP not supported: " + device);
            return false;
        }