mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-13 03:51:10 +00:00
fix: report a full battery at 100% while charging, so Steam stops showing 99% (#1577)
* fix: report a full battery at 100% while charging, so Steam stops showing 99% * test: charging at 100% is reported full
This commit is contained in:
1 parent
cf13762939
commit
02767b7e6c
2 files changed
+19
-4
No files matched your search
@@ -56,8 +56,9 @@ class BatteryComponent(val dir: File, private val vpowerDir: File) : SessionPart
|
||||
val timeToEmptyS = if (discharging && chargeNowUah > 0 && abs(currentAvgUa) > 0) chargeNowUah * 3600L / abs(currentAvgUa) else 0L
|
||||
val charging = status == BatteryManager.BATTERY_STATUS_CHARGING
|
||||
val timeToFullS = if (charging && chargeFullUah > chargeNowUah && abs(currentAvgUa) > 0) (chargeFullUah - chargeNowUah) * 3600L / abs(currentAvgUa) else 0L
|
||||
// Android can keep reporting charging at 100%; Linux reports Full there, and Steam shows 99% until it does.
|
||||
val statusText = when (status) {
|
||||
BatteryManager.BATTERY_STATUS_CHARGING -> "Charging"
|
||||
BatteryManager.BATTERY_STATUS_CHARGING -> if (pct >= 100) "Full" else "Charging"
|
||||
BatteryManager.BATTERY_STATUS_DISCHARGING -> "Discharging"
|
||||
BatteryManager.BATTERY_STATUS_FULL -> "Full"
|
||||
BatteryManager.BATTERY_STATUS_NOT_CHARGING -> "Not charging"
|
||||
|
||||
@@ -49,11 +49,25 @@ class BatteryComponentTest {
|
||||
assertEquals("-2000000", File(supplies, "BAT1/current_now").readText().trim())
|
||||
}
|
||||
|
||||
private fun start(supplies: File, vpower: File, currentUa: Long) {
|
||||
@Test fun chargingAtFullLevelIsReportedFullSoSteamStopsSaying99() {
|
||||
val supplies = tmp.newFolder("power_supply")
|
||||
val vpower = tmp.newFolder("vpower")
|
||||
start(supplies, vpower, 2_000_000L, BatteryManager.BATTERY_STATUS_CHARGING, 100)
|
||||
assertEquals("Full", File(supplies, "BAT1/status").readText().trim())
|
||||
assertEquals("Full", File(vpower, "battery_status").readText().trim())
|
||||
battery?.stop()
|
||||
start(supplies, vpower, 2_000_000L, BatteryManager.BATTERY_STATUS_CHARGING, 99)
|
||||
assertEquals("Charging", File(supplies, "BAT1/status").readText().trim())
|
||||
}
|
||||
|
||||
private fun start(
|
||||
supplies: File, vpower: File, currentUa: Long,
|
||||
status: Int = BatteryManager.BATTERY_STATUS_DISCHARGING, level: Int = 50,
|
||||
) {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
context.sendStickyBroadcast(Intent(Intent.ACTION_BATTERY_CHANGED).apply {
|
||||
putExtra(BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STATUS_DISCHARGING)
|
||||
putExtra(BatteryManager.EXTRA_LEVEL, 50)
|
||||
putExtra(BatteryManager.EXTRA_STATUS, status)
|
||||
putExtra(BatteryManager.EXTRA_LEVEL, level)
|
||||
putExtra(BatteryManager.EXTRA_SCALE, 100)
|
||||
putExtra(BatteryManager.EXTRA_VOLTAGE, 4000)
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user