Merge "Clean up Settings to allow a2dp, hfp, and le audio to be simultaneously connected on the same device"

This commit is contained in:
Treehugger Robot
2023-03-24 01:24:50 +00:00
committed by Gerrit Code Review

View File

@@ -20,6 +20,7 @@ import android.bluetooth.BluetoothCsipSetCoordinator;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothProfile;
import android.content.Context; import android.content.Context;
import android.os.SystemProperties;
import android.provider.DeviceConfig; import android.provider.DeviceConfig;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@@ -66,6 +67,9 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
@VisibleForTesting @VisibleForTesting
static final String HIGH_QUALITY_AUDIO_PREF_TAG = "A2dpProfileHighQualityAudio"; 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 LocalBluetoothManager mManager;
private LocalBluetoothProfileManager mProfileManager; private LocalBluetoothProfileManager mProfileManager;
private CachedBluetoothDevice mCachedDevice; private CachedBluetoothDevice mCachedDevice;
@@ -118,40 +122,17 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
/** /**
* Refreshes the state for an existing SwitchPreference for a profile. * 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, private void refreshProfilePreference(SwitchPreference profilePref,
LocalBluetoothProfile profile) { LocalBluetoothProfile profile) {
BluetoothDevice device = mCachedDevice.getDevice(); BluetoothDevice device = mCachedDevice.getDevice();
boolean isLeAudioEnabled = isLeAudioEnabled(); boolean isLeAudioEnabled = isLeAudioEnabled();
if (profile instanceof A2dpProfile if (profile instanceof A2dpProfile || profile instanceof HeadsetProfile
|| profile instanceof HeadsetProfile) { || profile instanceof LeAudioProfile) {
if (isLeAudioEnabled) { List<CachedBluetoothDevice> deviceList = mProfileDeviceMap.get(
// 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<CachedBluetoothDevice> deviceList = mProfileDeviceMap.get(
profile.toString());
boolean isBusy = deviceList != null
&& deviceList.stream().anyMatch(item -> item.isBusy());
profilePref.setEnabled(!isBusy);
}
} else if (profile instanceof LeAudioProfile) {
List<CachedBluetoothDevice> leAudioDeviceList = mProfileDeviceMap.get(
profile.toString()); profile.toString());
boolean isBusy = leAudioDeviceList != null boolean isBusy = deviceList != null
&& leAudioDeviceList.stream().anyMatch(item -> item.isBusy()); && deviceList.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);
}
profilePref.setEnabled(!isBusy); profilePref.setEnabled(!isBusy);
} else if (profile instanceof PbapServerProfile } else if (profile instanceof PbapServerProfile
&& isLeAudioEnabled && isLeAudioEnabled
@@ -183,7 +164,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
highQualityPref.setVisible(true); highQualityPref.setVisible(true);
highQualityPref.setTitle(a2dp.getHighQualityAudioOptionLabel(device)); highQualityPref.setTitle(a2dp.getHighQualityAudioOptionLabel(device));
highQualityPref.setChecked(a2dp.isHighQualityAudioEnabled(device)); highQualityPref.setChecked(a2dp.isHighQualityAudioEnabled(device));
highQualityPref.setEnabled(!mCachedDevice.isBusy() && !isLeAudioEnabled); highQualityPref.setEnabled(!mCachedDevice.isBusy());
} else { } else {
highQualityPref.setVisible(false); highQualityPref.setVisible(false);
} }
@@ -205,16 +186,6 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
return false; 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. * Helper method to enable a profile for a device.
*/ */
@@ -321,6 +292,17 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
if (mapPermission != BluetoothDevice.ACCESS_UNKNOWN) { if (mapPermission != BluetoothDevice.ACCESS_UNKNOWN) {
result.add(mapProfile); 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); Log.d(TAG, "getProfiles:result:" + result);
return 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. * Disable the Le Audio profile, VCP, and CSIP for each of the Le Audio devices.
* 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.
* *
* @param profile the LeAudio profile * @param profile the LeAudio profile
*/ */
@@ -354,8 +333,6 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
} }
LocalBluetoothProfile vcp = mProfileManager.getVolumeControlProfile(); LocalBluetoothProfile vcp = mProfileManager.getVolumeControlProfile();
LocalBluetoothProfile csip = mProfileManager.getCsipSetCoordinatorProfile(); LocalBluetoothProfile csip = mProfileManager.getCsipSetCoordinatorProfile();
LocalBluetoothProfile a2dp = mProfileManager.getA2dpProfile();
LocalBluetoothProfile headset = mProfileManager.getHeadsetProfile();
for (CachedBluetoothDevice leAudioDevice : mProfileDeviceMap.get(profile.toString())) { for (CachedBluetoothDevice leAudioDevice : mProfileDeviceMap.get(profile.toString())) {
Log.d(TAG, Log.d(TAG,
@@ -369,15 +346,15 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
} }
} }
enableProfileAfterUserDisablesLeAudio(a2dp); if (!SystemProperties.getBoolean(ENABLE_DUAL_MODE_AUDIO, false)) {
enableProfileAfterUserDisablesLeAudio(headset); 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. * Enable the Le Audio profile, VCP, and CSIP for each of the Le Audio devices.
* 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.
* *
* @param profile the LeAudio profile * @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."); Log.e(TAG, "There is no the LE profile or no device in mProfileDeviceMap. Do nothing.");
return; 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 vcp = mProfileManager.getVolumeControlProfile();
LocalBluetoothProfile csip = mProfileManager.getCsipSetCoordinatorProfile(); LocalBluetoothProfile csip = mProfileManager.getCsipSetCoordinatorProfile();
disableProfileBeforeUserEnablesLeAudio(a2dp);
disableProfileBeforeUserEnablesLeAudio(headset);
for (CachedBluetoothDevice leAudioDevice : mProfileDeviceMap.get(profile.toString())) { for (CachedBluetoothDevice leAudioDevice : mProfileDeviceMap.get(profile.toString())) {
Log.d(TAG, Log.d(TAG,
"User enable LE device: " + leAudioDevice.getDevice().getAnonymizedAddress()); "User enable LE device: " + leAudioDevice.getDevice().getAnonymizedAddress());