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

Commit 877cb278 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

PhonePolicy: Connect VC before LeAudio service

Make sure to have proper volume set when connecting LeAudio device
Also it remove unused import as `repo upload` suggested

Bug: 309882321
Test: atest VolumeControlServiceTest
Tag: #feature
Change-Id: Ia34834cbe05817ffc7ff55eea2df2c3ae0402682
parent e46250c1
Loading
Loading
Loading
Loading
+29 −29
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.os.Looper;
import android.os.Message;
import android.os.ParcelUuid;
import android.os.SystemProperties;
import android.provider.DeviceConfig;
import android.util.Log;

import com.android.bluetooth.R;
@@ -301,6 +300,35 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback {
            }
        }

        /* Make sure to connect Volume Control before LeAudio service */
        if ((volumeControlService != null)
                && Utils.arrayContains(uuids, BluetoothUuid.VOLUME_CONTROL)
                && (volumeControlService.getConnectionPolicy(device)
                        == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) {
            if (isLeAudioProfileAllowed) {
                debugLog("setting volume control profile priority for device " + device);
                if (mAutoConnectProfilesSupported) {
                    volumeControlService.setConnectionPolicy(
                            device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                } else {
                    mAdapterService
                            .getDatabase()
                            .setProfileConnectionPolicy(
                                    device,
                                    BluetoothProfile.VOLUME_CONTROL,
                                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                }
            } else {
                debugLog("clear VCP priority because dual mode is disabled by default");
                mAdapterService
                        .getDatabase()
                        .setProfileConnectionPolicy(
                                device,
                                BluetoothProfile.VOLUME_CONTROL,
                                BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
            }
        }

        // If we do not have a stored priority for HFP/A2DP (all roles) then default to on.
        if ((panService != null)
                && (Utils.arrayContains(uuids, BluetoothUuid.PANU)
@@ -377,34 +405,6 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback {
            }
        }

        if ((volumeControlService != null)
                && Utils.arrayContains(uuids, BluetoothUuid.VOLUME_CONTROL)
                && (volumeControlService.getConnectionPolicy(device)
                        == BluetoothProfile.CONNECTION_POLICY_UNKNOWN)) {
            if (isLeAudioProfileAllowed) {
                debugLog("setting volume control profile priority for device " + device);
                if (mAutoConnectProfilesSupported) {
                    volumeControlService.setConnectionPolicy(
                            device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                } else {
                    mAdapterService
                            .getDatabase()
                            .setProfileConnectionPolicy(
                                    device,
                                    BluetoothProfile.VOLUME_CONTROL,
                                    BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                }
            } else {
                debugLog("clear VCP priority because dual mode is disabled by default");
                mAdapterService
                        .getDatabase()
                        .setProfileConnectionPolicy(
                                device,
                                BluetoothProfile.VOLUME_CONTROL,
                                BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
            }
        }

        if ((hapClientService != null)
                && Utils.arrayContains(uuids, BluetoothUuid.HAS)
                && (hapClientService.getConnectionPolicy(device)