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

Commit 72dbb076 authored by weichinweng's avatar weichinweng
Browse files

Don't read HearingAid properties if already have properties value.

When read HearingAid properties, don't read it if already have the
HearingAid properties in config file. Will use these values in config
file since these values should never change.

Bug: 128464408
Test: 1.Forget/Repair HearingAid device from Bluetooth UI.
2.Disconnect/Reconnect HearingAid device from Bluetooth UI.
3.HearingAid device power off/on, check them can reconnect.

Change-Id: Id4c30947c75f0615514075ec36c50afb58fc3f14
Merged-In: Id4c30947c75f0615514075ec36c50afb58fc3f14
parent d66740e8
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@ constexpr uint16_t CONNECTION_INTERVAL_10MS_PARAM = 0x0008;
constexpr uint16_t CONNECTION_INTERVAL_20MS_PARAM = 0x0010;

void btif_storage_add_hearing_aid(const HearingDevice& dev_info);
bool btif_storage_get_hearing_aid_prop(
    const RawAddress& address, uint8_t* capabilities, uint64_t* hi_sync_id,
    uint16_t* render_delay, uint16_t* preparation_delay, uint16_t* codecs);

constexpr uint8_t CODEC_G722_16KHZ = 0x01;
constexpr uint8_t CODEC_G722_24KHZ = 0x02;
@@ -626,11 +629,16 @@ class HearingAidImpl : public HearingAid {

    for (const gatt::Characteristic& charac : service->characteristics) {
      if (charac.uuid == READ_ONLY_PROPERTIES_UUID) {
        DVLOG(2) << "Reading read only properties "
        if (!btif_storage_get_hearing_aid_prop(
                hearingDevice->address, &hearingDevice->capabilities,
                &hearingDevice->hi_sync_id, &hearingDevice->render_delay,
                &hearingDevice->preparation_delay, &hearingDevice->codecs)) {
          VLOG(2) << "Reading read only properties "
                  << loghex(charac.value_handle);
          BtaGattQueue::ReadCharacteristic(
              conn_id, charac.value_handle,
              HearingAidImpl::OnReadOnlyPropertiesReadStatic, nullptr);
        }
      } else if (charac.uuid == AUDIO_CONTROL_POINT_UUID) {
        hearingDevice->audio_control_point_handle = charac.value_handle;
        // store audio control point!
+5 −0
Original line number Diff line number Diff line
@@ -177,6 +177,11 @@ struct HearingDevice {
        audio_status_ccc_handle(0),
        service_changed_ccc_handle(0),
        read_psm_handle(0),
        capabilities(0),
        hi_sync_id(0),
        render_delay(0),
        preparation_delay(0),
        codecs(0),
        playback_started(false),
        command_acked(false),
        read_rssi_count(0) {}
+5 −0
Original line number Diff line number Diff line
@@ -231,6 +231,11 @@ void btif_storage_remove_hearing_aid(const RawAddress& address);
void btif_storage_set_hearing_aid_white_list(const RawAddress& address,
                                             bool add_to_whitelist);

/** Get the hearing aid device properties. */
bool btif_storage_get_hearing_aid_prop(
    const RawAddress& address, uint8_t* capabilities, uint64_t* hi_sync_id,
    uint16_t* render_delay, uint16_t* preparation_delay, uint16_t* codecs);

/*******************************************************************************
 *
 * Function         btif_storage_is_retricted_device
+41 −0
Original line number Diff line number Diff line
@@ -1643,6 +1643,47 @@ void btif_storage_set_hearing_aid_white_list(const RawAddress& address,
  btif_config_save();
}

/** Get the hearing aid device properties. */
bool btif_storage_get_hearing_aid_prop(
    const RawAddress& address, uint8_t* capabilities, uint64_t* hi_sync_id,
    uint16_t* render_delay, uint16_t* preparation_delay, uint16_t* codecs) {
  std::string addrstr = address.ToString();

  int value;
  if (btif_config_get_int(addrstr, HEARING_AID_CAPABILITIES, &value)) {
    *capabilities = value;
  } else {
    return false;
  }

  if (btif_config_get_int(addrstr, HEARING_AID_CODECS, &value)) {
    *codecs = value;
  } else {
    return false;
  }

  if (btif_config_get_int(addrstr, HEARING_AID_RENDER_DELAY, &value)) {
    *render_delay = value;
  } else {
    return false;
  }

  if (btif_config_get_int(addrstr, HEARING_AID_PREPARATION_DELAY, &value)) {
    *preparation_delay = value;
  } else {
    return false;
  }

  uint64_t lvalue;
  if (btif_config_get_uint64(addrstr, HEARING_AID_SYNC_ID, &lvalue)) {
    *hi_sync_id = lvalue;
  } else {
    return false;
  }

  return true;
}

/*******************************************************************************
 *
 * Function         btif_storage_is_restricted_device