OSDN Git Service

Don't read HearingAid properties if already have properties value.
authorweichinweng <weichinweng@google.com>
Thu, 2 May 2019 07:31:33 +0000 (15:31 +0800)
committerweichinweng <weichinweng@google.com>
Fri, 3 May 2019 01:11:13 +0000 (09:11 +0800)
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

bta/hearing_aid/hearing_aid.cc
bta/include/bta_hearing_aid_api.h
btif/include/btif_storage.h
btif/src/btif_storage.cc

index a9d567b..28b69d2 100644 (file)
@@ -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 "
-                 << loghex(charac.value_handle);
-        BtaGattQueue::ReadCharacteristic(
-            conn_id, charac.value_handle,
-            HearingAidImpl::OnReadOnlyPropertiesReadStatic, nullptr);
+        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!
index 9f748bf..d9e1550 100644 (file)
@@ -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) {}
index e913d79..1c1163d 100644 (file)
@@ -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
index 99c1965..2427493 100644 (file)
@@ -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