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

Commit aa49d2c0 authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Attempt outgoing HID host reconnection

When phone initiates the reconnection, it does not attempt to
reconnect HID profile.

Bug: 242641683
Tag: #stability
Test: Initiate reconnection from phone
Ignore-AOSP-First: Required for spatial audio
Change-Id: Icf3c869a6ab335cdee3b44592fcadfb444628d17
parent e8deba6c
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -576,6 +576,7 @@ class PhonePolicy {
                    + " attempting auto connection");
            autoConnectHeadset(mostRecentlyActiveA2dpDevice);
            autoConnectA2dp(mostRecentlyActiveA2dpDevice);
            autoConnectHidHost(mostRecentlyActiveA2dpDevice);
        } else {
            debugLog("autoConnect() - BT is in quiet mode. Not initiating auto connections");
        }
@@ -614,6 +615,23 @@ class PhonePolicy {
        }
    }

    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    private void autoConnectHidHost(BluetoothDevice device) {
        final HidHostService hidHostService = mFactory.getHidHostService();
        if (hidHostService == null) {
            warnLog("autoConnectHidHost: service is null, failed to connect to " + device);
            return;
        }
        int hidHostConnectionPolicy = hidHostService.getConnectionPolicy(device);
        if (hidHostConnectionPolicy == BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
            debugLog("autoConnectHidHost: Connecting HID with " + device);
            hidHostService.connect(device);
        } else {
            debugLog("autoConnectHidHost: skipped auto-connect HID with device " + device
                    + " connectionPolicy " + hidHostConnectionPolicy);
        }
    }

    private void connectOtherProfile(BluetoothDevice device) {
        if (mAdapterService.isQuietModeEnabled()) {
            debugLog("connectOtherProfile: in quiet mode, skip connect other profile " + device);
@@ -657,6 +675,7 @@ class PhonePolicy {
        VolumeControlService volumeControlService =
            mFactory.getVolumeControlService();
        BatteryService batteryService = mFactory.getBatteryService();
        HidHostService hidHostService = mFactory.getHidHostService();

        if (hsService != null) {
            if (!mHeadsetRetrySet.contains(device) && (hsService.getConnectionPolicy(device)
@@ -730,6 +749,15 @@ class PhonePolicy {
                batteryService.connect(device);
            }
        }
        if (hidHostService != null) {
            if ((hidHostService.getConnectionPolicy(device)
                    == BluetoothProfile.CONNECTION_POLICY_ALLOWED)
                    && (hidHostService.getConnectionState(device)
                    == BluetoothProfile.STATE_DISCONNECTED)) {
                debugLog("Retrying connection to HID with device " + device);
                hidHostService.connect(device);
            }
        }
    }

    private static void debugLog(String msg) {