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

Commit e887ee15 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. If the BluetoothDevice argument is null,
the API applies to the device that is currently the Active A2DP device.

Exempt-From-Owner-Approval: De-facto owner of the relevant changes is
the Bluetooth team.
Bug: 69269748
Test: Manual
Change-Id: I7417b7b0741f706df475cb2b27fbe6525f744269
parent 345a3cb6
Loading
Loading
Loading
Loading
+15 −10
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.settings.development;

import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.ListPreference;
@@ -80,7 +82,7 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
        final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig();
        synchronized (mBluetoothA2dpConfigStore) {
            if (mBluetoothA2dp != null) {
                setCodecConfigPreference(codecConfig);
                setCodecConfigPreference(null, codecConfig);    // Use current active device
            }
        }
        // Because the setting is not persisted into permanent storage, we cannot call update state
@@ -99,13 +101,13 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends

    @Override
    public void updateState(Preference preference) {
        if (getCodecConfig() == null || mPreference == null) {
        if (getCodecConfig(null) == null || mPreference == null) { // Use current active device
            return;
        }

        BluetoothCodecConfig codecConfig;
        synchronized (mBluetoothA2dpConfigStore) {
            codecConfig = getCodecConfig();
            codecConfig = getCodecConfig(null);         // Use current active device
        }

        final int index = getCurrentA2dpSettingIndex(codecConfig);
@@ -183,16 +185,19 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
    protected abstract int getDefaultIndex();

    @VisibleForTesting
    void setCodecConfigPreference(BluetoothCodecConfig config) {
        mBluetoothA2dp.setCodecConfigPreference(config);
    void setCodecConfigPreference(BluetoothDevice device,
                                  BluetoothCodecConfig config) {
        mBluetoothA2dp.setCodecConfigPreference(device, config);
    }

    @VisibleForTesting
    BluetoothCodecConfig getCodecConfig() {
        if (mBluetoothA2dp == null || mBluetoothA2dp.getCodecStatus() == null) {
            return null;
    BluetoothCodecConfig getCodecConfig(BluetoothDevice device) {
        if (mBluetoothA2dp != null) {
            BluetoothCodecStatus codecStatus = mBluetoothA2dp.getCodecStatus(device);
            if (codecStatus != null) {
                return codecStatus.getCodecConfig();
            }

        return mBluetoothA2dp.getCodecStatus().getCodecConfig();
        }
        return null;
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -109,14 +109,14 @@ public class BluetoothAudioCodecPreferenceController extends
            case 6:
                synchronized (mBluetoothA2dpConfigStore) {
                    if (mBluetoothA2dp != null) {
                        mBluetoothA2dp.enableOptionalCodecs();
                        mBluetoothA2dp.enableOptionalCodecs(null); // Use current active device
                    }
                }
                return;
            case 7:
                synchronized (mBluetoothA2dpConfigStore) {
                    if (mBluetoothA2dp != null) {
                        mBluetoothA2dp.disableOptionalCodecs();
                        mBluetoothA2dp.disableOptionalCodecs(null); // Use current active device
                    }
                }
                return;
+4 −4
Original line number Diff line number Diff line
@@ -74,8 +74,8 @@ public class AbstractBluetoothA2dpPreferenceControllerTest {
        mLifecycle = new Lifecycle(mLifecycleOwner);
        mController = spy(new AbstractBluetoothA2dpPreferenceControllerImpl(mContext, mLifecycle,
                mBluetoothA2dpConfigStore));
        doReturn(mBluetoothCodecConfig).when(mController).getCodecConfig();
        doNothing().when(mController).setCodecConfigPreference(any());
        doReturn(mBluetoothCodecConfig).when(mController).getCodecConfig(null);
        doNothing().when(mController).setCodecConfigPreference(any(), any());
        when(mBluetoothA2dpConfigStore.createCodecConfig()).thenReturn(mBluetoothCodecConfig);
        when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
        mController.displayPreference(mScreen);
@@ -87,7 +87,7 @@ public class AbstractBluetoothA2dpPreferenceControllerTest {

        mController.onPreferenceChange(mPreference, "" /* new value */);

        verify(mController).setCodecConfigPreference(any());
        verify(mController).setCodecConfigPreference(any(), any());
    }

    @Test
@@ -96,7 +96,7 @@ public class AbstractBluetoothA2dpPreferenceControllerTest {

        mController.onPreferenceChange(mPreference, "" /* new value */);

        verify(mController, never()).setCodecConfigPreference(any());
        verify(mController, never()).setCodecConfigPreference(any(), any());
    }

    @Test