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

Commit 4a4b477b authored by Joseph Pirozzo's avatar Joseph Pirozzo
Browse files

AVRCP getConnectedDevices

Utilize the same connectedDevice list rather than asking the
avrcpService for the list multiple times possibly yielding different
lists.

Bug: 63103934
Test: Insert delays and disconnect BT while in the middle of sending
play/pause commands.

Change-Id: Ib6016d853cf1e7e72923df851e7a17752bfee07d
Merged-In: I85b6ce47b1724557b298c54e0a73bef8849ac3ba
(cherry picked from commit 810b86ee)
parent 5cae5fbd
Loading
Loading
Loading
Loading
+29 −18
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.bluetooth.a2dpsink;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.media.AudioAttributes;
import android.media.AudioManager;
@@ -27,6 +28,8 @@ import android.util.Log;
import com.android.bluetooth.avrcpcontroller.AvrcpControllerService;
import com.android.bluetooth.R;

import java.util.List;

/**
 * Bluetooth A2DP SINK Streaming Handler.
 *
@@ -275,16 +278,20 @@ public class A2dpSinkStreamHandler extends Handler {
        if (DBG) {
            Log.d(TAG, "sendAvrcpPause");
        }
        if (avrcpService != null && avrcpService.getConnectedDevices().size() == 1) {
        if (avrcpService != null) {
            List<BluetoothDevice> connectedDevices = avrcpService.getConnectedDevices();
            if (!connectedDevices.isEmpty()) {
                BluetoothDevice targetDevice = connectedDevices.get(0);
                if (DBG) {
                    Log.d(TAG, "Pausing AVRCP.");
                }
            avrcpService.sendPassThroughCmd(avrcpService.getConnectedDevices().get(0),
                avrcpService.sendPassThroughCmd(targetDevice,
                        AvrcpControllerService.PASS_THRU_CMD_ID_PAUSE,
                        AvrcpControllerService.KEY_STATE_PRESSED);
            avrcpService.sendPassThroughCmd(avrcpService.getConnectedDevices().get(0),
                avrcpService.sendPassThroughCmd(targetDevice,
                        AvrcpControllerService.PASS_THRU_CMD_ID_PAUSE,
                        AvrcpControllerService.KEY_STATE_RELEASED);
            }
        } else {
            Log.e(TAG, "Passthrough not sent, connection un-available.");
        }
@@ -297,16 +304,20 @@ public class A2dpSinkStreamHandler extends Handler {
        if (DBG) {
            Log.d(TAG, "sendAvrcpPlay");
        }
        if (avrcpService != null && avrcpService.getConnectedDevices().size() == 1) {
        if (avrcpService != null) {
            List<BluetoothDevice> connectedDevices = avrcpService.getConnectedDevices();
            if (!connectedDevices.isEmpty()) {
                BluetoothDevice targetDevice = connectedDevices.get(0);
                if (DBG) {
                    Log.d(TAG, "Playing AVRCP.");
                }
            avrcpService.sendPassThroughCmd(avrcpService.getConnectedDevices().get(0),
                avrcpService.sendPassThroughCmd(targetDevice,
                        AvrcpControllerService.PASS_THRU_CMD_ID_PLAY,
                        AvrcpControllerService.KEY_STATE_PRESSED);
            avrcpService.sendPassThroughCmd(avrcpService.getConnectedDevices().get(0),
                avrcpService.sendPassThroughCmd(targetDevice,
                        AvrcpControllerService.PASS_THRU_CMD_ID_PLAY,
                        AvrcpControllerService.KEY_STATE_RELEASED);
            }
        } else {
            Log.e(TAG, "Passthrough not sent, connection un-available.");
        }