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

Commit 87141c9e authored by Łukasz Rymanowski's avatar Łukasz Rymanowski Committed by Gerrit Code Review
Browse files

Merge "leaudio: Fix recovery reconnect"

parents d8df5286 bd7e9846
Loading
Loading
Loading
Loading
+38 −6
Original line number Original line Diff line number Diff line
@@ -1986,6 +1986,39 @@ class LeAudioClientImpl : public LeAudioClient {
    );
    );
  }
  }


  void recoveryReconnect(RawAddress address) {
    LOG_INFO("Reconnecting to %s after timeout on state machine.",
             ADDRESS_TO_LOGGABLE_CSTR(address));
    LeAudioDevice* leAudioDevice = leAudioDevices_.FindByAddress(address);

    if (leAudioDevice == nullptr ||
        leAudioDevice->GetConnectionState() !=
            DeviceConnectState::DISCONNECTING_AND_RECOVER) {
      LOG_WARN("Device %s, not interested in recovery connect anymore",
               ADDRESS_TO_LOGGABLE_CSTR(address));
      return;
    }

    leAudioDevice->SetConnectionState(
        DeviceConnectState::CONNECTING_AUTOCONNECT);
    BTA_GATTC_Open(gatt_if_, address, BTM_BLE_DIRECT_CONNECTION, false);
  }

  void scheduleRecoveryReconnect(RawAddress& address) {
    LOG_INFO("Schedule reconnecting to %s after timeout on state machine.",
             ADDRESS_TO_LOGGABLE_CSTR(address));
    do_in_main_thread_delayed(
        FROM_HERE,
        base::BindOnce(&LeAudioClientImpl::recoveryReconnect,
                       base::Unretained(this), address),
#if BASE_VER < 931007
        base::TimeDelta::FromMilliseconds(kRecoveryReconnectDelayMs)
#else
        base::Milliseconds(kDeviceAttachDelayMs)
#endif
    );
  }

  void OnGattDisconnected(uint16_t conn_id, tGATT_IF client_if,
  void OnGattDisconnected(uint16_t conn_id, tGATT_IF client_if,
                          RawAddress address, tGATT_DISCONN_REASON reason) {
                          RawAddress address, tGATT_DISCONN_REASON reason) {
    LeAudioDevice* leAudioDevice = leAudioDevices_.FindByAddress(address);
    LeAudioDevice* leAudioDevice = leAudioDevices_.FindByAddress(address);
@@ -2026,13 +2059,11 @@ class LeAudioClientImpl : public LeAudioClient {
        DeviceConnectState::DISCONNECTING_AND_RECOVER) {
        DeviceConnectState::DISCONNECTING_AND_RECOVER) {
      /* We are back after disconnecting device which was in a bad state.
      /* We are back after disconnecting device which was in a bad state.
       * lets try to reconnected - 30 sec with direct connect and later fallback
       * lets try to reconnected - 30 sec with direct connect and later fallback
       * to default background reconnection mode
       * to default background reconnection mode.
       * Since GATT notifies us before ACL was dropped, let's wait a bit
       * before we do reconnect.
       */
       */
      LOG_INFO("Reconnecting to %s after timeout on state machine.",
      scheduleRecoveryReconnect(address);
               ADDRESS_TO_LOGGABLE_CSTR(address));
      leAudioDevice->SetConnectionState(
          DeviceConnectState::CONNECTING_AUTOCONNECT);
      BTA_GATTC_Open(gatt_if_, address, BTM_BLE_DIRECT_CONNECTION, false);
      return;
      return;
    }
    }


@@ -4922,6 +4953,7 @@ class LeAudioClientImpl : public LeAudioClient {
  /* Reconnection mode */
  /* Reconnection mode */
  tBTM_BLE_CONN_TYPE reconnection_mode_;
  tBTM_BLE_CONN_TYPE reconnection_mode_;
  static constexpr uint64_t kGroupStreamingWatchDelayMs = 3000;
  static constexpr uint64_t kGroupStreamingWatchDelayMs = 3000;
  static constexpr uint64_t kRecoveryReconnectDelayMs = 2000;


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