diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index d84b0084ec6..b65586557d0 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -196,6 +196,42 @@
android:key="bluetooth_disable_absolute_volume"
android:title="@string/bluetooth_disable_absolute_volume"
android:summary="@string/bluetooth_disable_absolute_volume_summary"/>
+
+
+
+
+
+
+
+
+
+
+
= 0) {
+ titles = getResources().getStringArray(R.array.bluetooth_a2dp_codec_titles);
+ mBluetoothSelectA2dpCodec.setSummary("Streaming: " + titles[index]);
+ }
+
+ // Update the Sample Rate
+ index = -1;
+ switch (codecConfig.getSampleRate()) {
+ case BluetoothCodecConfig.SAMPLE_RATE_44100:
+ index = 1;
+ break;
+ case BluetoothCodecConfig.SAMPLE_RATE_48000:
+ index = 2;
+ break;
+ case BluetoothCodecConfig.SAMPLE_RATE_88200:
+ index = 3;
+ break;
+ case BluetoothCodecConfig.SAMPLE_RATE_96000:
+ index = 4;
+ break;
+ case BluetoothCodecConfig.SAMPLE_RATE_176400:
+ case BluetoothCodecConfig.SAMPLE_RATE_192000:
+ case BluetoothCodecConfig.SAMPLE_RATE_NONE:
+ default:
+ break;
+ }
+ if (index >= 0) {
+ titles = getResources().getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_titles);
+ mBluetoothSelectA2dpSampleRate.setSummary("Streaming: " + titles[index]);
+ }
+
+ // Update the Bits Per Sample
+ index = -1;
+ switch (codecConfig.getBitsPerSample()) {
+ case BluetoothCodecConfig.BITS_PER_SAMPLE_16:
+ index = 1;
+ break;
+ case BluetoothCodecConfig.BITS_PER_SAMPLE_24:
+ index = 2;
+ break;
+ case BluetoothCodecConfig.BITS_PER_SAMPLE_32:
+ index = 3;
+ break;
+ case BluetoothCodecConfig.BITS_PER_SAMPLE_NONE:
+ default:
+ break;
+ }
+ if (index >= 0) {
+ titles = getResources().getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_titles);
+ mBluetoothSelectA2dpBitsPerSample.setSummary("Streaming: " + titles[index]);
+ }
+
+ // Update the Channel Mode
+ index = -1;
+ switch (codecConfig.getChannelMode()) {
+ case BluetoothCodecConfig.CHANNEL_MODE_MONO:
+ index = 1;
+ break;
+ case BluetoothCodecConfig.CHANNEL_MODE_STEREO:
+ index = 2;
+ break;
+ case BluetoothCodecConfig.CHANNEL_MODE_NONE:
+ default:
+ break;
+ }
+ if (index >= 0) {
+ titles = getResources().getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_titles);
+ mBluetoothSelectA2dpChannelMode.setSummary("Streaming: " + titles[index]);
+ }
+
+ // Update the LDAC Playback Quality
+ index = -1;
+ switch ((int)codecConfig.getCodecSpecific1()) {
+ case 1000:
+ index = 0;
+ break;
+ case 1001:
+ index = 1;
+ break;
+ case 1002:
+ index = 2;
+ break;
+ default:
+ break;
+ }
+ if (index >= 0) {
+ titles = getResources().getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_titles);
+ mBluetoothSelectA2dpLdacPlaybackQuality.setSummary("Streaming: " + titles[index]);
+ }
+ }
+
+ private void writeBluetoothConfigurationOption(Preference preference,
+ Object newValue) {
+ String[] titles;
+ int index;
+ int codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID;
+ int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
+ int sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_NONE;
+ int bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_NONE;
+ int channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_NONE;
+ long codecSpecific1Value = 0;
+ long codecSpecific2Value = 0;
+ long codecSpecific3Value = 0;
+ long codecSpecific4Value = 0;
+
+ // Codec Type
+ String codecType = mBluetoothSelectA2dpCodec.getValue();
+ if (preference == mBluetoothSelectA2dpCodec) {
+ codecType = newValue.toString();
+ index = mBluetoothSelectA2dpCodec.findIndexOfValue(newValue.toString());
+ if (index >= 0) {
+ titles = getResources().getStringArray(R.array.bluetooth_a2dp_codec_titles);
+ mBluetoothSelectA2dpCodec.setSummary(titles[index]);
+ }
+ }
+ index = mBluetoothSelectA2dpCodec.findIndexOfValue(codecType);
+ switch (index) {
+ case 0:
+ // Reset the priority of the current codec to default
+ String oldValue = mBluetoothSelectA2dpCodec.getValue();
+ switch (mBluetoothSelectA2dpCodec.findIndexOfValue(oldValue)) {
+ case 0:
+ break; // No current codec
+ case 1:
+ codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC;
+ break;
+ case 2:
+ codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX;
+ break;
+ case 3:
+ codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD;
+ break;
+ case 4:
+ codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
+ break;
+ default:
+ break;
+ }
+ break;
+ case 1:
+ codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC;
+ codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
+ break;
+ case 2:
+ codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX;
+ codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
+ break;
+ case 3:
+ codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD;
+ codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
+ break;
+ case 4:
+ codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
+ codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
+ break;
+ default:
+ break;
+ }
+
+ // Sample Rate
+ String sampleRate = mBluetoothSelectA2dpSampleRate.getValue();
+ if (preference == mBluetoothSelectA2dpSampleRate) {
+ sampleRate = newValue.toString();
+ index = mBluetoothSelectA2dpSampleRate.findIndexOfValue(newValue.toString());
+ if (index >= 0) {
+ titles = getResources().getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_titles);
+ mBluetoothSelectA2dpSampleRate.setSummary(titles[index]);
+ }
+ }
+ index = mBluetoothSelectA2dpSampleRate.findIndexOfValue(sampleRate);
+ switch (index) {
+ case 0:
+ // Reset to default
+ break;
+ case 1:
+ sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_44100;
+ break;
+ case 2:
+ sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_48000;
+ break;
+ case 3:
+ sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_88200;
+ break;
+ case 4:
+ sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_96000;
+ break;
+ default:
+ break;
+ }
+
+ // Bits Per Sample
+ String bitsPerSample = mBluetoothSelectA2dpBitsPerSample.getValue();
+ if (preference == mBluetoothSelectA2dpBitsPerSample) {
+ bitsPerSample = newValue.toString();
+ index = mBluetoothSelectA2dpBitsPerSample.findIndexOfValue(newValue.toString());
+ if (index >= 0) {
+ titles = getResources().getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_titles);
+ mBluetoothSelectA2dpBitsPerSample.setSummary(titles[index]);
+ }
+ }
+ index = mBluetoothSelectA2dpBitsPerSample.findIndexOfValue(bitsPerSample);
+ switch (index) {
+ case 0:
+ // Reset to default
+ break;
+ case 1:
+ bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_16;
+ break;
+ case 2:
+ bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_24;
+ break;
+ case 3:
+ bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_32;
+ break;
+ default:
+ break;
+ }
+
+ // Channel Mode
+ String channelMode = mBluetoothSelectA2dpChannelMode.getValue();
+ if (preference == mBluetoothSelectA2dpChannelMode) {
+ channelMode = newValue.toString();
+ index = mBluetoothSelectA2dpChannelMode.findIndexOfValue(newValue.toString());
+ if (index >= 0) {
+ titles = getResources().getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_titles);
+ mBluetoothSelectA2dpChannelMode.setSummary(titles[index]);
+ }
+ }
+ index = mBluetoothSelectA2dpChannelMode.findIndexOfValue(channelMode);
+ switch (index) {
+ case 0:
+ // Reset to default
+ break;
+ case 1:
+ channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_MONO;
+ break;
+ case 2:
+ channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_STEREO;
+ break;
+ default:
+ break;
+ }
+
+ // LDAC Playback Quality
+ String ldacPlaybackQuality = mBluetoothSelectA2dpLdacPlaybackQuality.getValue();
+ if (preference == mBluetoothSelectA2dpLdacPlaybackQuality) {
+ ldacPlaybackQuality = newValue.toString();
+ index = mBluetoothSelectA2dpLdacPlaybackQuality.findIndexOfValue(newValue.toString());
+ if (index >= 0) {
+ titles = getResources().getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_titles);
+ mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(titles[index]);
+ }
+ }
+ index = mBluetoothSelectA2dpLdacPlaybackQuality.findIndexOfValue(ldacPlaybackQuality);
+ switch (index) {
+ case 0:
+ codecSpecific1Value = 1000;
+ break;
+ case 1:
+ codecSpecific1Value = 1001;
+ break;
+ case 2:
+ codecSpecific1Value = 1002;
+ break;
+ default:
+ break;
+ }
+
+ BluetoothCodecConfig codecConfig =
+ new BluetoothCodecConfig(codecTypeValue, codecPriorityValue,
+ sampleRateValue, bitsPerSampleValue,
+ channelModeValue, codecSpecific1Value,
+ codecSpecific2Value, codecSpecific3Value,
+ codecSpecific4Value);
+
+ synchronized (mBluetoothA2dpLock) {
+ if (mBluetoothA2dp != null) {
+ mBluetoothA2dp.setCodecConfigPreference(codecConfig);
+ }
+ }
+ }
+
private void writeImmediatelyDestroyActivitiesOptions() {
try {
ActivityManagerNative.getDefault().setAlwaysFinish(
@@ -2090,6 +2489,13 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
toast.show();
}
return false;
+ } else if ((preference == mBluetoothSelectA2dpCodec) ||
+ (preference == mBluetoothSelectA2dpSampleRate) ||
+ (preference == mBluetoothSelectA2dpBitsPerSample) ||
+ (preference == mBluetoothSelectA2dpChannelMode) ||
+ (preference == mBluetoothSelectA2dpLdacPlaybackQuality)) {
+ writeBluetoothConfigurationOption(preference, newValue);
+ return true;
} else if (preference == mLogdSize) {
writeLogdSizeOption(newValue);
return true;
@@ -2229,6 +2635,31 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
}
};
+ private BroadcastReceiver mBluetoothA2dpReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ updateBluetoothA2dpConfigurationValues();
+ }
+ };
+
+ private BluetoothProfile.ServiceListener mBluetoothA2dpServiceListener =
+ new BluetoothProfile.ServiceListener() {
+ public void onServiceConnected(int profile,
+ BluetoothProfile proxy) {
+ synchronized (mBluetoothA2dpLock) {
+ mBluetoothA2dp = (BluetoothA2dp) proxy;
+ }
+ updateBluetoothA2dpConfigurationValues();
+ }
+
+ public void onServiceDisconnected(int profile) {
+ synchronized (mBluetoothA2dpLock) {
+ mBluetoothA2dp = null;
+ }
+ updateBluetoothA2dpConfigurationValues();
+ }
+ };
+
public static class SystemPropPoker extends AsyncTask {
@Override
protected Void doInBackground(Void... params) {