Loading android/app/src/com/android/bluetooth/bas/BatteryService.java +14 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading android/app/src/com/android/bluetooth/btservice/RemoteDevices.java +4 −2 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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); Loading Loading
android/app/src/com/android/bluetooth/bas/BatteryService.java +14 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading
android/app/src/com/android/bluetooth/btservice/RemoteDevices.java +4 −2 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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); Loading