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

Commit 25adcaa1 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I60ac5864,If37b0519,Ia9a24377 into tm-qpr-dev

* changes:
  leaudio: Improve set autoconnect on the Bluetooth On
  leaudio: Start using Targeted announcements
  connection_manager: Integrate targeted annoucement filtering
parents 58f91667 2322ebd8
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -605,6 +605,7 @@ cc_test {
        "le_audio/le_audio_types_test.cc",
        "le_audio/le_audio_types_test.cc",
        "le_audio/metrics_collector_linux.cc",
        "le_audio/metrics_collector_linux.cc",
        "le_audio/mock_iso_manager.cc",
        "le_audio/mock_iso_manager.cc",
        "test/common/btif_storage_mock.cc",
        "test/common/mock_controller.cc",
        "test/common/mock_controller.cc",
        "test/common/mock_csis_client.cc",
        "test/common/mock_csis_client.cc",
        "le_audio/state_machine.cc",
        "le_audio/state_machine.cc",
+27 −10
Original line number Original line Diff line number Diff line
@@ -253,6 +253,15 @@ class LeAudioClientImpl : public LeAudioClient {
    LeAudioGroupStateMachine::Initialize(state_machine_callbacks_);
    LeAudioGroupStateMachine::Initialize(state_machine_callbacks_);
    groupStateMachine_ = LeAudioGroupStateMachine::Get();
    groupStateMachine_ = LeAudioGroupStateMachine::Get();


    if (bluetooth::common::InitFlags::
            IsTargetedAnnouncementReconnectionMode()) {
      LOG_INFO(" Reconnection mode: TARGETED_ANNOUNCEMENTS");
      reconnection_mode_ = BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS;
    } else {
      LOG_INFO(" Reconnection mode: ALLOW_LIST");
      reconnection_mode_ = BTM_BLE_BKG_CONNECT_ALLOW_LIST;
    }

    BTA_GATTC_AppRegister(
    BTA_GATTC_AppRegister(
        le_audio_gattc_callback,
        le_audio_gattc_callback,
        base::Bind(
        base::Bind(
@@ -1199,12 +1208,12 @@ class LeAudioClientImpl : public LeAudioClient {
      LOG_WARN("Could not load ases");
      LOG_WARN("Could not load ases");
    }
    }


    if (autoconnect) {
    leAudioDevice->autoconnect_flag_ = autoconnect;
      leAudioDevice->SetConnectionState(
    /* When adding from storage, make sure that autoconnect is used
          DeviceConnectState::CONNECTING_AUTOCONNECT);
     * by all the devices in the group.
      leAudioDevice->autoconnect_flag_ = true;
     */
      BTA_GATTC_Open(gatt_if_, address, BTM_BLE_BKG_CONNECT_ALLOW_LIST, false);
    leAudioDevices_.SetInitialGroupAutoconnectState(
    }
        group_id, gatt_if_, reconnection_mode_, autoconnect);
  }
  }


  bool GetHandlesForStorage(const RawAddress& addr, std::vector<uint8_t>& out) {
  bool GetHandlesForStorage(const RawAddress& addr, std::vector<uint8_t>& out) {
@@ -1250,8 +1259,8 @@ class LeAudioClientImpl : public LeAudioClient {


    leAudioDevice->SetConnectionState(
    leAudioDevice->SetConnectionState(
        DeviceConnectState::CONNECTING_AUTOCONNECT);
        DeviceConnectState::CONNECTING_AUTOCONNECT);
    BTA_GATTC_Open(gatt_if_, leAudioDevice->address_,
    BTA_GATTC_Open(gatt_if_, leAudioDevice->address_, reconnection_mode_,
                   BTM_BLE_BKG_CONNECT_ALLOW_LIST, false);
                   false);
  }
  }


  void Disconnect(const RawAddress& address) override {
  void Disconnect(const RawAddress& address) override {
@@ -1825,7 +1834,7 @@ class LeAudioClientImpl : public LeAudioClient {
        leAudioDevice->autoconnect_flag_) {
        leAudioDevice->autoconnect_flag_) {
      leAudioDevice->SetConnectionState(
      leAudioDevice->SetConnectionState(
          DeviceConnectState::CONNECTING_AUTOCONNECT);
          DeviceConnectState::CONNECTING_AUTOCONNECT);
      BTA_GATTC_Open(gatt_if_, address, BTM_BLE_BKG_CONNECT_ALLOW_LIST, false);
      BTA_GATTC_Open(gatt_if_, address, reconnection_mode_, false);
    } else {
    } else {
      leAudioDevice->SetConnectionState(DeviceConnectState::DISCONNECTED);
      leAudioDevice->SetConnectionState(DeviceConnectState::DISCONNECTED);
    }
    }
@@ -3026,6 +3035,10 @@ class LeAudioClientImpl : public LeAudioClient {


  void Dump(int fd) {
  void Dump(int fd) {
    dprintf(fd, "  Active group: %d\n", active_group_id_);
    dprintf(fd, "  Active group: %d\n", active_group_id_);
    dprintf(fd, "    reconnection mode: %s \n",
            (reconnection_mode_ == BTM_BLE_BKG_CONNECT_ALLOW_LIST
                 ? " Allow List"
                 : " Targeted Announcements"));
    dprintf(fd, "    configuration: %s  (0x%08hx)\n",
    dprintf(fd, "    configuration: %s  (0x%08hx)\n",
            bluetooth::common::ToString(configuration_context_type_).c_str(),
            bluetooth::common::ToString(configuration_context_type_).c_str(),
            configuration_context_type_);
            configuration_context_type_);
@@ -4295,6 +4308,10 @@ class LeAudioClientImpl : public LeAudioClient {
  AudioState audio_sender_state_;
  AudioState audio_sender_state_;
  /* Keep in call state. */
  /* Keep in call state. */
  bool in_call_;
  bool in_call_;

  /* Reconnection mode */
  tBTM_BLE_CONN_TYPE reconnection_mode_;

  static constexpr char kNotifyUpperLayerAboutGroupBeingInIdleDuringCall[] =
  static constexpr char kNotifyUpperLayerAboutGroupBeingInIdleDuringCall[] =
      "persist.bluetooth.leaudio.notify.idle.during.call";
      "persist.bluetooth.leaudio.notify.idle.during.call";


+37 −0
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@
#include "bta_gatt_queue.h"
#include "bta_gatt_queue.h"
#include "bta_groups.h"
#include "bta_groups.h"
#include "bta_le_audio_api.h"
#include "bta_le_audio_api.h"
#include "btif_storage.h"
#include "btm_iso_api.h"
#include "btm_iso_api.h"
#include "btm_iso_api_types.h"
#include "btm_iso_api_types.h"
#include "device/include/controller.h"
#include "device/include/controller.h"
@@ -2726,6 +2727,42 @@ LeAudioDevice* LeAudioDevices::FindByCisConnHdl(uint8_t cig_id,
  return iter->get();
  return iter->get();
}
}


void LeAudioDevices::SetInitialGroupAutoconnectState(
    int group_id, int gatt_if, tBTM_BLE_CONN_TYPE reconnection_mode,
    bool current_dev_autoconnect_flag) {
  if (!current_dev_autoconnect_flag) {
    /* If current device autoconnect flag is false, check if there is other
     * device in the group which is in autoconnect mode.
     * If yes, assume whole group is in autoconnect.
     */
    auto iter = std::find_if(leAudioDevices_.begin(), leAudioDevices_.end(),
                             [&group_id](auto& d) {
                               LeAudioDevice* dev;
                               dev = d.get();
                               if (dev->group_id_ != group_id) {
                                 return false;
                               }
                               return dev->autoconnect_flag_;
                             });

    current_dev_autoconnect_flag = !(iter == leAudioDevices_.end());
  }

  if (!current_dev_autoconnect_flag) {
    return;
  }

  for (auto dev : leAudioDevices_) {
    if ((dev->group_id_ == group_id) &&
        (dev->GetConnectionState() == DeviceConnectState::DISCONNECTED)) {
      dev->SetConnectionState(DeviceConnectState::CONNECTING_AUTOCONNECT);
      dev->autoconnect_flag_ = true;
      btif_storage_set_leaudio_autoconnect(dev->address_, true);
      BTA_GATTC_Open(gatt_if, dev->address_, reconnection_mode, false);
    }
  }
}

size_t LeAudioDevices::Size() { return (leAudioDevices_.size()); }
size_t LeAudioDevices::Size() { return (leAudioDevices_.size()); }


void LeAudioDevices::Dump(int fd, int group_id) {
void LeAudioDevices::Dump(int fd, int group_id) {
+3 −0
Original line number Original line Diff line number Diff line
@@ -204,6 +204,9 @@ class LeAudioDevices {
  std::shared_ptr<LeAudioDevice> GetByAddress(const RawAddress& address);
  std::shared_ptr<LeAudioDevice> GetByAddress(const RawAddress& address);
  LeAudioDevice* FindByConnId(uint16_t conn_id);
  LeAudioDevice* FindByConnId(uint16_t conn_id);
  LeAudioDevice* FindByCisConnHdl(uint8_t cig_id, uint16_t conn_hdl);
  LeAudioDevice* FindByCisConnHdl(uint8_t cig_id, uint16_t conn_hdl);
  void SetInitialGroupAutoconnectState(int group_id, int gatt_if,
                                       tBTM_BLE_CONN_TYPE reconnection_mode,
                                       bool current_dev_autoconnect_flag);
  size_t Size(void);
  size_t Size(void);
  void Dump(int fd, int group_id);
  void Dump(int fd, int group_id);
  void Cleanup(tGATT_IF client_if);
  void Cleanup(tGATT_IF client_if);
+13 −6
Original line number Original line Diff line number Diff line
@@ -77,6 +77,7 @@ static constexpr char kNotifyUpperLayerAboutGroupBeingInIdleDuringCall[] =
    "persist.bluetooth.leaudio.notify.idle.during.call";
    "persist.bluetooth.leaudio.notify.idle.during.call";
const char* test_flags[] = {
const char* test_flags[] = {
    "INIT_logging_debug_enabled_for_all=true",
    "INIT_logging_debug_enabled_for_all=true",
    "INIT_leaudio_targeted_announcement_reconnection_mode=true",
    nullptr,
    nullptr,
};
};


@@ -2446,7 +2447,8 @@ TEST_F(UnicastTest, ConnectRemoteDisconnectOneEarbud) {
      .Times(1);
      .Times(1);
  /* For remote disconnection, expect stack to try background re-connect */
  /* For remote disconnection, expect stack to try background re-connect */
  EXPECT_CALL(mock_gatt_interface_,
  EXPECT_CALL(mock_gatt_interface_,
              Open(gatt_if, test_address0, BTM_BLE_BKG_CONNECT_ALLOW_LIST, _))
              Open(gatt_if, test_address0,
                   BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS, _))
      .Times(1);
      .Times(1);


  EXPECT_CALL(mock_audio_hal_client_callbacks_,
  EXPECT_CALL(mock_audio_hal_client_callbacks_,
@@ -2612,7 +2614,8 @@ TEST_F(UnicastTestNoInit, LoadStoredEarbudsCsisGrouped) {
  ON_CALL(mock_btm_interface_, BTM_IsEncrypted(test_address0, _))
  ON_CALL(mock_btm_interface_, BTM_IsEncrypted(test_address0, _))
      .WillByDefault(DoAll(Return(true)));
      .WillByDefault(DoAll(Return(true)));
  EXPECT_CALL(mock_gatt_interface_,
  EXPECT_CALL(mock_gatt_interface_,
              Open(gatt_if, test_address0, BTM_BLE_BKG_CONNECT_ALLOW_LIST, _))
              Open(gatt_if, test_address0,
                   BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS, _))
      .Times(1);
      .Times(1);


  // Expect stored device1 to connect automatically
  // Expect stored device1 to connect automatically
@@ -2622,7 +2625,8 @@ TEST_F(UnicastTestNoInit, LoadStoredEarbudsCsisGrouped) {
  ON_CALL(mock_btm_interface_, BTM_IsEncrypted(test_address1, _))
  ON_CALL(mock_btm_interface_, BTM_IsEncrypted(test_address1, _))
      .WillByDefault(DoAll(Return(true)));
      .WillByDefault(DoAll(Return(true)));
  EXPECT_CALL(mock_gatt_interface_,
  EXPECT_CALL(mock_gatt_interface_,
              Open(gatt_if, test_address1, BTM_BLE_BKG_CONNECT_ALLOW_LIST, _))
              Open(gatt_if, test_address1,
                   BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS, _))
      .Times(1);
      .Times(1);


  ON_CALL(mock_groups_module_, GetGroupId(_, _))
  ON_CALL(mock_groups_module_, GetGroupId(_, _))
@@ -2743,7 +2747,8 @@ TEST_F(UnicastTestNoInit, LoadStoredEarbudsCsisGroupedDifferently) {
  ON_CALL(mock_btm_interface_, BTM_IsEncrypted(test_address0, _))
  ON_CALL(mock_btm_interface_, BTM_IsEncrypted(test_address0, _))
      .WillByDefault(DoAll(Return(true)));
      .WillByDefault(DoAll(Return(true)));
  EXPECT_CALL(mock_gatt_interface_,
  EXPECT_CALL(mock_gatt_interface_,
              Open(gatt_if, test_address0, BTM_BLE_BKG_CONNECT_ALLOW_LIST, _))
              Open(gatt_if, test_address0,
                   BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS, _))
      .Times(1);
      .Times(1);


  // Expect stored device1 to NOT connect automatically
  // Expect stored device1 to NOT connect automatically
@@ -2753,7 +2758,8 @@ TEST_F(UnicastTestNoInit, LoadStoredEarbudsCsisGroupedDifferently) {
  ON_CALL(mock_btm_interface_, BTM_IsEncrypted(test_address1, _))
  ON_CALL(mock_btm_interface_, BTM_IsEncrypted(test_address1, _))
      .WillByDefault(DoAll(Return(true)));
      .WillByDefault(DoAll(Return(true)));
  EXPECT_CALL(mock_gatt_interface_,
  EXPECT_CALL(mock_gatt_interface_,
              Open(gatt_if, test_address1, BTM_BLE_BKG_CONNECT_ALLOW_LIST, _))
              Open(gatt_if, test_address1,
                   BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS, _))
      .Times(0);
      .Times(0);


  // Initialize
  // Initialize
@@ -3729,7 +3735,8 @@ TEST_F(UnicastTest, TwoEarbuds2ndDisconnected) {
  }
  }


  EXPECT_CALL(mock_gatt_interface_,
  EXPECT_CALL(mock_gatt_interface_,
              Open(_, device->address_, BTM_BLE_BKG_CONNECT_ALLOW_LIST, false))
              Open(_, device->address_,
                   BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS, false))
      .Times(1);
      .Times(1);


  auto conn_id = device->conn_id_;
  auto conn_id = device->conn_id_;
Loading