-
Notifications
You must be signed in to change notification settings - Fork 7
Fix: Implement BootBroadcastReceiver to reschedule alarms after reboot #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,42 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| package com.ccextractor.uac_companion | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| import android.content.BroadcastReceiver | ||||||||||||||||||||||||||||||||||||||||||||
| import android.content.Context | ||||||||||||||||||||||||||||||||||||||||||||
| import android.content.Intent | ||||||||||||||||||||||||||||||||||||||||||||
| import android.util.Log | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * BootBroadcastReceiver listens for device boot completion. | ||||||||||||||||||||||||||||||||||||||||||||
| * When the device restarts, all pending alarms are cleared by the Android system. | ||||||||||||||||||||||||||||||||||||||||||||
| * This receiver reschedules all active alarms from the database. | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| class BootBroadcastReceiver : BroadcastReceiver() { | ||||||||||||||||||||||||||||||||||||||||||||
| companion object { | ||||||||||||||||||||||||||||||||||||||||||||
| private const val TAG = "BootBroadcastReceiver" | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| override fun onReceive(context: Context, intent: Intent) { | ||||||||||||||||||||||||||||||||||||||||||||
| if (intent.action == Intent.ACTION_BOOT_COMPLETED) { | ||||||||||||||||||||||||||||||||||||||||||||
| Log.d(TAG, "Device boot completed. Rescheduling alarms...") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||
| // Get all enabled alarms from the database | ||||||||||||||||||||||||||||||||||||||||||||
| val alarms = AlarmUtils.getAllAlarmsFromDb(context) | ||||||||||||||||||||||||||||||||||||||||||||
| val enabledAlarms = alarms.filter { it.isEnabled == 1 } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Log.d(TAG, "Found ${enabledAlarms.size} enabled alarms to reschedule") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Reschedule each alarm using the AlarmScheduler | ||||||||||||||||||||||||||||||||||||||||||||
| // The scheduler will automatically pick the next upcoming alarm | ||||||||||||||||||||||||||||||||||||||||||||
| if (enabledAlarms.isNotEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||||
| AlarmScheduler.scheduleNextAlarm(context) | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+29
to
+32
|
||||||||||||||||||||||||||||||||||||||||||||
| Log.d(TAG, "Successfully rescheduled alarms after boot") | ||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||
| Log.d(TAG, "No active alarms to reschedule") | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+21
to
+36
|
||||||||||||||||||||||||||||||||||||||||||||
| try { | |
| // Get all enabled alarms from the database | |
| val alarms = AlarmUtils.getAllAlarmsFromDb(context) | |
| val enabledAlarms = alarms.filter { it.isEnabled == 1 } | |
| Log.d(TAG, "Found ${enabledAlarms.size} enabled alarms to reschedule") | |
| // Reschedule each alarm using the AlarmScheduler | |
| // The scheduler will automatically pick the next upcoming alarm | |
| if (enabledAlarms.isNotEmpty()) { | |
| AlarmScheduler.scheduleNextAlarm(context) | |
| Log.d(TAG, "Successfully rescheduled alarms after boot") | |
| } else { | |
| Log.d(TAG, "No active alarms to reschedule") | |
| } | |
| try { | |
| // Delegate rescheduling to AlarmScheduler; it will handle enabled alarms internally | |
| AlarmScheduler.scheduleNextAlarm(context) | |
| Log.d(TAG, "Reschedule request sent to AlarmScheduler after boot") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent filter in AndroidManifest.xml includes both BOOT_COMPLETED and QUICKBOOT_POWERON actions, but this receiver only handles BOOT_COMPLETED. The QUICKBOOT_POWERON action (used by some manufacturers for quick boot) will not trigger alarm rescheduling. Consider checking for both actions or using a more general approach.