OSDN Git Service

HearingAid: add addToWhiteList NativeInterface API
authorweichinweng <weichinweng@google.com>
Tue, 23 Apr 2019 02:56:20 +0000 (10:56 +0800)
committerWeichin Weng <weichinweng@google.com>
Wed, 24 Apr 2019 09:17:14 +0000 (09:17 +0000)
Add a new native interface API, addToWhiteList, that adds a LE device to
the whitelist.

Bug: 129452236
Test: Manual testing with Hearing Aids
Change-Id: I57c327380f07243e484c5c3afedfe60404f883fa
Merged-In: I57c327380f07243e484c5c3afedfe60404f883fa

bta/hearing_aid/hearing_aid.cc
bta/include/bta_hearing_aid_api.h
btif/include/btif_storage.h
btif/src/btif_hearing_aid.cc
btif/src/btif_storage.cc
include/hardware/bt_hearing_aid.h

index 5abab11..2437e98 100644 (file)
@@ -289,6 +289,12 @@ class HearingAidImpl : public HearingAid {
     BTA_GATTC_Open(gatt_if, address, true, GATT_TRANSPORT_LE, false);
   }
 
+  void AddToWhiteList(const RawAddress& address) override {
+    VLOG(2) << __func__ << " address: " << address;
+    hearingDevices.Add(HearingDevice(address, true));
+    BTA_GATTC_Open(gatt_if, address, false, GATT_TRANSPORT_LE, false);
+  }
+
   void AddFromStorage(const HearingDevice& dev_info, uint16_t is_white_listed) {
     DVLOG(2) << __func__ << " " << dev_info.address
              << ", hiSyncId=" << loghex(dev_info.hi_sync_id)
index aa8c7c7..9f748bf 100644 (file)
@@ -206,6 +206,7 @@ class HearingAid {
 
   virtual void Connect(const RawAddress& address) = 0;
   virtual void Disconnect(const RawAddress& address) = 0;
+  virtual void AddToWhiteList(const RawAddress& address) = 0;
   virtual void SetVolume(int8_t volume) = 0;
 };
 
index 30615ce..e913d79 100644 (file)
@@ -227,8 +227,9 @@ void btif_storage_load_bonded_hearing_aids();
 /** Deletes the bonded hearing aid device info from NVRAM */
 void btif_storage_remove_hearing_aid(const RawAddress& address);
 
-/** Remove the hearing aid device from white list */
-void btif_storage_remove_hearing_aid_white_list(const RawAddress& address);
+/** Set/Unset the hearing aid device HEARING_AID_IS_WHITE_LISTED flag. */
+void btif_storage_set_hearing_aid_white_list(const RawAddress& address,
+                                             bool add_to_whitelist);
 
 /*******************************************************************************
  *
index efba57d..943017e 100644 (file)
@@ -92,8 +92,16 @@ class HearingAidInterfaceImpl
     DVLOG(2) << __func__ << " address: " << address;
     do_in_main_thread(FROM_HERE, Bind(&HearingAid::Disconnect,
                                       Unretained(HearingAid::Get()), address));
-    do_in_jni_thread(
-        FROM_HERE, Bind(&btif_storage_remove_hearing_aid_white_list, address));
+    do_in_jni_thread(FROM_HERE, Bind(&btif_storage_set_hearing_aid_white_list,
+                                     address, false));
+  }
+
+  void AddToWhiteList(const RawAddress& address) override {
+    VLOG(2) << __func__ << " address: " << address;
+    do_in_main_thread(FROM_HERE, Bind(&HearingAid::AddToWhiteList,
+                                      Unretained(HearingAid::Get()), address));
+    do_in_jni_thread(FROM_HERE, Bind(&btif_storage_set_hearing_aid_white_list,
+                                     address, true));
   }
 
   void SetVolume(int8_t volume) override {
index 49feb73..99c1965 100644 (file)
@@ -1634,11 +1634,13 @@ void btif_storage_remove_hearing_aid(const RawAddress& address) {
   btif_config_save();
 }
 
-/** Remove the hearing aid device from white list */
-void btif_storage_remove_hearing_aid_white_list(const RawAddress& address) {
+/** Set/Unset the hearing aid device HEARING_AID_IS_WHITE_LISTED flag. */
+void btif_storage_set_hearing_aid_white_list(const RawAddress& address,
+                                             bool add_to_whitelist) {
   std::string addrstr = address.ToString();
 
-  btif_config_set_int(addrstr, HEARING_AID_IS_WHITE_LISTED, false);
+  btif_config_set_int(addrstr, HEARING_AID_IS_WHITE_LISTED, add_to_whitelist);
+  btif_config_save();
 }
 
 /*******************************************************************************
index a54f82a..1911159 100644 (file)
@@ -59,6 +59,9 @@ class HearingAidInterface {
   /** Disconnect from Hearing Aid */
   virtual void Disconnect(const RawAddress& address) = 0;
 
+  /** Add a hearing aid device to white list */
+  virtual void AddToWhiteList(const RawAddress& address) = 0;
+
   /** Set the volume */
   virtual void SetVolume(int8_t volume) = 0;