π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] clean-up feature flag checks for memory lane
Priyanshu Dangareff75692587ad
diff --git a/mobile/apps/photos/lib/main.dart b/mobile/apps/photos/lib/main.dartindex f8e0d86bb3..3863b386fc 100644--- a/mobile/apps/photos/lib/main.dart+++ b/mobile/apps/photos/lib/main.dart@@ -181,7 +181,13 @@ Future<void> _runInForeground(}WidgetsBinding.instance.addPostFrameCallback((_) {unawaited(SemanticSearchService.instance.init());- unawaited(_warmForegroundDeferredServices());+ unawaited(MemoryLaneService.instance.init());+ unawaited(+ Future.delayed(+ const Duration(seconds: 5),+ installSourceService.autoAttributePendingSource,+ ),+ );});unawaited(_scheduleFGSync('appStart in FG'));});@@ -198,26 +204,6 @@ Future<void> _warmPickerFilesDb() async {}}-Future<void> _warmForegroundDeferredServices() async {- try {- final memoryLaneService = MemoryLaneService.instance;- if (memoryLaneService.isFeatureEnabled) {- await memoryLaneService.init();- memoryLaneService.queueFullRecompute().ignore();- } else {- _logger.info("Memory Lane disabled");- }- } catch (e, s) {- _logger.warning("Deferred MemoryLaneService warm failed", e, s);- }- unawaited(- Future.delayed(- const Duration(seconds: 5),- installSourceService.autoAttributePendingSource,- ),- );-}-ThemeMode _themeMode(AdaptiveThemeMode? savedThemeMode) {if (savedThemeMode == null) return ThemeMode.system;if (savedThemeMode.isLight) return ThemeMode.light;diff --git a/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dart b/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dartindex 4552d597b4..677650ef33 100644--- a/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dart+++ b/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dart@@ -40,7 +40,7 @@ int? eligibleCreationTimeCutoffMicros(String? birthDateString) {}class MemoryLaneService {- MemoryLaneService._internal() : _enabledForSession = hasGrantedMLConsent;+ MemoryLaneService._internal();static final MemoryLaneService instance = MemoryLaneService._internal();@@ -74,16 +74,11 @@ class MemoryLaneService {final Map<String, bool> _pendingRequests = {};final Set<String> _cropReadinessInFlight = {};- bool _enabledForSession;bool _initialized = false;Timer? _startupBackfillTimer;- bool get isFeatureEnabled =>- _enabledForSession && flagService.facesTimeline && hasGrantedMLConsent;-Future<void> init() async {- if (!isFeatureEnabled) throw StateError("Memory Lane is disabled");if (_initialized) return;await _cacheService.init();await _cacheService.ensureComputeLogVersion(_timelineLogicVersion);@@ -91,18 +86,22 @@ class MemoryLaneService {Bus.instance.on<PeopleChangedEvent>().listen(_handlePeopleChange);Bus.instance.on<MLConsentChangedEvent>().listen(_handleMlConsentChange);_scheduleStartupBackfill();+ unawaited(_queueFullRecompute());_initialized = true;}void _handleMlConsentChange(MLConsentChangedEvent event) {- if (event.enabled) return;- _enabledForSession = false;+ if (event.enabled) {+ _scheduleStartupBackfill();+ unawaited(_queueFullRecompute());+ return;+ }_startupBackfillTimer?.cancel();_startupBackfillTimer = null;}- Future<void> queueFullRecompute({bool force = false}) async {- if (!isFeatureEnabled) throw StateError("Memory Lane is disabled");+ Future<void> _queueFullRecompute({bool force = false}) async {+ if (!hasGrantedMLConsent) return;if (!PersonService.isInitialized) {_logger.warning("Memory Lane full recompute skipped: PersonService not initialized",@@ -120,7 +119,6 @@ class MemoryLaneService {}void schedulePersonRecompute(String personId, {bool force = false}) {- if (!isFeatureEnabled) throw StateError("Memory Lane is disabled");if (personId.isEmpty) return;_pendingRequests[personId] = (_pendingRequests[personId] ?? false) || force;_precomputeQueue@@ -139,7 +137,7 @@ class MemoryLaneService {}Future<void> ensureTimelineReachability(String personId) async {- if (!isFeatureEnabled) throw StateError("Memory Lane is disabled");+ if (!hasGrantedMLConsent) return;if (personId.isEmpty) {return;}@@ -158,7 +156,7 @@ class MemoryLaneService {}Future<MemoryLanePersonTimeline?> getTimeline(String personId) async {- if (!isFeatureEnabled) throw StateError("Memory Lane is disabled");+ if (!hasGrantedMLConsent) throw StateError("Memory Lane is disabled");final timeline = await _cacheService.getTimeline(personId);if (timeline == null || timeline.entries.isEmpty) {return timeline;@@ -194,7 +192,7 @@ class MemoryLaneService {}bool hasReadyTimelineSync(String personId) {- if (!isFeatureEnabled) throw StateError("Memory Lane is disabled");+ if (!hasGrantedMLConsent) throw StateError("Memory Lane is disabled");return readyPersonIds.value.contains(personId);}@@ -307,7 +305,7 @@ class MemoryLaneService {}void _handlePeopleChange(PeopleChangedEvent event) {- if (!isFeatureEnabled) return;+ if (!hasGrantedMLConsent) return;if (event.type == PeopleEventType.syncDone) {return;}@@ -406,6 +404,7 @@ class MemoryLaneService {}Future<void> _runStartupBackfill() async {+ if (!hasGrantedMLConsent) return;if (!PersonService.isInitialized) {_logger.warning("Memory Lane startup diff skipped: PersonService not initialized",@@ -515,6 +514,7 @@ class MemoryLaneService {String personId, {required bool force,}) async {+ if (!hasGrantedMLConsent) return;if (!PersonService.isInitialized) {_logger.warning("Memory Lane recompute skipped for $personId: PersonService not initialized",@@ -836,7 +836,7 @@ class MemoryLaneService {String personId, {int frameCount = 6,}) async {- if (!isFeatureEnabled) throw StateError("Memory Lane is disabled");+ if (!hasGrantedMLConsent) return;try {final timeline = await _cacheService.getTimeline(personId);if (timeline == null || !timeline.isReady || timeline.entries.isEmpty) {diff --git a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_debug_panel.dart b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_debug_panel.dartdeleted file mode 100644index 45e2366643..0000000000--- a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_debug_panel.dart+++ /dev/null@@ -1,227 +0,0 @@-import "dart:async";--import "package:flutter/foundation.dart";-import "package:flutter/material.dart";-import "package:photos/core/event_bus.dart";-import "package:photos/events/memory_lane_changed_event.dart";-import "package:photos/models/memory_lane/memory_lane_models.dart";-import "package:photos/services/memory_lane/memory_lane_cache_service.dart";-import "package:photos/services/memory_lane/memory_lane_service.dart";-import "package:photos/theme/ente_theme.dart";--class MemoryLaneDebugPanel extends StatefulWidget {- final String personId;-- const MemoryLaneDebugPanel({required this.personId, super.key});-- @override- State<MemoryLaneDebugPanel> createState() => _MemoryLaneDebugPanelState();-}--class _MemoryLaneDebugPanelState extends State<MemoryLaneDebugPanel> {- MemoryLanePersonTimeline? _timeline;- bool _loading = false;- String? _error;- String? _info;- StreamSubscription<MemoryLaneChangedEvent>? _timelineSubscription;-- bool get _featureEnabled => MemoryLaneService.instance.isFeatureEnabled;-- @override- void initState() {- super.initState();- if (kDebugMode && _featureEnabled) {- _reloadTimeline();- _timelineSubscription = Bus.instance.on<MemoryLaneChangedEvent>().listen(- _handleTimelineChanged,- );- }- }-- @override- void dispose() {- _timelineSubscription?.cancel();- super.dispose();- }-- void _handleTimelineChanged(MemoryLaneChangedEvent event) {- if (event.personId != widget.personId) return;- _reloadTimeline();- }-- Future<void> _reloadTimeline() async {- if (!mounted) return;- setState(() {- _loading = true;- _error = null;- });- try {- final timeline = await MemoryLaneService.instance.getTimeline(- widget.personId,- );- if (!mounted) return;- setState(() {- _timeline = timeline;- });- } catch (error) {- if (!mounted) return;- setState(() {- _error = "$error";- });- } finally {- if (mounted) {- setState(() {- _loading = false;- });- }- }- }-- Future<void> _forceRecompute() async {- MemoryLaneService.instance.schedulePersonRecompute(- widget.personId,- force: true,- );- if (!mounted) return;- setState(() {- _info =- "Recompute queued at ${DateTime.now().toLocal().toIso8601String()}";- });- }-- Future<void> _clearTimeline() async {- setState(() {- _loading = true;- _error = null;- });- try {- await MemoryLaneCacheService.instance.removeTimeline(widget.personId);- await _reloadTimeline();- if (!mounted) return;- setState(() {- _info =- "Timeline cache cleared at ${DateTime.now().toLocal().toIso8601String()}";- });- } catch (error) {- if (!mounted) return;- setState(() {- _error = "$error";- });- } finally {- if (mounted) {- setState(() {- _loading = false;- });- }- }- }-- @override- Widget build(BuildContext context) {- if (!kDebugMode || !_featureEnabled) return const SizedBox.shrink();- final colorScheme = getEnteColorScheme(context);- final textTheme = getEnteTextTheme(context);- final timeline = _timeline;- final bool inReadySet = MemoryLaneService.instance.hasReadyTimelineSync(- widget.personId,- );- final DateTime? updatedAt = timeline == null- ? null- : DateTime.fromMicrosecondsSinceEpoch(- timeline.updatedAtMicros,- ).toLocal();- final int uniqueYears = timeline == null- ? 0- : timeline.entries.map((entry) => entry.year).toSet().length;-- return Padding(- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),- child: Container(- padding: const EdgeInsets.all(16),- decoration: BoxDecoration(- color: colorScheme.fillFaint,- borderRadius: BorderRadius.circular(12),- border: Border.all(color: colorScheme.strokeFaint),- ),- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Row(- children: [- Icon(Icons.bug_report_outlined, color: colorScheme.primary500),- const SizedBox(width: 8),- Text("Faces timeline debug", style: textTheme.bodyBold),- const Spacer(),- IconButton(- onPressed: _loading ? null : _reloadTimeline,- tooltip: "Refresh timeline",- icon: _loading- ? SizedBox(- width: 16,- height: 16,- child: CircularProgressIndicator(- strokeWidth: 2,- color: colorScheme.primary500,- ),- )- : const Icon(Icons.refresh),- ),- ],- ),- const SizedBox(height: 12),- if (_error != null)- Text(- _error!,- style: textTheme.miniMuted.copyWith(- color: colorScheme.warning500,- ),- ),- if (_info != null)- Padding(- padding: const EdgeInsets.only(bottom: 8),- child: Text(- _info!,- style: textTheme.miniMuted.copyWith(- color: colorScheme.primary500,- ),- ),- ),- Text(- "Status: ${timeline == null ? "missing" : timeline.status.name}",- style: textTheme.miniMuted,- ),- Text(- "Ready set contains person: ${inReadySet ? "yes" : "no"}",- style: textTheme.miniMuted,- ),- Text(- "Entries: ${timeline?.entries.length ?? 0} β’ Years: $uniqueYears",- style: textTheme.miniMuted,- ),- Text(- "Updated: ${updatedAt?.toIso8601String() ?? "n/a"}",- style: textTheme.miniMuted,- ),- const SizedBox(height: 12),- Wrap(- spacing: 8,- runSpacing: 8,- children: [- FilledButton(- onPressed: _loading ? null : _forceRecompute,- child: const Text("Force recompute"),- ),- FilledButton.tonal(- onPressed: _loading || timeline == null- ? null- : _clearTimeline,- child: const Text("Clear cache entry"),- ),- ],- ),- ],- ),- ),- );- }-}diff --git a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page.dart b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page.dartindex b94f2f00e0..74ba59d469 100644--- a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page.dart@@ -109,9 +109,8 @@ class _MemoryLanePageState extends State<MemoryLanePage>int _currentCaptionValue = 0;_CaptionType _currentCaptionType = _CaptionType.yearsAgo;int _maxCaptionDigits = 1;- bool get _featureEnabled => MemoryLaneService.instance.isFeatureEnabled;bool get _showShareAction =>- _featureEnabled &&+ hasGrantedMLConsent &&flagService.enableMemoryShareLink &&!isLocalGalleryMode;@@ -123,7 +122,7 @@ class _MemoryLanePageState extends State<MemoryLanePage>..addListener(_onCardAnimationTick)..addStatusListener(_onCardAnimationStatusChanged);_stackProgressNotifier = ValueNotifier<double>(_stackProgress);- if (_featureEnabled) {+ if (hasGrantedMLConsent) {unawaited(_loadFrames());} else {_timelineUnavailable = true;@@ -600,7 +599,7 @@ class _MemoryLanePageState extends State<MemoryLanePage>@overrideWidget build(BuildContext context) {- if (!_featureEnabled) {+ if (!hasGrantedMLConsent) {final l10n = context.strings;final colorScheme = getEnteColorScheme(context);final textTheme = getEnteTextTheme(context);diff --git a/mobile/apps/photos/lib/ui/viewer/people/people_page.dart b/mobile/apps/photos/lib/ui/viewer/people/people_page.dartindex 29dd7b6e8d..a9f98bebce 100644--- a/mobile/apps/photos/lib/ui/viewer/people/people_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/people_page.dart@@ -31,7 +31,6 @@ import "package:photos/ui/viewer/gallery/state/inherited_search_filter_data.dartimport "package:photos/ui/viewer/gallery/state/search_filter_data_provider.dart";import "package:photos/ui/viewer/gallery/state/selection_state.dart";import "package:photos/ui/viewer/people/memory_lane_banner.dart";-import "package:photos/ui/viewer/people/memory_lane_debug_panel.dart";import "package:photos/ui/viewer/people/memory_lane_page.dart";import "package:photos/ui/viewer/people/people_app_bar.dart";import "package:photos/ui/viewer/people/person_gallery_suggestion.dart";@@ -72,7 +71,7 @@ class _PeoplePageState extends State<PeoplePage> {bool _memoryLanePrewarmStarted = false;bool _isTryingToPopDeletedPersonPage = false;- bool get _memoryLaneEnabled => MemoryLaneService.instance.isFeatureEnabled;+ bool get _memoryLaneEnabled => hasGrantedMLConsent;@overridevoid initState() {@@ -388,8 +387,6 @@ class _GalleryState extends State<_Gallery> {personId: widget.personEntity.remoteID,onTap: widget.memoryLaneEnabled ? widget.onTimelineTap : null,),- if (widget.memoryLaneEnabled)- MemoryLaneDebugPanel(personId: widget.personEntity.remoteID),!userDismissedPersonGallerySuggestion? Dismissible(key: const Key("personGallerySuggestion"),