LifeMate — Personal, Family & Learning Companion
feat/flutter-mobile-navigation
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/foundation.dart'; |
| 2 | import 'package:flutter/services.dart'; |
| 3 | import 'web_instance.dart'; |
| 4 | |
| 5 | /// Android process lifetime protection, independent of a Flutter engine/isolate. |
| 6 | /// An unconfirmed write can only be recovered by killing the Android process. |
| 7 | final class LocalWriteGuard { |
| 8 | const LocalWriteGuard(); |
| 9 | |
| 10 | static const _channel = MethodChannel('lifeguide/local_write_guard'); |
| 11 | bool get _native => |
| 12 | !kIsWeb && defaultTargetPlatform == TargetPlatform.android; |
| 13 | |
| 14 | Future<bool> getBlocked() async { |
| 15 | requireWebInstanceOwnership(); |
| 16 | if (!_native) return false; |
| 17 | // A missing/invalid native response must never grant access to cached data. |
| 18 | return await _channel.invokeMethod<bool>('getBlocked') ?? true; |
| 19 | } |
| 20 | |
| 21 | Future<String?> beginWrite() async { |
| 22 | requireWebInstanceOwnership(); |
| 23 | if (!_native) return null; |
| 24 | final token = await _channel.invokeMethod<String>('beginWrite'); |
| 25 | if (token == null || token.isEmpty) { |
| 26 | throw StateError('Native local write guard did not grant ownership'); |
| 27 | } |
| 28 | return token; |
| 29 | } |
| 30 | |
| 31 | Future<void> completeWrite(String? token) async { |
| 32 | requireWebInstanceOwnership(); |
| 33 | if (!_native) return; |
| 34 | if (token == null || |
| 35 | await _channel.invokeMethod<bool>('completeWrite', token) != true) { |
| 36 | throw StateError('Native local write guard did not confirm completion'); |
| 37 | } |
| 38 | } |
| 39 | } |