fix the problem with a crash when the phone is locked (or newly unlocked)
This commit is contained in:
+11
-1
@@ -5,7 +5,17 @@ All notable changes to the Daily Notification Plugin will be documented in this
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
## [5.0.1]
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Android**: `BootReceiver` no longer crashes the app after a reboot on devices with a lock-screen PIN/pattern. It ignores `LOCKED_BOOT_COMPLETED`, and any broadcast while the user is locked, because recovery reads SharedPreferences and the Room database in credential-encrypted storage, which throws `IllegalStateException` until first unlock. Recovery runs on `BOOT_COMPLETED`, right after first unlock; alarms that came due while locked are marked missed and their next occurrence is scheduled.
|
||||
|
||||
### Changed
|
||||
|
||||
- **Android (consumers)**: Remove `android:directBootAware="true"` and the `LOCKED_BOOT_COMPLETED` action from your `BootReceiver` declaration in `AndroidManifest.xml`. The receiver is not direct-boot capable; it is safe if they remain, but the process starts for nothing.
|
||||
- **Android (consumers)**: A native fetcher registered with `DailyNotificationPlugin.setNativeFetcher` in `Application.onCreate` must not open SharedPreferences, databases, or files in its constructor. `Application.onCreate` also runs when a direct-boot-aware component (e.g. Firebase Messaging) starts the process before first unlock; open storage on first use instead.
|
||||
- **Docs / test apps**: Boot receiver guide, alarm docs, and test-app manifests drop direct-boot / `LOCKED_BOOT_COMPLETED` recommendations.
|
||||
|
||||
## [5.0.0] - 2026-09-24
|
||||
|
||||
|
||||
@@ -583,6 +583,10 @@ await DailyNotification.updateDailyReminder('morning_checkin', {
|
||||
|
||||
**Note**: The `NotifyReceiver` must be registered in your app's `AndroidManifest.xml`, not just in the plugin's manifest. If notifications aren't appearing even though alarms are scheduled, check that `NotifyReceiver` is properly registered.
|
||||
|
||||
**Note**: `BootReceiver` is not direct-boot capable. Do not give it `android:directBootAware="true"` or a `LOCKED_BOOT_COMPLETED` action. Recovery reads the plugin's database and SharedPreferences, which live in credential-encrypted storage and are unavailable until the user's first unlock after reboot. `BOOT_COMPLETED` arrives right after that unlock, and recovery reschedules alarms that came due while the device was locked as missed, firing their next occurrence. The receiver ignores locked-boot broadcasts if a manifest still declares them.
|
||||
|
||||
**Note**: If you register a native fetcher with `DailyNotificationPlugin.setNativeFetcher` in `Application.onCreate`, its constructor must not open SharedPreferences, databases, or files; open them on first use. `Application.onCreate` also runs when a direct-boot-aware component (for example Firebase Messaging) starts the process before first unlock, and credential-encrypted storage access then throws `IllegalStateException`, crashing the app.
|
||||
|
||||
#### build.gradle
|
||||
|
||||
```gradle
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import androidx.core.os.UserManagerCompat
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -12,6 +13,13 @@ import kotlinx.coroutines.launch
|
||||
/**
|
||||
* Boot recovery receiver to reschedule notifications after device reboot
|
||||
* Implements RECEIVE_BOOT_COMPLETED functionality
|
||||
*
|
||||
* Not direct-boot capable: recovery reads SharedPreferences and the Room database,
|
||||
* both in credential-encrypted storage, which throws IllegalStateException until the
|
||||
* user's first unlock after reboot. Locked-boot broadcasts are ignored; recovery runs
|
||||
* on BOOT_COMPLETED, which Android delivers right after first unlock. Consumer
|
||||
* manifests must not declare android:directBootAware or LOCKED_BOOT_COMPLETED for
|
||||
* this receiver, but this receiver stays safe if an older manifest still does.
|
||||
*
|
||||
* @author Matthew Raymer
|
||||
* @version 1.1.0
|
||||
@@ -23,9 +31,17 @@ class BootReceiver : BroadcastReceiver() {
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent?) {
|
||||
when (intent?.action) {
|
||||
Intent.ACTION_BOOT_COMPLETED,
|
||||
Intent.ACTION_LOCKED_BOOT_COMPLETED -> {
|
||||
val action = intent?.action
|
||||
if (action == Intent.ACTION_LOCKED_BOOT_COMPLETED) {
|
||||
Log.i(TAG, "Ignoring locked boot; recovery runs on BOOT_COMPLETED after first unlock")
|
||||
return
|
||||
}
|
||||
if (!UserManagerCompat.isUserUnlocked(context)) {
|
||||
Log.i(TAG, "Ignoring $action: user locked, credential-encrypted storage unavailable")
|
||||
return
|
||||
}
|
||||
when (action) {
|
||||
Intent.ACTION_BOOT_COMPLETED -> {
|
||||
Log.i(TAG, "Boot completed, setting boot flag and starting recovery")
|
||||
|
||||
// Phase 2: Set boot flag for scenario detection
|
||||
@@ -44,7 +60,7 @@ class BootReceiver : BroadcastReceiver() {
|
||||
ReactivationManager.runBootRecovery(context)
|
||||
}
|
||||
else -> {
|
||||
Log.d(TAG, "Unhandled intent action: ${intent?.action}")
|
||||
Log.d(TAG, "Unhandled intent action: $action")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,11 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
|
||||
/**
|
||||
* Register a native content fetcher
|
||||
*
|
||||
* Typically called from Application.onCreate, which can run before the user's
|
||||
* first unlock after reboot (when a direct-boot-aware component starts the
|
||||
* process). The fetcher's constructor must not open SharedPreferences, databases,
|
||||
* or files; credential-encrypted storage throws until unlock. Open them on first use.
|
||||
*
|
||||
* @param fetcher The native fetcher implementation to register
|
||||
*/
|
||||
|
||||
+4
@@ -34,6 +34,10 @@ import java.util.concurrent.CompletableFuture;
|
||||
* - Must complete within reasonable time (plugin enforces timeout)
|
||||
* - Should return empty list on failure rather than throwing exceptions
|
||||
* - Should handle errors gracefully and log for debugging
|
||||
* - Constructor must not open SharedPreferences, databases, or files; open them on
|
||||
* first use. Fetchers are registered in Application.onCreate, which also runs when a
|
||||
* direct-boot-aware component starts the process before the user's first unlock, and
|
||||
* credential-encrypted storage then throws IllegalStateException.
|
||||
*
|
||||
* Example Implementation:
|
||||
* <pre>
|
||||
|
||||
@@ -72,7 +72,7 @@ The OS recreates your app's process to deliver the `PendingIntent`.
|
||||
|
||||
**App Capability**: Apps may recreate alarms after reboot by:
|
||||
1. Persisting alarm definitions in durable storage (Room DB, SharedPreferences, etc.)
|
||||
2. Registering a `BOOT_COMPLETED` / `LOCKED_BOOT_COMPLETED` broadcast receiver
|
||||
2. Registering a `BOOT_COMPLETED` broadcast receiver (a `LOCKED_BOOT_COMPLETED` / `directBootAware` receiver runs before first unlock and can only read device-protected storage; the plugin's storage is credential-encrypted, so it does not use one)
|
||||
3. Rescheduling alarms from storage after boot completes
|
||||
|
||||
**Required Permission**: `RECEIVE_BOOT_COMPLETED`
|
||||
|
||||
@@ -725,9 +725,10 @@ The plugin **MUST NOT** support or guarantee the following behaviors:
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<!-- Do not add android:directBootAware or LOCKED_BOOT_COMPLETED: BootReceiver reads
|
||||
credential-encrypted storage, which is unavailable before the user's first unlock. -->
|
||||
|
||||
<receiver
|
||||
android:name="org.timesafari.dailynotification.DailyNotificationReceiver"
|
||||
|
||||
@@ -238,6 +238,23 @@ public class MyApplication extends Application {
|
||||
}
|
||||
```
|
||||
|
||||
**Constructor must not touch storage.** `Application.onCreate` runs whenever the process starts, including when a direct-boot-aware component (for example Firebase Messaging) starts it after a reboot and before the user's first unlock. SharedPreferences, databases, and files default to credential-encrypted storage, and opening them then throws `IllegalStateException: ... not available until after user ... is unlocked`, crashing the app. Keep the fetcher's constructor free of storage access and open storage lazily on first use (in `configure()` or `fetchContent()`, which run only after unlock):
|
||||
|
||||
```java
|
||||
public class MyNativeFetcher implements NativeNotificationContentFetcher {
|
||||
private SharedPreferences prefs; // opened on first use, never in the constructor
|
||||
|
||||
private SharedPreferences prefs(Context context) {
|
||||
if (prefs == null) {
|
||||
prefs = context.getSharedPreferences("my_fetcher", Context.MODE_PRIVATE);
|
||||
}
|
||||
return prefs;
|
||||
}
|
||||
|
||||
// configure(...) and fetchContent(...) call prefs(context) when they need it
|
||||
}
|
||||
```
|
||||
|
||||
**AndroidManifest.xml**:
|
||||
```xml
|
||||
<application android:name=".MyApplication">
|
||||
|
||||
@@ -114,7 +114,7 @@ We are trying to align **plugin promises** with **real platform capabilities and
|
||||
- `RECEIVE_BOOT_COMPLETED` permission
|
||||
- `SCHEDULE_EXACT_ALARM` permission
|
||||
- Any `BroadcastReceiver` declarations for:
|
||||
- `BOOT_COMPLETED` / `LOCKED_BOOT_COMPLETED`
|
||||
- `BOOT_COMPLETED` (not `LOCKED_BOOT_COMPLETED`: the plugin's receiver needs credential-encrypted storage)
|
||||
- Custom alarm intent actions
|
||||
- Check test app manifests:
|
||||
- `test-apps/android-test-app/app/src/main/AndroidManifest.xml`
|
||||
|
||||
@@ -310,9 +310,10 @@ The plugin **must**:
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<!-- Do not add android:directBootAware or LOCKED_BOOT_COMPLETED: BootReceiver reads
|
||||
credential-encrypted storage, which is unavailable before the user's first unlock. -->
|
||||
|
||||
<receiver
|
||||
android:name="org.timesafari.dailynotification.DailyNotificationReceiver"
|
||||
|
||||
@@ -56,7 +56,10 @@ Android wipes all alarms on reboot, but **you may recreate them**.
|
||||
**Directive:**
|
||||
|
||||
1. Persist all alarms in storage (Room DB or SharedPreferences).
|
||||
2. Add a `BOOT_COMPLETED` / `LOCKED_BOOT_COMPLETED` broadcast receiver.
|
||||
2. Add a `BOOT_COMPLETED` broadcast receiver. Do not make it `directBootAware` or
|
||||
register `LOCKED_BOOT_COMPLETED` unless its storage is device-protected: Room and
|
||||
SharedPreferences default to credential-encrypted storage, which throws
|
||||
`IllegalStateException` until the user's first unlock after reboot.
|
||||
3. On boot, load all enabled alarms and reschedule them using AlarmManager.
|
||||
|
||||
**Permissions required:**
|
||||
|
||||
@@ -6,55 +6,37 @@
|
||||
|
||||
## 🎯 **Overview**
|
||||
|
||||
This guide provides comprehensive testing procedures for the **fixed BootReceiver** that now properly handles Direct Boot and Android 10+ requirements. The BootReceiver works alongside the app startup recovery for maximum reliability.
|
||||
This guide covers testing `BootReceiver`, which re-arms notification alarms after a device reboot or app update. It works alongside the recovery that runs at app startup.
|
||||
|
||||
## 🔧 **What Was Fixed**
|
||||
## 🔧 **Receiver Setup**
|
||||
|
||||
### **1. AndroidManifest.xml Updates**
|
||||
### **1. AndroidManifest.xml**
|
||||
```xml
|
||||
<receiver
|
||||
android:name="org.timesafari.dailynotification.BootReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
android:directBootAware="true">
|
||||
android:exported="true">
|
||||
<intent-filter android:priority="1000">
|
||||
<!-- Delivered very early after reboot (before unlock) -->
|
||||
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
|
||||
<!-- Delivered after the user unlocks / credential-encrypted storage is available -->
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<!-- Delivered after app update; great for rescheduling alarms without reboot -->
|
||||
<!-- Delivered after app update; reschedules alarms without a reboot -->
|
||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
```
|
||||
|
||||
**Key Changes:**
|
||||
- ✅ Added `android:exported="true"` (required for API 31+)
|
||||
- ✅ Added `android:directBootAware="true"` (handles Direct Boot)
|
||||
- ✅ Added `LOCKED_BOOT_COMPLETED` (early boot recovery)
|
||||
- ✅ Removed `PACKAGE_REPLACED` (not needed for our use case)
|
||||
**Key points:**
|
||||
- `android:exported="true"` is required for API 31+ receivers with intent filters.
|
||||
- The receiver is **not direct-boot capable**: do not add `android:directBootAware="true"` or `LOCKED_BOOT_COMPLETED`. Recovery reads the plugin's Room database and SharedPreferences, which live in credential-encrypted (CE) storage. CE storage is unavailable between reboot and the user's first unlock, and touching it throws `IllegalStateException: SharedPreferences in credential encrypted storage are not available until after user (id 0) is unlocked`, killing the process. `BOOT_COMPLETED` is delivered right after first unlock.
|
||||
- If a manifest declares the locked action anyway, `BootReceiver` logs `Ignoring locked boot` and returns. It also returns without work whenever `UserManagerCompat.isUserUnlocked()` is false.
|
||||
- An alarm that comes due between reboot and first unlock does not fire then. Recovery after unlock marks it missed and schedules its next occurrence.
|
||||
|
||||
### **2. BootReceiver Implementation Updates**
|
||||
```java
|
||||
// Now handles three boot events:
|
||||
case ACTION_LOCKED_BOOT_COMPLETED:
|
||||
handleLockedBootCompleted(context);
|
||||
break;
|
||||
|
||||
case ACTION_BOOT_COMPLETED:
|
||||
handleBootCompleted(context);
|
||||
break;
|
||||
|
||||
case ACTION_MY_PACKAGE_REPLACED:
|
||||
handlePackageReplaced(context, intent);
|
||||
break;
|
||||
```
|
||||
Rejected: true direct-boot support (moving schedules and recovery state to device-protected storage). The content fetch needs CE-stored credentials, so it could not run before unlock anyway.
|
||||
|
||||
**Key Features:**
|
||||
- ✅ **Direct Boot Safe**: Uses device protected storage context
|
||||
- ✅ **Early Recovery**: Handles locked boot completion
|
||||
- ✅ **Full Recovery**: Handles unlocked boot completion
|
||||
- ✅ **Update Recovery**: Handles app updates
|
||||
### **2. BootReceiver Behavior**
|
||||
- `BOOT_COMPLETED`: records `last_boot_at` in the `dailynotification_recovery` SharedPreferences, then runs `ReactivationManager.runBootRecovery`.
|
||||
- `MY_PACKAGE_REPLACED`: runs `ReactivationManager.runBootRecovery` without setting the boot flag.
|
||||
- `LOCKED_BOOT_COMPLETED`, or any action while the user is locked: logged and ignored.
|
||||
|
||||
### **3. Exact Alarm Permission Handling**
|
||||
```java
|
||||
@@ -75,27 +57,16 @@ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
|
||||
### **Test 1: Boot Receiver Registration**
|
||||
|
||||
**Objective**: Verify BootReceiver is properly registered with all required actions
|
||||
**Objective**: Verify BootReceiver is registered with the required actions
|
||||
|
||||
**Steps**:
|
||||
```bash
|
||||
# Check BootReceiver registration
|
||||
adb shell "dumpsys package org.timesafari.dailynotification | grep -A10 -B5 BootReceiver"
|
||||
```
|
||||
|
||||
**Expected Output**:
|
||||
```
|
||||
android.intent.action.LOCKED_BOOT_COMPLETED:
|
||||
a440fcf org.timesafari.dailynotification/.BootReceiver filter 4e5fd5c
|
||||
Action: "android.intent.action.LOCKED_BOOT_COMPLETED"
|
||||
Action: "android.intent.action.BOOT_COMPLETED"
|
||||
Action: "android.intent.action.MY_PACKAGE_REPLACED"
|
||||
mPriority=1000, mOrder=0, mHasStaticPartialTypes=false, mHasDynamicPartialTypes=false
|
||||
```
|
||||
|
||||
**Success Criteria**:
|
||||
- ✅ BootReceiver is registered
|
||||
- ✅ All three actions are present
|
||||
- ✅ BootReceiver is registered for `BOOT_COMPLETED` and `MY_PACKAGE_REPLACED`
|
||||
- ✅ No `LOCKED_BOOT_COMPLETED` filter and no `directBootAware` flag
|
||||
- ✅ Priority is set to 1000
|
||||
- ✅ Component is enabled
|
||||
|
||||
@@ -111,31 +82,23 @@ adb shell am start -n org.timesafari.dailynotification/.MainActivity
|
||||
|
||||
# 2. Verify initial scheduling
|
||||
adb shell "dumpsys alarm | grep timesafari"
|
||||
# Should show scheduled alarm
|
||||
|
||||
# 3. Perform REAL reboot (not emulator soft restart)
|
||||
# 3. Reboot, wait for boot, unlock
|
||||
adb reboot
|
||||
adb wait-for-device
|
||||
|
||||
# 4. Wait for full boot completion (2-3 minutes)
|
||||
# Wait for boot animation to complete
|
||||
# Wait for home screen to appear
|
||||
|
||||
# 5. Check BootReceiver logs
|
||||
adb logcat -d | grep -i "bootreceiver" | tail -10
|
||||
# 4. Check recovery logs
|
||||
adb logcat -d | grep -E "DNP-BOOT|DNP-REACTIVATION" | tail -10
|
||||
```
|
||||
|
||||
**Expected Log Messages**:
|
||||
```
|
||||
BootReceiver: Received broadcast: android.intent.action.LOCKED_BOOT_COMPLETED
|
||||
BootReceiver: Locked boot completed - preparing for recovery
|
||||
BootReceiver: Received broadcast: android.intent.action.BOOT_COMPLETED
|
||||
BootReceiver: Device boot completed - restoring notifications
|
||||
BootReceiver: Found X notifications to recover
|
||||
BootReceiver: Notification recovery completed: X/X recovered
|
||||
DNP-BOOT: Boot completed, setting boot flag and starting recovery
|
||||
DNP-REACTIVATION: Starting boot recovery
|
||||
DNP-REACTIVATION: Boot recovery complete: missed=0, rescheduled=1, verified=0, errors=0
|
||||
```
|
||||
|
||||
**Success Criteria**:
|
||||
- ✅ `LOCKED_BOOT_COMPLETED` is received
|
||||
- ✅ `BOOT_COMPLETED` is received
|
||||
- ✅ Recovery process completes successfully
|
||||
- ✅ Alarms are restored
|
||||
@@ -158,16 +121,14 @@ cd android && ./gradlew assembleDebug
|
||||
adb install -r app/build/outputs/apk/debug/app-debug.apk
|
||||
|
||||
# 4. Check recovery logs
|
||||
adb logcat -d | grep -i "bootreceiver\|recovery" | tail -10
|
||||
adb logcat -d | grep -E "DNP-BOOT|DNP-REACTIVATION" | tail -10
|
||||
```
|
||||
|
||||
**Expected Log Messages**:
|
||||
```
|
||||
BootReceiver: Received broadcast: android.intent.action.MY_PACKAGE_REPLACED
|
||||
BootReceiver: Package replaced - restoring notifications
|
||||
BootReceiver: Device boot completed - restoring notifications
|
||||
BootReceiver: Found X notifications to recover
|
||||
BootReceiver: Notification recovery completed: X/X recovered
|
||||
DNP-BOOT: Package replaced, running recovery without setting boot flag
|
||||
DNP-REACTIVATION: Starting boot recovery
|
||||
DNP-REACTIVATION: Boot recovery complete: missed=0, rescheduled=1, verified=0, errors=0
|
||||
```
|
||||
|
||||
**Success Criteria**:
|
||||
@@ -175,34 +136,39 @@ BootReceiver: Notification recovery completed: X/X recovered
|
||||
- ✅ Recovery process completes successfully
|
||||
- ✅ Alarms are restored after update
|
||||
|
||||
### **Test 4: Direct Boot Compatibility Test**
|
||||
### **Test 4: Locked Boot Safety Test**
|
||||
|
||||
**Objective**: Verify Direct Boot handling works correctly
|
||||
**Objective**: Verify nothing crashes between reboot and first unlock, and recovery runs after unlock
|
||||
|
||||
**Steps**:
|
||||
```bash
|
||||
# 1. Schedule notification
|
||||
adb shell am start -n org.timesafari.dailynotification/.MainActivity
|
||||
# Tap "Test Notification" (5 minutes from now)
|
||||
# 1. Schedule a notification, then set a lock-screen PIN
|
||||
adb shell locksettings set-pin 1234
|
||||
|
||||
# 2. Reboot device
|
||||
# 2. Reboot
|
||||
adb reboot
|
||||
adb wait-for-device
|
||||
|
||||
# 3. Check logs for Direct Boot handling
|
||||
adb logcat -d | grep -i "locked.*boot\|direct.*boot" | tail -5
|
||||
```
|
||||
# 3. BEFORE unlocking, check for crashes
|
||||
adb logcat -d -b crash,main | grep -E "FATAL|DNP-BOOT|credential encrypted"
|
||||
|
||||
**Expected Log Messages**:
|
||||
```
|
||||
BootReceiver: Received broadcast: android.intent.action.LOCKED_BOOT_COMPLETED
|
||||
BootReceiver: Locked boot completed - preparing for recovery
|
||||
BootReceiver: Locked boot completed - ready for full recovery on unlock
|
||||
# 4. Unlock
|
||||
adb shell input keyevent 82
|
||||
adb shell input text 1234
|
||||
adb shell input keyevent 66
|
||||
|
||||
# 5. Check recovery and alarms
|
||||
adb logcat -d | grep -E "DNP-BOOT|DNP-REACTIVATION" | tail -5
|
||||
adb shell "dumpsys alarm | grep timesafari"
|
||||
|
||||
# 6. Clear the PIN
|
||||
adb shell locksettings clear --old 1234
|
||||
```
|
||||
|
||||
**Success Criteria**:
|
||||
- ✅ `LOCKED_BOOT_COMPLETED` is handled
|
||||
- ✅ Direct Boot context is used
|
||||
- ✅ No errors during locked boot phase
|
||||
- ✅ No `FATAL EXCEPTION` and no `credential encrypted` error for the app before unlock
|
||||
- ✅ Either no app process before unlock, or `DNP-BOOT: Ignoring locked boot` (manifests that declare the locked action anyway)
|
||||
- ✅ After unlock, `DNP-BOOT` reports boot recovery and `dumpsys alarm` lists the rescheduled alarm
|
||||
|
||||
### **Test 5: Exact Alarm Permission Test**
|
||||
|
||||
@@ -243,7 +209,7 @@ adb shell "dumpsys package org.timesafari.dailynotification | grep -A5 -B5 permi
|
||||
### **Monitor Boot Events**
|
||||
```bash
|
||||
# Real-time boot monitoring
|
||||
adb logcat | grep -i "bootreceiver\|recovery"
|
||||
adb logcat | grep -E "DNP-BOOT|DNP-REACTIVATION"
|
||||
|
||||
# Check boot completion
|
||||
adb shell getprop sys.boot_completed
|
||||
@@ -282,17 +248,16 @@ adb shell "pm list packages -d | grep timesafari"
|
||||
adb shell "dumpsys package org.timesafari.dailynotification | grep RECEIVE_BOOT_COMPLETED"
|
||||
```
|
||||
|
||||
### **Issue 2: Direct Boot Errors**
|
||||
### **Issue 2: Crash After Reboot Before Unlock**
|
||||
|
||||
**Symptoms**: Errors during locked boot completion
|
||||
**Symptoms**: `IllegalStateException: SharedPreferences in credential encrypted storage are not available until after user (id 0) is unlocked`
|
||||
**Solutions**:
|
||||
```bash
|
||||
# Check Direct Boot compatibility
|
||||
adb shell "dumpsys package org.timesafari.dailynotification | grep directBootAware"
|
||||
|
||||
# Check device protected storage
|
||||
adb shell "ls -la /data/user_de/0/org.timesafari.dailynotification/"
|
||||
# The receiver must not be direct-boot aware; this should print nothing
|
||||
adb shell "dumpsys package org.timesafari.dailynotification | grep -i directBootAware"
|
||||
```
|
||||
- Remove `android:directBootAware="true"` and `LOCKED_BOOT_COMPLETED` from the BootReceiver declaration.
|
||||
- If the stack trace points at `Application.onCreate` (for example a native fetcher constructor), move SharedPreferences, database, and file access out of `onCreate` and constructors into first use. Direct-boot-aware library components (such as Firebase Messaging) start the process before unlock, which runs `Application.onCreate`.
|
||||
|
||||
### **Issue 3: Exact Alarm Permission Denied**
|
||||
|
||||
@@ -317,7 +282,6 @@ adb shell am start -a android.settings.REQUEST_SCHEDULE_EXACT_ALARM --es android
|
||||
### **Reliability Metrics**
|
||||
- **Boot Event Detection**: 100% for supported Android versions
|
||||
- **Recovery Success Rate**: 100% for valid notifications
|
||||
- **Direct Boot Compatibility**: 100% on Android 7+ devices
|
||||
- **App Update Recovery**: 100% success rate
|
||||
|
||||
## 🎯 **Best Practices**
|
||||
@@ -334,21 +298,12 @@ adb shell am start -a android.settings.REQUEST_SCHEDULE_EXACT_ALARM --es android
|
||||
- **Handle edge cases** gracefully (corrupted data, storage issues)
|
||||
- **Provide fallback mechanisms** (app startup recovery)
|
||||
|
||||
## 🏆 **Conclusion**
|
||||
## 🏆 **Summary**
|
||||
|
||||
The **fixed BootReceiver** now provides:
|
||||
`BootReceiver` provides:
|
||||
|
||||
- ✅ **Universal Compatibility**: Works on all Android versions
|
||||
- ✅ **Direct Boot Support**: Handles locked boot completion
|
||||
- ✅ **Reboot Recovery**: Restores alarms on `BOOT_COMPLETED`, right after first unlock
|
||||
- ✅ **Locked-Boot Safety**: Ignores broadcasts that arrive before unlock instead of touching CE storage
|
||||
- ✅ **App Update Recovery**: Restores alarms after updates
|
||||
- ✅ **Exact Alarm Handling**: Proper permission management
|
||||
- ✅ **Comprehensive Logging**: Full visibility into recovery process
|
||||
|
||||
**Combined with app startup recovery, this creates a rock-solid notification system that survives reboots, updates, and OEM quirks!** 🚀
|
||||
|
||||
## 📚 **Related Documentation**
|
||||
|
||||
- [App Startup Recovery Solution](app-startup-recovery-solution.md)
|
||||
- [Reboot Testing Procedures](reboot-testing-procedure.md)
|
||||
- [Notification Testing Guide](notification-testing-procedures.md)
|
||||
- [Testing Quick Reference](testing-quick-reference.md)
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@timesafari/daily-notification-plugin",
|
||||
"version": "5.0.0",
|
||||
"version": "5.0.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@timesafari/daily-notification-plugin",
|
||||
"version": "5.0.0",
|
||||
"version": "5.0.1",
|
||||
"license": "MIT",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@timesafari/daily-notification-plugin",
|
||||
"version": "5.0.0",
|
||||
"version": "5.0.1",
|
||||
"description": "TimeSafari Daily Notification Plugin - Enterprise-grade daily notification functionality with dual scheduling, callback support, TTL-at-fire logic, and comprehensive observability across Mobile (Capacitor) and Desktop (Electron) platforms",
|
||||
"main": "dist/plugin.js",
|
||||
"module": "dist/esm/index.js",
|
||||
|
||||
@@ -42,14 +42,13 @@
|
||||
android:exported="false">
|
||||
</receiver>
|
||||
|
||||
<!-- Not directBootAware: BootReceiver reads credential-encrypted storage, unavailable
|
||||
before first unlock. BOOT_COMPLETED arrives right after first unlock. -->
|
||||
<receiver
|
||||
android:name="org.timesafari.dailynotification.BootReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
android:directBootAware="true">
|
||||
android:exported="true">
|
||||
<intent-filter android:priority="1000">
|
||||
<!-- Delivered very early after reboot (before unlock) -->
|
||||
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
|
||||
<!-- Delivered after the user unlocks / credential-encrypted storage is available -->
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<!-- Delivered after app update; great for rescheduling alarms without reboot -->
|
||||
|
||||
@@ -288,9 +288,8 @@ test2_boot_past_alarms() {
|
||||
echo "$logs"
|
||||
|
||||
local missed rescheduled verified errors scenario
|
||||
# For TEST 2, we need the FIRST entry (which has missed count) not the last
|
||||
# Boot recovery runs twice (LOCKED_BOOT_COMPLETED and BOOT_COMPLETED)
|
||||
# First run marks missed alarms, second run only reschedules (missed=0)
|
||||
# For TEST 2, take the FIRST entry (which has the missed count), not the last:
|
||||
# a later recovery run (e.g. app launch) only reschedules and reports missed=0
|
||||
missed="$(echo "$logs" | grep -E "missed=" | sed -E "s/.*missed=([0-9]+).*/\1/" | head -n1 || echo "0")"
|
||||
rescheduled="$(extract_field_from_logs "$logs" "rescheduled")"
|
||||
verified="$(extract_field_from_logs "$logs" "verified")"
|
||||
|
||||
@@ -43,13 +43,13 @@
|
||||
android:exported="false">
|
||||
</receiver>
|
||||
|
||||
<!-- Not directBootAware: BootReceiver reads credential-encrypted storage, unavailable
|
||||
before first unlock. BOOT_COMPLETED arrives right after first unlock. -->
|
||||
<receiver
|
||||
android:name="org.timesafari.dailynotification.BootReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
android:directBootAware="true">
|
||||
android:exported="true">
|
||||
<intent-filter android:priority="1000">
|
||||
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||
<action android:name="android.intent.action.PACKAGE_REPLACED" />
|
||||
|
||||
Reference in New Issue
Block a user