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

Commit a2a23790 authored by Rahul Arya's avatar Rahul Arya
Browse files

Revert^2 [Connection Manager] Forward disconnection callbacks

Bug: 272572974
Test: platinum tests

This reverts commit b6fbc18a.

Change-Id: I168473c96f060fee655c868b57cb9ef510613bc1
parent 0a8b9be1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -35,6 +35,12 @@ class LeAcceptlistCallbacks {
  // Invoked when controller sends Connection Complete event with Success error code
  // AddressWithType is the address returned by the controller.
  virtual void OnLeConnectSuccess(AddressWithType) = 0;
  // Invoked when controller sends Connection Complete event with failing error code
  // AddressWithType is the address returned by the controller.
  virtual void OnLeConnectFail(AddressWithType, ErrorCode reason) = 0;
  // Invoked when an LE connection is disconnected. AddressWithType is the remote address
  // associated with this connection at the time of connection.
  virtual void OnLeDisconnection(AddressWithType) = 0;
  // Invoked when the resolving list has changed, so we need to re-resolve our addresses.
  virtual void OnResolvingListChange() = 0;
};
+18 −20
Original line number Diff line number Diff line
@@ -313,6 +313,17 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    return connections.send_packet_upward(handle, cb);
  }

  void report_le_connection_failure(AddressWithType address, ErrorCode status) {
    le_client_handler_->Post(common::BindOnce(
        &LeConnectionCallbacks::OnLeConnectFail,
        common::Unretained(le_client_callbacks_),
        address,
        status));
    if (le_acceptlist_callbacks_ != nullptr) {
      le_acceptlist_callbacks_->OnLeConnectFail(address, status);
    }
  }

  // connection canceled by LeAddressManager.OnPause(), will auto reconnect by LeAddressManager.OnResume()
  void on_le_connection_canceled_on_pause() {
    ASSERT_LOG(pause_connection, "Connection must be paused to ack the le address manager");
@@ -387,11 +398,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
      }

      if (status != ErrorCode::SUCCESS) {
        le_client_handler_->Post(common::BindOnce(
            &LeConnectionCallbacks::OnLeConnectFail,
            common::Unretained(le_client_callbacks_),
            remote_address,
            status));
        report_le_connection_failure(remote_address, status);
        return;
      }
    } else {
@@ -404,11 +411,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
      if (status != ErrorCode::SUCCESS) {
        std::string error_code = ErrorCodeText(status);
        LOG_WARN("Received on_le_connection_complete with error code %s", error_code.c_str());
        le_client_handler_->Post(common::BindOnce(
            &LeConnectionCallbacks::OnLeConnectFail,
            common::Unretained(le_client_callbacks_),
            remote_address,
            status));
        report_le_connection_failure(remote_address, status);
        return;
      }

@@ -543,11 +546,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
      }

      if (status != ErrorCode::SUCCESS) {
        le_client_handler_->Post(common::BindOnce(
            &LeConnectionCallbacks::OnLeConnectFail,
            common::Unretained(le_client_callbacks_),
            remote_address,
            status));
        report_le_connection_failure(remote_address, status);
        return;
      }

@@ -561,11 +560,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
      if (status != ErrorCode::SUCCESS) {
        std::string error_code = ErrorCodeText(status);
        LOG_WARN("Received on_le_enhanced_connection_complete with error code %s", error_code.c_str());
        le_client_handler_->Post(common::BindOnce(
            &LeConnectionCallbacks::OnLeConnectFail,
            common::Unretained(le_client_callbacks_),
            remote_address,
            status));
        report_le_connection_failure(remote_address, status);
        return;
      }

@@ -668,6 +663,9 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
          callbacks->OnDisconnection(reason);
        },
        kRemoveConnectionAfterwards);
    if (le_acceptlist_callbacks_ != nullptr) {
      le_acceptlist_callbacks_->OnLeDisconnection(remote_address);
    }
    connections.crash_on_unknown_handle_ = event_also_routes_to_other_receivers;

    if (background_connections_.count(remote_address) == 1) {
+87 −1
Original line number Diff line number Diff line
@@ -407,7 +407,9 @@ class MockLeConnectionCallbacks : public LeConnectionCallbacks {

class MockLeAcceptlistCallbacks : public LeAcceptlistCallbacks {
 public:
  MOCK_METHOD(void, OnLeConnectSuccess, (AddressWithType address_with_type), (override));
  MOCK_METHOD(void, OnLeConnectSuccess, (AddressWithType address), (override));
  MOCK_METHOD(void, OnLeConnectFail, (AddressWithType address, ErrorCode reason), (override));
  MOCK_METHOD(void, OnLeDisconnection, (AddressWithType address), (override));
  MOCK_METHOD(void, OnResolvingListChange, (), (override));
};

@@ -1726,6 +1728,90 @@ TEST_F(LeImplTest, ResolvingListCallback) {
  Mock::VerifyAndClearExpectations(&callbacks);
}

TEST_F(LeImplTest, ConnectionFailedAcceptlistCallback) {
  // arrange
  MockLeAcceptlistCallbacks callbacks;
  le_impl_->handle_register_le_acceptlist_callbacks(&callbacks);
  set_random_device_address_policy();

  // expect
  AddressWithType remote_address;
  ErrorCode reason;
  EXPECT_CALL(callbacks, OnLeConnectFail(_, _))
      .WillOnce([&](AddressWithType addr, ErrorCode error) {
        remote_address = addr;
        reason = error;
      });

  // act
  auto command = LeEnhancedConnectionCompleteBuilder::Create(
      ErrorCode::CONTROLLER_BUSY,
      kHciHandle,
      Role::PERIPHERAL,
      AddressType::PUBLIC_DEVICE_ADDRESS,
      remote_address_,
      local_rpa_,
      remote_rpa_,
      0x0024,
      0x0000,
      0x0011,
      ClockAccuracy::PPM_30);
  auto bytes = Serialize<LeEnhancedConnectionCompleteBuilder>(std::move(command));
  auto view = CreateLeEventView<hci::LeEnhancedConnectionCompleteView>(bytes);
  ASSERT_TRUE(view.IsValid());
  le_impl_->on_le_event(view);
  sync_handler();

  // assert
  EXPECT_EQ(remote_address, remote_public_address_with_type_);
  EXPECT_EQ(reason, ErrorCode::CONTROLLER_BUSY);
}

TEST_F(LeImplTest, DisconnectionAcceptlistCallback) {
  // expect
  MockLeAcceptlistCallbacks callbacks;
  AddressWithType remote_address;
  EXPECT_CALL(callbacks, OnLeDisconnection(_)).WillOnce([&](AddressWithType addr) {
    remote_address = addr;
  });
  // we need to capture the LeAclConnection so it is not immediately dropped => disconnected
  std::unique_ptr<LeAclConnection> connection;
  EXPECT_CALL(mock_le_connection_callbacks_, OnLeConnectSuccess(_, _))
      .WillOnce([&](AddressWithType, std::unique_ptr<LeAclConnection> conn) {
        connection = std::move(conn);
        connection->RegisterCallbacks(&connection_management_callbacks_, handler_);
      });

  // arrange: an active connection to a peer
  le_impl_->handle_register_le_acceptlist_callbacks(&callbacks);
  set_random_device_address_policy();
  auto command = LeEnhancedConnectionCompleteBuilder::Create(
      ErrorCode::SUCCESS,
      kHciHandle,
      Role::PERIPHERAL,
      AddressType::PUBLIC_DEVICE_ADDRESS,
      remote_address_,
      local_rpa_,
      remote_rpa_,
      0x0024,
      0x0000,
      0x0011,
      ClockAccuracy::PPM_30);
  auto bytes = Serialize<LeEnhancedConnectionCompleteBuilder>(std::move(command));
  auto view = CreateLeEventView<hci::LeEnhancedConnectionCompleteView>(bytes);
  ASSERT_TRUE(view.IsValid());
  le_impl_->on_le_event(view);
  sync_handler();

  // act
  le_impl_->on_le_disconnect(kHciHandle, ErrorCode::REMOTE_USER_TERMINATED_CONNECTION);
  sync_handler();

  // assert
  EXPECT_EQ(remote_public_address_with_type_, remote_address);
  Mock::VerifyAndClearExpectations(&callbacks);
}

}  // namespace acl_manager
}  // namespace hci
}  // namespace bluetooth
+1 −1
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ mod inner {
        fn on_le_connect_success(&self, address: AddressWithType);
        #[cxx_name = "OnLeConnectFail"]
        fn on_le_connect_fail(&self, address: AddressWithType, status: u8);
        #[cxx_name = "OnDisconnect"]
        #[cxx_name = "OnLeDisconnection"]
        fn on_disconnect(&self, address: AddressWithType);
    }

+13 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ struct LeAclManagerCallbackShim {
  void OnLeConnectFail(core::AddressWithType addr, uint8_t status) const {
    LOG_ALWAYS_FATAL("system/rust not available in Floss");
  };
  void OnDisconnect(core::AddressWithType addr) const {
  void OnLeDisconnection(core::AddressWithType addr) const {
    LOG_ALWAYS_FATAL("system/rust not available in Floss");
  };
};
@@ -104,6 +104,18 @@ struct LeAclManagerShim::impl : hci::acl_manager::LeAcceptlistCallbacks {
    callbacks_.value()->OnLeConnectSuccess(ToRustAddress(address));
  }

  // hci::acl_manager::LeAcceptlistCallbacks
  virtual void OnLeConnectFail(hci::AddressWithType address,
                               hci::ErrorCode reason) {
    callbacks_.value()->OnLeConnectFail(ToRustAddress(address),
                                        static_cast<uint8_t>(reason));
  }

  // hci::acl_manager::LeAcceptlistCallbacks
  virtual void OnLeDisconnection(hci::AddressWithType address) {
    callbacks_.value()->OnLeDisconnection(ToRustAddress(address));
  }

  // hci::acl_manager::LeAcceptlistCallbacks
  virtual void OnResolvingListChange() {}

Loading