Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 39950ef8 authored by Rahul Sabnis's avatar Rahul Sabnis Committed by Automerger Merge Worker
Browse files

Merge "Adjusts getPreferredAudioProfiles to check all devices in the CSIP...

Merge "Adjusts getPreferredAudioProfiles to check all devices in the CSIP group" am: 90b3c70e am: 67eb3ab7 am: ff2179b4

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2530159



Change-Id: I7e776327eff0b23bf696a436191166f11a5e9692
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 9224d55c ff2179b4
Loading
Loading
Loading
Loading
+37 −22
Original line number Diff line number Diff line
@@ -4811,23 +4811,38 @@ public class AdapterService extends Service {
                || !isDualModeAudioSinkDevice(device)) {
            return Bundle.EMPTY;
        }
        // Gets the lead device in the CSIP group to set the preference
        BluetoothDevice groupLead = mLeAudioService.getLeadDevice(device);
        if (groupLead == null) {
        // Checks if the device is part of an LE Audio group
        List<BluetoothDevice> groupDevices = mLeAudioService.getGroupDevices(device);
        if (groupDevices.isEmpty()) {
            return Bundle.EMPTY;
        }

        // If there are no preferences stored, return the defaults
        Bundle storedBundle = mDatabaseManager.getPreferredAudioProfiles(groupLead);
        Bundle storedBundle = Bundle.EMPTY;
        for (BluetoothDevice groupDevice: groupDevices) {
            Bundle groupDevicePreferences = mDatabaseManager.getPreferredAudioProfiles(groupDevice);
            if (!groupDevicePreferences.isEmpty()) {
                storedBundle = groupDevicePreferences;
                break;
            }
        }

        if (storedBundle.isEmpty()) {
            Bundle defaultPreferencesBundle = new Bundle();
            boolean useDefaultPreferences = false;
            if (isOutputOnlyAudioSupported(groupDevices)) {
                // Gets the default output only audio profile or defaults to LE_AUDIO if not present
            int outputOnlyDefault = BluetoothProperties.getDefaultOutputOnlyAudioProfile().orElse(
                    BluetoothProfile.LE_AUDIO);
                int outputOnlyDefault = BluetoothProperties.getDefaultOutputOnlyAudioProfile()
                        .orElse(BluetoothProfile.LE_AUDIO);
                if (outputOnlyDefault != BluetoothProfile.A2DP
                        && outputOnlyDefault != BluetoothProfile.LE_AUDIO) {
                    outputOnlyDefault = BluetoothProfile.LE_AUDIO;
                }

                defaultPreferencesBundle.putInt(BluetoothAdapter.AUDIO_MODE_OUTPUT_ONLY,
                        outputOnlyDefault);
                useDefaultPreferences = true;
            }
            if (isDuplexAudioSupported(groupDevices)) {
                // Gets the default duplex audio profile or defaults to LE_AUDIO if not present
                int duplexDefault = BluetoothProperties.getDefaultDuplexAudioProfile().orElse(
                        BluetoothProfile.LE_AUDIO);
@@ -4835,12 +4850,12 @@ public class AdapterService extends Service {
                        && duplexDefault != BluetoothProfile.LE_AUDIO) {
                    duplexDefault = BluetoothProfile.LE_AUDIO;
                }

            if (isOutputOnlyAudioSupported(mLeAudioService.getGroupDevices(device))) {
                storedBundle.putInt(BluetoothAdapter.AUDIO_MODE_OUTPUT_ONLY, outputOnlyDefault);
                defaultPreferencesBundle.putInt(BluetoothAdapter.AUDIO_MODE_DUPLEX, duplexDefault);
                useDefaultPreferences = true;
            }
            if (isDuplexAudioSupported(mLeAudioService.getGroupDevices(device))) {
                storedBundle.putInt(BluetoothAdapter.AUDIO_MODE_DUPLEX, duplexDefault);

            if (useDefaultPreferences) {
                return defaultPreferencesBundle;
            }
        }
        return storedBundle;