Skip to content

Battery current: unit key auto/uA/mA (#9) - #10

Merged
groupsky merged 2 commits into
mainfrom
aoda-9-battery-unit
Nov 15, 2026
Merged

groupsky merged 2 commits into
mainfrom
aoda-9-battery-unit

Conversation

@groupsky

@groupsky groupsky commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Refs #9

Adds collectors.battery.current_unit (auto, uA, mA; default auto) for the raw BATTERY_PROPERTY_CURRENT_NOW value.

Choices

  • Auto rule (leaner than watching how the charge counter changes): a raw value of 50000 or more is µA (50 A is not a real phone current, even with 240 W fast charging; 10 A would be too low a cut for those phones), and after one such value the app keeps µA until restart; else mA for Build.MANUFACTURER OnePlus, OPPO or realme (one shared battery service); else µA as Android says. No new state on disk, no wait for a second reading.
  • Sign: kept as the phone gives it, no sign key. The README says so.
  • Key place: under collectors.battery, next to the other battery settings. The config file and the adb import both go through ConfigLoader, so a wrong value rejects the import like a wrong wake_policy.

Progress

  • The unit key exists (auto, uA, mA), with auto as default, and it is in the README config table.
  • The key is read from the config file and from the adb import. A wrong value is rejected, like a wrong wake_policy.
  • On a OnePlus phone that gives mA, device.battery.current is about 1.5 A in size while it charges at 1.5 A, with the default config. Needs a real phone: for Geno.
  • On the emulator (which gives µA), the value does not change from today. See "Emulator test" below.
  • Unit tests cover the unit choice.
  • The README row for device.battery.current says how the unit is chosen, how to override it, and which sign is used.

Emulator test (2026-11-15)

Emulator: Android 15, API 35, x86_64 (AOSP image, device.manufacturer = unknown). Receiver: a throw-away VictoriaMetrics container on 127.0.0.1, removed after.

  • Raw BATTERY_PROPERTY_CURRENT_NOW (service call batteryproperties 1 i32 2): 0x000dbba0 = 900000 µA. The emulator console cannot set another current.
  • device.battery.current with the default (auto): 0.9 (same as before this change: 900000 µA / 1e6).
  • "current_unit": "mA": 900 (1000× bigger, as expected). "uA": 0.9 again.
  • "current_unit": "bogus" by adb broadcast: result=0, data="error: collectors > battery > current_unit: must be one of auto, uA, mA"; the config in use stayed.

For Geno: the OnePlus check

On the OnePlus Nord CE 2 Lite, with the default config (no current_unit), while it charges at about 1.5 A (dumpsys battery shows Battery current : -1508 or so): device.battery.current should be about -1.5 (size 1.5 A; the sign stays as the phone gives it), not -0.0015.

Some phones (OnePlus) give BATTERY_PROPERTY_CURRENT_NOW in mA, not uA.
New key collectors.battery.current_unit; auto reads uA for values too
large to be mA, mA for OnePlus/OPPO/realme, else uA. The sign is kept.
Fast charging (150-240 W) can go above 10 A on the mA makers.
@groupsky
groupsky marked this pull request as ready for review November 15, 2026 20:21
@groupsky
groupsky merged commit e7359cb into main Nov 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant