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

Commit 41cfaa9f authored by tim peng's avatar tim peng Committed by Gerrit Code Review
Browse files

Merge "Phone fails to switch channel mode from stereo to mono"

parents ab7640dc 07b36757
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -219,11 +219,17 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
     */
     */
    public void onHDAudioEnabled(boolean enabled) {}
    public void onHDAudioEnabled(boolean enabled) {}


    static int getHighestCodec(BluetoothCodecConfig[] configs) {
    static int getHighestCodec(BluetoothA2dp bluetoothA2dp, BluetoothDevice activeDevice,
            BluetoothCodecConfig[] configs) {
        if (configs == null) {
        if (configs == null) {
            Log.d(TAG, "Unable to get highest codec. Configs are empty");
            Log.d(TAG, "Unable to get highest codec. Configs are empty");
            return BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID;
            return BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID;
        }
        }
        // If HD audio is not enabled, SBC is the only one available codec.
        if (bluetoothA2dp.isOptionalCodecsEnabled(activeDevice)
                != BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) {
            return BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC;
        }
        for (int i = 0; i < CODEC_TYPES.length; i++) {
        for (int i = 0; i < CODEC_TYPES.length; i++) {
            for (int j = 0; j < configs.length; j++) {
            for (int j = 0; j < configs.length; j++) {
                if ((configs[j].getCodecType() == CODEC_TYPES[i])) {
                if ((configs[j].getCodecType() == CODEC_TYPES[i])) {
+8 −2
Original line number Original line Diff line number Diff line
@@ -93,8 +93,9 @@ public class BluetoothCodecDialogPreferenceController extends
        int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
        int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
        switch (index) {
        switch (index) {
            case 0:
            case 0:
                codecTypeValue = getHighestCodec(getSelectableConfigs(
                final BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
                    mBluetoothA2dp.getActiveDevice()));
                codecTypeValue = getHighestCodec(mBluetoothA2dp, activeDevice,
                        getSelectableConfigs(activeDevice));
                codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
                codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
                break;
                break;
            case 1:
            case 1:
@@ -147,6 +148,11 @@ public class BluetoothCodecDialogPreferenceController extends
        mCallback.onBluetoothCodecChanged();
        mCallback.onBluetoothCodecChanged();
    }
    }


    @Override
    public void onHDAudioEnabled(boolean enabled) {
        writeConfigurationValues(/* index= */ 0);
    }

    private List<Integer> getIndexFromConfig(BluetoothCodecConfig[] configs) {
    private List<Integer> getIndexFromConfig(BluetoothCodecConfig[] configs) {
        List<Integer> indexArray = new ArrayList<>();
        List<Integer> indexArray = new ArrayList<>();
        for (int i = 0; i < configs.length; i++) {
        for (int i = 0; i < configs.length; i++) {
+36 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settings.development.bluetooth;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertThat;


import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;
@@ -108,6 +109,8 @@ public class BluetoothCodecDialogPreferenceControllerTest {
        BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
        BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
        mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs);
        mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs);
        when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
        when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
        when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
                BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED);
        mController.onBluetoothServiceConnected(mBluetoothA2dp);
        mController.onBluetoothServiceConnected(mBluetoothA2dp);


        mController.writeConfigurationValues(0);
        mController.writeConfigurationValues(0);
@@ -172,4 +175,37 @@ public class BluetoothCodecDialogPreferenceControllerTest {


        verify(mCallback).onBluetoothCodecChanged();
        verify(mCallback).onBluetoothCodecChanged();
    }
    }

    @Test
    public void onHDAudioEnabled_optionalCodecEnabled_setsCodecTypeAsAAC() {
        BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC,
                /* codecsLocalCapabilities= */ null,
                mCodecConfigs);
        when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
        when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
                BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED);
        mController.onBluetoothServiceConnected(mBluetoothA2dp);

        mController.onHDAudioEnabled(/* enabled= */ true);

        verify(mBluetoothA2dpConfigStore, atLeastOnce()).setCodecType(
                eq(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC));
    }
    @Test
    public void onHDAudioEnabled_optionalCodecDisabled_setsCodecTypeAsSBC() {
        BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC,
                /* codecsLocalCapabilities= */ null,
                mCodecConfigs);
        when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
        when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
                BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED);
        mController.onBluetoothServiceConnected(mBluetoothA2dp);

        mController.onHDAudioEnabled(/* enabled= */ false);

        verify(mBluetoothA2dpConfigStore, atLeastOnce()).setCodecType(
                eq(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC));
    }
}
}