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

Commit 705a4b14 authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Automerger Merge Worker
Browse files

Merge "leaudio: Add member of streaming group to allow list" am: d8a409ce...

Merge "leaudio: Add member of streaming group to allow list" am: d8a409ce am: f14f9135 am: ba604b27 am: 59ba3d3b

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2523735



Change-Id: I1cb021e14f2ce956aaf31aabb9970b6db75c2283
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents ac650e20 59ba3d3b
Loading
Loading
Loading
Loading
+47 −2
Original line number Diff line number Diff line
@@ -1716,6 +1716,35 @@ class LeAudioClientImpl : public LeAudioClient {
    LeAudioCharValueHandle(conn_id, hdl, len, value);
  }

  bool IsDeviceGroupStreaming(LeAudioDevice* leAudioDevice) {
    LOG_DEBUG("%s", ADDRESS_TO_LOGGABLE_CSTR(leAudioDevice->address_));

    if (leAudioDevice->group_id_ != active_group_id_) {
      return false;
    }
    auto group = aseGroups_.FindById(active_group_id_);
    return (group != nullptr &&
            group->GetState() == AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING);
  }

  void AddToBackgroundConnectCheckStreaming(LeAudioDevice* leAudioDevice) {
    /* If device belongs to streaming group, add it on allow list */
    auto address = leAudioDevice->address_;
    if (IsDeviceGroupStreaming(leAudioDevice)) {
      LOG_INFO("Group %d in streaming state. Adding %s to allow list ",
               leAudioDevice->group_id_, ADDRESS_TO_LOGGABLE_CSTR(address));
      /* Make sure TA is canceled before adding to allow list */
      BTA_GATTC_CancelOpen(gatt_if_, address, false);
      BTA_GATTC_Open(gatt_if_, address, BTM_BLE_BKG_CONNECT_ALLOW_LIST, false);
    } else {
      LOG_INFO(
          "Adding %s to backgroud connect (default reconnection_mode "
          "(0x%02x))",
          ADDRESS_TO_LOGGABLE_CSTR(address), reconnection_mode_);
      BTA_GATTC_Open(gatt_if_, address, reconnection_mode_, false);
    }
  }

  void OnGattConnected(tGATT_STATUS status, uint16_t conn_id,
                       tGATT_IF client_if, RawAddress address,
                       tBT_TRANSPORT transport, uint16_t mtu) {
@@ -1731,7 +1760,7 @@ class LeAudioClientImpl : public LeAudioClient {
              DeviceConnectState::CONNECTING_AUTOCONNECT ||
          leAudioDevice->autoconnect_flag_) {
        LOG_INFO("Device not available now, do background connect.");
        BTA_GATTC_Open(gatt_if_, address, reconnection_mode_, false);
        AddToBackgroundConnectCheckStreaming(leAudioDevice);
        return;
      }

@@ -1949,11 +1978,19 @@ class LeAudioClientImpl : public LeAudioClient {
     * or if autoconnect is set and device got disconnected because of some
     * issues
     */
    LOG_INFO("%s, autoconnect %d, reason 0x%02x",
             ADDRESS_TO_LOGGABLE_CSTR(leAudioDevice->address_),
             leAudioDevice->autoconnect_flag_, reason);

    if (reason != GATT_CONN_TERMINATE_LOCAL_HOST ||
        leAudioDevice->autoconnect_flag_) {
      leAudioDevice->SetConnectionState(
          DeviceConnectState::CONNECTING_AUTOCONNECT);
      if (reason == GATT_CONN_TIMEOUT) {
        AddToBackgroundConnectCheckStreaming(leAudioDevice);
      } else {
        BTA_GATTC_Open(gatt_if_, address, reconnection_mode_, false);
      }
    } else {
      leAudioDevice->SetConnectionState(DeviceConnectState::DISCONNECTED);
    }
@@ -4695,6 +4732,10 @@ class LeAudioClientImpl : public LeAudioClient {

        if (group) {
          updateOffloaderIfNeeded(group);
          if (reconnection_mode_ ==
              BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS) {
            group->AddToAllowListNotConnectedGroupMembers(gatt_if_);
          }
        }

        if (audio_sender_state_ == AudioState::READY_TO_START)
@@ -4766,6 +4807,10 @@ class LeAudioClientImpl : public LeAudioClient {
          HandlePendingAvailableContextsChange(group);
          HandlePendingDeviceRemove(group);
          HandlePendingDeviceDisconnection(group);
          if (reconnection_mode_ ==
              BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS) {
            group->RemoveFromAllowListNotConnectedGroupMembers(gatt_if_);
          }
        }
        break;
      }
+45 −0
Original line number Diff line number Diff line
@@ -1948,6 +1948,51 @@ void LeAudioDeviceGroup::ClearPendingConfiguration(void) {
  stream_conf.pending_configuration = false;
}

void LeAudioDeviceGroup::AddToAllowListNotConnectedGroupMembers(int gatt_if) {
  for (const auto& device_iter : leAudioDevices_) {
    auto connection_state = device_iter.lock()->GetConnectionState();
    if (connection_state == DeviceConnectState::CONNECTED ||
        connection_state == DeviceConnectState::CONNECTING_BY_USER ||
        connection_state ==
            DeviceConnectState::CONNECTED_BY_USER_GETTING_READY ||
        connection_state ==
            DeviceConnectState::CONNECTED_AUTOCONNECT_GETTING_READY) {
      continue;
    }

    auto address = device_iter.lock()->address_;
    LOG_INFO("Group %d in state %s. Adding %s to allow list ", group_id_,
             bluetooth::common::ToString(GetState()).c_str(),
             ADDRESS_TO_LOGGABLE_CSTR(address));

    BTA_GATTC_CancelOpen(gatt_if, address, false);
    BTA_GATTC_Open(gatt_if, address, BTM_BLE_BKG_CONNECT_ALLOW_LIST, false);
    device_iter.lock()->SetConnectionState(
        DeviceConnectState::CONNECTING_AUTOCONNECT);
  }
}

void LeAudioDeviceGroup::RemoveFromAllowListNotConnectedGroupMembers(
    int gatt_if) {
  for (const auto& device_iter : leAudioDevices_) {
    auto connection_state = device_iter.lock()->GetConnectionState();
    if (connection_state != DeviceConnectState::CONNECTING_AUTOCONNECT) {
      continue;
    }

    auto address = device_iter.lock()->address_;
    LOG_INFO(
        "Group %d in state %s. Adding %s back to target announcement"
        "reconnect policy",
        group_id_, bluetooth::common::ToString(GetState()).c_str(),
        ADDRESS_TO_LOGGABLE_CSTR(address));

    BTA_GATTC_CancelOpen(gatt_if, address, false);
    BTA_GATTC_Open(gatt_if, address, BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS,
                   false);
  }
}

bool LeAudioDeviceGroup::IsConfigurationSupported(
    LeAudioDevice* leAudioDevice,
    const set_configurations::AudioSetConfiguration* audio_set_conf) {
+2 −0
Original line number Diff line number Diff line
@@ -339,6 +339,8 @@ class LeAudioDeviceGroup {
  bool IsPendingConfiguration(void);
  void SetPendingConfiguration(void);
  void ClearPendingConfiguration(void);
  void AddToAllowListNotConnectedGroupMembers(int gatt_if);
  void RemoveFromAllowListNotConnectedGroupMembers(int gatt_if);
  bool IsConfigurationSupported(
      LeAudioDevice* leAudioDevice,
      const set_configurations::AudioSetConfiguration* audio_set_conf);