From a719931c5e6ff4b31d665b6173811902553dcc16 Mon Sep 17 00:00:00 2001 From: Kiran Kelageri Date: Wed, 4 Apr 2018 23:46:24 -0700 Subject: [PATCH 01/12] Bluetooth: Create new catogory for earbuds Create new catagory for TWS devices such that only paired TWS devices will be populated under this catagory. CRs-fixed: 2230362 Change-Id: I6f7084c4bb319820e9d534c06adb01904b082ff9 --- res/values/styx_strings.xml | 2 + res/xml/connected_devices.xml | 5 + .../SavedBluetoothDeviceUpdater.java | 39 ++++- .../SavedBluetoothTwsDeviceUpdater.java | 91 ++++++++++ .../ConnectedDeviceDashboardFragment.java | 34 ++++ .../SavedTwsDeviceGroupController.java | 157 ++++++++++++++++++ 6 files changed, 326 insertions(+), 2 deletions(-) create mode 100644 src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java create mode 100644 src/com/android/settings/connecteddevice/SavedTwsDeviceGroupController.java diff --git a/res/values/styx_strings.xml b/res/values/styx_strings.xml index bf0be5e1276..cf65c477fe4 100644 --- a/res/values/styx_strings.xml +++ b/res/values/styx_strings.xml @@ -54,4 +54,6 @@ RAM + + Saved Earbuds diff --git a/res/xml/connected_devices.xml b/res/xml/connected_devices.xml index 8e606484b7a..2ac73aef497 100644 --- a/res/xml/connected_devices.xml +++ b/res/xml/connected_devices.xml @@ -36,6 +36,11 @@ android:title="@string/connected_device_other_device_title" settings:controller="com.android.settings.connecteddevice.ConnectedDeviceGroupController"/> + + Date: Mon, 23 Jul 2018 17:17:46 -0700 Subject: [PATCH 02/12] Bluetooth-TWS: Filter TWS devices Added filter to display TWS devices only under saved earbuds category. CRs-Fixed: 2285057 Change-Id: Id254210a4a308360e0f2110d6b81d8a3a780bd38 --- .../settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java b/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java index 55505d078fa..8759e6f1d8d 100644 --- a/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java @@ -75,9 +75,10 @@ public SavedBluetoothTwsDeviceUpdater(Context context, DashboardFragment fragmen @Override public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) { + final BluetoothDevice device = cachedDevice.getDevice(); if (state == BluetoothAdapter.STATE_CONNECTED) { removePreference(cachedDevice); - } else if (state == BluetoothAdapter.STATE_DISCONNECTED) { + } else if (state == BluetoothAdapter.STATE_DISCONNECTED && device.isTwsPlusDevice()) { addPreference(cachedDevice); } } From c34da9da4a902225d3436b8a025831b612497a67 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Tue, 14 Aug 2018 20:15:39 +0900 Subject: [PATCH 03/12] Fix build error android.support.* are renamed to androidx. Test: m -j Settings Change-Id: I6048ba8b014d2804c624113bd214f10ddee8c13a --- .../connecteddevice/SavedTwsDeviceGroupController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/connecteddevice/SavedTwsDeviceGroupController.java b/src/com/android/settings/connecteddevice/SavedTwsDeviceGroupController.java index f7ad20b5711..1e1f0ac3ee2 100644 --- a/src/com/android/settings/connecteddevice/SavedTwsDeviceGroupController.java +++ b/src/com/android/settings/connecteddevice/SavedTwsDeviceGroupController.java @@ -51,9 +51,9 @@ import android.content.pm.PackageManager; import android.content.Context; -import android.support.v7.preference.Preference; -import android.support.v7.preference.PreferenceGroup; -import android.support.v7.preference.PreferenceScreen; +import androidx.preference.Preference; +import androidx.preference.PreferenceGroup; +import androidx.preference.PreferenceScreen; import com.android.settings.bluetooth.BluetoothDeviceUpdater; import com.android.settings.bluetooth.SavedBluetoothTwsDeviceUpdater; From bf0482c56336387b82a25259084eec47f1d66c6b Mon Sep 17 00:00:00 2001 From: Kiran Kelageri Date: Wed, 22 Aug 2018 18:35:31 -0700 Subject: [PATCH 04/12] Bluetooth-TWS: UI updates based on profile connection. Changes are made as per aosp implementation for TWS, UI update is moved to profile connection states instead of depending connection states. CRs-fixed: 2300825 Change-Id: I7074698b3c421822756c30a808da6cd02968bced --- .../bluetooth/SavedBluetoothTwsDeviceUpdater.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java b/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java index 8759e6f1d8d..450431807ba 100644 --- a/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java @@ -50,6 +50,7 @@ import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; +import android.bluetooth.BluetoothProfile; import android.content.Context; import com.android.settings.connecteddevice.DevicePreferenceCallback; @@ -74,11 +75,12 @@ public SavedBluetoothTwsDeviceUpdater(Context context, DashboardFragment fragmen } @Override - public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) { + public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state, + int bluetoothProfile) { final BluetoothDevice device = cachedDevice.getDevice(); - if (state == BluetoothAdapter.STATE_CONNECTED) { + if (state == BluetoothProfile.STATE_CONNECTED) { removePreference(cachedDevice); - } else if (state == BluetoothAdapter.STATE_DISCONNECTED && device.isTwsPlusDevice()) { + } else if (state == BluetoothProfile.STATE_DISCONNECTED && device.isTwsPlusDevice()) { addPreference(cachedDevice); } } From 5735247c811161ca0af9632324523bfd3056106e Mon Sep 17 00:00:00 2001 From: zhenchao Date: Tue, 10 Sep 2019 19:18:17 +0800 Subject: [PATCH 05/12] Bluetooth-TWS: UI updates based on Filter matched Change implementation of Saved Earbuds category as same as Previous Connected Devices category for legacy devices, onProfileConnectionStateChanged in BluetoothDeviceUpdater is used and UI updates based on Filter matched or not. Change-Id: Iff047ccd90e81696e805fd090ada86dc0c6b2feb CRs-Fixed: 2524220 --- .../bluetooth/SavedBluetoothTwsDeviceUpdater.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java b/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java index 450431807ba..d1773a9a09a 100644 --- a/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java @@ -74,17 +74,6 @@ public SavedBluetoothTwsDeviceUpdater(Context context, DashboardFragment fragmen super(fragment, devicePreferenceCallback, localBluetoothManager); } - @Override - public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state, - int bluetoothProfile) { - final BluetoothDevice device = cachedDevice.getDevice(); - if (state == BluetoothProfile.STATE_CONNECTED) { - removePreference(cachedDevice); - } else if (state == BluetoothProfile.STATE_DISCONNECTED && device.isTwsPlusDevice()) { - addPreference(cachedDevice); - } - } - @Override public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) { final BluetoothDevice device = cachedDevice.getDevice(); From 1605a9dfa10735576c85b62566e6da7f21d7648b Mon Sep 17 00:00:00 2001 From: Satheesh Kumar Pallemoni Date: Wed, 8 Apr 2020 12:36:07 +0530 Subject: [PATCH 06/12] A2dpSrc: DEV-UI support for Blutooth Audio codec. Due to enhancements in the DEV-UI by AOSP, Blutooth Audio codec menu showing nothing in developer settings. Due to length mismatch of the bluetooth_a2dp_codec_titles and bluetooth_a2dp_codec_summaries in settings leading to this issue. Issue has been fixed by introducing QVA codecs too, so that length won't mismatch. CRs-Fixed: 2624640 Change-Id: I849e340152be5043782fa8274636a534c147c8bb --- res/layout/bluetooth_audio_codec_dialog.xml | 8 ++++++++ .../AbstractBluetoothDialogPreferenceController.java | 5 ++++- .../bluetooth/BluetoothCodecDialogPreference.java | 10 ++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/res/layout/bluetooth_audio_codec_dialog.xml b/res/layout/bluetooth_audio_codec_dialog.xml index 96364270558..1fd9de80219 100644 --- a/res/layout/bluetooth_audio_codec_dialog.xml +++ b/res/layout/bluetooth_audio_codec_dialog.xml @@ -51,9 +51,17 @@ android:id="@+id/bluetooth_audio_codec_aptx_hd" layout="@layout/preference_widget_dialog_radiobutton"/> + + + + Date: Fri, 5 Jun 2020 22:44:39 +0800 Subject: [PATCH 07/12] BT: Use translated a2dp codec strings Change-Id: I75551fb2e3aa4358c80a61b799cd4093ee88d889 --- .../bluetooth/BluetoothCodecDialogPreference.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreference.java b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreference.java index 6178ed19375..86c541f790a 100644 --- a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreference.java +++ b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreference.java @@ -68,14 +68,15 @@ private void initialize(Context context) { mRadioButtonIds.add(R.id.bluetooth_audio_codec_ldac); mRadioButtonIds.add(R.id.bluetooth_audio_codec_aptx_twsp); String[] stringArray = context.getResources().getStringArray( - R.array.bluetooth_a2dp_codec_titles); + R.array.bluetooth_a2dp_codec_titles_cm); Log.e(TAG, "a2dp_codec_titles array length: " + stringArray.length); for (int i = 0; i < stringArray.length; i++) { mRadioButtonStrings.add(stringArray[i]); } - stringArray = context.getResources().getStringArray(R.array.bluetooth_a2dp_codec_summaries); + stringArray = context.getResources().getStringArray( + R.array.bluetooth_a2dp_codec_summaries_cm); Log.e(TAG, "a2dp_codec_summaries array length: " + stringArray.length); for (int i = 0; i < stringArray.length; i++) { mSummaryStrings.add(stringArray[i]); From 4872f48c98e6baa9a3ea7f4d4c0644c0636459ff Mon Sep 17 00:00:00 2001 From: Justin DeMartino Date: Thu, 16 Jan 2020 11:36:41 -0800 Subject: [PATCH 08/12] Implement abstract method getPreferenceKey in SavedBluetoothTwsDeviceUpdater Bug:147819852 Change-Id: Ifb11cc864d52c36704346debf89523cdcf5ce536 --- .../settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java b/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java index d1773a9a09a..d9c3d217b4e 100644 --- a/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java @@ -63,6 +63,8 @@ */ public class SavedBluetoothTwsDeviceUpdater extends BluetoothDeviceUpdater { + private static final String PREF_KEY = "saved_bt_tws"; + public SavedBluetoothTwsDeviceUpdater(Context context, DashboardFragment fragment, DevicePreferenceCallback devicePreferenceCallback) { super(context, fragment, devicePreferenceCallback); @@ -80,4 +82,9 @@ public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) { return device.getBondState() == BluetoothDevice.BOND_BONDED && !device.isConnected() && device.isTwsPlusDevice(); } + + @Override + protected String getPreferenceKey() { + return PREF_KEY; + } } From 1471634b0f20c24fd698cf3e369d12998417d0dd Mon Sep 17 00:00:00 2001 From: Steven Laver Date: Tue, 17 Mar 2020 14:10:58 -0700 Subject: [PATCH 09/12] bluetooth: update SavedBluetoothTwsDeviceUpdater for superclass ctor signature change In 130629b1dbe3f43fe7695c606224b805ec413e7b, the constructor signature of BluetoothDeviceUpdater changed; a Context parameter was added. Update its subclass, SavedBluetoothTwsDeviceUpdater, accordingly. Change-Id: I07945f96e0ff6b1e82b1c9f5732eff69cecdca97 --- .../settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java b/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java index d9c3d217b4e..f4a5638c8b4 100644 --- a/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/SavedBluetoothTwsDeviceUpdater.java @@ -70,10 +70,10 @@ public SavedBluetoothTwsDeviceUpdater(Context context, DashboardFragment fragmen super(context, fragment, devicePreferenceCallback); } - SavedBluetoothTwsDeviceUpdater(DashboardFragment fragment, + SavedBluetoothTwsDeviceUpdater(Context context, DashboardFragment fragment, DevicePreferenceCallback devicePreferenceCallback, LocalBluetoothManager localBluetoothManager) { - super(fragment, devicePreferenceCallback, localBluetoothManager); + super(context, fragment, devicePreferenceCallback, localBluetoothManager); } @Override From 0318a33418431920a9659dd4362b44ee2aedb906 Mon Sep 17 00:00:00 2001 From: Satheesh Kumar Pallemoni Date: Mon, 13 Apr 2020 20:18:09 +0530 Subject: [PATCH 10/12] A2dpSrc: Bluetooth codec Dev-UI support for QVA codecs Added Bluetooth codec Dev-UI support for QVA codecs. CRs-Fixed: 2663248 Change-Id: I035d760bbf4de27f2216c4ffb42df26a0c0ce476 --- .../DevelopmentSettingsDashboardFragment.java | 1 + ...etoothCodecDialogPreferenceController.java | 23 +++++++++++++++++++ .../BluetoothHDAudioPreferenceController.java | 1 + ...oothQualityDialogPreferenceController.java | 3 ++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java index fbab1fd1240..0adc2445349 100644 --- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java @@ -597,6 +597,7 @@ public void onBluetoothCodecChanged() { @Override public void onBluetoothHDAudioEnabled(boolean enabled) { + Log.d(TAG, "onBluetoothHDAudioEnabled: " + enabled); for (AbstractPreferenceController controller : mPreferenceControllers) { if (controller instanceof AbstractBluetoothDialogPreferenceController) { ((AbstractBluetoothDialogPreferenceController) controller).onHDAudioEnabled( diff --git a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java index 6b243c600f1..dc326fe9fd4 100644 --- a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java +++ b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java @@ -60,6 +60,15 @@ public void displayPreference(PreferenceScreen screen) { ((BaseBluetoothDialogPreference) mPreference).setCallback(this); } + @Override + public void onHDAudioEnabled(boolean enabled) { + Log.d(TAG, " onHDAudioEnabled: " + enabled); + if (!enabled) { + // If option codec is disabled, SBC is the only only one available codec. + onIndexUpdated(convertCfgToBtnIndex(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC)); + } + } + @Override public List getSelectableIndex() { List index = new ArrayList<>(); @@ -117,6 +126,14 @@ protected void writeConfigurationValues(final int index) { codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC; codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; break; + case 6: + codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_ADAPTIVE; + codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; + break; + case 7: + codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_TWSP; + codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; + break; default: break; } @@ -171,9 +188,15 @@ int convertCfgToBtnIndex(int config) { case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD: index = 4; break; + case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_ADAPTIVE: + index = 6; + break; case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC: index = 5; break; + case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_TWSP: + index = 7; + break; default: Log.e(TAG, "Unsupported config:" + config); break; diff --git a/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceController.java b/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceController.java index d4ca4e57952..6481c759f7a 100644 --- a/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceController.java +++ b/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceController.java @@ -81,6 +81,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { return true; } final boolean enabled = (Boolean) newValue; + Log.e(TAG, "onPreferenceChange: " + enabled); final int prefValue = enabled ? BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED : BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED; diff --git a/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceController.java b/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceController.java index 4b38e119778..f4d685733b4 100644 --- a/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceController.java +++ b/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceController.java @@ -105,7 +105,8 @@ public void updateState(Preference preference) { @Override public void onHDAudioEnabled(boolean enabled) { - mPreference.setEnabled(false); + Log.d(TAG, "onHDAudioEnabled: " + enabled); + mPreference.setEnabled(enabled); } @VisibleForTesting From 8ca181cd6bb257fb961010ea99c27a04c689ce32 Mon Sep 17 00:00:00 2001 From: Tim Peng Date: Thu, 1 Apr 2021 21:38:00 +0800 Subject: [PATCH 11/12] BTHS will have no sound after disable HD audio -setCodecConfigPreference() should not be called when disableOptionalCodecs() is called. -disableOptionalCodecs() would set SBC codec automatically Bug: 183456866 Test: make -j50 RunSettingsRoboTests ROBOTEST_FILTER=BluetoothCodecDialogPreferenceControllerTest Change-Id: Ib18f4a683dcba7ba92df827c30da0088c90b4d72 --- .../BluetoothCodecDialogPreferenceController.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java index dc326fe9fd4..66f387b79d6 100644 --- a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java +++ b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java @@ -60,15 +60,6 @@ public void displayPreference(PreferenceScreen screen) { ((BaseBluetoothDialogPreference) mPreference).setCallback(this); } - @Override - public void onHDAudioEnabled(boolean enabled) { - Log.d(TAG, " onHDAudioEnabled: " + enabled); - if (!enabled) { - // If option codec is disabled, SBC is the only only one available codec. - onIndexUpdated(convertCfgToBtnIndex(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC)); - } - } - @Override public List getSelectableIndex() { List index = new ArrayList<>(); From acf447ea7fb9c0a7545e098842b1d6bbe5c50e71 Mon Sep 17 00:00:00 2001 From: Tim Peng Date: Fri, 20 Aug 2021 05:43:29 +0000 Subject: [PATCH 12/12] Phone fails to switch channel mode from stereo to mono -Set codec to SBC when HD audio is off Bug: 194349060 Test: make -j50 RunSettingsRoboTests CRs-Fixed: 3075863 Change-Id: Iae4aa3f1d77350f5b4d91e7a687e048091c1daea --- ...ctBluetoothDialogPreferenceController.java | 8 ++++- ...etoothCodecDialogPreferenceController.java | 10 ++++-- ...thCodecDialogPreferenceControllerTest.java | 36 +++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java b/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java index c0143ba82a2..7a649edc01b 100644 --- a/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java +++ b/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java @@ -221,12 +221,18 @@ protected BluetoothCodecConfig getSelectableByCodecType(int codecTypeValue) { */ public void onHDAudioEnabled(boolean enabled) {} - static int getHighestCodec(BluetoothCodecConfig[] configs) { + static int getHighestCodec(BluetoothA2dp bluetoothA2dp, BluetoothDevice activeDevice, + BluetoothCodecConfig[] configs) { if (configs == null) { Log.d(TAG, "Unable to get highest codec. Configs are empty"); return BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID; } Log.d(TAG, "CODEC_TYPES len: " + CODEC_TYPES.length + " codec_config len: " + configs.length); + // 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 j = 0; j < configs.length; j++) { if ((configs[j].getCodecType() == CODEC_TYPES[i])) { diff --git a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java index 66f387b79d6..c8c9241b92b 100644 --- a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java +++ b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java @@ -93,8 +93,9 @@ protected void writeConfigurationValues(final int index) { int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT; switch (index) { case 0: - codecTypeValue = getHighestCodec(getSelectableConfigs( - mBluetoothA2dp.getActiveDevice())); + final BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice(); + codecTypeValue = getHighestCodec(mBluetoothA2dp, activeDevice, + getSelectableConfigs(activeDevice)); codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; break; case 1: @@ -155,6 +156,11 @@ public void onIndexUpdated(int index) { mCallback.onBluetoothCodecChanged(); } + @Override + public void onHDAudioEnabled(boolean enabled) { + writeConfigurationValues(/* index= */ 0); + } + private List getIndexFromConfig(BluetoothCodecConfig[] configs) { List indexArray = new ArrayList<>(); for (int i = 0; i < configs.length; i++) { diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java index 7dd29069416..0f01e00a3f4 100644 --- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java @@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.eq; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -108,6 +109,8 @@ public void writeConfigurationValues_selectDefault_setHighest() { BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus); + when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn( + BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED); mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.writeConfigurationValues(0); @@ -172,4 +175,37 @@ public void onIndexUpdated_notifyPreference() { 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)); + } }