fix(android): avoid overwriting app schedule when rollover uses daily_rollover_ id

NotifyReceiver's post-schedule DB update no longer uses the "first enabled
notify schedule" fallback when stableScheduleId starts with "daily_rollover_".
That fallback was updating the app's schedule row (e.g. daily_timesafari_reminder)
with the rollover time and could leave the app's next alarm in a bad state after
a notification fired.

Add docs/CONSUMING_APP_ANDROID_NOTES.md with notes for consuming apps: debounce
double scheduleDailyNotification calls, and include DailyNotificationReceiver
in logcat when debugging alarms that are scheduled but do not fire.
This commit is contained in:
Jose Olarte III
2026-02-16 18:16:20 +08:00
parent 02a44a3e7b
commit 0b61d33f21
2 changed files with 42 additions and 3 deletions

View File

@@ -420,9 +420,11 @@ class NotifyReceiver : BroadcastReceiver() {
// First, try to find schedule by the provided stableScheduleId
var scheduleToUpdate = db.scheduleDao().getById(stableScheduleId)
// If not found by ID, find the existing enabled notify schedule (for rollover scenarios)
// getNotificationStatus() finds schedules with kind="notify" && enabled=true
if (scheduleToUpdate == null) {
// If not found by ID, only use "first enabled notify" fallback when this is NOT
// a rollover id (daily_rollover_*). Rollover work may use a different notification_id
// (e.g. from recovery); updating the app's schedule row here would overwrite
// nextRunAt with the rollover time and can leave the app's alarm in a bad state.
if (scheduleToUpdate == null && !stableScheduleId.startsWith("daily_rollover_")) {
val allSchedules = db.scheduleDao().getAll()
scheduleToUpdate = allSchedules.firstOrNull { it.kind == "notify" && it.enabled }
}