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

Commit 7f195cee authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Add support for Multi-A2DP state machines per device

* Update usage of A2dpService API calls that take BluetoothDevice
  as an additional argument
* Update the description for BluetoothA2dp.connect()

Exempt-From-Owner-Approval: De-facto owner of the relevant changes is
the Bluetooth team.
Bug: 69269748
Test: Manual
Change-Id: I190ed48ef65bbc8b88b45f84ebd6ab3d21cf0b4e
Merged-In: I190ed48ef65bbc8b88b45f84ebd6ab3d21cf0b4e
(cherry picked from commit 164b38b9)
parent a361dd6e
Loading
Loading
Loading
Loading
+27 −20
Original line number Diff line number Diff line
@@ -300,11 +300,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
    }

    /**
     * Initiate connection to a profile of the remote bluetooth device.
     *
     * <p> Currently, the system supports only 1 connection to the
     * A2DP profile. The API will automatically disconnect connected
     * devices before connecting.
     * Initiate connection to a profile of the remote Bluetooth device.
     *
     * <p> This API returns false in scenarios like the profile on the
     * device is already connected or Bluetooth is not turned on.
@@ -699,15 +695,17 @@ public final class BluetoothA2dp implements BluetoothProfile {
    /**
     * Gets the current codec status (configuration and capability).
     *
     * @param device the remote Bluetooth device. If null, use the current
     * active A2DP Bluetooth device.
     * @return the current codec status
     * @hide
     */
    public BluetoothCodecStatus getCodecStatus() {
        if (DBG) Log.d(TAG, "getCodecStatus");
    public BluetoothCodecStatus getCodecStatus(BluetoothDevice device) {
        if (DBG) Log.d(TAG, "getCodecStatus(" + device + ")");
        try {
            mServiceLock.readLock().lock();
            if (mService != null && isEnabled()) {
                return mService.getCodecStatus();
                return mService.getCodecStatus(device);
            }
            if (mService == null) {
                Log.w(TAG, "Proxy not attached to service");
@@ -724,15 +722,18 @@ public final class BluetoothA2dp implements BluetoothProfile {
    /**
     * Sets the codec configuration preference.
     *
     * @param device the remote Bluetooth device. If null, use the current
     * active A2DP Bluetooth device.
     * @param codecConfig the codec configuration preference
     * @hide
     */
    public void setCodecConfigPreference(BluetoothCodecConfig codecConfig) {
        if (DBG) Log.d(TAG, "setCodecConfigPreference");
    public void setCodecConfigPreference(BluetoothDevice device,
                                         BluetoothCodecConfig codecConfig) {
        if (DBG) Log.d(TAG, "setCodecConfigPreference(" + device + ")");
        try {
            mServiceLock.readLock().lock();
            if (mService != null && isEnabled()) {
                mService.setCodecConfigPreference(codecConfig);
                mService.setCodecConfigPreference(device, codecConfig);
            }
            if (mService == null) Log.w(TAG, "Proxy not attached to service");
            return;
@@ -747,36 +748,42 @@ public final class BluetoothA2dp implements BluetoothProfile {
    /**
     * Enables the optional codecs.
     *
     * @param device the remote Bluetooth device. If null, use the currect
     * active A2DP Bluetooth device.
     * @hide
     */
    public void enableOptionalCodecs() {
        if (DBG) Log.d(TAG, "enableOptionalCodecs");
        enableDisableOptionalCodecs(true);
    public void enableOptionalCodecs(BluetoothDevice device) {
        if (DBG) Log.d(TAG, "enableOptionalCodecs(" + device + ")");
        enableDisableOptionalCodecs(device, true);
    }

    /**
     * Disables the optional codecs.
     *
     * @param device the remote Bluetooth device. If null, use the currect
     * active A2DP Bluetooth device.
     * @hide
     */
    public void disableOptionalCodecs() {
        if (DBG) Log.d(TAG, "disableOptionalCodecs");
        enableDisableOptionalCodecs(false);
    public void disableOptionalCodecs(BluetoothDevice device) {
        if (DBG) Log.d(TAG, "disableOptionalCodecs(" + device + ")");
        enableDisableOptionalCodecs(device, false);
    }

    /**
     * Enables or disables the optional codecs.
     *
     * @param device the remote Bluetooth device. If null, use the currect
     * active A2DP Bluetooth device.
     * @param enable if true, enable the optional codecs, other disable them
     */
    private void enableDisableOptionalCodecs(boolean enable) {
    private void enableDisableOptionalCodecs(BluetoothDevice device, boolean enable) {
        try {
            mServiceLock.readLock().lock();
            if (mService != null && isEnabled()) {
                if (enable) {
                    mService.enableOptionalCodecs();
                    mService.enableOptionalCodecs(device);
                } else {
                    mService.disableOptionalCodecs();
                    mService.disableOptionalCodecs(device);
                }
            }
            if (mService == null) Log.w(TAG, "Proxy not attached to service");