fix: refresh UI on app resume after force-stop recovery

- Add visibility change handler to refresh UI when app becomes visible
- Check for recent notifications and show indicator if notification was received
- Update lastKnownNextNotificationTime on app resume
- Auto-enable fire verification in Test 1 if alarm is within 5 minutes

Previously, after force-stop recovery:
- UI only refreshed on page load (which doesn't fire again after force-stop)
- Notification received indicator didn't show if notification fired while app was stopped
- Test 1 didn't verify that restored alarms actually fire

The fix:
- Listen for visibilitychange event to detect app resume
- Refresh all status displays (plugin, permissions, channel) when app becomes visible
- Check for notifications received in last 2 minutes and show indicator
- Wait 1 second after visibility change to allow recovery to complete
- Test 1 now automatically verifies restored alarms fire if within 5 minutes

This ensures the UI stays in sync after force-stop recovery and shows
notification indicators for notifications that fired while the app was stopped.
This commit is contained in:
Matthew Raymer
2025-12-30 08:58:11 +00:00
parent 4c1281754e
commit d913f03e23
2 changed files with 97 additions and 28 deletions

View File

@@ -1221,43 +1221,62 @@ main() {
evidence_block "test1_force_stop_recovery"
# Optional: Verify alarm fires (controlled by VERIFY_FIRE flag)
if [ "${VERIFY_FIRE}" = "true" ] && [ -n "${alarm_trigger_ms}" ] && [ "${goto_test1_end}" != "true" ]; then
substep "Step 8: Verify alarm fires at scheduled time (optional)"
# Verify alarm fires if it's scheduled within reasonable time window (< 5 minutes)
# This ensures restored alarms actually work, not just that they were restored
if [ -n "${alarm_trigger_ms}" ] && [ "${goto_test1_end}" != "true" ]; then
local current_time_sec current_time_ms wait_ms wait_sec
current_time_sec=$(get_current_time)
current_time_ms=$((current_time_sec * 1000))
wait_ms=$((alarm_trigger_ms - current_time_ms))
if [ "${wait_ms}" -lt 0 ]; then
warn "Alarm time already passed (${wait_ms} ms ago); skipping fire verification"
else
wait_sec=$((wait_ms / 1000))
# Auto-enable fire verification if alarm is within 5 minutes (300 seconds)
# Or if VERIFY_FIRE is explicitly set to true
local should_verify_fire=false
if [ "${VERIFY_FIRE}" = "true" ]; then
should_verify_fire=true
elif [ "${wait_ms}" -gt 0 ] && [ "${wait_ms}" -lt 300000 ]; then
# Alarm is in the future and within 5 minutes - auto-verify
should_verify_fire=true
fi
if [ "${should_verify_fire}" = "true" ]; then
substep "Step 8: Verify restored alarm fires at scheduled time"
set_test_context "phase1" "phase1_test1" "p1_t1_s6"
# Clamp upper bound to prevent accidentally waiting 30+ minutes
if [ "${wait_sec}" -gt 600 ]; then
warn "Alarm is >10 minutes away (${wait_sec}s); skipping fire verification"
info "To test fire verification, schedule alarm closer to current time"
if [ "${wait_ms}" -lt 0 ]; then
step_warn "p1_t1_s6" "Alarm time already passed"
warn "Alarm time already passed (${wait_ms} ms ago); cannot verify fire"
else
info "Alarm scheduled for: ${alarm_readable}"
info "Current time: $(date -d "@${current_time_sec}" 2>/dev/null || echo "${current_time_sec}")"
info "Waiting ~${wait_sec} seconds for alarm to fire..."
wait_sec=$((wait_ms / 1000))
clear_logs
sleep ${wait_sec}
sleep 2
info "Checking logs for fired alarm..."
local alarm_fired
alarm_fired="$($ADB_BIN logcat -d | grep -E "DNP-RECEIVE|DNP-NOTIFY|DNP-WORK|Alarm fired|Notification displayed" | tail -10)"
if [ -n "${alarm_fired}" ]; then
ok "Alarm fired! Logs:"
echo "${alarm_fired}"
# Clamp upper bound to prevent accidentally waiting too long
if [ "${wait_sec}" -gt 600 ]; then
step_warn "p1_t1_s6" "Alarm too far in future"
warn "Alarm is >10 minutes away (${wait_sec}s); skipping fire verification"
info "To test fire verification, schedule alarm closer to current time"
else
warn "No alarm fire logs found"
info "Check notification tray manually or review recent logs"
step_start "p1_t1_s6" "Waiting for restored alarm to fire"
info "Restored alarm scheduled for: ${alarm_readable}"
info "Current time: $(date -d "@${current_time_sec}" 2>/dev/null || echo "${current_time_sec}")"
info "Waiting ~${wait_sec} seconds for restored alarm to fire..."
clear_logs
sleep ${wait_sec}
sleep 2
info "Checking logs for fired alarm..."
local alarm_fired
alarm_fired="$($ADB_BIN logcat -d | grep -E "DNP-RECEIVE|DNP-NOTIFY|DNP-WORK|Alarm fired|Notification displayed" | tail -10)"
if [ -n "${alarm_fired}" ]; then
step_pass "p1_t1_s6" "Restored alarm fired successfully"
ok "✅ Restored alarm fired! Logs:"
echo "${alarm_fired}"
else
step_fail "p1_t1_s6" "Restored alarm did not fire"
warn "⚠️ No alarm fire logs found - restored alarm may not have fired"
info "Check notification tray manually or review recent logs"
fi
fi
fi
fi