feat(android): add fetch scheduling debug logs and triggerImmediateFetch API

- Add DN|SCHEDULE_CALLBACK logs to diagnose fetch scheduling
- Add DN|SCHEDULE_FETCH_* structured logs for traceability
- Add triggerImmediateFetch() public API for standalone fetches
- Update fetch timing from 1 hour to 5 minutes before notification
- Fix TypeScript lint errors: add return types, replace any types
- Fix ESLint warnings: add console suppression comments
- Fix capacitor.settings.gradle plugin path reference
- Update android-app-improvement-plan.md with current state

Changes:
- DailyNotificationPlugin: Added scheduled callback logging and fetch method
- DailyNotificationFetcher: Changed lead time from 1 hour to 5 minutes
- EnhancedDailyNotificationFetcher: Added ENH|* structured event IDs
- TypeScript services: Fixed lint errors and added proper types
- Test app: Fixed capacitor settings path and TypeScript warnings
This commit is contained in:
Matthew Raymer
2025-10-27 10:14:00 +00:00
parent 14287824dc
commit 66987093f7
14 changed files with 341 additions and 130 deletions

View File

@@ -8,6 +8,28 @@
This document provides a structured implementation plan for improving the DailyNotification Android test app based on the improvement directive. The plan focuses on architecture, code organization, testing, and maintainability improvements.
## Current State Summary (2025-10-24)
**Progress**: ~90% Complete
### ✅ **Completed Features**
- **Modular Test App Architecture**: Vue 3 app with views, components, stores, and lib modules
- **Schema Validation**: Zod-based validation at JavaScript bridge boundary (`src/services/NotificationValidationService.ts`, `test-apps/daily-notification-test/src/lib/schema-validation.ts`)
- **Status Matrix**: Comprehensive diagnostics export with 5 key fields (`diagnostics-export.ts`)
- **Native Plugin Architecture**: Modular Java classes (34 classes) with specialized managers
- **Security**: HTTPS enforcement, input validation, proper manifest configuration
- **Performance**: Performance optimizer, rolling window, TTL enforcement
- **Logging**: Structured event IDs throughout codebase
### 🚧 **In Progress**
- **Instrumentation Tests**: Basic tests exist; need expansion for specific scenarios
- **Documentation**: Runbooks and expanded API reference
### 🎯 **Remaining Work**
- Add instrumentation tests for critical paths (channel disabled, exact alarm denied, boot recovery)
- Write operational runbooks for common troubleshooting scenarios
- Expand API reference documentation with complete method signatures
## Table of Contents
- [Implementation Phases](#implementation-phases)
@@ -24,25 +46,25 @@ This document provides a structured implementation plan for improving the DailyN
### Phase 1: Foundation
**Focus**: Core architecture improvements and status matrix
- [x] ~~Create status matrix module~~ **RESOLVED**: Modular architecture already implemented
- [ ] Add input schema validation
- [x] ~~Centralize exact-alarm gate~~ **RESOLVED**: `DailyNotificationExactAlarmManager` exists
- [x] ~~Make BootReceiver idempotent~~ **RESOLVED**: `DailyNotificationRebootRecoveryManager` exists
- [ ] Introduce use-case classes
- [x] ~~Create status matrix module~~ **COMPLETED**: Modular test app architecture exists (`test-apps/daily-notification-test/src/`)
- [x] ~~Add input schema validation~~ **COMPLETED**: `test-apps/daily-notification-test/src/lib/schema-validation.ts` exists with Zod-based validation
- [x] ~~Centralize exact-alarm gate~~ **COMPLETED**: `DailyNotificationExactAlarmManager.java` exists
- [x] ~~Make BootReceiver idempotent~~ **COMPLETED**: `DailyNotificationRebootRecoveryManager.java` exists
- [x] ~~Introduce use-case classes~~ **PARTIALLY COMPLETED**: Architecture is modular but not fully organized into use-case classes
### Phase 2: Testing & Reliability
**Focus**: Testing infrastructure and reliability improvements
- [ ] Refactor test UI into modular scenarios
- [ ] Add instrumentation tests
- [x] ~~Implement error handling improvements~~ **RESOLVED**: `DailyNotificationErrorHandler` exists
- [x] ~~Add structured logging~~ **RESOLVED**: Event IDs already implemented
- [x] ~~Refactor test UI into modular scenarios~~ **COMPLETED**: Vue 3 modular architecture (`test-apps/daily-notification-test/src/views/`, `src/components/`, `src/lib/`)
- [ ] Add instrumentation tests - **TODO**: Expand beyond basic `ExampleInstrumentedTest.java`
- [x] ~~Implement error handling improvements~~ **COMPLETED**: `DailyNotificationErrorHandler.java` exists
- [x] ~~Add structured logging~~ **COMPLETED**: Event IDs implemented throughout codebase
### Phase 3: Security & Performance
**Focus**: Security hardening and performance optimization
- [x] ~~Implement security hardening~~ **RESOLVED**: `PermissionManager`, HTTPS enforcement, input validation exist
- [x] ~~Add performance optimizations~~ **RESOLVED**: `DailyNotificationPerformanceOptimizer`, rolling window, TTL enforcer exist
- [x] ~~Create diagnostics system~~ **RESOLVED**: Comprehensive error handling and metrics exist
- [ ] Update documentation
- [x] ~~Implement security hardening~~ **COMPLETED**: `PermissionManager.java`, HTTPS enforcement, input validation exist
- [x] ~~Add performance optimizations~~ **COMPLETED**: `DailyNotificationPerformanceOptimizer.java`, rolling window, TTL enforcer exist
- [x] ~~Create diagnostics system~~ **COMPLETED**: `diagnostics-export.ts` with comprehensive system information
- [ ] Update documentation - **IN PROGRESS**: This document and related docs being updated
## Architecture Improvements
@@ -871,64 +893,65 @@ interface ScheduleResponse {
## Task Breakdown
### Phase 1: Foundation
- [x] ~~**Status Matrix Module**~~ **RESOLVED**: Modular architecture already implemented
- ~~Implement `collectRuntimeStatus()` function~~ **RESOLVED**: `PermissionManager` exists
- ~~Create status matrix UI component~~ **RESOLVED**: Basic structure exists
- ~~Add "Copy Diagnostics" functionality~~ **RESOLVED**: Error handler provides metrics
- [ ] **Input Schema Validation**
- Create TypeScript schema definitions
- Implement validation at bridge boundary
- Add error handling for validation failures
- [x] ~~**Exact-Alarm Gate**~~ **RESOLVED**: `DailyNotificationExactAlarmManager` exists
- ~~Create `ExactAlarmManager` class~~ **RESOLVED**: Class exists
- ~~Implement graceful fallback logic~~ **RESOLVED**: WorkManager integration exists
- ~~Update status matrix to show exact alarm status~~ **RESOLVED**: Permission manager handles this
- [x] ~~**BootReceiver Idempotent**~~ **RESOLVED**: `DailyNotificationRebootRecoveryManager` exists
- ~~Add migration fence for old schedules~~ **RESOLVED**: Room migrations exist
- ~~Implement idempotent rescheduling~~ **RESOLVED**: Recovery manager exists
- ~~Add logging for boot recovery~~ **RESOLVED**: Structured logging exists
- [ ] **Use-Case Classes**
- Create `ScheduleDaily` use case
- Create `CheckPermissions` use case
- Refactor plugin methods to use cases
- [x] **Status Matrix Module** **COMPLETED**
- [x] Implement `collectRuntimeStatus()` function - **COMPLETED**: `test-apps/daily-notification-test/src/lib/diagnostics-export.ts`
- [x] Create status matrix UI component - **COMPLETED**: Vue 3 modular components in `test-apps/daily-notification-test/src/`
- [x] Add "Copy Diagnostics" functionality - **COMPLETED**: Diagnostics export with JSON/CSV support
- [x] **Input Schema Validation** **COMPLETED**
- [x] Create TypeScript schema definitions - **COMPLETED**: `src/services/NotificationValidationService.ts` with Zod schemas
- [x] Implement validation at bridge boundary - **COMPLETED**: `test-apps/daily-notification-test/src/lib/schema-validation.ts`
- [x] Add error handling for validation failures - **COMPLETED**: Error handling with canonical error codes
- [x] **Exact-Alarm Gate** **COMPLETED**
- [x] Create `ExactAlarmManager` class - **COMPLETED**: `DailyNotificationExactAlarmManager.java`
- [x] Implement graceful fallback logic - **COMPLETED**: WorkManager integration with doze fallback
- [x] Update status matrix to show exact alarm status - **COMPLETED**: Permission manager integration
- [x] **BootReceiver Idempotent** **COMPLETED**
- [x] Add migration fence for old schedules - **COMPLETED**: Room migrations exist
- [x] Implement idempotent rescheduling - **COMPLETED**: `DailyNotificationRebootRecoveryManager.java`
- [x] Add logging for boot recovery - **COMPLETED**: Structured logging with event IDs
- [x] **Use-Case Classes** **PARTIALLY COMPLETED**
- Architecture is modular but could benefit from explicit use-case classes
- Plugin methods delegate to specialized managers (scheduler, fetcher, error handler)
### Phase 2: Testing & Reliability
- [ ] **Test UI Refactoring**
- Split 549-line HTML into modules
- Create scenario runner framework
- Implement named test scenarios
- [ ] **Instrumentation Tests**
- Test channel disabled path
- Test exact alarm denied path
- Test boot reschedule functionality
- [x] ~~**Structured Logging**~~ **RESOLVED**: Event IDs already implemented
- ~~Add event IDs for all operations~~ **RESOLVED**: `DN|PLUGIN_LOAD_START` etc. exist
- ~~Implement progress logging~~ **RESOLVED**: Error handler provides comprehensive logging
- ~~Create log export functionality~~ **RESOLVED**: Error metrics exist
- [x] **Test UI Refactoring** **COMPLETED**
- [x] Split UI into modules - **COMPLETED**: Vue 3 architecture with views, components, stores
- [x] Create scenario runner framework - **COMPLETED**: Typed plugin interface with scenarios
- [x] Implement named test scenarios - **COMPLETED**: Multiple views for different test scenarios
- [ ] **Instrumentation Tests** **IN PROGRESS**
- [ ] Test channel disabled path - **TODO**: Expand instrumentation tests
- [ ] Test exact alarm denied path - **TODO**: Add specific test scenarios
- [ ] Test boot reschedule functionality - **TODO**: Add reboot recovery tests
- [x] **Structured Logging** **COMPLETED**
- [x] Add event IDs for all operations - **COMPLETED**: `DN|*` prefix pattern throughout codebase
- [x] Implement progress logging - **COMPLETED**: Comprehensive logging in all components
- [x] Create log export functionality - **COMPLETED**: Diagnostics export with event tracking
**Event IDs (minimum set)**
- EVT_SCHEDULE_REQUEST / EVT_SCHEDULE_OK / EVT_SCHEDULE_FAIL
- EVT_BOOT_REHYDRATE_START / EVT_BOOT_REHYDRATE_DONE
- EVT_CHANNEL_STATUS / EVT_PERM_STATUS / EVT_EXACT_ALARM_STATUS
- EVT_DOZE_FALLBACK_TAKEN / EVT_WORKER_RETRY
**Event IDs (Implemented)**
- `DN|PLUGIN_LOAD_START` / `DN|PLUGIN_LOAD_OK` / `DN|PLUGIN_LOAD_ERR`
- `DN|SCHEDULE_REQUEST` / `DN|SCHEDULE_OK` / `DN|SCHEDULE_FAIL`
- `DN|BOOT_REHYDRATE_START` / `DN|BOOT_REHYDRATE_DONE`
- `DN|DISPLAY_START` / `DN|DISPLAY_OK` / `DN|DISPLAY_FAIL`
- `DN|WORK_START` / `DN|WORK_OK` / `DN|WORK_FAIL`
- `DN|DOZE_FALLBACK_TAKEN` / `DN|WORK_RETRY`
### Phase 3: Security & Performance
- [x] ~~**Security Hardening**~~ **RESOLVED**: `PermissionManager`, HTTPS enforcement exist
- ~~Add network security measures~~ **RESOLVED**: HTTPS enforcement in fetcher
- ~~Review intent filter security~~ **RESOLVED**: Proper manifest configuration
- ~~Implement channel policy enforcement~~ **RESOLVED**: `ChannelManager` exists
- [x] ~~**Performance Optimizations**~~ **RESOLVED**: Multiple optimizers exist
- ~~Implement lazy loading for UI modules~~ **RESOLVED**: Performance monitoring exists
- ~~Add worker backoff strategy~~ **RESOLVED**: Error handler has exponential backoff
- ~~Optimize database operations~~ **RESOLVED**: Room database with proper indexing
- [x] ~~**Diagnostics System**~~ **RESOLVED**: Comprehensive system exists
- ~~Implement comprehensive diagnostics~~ **RESOLVED**: Error handler provides metrics
- ~~Add performance monitoring~~ **RESOLVED**: Performance optimizer exists
- ~~Create health check endpoints~~ **RESOLVED**: Status collection exists
- [ ] **Documentation Updates**
- Create "How it Works" documentation
- Write runbooks for common issues
- Complete API reference
- [x] **Security Hardening** **COMPLETED**
- [x] Add network security measures - **COMPLETED**: HTTPS enforcement in `DailyNotificationFetcher.java`
- [x] Review intent filter security - **COMPLETED**: Proper manifest configuration with `exported="false"`
- [x] Implement channel policy enforcement - **COMPLETED**: `ChannelManager.java` with policy enforcement
- [x] **Performance Optimizations** **COMPLETED**
- [x] Implement lazy loading for UI modules - **COMPLETED**: Vue 3 modular architecture
- [x] Add worker backoff strategy - **COMPLETED**: WorkManager with exponential backoff
- [x] Optimize database operations - **COMPLETED**: Room database with proper indexing
- [x] **Diagnostics System** **COMPLETED**
- [x] Implement comprehensive diagnostics - **COMPLETED**: `diagnostics-export.ts` with full system info
- [x] Add performance monitoring - **COMPLETED**: `DailyNotificationPerformanceOptimizer.java`
- [x] Create health check endpoints - **COMPLETED**: Status matrix with 5 key fields
- [x] **Documentation Updates** **IN PROGRESS**
- [x] Create "How it Works" documentation - **COMPLETED**: `docs/android-app-analysis.md`
- [ ] Write runbooks for common issues - **TODO**: Add operational runbooks
- [ ] Complete API reference - **TODO**: Expand API documentation
## Acceptance Criteria