Add support for selection of Opus in Developer Options
Stub implementation for LC3 is added due to the interfaces being present. The BT stack does not currently implement LC3 over A2DP. Bug: 226441860 Test: BluetoothCodecDialogPreferenceControllerTest Change-Id: I40546c97370872b37c0258d10e67a3871f9d9af5
This commit is contained in:
@@ -54,6 +54,15 @@
|
|||||||
<include
|
<include
|
||||||
android:id="@+id/bluetooth_audio_codec_ldac"
|
android:id="@+id/bluetooth_audio_codec_ldac"
|
||||||
layout="@layout/preference_widget_dialog_radiobutton"/>
|
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>
|
</RadioGroup>
|
||||||
|
|
||||||
<include
|
<include
|
||||||
|
@@ -40,7 +40,11 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
|
|||||||
|
|
||||||
private static final String TAG = "AbstractBtDlgCtr";
|
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_HD,
|
||||||
BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX,
|
BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX,
|
||||||
BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
|
BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
|
||||||
|
@@ -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);
|
||||||
mRadioButtonIds.add(R.id.bluetooth_audio_codec_aptx_hd);
|
mRadioButtonIds.add(R.id.bluetooth_audio_codec_aptx_hd);
|
||||||
mRadioButtonIds.add(R.id.bluetooth_audio_codec_ldac);
|
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(
|
String[] stringArray = context.getResources().getStringArray(
|
||||||
R.array.bluetooth_a2dp_codec_titles);
|
R.array.bluetooth_a2dp_codec_titles);
|
||||||
for (int i = 0; i < stringArray.length; i++) {
|
for (int i = 0; i < stringArray.length; i++) {
|
||||||
|
@@ -40,6 +40,8 @@ public class BluetoothCodecDialogPreferenceController extends
|
|||||||
private static final String KEY = "bluetooth_audio_codec_settings";
|
private static final String KEY = "bluetooth_audio_codec_settings";
|
||||||
private static final String TAG = "BtCodecCtr";
|
private static final String TAG = "BtCodecCtr";
|
||||||
|
|
||||||
|
private static final int SOURCE_CODEC_TYPE_OPUS = 6; // TODO remove in U
|
||||||
|
|
||||||
private final Callback mCallback;
|
private final Callback mCallback;
|
||||||
|
|
||||||
public BluetoothCodecDialogPreferenceController(Context context, Lifecycle lifecycle,
|
public BluetoothCodecDialogPreferenceController(Context context, Lifecycle lifecycle,
|
||||||
@@ -118,6 +120,14 @@ public class BluetoothCodecDialogPreferenceController extends
|
|||||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
|
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
|
||||||
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
|
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
|
||||||
break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -180,6 +190,9 @@ public class BluetoothCodecDialogPreferenceController extends
|
|||||||
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC:
|
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC:
|
||||||
index = 5;
|
index = 5;
|
||||||
break;
|
break;
|
||||||
|
case SOURCE_CODEC_TYPE_OPUS: // TODO update in U
|
||||||
|
index = 7;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Log.e(TAG, "Unsupported config:" + config);
|
Log.e(TAG, "Unsupported config:" + config);
|
||||||
break;
|
break;
|
||||||
|
@@ -52,6 +52,8 @@ import java.util.List;
|
|||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class BluetoothCodecDialogPreferenceControllerTest {
|
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";
|
private static final String DEVICE_ADDRESS = "00:11:22:33:44:55";
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
@@ -72,6 +74,7 @@ public class BluetoothCodecDialogPreferenceControllerTest {
|
|||||||
private BluetoothCodecConfig mCodecConfigAPTX;
|
private BluetoothCodecConfig mCodecConfigAPTX;
|
||||||
private BluetoothCodecConfig mCodecConfigAPTXHD;
|
private BluetoothCodecConfig mCodecConfigAPTXHD;
|
||||||
private BluetoothCodecConfig mCodecConfigLDAC;
|
private BluetoothCodecConfig mCodecConfigLDAC;
|
||||||
|
private BluetoothCodecConfig mCodecConfigOPUS;
|
||||||
private BluetoothDevice mActiveDevice;
|
private BluetoothDevice mActiveDevice;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private LifecycleOwner mLifecycleOwner;
|
private LifecycleOwner mLifecycleOwner;
|
||||||
@@ -119,13 +122,17 @@ public class BluetoothCodecDialogPreferenceControllerTest {
|
|||||||
mCodecConfigLDAC = new BluetoothCodecConfig.Builder()
|
mCodecConfigLDAC = new BluetoothCodecConfig.Builder()
|
||||||
.setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC)
|
.setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC)
|
||||||
.build();
|
.build();
|
||||||
|
mCodecConfigOPUS = new BluetoothCodecConfig.Builder()
|
||||||
|
.setCodecType(SOURCE_CODEC_TYPE_OPUS)
|
||||||
|
.build();
|
||||||
when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
|
when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.A2DP)))
|
||||||
.thenReturn(Arrays.asList(mActiveDevice));
|
.thenReturn(Arrays.asList(mActiveDevice));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void writeConfigurationValues_selectDefault_setHighest() {
|
public void writeConfigurationValues_selectDefault_setHighest() {
|
||||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
|
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigOPUS, mCodecConfigAAC,
|
||||||
|
mCodecConfigSBC};
|
||||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||||
.setCodecConfig(mCodecConfigSBC)
|
.setCodecConfig(mCodecConfigSBC)
|
||||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||||
@@ -136,13 +143,14 @@ public class BluetoothCodecDialogPreferenceControllerTest {
|
|||||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||||
|
|
||||||
mController.writeConfigurationValues(0);
|
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
|
@Test
|
||||||
public void writeConfigurationValues_checkCodec() {
|
public void writeConfigurationValues_checkCodec() {
|
||||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX,
|
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigOPUS, mCodecConfigAAC,
|
||||||
mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC};
|
mCodecConfigSBC, mCodecConfigAPTX, mCodecConfigAPTXHD, mCodecConfigLDAC};
|
||||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||||
.setCodecConfig(mCodecConfigSBC)
|
.setCodecConfig(mCodecConfigSBC)
|
||||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||||
@@ -167,12 +175,15 @@ public class BluetoothCodecDialogPreferenceControllerTest {
|
|||||||
mController.writeConfigurationValues(5);
|
mController.writeConfigurationValues(5);
|
||||||
verify(mBluetoothA2dpConfigStore).setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC);
|
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
|
@Test
|
||||||
public void writeConfigurationValues_resetHighestConfig() {
|
public void writeConfigurationValues_resetHighestConfig() {
|
||||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX,
|
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX,
|
||||||
mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC};
|
mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigOPUS};
|
||||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||||
.setCodecConfig(mCodecConfigAAC)
|
.setCodecConfig(mCodecConfigAAC)
|
||||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||||
@@ -197,6 +208,14 @@ public class BluetoothCodecDialogPreferenceControllerTest {
|
|||||||
mController.convertCfgToBtnIndex(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC));
|
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
|
@Test
|
||||||
public void onIndexUpdated_notifyPreference() {
|
public void onIndexUpdated_notifyPreference() {
|
||||||
mController.onIndexUpdated(0);
|
mController.onIndexUpdated(0);
|
||||||
@@ -204,9 +223,29 @@ public class BluetoothCodecDialogPreferenceControllerTest {
|
|||||||
verify(mCallback).onBluetoothCodecChanged();
|
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
|
@Test
|
||||||
public void onHDAudioEnabled_optionalCodecEnabled_setsCodecTypeAsAAC() {
|
public void onHDAudioEnabled_optionalCodecEnabled_setsCodecTypeAsAAC() {
|
||||||
List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigAAC, mCodecConfigSBC);
|
List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigOPUS,
|
||||||
|
mCodecConfigAAC, mCodecConfigSBC);
|
||||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||||
.setCodecConfig(mCodecConfigAAC)
|
.setCodecConfig(mCodecConfigAAC)
|
||||||
.setCodecsSelectableCapabilities(mCodecConfigs)
|
.setCodecsSelectableCapabilities(mCodecConfigs)
|
||||||
@@ -223,7 +262,8 @@ public class BluetoothCodecDialogPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void onHDAudioEnabled_optionalCodecDisabled_setsCodecTypeAsSBC() {
|
public void onHDAudioEnabled_optionalCodecDisabled_setsCodecTypeAsSBC() {
|
||||||
List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigAAC, mCodecConfigSBC);
|
List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigOPUS,
|
||||||
|
mCodecConfigAAC, mCodecConfigSBC);
|
||||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||||
.setCodecConfig(mCodecConfigAAC)
|
.setCodecConfig(mCodecConfigAAC)
|
||||||
.setCodecsSelectableCapabilities(mCodecConfigs)
|
.setCodecsSelectableCapabilities(mCodecConfigs)
|
||||||
|
Reference in New Issue
Block a user