Files
crowd-funder-for-time-pwa/scripts/check-alarm-logs.sh
Matthew a71bd09b78 docs: Add investigation documentation and test scripts for notification receiver issue
After changing DailyNotificationReceiver to exported="true", testing revealed
that while the receiver works when manually triggered, AlarmManager broadcasts
are not reaching it when alarms fire automatically. Alarms are scheduled and
fire correctly, but the PendingIntent broadcast does not trigger the receiver.

Added comprehensive documentation and diagnostic tools:

1. Documentation (doc/daily-notification-plugin-android-receiver-issue.md):
   - Complete problem analysis with evidence from logs and dumpsys
   - Root cause hypotheses focusing on PendingIntent creation in plugin
   - Testing steps and expected behavior after fix
   - Technical details for plugin maintainer reference

2. Test scripts:
   - scripts/test-notification-receiver.sh: Manually trigger receiver to
     verify it works and test with/without ID parameter
   - scripts/check-alarm-logs.sh: Check logs and verify alarm scheduling

Findings:
- Receiver registration is correct (exported="true" works for manual tests)
- Alarms schedule and fire successfully (confirmed via dumpsys alarm)
- Issue is in plugin's PendingIntent creation - broadcasts don't reach receiver
- Additional issue: Intent extras missing scheduleId (causes "missing_id" error)

The exported="true" change was necessary and correct. The remaining issue
requires a fix in the plugin's PendingIntent creation code to explicitly
set the component and include the scheduleId in Intent extras.

This documentation is intended for use when working on the plugin project
to fix the PendingIntent delivery issue.
2026-02-05 03:07:18 -08:00

71 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# check-alarm-logs.sh
# Author: Matthew Raymer
# Description: Check logs around a specific time to see if alarm fired
# Function to find adb command
find_adb() {
# Check if adb is in PATH
if command -v adb >/dev/null 2>&1; then
echo "adb"
return 0
fi
# Check for ANDROID_HOME
if [ -n "$ANDROID_HOME" ] && [ -x "$ANDROID_HOME/platform-tools/adb" ]; then
echo "$ANDROID_HOME/platform-tools/adb"
return 0
fi
# Check for local.properties
local local_props="android/local.properties"
if [ -f "$local_props" ]; then
local sdk_dir=$(grep "^sdk.dir=" "$local_props" 2>/dev/null | cut -d'=' -f2 | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | sed "s|^file://||")
if [ -n "$sdk_dir" ] && [ -x "$sdk_dir/platform-tools/adb" ]; then
echo "$sdk_dir/platform-tools/adb"
return 0
fi
fi
# Try common macOS locations
local common_locations=(
"$HOME/Library/Android/sdk"
"$HOME/Android/Sdk"
"$HOME/.android/sdk"
)
for sdk_path in "${common_locations[@]}"; do
if [ -x "$sdk_path/platform-tools/adb" ]; then
echo "$sdk_path/platform-tools/adb"
return 0
fi
done
# Not found
return 1
}
# Find adb
ADB_CMD=$(find_adb)
if [ $? -ne 0 ] || [ -z "$ADB_CMD" ]; then
echo "Error: adb command not found!"
exit 1
fi
echo "Checking logs for alarm activity..."
echo "Looking for: DN|RECEIVE_START, AlarmManager, DailyNotification, timesafari"
echo ""
# Check recent logs for alarm-related activity
echo "=== Recent alarm/receiver logs ==="
"$ADB_CMD" logcat -d | grep -iE "DN|RECEIVE_START|RECEIVE_ERR|alarm.*timesafari|daily.*notification|com\.timesafari\.daily" | tail -20
echo ""
echo "=== All AlarmManager activity (last 50 lines) ==="
"$ADB_CMD" logcat -d | grep -i "AlarmManager" | tail -50
echo ""
echo "=== Check if alarm is still scheduled ==="
echo "Run this to see all scheduled alarms:"
echo " $ADB_CMD shell dumpsys alarm | grep -A 5 timesafari"