Commit Graph

449 Commits

Author SHA1 Message Date
Jose Olarte III
0a2cbf24f7 fix(ios): correct next notification time and improve rollover UI refresh
- Fix getNextNotificationTime() to find earliest scheduled notification
  instead of using first request (pendingNotificationRequests doesn't
  guarantee order)
- Add comprehensive logging for rollover tracking with DNP-ROLLOVER
  prefix for Xcode console filtering
- Reset all notifications and rollover state when scheduling new
  notification via scheduleDailyNotification() to ensure clean test
  state
- Fix userInfo scope error in handleNotificationDelivery error handler
- Update test app UI to refresh status every 5-10 seconds and
  immediately after notification delivery to reflect rollover changes
- Add console logging in UI to debug getNotificationStatus() results

This ensures the UI correctly displays the next notification time after
rollover completes, and test notifications start with a clean slate.
2025-12-15 21:42:48 +08:00
Jose Olarte III
527c075941 fix(ios): improve test script reliability and pending notification detection
Fixed multiple issues in iOS test script and added logging for test compatibility:

Test Script Fixes:
- Fixed get_simulator_id() to correctly extract UUID from booted devices
- Fixed get_app_logs() to use log show (historical) instead of log stream (live) to avoid hanging
- Improved check_plugin_configured() with multiple detection methods (app container, app listing, data directory)
- Added ensure_plugin_configured() function matching Android pattern for consistent user interaction flow
- Fixed integer comparison error in booted device check (removed newlines from count)
- Removed 'local' keyword from variables in main script body (local can only be used in functions)
- Fixed APP_BUNDLE_ID to match actual bundle identifier

Pending Notification Detection:
- Improved get_pending_notifications() to parse pendingCount from plugin logs
- Added direct log query without restrictive predicate to catch plugin logs
- Added multiple fallback methods for detecting pending count

Plugin Logging Enhancement:
- Added explicit pendingCount logging in DailyNotificationScheduler after scheduling
- Uses both NSLog() and print() to ensure logs appear in system logs and Xcode console
- Matches Android's alarm count logging pattern for test script compatibility

This resolves script crashes and enables reliable detection of pending notifications
for automated testing.
2025-12-11 20:12:34 +08:00
Jose Olarte III
1bfd87a0e4 fix(ios): resolve build errors and add missing configureNativeFetcher method
Fixed Swift compilation errors preventing iOS build:
- Added explicit self capture [self] in closures in DailyNotificationReactivationManager
- Removed invalid BGTaskScheduler.shared.registeredTaskIdentifiers API call
- Fixed initialization order in DailyNotificationModel (verifyEntities after container init)

Added missing configureNativeFetcher method to iOS plugin:
- Implemented method matching Android functionality
- Stores configuration in UserDefaults for persistence
- Registered method in pluginMethods array
- Supports both jwtToken and jwtSecret parameters for compatibility

This resolves the runtime error "configureNativeFetcher is not a function"
that was preventing the test app from configuring the plugin.
2025-12-11 16:44:18 +08:00
Matthew
332dfbad75 feat(ios): enhance background task handlers and documentation
Enhance background task handlers with recovery logic and comprehensive
code documentation:

Background Task Handlers (Section 3.3):
- Enhance handleBackgroundFetch with recovery logic:
  - Verify scheduled notifications after fetch
  - Schedule next background task automatically
  - Improved expiration handling with graceful cleanup
- Enhance handleBackgroundNotify with recovery logic:
  - Verify scheduled notifications state
  - Prepare for next task scheduling
  - Improved expiration handling with graceful cleanup
- Add getNextScheduledNotificationTime() helper method
  - Wraps scheduler.getNextNotificationTime() with timeout
  - Used for automatic next task scheduling

Code Documentation (Section 10.1):
- Add comprehensive file-level documentation to ReactivationManager:
  - Purpose, features, architecture overview
  - Recovery scenarios supported
  - Error handling approach
  - Thread safety notes
  - Cross-references to requirements docs
- Add detailed method-level documentation:
  - performRecovery(): process, scenarios, error handling
  - detectScenario(): detection logic, error handling
  - performColdStartRecovery(): steps, return values
  - detectMissedNotifications(): criteria, error handling
  - verifyFutureNotifications(): verification process
  - rescheduleMissingNotification(): process, throws
  - handleTerminationRecovery(): comprehensive recovery
  - performBootRecovery(): boot recovery process
  - recordRecoveryHistory(): history recording
  - recordRecoveryFailure(): failure recording
  - detectBootScenario(): detection logic
  - updateLastLaunchTime(): storage details
  - verifyBGTaskRegistration(): diagnostic method
- Add @param, @return, @throws tags to all methods
- Document error handling behavior for all methods

Implementation Status (Section 10.2):
- Update ios/Plugin/README.md with current status:
  - Mark all completed features as 
  - Add new components (DAO classes, ReactivationManager)
  - Update version to 1.1.0
  - Add recovery scenarios supported
  - Update architecture overview
  - Add last updated date (2025-12-08)

Completes sections 3.3, 10.1, and 10.2 of iOS implementation checklist.
2025-12-09 19:09:07 -08:00
Matthew
3649e76c49 feat(ios): add error handling and integration tests
Implement comprehensive error handling and integration test suite:

Error Handling (Section 8):
- Add iOS-specific error codes to DailyNotificationErrorCodes:
  - NOTIFICATION_PERMISSION_DENIED
  - PENDING_NOTIFICATION_LIMIT_EXCEEDED
  - BG_TASK_NOT_REGISTERED
  - BG_TASK_EXECUTION_FAILED
  - BACKGROUND_REFRESH_DISABLED
- Add helper methods for iOS-specific error responses
- Enhance error handling in ReactivationManager:
  - Database errors handled gracefully (non-fatal)
  - Notification center errors handled gracefully (non-fatal)
  - Scheduling errors handled gracefully (non-fatal)
  - All errors logged, app continues normally
  - Partial results returned when operations fail
- Update plugin methods to use iOS-specific error codes:
  - getNotificationPermissionStatus uses NOTIFICATION_PERMISSION_DENIED

Integration Tests (Section 9.2):
- Add DailyNotificationRecoveryIntegrationTests:
  - Full recovery flow tests (cold start, termination)
  - Error handling tests (database, notification center, scheduling)
  - App stability tests (no crashes, concurrent operations)
  - Partial recovery tests
  - Timeout handling tests
- Test coverage:
  - 10 integration tests covering recovery scenarios
  - Error handling verification
  - App stability verification
  - Concurrent operation safety

Completes sections 8.1, 8.2, and 9.2 of iOS implementation checklist.
2025-12-09 02:46:13 -08:00
Matthew
12d8536588 feat(ios): enhance recovery logging and metrics recording
Implement comprehensive logging and observability for recovery operations:

- Add HistoryDAO for Core Data history recording
  - recordRecovery() method with execution time tracking
  - recordRecoveryFailure() method with detailed error info
  - Query helpers for history retrieval
- Enhance DailyNotificationReactivationManager logging:
  - Add execution time tracking (startTime/endTime)
  - Enhanced error logging with NSError details (domain, code, userInfo)
  - Comprehensive logging at each recovery step
  - Missed/future notification count logging
- Implement Core Data persistence for recovery metrics:
  - Recovery execution time
  - Missed notification count
  - Rescheduled notification count
  - Verified notification count
  - Error count
  - Diagnostic JSON with full recovery context
- Update recovery methods to record history:
  - Cold start recovery
  - Termination recovery
  - Boot recovery
  - All with timing and metrics

Completes section 7.1 (Recovery Logging) and 7.2 (Metrics Recording)
of iOS implementation checklist.
2025-12-09 02:37:27 -08:00
Matthew
a90d08c425 feat(ios): add Core Data DAO layer and unit tests
Implement comprehensive data access layer for Core Data entities:

- Add NotificationContentDAO, NotificationDeliveryDAO, and NotificationConfigDAO
  with full CRUD operations and query helpers
- Add DailyNotificationDataConversions utility for type conversions
  (Date ↔ Int64, Int ↔ Int32, JSON, optional strings)
- Update PersistenceController with entity verification and migration policies
- Add comprehensive unit tests for all DAO classes and data conversions
- Update Core Data model with NotificationContent, NotificationDelivery,
  and NotificationConfig entities (relationships and indexes)
- Integrate ReactivationManager into DailyNotificationPlugin.load()

DAO Features:
- Create/Insert methods with dictionary support
- Read/Query methods with predicates (by timesafariDid, notificationType,
  scheduledTime range, deliveryStatus, etc.)
- Update methods (touch, updateDeliveryStatus, recordUserInteraction)
- Delete methods (by ID, by key, delete all)
- Relationship management (NotificationContent ↔ NotificationDelivery)
- Cascade delete support

Test Coverage:
- 328 lines: DailyNotificationDataConversionsTests (time, numeric, string, JSON)
- 490 lines: NotificationContentDAOTests (CRUD, queries, updates)
- 415 lines: NotificationDeliveryDAOTests (CRUD, relationships, cascade delete)
- 412 lines: NotificationConfigDAOTests (CRUD, queries, active filtering)

All tests use in-memory Core Data stack for isolation and speed.

Completes sections 4.4, 4.5, and 6.0 of iOS implementation checklist.
2025-12-09 02:23:05 -08:00
Matthew
dd8d67462f docs(ios): add comprehensive iOS implementation documentation
Adds complete iOS documentation suite to support iOS implementation
parity with Android features. Includes implementation directives,
recovery scenario mappings, database migration guide, troubleshooting
guide, and test scripts.

New Documentation:
- iOS Implementation Directive: Phase-based implementation guide
  mirroring Android structure with iOS-specific considerations
- iOS Recovery Scenario Mapping: Maps Android recovery scenarios
  to iOS equivalents with detection logic comparisons
- iOS Core Data Migration Guide: Complete Room → Core Data entity
  mappings with implementation checklist for missing entities
- iOS Troubleshooting Guide: Common issues, debugging techniques,
  and error code reference

Enhanced Documentation:
- API.md: Added iOS-only methods (permissions, background tasks,
  pending notifications), platform differences table, and iOS-specific
  error types. Updated version to 2.3.0.

Test Infrastructure:
- iOS test scripts for Phase 1 (cold start), Phase 2 (termination),
  and Phase 3 (boot recovery) testing scenarios

All documentation addresses gaps identified in iOS Implementation
Documentation Review and provides foundation for iOS recovery feature
implementation (currently pending).

Note: iOS recovery features (ReactivationManager, scenario detection)
are NOT yet implemented. Documentation is ready to guide implementation.
2025-12-08 23:36:30 -08:00
Matthew
dac9cf3ddc Merge branch 'master' into ios-2 2025-12-08 22:42:23 -08:00
Matthew Raymer
2c4178d6b8 docs(test-app): add ADB commands section to README
Adds comprehensive ADB command reference for Android testing workflow.
Includes commands for installation, package management, app launching,
uninstallation, and debugging operations.

ADB Commands Added:
- Check device connection
- Install app (via Gradle)
- List installed packages
- Launch/raise app
- Uninstall app
- View app logs (with filtering)
- Check app info
- Force stop app (for testing recovery)
- Clear app data

Package name documented: com.timesafari.dailynotification.test

Also includes minor package-lock.json updates (plugin version 1.0.11
and dependency metadata cleanup).
2025-12-09 06:23:51 +00:00
Matthew Raymer
8b6df50115 docs(ios): add comprehensive documentation review for iOS implementation
Reviews Android plugin and test app documentation to ensure sufficient
detail exists for iOS implementation to mirror all Android features.

Documentation Review:
- Core architecture:  Ready (architecture, database schema, recovery logic)
- Platform specifics:  Missing (iOS-specific docs needed)
- API methods: ⚠️ Partially documented (54 methods, ~20 in API.md)
- Testing: ⚠️ Partially ready (Android scripts exist, iOS equivalents needed)

Key Findings:
- Database schema well-documented (all 7 tables with fields/types)
- Recovery scenarios clearly defined (COLD_START, FORCE_STOP, BOOT, NONE)
- Test procedures comprehensive (Phase 1-3 scripts with expected results)
- Missing iOS platform capability reference and implementation directive

Recommendations:
- Create iOS Platform Capability Reference (high priority)
- Create iOS Implementation Directive mirroring Android phase structure
- Complete API documentation for all 54 plugin methods
- Create iOS test scripts equivalent to Android test-phase*.sh

Assessment: Android documentation is comprehensive and provides solid
foundation for iOS implementation. Core architecture, database schema,
and recovery logic are ready. Platform-specific documentation needs
to be created for iOS.

Provides clear roadmap for ensuring iOS implementation mirrors all
Android features with identified gaps and prioritized action items.
2025-12-09 05:13:00 +00:00
Matthew Raymer
8c75b964a6 test(phase3): fix TEST 2 missed count extraction for duplicate boot recovery
Boot recovery runs twice on Android (both LOCKED_BOOT_COMPLETED and
BOOT_COMPLETED fire). The first run marks missed alarms (missed=1), while
the second run only reschedules future alarms (missed=0).

TEST 2 was incorrectly extracting the last entry (missed=0) instead of
the first entry (missed=1), causing false test failures.

Changes:
- Extract first missed count using head -n1 instead of tail -n1
- Add comment explaining why first entry is needed
- Test now correctly validates missed alarm detection

Fixes test validation for past alarm detection during boot recovery.
2025-12-08 10:40:42 +00:00
Matthew Raymer
3501cc4b6f fix(android): upgrade COLD_START detection log to INFO level
Changes COLD_START scenario detection log from DEBUG to INFO so it's
visible in test output when recovery runs. This improves testability
and debugging visibility for scenario detection.

The log message was already informative but hidden at DEBUG level,
making it difficult to verify scenario detection in test runs.
2025-12-08 07:44:18 +00:00
Matthew Raymer
4c4a5e2aa9 feat(android): implement Phase 2 force stop detection and recovery
Implements force stop scenario detection and comprehensive alarm recovery.
Adds scenario differentiation (FORCE_STOP, BOOT, COLD_START, NONE) to route
recovery logic appropriately.

Changes:
- Add RecoveryScenario enum and detectScenario() method
- Add performForceStopRecovery() for force stop scenario
- Add alarmsExist() helper to check AlarmManager state
- Update isBootRecovery() to ignore flags < 1 second old (emulator quirk fix)
- Update BootReceiver to only set boot flag for actual boot events
- Add test script step to clear boot flag before testing
- Fix compiler warnings (remove unused parameters)

Fixes false BOOT detection when alarms are cleared after force stop.
Boot flag age validation prevents emulator quirks from triggering BOOT
scenario during app launch.

Implements: Plugin Requirements §3.1.4 - Force Stop Recovery
2025-12-08 07:37:51 +00:00
Matthew Raymer
1053b668d0 test(phase1): automate TEST 4 invalid data handling verification
Implements automated testing for TEST 4 (Invalid Data Handling) to verify
recovery gracefully handles invalid database entries without crashing.

Changes:
- Add injectInvalidTestData plugin method for injecting invalid test data
  (empty schedule IDs, null nextRunAt, empty notification IDs)
- Make test app debuggable to enable direct database access
- Enhance test-phase1.sh with automated database injection and verification:
  * Detect debuggable app status (check for DEBUGGABLE flag)
  * Inject invalid data via direct SQL (schedules and notifications)
  * Handle WAL mode with checkpoint
  * Verify data injection success
  * Trigger recovery and check logs for "Skipping invalid" messages
  * Report pass/fail/inconclusive results

Fixes database constraint issues discovered during testing:
- Include jitterMs and backoffPolicy in schedule inserts
- Include priority, vibration_enabled, sound_enabled in notification inserts

Test results:  PASSED
- Invalid data successfully injected
- Cold start recovery correctly skips invalid entries
- Recovery completes without crashing
- Boot recovery processes invalid data (follow-up improvement needed)

This enables automated verification that recovery handles corrupted or
invalid database entries gracefully, preventing crashes in production.
2025-12-08 07:06:00 +00:00
Matthew Raymer
5bdb6979e1 fix(android): enforce one-per-day semantics in scheduleDailyNotification
Fix duplicate alarm bug where updating schedule time created multiple
schedules in database, violating "one notification per day" contract.

Plugin Changes:
- Use stable scheduleId "daily_notification" instead of timestamp-based IDs
- Delete all existing notification schedules before creating new one
- Cancel alarms in AlarmManager before database deletion
- Add detailed logging for cleanup operations
- Make scheduleDailyReminder delegate to scheduleDailyNotification

Test Harness Changes:
- Make TEST 2 fail when alarm count > 1 after schedule update
- Make TEST 2 fail when alarm count > 1 after recovery
- Add clear failure messages explaining "one per day" violation
- Add final verdict section with detailed failure summary

Results:
- Before: 2-3 alarms, 2 schedules in DB, "Pending: 2" in UI
- After: 1 alarm, 1 schedule in DB, "Pending: 1" in UI
- TEST 2 now correctly passes with proper validation

This ensures that updating schedule time maintains exactly one alarm
per day, preventing duplicate notifications and database bloat.
2025-12-08 06:36:16 +00:00
Matthew Raymer
ca194952e4 test(android): add auto-reset for TEST 1 and create golden run documentation
Add automatic app state reset for TEST 1 to ensure clean starting state when
lingering alarms from TEST 0 are detected. Create PHASE1_TEST1_GOLDEN.md with
actual values from successful run.

TEST 1 Auto-Reset:
- Detect lingering plugin alarms before TEST 1 starts
- Automatically uninstall/reinstall app to clear alarms
- Verify clean state (0 alarms) before proceeding
- Gracefully skip TEST 1 if clean state cannot be achieved
- Take failure screenshots when reset fails
- Wrap all TEST 1 steps in conditional to skip on reset failure

Documentation:
- Create PHASE1_TEST1_GOLDEN.md with actual values from passing run
- Document auto-reset behavior in golden run steps
- Add cross-references between TEST 0 and TEST 1 golden docs
- Include actual timestamps, scheduleIds, and recovery metrics

This ensures TEST 1 always starts from a known clean state, making test
results reliable and reproducible. The golden doc serves as a baseline for
comparing future TEST 1 runs.
2025-12-04 10:22:35 +00:00
Matthew Raymer
1103513db3 test(android): fix alarm counting logic and add screenshot capture
Fix alarm counting to correctly parse dumpsys output where app ID and
action appear on different lines. Add screenshot capture for test
diagnostics and create golden run documentation.

Test Harness Improvements:
- Fix get_plugin_alarm_count() to track app ID and action separately
  across alarm block lines (fixes false 0-count bug)
- Add show_plugin_alarms_compact() to display complete alarm blocks
- Add wait_for_stable_plugin_alarm_count() polling helper to reduce
  race condition false negatives
- Add take_screenshot() and take_failure_screenshot() helpers for
  automatic test state capture
- Integrate screenshots into TEST 0 at key checkpoints
- Update TEST 0 messaging to handle race conditions gracefully
- Add screenshots/ to .gitignore

Documentation:
- Create PHASE1_TEST0_GOLDEN.md with actual values from successful run
- Document expected script output, UI state, dumpsys shape, and logcat
  patterns
- Include pass/fail checklist for future test runs

This fixes the issue where alarm counting always returned 0 because the
AWK logic required app ID and action on the same line, but dumpsys
output has them on separate lines (header line has app ID, tag line
has action).
2025-12-04 09:28:28 +00:00
Matthew Raymer
fc2f64bae3 fix(notify): eliminate duplicate alarm scheduling and fix test harness counting
Centralize all notification alarm scheduling through NotifyReceiver.scheduleExactNotification()
with idempotence checks to prevent duplicate alarms. Implement one-alarm policy using
setAlarmClock() only. Fix test harness alarm counting to deduplicate by Alarm handle.

Plugin Changes:
- Add ScheduleSource enum to track scheduling paths (INITIAL_SETUP, ROLLOVER_ON_FIRE, etc.)
- Add DB-level idempotence check before scheduling (prevents logical duplicates)
- Add explicit alarm cancellation before scheduling (safety net)
- Implement one-alarm policy: use setAlarmClock() only, no setExact* fallbacks for same event
- Add deep logging for all AlarmManager calls (variant, requestCode, pendingIntentHash)
- Update all rollover paths (DailyNotificationReceiver, DailyNotificationWorker) to use
  centralized function with ROLLOVER_ON_FIRE source
- Add @JvmStatic annotation to scheduleExactNotification for Java interop

Test Harness Changes:
- Fix get_plugin_alarm_count() to deduplicate by Alarm handle (prevents double-counting
  same alarm in main list and "Next wake from idle" section)
- Update TEST 0 messaging: treat 0 alarms as race condition (inconclusive, not failure)
- Make post-rollover check the authoritative assertion point (only fails on >1 or 0 alarms)
- Remove redundant "Found 0 alarms - test may not be accurate" messages

This fixes the duplicate alarm bug where two distinct AlarmManager entries were created
for the same daily notification, violating the "one notification per day" contract.
2025-12-01 10:09:54 +00:00
Matthew Raymer
ba8f98db65 refactor(test-app): remove alarm list UI from test app
Remove the 'List Alarms' button and alarm list display functionality
from the Android test app UI. This feature was added for testing but
is no longer needed as alarm verification is handled by the test scripts.

Removed:
- '📋 List Alarms' button
- alarmListContainer div and alarm list display
- loadAlarmList() JavaScript function
- getSchedulesWithStatus() API call usage

The getSchedulesWithStatus() plugin method remains available for
programmatic use if needed in the future.
2025-11-28 08:56:06 +00:00
Matthew Raymer
0f87dad135 fix(android): correct NotificationContentEntity DAO method calls
Fix ReactivationManager to use correct DAO method names and entity
constructor for NotificationContentEntity:

- Change getById() to getNotificationById()
- Change insert() to insertNotification()
- Update NotificationContentEntity construction to use Java class
  constructor with positional parameters
- Set entity fields using Java property syntax after construction

This fixes compilation errors introduced when switching to Java-based
NotificationContentEntity class.
2025-11-28 08:56:02 +00:00
Matthew Raymer
07ace32982 refactor(test): extract shared helpers into alarm-test-lib.sh
Extract common helper functions from test-phase1.sh, test-phase2.sh,
and test-phase3.sh into a shared library (alarm-test-lib.sh) to reduce
code duplication and improve maintainability.

Changes:
- Create alarm-test-lib.sh with shared configuration, UI helpers, ADB
  helpers, log parsing, and test selection logic
- Refactor all three phase test scripts to source the shared library
- Remove ~200 lines of duplicated code across the three scripts
- Preserve all existing behavior, CLI arguments, and test semantics
- Maintain Phase 1 compatibility (print_* functions, VERIFY_FIRE flag)
- Update all adb references to use $ADB_BIN variable
- Standardize alarm counting to use shared count_alarms() function

Benefits:
- Single source of truth for shared helpers
- Easier maintenance (fix once, benefits all scripts)
- Consistent behavior across all test phases
- No functional changes to test execution or results
2025-11-28 08:53:42 +00:00
Matthew Raymer
73301f7d1d feat(android): add getSchedulesWithStatus() and alarm list UI
Adds ability to list alarms with AlarmManager status in web interface.

Changes:
- Add getSchedulesWithStatus() method to DailyNotificationPlugin
- Add ScheduleWithStatus TypeScript interface with isActuallyScheduled flag
- Add alarm list UI to android-test-app with status indicators

Backend:
- getSchedulesWithStatus() returns schedules with AlarmManager verification
- Checks isAlarmScheduled() for each notify schedule with nextRunAt
- Returns isActuallyScheduled boolean flag for each schedule

TypeScript:
- New ScheduleWithStatus interface extending Schedule
- Method signature with JSDoc and usage examples

UI:
- New "📋 List Alarms" button in test app
- Color-coded alarm cards (green=scheduled, orange=not scheduled)
- Shows schedule ID, next run time, pattern, and AlarmManager status
- Useful for debugging recovery scenarios and verifying alarm state

Use case:
- Verify which alarms are in database vs actually scheduled
- Debug Phase 1/2/3 recovery scenarios
- Visual confirmation of alarm state after app launch/boot

Related:
- Enhances: android-test-app for Phase 1-3 testing
- Supports: Recovery verification and debugging
2025-11-28 04:56:19 +00:00
Matthew Raymer
945956dc5a feat(android): implement Phase 3 boot-time recovery
Implements boot-time recovery that restores alarms after device reboot,
matching Phase 3 directive and test suite expectations.

Changes:
- Add ReactivationManager.runBootRecovery() companion method
- Update BootReceiver to delegate to ReactivationManager
- Handle past alarms: mark as missed, schedule next occurrence
- Handle future alarms: reschedule immediately
- Use DNP-REACTIVATION tag for all boot recovery logs
- Log summary: "Boot recovery complete: missed=X, rescheduled=Y, verified=0, errors=Z"
- Record history with scenario=BOOT

Recovery behavior:
- Loads all schedules from database on boot
- Detects past vs future scheduled times
- Marks missed notifications for past alarms
- Reschedules all alarms (past and future)
- Completes within 2-second timeout (non-blocking)
- Handles empty DB gracefully (logs "BOOT: No schedules found")

Implementation details:
- Uses companion object method for static access from BootReceiver
- Helper methods for schedule calculation, missed marking, rescheduling
- Error handling: non-fatal, continues processing other schedules
- History recording with boot_recovery kind and scenario=BOOT

Related:
- Implements: android-implementation-directive-phase3.md
- Requirements: docs/alarms/03-plugin-requirements.md §3.1.1
- Testing: docs/alarms/PHASE3-EMULATOR-TESTING.md
- Verification: docs/alarms/PHASE3-VERIFICATION.md
2025-11-28 04:43:26 +00:00
Matthew Raymer
87594be5be docs: integrate Phase 1-3 into unified directive and activation guide
Updates master coordination documents to reflect Phase 1-3 completion status.

Changes:
- Update 000-UNIFIED-ALARM-DIRECTIVE.md status matrix:
  - P1: Marked as emulator-verified
  - P2: Marked as implemented, ready for testing
  - P3: Marked as implemented, ready for testing
  - V1-V3: Added verification doc rows
- Update ACTIVATION-GUIDE.md status bullets:
  - Phase 1: Complete and emulator-verified
  - Phase 2: Implemented, ready for emulator testing
  - Phase 3: Implemented, ready for emulator testing
  - Overall status updated to reflect all three phases

All three phases now have:
- Implementation directives
- Emulator testing guides
- Verification documents
- Automated test harnesses

Related:
- Unified Directive: docs/alarms/000-UNIFIED-ALARM-DIRECTIVE.md
- Activation Guide: docs/alarms/ACTIVATION-GUIDE.md
2025-11-27 10:01:55 +00:00
Matthew Raymer
28fb233286 docs(test): add Phase 3 boot recovery testing infrastructure
Adds documentation and test harness for Phase 3 (Boot-Time Recovery).

Changes:
- Update android-implementation-directive-phase3.md with concise boot recovery flow
- Add PHASE3-EMULATOR-TESTING.md with detailed test procedures
- Add PHASE3-VERIFICATION.md with test matrix and verification template
- Add test-phase3.sh automated test harness

Test harness features:
- 4 test cases: future alarms, past alarms, no schedules, silent recovery
- Automatic emulator reboot handling
- Log parsing for boot recovery scenario and results
- UI prompts for plugin configuration and scheduling
- Verifies silent recovery without app launch

Related:
- Directive: android-implementation-directive-phase3.md
- Requirements: docs/alarms/03-plugin-requirements.md §3.1.1
- Testing: docs/alarms/PHASE3-EMULATOR-TESTING.md
- Verification: docs/alarms/PHASE3-VERIFICATION.md
2025-11-27 10:01:46 +00:00
Matthew Raymer
c8a3906449 docs(test): add Phase 2 force stop recovery testing infrastructure
Adds documentation and test harness for Phase 2 (Force Stop Detection & Recovery).

Changes:
- Add PHASE2-EMULATOR-TESTING.md with detailed test procedures
- Add PHASE2-VERIFICATION.md with test matrix and verification template
- Add test-phase2.sh automated test harness

Test harness features:
- 3 test cases: force stop with cleared alarms, intact alarms, empty DB
- Automatic force stop simulation via adb
- Log parsing for scenario detection and recovery results
- UI prompts for plugin configuration and scheduling

Related:
- Directive: android-implementation-directive-phase2.md
- Requirements: docs/alarms/03-plugin-requirements.md §3.1.4
- Testing: docs/alarms/PHASE2-EMULATOR-TESTING.md
- Verification: docs/alarms/PHASE2-VERIFICATION.md
2025-11-27 10:01:40 +00:00
Matthew Raymer
3151a1cc31 feat(android): implement Phase 1 cold start recovery
Implements cold start recovery for missed notifications and future alarm
verification/rescheduling as specified in Phase 1 directive.

Changes:
- Add ReactivationManager.kt with cold start recovery logic
- Integrate recovery into DailyNotificationPlugin.load()
- Fix NotifyReceiver to always store NotificationContentEntity for recovery
- Add Phase 1 emulator testing guide and verification doc
- Add test-phase1.sh automated test harness

Recovery behavior:
- Detects missed notifications on app launch
- Marks missed notifications in database
- Verifies future alarms are scheduled in AlarmManager
- Reschedules missing future alarms
- Completes within 2-second timeout (non-blocking)

Test harness:
- Automated script with 4 test cases
- UI prompts for plugin configuration
- Log parsing for recovery results
- Verified on Pixel 8 API 34 emulator

Related:
- Implements: android-implementation-directive-phase1.md
- Requirements: docs/alarms/03-plugin-requirements.md §3.1.2
- Testing: docs/alarms/PHASE1-EMULATOR-TESTING.md
- Verification: docs/alarms/PHASE1-VERIFICATION.md
2025-11-27 10:01:34 +00:00
Matthew Raymer
77b6f2260f chore: directive activation guide 2025-11-27 07:38:05 +00:00
Matthew Raymer
bd842c6ef8 [ALARM-DOCS] fix(docs): remove duplicate status matrix and fix cross-references
Remove duplicate status matrix from Section 3.3 and consolidate to Section 11
as single source of truth. Fix all section number references throughout
documentation.

Changes:
- Remove duplicate status matrix table from Section 3.3
- Update all references from "Section 3.3" and "Section 10" to "Section 11"
- Fix phase directive paths to use consistent ../ prefix format
- Fix P1 path typo (missing "directive" in filename)
- Update Doc C status in matrix to reflect completion
- Remove duplicate text in Doc B baseline scenarios
- Remove self-referencing links in Doc B

All status matrix references now point to Section 11, eliminating confusion
about which matrix is authoritative.
2025-11-27 07:34:47 +00:00
Matthew Raymer
35babb3126 docs(alarms): unify and enhance alarm directive documentation stack
Create unified alarm documentation system with strict role separation:
- Doc A: Platform capability reference (canonical OS facts)
- Doc B: Plugin behavior exploration (executable test harness)
- Doc C: Plugin requirements (guarantees, JS/TS contract, traceability)

Changes:
- Add canonical rule to Doc A preventing platform fact duplication
- Convert Doc B to pure executable test spec with scenario tables
- Complete Doc C with guarantees matrix, JS/TS API contract, recovery
  contract, unsupported behaviors, and traceability matrix
- Remove implementation details from unified directive
- Add compliance milestone tracking and iOS parity gates
- Add deprecation banners to legacy platform docs

All documents now enforce strict role separation with cross-references
to prevent duplication and ensure single source of truth.
2025-11-25 10:09:46 +00:00
Matthew Raymer
afbc98f7dc chore: synch this plan 2025-11-25 08:04:53 +00:00
Matthew Raymer
6aa9140f67 docs: add comprehensive alarm/notification behavior documentation
- Add platform capability reference (Android & iOS OS-level facts)
- Add plugin behavior exploration template (executable test matrices)
- Add plugin requirements & implementation directive
- Add Android-specific implementation directive with detailed test procedures
- Add exploration findings from code inspection
- Add improvement directive for refining documentation structure
- Add Android alarm persistence directive (OS capabilities)

All documents include:
- File locations, function references, and line numbers
- Detailed test procedures with ADB commands
- Cross-platform comparisons
- Implementation checklists and code examples
2025-11-21 07:30:25 +00:00
Matthew
b44fd3a435 feat(test-app): add iOS project structure and configuration
- Add iOS .gitignore for Capacitor iOS project
- Add Podfile with DailyNotificationPlugin dependency
- Add Xcode project and workspace files
- Add AppDelegate.swift for iOS app entry point
- Add Assets.xcassets with app icons and splash screens
- Add Base.lproj storyboards for launch and main screens

These files are generated by Capacitor when iOS platform is added.
The Podfile correctly references DailyNotificationPlugin from node_modules.
2025-11-20 23:10:17 -08:00
Matthew
95b3d74ddc chore: update package-lock.json with peer dependency flags
- Add peer: true flags to Capacitor dependencies
- Reflects npm install updates for peer dependency handling
2025-11-20 23:07:22 -08:00
Matthew
cebf341839 fix(test-app): iOS permission handling and build improvements
- Add BGTask identifiers and background modes to iOS Info.plist
- Fix permission method calls (checkPermissionStatus vs checkPermissions)
- Implement Android-style permission checking pattern
- Add "Request Permissions" action card with check-then-request flow
- Fix simulator selection in build script (use device ID for reliability)
- Add Podfile auto-fix to fix-capacitor-plugins.js
- Update build documentation with unified script usage

Fixes:
- BGTask registration errors (Info.plist missing identifiers)
- Permission method not found errors (checkPermissions -> checkPermissionStatus)
- Simulator selection failures (now uses device ID)
- Podfile incorrect pod name (TimesafariDailyNotificationPlugin -> DailyNotificationPlugin)

The permission flow now matches Android: check status first, then show
system dialog if needed. iOS system dialog appears automatically when
requestNotificationPermissions() is called.

Files changed:
- test-apps/daily-notification-test/ios/App/App/Info.plist (new)
- test-apps/daily-notification-test/src/lib/typed-plugin.ts
- test-apps/daily-notification-test/src/views/HomeView.vue
- test-apps/daily-notification-test/scripts/build.sh (new)
- test-apps/daily-notification-test/scripts/fix-capacitor-plugins.js
- test-apps/daily-notification-test/docs/BUILD_QUICK_REFERENCE.md
- test-apps/daily-notification-test/README.md
- test-apps/daily-notification-test/package.json
- test-apps/daily-notification-test/package-lock.json
2025-11-20 23:05:49 -08:00
Matthew
e6cd8eb055 fix(ios): remove unused variable warning in AppDelegate
Replace if let binding with boolean is check for CAPBridgedPlugin
conformance test. This eliminates the compiler warning about unused
variable 'capacitorPluginType' while maintaining the same diagnostic
functionality.
2025-11-19 22:03:25 -08:00
Matthew Raymer
53845330f9 feat(test-app): add notification delivery indicator
- Add visual indicator when notification is received (shows for 30s)
- Poll notification status every 5 seconds to detect recent deliveries
- Add helpful message in test notification success about checking top of screen
- Improve user feedback for notification testing workflow
2025-11-20 04:37:08 +00:00
Matthew
92bb566631 fix(ios): configure method parameter parsing and improve build process
Fix configure() method to read parameters directly from CAPPluginCall
instead of expecting nested options object, matching Android implementation.

Improve build process to ensure canonical UI is always copied:
- iOS build script: Copy www/index.html to test app before build
- Android build.gradle: Add copyCanonicalUI task to run before build
- Ensures test apps always use latest UI from www/index.html

This fixes the issue where configure() was returning 'Configuration
options required' error because it expected a nested options object
when Capacitor passes parameters directly on the call object.
2025-11-19 20:09:01 -08:00
Matthew
3d9254e26d feat(ios): show notifications in foreground and add visual feedback
Implement UNUserNotificationCenterDelegate in AppDelegate to display
notifications when app is in foreground. Add visual feedback indicator
in test app UI to confirm notification delivery.

Changes:
- AppDelegate: Conform to UNUserNotificationCenterDelegate protocol
- AppDelegate: Implement willPresent and didReceive delegate methods
- AppDelegate: Set delegate at multiple lifecycle points to ensure
  it's always active (immediate, after Capacitor init, on app active)
- UI: Add notification received indicator in status card
- UI: Add periodic check for notification delivery (every 5 seconds)
- UI: Add instructions on where to look for notification banner
- Docs: Add IOS_LOGGING_GUIDE.md for debugging iOS logs

This fixes the issue where scheduled notifications were not visible
when the app was in the foreground. The delegate method now properly
presents notifications with banner, sound, and badge options.

Verified working: Logs show delegate method called successfully when
notification fires, with proper presentation options set.
2025-11-19 01:15:20 -08:00
Matthew
ee0e85d76a Merge branch 'master' into ios-2 2025-11-18 21:27:55 -08:00
Matthew
9f26588331 fix(ios): iOS 13.0 compatibility and test app UI unification
Fixed iOS 13.0 compatibility issue in test harness by replacing Logger
(iOS 14+) with os_log (iOS 13+). Fixed build script to correctly detect
and sync Capacitor config from App subdirectory. Unified both Android
and iOS test app UIs to use www/index.html as the canonical source.

Changes:
- DailyNotificationBackgroundTaskTestHarness: Replace Logger with os_log
  for iOS 13.0 deployment target compatibility
- build-ios-test-app.sh: Fix Capacitor sync path detection to check
  both current directory and App/ subdirectory for config files
- test-apps: Update both Android and iOS test apps to use www/index.html
  as the canonical UI source for consistency

This ensures the plugin builds on iOS 13.0+ and both test apps provide
the same testing experience across platforms.
2025-11-18 21:25:14 -08:00
Matthew Raymer
9d93216327 chore: fixing source of design truth 2025-11-19 05:19:24 +00:00
Matthew
b74d38056f Merge branch 'master' into ios-2 2025-11-18 19:29:26 -08:00
Matthew Raymer
ed62f7ee25 style: fix indentation in DailyNotificationWorker and AndroidManifest
- Normalize indentation in DailyNotificationWorker.java
- Normalize indentation in AndroidManifest.xml
2025-11-18 09:51:20 +00:00
Matthew Raymer
a8039d072d fix(android): improve channel status detection and UI refresh
- Fix isChannelEnabled() to create channel if missing and re-fetch from system
  to get actual state (handles previously blocked channels)
- Use correct channel ID 'timesafari.daily' instead of 'daily_notification_channel'
- Add detailed logging for channel status checks
- Fix UI to refresh channel status after notification permissions are granted
- Channel status now correctly reflects both app-level and channel-level settings
2025-11-18 09:50:23 +00:00
Matthew Raymer
8f20da7e8d fix(android): support static reminder notifications and ensure channel exists
Static reminders scheduled via scheduleDailyNotification() with
isStaticReminder=true were being skipped because they don't have content
in storage - title/body are in Intent extras. Fixed by:

- DailyNotificationReceiver: Extract static reminder extras from Intent
  and pass to WorkManager as input data
- DailyNotificationWorker: Check for static reminder flag in input data
  and create NotificationContent from input data instead of loading from
  storage
- DailyNotificationWorker: Ensure notification channel exists before
  displaying (fixes "No Channel found" errors)

Also updated prefetch timing from 5 minutes to 2 minutes before notification
time in plugin code and web UI.
2025-11-18 04:02:56 +00:00
Matthew Raymer
b3d0d97834 docs(ios-prefetch): clarify Xcode background fetch simulation methods
Fix documentation to address Xcode behavior where 'Simulate Background
Fetch' menu item only appears when app is NOT running.

Changes:
- Add explicit note about Xcode menu item availability
- Prioritize LLDB command method when app is running (recommended)
- Document three methods: LLDB command, Xcode menu, and UI button
- Add troubleshooting section for common issues
- Update quick start section to reference LLDB method
- Explicitly reference test-apps/ios-test-app path for clarity

This resolves confusion when 'Simulate Background Fetch' disappears
from Debug menu while app is running. LLDB command method works reliably
in all scenarios.
2025-11-17 08:42:39 +00:00
Matthew
4d53faabad chore: update 2025-11-17 00:07:51 -08:00
Matthew Raymer
95507c6121 test(ios-prefetch): enhance testing infrastructure and validation
Apply comprehensive enhancements to iOS prefetch plugin testing and
validation system per directive requirements.

Technical Correctness Improvements:
- Enhanced BGTask scheduling with validation (60s minimum lead time)
- Implemented one active task rule (cancel existing before scheduling)
- Added graceful simulator error handling (Code=1 expected)
- Follow Apple best practice: schedule next task immediately at execution
- Ensure task completion even on expiration with guard flag
- Improved error handling and structured logging

Testing Coverage Expansion:
- Added edge case scenarios table (7 scenarios: Background Refresh Off,
  Low Power Mode, Force-Quit, Timezone Change, DST, Multi-Day, Reboot)
- Expanded failure injection tests (8 new negative-path scenarios)
- Documented automated testing strategies (unit and integration tests)

Validation Enhancements:
- Added structured JSON logging schema for events
- Provided log validation script (validate-ios-logs.sh)
- Enhanced test run template with telemetry and state verification
- Documented state integrity checks (content hash, schedule hash)
- Added UI indicators and persistent test artifacts requirements

Documentation Updates:
- Enhanced IOS_PREFETCH_TESTING.md with comprehensive test strategies
- Added Technical Correctness Requirements to IOS_TEST_APP_REQUIREMENTS.md
- Expanded error handling test cases from 2 to 7 scenarios
- Created ENHANCEMENTS_APPLIED.md summary document

Files modified:
- ios/Plugin/DailyNotificationBackgroundTaskTestHarness.swift: Enhanced
  with technical correctness improvements
- doc/test-app-ios/IOS_PREFETCH_TESTING.md: Expanded testing coverage
- doc/test-app-ios/IOS_TEST_APP_REQUIREMENTS.md: Added technical
  requirements
- doc/test-app-ios/ENHANCEMENTS_APPLIED.md: New summary document
2025-11-17 06:37:06 +00:00