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

Commit ff2179b4 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

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



Change-Id: I6cc22b3af5aaaf8c03b348552aa493a825775086
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 546c56d7 67eb3ab7
Loading
Loading
Loading
Loading
+37 −22
Original line number Diff line number Diff line
@@ -4796,23 +4796,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);
@@ -4820,12 +4835,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;