Skip to content

🔴 Bogus battery capacity + 1% health on devices with non-µAh CHARGE_COUNTER (Kirin) #69

Description

@almothafar

Symptoms (found on-device: Huawei Mate 10 Pro, BLA-L29, Android 10 / API 29, EMUI 12)

  1. Battery details show an absurd Capacity of "2 mAh" / "3 mAh" / "9 mAh" (fluctuating) instead of the ~4000 mAh real capacity.
  2. After entering a 4000 mAh design capacity, Battery Health shows "1% — Poor".

Root cause

SystemService.getBatteryCapacity() estimates full capacity as
CHARGE_COUNTER (µAh) ÷ (CAPACITY% × 10). Android's contract says
BATTERY_PROPERTY_CHARGE_COUNTER is µAh (≈4,000,000 for a full 4000 mAh battery), but this
Kirin/HiSilicon device reports it in the low thousands:

$ adb shell dumpsys battery
  Charge counter: 9000        # should be ~4,000,000 µAh at 100%
  level: 100  scale: 100

So estimateFullCapacityMah(9000, 100) = round(9000 / 1000) = 9 mAh. That 9 mAh is shown as the
capacity, and it also poisons the measured-health figure:
computeMeasuredHealth(9, 4000, 100) = round(9 × 100 / 4000) = 0 → clamped to 1%"1% Poor".

Locations: SystemService.estimateFullCapacityMah, consumed by the details row and BatteryHealthTracker.getMeasuredHealthPercentage.

Proposed fix

Add a plausibility guard to estimateFullCapacityMah: if the estimate falls outside a sane
phone-battery range (~500–15000 mAh, matching the accepted design-capacity range), return 0
("unknown"). Effects:

  • Details Capacity row shows "Unknown" instead of "9 mAh" (already handled for <= 0).
  • The design-capacity dialog no longer prefills garbage.
  • getMeasuredHealthPercentage returns -1 → UI falls back to the honest Estimated (cycle-based)
    health instead of "1% Poor".

Note: on this device a measured health figure is simply not possible (the charge counter is
unusable), so falling back to the labeled Estimated value is the correct, honest behaviour.

Acceptance criteria

  • Implausible capacity estimates (e.g. from CHARGE_COUNTER = 9000) yield 0, surfaced as "Unknown".
  • Measured health is withheld (falls back to Estimated) when capacity can't be trusted — no more "1%".
  • Normal readings (e.g. 4,000,000 µAh at 100% → 4000 mAh) are unaffected.
  • SystemServiceTest covers the guard.

Found during on-device testing of #68.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions