Skip to content

feat: show the battery temperature range since the last full charge - #262

Open
almothafar wants to merge 1 commit into
masterfrom
claude/temperature-range-insights-260
Open

feat: show the battery temperature range since the last full charge#262
almothafar wants to merge 1 commit into
masterfrom
claude/temperature-range-insights-260

Conversation

@almothafar

Copy link
Copy Markdown
Owner

Closes #260

The problem

The battery temperature is read on every broadcast but was never retained, so after the fact there
was no way to tell whether the battery brushed the alert threshold for a minute or spent the
afternoon there — and no sense of what a normal temperature looks like on your own device.

The change

A new Temperature Range card in Battery Insights showing the coldest and hottest reading, in
the user's display unit (reuses TemperatureUtils.format, so °C/°F and the Western-digit
convention are already handled).

The window

The range accumulates continuously and resets only when a charge completes. Plugging in,
unplugging and the clock do nothing.

  • "Charge complete" is BATTERY_STATUS_FULL or a level of 100. The status alone misses devices
    whose charge cap stops them short of 100 %; the level alone misses OEMs that report full a tick
    early.
  • The reset is edge-triggered through a fullSeen flag, so it fires once per completed charge and
    re-arms when the battery leaves the full state — otherwise sitting plugged in at full would wipe
    the range on every broadcast. Same fire-once-then-re-arm shape as the full-battery alert's
    fullNotified.

The tracker

BatteryTemperatureTracker holds a running min/max plus that flag in the backup-excluded
battery_transient prefs (another device's range says nothing about this one). Fed from
BatteryLevelReceiver.onReceive next to BatteryHealthTracker.recordBatteryState, so no new
polling. Pure fold/summarize helpers, mirroring BatteryCapacityTracker.

Two details worth flagging:

  • Readings of exactly 0 are rejected. SystemService reads EXTRA_TEMPERATURE with a
    default of 0, so on a device that doesn't report a temperature every tick would look like a
    freezing battery.
  • No sample count. It would change on every tick and defeat the save-on-change rule the other
    trackers follow; hasData flips once and after that only a genuinely wider range writes.

Other files

  • values/strings.xml + values-ar/strings.xml — four new strings, kept in parity (the
    MissingTranslation lint gate passes).
  • CONTEXT.md — a Temperature range glossary entry, since CLAUDE.md makes the glossary
    binding for UI and code wording.

Tests

New BatteryTemperatureTrackerTest covering the running range, the plausibility gate (0, out of
band, and leaving an existing range untouched), and the reset: a completed charge starts a fresh
range; staying at full does not keep resetting; leaving full re-arms; plug-in/unplug alone do not
reset; full-level-without-full-status and full-status-below-full-level both count.

testDebugUnitTest, lintDebug and assembleDebug all pass on this branch.

Manual verification

Not run — no device available in this environment. Worth checking on hardware:

  1. The card reads "—" on a fresh install, then real min/max once a broadcast lands.
  2. Switching the unit preference to Fahrenheit — both values should follow.
  3. The card in Arabic (RTL) for wrapping.
  4. Charging to full collapses the range to that moment and it widens again; sitting at full does
    not keep resetting it.

Generated by Claude Code

The battery temperature was read on every broadcast but never retained, so
after the fact there was no way to tell whether the battery brushed the
alert threshold for a minute or spent the afternoon there.

Add BatteryTemperatureTracker, a running min/max in the backup-excluded
transient prefs, fed from BatteryLevelReceiver on every ACTION_BATTERY_CHANGED
tick, and surface it as a Temperature Range card in Battery Insights.

The range resets only when a charge completes; plugging in, unplugging and
the clock do nothing. "Charge complete" is BATTERY_STATUS_FULL or a level of
100 -- the status alone misses devices whose charge cap stops them short of
100%, the level alone misses OEMs that report full a tick early. The reset is
edge-triggered through a fullSeen flag so it fires once per completed charge
and re-arms when the battery leaves the full state, rather than wiping the
range on every tick while sitting plugged in at full.

Readings of exactly 0 are rejected: SystemService defaults EXTRA_TEMPERATURE
to 0, so 0 is indistinguishable from "this device didn't report one". There
is deliberately no sample count, which would change every tick and defeat the
save-on-change rule the other trackers follow.

Closes #260

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P8Rjarp53XHQEaZYX4SwTD
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.

feat: show the battery temperature range since the last full charge in Insights

2 participants