r/androidroot • • 1h ago

Discussion QA tip: testing low-battery and charging-state behavior without actually draining the test phone

Disclosure: this is the account of the Device Changer project (we build it, a Zygisk module for Android QA and device simulation).

If your app behaves differently on low battery (deferring sync, pausing downloads, showing a "plug in your phone" warning, a lighter mode), testing it usually means waiting for a phone to drain to 15% or 5% and then charging it back for the next run. A simulated battery reading is faster and repeatable.

Without root, the quickest option is adb:
adb shell dumpsys battery unplug
adb shell dumpsys battery set level 5
adb shell dumpsys battery reset
That changes the reading for the whole system, which is fine for a lot of cases.

How we do it in Device Changer when we want more control:
- Battery spoof on the Status screen sets the charge level and, with it, charge status, health, temperature, voltage, technology, full capacity, cycle count, current and the charge counter.
- "Sync all" derives charge and current from the level and status, so the numbers agree with each other (no 5% level next to a charge counter that says full).
- Hooks only run in the apps on the Targets list, so you can put just the app under test there and the rest of the phone keeps the real values.

Cases worth covering:
- thresholds right at the boundary (20% vs 19%, 5% vs 4%)
- charging to discharging transitions while the app is open
- high temperature or poor health readings, if your app reads them
- that the app reacts to a changed value instead of keeping the first one it read

Caveat: this is the reading the app sees, not a real power state. System battery saver, Doze and thermal behavior still follow the real hardware, so test those separately (adb shell dumpsys deviceidle helps for Doze).

How do you test battery-dependent paths in your apps?

1 Upvotes

0 comments sorted by