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

Commit f3172f01 authored by Rongxuan Liu's avatar Rongxuan Liu
Browse files

Restore advertising enable parameters onResume

When starting extended advertsing, we're not saving the enabled set
duration and max events parameters together with set id. This caused
issue that we're reenableing advertising set with wrong parameters
when advertsinig_manager onResume().

We need to save the parameters as well at enabling advertising. Added
unit test to cover this change and validated the original issue exists
and the fix works.

Test: atest bluetooth_test_gd_unit
Bug: 281900690
Change-Id: I0d58a4e6a13d21295b293caeeb756938735bbef7
parent 292e410b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1230,6 +1230,12 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb

    if (enable) {
      enabled_sets_[advertiser_id].advertising_handle_ = advertiser_id;
      if (advertising_api_type_ == AdvertisingApiType::EXTENDED) {
        enabled_sets_[advertiser_id].duration_ = duration;
        enabled_sets_[advertiser_id].max_extended_advertising_events_ =
            max_extended_advertising_events;
      }

      advertising_sets_[advertiser_id].duration = duration;
      advertising_sets_[advertiser_id].max_extended_advertising_events = max_extended_advertising_events;
    } else {
+41 −0
Original line number Diff line number Diff line
@@ -1717,6 +1717,47 @@ TEST_F(LeExtendedAdvertisingAPITest, trigger_advertiser_callbacks_if_started_whi
  sync_client_handler();
}

TEST_F(LeExtendedAdvertisingAPITest, duration_maxevents_restored_on_resume) {
  // arrange
  auto test_le_address_manager = (TestLeAddressManager*)test_acl_manager_->GetLeAddressManager();
  uint16_t duration = 1000;
  uint8_t max_extended_advertising_events = 100;

  // enable advertiser
  le_advertising_manager_->EnableAdvertiser(
      advertiser_id_, true, duration, max_extended_advertising_events);
  ASSERT_EQ(OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE, test_hci_layer_->GetCommand().GetOpCode());
  EXPECT_CALL(
      mock_advertising_callback_,
      OnAdvertisingEnabled(advertiser_id_, true, AdvertisingCallback::AdvertisingStatus::SUCCESS));
  test_hci_layer_->IncomingEvent(
      LeSetExtendedAdvertisingEnableCompleteBuilder::Create(uint8_t{1}, ErrorCode::SUCCESS));

  test_le_address_manager->client_->OnPause();
  // verify advertising is disabled onPause
  ASSERT_EQ(OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE, test_hci_layer_->GetCommand().GetOpCode());
  test_hci_layer_->IncomingEvent(
      LeSetExtendedAdvertisingEnableCompleteBuilder::Create(1, ErrorCode::SUCCESS));
  sync_client_handler();

  test_le_address_manager->client_->OnResume();
  // verify advertising is reenabled onResume with correct parameters
  auto command = test_hci_layer_->GetCommand();
  ASSERT_EQ(OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE, command.GetOpCode());
  auto enable_command_view =
      LeSetExtendedAdvertisingEnableView::Create(LeAdvertisingCommandView::Create(command));
  ASSERT_TRUE(enable_command_view.IsValid());
  ASSERT_EQ(bluetooth::hci::Enable::ENABLED, enable_command_view.GetEnable());
  auto enabled_sets = enable_command_view.GetEnabledSets();
  ASSERT_EQ(static_cast<uint8_t>(1), enabled_sets.size());
  ASSERT_EQ(duration, enabled_sets[0].duration_);
  ASSERT_EQ(max_extended_advertising_events, enabled_sets[0].max_extended_advertising_events_);
  test_hci_layer_->IncomingEvent(
      LeSetExtendedAdvertisingEnableCompleteBuilder::Create(1, ErrorCode::SUCCESS));

  sync_client_handler();
}

TEST_F(LeExtendedAdvertisingAPITest, no_callbacks_on_pause) {
  // arrange
  auto test_le_address_manager = (TestLeAddressManager*)test_acl_manager_->GetLeAddressManager();