feat: show the battery temperature range since the last full charge - #262
Open
almothafar wants to merge 1 commit into
Open
feat: show the battery temperature range since the last full charge#262almothafar wants to merge 1 commit into
almothafar wants to merge 1 commit into
Conversation
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
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-digitconvention are already handled).
The window
The range accumulates continuously and resets only when a charge completes. Plugging in,
unplugging and the clock do nothing.
BATTERY_STATUS_FULLor a level of 100. The status alone misses deviceswhose charge cap stops them short of 100 %; the level alone misses OEMs that report full a tick
early.
fullSeenflag, so it fires once per completed charge andre-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
BatteryTemperatureTrackerholds a running min/max plus that flag in the backup-excludedbattery_transientprefs (another device's range says nothing about this one). Fed fromBatteryLevelReceiver.onReceivenext toBatteryHealthTracker.recordBatteryState, so no newpolling. Pure
fold/summarizehelpers, mirroringBatteryCapacityTracker.Two details worth flagging:
0are rejected.SystemServicereadsEXTRA_TEMPERATUREwith adefault of 0, so on a device that doesn't report a temperature every tick would look like a
freezing battery.
trackers follow;
hasDataflips 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 (theMissingTranslationlint gate passes).CONTEXT.md— a Temperature range glossary entry, sinceCLAUDE.mdmakes the glossarybinding for UI and code wording.
Tests
New
BatteryTemperatureTrackerTestcovering the running range, the plausibility gate (0, out ofband, 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,lintDebugandassembleDebugall pass on this branch.Manual verification
Not run — no device available in this environment. Worth checking on hardware:
not keep resetting it.
Generated by Claude Code