Skip to content

Fix: Implement BootBroadcastReceiver to reschedule alarms after reboot#14

Open
itsmeaabhii wants to merge 2 commits into
CCExtractor:mainfrom
itsmeaabhii:abhishek
Open

Fix: Implement BootBroadcastReceiver to reschedule alarms after reboot#14
itsmeaabhii wants to merge 2 commits into
CCExtractor:mainfrom
itsmeaabhii:abhishek

Conversation

@itsmeaabhii
Copy link
Copy Markdown

@itsmeaabhii itsmeaabhii commented Feb 21, 2026

Fix: Implement BootBroadcastReceiver to reschedule alarms after reboot

Description

This PR fixes the issue where alarms fail to ring after device reboot. Previously, when a Wear OS device restarted, all pending alarms scheduled via AlarmManager were wiped by the Android system, and the app did not automatically reschedule them. This implementation adds a BootBroadcastReceiver that listens for device boot completion and automatically reschedules all active alarms from the SQLite database.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (code improvement/cleanup without logical changes)
  • UI/Design change

Proposed Changes

  • Added BootBroadcastReceiver.kt to handle BOOT_COMPLETED and QUICKBOOT_POWERON intents
  • Added RECEIVE_BOOT_COMPLETED permission to AndroidManifest.xml
  • Registered BootBroadcastReceiver in AndroidManifest with proper intent filters
  • Receiver queries database for all enabled alarms on boot
  • Automatically reschedules alarms using existing AlarmScheduler.scheduleNextAlarm() method
  • Added error handling and logging for boot alarm rescheduling

Fixes #9

Screenshots

N/A - This is a background service fix with no UI changes. The functionality can be tested by:

  1. Setting an alarm in the app
  2. Rebooting the device
  3. Verifying the alarm still rings at the scheduled time

Checklist

  • Tests have been added or updated to cover the changes
  • Documentation has been updated to reflect the changes
  • Code follows the established coding style guidelines
  • All tests are passing

- Added BootBroadcastReceiver to handle BOOT_COMPLETED intent
- Added RECEIVE_BOOT_COMPLETED permission to AndroidManifest.xml
- Automatically reschedules all active alarms from database on boot
- Fixes issue CCExtractor#9
Copilot AI review requested due to automatic review settings February 21, 2026 17:10
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements a BootBroadcastReceiver to address the issue where alarms fail to ring after device reboot. When an Android device restarts, all pending alarms scheduled via AlarmManager are cleared by the system. This PR adds functionality to automatically reschedule active alarms from the database when the device boots up.

Changes:

  • Added BootBroadcastReceiver class to handle device boot events and reschedule alarms
  • Added RECEIVE_BOOT_COMPLETED permission to AndroidManifest.xml
  • Updated dependency versions in pubspec.lock (transitive dependency updates)

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
android/app/src/main/kotlin/com/example/uac_companion/AlarmServices/BroadcastReceivers/BootBroadcastReceiver.kt New receiver that listens for boot completion and reschedules enabled alarms from the database
android/app/src/main/AndroidManifest.xml Added RECEIVE_BOOT_COMPLETED permission and registered BootBroadcastReceiver with intent filters for BOOT_COMPLETED and QUICKBOOT_POWERON
pubspec.lock Updated transitive dependencies to newer versions (standard Flutter/Dart SDK updates)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +16 to +20
}

override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
Log.d(TAG, "Device boot completed. Rescheduling alarms...")
Copy link

Copilot AI Feb 21, 2026

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.

Suggested change
}
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
Log.d(TAG, "Device boot completed. Rescheduling alarms...")
private const val ACTION_QUICKBOOT_POWERON = "android.intent.action.QUICKBOOT_POWERON"
private const val ACTION_HTC_QUICKBOOT_POWERON = "com.htc.intent.action.QUICKBOOT_POWERON"
}
override fun onReceive(context: Context, intent: Intent) {
val action = intent.action
if (action == Intent.ACTION_BOOT_COMPLETED ||
action == ACTION_QUICKBOOT_POWERON ||
action == ACTION_HTC_QUICKBOOT_POWERON) {
Log.d(TAG, "Device boot completed or quick boot power on. Rescheduling alarms...")

Copilot uses AI. Check for mistakes.
Comment on lines +29 to +32
// Reschedule each alarm using the AlarmScheduler
// The scheduler will automatically pick the next upcoming alarm
if (enabledAlarms.isNotEmpty()) {
AlarmScheduler.scheduleNextAlarm(context)
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment on line 29 states "Reschedule each alarm using the AlarmScheduler," but the code actually only schedules the next upcoming alarm via scheduleNextAlarm(context). Based on the AlarmScheduler implementation, this only schedules one alarm at a time (the next upcoming one). The comment should be updated to reflect this behavior, or if all enabled alarms should be scheduled, the implementation needs to be changed.

Copilot uses AI. Check for mistakes.
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")
}
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enabledAlarms variable is filtered but never used. Lines 24-27 filter for enabled alarms and log the count, but line 32 calls scheduleNextAlarm which internally filters again for enabled alarms. Consider removing the unused variable or using it to avoid redundant filtering.

Suggested change
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")

Copilot uses AI. Check for mistakes.
- Implemented dynamic location fetching using fl_location package
- Added fetchCurrentLocation() method with permission handling
- Replaced hardcoded New Delhi coordinates with real-time user location
- Added fallback to default location if permission denied or unavailable
- Added loading indicator in UI while fetching location
- Graceful error handling with user-friendly snackbar notifications
- Fixes issue CCExtractor#6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Alarms fail to ring after device reboot (Missing BootReceiver)

2 participants