LifeMate — Personal, Family & Learning Companion
fix/local-task-persistence
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 | import 'package:flutter/services.dart'; |
| 2 | import 'package:flutter_test/flutter_test.dart'; |
| 3 | import 'package:shared_preferences/shared_preferences.dart'; |
| 4 | import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart'; |
| 5 | import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart'; |
| 6 | |
| 7 | /// Represents one native Android process, independent of Dart session instances. |
| 8 | final class MockNativeLocalWriteGuard { |
| 9 | String? _pending; |
| 10 | int _sequence = 0; |
| 11 | |
| 12 | bool get blocked => _pending != null; |
| 13 | |
| 14 | String beginWrite() { |
| 15 | if (blocked) { |
| 16 | throw PlatformException(code: 'local_storage_restart_required'); |
| 17 | } |
| 18 | return _pending = 'mock-owned-token-${++_sequence}'; |
| 19 | } |
| 20 | |
| 21 | bool completeWrite(String? token) { |
| 22 | if (token == null || token != _pending) return false; |
| 23 | _pending = null; |
| 24 | return true; |
| 25 | } |
| 26 | |
| 27 | Future<Object?> handle(MethodCall call) async => switch (call.method) { |
| 28 | 'getBlocked' => blocked, |
| 29 | 'beginWrite' => beginWrite(), |
| 30 | 'completeWrite' => completeWrite(call.arguments as String?), |
| 31 | _ => throw MissingPluginException(), |
| 32 | }; |
| 33 | } |
| 34 | |
| 35 | /// Only tests can simulate killing the native process; the app has no reset API. |
| 36 | MockNativeLocalWriteGuard resetNativeLocalWriteGuard() { |
| 37 | TestWidgetsFlutterBinding.ensureInitialized(); |
| 38 | final native = MockNativeLocalWriteGuard(); |
| 39 | TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger |
| 40 | .setMockMethodCallHandler( |
| 41 | const MethodChannel('lifeguide/local_write_guard'), native.handle); |
| 42 | return native; |
| 43 | } |
| 44 | |
| 45 | /// Unit/widget plugin substitutes only. Real Android integration never calls this. |
| 46 | void resetLocalPreferences([Map<String, Object> values = const {}]) { |
| 47 | resetNativeLocalWriteGuard(); |
| 48 | SharedPreferences.setMockInitialValues( |
| 49 | values); // legacy profile/production cache |
| 50 | SharedPreferencesAsyncPlatform.instance = |
| 51 | InMemorySharedPreferencesAsync.withData( |
| 52 | values); // local DataStore adapter |
| 53 | } |