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

Commit acf0086d authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Pass UI Into Security Manager" am: 43594ba0

Change-Id: Ibbdfc480ea0f00c3c165fdc59ae3160bb65afd1b
parents 98504bc3 43594ba0
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -98,7 +98,8 @@ struct InitialInformations {
  std::optional<MyOobData> my_oob_data;

  /* Used by Pairing Handler to present user with requests*/
  UI* ui_handler;
  UI* user_interface;
  os::Handler* user_interface_handler;

  /* HCI interface to use */
  hci::LeSecurityInterface* le_security_interface;
+12 −15
Original line number Diff line number Diff line
@@ -33,19 +33,6 @@ namespace bluetooth {
namespace security {
namespace internal {

namespace {
// TOOD: implement properly, have it passed form other module?
class UIHandler : public ::bluetooth::security::UI {
 public:
  void DisplayPairingPrompt(const hci::AddressWithType& address, std::string& name) {}
  void CancelPairingPrompt(const hci::AddressWithType& address) {}
  void DisplayConfirmValue(uint32_t numeric_value) {}
  void DisplayEnterPasskeyDialog() {}
  void DisplayPasskey(uint32_t passkey) {}
};
UIHandler static_ui_handler;
}  // namespace

void SecurityManagerImpl::DispatchPairingHandler(record::SecurityRecord& record, bool locally_initiated) {
  common::OnceCallback<void(hci::Address, PairingResultOrFailure)> callback =
      common::BindOnce(&SecurityManagerImpl::OnPairingHandlerComplete, common::Unretained(this));
@@ -122,6 +109,14 @@ void SecurityManagerImpl::RemoveBond(hci::AddressWithType device) {
  // Signal Remove from database
}

void SecurityManagerImpl::SetUserInterfaceHandler(UI* user_interface, os::Handler* handler) {
  if (user_interface_ != nullptr || user_interface_handler_ != nullptr) {
    LOG_ALWAYS_FATAL("Listener has already been registered!");
  }
  user_interface_ = user_interface;
  user_interface_handler_ = handler;
}

void SecurityManagerImpl::RegisterCallbackListener(ISecurityManagerListener* listener, os::Handler* handler) {
  for (auto it = listeners_.begin(); it != listeners_.end(); ++it) {
    if (it->first == listener) {
@@ -320,8 +315,10 @@ void SecurityManagerImpl::OnConnectionOpenLe(std::unique_ptr<l2cap::le::FixedCha
      .pairing_request = std::nullopt,  // TODO: handle remotely initiated pairing in SecurityManager properly
      .remote_oob_data = std::nullopt,  // TODO:
      .my_oob_data = std::nullopt,      // TODO:
      // /* Used by Pairing Handler to present user with requests*/
      .ui_handler = &static_ui_handler,
      /* Used by Pairing Handler to present user with requests*/
      .user_interface = user_interface_,
      .user_interface_handler = user_interface_handler_,

      /* HCI interface to use */
      .le_security_interface = hci_security_interface_le_,
      .proper_l2cap_interface = pending_le_pairing_.enqueue_buffer_.get(),
+8 −0
Original line number Diff line number Diff line
@@ -86,6 +86,11 @@ class SecurityManagerImpl : public channel::ISecurityManagerChannelListener {

  /* void RemoveBond(std::shared_ptr<hci::LeDevice> device); */

  /**
   * Register Security UI handler, for handling prompts around the Pairing process.
   */
  void SetUserInterfaceHandler(UI* user_interface, os::Handler* handler);

  /**
   * Register to listen for callback events from SecurityManager
   *
@@ -117,6 +122,9 @@ class SecurityManagerImpl : public channel::ISecurityManagerChannelListener {

 protected:
  std::vector<std::pair<ISecurityManagerListener*, os::Handler*>> listeners_;
  UI* user_interface_ = nullptr;
  os::Handler* user_interface_handler_ = nullptr;

  void NotifyDeviceBonded(hci::AddressWithType device);
  void NotifyDeviceBondFailed(hci::AddressWithType device, PairingResultOrFailure status);
  void NotifyDeviceUnbonded(hci::AddressWithType device);
+2 −1
Original line number Diff line number Diff line
@@ -26,7 +26,8 @@ void PairingHandlerLe::PairingMain(InitialInformations i) {

  if (i.remotely_initiated) {
    LOG_INFO("Was remotely initiated, presenting user with the accept prompt");
    i.ui_handler->DisplayPairingPrompt(i.remote_connection_address, i.remote_name);
    i.user_interface_handler->Post(common::BindOnce(&UI::DisplayPairingPrompt, common::Unretained(i.user_interface),
                                                    i.remote_connection_address, i.remote_name));

    // If pairing was initiated by remote device, wait for the user to accept
    // the request from the UI.
+4 −2
Original line number Diff line number Diff line
@@ -89,9 +89,11 @@ LegacyStage1ResultOrFailure PairingHandlerLe::LegacyPasskeyEntry(const InitialIn
    constexpr uint32_t PASSKEY_MAX = 999999;
    if (passkey > PASSKEY_MAX) passkey >>= 1;

    i.ui_handler->DisplayConfirmValue(passkey);
    i.user_interface_handler->Post(
        common::BindOnce(&UI::DisplayConfirmValue, common::Unretained(i.user_interface), passkey));
  } else {
    i.ui_handler->DisplayEnterPasskeyDialog();
    i.user_interface_handler->Post(
        common::BindOnce(&UI::DisplayEnterPasskeyDialog, common::Unretained(i.user_interface)));
    std::optional<PairingEvent> response = WaitUiPasskey();
    if (!response) return PairingFailure("Passkey did not arrive!");

Loading