From 36bbb0754c1a18302fffcc8b35ce2b6a1807ca08 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 18 Feb 2023 17:11:22 +0100 Subject: [PATCH] handle plugged state correctly --- .../androidaps/receivers/ChargingStateReceiver.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/ChargingStateReceiver.kt b/app/src/main/java/info/nightscout/androidaps/receivers/ChargingStateReceiver.kt index 321eaf1b6c..5923978509 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/ChargingStateReceiver.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/ChargingStateReceiver.kt @@ -32,12 +32,15 @@ class ChargingStateReceiver : DaggerBroadcastReceiver() { var batteryLevel = 0 val level = batteryStatus?.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) ?: -1 val scale = batteryStatus?.getIntExtra(BatteryManager.EXTRA_SCALE, -1) ?: -1 + val plugged = batteryStatus?.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) ?: -1 if (level != -1 && scale != -1) batteryLevel = (level.toFloat() / scale.toFloat() * 100.0f).toInt() - // Status - val status: Int = batteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1) ?: -1 - val isCharging: Boolean = status == BatteryManager.BATTERY_STATUS_CHARGING - || status == BatteryManager.BATTERY_STATUS_FULL + // Plugged + val isCharging: Boolean = + plugged == BatteryManager.BATTERY_PLUGGED_AC || + plugged == BatteryManager.BATTERY_PLUGGED_USB || + plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS || + plugged == BatteryManager.BATTERY_PLUGGED_DOCK return EventChargingState(isCharging, batteryLevel).also { receiverStatusStore.lastChargingEvent = it } }