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

Commit b9b44e7b authored by Rahul Sabnis's avatar Rahul Sabnis
Browse files

Adjusts getPreferredAudioProfiles to check all devices in the CSIP group

Tag: #feature
Bug: 265077412
Test: Manual
Change-Id: I485e255e2d11309670025f3b45dfac807ef4586f
parent 0faca70c
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;