Files
crowd-funder-for-time-pwa/scripts/test-notification-receiver.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

105 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# test-notification-receiver.sh
# Author: Matthew Raymer
# Description: Test script to manually trigger the DailyNotificationReceiver
# to verify it's working correctly
# 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!"
echo ""
echo "Please ensure one of the following:"
echo " 1. adb is in your PATH"
echo " 2. ANDROID_HOME is set and points to Android SDK"
echo " 3. Android SDK is installed at:"
echo " - $HOME/Library/Android/sdk (macOS default)"
echo " - $HOME/Android/Sdk"
echo ""
echo "You can find your SDK location in Android Studio:"
echo " Preferences > Appearance & Behavior > System Settings > Android SDK"
exit 1
fi
echo "Testing DailyNotificationReceiver..."
echo "Using adb: $ADB_CMD"
echo ""
# Get the package name
PACKAGE_NAME="app.timesafari.app"
INTENT_ACTION="com.timesafari.daily.NOTIFICATION"
echo "Package: $PACKAGE_NAME"
echo "Intent Action: $INTENT_ACTION"
echo ""
# Check if device is connected
if ! "$ADB_CMD" devices | grep -q $'\tdevice'; then
echo "Error: No Android device/emulator connected!"
echo ""
echo "Please:"
echo " 1. Start an Android emulator in Android Studio, or"
echo " 2. Connect a physical device via USB"
echo ""
echo "Then run: $ADB_CMD devices"
exit 1
fi
# Test 1: Send broadcast intent to trigger receiver (without ID - simulates current bug)
echo "Test 1: Sending broadcast intent to DailyNotificationReceiver (without ID)..."
"$ADB_CMD" shell am broadcast -a "$INTENT_ACTION" -n "$PACKAGE_NAME/com.timesafari.dailynotification.DailyNotificationReceiver"
echo ""
echo "Test 2: Sending broadcast intent WITH ID (to test if receiver works with ID)..."
"$ADB_CMD" shell am broadcast -a "$INTENT_ACTION" -n "$PACKAGE_NAME/com.timesafari.dailynotification.DailyNotificationReceiver" --es "id" "timesafari_daily_reminder"
echo ""
echo "Check logcat for 'DN|RECEIVE_START' to see if receiver was triggered"
echo "Test 1 should show 'missing_id' error"
echo "Test 2 should work correctly (if plugin supports it)"
echo ""
echo "To monitor logs, run:"
echo " $ADB_CMD logcat | grep -E 'DN|RECEIVE_START|DailyNotification'"