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

Commit 4a691142 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Attempt outgoing HID host reconnection"

parents c2241049 c36de01a
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) {