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

Commit e2f924c4 authored by Krzysztof Kopyściński's avatar Krzysztof Kopyściński Committed by Krzysztof Kopyscinski (xWF)
Browse files

PhonePolicy: add HAP to processConnectOtherProfiles

On reconnection, profile was not always getting connected, and
workaround had to be used to make profile usable again. This patch fixes
the issue by calling hapClientService.connect() when other profiles
connect.

Bug: 376489074
Bug: 379771539
Flag: com.android.bluetooth.flags.connect_hap_on_other_profile_connect
Test: m -j
Change-Id: I491ed2140df888e3eedd552430a767607643adee
parent 9bf35901
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -1020,6 +1020,7 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback {
        BatteryService batteryService = mFactory.getBatteryService();
        HidHostService hidHostService = mFactory.getHidHostService();
        BassClientService bcService = mFactory.getBassClientService();
        HapClientService hapClientService = mFactory.getHapClientService();

        if (hsService != null) {
            if (!mHeadsetRetrySet.contains(device)
@@ -1120,6 +1121,19 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback {
                bcService.connect(device);
            }
        }
        if (Flags.connectHapOnOtherProfileConnect()) {
            if (hapClientService != null) {
                List<BluetoothDevice> connectedDevices = hapClientService.getConnectedDevices();
                if (!connectedDevices.contains(device)
                        && (hapClientService.getConnectionPolicy(device)
                                == BluetoothProfile.CONNECTION_POLICY_ALLOWED)
                        && (hapClientService.getConnectionState(device)
                                == BluetoothProfile.STATE_DISCONNECTED)) {
                    debugLog("Retrying connection to HAS with device " + device);
                    hapClientService.connect(device);
                }
            }
        }
    }

    /**
+4 −1
Original line number Diff line number Diff line
@@ -280,7 +280,10 @@ public class HapClientService extends ProfileService {
        }
    }

    List<BluetoothDevice> getConnectedDevices() {
    /**
     * @return A list of connected {@link BluetoothDevice}.
     */
    public List<BluetoothDevice> getConnectedDevices() {
        synchronized (mStateMachines) {
            List<BluetoothDevice> devices = new ArrayList<>();
            for (HapClientStateMachine sm : mStateMachines.values()) {