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

Commit ad13a121 authored by David Duarte's avatar David Duarte
Browse files

BlueberryServer: Always play audio track

In some runs of PtsBot cases a2dp is already playing
(`isA2dpPlaying` returns true) when we start. In this
case we don't call AudioTrack#play making the playback
AudioTrack#write calls fails.
We should investigate why a2dp is playing instead but
in the meantime this is a simple and effective fix.

Test: atest pts-bot
Change-Id: I67d81723fb0c468f8629e0bfe4c43adac59a709c
parent 76e55632
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -168,17 +168,18 @@ class A2dp(val context: Context) : A2DPImplBase() {
        throw Status.UNKNOWN.asException()
      }

      audioTrack.play()

      // If A2dp is not already playing, wait for it
      if (!bluetoothA2dp.isA2dpPlaying(device)) {
        val a2dpPlayingStateFlow =
        flow
          .filter { it.getAction() == BluetoothA2dp.ACTION_PLAYING_STATE_CHANGED }
          .filter {
            it.getParcelableExtra<BluetoothDevice>(BluetoothDevice.EXTRA_DEVICE).address == address
          }
          .map { it.getIntExtra(BluetoothA2dp.EXTRA_STATE, BluetoothAdapter.ERROR) }

        audioTrack.play()
        a2dpPlayingStateFlow.filter { it == BluetoothA2dp.STATE_PLAYING }.first()
          .filter { it == BluetoothA2dp.STATE_PLAYING }
          .first()
      }
      StartResponse.getDefaultInstance()
    }