fix: dismiss the overheat notification once the battery cools - #261
Open
almothafar wants to merge 1 commit into
Open
fix: dismiss the overheat notification once the battery cools#261almothafar wants to merge 1 commit into
almothafar wants to merge 1 commit into
Conversation
The high-temperature alert had hysteresis on firing but none on clearing. decideTemperature re-arms the persisted flag once the battery cools past threshold - 3 C, but handleTemperature used that decision only to rewrite the boolean; TEMPERATURE_NOTIFICATION_ID was never cancelled anywhere and the shared alert builder never sets setAutoCancel. The warning therefore outlived the hot spell and sat in the shade until the user swiped it. Act on the true -> false transition the method already computes and call the new NotificationService.clearTemperatureAlert, the same "don't leave a stale alert alive" cleanup FastDrainDetector does for its own warning. This also covers switching the alert off in Settings while one is showing, since decideTemperature re-arms there too. Staying inside the hysteresis band still holds, so the notification cannot flap. Closes #259 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P8Rjarp53XHQEaZYX4SwTD
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 #259
The problem
The high-temperature alert had hysteresis on firing but none on clearing:
decideTemperaturere-arms the persisted_temperature_alert_sentflag once the battery coolsto
threshold − TEMPERATURE_HYSTERESIS_C(3 °C).handleTemperatureused that decision only to rewrite the boolean — it ignored thetrue → falsetransition.TEMPERATURE_NOTIFICATION_IDwas never passed toNotificationManager.cancel()anywhere in theapp, and the shared
alertBuildernever setssetAutoCancel(true).So the warning outlived the hot spell and sat in the shade until the user swiped it, reading as
"still overheating" on a phone that had long since cooled.
The change
Act on the
true → falsetransitionhandleTemperaturealready computes and call the newNotificationService.clearTemperatureAlert— the same "don't leave a stale alert alive" cleanupFastDrainDetectoralready does for its own warning. No extra prefs read, no new state.This covers both re-arm paths in
decideTemperature:Staying inside the hysteresis band still holds the alert, so the notification cannot flap.
Deliberately out of scope: adding
setAutoCancel(true)to the sharedalertBuilder— thatwould change tap-behaviour for every quiet-hours-aware alert, not just temperature.
Tests
Three cases added to
BatteryLevelReceiverTest, which already mocks theNotificationServicestatics:
temperature_cooledBelowHysteresis_dismissesStaleAlert— hot tick then a cool tick, assertsclearTemperatureAlertcalled once.temperature_withinHysteresisBand_keepsAlertShown— negative case at 43 °C, assertsnever().temperature_alertDisabledWhileShown_dismissesStaleAlert.testDebugUnitTest,lintDebugandassembleDebugall pass on this branch.Manual verification
Not run — no device available in this environment. Worth checking on hardware:
Generated by Claude Code