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

Commit 97e42903 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: If TA reconnection policy is enabled, autoconnect is always on

With this patch, autoconnect flag is always enabled when TA is enabled.
Thanks to that, LE HS will be always available to reconnect

Bug: 277557618
Test: atest BluetoothInstrumentationTests
Test: manual
Tag: #feature

Change-Id: I85af7a6998f8fdf0161ed51750454bd8a91b2da3
parent 84446b40
Loading
Loading
Loading
Loading
+16 −12
Original line number Diff line number Diff line
@@ -1207,6 +1207,10 @@ class LeAudioClientImpl : public LeAudioClient {
      return;
    }

    /* Remove device from the background connect if it is there */
    BTA_GATTC_CancelOpen(gatt_if_, address, false);
    btif_storage_set_leaudio_autoconnect(address, false);

    LOG_INFO("%s, state: %s", ADDRESS_TO_LOGGABLE_CSTR(address),
             bluetooth::common::ToString(leAudioDevice->GetConnectionState())
                 .c_str());
@@ -1224,8 +1228,6 @@ class LeAudioClientImpl : public LeAudioClient {
        [[fallthrough]];
      case DeviceConnectState::DISCONNECTING:
      case DeviceConnectState::DISCONNECTING_AND_RECOVER:
        /* Remove device from the background connect if it is there */
        BTA_GATTC_CancelOpen(gatt_if_, address, false);
        /* Device is disconnecting, just mark it shall be removed after all. */
        leAudioDevice->SetConnectionState(DeviceConnectState::REMOVING);
        return;
@@ -1233,9 +1235,6 @@ class LeAudioClientImpl : public LeAudioClient {
        BTA_GATTC_CancelOpen(gatt_if_, address, true);
        [[fallthrough]];
      case DeviceConnectState::CONNECTING_AUTOCONNECT:
        /* Cancel background conection */
        BTA_GATTC_CancelOpen(gatt_if_, address, false);
        break;
      case DeviceConnectState::DISCONNECTED:
        /* Do nothing, just remove device  */
        break;
@@ -1451,20 +1450,25 @@ class LeAudioClientImpl : public LeAudioClient {
        break;
      case DeviceConnectState::CONNECTED: {
        /* User is disconnecting the device, we shall remove the autoconnect
         * flag for this device and all others
         * flag for this device and all others if not TA is used
         */
        /* If target announcement is used, do not remove autoconnect
         */
        bool remove_from_autoconnect =
            (reconnection_mode_ != BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS);

        if (leAudioDevice->autoconnect_flag_ && remove_from_autoconnect) {
          LOG_INFO("Removing autoconnect flag for group_id %d",
                   leAudioDevice->group_id_);

        if (leAudioDevice->autoconnect_flag_) {
          /* Removes device from background connect */
          BTA_GATTC_CancelOpen(gatt_if_, address, false);
          btif_storage_set_leaudio_autoconnect(address, false);
          leAudioDevice->autoconnect_flag_ = false;
        }
        auto group = aseGroups_.FindById(leAudioDevice->group_id_);

        if (group) {
        auto group = aseGroups_.FindById(leAudioDevice->group_id_);
        if (group && remove_from_autoconnect) {
          /* Remove devices from auto connect mode */
          for (auto dev = group->GetFirstDevice(); dev;
               dev = group->GetNextDevice(dev)) {
@@ -2074,7 +2078,7 @@ class LeAudioClientImpl : public LeAudioClient {
  }

  void scheduleGroupConnectedCheck(int group_id) {
    LOG_INFO("Schedule group_id %d streaming check.", group_id);
    LOG_INFO("Schedule group_id %d connected check.", group_id);
    do_in_main_thread_delayed(
        FROM_HERE,
        base::BindOnce(
+30 −8
Original line number Diff line number Diff line
@@ -2518,10 +2518,13 @@ TEST_F(UnicastTest, ConnectTwoEarbudsCsisGrouped) {

  Mock::VerifyAndClearExpectations(&mock_btif_storage_);

  /* for Target announcements AutoConnect is always there, until
   * device is removed
   */
  EXPECT_CALL(mock_btif_storage_, AddLeaudioAutoconnect(test_address1, false))
      .Times(1);
      .Times(0);
  EXPECT_CALL(mock_btif_storage_, AddLeaudioAutoconnect(test_address0, false))
      .Times(1);
      .Times(0);

  // Verify grouping information
  std::vector<RawAddress> devs =
@@ -2567,10 +2570,13 @@ TEST_F(UnicastTest, ConnectTwoEarbudsCsisGroupUnknownAtConnect) {
  ASSERT_NE(std::find(devs.begin(), devs.end(), test_address0), devs.end());
  ASSERT_NE(std::find(devs.begin(), devs.end(), test_address1), devs.end());

  /* for Target announcements AutoConnect is always there, until
   *  device is removed
   */
  EXPECT_CALL(mock_btif_storage_, AddLeaudioAutoconnect(test_address1, false))
      .Times(1);
      .Times(0);
  EXPECT_CALL(mock_btif_storage_, AddLeaudioAutoconnect(test_address0, false))
      .Times(1);
      .Times(0);
  DisconnectLeAudio(test_address0, 1);
  DisconnectLeAudio(test_address1, 2);
}
@@ -2919,6 +2925,7 @@ TEST_F(UnicastTest, GroupingAddRemove) {
  SyncOnMainLoop();

  Mock::VerifyAndClearExpectations(&mock_groups_module_);
  Mock::VerifyAndClearExpectations(&mock_btif_storage_);

  EXPECT_CALL(mock_groups_module_, AddDevice(test_address1, _, group_id0))
      .Times(1);
@@ -3346,8 +3353,11 @@ TEST_F(UnicastTest, DisconnectDeviceWhenConnected) {
  Mock::VerifyAndClearExpectations(&mock_btif_storage_);
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);

  /* for Target announcements AutoConnect is always there, until
   * device is removed
   */
  EXPECT_CALL(mock_btif_storage_, AddLeaudioAutoconnect(test_address0, false))
      .Times(1);
      .Times(0);
  EXPECT_CALL(mock_gatt_queue_, Clean(conn_id)).Times(AtLeast(1));
  EXPECT_CALL(mock_gatt_interface_, Close(conn_id)).Times(1);

@@ -4158,15 +4168,27 @@ TEST_F(UnicastTest, TwoEarbudsStreamingProfileDisconnect) {
  uint8_t cis_count_in = 0;
  TestAudioDataTransfer(group_id, cis_count_out, cis_count_in, 1920);

  // Disconnect one device and expect the group to keep on streaming
  EXPECT_CALL(mock_gatt_interface_,
              Open(_, _, BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS, _))
      .Times(1);
  EXPECT_CALL(mock_gatt_interface_,
              Open(_, _, BTM_BLE_BKG_CONNECT_ALLOW_LIST, _))
      .Times(1);
  EXPECT_CALL(mock_state_machine_, StopStream(_)).Times(1);
  EXPECT_CALL(mock_gatt_interface_, Open(_, _, _, _)).Times(0);

  DisconnectLeAudio(test_address0, 1);
  SyncOnMainLoop();
  Mock::VerifyAndClearExpectations(&mock_gatt_interface_);
  Mock::VerifyAndClearExpectations(&mock_state_machine_);

  EXPECT_CALL(mock_gatt_interface_,
              Open(_, _, BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS, _))
      .Times(1);

  DisconnectLeAudio(test_address1, 2);

  SyncOnMainLoop();
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
  Mock::VerifyAndClearExpectations(&mock_gatt_interface_);
}

TEST_F(UnicastTest, EarbudsWithStereoSinkMonoSourceSupporting32kHz) {