LifeMate — Personal, Family & Learning Companion
docs/offline-data-rescue-options
chore/phase1-repository-cleanup
deploy/stable-web-apk
deployment-static
design/mobile-accessibility-v2
design/mobile-navigation-review
docs/child-education-access-decision
docs/offline-data-rescue-options
docs/owner-guide-and-delivery-plan
docs/phase1-policy-options
docs/public-review-live-2026-10-15
feat/aparat-learning-library
feat/child-device-safety
feat/child-identity-schema
feat/flutter-mobile-navigation
feat/learning-content-operations
feat/local-signing-preflight
feat/online-family-stage0
feat/personal-encrypted-recovery
feat/private-planner-series-api
feat/public-review-page
feat/standalone-weekly-planner
feat/weekly-planner-android
final-feature-1/iran-family-school
fix/auth-abuse-expiry-safety
fix/auth-expiry-after-lock
fix/backend-request-safety
fix/lifeguide-bootstrap-naming-ci
fix/lifeguide-pages-qa-base-preflight
fix/lifeguide-qa-pages-env-deployment
fix/local-task-persistence
fix/managed-child-session-boundary
fix/personal-jalali-dates
fix/personal-notification-controls
fix/personal-upgrade-delivery-guard
fix/sms-approval-gates
fix/study-duration-display
infra/cloudflare-neon-migration
infra/lifeguide-cloudflare-qa
infra/lifeguide-github-pages-qa
infra/lifeguide-supabase-qa
main
phase-1/foundation-completion
phase-2/product-foundation-identity
phase-3/planner-school-family-core
phase-4/ai-learning-wellbeing
phase-5/hardening-observability-release
test/android-reminder-acceptance
test/personal-notification-settings
test/personal-recovery-acceptance
test/role-entry-apk
| 1 | // Emulator-only test entry point. Never import from lib/ or distribute its APK. |
| 2 | // No API, credentials, identity or real server acknowledgement is involved. |
| 3 | import 'dart:convert'; |
| 4 | import 'package:flutter/foundation.dart'; |
| 5 | import 'package:flutter/material.dart'; |
| 6 | import 'package:lifemate/local_reminders.dart'; |
| 7 | |
| 8 | const owner = '11111111-1111-4111-8111-111111111111'; |
| 9 | const plan = '22222222-2222-4222-8222-222222222222'; |
| 10 | const reminder = '33333333-3333-4333-8333-333333333333'; |
| 11 | const scope = 'emulator-fixture-v1|$owner'; |
| 12 | const companion = 'LifeGuide EMULATOR FIXTURE'; |
| 13 | |
| 14 | /// The host additionally refuses physical devices and preinstalled packages. |
| 15 | /// Flags are injectable only to test this tool's fail-closed boundary. |
| 16 | Future<Map<String, Object?>> runFixture(String route, |
| 17 | {required bool enabled, |
| 18 | required bool debug, |
| 19 | required bool android, |
| 20 | DateTime Function()? now}) async { |
| 21 | if (!enabled || !debug || !android) { |
| 22 | throw StateError('fixture_disabled'); |
| 23 | } |
| 24 | final uri = Uri.tryParse(route); |
| 25 | const modes = {'/schedule', '/inspect', '/suppress', '/off'}; |
| 26 | if (uri == null || |
| 27 | uri.hasScheme || |
| 28 | uri.hasAuthority || |
| 29 | uri.hasFragment || |
| 30 | !modes.contains(uri.path) || |
| 31 | uri.queryParametersAll.entries.any((e) => |
| 32 | e.value.length != 1 || |
| 33 | !(e.key == 'nonce' || |
| 34 | (uri.path == '/schedule' && e.key == 'delay')))) { |
| 35 | throw ArgumentError('invalid_fixture_route'); |
| 36 | } |
| 37 | final nonce = uri.queryParameters['nonce'] ?? ''; |
| 38 | final delay = int.tryParse(uri.queryParameters['delay'] ?? '45'); |
| 39 | if (!RegExp(r'^[0-9a-f]{8,32}$').hasMatch(nonce) || |
| 40 | delay == null || |
| 41 | delay < 30 || |
| 42 | delay > 90) { |
| 43 | throw ArgumentError('invalid_fixture_metadata'); |
| 44 | } |
| 45 | final clock = now ?? DateTime.now; |
| 46 | final port = AndroidLocalReminderPort(now: clock); |
| 47 | DateTime? at; |
| 48 | switch (uri.path) { |
| 49 | case '/schedule': |
| 50 | final before = await port.status(); |
| 51 | if (!before.supported || !before.permissionGranted) { |
| 52 | throw StateError('fixture_permission_not_granted'); |
| 53 | } |
| 54 | await port.deactivate(); |
| 55 | final utc = clock().toUtc(); |
| 56 | at = utc.add(Duration(seconds: delay)); |
| 57 | await port.activate(scope, |
| 58 | validUntil: utc.add(const Duration(minutes: 10))); |
| 59 | await port.replace( |
| 60 | scope, |
| 61 | [ |
| 62 | LocalReminder( |
| 63 | id: reminder, |
| 64 | planItemId: plan, |
| 65 | scheduledAt: at, |
| 66 | companionName: companion, |
| 67 | ownerUserId: owner, |
| 68 | serverAcknowledged: true) |
| 69 | ], |
| 70 | currentUserId: owner); |
| 71 | case '/suppress': |
| 72 | await port.suppressPlanItems(scope, {plan}); |
| 73 | case '/off': |
| 74 | await port.deactivate(); |
| 75 | case '/inspect': |
| 76 | break; // Intentionally no activate: preserve the stored generation. |
| 77 | } |
| 78 | final status = await port.status(); |
| 79 | return { |
| 80 | 'nonce': nonce, |
| 81 | 'mode': uri.path.substring(1), |
| 82 | 'simulatedServerAcknowledgement': true, |
| 83 | if (at != null) 'scheduledAtEpochMs': at.millisecondsSinceEpoch, |
| 84 | 'status': { |
| 85 | 'supported': status.supported, |
| 86 | 'permissionGranted': status.permissionGranted, |
| 87 | 'active': status.active, |
| 88 | 'activeScope': status.activeScope, |
| 89 | 'scheduledCount': status.scheduledCount, |
| 90 | 'timing': status.timing, |
| 91 | 'canScheduleExactAlarms': status.canScheduleExactAlarms |
| 92 | } |
| 93 | }; |
| 94 | } |
| 95 | |
| 96 | Future<void> main() async { |
| 97 | final binding = WidgetsFlutterBinding.ensureInitialized(); |
| 98 | final route = binding.platformDispatcher.defaultRouteName; |
| 99 | const enabled = bool.fromEnvironment('LG_NATIVE_REMINDER_FIXTURE'); |
| 100 | final android = !kIsWeb && defaultTargetPlatform == TargetPlatform.android; |
| 101 | const label = 'EMULATOR ONLY — SYNTHETIC DATA — NOT THE APPLICATION'; |
| 102 | runApp(const MaterialApp( |
| 103 | initialRoute: '/', |
| 104 | home: Scaffold( |
| 105 | body: SafeArea( |
| 106 | child: Padding( |
| 107 | padding: EdgeInsets.all(24), |
| 108 | child: Text('$label\nSYNTHETIC_PRIVATE_TASK_CANARY')))))); |
| 109 | try { |
| 110 | final result = await runFixture(route, |
| 111 | enabled: enabled, debug: kDebugMode, android: android); |
| 112 | debugPrint('LG_NATIVE_REMINDER_FIXTURE ${jsonEncode(result)}'); |
| 113 | } catch (_) { |
| 114 | // Never dump native exceptions, routes or arbitrary storage into logs. |
| 115 | debugPrint('LG_NATIVE_REMINDER_FIXTURE_ERROR fixture_failed_closed'); |
| 116 | } |
| 117 | } |