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

Commit cb930bc0 authored by Omer Osman's avatar Omer Osman Committed by Android (Google) Code Review
Browse files

Merge "Add support for selection of Opus in Developer Options" into tm-qpr-dev

parents 79241088 b61e129f
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -54,6 +54,15 @@
            <include
                android:id="@+id/bluetooth_audio_codec_ldac"
                layout="@layout/preference_widget_dialog_radiobutton"/>

            <include
                android:id="@+id/bluetooth_audio_codec_lc3"
                layout="@layout/preference_widget_dialog_radiobutton"/>

            <include
                android:id="@+id/bluetooth_audio_codec_opus"
                layout="@layout/preference_widget_dialog_radiobutton"/>

        </RadioGroup>

        <include
+5 −1
Original line number Diff line number Diff line
@@ -40,7 +40,11 @@ public abstract class AbstractBluetoothDialogPreferenceController extends

    private static final String TAG = "AbstractBtDlgCtr";

    protected static final int[] CODEC_TYPES = {BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC,
    private static final int SOURCE_CODEC_TYPE_OPUS = 6; // TODO(b/240635097): remove in U

    protected static final int[] CODEC_TYPES = {SOURCE_CODEC_TYPE_OPUS,
            BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3,
            BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC,
            BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD,
            BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX,
            BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
+2 −0
Original line number Diff line number Diff line
@@ -61,6 +61,8 @@ public class BluetoothCodecDialogPreference extends BaseBluetoothDialogPreferenc
        mRadioButtonIds.add(R.id.bluetooth_audio_codec_aptx);
        mRadioButtonIds.add(R.id.bluetooth_audio_codec_aptx_hd);
        mRadioButtonIds.add(R.id.bluetooth_audio_codec_ldac);
        mRadioButtonIds.add(R.id.bluetooth_audio_codec_lc3);
        mRadioButtonIds.add(R.id.bluetooth_audio_codec_opus);
        String[] stringArray = context.getResources().getStringArray(
                R.array.bluetooth_a2dp_codec_titles);
        for (int i = 0; i < stringArray.length; i++) {
+13 −0
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ public class BluetoothCodecDialogPreferenceController extends
    private static final String KEY = "bluetooth_audio_codec_settings";
    private static final String TAG = "BtCodecCtr";

    private static final int SOURCE_CODEC_TYPE_OPUS = 6; // TODO remove in U

    private final Callback mCallback;

    public BluetoothCodecDialogPreferenceController(Context context, Lifecycle lifecycle,
@@ -118,6 +120,14 @@ public class BluetoothCodecDialogPreferenceController extends
                codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
                codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
                break;
            case 6:
                codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LC3;
                codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
                break;
            case 7:
                codecTypeValue = SOURCE_CODEC_TYPE_OPUS; // TODO update in U
                codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
                break;
            default:
                break;
        }
@@ -180,6 +190,9 @@ public class BluetoothCodecDialogPreferenceController extends
            case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC:
                index = 5;
                break;
            case SOURCE_CODEC_TYPE_OPUS: // TODO update in U
                index = 7;
                break;
            default:
                Log.e(TAG, "Unsupported config:" + config);
                break;
+47 −7
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ import java.util.List;
@RunWith(RobolectricTestRunner.class)
public class BluetoothCodecDialogPreferenceControllerTest {

    private static final int SOURCE_CODEC_TYPE_OPUS = 6; // TODO(b/240635097): remove in U

    private static final String DEVICE_ADDRESS = "00:11:22:33:44:55";

    @Mock
@@ -72,6 +74,7 @@ public class BluetoothCodecDialogPreferenceControllerTest {
    private BluetoothCodecConfig mCodecConfigAPTX;
    private BluetoothCodecConfig mCodecConfigAPTXHD;
    private BluetoothCodecConfig mCodecConfigLDAC;
    private BluetoothCodecConfig mCodecConfigOPUS;
    private BluetoothDevice mActiveDevice;
    private Context mContext;
    private LifecycleOwner mLifecycleOwner;
@@ -119,13 +122,17 @@ public class BluetoothCodecDialogPreferenceControllerTest {
        mCodecConfigLDAC = new BluetoothCodecConfig.Builder()
                .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC)
                .build();
        mCodecConfigOPUS = new BluetoothCodecConfig.Builder()
                .setCodecType(SOURCE_CODEC_TYPE_OPUS)
                .build();
        when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
                .thenReturn(Arrays.asList(mActiveDevice));
    }

    @Test
    public void writeConfigurationValues_selectDefault_setHighest() {
        BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
        BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigOPUS, mCodecConfigAAC,
                                                mCodecConfigSBC};
        mCodecStatus = new BluetoothCodecStatus.Builder()
                .setCodecConfig(mCodecConfigSBC)
                .setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
@@ -136,13 +143,14 @@ public class BluetoothCodecDialogPreferenceControllerTest {
        mController.onBluetoothServiceConnected(mBluetoothA2dp);

        mController.writeConfigurationValues(0);
        verify(mBluetoothA2dpConfigStore).setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC);
                                                // TODO(b/240635097): update in U
        verify(mBluetoothA2dpConfigStore).setCodecType(SOURCE_CODEC_TYPE_OPUS);
    }

    @Test
    public void writeConfigurationValues_checkCodec() {
        BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX,
                mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC};
        BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigOPUS, mCodecConfigAAC,
                mCodecConfigSBC, mCodecConfigAPTX, mCodecConfigAPTXHD, mCodecConfigLDAC};
        mCodecStatus = new BluetoothCodecStatus.Builder()
                .setCodecConfig(mCodecConfigSBC)
                .setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
@@ -167,12 +175,15 @@ public class BluetoothCodecDialogPreferenceControllerTest {
        mController.writeConfigurationValues(5);
        verify(mBluetoothA2dpConfigStore).setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC);

        mController.writeConfigurationValues(7);
                                                // TODO(b/240635097): update in U
        verify(mBluetoothA2dpConfigStore).setCodecType(SOURCE_CODEC_TYPE_OPUS);
    }

    @Test
    public void writeConfigurationValues_resetHighestConfig() {
        BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX,
                mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC};
                mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigOPUS};
        mCodecStatus = new BluetoothCodecStatus.Builder()
                .setCodecConfig(mCodecConfigAAC)
                .setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
@@ -197,6 +208,14 @@ public class BluetoothCodecDialogPreferenceControllerTest {
                mController.convertCfgToBtnIndex(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC));
    }

    @Test
    public void getCurrentIndexByConfig_verifyOpusIndex() {
        assertThat(mController.getCurrentIndexByConfig(mCodecConfigOPUS)).isEqualTo(
                mController.convertCfgToBtnIndex(SOURCE_CODEC_TYPE_OPUS));
                                             // TODO(b/240635097): update in U
    }


    @Test
    public void onIndexUpdated_notifyPreference() {
        mController.onIndexUpdated(0);
@@ -204,9 +223,29 @@ public class BluetoothCodecDialogPreferenceControllerTest {
        verify(mCallback).onBluetoothCodecChanged();
    }

    @Test
    public void onHDAudioEnabled_optionalCodecEnabled_setsCodecTypeAsOpus() {
        List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigOPUS,
                                                   mCodecConfigAAC, mCodecConfigSBC);
        mCodecStatus = new BluetoothCodecStatus.Builder()
                .setCodecConfig(mCodecConfigOPUS)
                .setCodecsSelectableCapabilities(mCodecConfigs)
                .build();
        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(SOURCE_CODEC_TYPE_OPUS)); // TODO(b/240635097): update in U
    }

    @Test
    public void onHDAudioEnabled_optionalCodecEnabled_setsCodecTypeAsAAC() {
        List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigAAC, mCodecConfigSBC);
        List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigOPUS,
                                                   mCodecConfigAAC, mCodecConfigSBC);
        mCodecStatus = new BluetoothCodecStatus.Builder()
                .setCodecConfig(mCodecConfigAAC)
                .setCodecsSelectableCapabilities(mCodecConfigs)
@@ -223,7 +262,8 @@ public class BluetoothCodecDialogPreferenceControllerTest {
    }
    @Test
    public void onHDAudioEnabled_optionalCodecDisabled_setsCodecTypeAsSBC() {
        List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigAAC, mCodecConfigSBC);
        List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigOPUS,
                                                   mCodecConfigAAC, mCodecConfigSBC);
        mCodecStatus = new BluetoothCodecStatus.Builder()
                .setCodecConfig(mCodecConfigAAC)
                .setCodecsSelectableCapabilities(mCodecConfigs)