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

Commit 67eb3ab7 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 group" am: 90b3c70e

parents f44cca8c 90b3c70e
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;