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

Commit 99bf17c1 authored by weichinweng's avatar weichinweng Committed by Weichin Weng
Browse files

HearingAid: add addToWhiteList NativeInterface API

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
parent a47f5862
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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)
+1 −0
Original line number Diff line number Diff line
@@ -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;
};

+3 −2
Original line number Diff line number Diff line
@@ -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);

/*******************************************************************************
 *
+10 −2
Original line number Diff line number Diff line
@@ -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 {
+5 −3
Original line number Diff line number Diff line
@@ -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();
}

/*******************************************************************************
Loading