# Reboot Testing Steps for DailyNotification Plugin

## 🎯 **Objective**
Test that scheduled notifications survive device reboots and are properly restored by the BootReceiver.

## ⏰ **Extended Testing Time**
- **Notification Delay**: 5 minutes (instead of 1 minute)
- **More Realistic**: Allows time for proper testing and verification
- **Better for Reboot Testing**: Gives time to reboot and verify recovery

## 🔄 **Complete Reboot Testing Procedure**

### **Step 1: Schedule Notification**
```bash
# Launch app
adb shell am start -n org.timesafari.dailynotification/.MainActivity
```
- Tap **"Test Notification"** button
- Verify message: **"Notification scheduled for [time]! Check your notification bar in 5 minutes."**
- **Note the scheduled time** (5 minutes from now)

### **Step 2: Verify Initial Scheduling**
```bash
# Check scheduled alarms
adb shell "dumpsys alarm | grep timesafari"
```
- Should show scheduled alarm with correct timestamp
- Note the alarm details

### **Step 3: Reboot Device**
```bash
# Reboot device
adb reboot
```
- **Wait 2-3 minutes** for device to fully boot
- Wait for boot animation to complete
- Wait for home screen to appear

### **Step 4: Verify Boot Recovery**
```bash
# Check recovery logs
adb logcat -d | grep -i "bootreceiver\|recovery"
```
**Look for these log messages:**
- `"Device boot completed - restoring notifications"`
- `"Found X notifications to recover"`
- `"Notification recovery completed: X/X recovered"`

### **Step 5: Verify Alarm Restoration**
```bash
# Check if alarm was restored
adb shell "dumpsys alarm | grep timesafari"
```
- Should show the same scheduled alarm as before reboot
- Alarm timestamp should match original schedule

### **Step 6: Wait for Notification**
- **Wait for the originally scheduled time** (5 minutes from when you scheduled it)
- **Check notification panel** for the test notification
- **Verify notification appears** with correct content

## 🧪 **Automated Reboot Test**

### **Run the Reboot Test Script:**
```bash
# Run automated reboot test
./scripts/reboot-test.sh
```

**What the script does:**
1. ✅ Checks boot receiver registration
2. 📅 Prompts you to schedule notification
3. 🔍 Verifies initial scheduling
4. 🔄 Reboots device automatically
5. ⏳ Waits for boot completion
6. 🔍 Checks recovery logs
7. ⏰ Verifies alarm restoration
8. 🎉 Reports success/failure

## 🔍 **Key Log Messages to Look For**

### **Successful Recovery:**
```
BootReceiver: Device boot completed - restoring notifications
BootReceiver: Found X notifications to recover
BootReceiver: Recovered notification: [notification-id]
BootReceiver: Notification recovery completed: X/X recovered
```

### **Recovery Issues:**
```
BootReceiver: No notifications to recover
BootReceiver: Failed to recover notification: [notification-id]
BootReceiver: Error during boot recovery
```

## 🚨 **Troubleshooting Reboot Recovery**

### **Issue 1: Boot Receiver Not Triggered**
**Symptoms**: No recovery logs after reboot
**Solutions**:
```bash
# Check boot receiver registration
adb shell "dumpsys package org.timesafari.dailynotification | grep -A10 -B10 receiver"

# Check BOOT_COMPLETED permission
adb shell "dumpsys package org.timesafari.dailynotification | grep permission"
```

### **Issue 2: Recovery Fails**
**Symptoms**: Recovery logs show errors
**Solutions**:
```bash
# Check notification storage
adb shell "run-as org.timesafari.dailynotification ls -la /data/data/org.timesafari.dailynotification/shared_prefs/"

# Check alarm permissions
adb shell "dumpsys alarm | grep SCHEDULE_EXACT_ALARM"
```

### **Issue 3: Alarms Not Restored**
**Symptoms**: No alarms after recovery
**Solutions**:
```bash
# Check exact alarm permissions
adb shell "dumpsys alarm | grep SCHEDULE_EXACT_ALARM"

# Check battery optimization
adb shell "dumpsys deviceidle | grep timesafari"
```

## 📊 **Success Criteria**

### ✅ **Test Passes When:**
- Boot receiver is triggered after reboot
- Recovery logs show successful restoration
- Alarms are rescheduled correctly
- Notification appears at the originally scheduled time
- All recovery log messages are present

### ❌ **Test Fails When:**
- Boot receiver is not triggered
- Recovery fails with errors
- Alarms are not restored
- Notification doesn't appear
- Recovery logs show failures

## 🎯 **Quick Test Commands**

### **One-Line Reboot Test:**
```bash
# Schedule notification, reboot, and verify
adb shell am start -n org.timesafari.dailynotification/.MainActivity && echo "Schedule notification, then:" && read -p "Press Enter to reboot..." && adb reboot && sleep 120 && adb logcat -d | grep -i "bootreceiver\|recovery"
```

### **Check Recovery Status:**
```bash
# Quick recovery check
adb logcat -d | grep -i "bootreceiver" | tail -10
```

### **Verify Alarms:**
```bash
# Quick alarm check
adb shell "dumpsys alarm | grep timesafari"
```

## 🔧 **Advanced Testing**

### **Test Multiple Reboots:**
```bash
# Test multiple reboot cycles
for i in {1..3}; do
    echo "Reboot test $i/3"
    ./scripts/reboot-test.sh
    sleep 60
done
```

### **Test with Different Notification Types:**
- Test with sound enabled/disabled
- Test with different priorities
- Test with different content
- Test with multiple notifications

### **Test Edge Cases:**
- Test with low battery
- Test with airplane mode
- Test with timezone changes
- Test with system updates

## 📱 **Production Considerations**

### **Real-World Scenarios:**
- Users rarely force-stop apps
- Device reboots are common (updates, crashes, etc.)
- App updates should preserve notifications
- Battery optimization can affect recovery

### **Best Practices:**
- Test on multiple Android versions
- Test on different OEMs
- Test with various battery optimization settings
- Test under different network conditions

## 🎉 **Expected Results**

After implementing the reboot recovery system:

1. **Notifications survive reboots** ✅
2. **Boot receiver activates automatically** ✅
3. **Recovery logs show success** ✅
4. **Alarms are properly restored** ✅
5. **Notifications appear at scheduled times** ✅

**The system is now robust and production-ready!** 🚀
