# PHASE 3 – EMULATOR TESTING **Boot-Time Recovery (Device Reboot / System Restart)** --- ## 1. Purpose Phase 3 verifies that the Daily Notification Plugin correctly: 1. Reconstructs **AlarmManager** alarms after a full device/emulator reboot. 2. Handles **past** scheduled times by marking them as missed and scheduling the next occurrence. 3. Handles **empty DB / no schedules** without misfiring recovery. 4. Performs **silent boot recovery** (recreate alarms) even when the app is never opened after reboot. This testing is driven by the script: ```bash test-apps/android-test-app/test-phase3.sh ``` --- ## 2. Prerequisites * Android emulator or device, e.g.: * Pixel 8 / API 34 (recommended baseline) * ADB available in `PATH` (or `ADB_BIN` exported) * Project with: * Daily Notification Plugin integrated * Test app at `test-apps/android-test-app` * Debug APK path: * `app/build/outputs/apk/debug/app-debug.apk` * Phase 1 and Phase 2 behaviors already implemented: * Cold start detection * Force-stop detection * Missed / rescheduled / verified / errors summary fields > ⚠️ **Important:** > This script will reboot the emulator multiple times. Each reboot may take 30–60 seconds. --- ## 3. How to Run From the `android-test-app` directory: ```bash cd test-apps/android-test-app chmod +x test-phase3.sh # first time only ./test-phase3.sh ``` The script will: 1. Run pre-flight checks (ADB / emulator readiness). 2. Build and install the debug APK. 3. Guide you through four tests: * **TEST 1:** Boot with Future Alarms * **TEST 2:** Boot with Past Alarms * **TEST 3:** Boot with No Schedules * **TEST 4:** Silent Boot Recovery (App Never Opened) 4. Parse and display `DNP-REACTIVATION` logs, including: * `scenario` * `missed` * `rescheduled` * `verified` * `errors` --- ## 4. Test Cases (Script-Driven Flow) ### 4.1 TEST 1 – Boot with Future Alarms **Goal:** Verify alarms are recreated on boot when schedules have **future run times**. **Script flow:** 1. **Launch app & check plugin status** * Script calls `launch_app`. * UI prompt: Confirm plugin status shows: * `⚙️ Plugin Settings: ✅ Configured` * `🔌 Native Fetcher: ✅ Configured` * If not, click **Configure Plugin**, wait until both show ✅, then continue. 2. **Schedule at least one future notification** * UI prompt: Click e.g. **Test Notification** to schedule a notification a few minutes in the future. 3. **Verify alarms are scheduled (pre-boot)** * Script calls `show_alarms` and `count_alarms`. * You should see at least one `RTC_WAKEUP` entry for `com.timesafari.dailynotification`. 4. **Reboot emulator** * Script calls `reboot_emulator`: * `adb reboot` * `adb wait-for-device` * Polls `getprop sys.boot_completed` until `1`. * You are warned that reboot will take 30–60 seconds. 5. **Collect boot recovery logs** * Script calls `get_recovery_logs`: ```bash adb logcat -d | grep "DNP-REACTIVATION" ``` * It parses: * `missed`, `rescheduled`, `verified`, `errors` * `scenario` via: * `Starting boot recovery`/`boot recovery` → `scenario=BOOT` * or `Detected scenario: ` 6. **Verify alarms were recreated (post-boot)** * Script calls `show_alarms` and `count_alarms` again. * Checks `scenario` and `rescheduled`. **Expected log patterns:** ```text DNP-REACTIVATION: Starting boot recovery DNP-REACTIVATION: Loaded schedules from DB DNP-REACTIVATION: Rescheduled alarm: daily_ for