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

Commit a6dcdf0d authored by Martin Brabham's avatar Martin Brabham
Browse files

SecurityModule: cleanup pairing handler

Bug: 144375377
Test: atest --host -t bluetooth_test_gd:ClassicPairingHandlerTest
Change-Id: Id91199aba8b05087f31f5bcd6feb12f8cb6b0641
parent 8886840d
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -24,6 +24,10 @@ namespace pairing {
void ClassicPairingHandler::OnRegistrationComplete(
    l2cap::classic::FixedChannelManager::RegistrationResult result,
    std::unique_ptr<l2cap::classic::FixedChannelService> fixed_channel_service) {
  if (result != l2cap::classic::FixedChannelManager::RegistrationResult::SUCCESS) {
    LOG_ERROR("Failed service registration!");
    return;
  }
  fixed_channel_service_ = std::move(fixed_channel_service);
  fixed_channel_manager_->ConnectServices(
      GetRecord()->GetPseudoAddress().GetAddress(),
@@ -31,12 +35,17 @@ void ClassicPairingHandler::OnRegistrationComplete(
}

void ClassicPairingHandler::OnUnregistered() {
  std::move(complete_callback_).Run(GetRecord()->GetPseudoAddress().GetAddress(), last_status_);
  PairingResultOrFailure result = PairingResult();
  if (last_status_ != hci::ErrorCode::SUCCESS) {
    result = PairingFailure(hci::ErrorCodeText(last_status_));
  }
  std::move(complete_callback_).Run(GetRecord()->GetPseudoAddress().GetAddress(), result);
}

void ClassicPairingHandler::OnConnectionOpen(std::unique_ptr<l2cap::classic::FixedChannel> fixed_channel) {
  ASSERT(fixed_channel_ == nullptr);
  fixed_channel_ = std::move(fixed_channel);
  ASSERT(fixed_channel_->GetDevice() == GetRecord()->GetPseudoAddress().GetAddress());
  fixed_channel_->Acquire();
  fixed_channel_->RegisterOnCloseCallback(
      security_handler_, common::BindOnce(&ClassicPairingHandler::OnConnectionClose, common::Unretained(this)));
@@ -143,6 +152,7 @@ void ClassicPairingHandler::OnReceive(hci::SimplePairingCompleteView packet) {
  ASSERT(packet.IsValid());
  LOG_INFO("Received: %s", hci::EventCodeText(packet.GetEventCode()).c_str());
  ASSERT_LOG(GetRecord()->GetPseudoAddress().GetAddress() == packet.GetBdAddr(), "Address mismatch");
  last_status_ = packet.GetStatus();
  Cancel();
}

+1 −1
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ class ClassicPairingHandler : public PairingHandler {
  hci::AuthenticationRequirements local_authentication_requirements_ __attribute__((unused));
  std::unique_ptr<l2cap::classic::FixedChannel> fixed_channel_{nullptr};
  common::OnceCallback<void(hci::Address, PairingResultOrFailure)> complete_callback_;
  PairingResultOrFailure last_status_;
  hci::ErrorCode last_status_;
  bool locally_initiated_ = false;
};

+1 −1
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ class ClassicPairingHandlerTest : public ::testing::Test {
    security_record_ = std::make_shared<record::SecurityRecord>(device_);
    std::shared_ptr<l2cap::classic::testing::MockFixedChannelManager> sptr =
        std::shared_ptr<l2cap::classic::testing::MockFixedChannelManager>(
            new l2cap::classic::testing::MockFixedChannelManager);
            new l2cap::classic::testing::MockFixedChannelManager());
    EXPECT_CALL(*sptr, RegisterService(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_))
        .Times(::testing::AnyNumber());
    pairing_handler_ = new pairing::ClassicPairingHandler(sptr, channel_, security_record_, handler_,