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

Commit a6cdcde6 authored by Rahul Arya's avatar Rahul Arya Committed by Gerrit Code Review
Browse files

Merge changes I34b8cea4,Ibe56093b,I918d0ede,I066a9a1f,Ifc38fcd8

* changes:
  [Connection Manager] Forward disconnection callbacks
  [Connection Manager] Implement direct + background connections
  [Connection Manager] Call into connection manager from C++
  [Connection Manager] Expose connection manager API from C++
  [Connection Manager] Add FFI to access le_impl from Rust
parents 4edfc104 c3bfd219
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ table InitFlagsData {
    set_min_encryption_is_enabled:bool (privacy:"Any");
    subrating_is_enabled:bool (privacy:"Any");
    trigger_advertising_callbacks_on_first_resume_after_pause_is_enabled:bool (privacy:"Any");
    use_unified_connection_manager_is_enabled:bool (privacy:"Any");
}
// LINT.ThenChange(/system/gd/dumpsys/init_flags.cc)

+2 −0
Original line number Diff line number Diff line
@@ -91,6 +91,8 @@ flatbuffers::Offset<bluetooth::common::InitFlagsData> bluetooth::dumpsys::InitFl
  builder.add_subrating_is_enabled(initFlags::subrating_is_enabled());
  builder.add_trigger_advertising_callbacks_on_first_resume_after_pause_is_enabled(
      initFlags::trigger_advertising_callbacks_on_first_resume_after_pause_is_enabled());
  builder.add_use_unified_connection_manager_is_enabled(
      initFlags::use_unified_connection_manager_is_enabled());

  return builder.Finish();
}
+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
Loading