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

Commit 4069bd3a authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Register bond state change change callbacks in shim" am: 5cbaedb8 am: ee800524

Change-Id: I2304cb668d88c61ff1e87503cc657404aed9f7fc
parents 9e0117c9 ee800524
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -290,6 +290,13 @@ static void btif_dm_data_free(uint16_t event, tBTA_DM_SEC* dm_sec) {
    osi_free_and_reset((void**)&dm_sec->ble_key.p_key_value);
}

static void btif_dm_send_bond_state_changed(RawAddress address, bt_bond_state_t bond_state) {
  do_in_jni_thread(FROM_HERE, base::BindOnce([](RawAddress address, bt_bond_state_t bond_state) {
    btif_stats_add_bond_event(address, BTIF_DM_FUNC_BOND_STATE_CHANGED, bond_state);
    HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, BT_STATUS_SUCCESS, &address, bond_state);
  }, address, bond_state));
}

void btif_dm_init(uid_set_t* set) {
  uid_set = set;
  if (bluetooth::shim::is_gd_shim_enabled()) {
@@ -309,6 +316,17 @@ void btif_dm_init(uid_set_t* set) {
        HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &address, &bd_name, cod, pairing_variant, pass_key);
      }, address, bd_name, cod, pairing_variant, pass_key));
    });

    bluetooth::shim::BTIF_RegisterBondStateChangeListener(
        [](RawAddress address) {
          btif_dm_send_bond_state_changed(address, BT_BOND_STATE_BONDING);
        },
        [](RawAddress address) {
          btif_dm_send_bond_state_changed(address, BT_BOND_STATE_BONDED);
        },
        [](RawAddress address) {
          btif_dm_send_bond_state_changed(address, BT_BOND_STATE_NONE);
        });
  }
}

+39 −0
Original line number Diff line number Diff line
@@ -87,6 +87,45 @@ void BTIF_DM_SetUiCallback(std::function<void(RawAddress, bt_bdname_t, uint32_t,
  security_manager->SetUserInterfaceHandler(&ui, bluetooth::shim::GetGdShimHandler());
}

class ShimBondListener : public security::ISecurityManagerListener {
 public:
  void SetLegacyCallbacks(std::function<void(RawAddress)> bond_state_bonding_cb,
                          std::function<void(RawAddress)> bond_state_bonded_cb,
                          std::function<void(RawAddress)> bond_state_none_cb) {
    bond_state_bonding_cb_ = bond_state_bonding_cb;
    bond_state_bonded_cb_ = bond_state_bonded_cb;
    bond_state_none_cb_ = bond_state_none_cb;
  }
  void OnDeviceBonded(bluetooth::hci::AddressWithType device) {
    bond_state_bonded_cb_(RawAddress(device.GetAddress().address));
  }

  void OnDeviceUnbonded(bluetooth::hci::AddressWithType device) {
    bond_state_none_cb_(RawAddress(device.GetAddress().address));
  }

  void OnDeviceBondFailed(bluetooth::hci::AddressWithType device) {
    bond_state_none_cb_(RawAddress(device.GetAddress().address));
  }

  std::function<void(RawAddress)> bond_state_bonding_cb_;
  std::function<void(RawAddress)> bond_state_bonded_cb_;
  std::function<void(RawAddress)> bond_state_none_cb_;
};

ShimBondListener shim_bond_listener;

void BTIF_RegisterBondStateChangeListener(
    std::function<void(RawAddress)> bonding_cb,
    std::function<void(RawAddress)> bonded_cb,
    std::function<void(RawAddress)> none_cb) {
  auto security_manager =
      bluetooth::shim::GetSecurityModule()->GetSecurityManager();
  shim_bond_listener.SetLegacyCallbacks(bonding_cb, bonded_cb, none_cb);
  security_manager->RegisterCallbackListener(
      &shim_bond_listener, bluetooth::shim::GetGdShimHandler());
}

void BTIF_DM_ssp_reply(const RawAddress bd_addr, uint8_t addr_type, bt_ssp_variant_t variant, uint8_t accept) {
  hci::AddressWithType address = ToAddressWithType(bd_addr, addr_type);
  auto security_manager = bluetooth::shim::GetSecurityModule()->GetSecurityManager();
+4 −0
Original line number Diff line number Diff line
@@ -31,5 +31,9 @@ namespace shim {
void BTIF_DM_SetUiCallback(std::function<void(RawAddress, bt_bdname_t, uint32_t, bt_ssp_variant_t, uint32_t)> callback);
void BTIF_DM_ssp_reply(const RawAddress bd_addr, uint8_t, bt_ssp_variant_t variant, uint8_t accept);
void BTIF_DM_pin_reply(const RawAddress bd_addr, uint8_t, uint8_t, uint8_t, bt_pin_code_t);
void BTIF_RegisterBondStateChangeListener(
    std::function<void(RawAddress)> bond_state_bonding_cb,
    std::function<void(RawAddress)> bond_state_bonded_cb,
    std::function<void(RawAddress)> bond_state_none_cb);
}  // namespace shim
}  // namespace bluetooth