Fix shake-to-extend sleep timer lifecycle #58
Loading…
Reference in a new issue
No description provided.
Delete branch "mcp/issue-7-shake-sleep-timer"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #7
Root cause
The motion listener was already owned outside Compose:
SleepTimerControlleris process-singleton state attached byPlaybackService, andShakeDetectoruses the application SensorManager. The failure was in settings/lifecycle reconciliation.The controller checked its cached
shakeToRestartvalue only once when a timer started. If the persisted settings flow's first value arrived after that start, sensing stayed disabled for the entire timer. Likewise, changing shake-to-extend while a timer was active did not start/stop the listener until another timer.Change
ShakeSourceseam around the existing application-context sensor implementation;No wake lock, polling loop, second service, or second timer/state machine is added.
Automated coverage
SleepTimerControllerTestcovers:Android lifecycle evidence
Android's sensor guidance recommends receiving continuous sensor events while foreground or from a foreground service on Android 9+. BookWave's existing playback service is already the correct lifecycle owner while playback is active, so this change does not add another service or keep the CPU awake.
Device acceptance still required
Real accelerometer behavior is not claimed by JVM tests. Verify a deliberate shake with playback + active timer in:
then cancel the timer and confirm further shakes do nothing.
Final implementation-owner status
f5d49d932b19bece0af60af322a455c4911f199bverifyDebug: BUILD SUCCESSFUL:playback:testDebugUnitTestand:playback:verifyDebug: passedRoot cause: the accelerometer was already service/process-owned, not Compose-owned. The controller made a one-time decision from the cached shake setting when a timer started. A late DataStore emission, or a setting change during an active timer, was never reconciled, leaving sensing disabled (or stale) for that timer.
The fix makes registration a derived, idempotent property of
timer active && shake enabledon the timer's main dispatcher, reusing the existing single timer and existing restart behavior.Outstanding physical-device acceptance:
Actual accelerometer/background/screen-off success remains device-only evidence and is not claimed by the JVM gate.
Platform acceptance nuance: the implementation correctly keeps shake sensing owned by the existing playback-service lifecycle, which is the right Android boundary for background playback. Screen-off delivery is still device-dependent because
SensorManager.getDefaultSensor(TYPE_ACCELEROMETER)is ordinarily a non-wake-up accelerometer; foreground-service ownership alone does not guarantee delivery while the application processor is suspended. This PR intentionally adds no partial wake lock or continuous polling. Physical-device acceptance must therefore explicitly cover screen-off playback. If that case fails on target hardware, treat wake-up/CPU-awake behavior as a measured follow-up rather than adding battery wakeups speculatively.f5d49d932bto5536241169