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

Commit ec1b8d72 authored by Himanshu Rawat's avatar Himanshu Rawat Committed by Gerrit Code Review
Browse files

Merge "Remember Android Headtracker support on reconnection" into main

parents 52a1876f 05c1e4e1
Loading
Loading
Loading
Loading
+30 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <com_android_bluetooth_flags.h>

#include "bta/hh/bta_hh_int.h"
#include "btif/include/btif_storage.h"
#include "stack/include/bt_types.h"
#include "stack/include/bt_uuid16.h"
#include "types/bluetooth/uuid.h"
@@ -104,7 +105,7 @@ void bta_hh_headtracker_parse_service(tBTA_HH_DEV_CB* p_dev_cb,
  log::info("");
  bta_hh_le_srvc_init(p_dev_cb, service->handle);
  p_dev_cb->mode = BTA_HH_PROTO_RPT_MODE;
  p_dev_cb->hid_srvc.is_headtracker = true;
  p_dev_cb->hid_srvc.headtracker_support = BTA_HH_AVAILABLE;

  bta_hh_le_save_report_map(p_dev_cb,
                            (uint16_t)sizeof(ANDROID_HEADTRACKER_DESCRIPTOR),
@@ -142,8 +143,34 @@ void bta_hh_headtracker_parse_service(tBTA_HH_DEV_CB* p_dev_cb,
 *
 ******************************************************************************/
bool bta_hh_headtracker_supported(tBTA_HH_DEV_CB* p_dev_cb) {
  return com::android::bluetooth::flags::android_headtracker_service() &&
         p_dev_cb->hid_srvc.is_headtracker;
  if (!com::android::bluetooth::flags::android_headtracker_service()) {
    return false;
  }

  if (p_dev_cb->hid_srvc.headtracker_support == BTA_HH_UNKNOWN) {
    bluetooth::Uuid remote_uuids[BT_MAX_NUM_UUIDS] = {};
    bt_property_t remote_properties = {BT_PROPERTY_UUIDS, sizeof(remote_uuids),
                                       &remote_uuids};
    const RawAddress& bd_addr = p_dev_cb->link_spec.addrt.bda;
    p_dev_cb->hid_srvc.headtracker_support = BTA_HH_UNAVAILABLE;

    // Find which services known to be available
    if (btif_storage_get_remote_device_property(&bd_addr, &remote_properties) ==
        BT_STATUS_SUCCESS) {
      int count = remote_properties.len / sizeof(remote_uuids[0]);
      for (int i = 0; i < count; i++) {
        if (remote_uuids[i] == ANDROID_HEADTRACKER_SERVICE_UUID) {
          p_dev_cb->hid_srvc.headtracker_support = BTA_HH_AVAILABLE;
          break;
        }
      }
    }

    log::verbose("Headtracker support: {}",
                 (p_dev_cb->hid_srvc.headtracker_support == BTA_HH_AVAILABLE));
  }

  return (p_dev_cb->hid_srvc.headtracker_support == BTA_HH_AVAILABLE);
}

/*******************************************************************************
+7 −1
Original line number Diff line number Diff line
@@ -154,6 +154,12 @@ enum tBTA_HH_SERVICE_STATE {
  BTA_HH_SERVICE_DISCOVERED,
};

enum tBTA_HH_AVAILABLE {
  BTA_HH_UNKNOWN = 0,
  BTA_HH_AVAILABLE,
  BTA_HH_UNAVAILABLE
};

typedef struct {
  tBTA_HH_SERVICE_STATE state;
  uint8_t srvc_inst_id;
@@ -168,7 +174,7 @@ typedef struct {
  uint8_t* rpt_map;
  uint16_t ext_rpt_ref;
  tBTA_HH_DEV_DESCR descriptor;
  bool is_headtracker;
  tBTA_HH_AVAILABLE headtracker_support;
} tBTA_HH_LE_HID_SRVC;

/* convert a HID handle to the LE CB index */