From b1e25950b85ab4ccc98377da2757c23c9b634855 Mon Sep 17 00:00:00 2001 From: Rahul Sabnis Date: Thu, 5 Jan 2023 11:10:50 -0800 Subject: [PATCH] Clean up Settings to allow a2dp, hfp, and le audio to be simultaneously connected on the same device Removes the classic audio toggles for dual mode audio devices. Bug: 257881495 Test: Manual Change-Id: Ie6794b4d904c74a7c5137ad141172c10188a99f9 --- .../BluetoothDetailsProfilesController.java | 92 +++++++------------ 1 file changed, 35 insertions(+), 57 deletions(-) diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java index a86b7589191..e2045f80c27 100644 --- a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java +++ b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java @@ -20,6 +20,7 @@ import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Context; +import android.os.SystemProperties; import android.provider.DeviceConfig; import android.text.TextUtils; import android.util.Log; @@ -66,6 +67,9 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll @VisibleForTesting static final String HIGH_QUALITY_AUDIO_PREF_TAG = "A2dpProfileHighQualityAudio"; + private static final String ENABLE_DUAL_MODE_AUDIO = + "persist.bluetooth.enable_dual_mode_audio"; + private LocalBluetoothManager mManager; private LocalBluetoothProfileManager mProfileManager; private CachedBluetoothDevice mCachedDevice; @@ -118,40 +122,17 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll /** * Refreshes the state for an existing SwitchPreference for a profile. - * If the LeAudio profile is enabled on the LeAudio devices, then the SwitchPreferences of - * A2dp profile and Headset profile are graied out. */ private void refreshProfilePreference(SwitchPreference profilePref, LocalBluetoothProfile profile) { BluetoothDevice device = mCachedDevice.getDevice(); boolean isLeAudioEnabled = isLeAudioEnabled(); - if (profile instanceof A2dpProfile - || profile instanceof HeadsetProfile) { - if (isLeAudioEnabled) { - // If the LeAudio profile is enabled on the LeAudio devices, then the - // SwitchPreferences of A2dp profile and Headset profile are grayed out. - Log.d(TAG, "LE is enabled, gray out " + profile.toString()); - profilePref.setEnabled(false); - } else { - List deviceList = mProfileDeviceMap.get( - profile.toString()); - boolean isBusy = deviceList != null - && deviceList.stream().anyMatch(item -> item.isBusy()); - profilePref.setEnabled(!isBusy); - } - } else if (profile instanceof LeAudioProfile) { - List leAudioDeviceList = mProfileDeviceMap.get( + if (profile instanceof A2dpProfile || profile instanceof HeadsetProfile + || profile instanceof LeAudioProfile) { + List deviceList = mProfileDeviceMap.get( profile.toString()); - boolean isBusy = leAudioDeviceList != null - && leAudioDeviceList.stream().anyMatch(item -> item.isBusy()); - if (isLeAudioEnabled && !isBusy) { - LocalBluetoothProfile a2dp = mProfileManager.getA2dpProfile(); - LocalBluetoothProfile headset = mProfileManager.getHeadsetProfile(); - // If the LeAudio profile is enabled on the LeAudio devices, then the - // SwitchPreferences of A2dp profile and Headset profile are graied out. - grayOutPreferenceWhenLeAudioIsEnabled(a2dp); - grayOutPreferenceWhenLeAudioIsEnabled(headset); - } + boolean isBusy = deviceList != null + && deviceList.stream().anyMatch(item -> item.isBusy()); profilePref.setEnabled(!isBusy); } else if (profile instanceof PbapServerProfile && isLeAudioEnabled @@ -183,7 +164,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll highQualityPref.setVisible(true); highQualityPref.setTitle(a2dp.getHighQualityAudioOptionLabel(device)); highQualityPref.setChecked(a2dp.isHighQualityAudioEnabled(device)); - highQualityPref.setEnabled(!mCachedDevice.isBusy() && !isLeAudioEnabled); + highQualityPref.setEnabled(!mCachedDevice.isBusy()); } else { highQualityPref.setVisible(false); } @@ -205,16 +186,6 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll return false; } - private void grayOutPreferenceWhenLeAudioIsEnabled(LocalBluetoothProfile profile) { - if (profile != null) { - SwitchPreference pref = mProfilesContainer.findPreference(profile.toString()); - if (pref != null) { - Log.d(TAG, "LE is enabled, gray out " + profile.toString()); - pref.setEnabled(false); - } - } - } - /** * Helper method to enable a profile for a device. */ @@ -321,6 +292,17 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll if (mapPermission != BluetoothDevice.ACCESS_UNKNOWN) { result.add(mapProfile); } + + // Removes phone calls & media audio toggles for dual mode devices + boolean leAudioSupported = result.contains( + mManager.getProfileManager().getLeAudioProfile()); + boolean classicAudioSupported = result.contains( + mManager.getProfileManager().getA2dpProfile()) || result.contains( + mManager.getProfileManager().getHeadsetProfile()); + if (leAudioSupported && classicAudioSupported) { + result.remove(mManager.getProfileManager().getA2dpProfile()); + result.remove(mManager.getProfileManager().getHeadsetProfile()); + } Log.d(TAG, "getProfiles:result:" + result); return result; } @@ -340,10 +322,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll } /** - * When user disable the Le Audio profile, the system needs to do two things. - * 1) Disable the Le Audio profile, VCP and CSIP for each of the Le Audio devices. - * 2) Enable the A2dp profile and Headset profile for the associated device. The system - * can't enable the A2dp profile and Headset profile if the Le Audio profile is enabled. + * Disable the Le Audio profile, VCP, and CSIP for each of the Le Audio devices. * * @param profile the LeAudio profile */ @@ -354,8 +333,6 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll } LocalBluetoothProfile vcp = mProfileManager.getVolumeControlProfile(); LocalBluetoothProfile csip = mProfileManager.getCsipSetCoordinatorProfile(); - LocalBluetoothProfile a2dp = mProfileManager.getA2dpProfile(); - LocalBluetoothProfile headset = mProfileManager.getHeadsetProfile(); for (CachedBluetoothDevice leAudioDevice : mProfileDeviceMap.get(profile.toString())) { Log.d(TAG, @@ -369,15 +346,15 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll } } - enableProfileAfterUserDisablesLeAudio(a2dp); - enableProfileAfterUserDisablesLeAudio(headset); + if (!SystemProperties.getBoolean(ENABLE_DUAL_MODE_AUDIO, false)) { + Log.i(TAG, "Enabling classic audio profiles because dual mode is disabled"); + enableProfileAfterUserDisablesLeAudio(mProfileManager.getA2dpProfile()); + enableProfileAfterUserDisablesLeAudio(mProfileManager.getHeadsetProfile()); + } } /** - * When user enable the Le Audio profile, the system needs to do two things. - * 1) Disable the A2dp profile and Headset profile for the associated device. The system - * can't enable the Le Audio if the A2dp profile and Headset profile are enabled. - * 2) Enable the Le Audio profile, VCP and CSIP for each of the Le Audio devices. + * Enable the Le Audio profile, VCP, and CSIP for each of the Le Audio devices. * * @param profile the LeAudio profile */ @@ -386,14 +363,15 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll Log.e(TAG, "There is no the LE profile or no device in mProfileDeviceMap. Do nothing."); return; } - LocalBluetoothProfile a2dp = mProfileManager.getA2dpProfile(); - LocalBluetoothProfile headset = mProfileManager.getHeadsetProfile(); + + if (!SystemProperties.getBoolean(ENABLE_DUAL_MODE_AUDIO, false)) { + Log.i(TAG, "Disabling classic audio profiles because dual mode is disabled"); + disableProfileBeforeUserEnablesLeAudio(mProfileManager.getA2dpProfile()); + disableProfileBeforeUserEnablesLeAudio(mProfileManager.getHeadsetProfile()); + } + LocalBluetoothProfile vcp = mProfileManager.getVolumeControlProfile(); LocalBluetoothProfile csip = mProfileManager.getCsipSetCoordinatorProfile(); - - disableProfileBeforeUserEnablesLeAudio(a2dp); - disableProfileBeforeUserEnablesLeAudio(headset); - for (CachedBluetoothDevice leAudioDevice : mProfileDeviceMap.get(profile.toString())) { Log.d(TAG, "User enable LE device: " + leAudioDevice.getDevice().getAnonymizedAddress());