π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Switch to flagService for mlConsent
Neeraj Gupta137a5cd77242
diff --git a/mobile/lib/services/machine_learning/ml_service.dart b/mobile/lib/services/machine_learning/ml_service.dartindex d6dcdb3bfc..be38b613b2 100644--- a/mobile/lib/services/machine_learning/ml_service.dart+++ b/mobile/lib/services/machine_learning/ml_service.dart@@ -21,7 +21,6 @@ import "package:photos/services/machine_learning/face_ml/person/person_service.dimport "package:photos/services/machine_learning/ml_indexing_isolate.dart";import 'package:photos/services/machine_learning/ml_result.dart';import "package:photos/services/machine_learning/semantic_search/semantic_search_service.dart";-import "package:photos/services/user_remote_flag_service.dart";import "package:photos/utils/ml_util.dart";import "package:photos/utils/network_util.dart";import "package:photos/utils/ram_check_util.dart";@@ -58,8 +57,7 @@ class MLService {/// Only call this function once at app startup, after that you can directly call [runAllML]Future<void> init() async {if (_isInitialized) return;- if (!userRemoteFlagService- .getCachedBoolValue(UserRemoteFlagService.mlEnabled)) {+ if (!flagService.hasGrantedMLConsent) {return;}_logger.info("init called");@@ -74,8 +72,7 @@ class MLService {// Listen on MachineLearningControllerBus.instance.on<MachineLearningControlEvent>().listen((event) {- if (!userRemoteFlagService- .getCachedBoolValue(UserRemoteFlagService.mlEnabled)) {+ if (!flagService.hasGrantedMLConsent) {return;}diff --git a/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dart b/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dartindex df56796cd1..4e881e718d 100644--- a/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dart+++ b/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dart@@ -21,7 +21,6 @@ import "package:photos/services/collections_service.dart";import "package:photos/services/machine_learning/ml_computer.dart";import "package:photos/services/machine_learning/ml_result.dart";import "package:photos/services/machine_learning/semantic_search/clip/clip_image_encoder.dart";-import "package:photos/services/user_remote_flag_service.dart";import "package:shared_preferences/shared_preferences.dart";class SemanticSearchService {@@ -48,8 +47,7 @@ class SemanticSearchService {_logger.info("Initialized already");return;}- final hasGivenConsent = userRemoteFlagService- .getCachedBoolValue(UserRemoteFlagService.mlEnabled);+ final hasGivenConsent = flagService.hasGrantedMLConsent;if (!hasGivenConsent) return;_logger.info("init called");@@ -67,9 +65,7 @@ class SemanticSearchService {}bool isMagicSearchEnabledAndReady() {- return userRemoteFlagService- .getCachedBoolValue(UserRemoteFlagService.mlEnabled) &&- _textModelIsLoaded;+ return flagService.hasGrantedMLConsent && _textModelIsLoaded;}// searchScreenQuery should only be used for the user initiate query on the search screen.@@ -78,7 +74,7 @@ class SemanticSearchService {if (!isMagicSearchEnabledAndReady()) {if (flagService.internalUser) {_logger.info(- "ML global consent: ${userRemoteFlagService.getCachedBoolValue(UserRemoteFlagService.mlEnabled)}, loaded: $_textModelIsLoaded ",+ "ML global consent: ${flagService.hasGrantedMLConsent}, loaded: $_textModelIsLoaded ",);}return (query, <EnteFile>[]);diff --git a/mobile/lib/services/magic_cache_service.dart b/mobile/lib/services/magic_cache_service.dartindex fc9d02a0a9..70379590c5 100644--- a/mobile/lib/services/magic_cache_service.dart+++ b/mobile/lib/services/magic_cache_service.dart@@ -23,7 +23,6 @@ import "package:photos/service_locator.dart";import "package:photos/services/machine_learning/semantic_search/semantic_search_service.dart";import "package:photos/services/remote_assets_service.dart";import "package:photos/services/search_service.dart";-import "package:photos/services/user_remote_flag_service.dart";import "package:photos/ui/viewer/search/result/magic_result_screen.dart";import "package:photos/utils/file_util.dart";import "package:photos/utils/navigation_util.dart";@@ -203,8 +202,7 @@ class MagicCacheService {return _prefs.getInt(_lastMagicCacheUpdateTime) ?? 0;}- bool get enableDiscover =>- userRemoteFlagService.getCachedBoolValue(UserRemoteFlagService.mlEnabled);+ bool get enableDiscover => flagService.hasGrantedMLConsent;void queueUpdate(String reason) {_pendingUpdateReason.add(reason);diff --git a/mobile/lib/services/search_service.dart b/mobile/lib/services/search_service.dartindex 62576eae03..8274db3b0a 100644--- a/mobile/lib/services/search_service.dart+++ b/mobile/lib/services/search_service.dart@@ -45,7 +45,6 @@ import "package:photos/services/machine_learning/face_ml/face_filtering/face_filimport "package:photos/services/machine_learning/face_ml/person/person_service.dart";import "package:photos/services/machine_learning/ml_computer.dart";import 'package:photos/services/machine_learning/semantic_search/semantic_search_service.dart';-import "package:photos/services/user_remote_flag_service.dart";import "package:photos/services/user_service.dart";import "package:photos/states/location_screen_state.dart";import "package:photos/ui/viewer/location/add_location_sheet.dart";@@ -249,8 +248,7 @@ class SearchService {Future<List<GenericSearchResult>> getMagicSectionResults(BuildContext context,) async {- if (userRemoteFlagService- .getCachedBoolValue(UserRemoteFlagService.mlEnabled)) {+ if (flagService.hasGrantedMLConsent) {return magicCacheService.getMagicGenericSearchResult(context);} else {return <GenericSearchResult>[];diff --git a/mobile/lib/services/user_remote_flag_service.dart b/mobile/lib/services/user_remote_flag_service.dartindex 71e9936526..0c8961fbd1 100644--- a/mobile/lib/services/user_remote_flag_service.dart+++ b/mobile/lib/services/user_remote_flag_service.dart@@ -7,7 +7,6 @@ import "package:flutter/foundation.dart";import 'package:logging/logging.dart';import 'package:photos/core/event_bus.dart';import 'package:photos/events/notification_event.dart';-import "package:photos/service_locator.dart";import 'package:photos/services/user_service.dart';import 'package:shared_preferences/shared_preferences.dart';@@ -17,7 +16,6 @@ class UserRemoteFlagService {final SharedPreferences _prefs;static const String recoveryVerificationFlag = "recoveryKeyVerified";- static const String mlEnabled = "faceSearchEnabled";static const String needRecoveryKeyVerification ="needRecoveryKeyVerification";@@ -40,19 +38,6 @@ class UserRemoteFlagService {}}- bool getCachedBoolValue(String key) {- bool defaultValue = false;- if (key == mlEnabled) {- defaultValue = flagService.hasGrantedMLConsent;- }- return _prefs.getBool(key) ?? defaultValue;- }-- Future<bool> setBoolValue(String key, bool value) async {- await _updateKeyValue(key, value.toString());- return _prefs.setBool(key, value);- }-// markRecoveryVerificationAsDone is used to track if user has verified their// recovery key in the past or not. This helps in avoid showing the same// prompt to the user on re-install or signing into a different devicediff --git a/mobile/lib/ui/home/status_bar_widget.dart b/mobile/lib/ui/home/status_bar_widget.dartindex e967d7b0b5..a36f2f75a5 100644--- a/mobile/lib/ui/home/status_bar_widget.dart+++ b/mobile/lib/ui/home/status_bar_widget.dart@@ -13,7 +13,6 @@ import "package:photos/models/preview/preview_item_status.dart";import "package:photos/service_locator.dart";import "package:photos/services/preview_video_store.dart";import 'package:photos/services/sync_service.dart';-import "package:photos/services/user_remote_flag_service.dart";import "package:photos/theme/ente_theme.dart";import 'package:photos/theme/text_style.dart';import 'package:photos/ui/account/verify_recovery_page.dart';@@ -43,8 +42,7 @@ class _StatusBarWidgetState extends State<StatusBarWidget> {bool _showStatus = false;bool _showErrorBanner = false;- bool _showMlBanner = !userRemoteFlagService- .getCachedBoolValue(UserRemoteFlagService.mlEnabled) &&+ bool _showMlBanner = !flagService.hasGrantedMLConsent &&!localSettings.hasSeenMLEnablingBanner;Error? _syncError;@@ -81,8 +79,7 @@ class _StatusBarWidgetState extends State<StatusBarWidget> {_notificationSubscription =Bus.instance.on<NotificationEvent>().listen((event) {if (mounted) {- _showMlBanner = !userRemoteFlagService- .getCachedBoolValue(UserRemoteFlagService.mlEnabled) &&+ _showMlBanner = !flagService.hasGrantedMLConsent &&!localSettings.hasSeenMLEnablingBanner;setState(() {});}diff --git a/mobile/lib/ui/settings/debug/ml_debug_section_widget.dart b/mobile/lib/ui/settings/debug/ml_debug_section_widget.dartindex d89ee548a1..e0cdf1cdad 100644--- a/mobile/lib/ui/settings/debug/ml_debug_section_widget.dart+++ b/mobile/lib/ui/settings/debug/ml_debug_section_widget.dart@@ -11,7 +11,6 @@ import "package:photos/services/machine_learning/face_ml/person/person_service.dimport "package:photos/services/machine_learning/ml_indexing_isolate.dart";import 'package:photos/services/machine_learning/ml_service.dart';import "package:photos/services/machine_learning/semantic_search/semantic_search_service.dart";-import "package:photos/services/user_remote_flag_service.dart";import 'package:photos/theme/ente_theme.dart';import 'package:photos/ui/components/captioned_text_widget.dart';import 'package:photos/ui/components/expandable_menu_item_widget.dart';@@ -81,17 +80,12 @@ class _MLDebugSectionWidgetState extends State<MLDebugSectionWidget> {},),trailingWidget: ToggleSwitchWidget(- value: () => userRemoteFlagService- .getCachedBoolValue(UserRemoteFlagService.mlEnabled),+ value: () => flagService.hasGrantedMLConsent,onChanged: () async {try {- final oldMlConsent = userRemoteFlagService- .getCachedBoolValue(UserRemoteFlagService.mlEnabled);+ final oldMlConsent = flagService.hasGrantedMLConsent;final mlConsent = !oldMlConsent;- await userRemoteFlagService.setBoolValue(- UserRemoteFlagService.mlEnabled,- mlConsent,- );+ await flagService.setMLConsent(mlConsent);logger.info('ML consent turned ${mlConsent ? 'on' : 'off'}');if (!mlConsent) {MLService.instance.pauseIndexingAndClustering();diff --git a/mobile/lib/ui/settings/ml/enable_ml_consent.dart b/mobile/lib/ui/settings/ml/enable_ml_consent.dartindex 972858c3d7..c828e9d36b 100644--- a/mobile/lib/ui/settings/ml/enable_ml_consent.dart+++ b/mobile/lib/ui/settings/ml/enable_ml_consent.dart@@ -3,7 +3,6 @@ import "package:photos/core/event_bus.dart";import "package:photos/events/notification_event.dart";import "package:photos/generated/l10n.dart";import "package:photos/service_locator.dart";-import "package:photos/services/user_remote_flag_service.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/common/web_page.dart";import "package:photos/ui/components/buttons/button_widget.dart";@@ -153,10 +152,7 @@ class _EnableMachineLearningConsentStateFuture<void> enableMlConsent(BuildContext context) async {try {- await userRemoteFlagService.setBoolValue(- UserRemoteFlagService.mlEnabled,- true,- );+ await flagService.setMLConsent(true);Bus.instance.fire(NotificationEvent());Navigator.of(context).pop(true);} catch (e) {diff --git a/mobile/lib/ui/settings/ml/machine_learning_settings_page.dart b/mobile/lib/ui/settings/ml/machine_learning_settings_page.dartindex 0ebe3656ba..ad4f87821a 100644--- a/mobile/lib/ui/settings/ml/machine_learning_settings_page.dart+++ b/mobile/lib/ui/settings/ml/machine_learning_settings_page.dart@@ -12,7 +12,6 @@ import "package:photos/services/machine_learning/semantic_search/clip/clip_imageimport "package:photos/services/machine_learning/semantic_search/clip/clip_text_encoder.dart";import 'package:photos/services/machine_learning/semantic_search/semantic_search_service.dart';import "package:photos/services/remote_assets_service.dart";-import "package:photos/services/user_remote_flag_service.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/common/loading_widget.dart";import "package:photos/ui/common/web_page.dart";@@ -77,8 +76,7 @@ class _MachineLearningSettingsPageState@overrideWidget build(BuildContext context) {- final hasEnabled = userRemoteFlagService- .getCachedBoolValue(UserRemoteFlagService.mlEnabled);+ final hasEnabled = flagService.hasGrantedMLConsent;return Scaffold(body: CustomScrollView(primary: false,@@ -211,8 +209,7 @@ class _MachineLearningSettingsPageState}Future<void> toggleMlConsent() async {- final oldMlConsent = userRemoteFlagService- .getCachedBoolValue(UserRemoteFlagService.mlEnabled);+ final oldMlConsent = flagService.hasGrantedMLConsent;// Go to consent page first if not enabledif (!oldMlConsent) {final result = await Navigator.push(@@ -228,10 +225,7 @@ class _MachineLearningSettingsPageState}}final mlConsent = !oldMlConsent;- await userRemoteFlagService.setBoolValue(- UserRemoteFlagService.mlEnabled,- mlConsent,- );+ await flagService.setMLConsent(mlConsent);if (!mlConsent) {MLService.instance.pauseIndexingAndClustering();unawaited(@@ -248,8 +242,7 @@ class _MachineLearningSettingsPageState}Widget _getMlSettings(BuildContext context) {- final hasEnabled = userRemoteFlagService- .getCachedBoolValue(UserRemoteFlagService.mlEnabled);+ final hasEnabled = flagService.hasGrantedMLConsent;if (!hasEnabled) {return const SizedBox.shrink();}diff --git a/mobile/lib/ui/viewer/file/file_details_widget.dart b/mobile/lib/ui/viewer/file/file_details_widget.dartindex 1138908860..12f722b357 100644--- a/mobile/lib/ui/viewer/file/file_details_widget.dart+++ b/mobile/lib/ui/viewer/file/file_details_widget.dart@@ -19,7 +19,6 @@ import "package:photos/models/metadata/file_magic.dart";import "package:photos/service_locator.dart";import "package:photos/services/file_magic_service.dart";import "package:photos/services/filedata/filedata_service.dart";-import "package:photos/services/user_remote_flag_service.dart";import 'package:photos/theme/ente_theme.dart';import 'package:photos/ui/components/buttons/icon_button_widget.dart';import "package:photos/ui/components/divider_widget.dart";@@ -298,8 +297,7 @@ class _FileDetailsWidgetState extends State<FileDetailsWidget> {]);}- if (userRemoteFlagService- .getCachedBoolValue(UserRemoteFlagService.mlEnabled)) {+ if (flagService.hasGrantedMLConsent) {fileDetailsTiles.addAll([FacesItemWidget(file),const FileDetailsDivider(),diff --git a/mobile/lib/ui/viewer/search_tab/search_tab.dart b/mobile/lib/ui/viewer/search_tab/search_tab.dartindex 27e3f46830..ec616f7ec4 100644--- a/mobile/lib/ui/viewer/search_tab/search_tab.dart+++ b/mobile/lib/ui/viewer/search_tab/search_tab.dart@@ -10,7 +10,6 @@ import "package:photos/models/search/index_of_indexed_stack.dart";import "package:photos/models/search/search_result.dart";import "package:photos/models/search/search_types.dart";import "package:photos/service_locator.dart";-import "package:photos/services/user_remote_flag_service.dart";import "package:photos/states/all_sections_examples_state.dart";import "package:photos/ui/common/loading_widget.dart";import "package:photos/ui/viewer/search/result/no_result_widget.dart";@@ -119,9 +118,7 @@ class _AllSearchSectionsState extends State<AllSearchSections> {itemBuilder: (context, index) {switch (searchTypes[index]) {case SectionType.face:- if (!userRemoteFlagService.getCachedBoolValue(- UserRemoteFlagService.mlEnabled,- )) {+ if (!flagService.hasGrantedMLConsent) {return const SizedBox.shrink();}return PeopleSection(diff --git a/mobile/plugins/ente_feature_flag/lib/src/service.dart b/mobile/plugins/ente_feature_flag/lib/src/service.dartindex 0b011f01eb..b6e99eb0b5 100644--- a/mobile/plugins/ente_feature_flag/lib/src/service.dart+++ b/mobile/plugins/ente_feature_flag/lib/src/service.dart@@ -60,6 +60,16 @@ class FlagService {String get castUrl => flags.castUrl;+ Future<void> setMapEnabled(bool isEnabled) async {+ await _updateKeyValue("mapEnabled", isEnabled.toString());+ _updateFlags(flags.copyWith(mapEnabled: isEnabled));+ }++ Future<void> setMLConsent(bool isEnabled) async {+ await _updateKeyValue("faceSearchEnabled", isEnabled.toString());+ _updateFlags(flags.copyWith(faceSearchEnabled: isEnabled));+ }+Completer<void>? _fetchCompleter;Future<void> _fetch() async {if (_fetchCompleter != null) {@@ -105,11 +115,6 @@ class FlagService {}}- Future<void> setMapEnabled(bool isEnabled) async {- await _updateKeyValue("mapEnabled", isEnabled.toString());- _updateFlags(flags.copyWith(mapEnabled: isEnabled));- }-void _updateFlags(RemoteFlags flags) {_flags = flags;_prefs.setString("remote_flags", flags.toJson());