fix: prevent a crash when cancelling the sleep timer after a reset#449
Closed
MiMoHo wants to merge 1 commit into
Closed
fix: prevent a crash when cancelling the sleep timer after a reset#449MiMoHo wants to merge 1 commit into
MiMoHo wants to merge 1 commit into
Conversation
The sleep timer was driven by a single TOGGLE_SLEEP_TIMER command whose behavior depended on a service-side isActive flag. Setting the timer twice desynced client intent from the service state: the second set toggled the timer off (zeroing config.sleepInTS), and a subsequent cancel toggled it back on, building a CountDownTimer from a stale, zeroed timestamp. That produced a non-positive duration, firing onFinish() immediately, which posted SleepTimerChanged(0) and made MainActivity call finish(). Split the ambiguous toggle into explicit START_SLEEP_TIMER and STOP_SLEEP_TIMER commands so setting always (re)starts and canceling always stops, removing the isActive flag and the toggle indirection. Closes FossifyOrg#345
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.
Type of change(s)
What changed and why
The sleep timer was driven by a single
TOGGLE_SLEEP_TIMERcustom command whose behavior depended on a service-sideisActiveboolean.MainActivitysent the same toggle command for both "set timer" (startSleepTimer) and "cancel" (stopSleepTimer), which only works while the client intent and the serviceisActivestate stay in sync.Setting the timer a second time desynced them: the second "set" toggled the timer off instead of restarting it (canceling the countdown and zeroing
config.sleepInTS, so the visible countdown froze). A subsequent tap on the stop button then toggled the timer back on, building aCountDownTimerfrom the stale, zeroed timestamp. That yielded a non-positivemillisInFuture, soCountDownTimer.start()firedonFinish()immediately, postingEvents.SleepTimerChanged(0);MainActivity.sleepTimerChanged()seesseconds == 0and callsfinish(), so the app exits.This fix splits the ambiguous toggle into explicit
START_SLEEP_TIMERandSTOP_SLEEP_TIMERcommands so that "set" always (re)starts the timer and "cancel" always stops it. The service-sideisActiveflag and thetoggleSleepTimer()indirection are removed since they are no longer needed. This addresses both reported symptoms (the countdown freezing when the timer is set again, and the app closing when it is then canceled).Tests performed
detekt,lint, unit tests and the build all pass locally (CI-equivalent).START_SLEEP_TIMER/STOP_SLEEP_TIMER) so cancelling after a reset no longer references a stale timer and crashes.Closes the following issue(s)
Checklist
CHANGELOG.md(if applicable).Coded with Opus 4.8 ultracode.