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

Commit 4c880681 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Connect battery service only when it's available" am: 1f68930c

parents 58750c37 1f68930c
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -221,6 +221,20 @@ public class BatteryService extends ProfileService {
        return true;
    }

    /**
     * Connects to the battery service of the given device if possible.
     * If it's impossible, it doesn't try without logging errors.
     */
    public boolean connectIfPossible(BluetoothDevice device) {
        if (device == null
                || getConnectionPolicy(device) == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN
                || !Utils.arrayContains(
                        mAdapterService.getRemoteUuids(device), BluetoothUuid.BATTERY)) {
            return false;
        }
        return connect(device);
    }

    /**
     * Disconnects from the battery service of the given device.
     */
+4 −2
Original line number Diff line number Diff line
@@ -948,7 +948,7 @@ final class RemoteDevices {
            }
            BatteryService batteryService = BatteryService.getBatteryService();
            if (batteryService != null) {
                batteryService.connect(device);
                batteryService.connectIfPossible(device);
            }
            debugLog(
                    "aclStateChangeCallback: Adapter State: " + BluetoothAdapter.nameForState(state)
@@ -972,7 +972,9 @@ final class RemoteDevices {
            // Reset battery level on complete disconnection
            if (mAdapterService.getConnectionState(device) == 0) {
                BatteryService batteryService = BatteryService.getBatteryService();
                if (batteryService != null) {
                if (batteryService != null
                        && batteryService.getConnectionState(device)
                        != BluetoothProfile.STATE_DISCONNECTED) {
                    batteryService.disconnect(device);
                }
                resetBatteryLevel(device);