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

Commit 4ee1dbcf authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "BTM_API Shim: Add ShimUi"

parents 0d3a0110 1befd6c3
Loading
Loading
Loading
Loading
+95 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include "gd/common/callback.h"
#include "gd/neighbor/name.h"
#include "gd/security/security_module.h"
#include "gd/security/ui.h"
#include "main/shim/btm.h"
#include "main/shim/btm_api.h"
#include "main/shim/controller.h"
@@ -231,6 +232,92 @@ void btm_api_process_extended_inquiry_result(RawAddress raw_address,
  }
}

class ShimUi : public bluetooth::security::UI {
 public:
  static ShimUi* GetInstance() {
    static ShimUi instance;
    return &instance;
  }

  ShimUi(const ShimUi&) = delete;
  ShimUi& operator=(const ShimUi&) = delete;

  void SetBtaCallbacks(const tBTM_APPL_INFO* bta_callbacks) {
    bta_callbacks_ = bta_callbacks;
    if (bta_callbacks->p_pin_callback == nullptr) {
      LOG_INFO("UNIMPLEMENTED %s pin_callback", __func__);
    }

    if (bta_callbacks->p_link_key_callback == nullptr) {
      LOG_INFO("UNIMPLEMENTED %s link_key_callback", __func__);
    }

    if (bta_callbacks->p_auth_complete_callback == nullptr) {
      LOG_INFO("UNIMPLEMENTED %s auth_complete_callback", __func__);
    }

    if (bta_callbacks->p_bond_cancel_cmpl_callback == nullptr) {
      LOG_INFO("UNIMPLEMENTED %s bond_cancel_complete_callback", __func__);
    }

    if (bta_callbacks->p_le_callback == nullptr) {
      LOG_INFO("UNIMPLEMENTED %s le_callback", __func__);
    }

    if (bta_callbacks->p_le_key_callback == nullptr) {
      LOG_INFO("UNIMPLEMENTED %s le_key_callback", __func__);
    }
  }

  void DisplayPairingPrompt(const bluetooth::hci::AddressWithType& address,
                            std::string name) {
    waiting_for_pairing_prompt_ = true;
    bt_bdname_t legacy_name{0};
    memcpy(legacy_name.name, name.data(), name.length());
  }

  void Cancel(const bluetooth::hci::AddressWithType& address) {
    LOG(WARNING) << " ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ " << __func__;
  }

  void DisplayConfirmValue(const bluetooth::hci::AddressWithType& address,
                           std::string name, uint32_t numeric_value) {
    waiting_for_pairing_prompt_ = false;
    bt_bdname_t legacy_name{0};
    memcpy(legacy_name.name, name.data(), name.length());
  }

  void DisplayYesNoDialog(const bluetooth::hci::AddressWithType& address,
                          std::string name) {
    waiting_for_pairing_prompt_ = false;
    bt_bdname_t legacy_name{0};
    memcpy(legacy_name.name, name.data(), name.length());
  }

  void DisplayEnterPasskeyDialog(const bluetooth::hci::AddressWithType& address,
                                 std::string name) {
    waiting_for_pairing_prompt_ = false;
    bt_bdname_t legacy_name{0};
    memcpy(legacy_name.name, name.data(), name.length());
  }

  void DisplayPasskey(const bluetooth::hci::AddressWithType& address,
                      std::string name, uint32_t passkey) {
    waiting_for_pairing_prompt_ = false;
    bt_bdname_t legacy_name{0};
    memcpy(legacy_name.name, name.data(), name.length());
  }

  bool waiting_for_pairing_prompt_ = false;

 private:
  ShimUi() : bta_callbacks_(nullptr) {}
  ~ShimUi() {}
  const tBTM_APPL_INFO* bta_callbacks_;
};

ShimUi* shim_ui_ = nullptr;

class ShimBondListener : public bluetooth::security::ISecurityManagerListener {
 public:
  static ShimBondListener* GetInstance() {
@@ -1023,6 +1110,14 @@ bool bluetooth::shim::BTM_SecRegister(const tBTM_APPL_INFO* bta_callbacks) {
      ->GetSecurityManager()
      ->RegisterCallbackListener(ShimBondListener::GetInstance(),
                                 bluetooth::shim::GetGdShimHandler());

  ShimUi::GetInstance()->SetBtaCallbacks(bta_callbacks);

  bluetooth::shim::GetSecurityModule()
      ->GetSecurityManager()
      ->SetUserInterfaceHandler(ShimUi::GetInstance(),
                                bluetooth::shim::GetGdShimHandler());

  return true;
}