Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mobile][photos] Surface ML decryption failures

laurensprieme7fddbc7a144
diff --git a/mobile/apps/photos/lib/service_locator.dart b/mobile/apps/photos/lib/service_locator.dart
index 8aeeea1057..d7e182fba1 100644
--- a/mobile/apps/photos/lib/service_locator.dart
+++ b/mobile/apps/photos/lib/service_locator.dart
@@ -35,6 +35,7 @@ import "package:photos/services/library_sharing_service.dart";
import "package:photos/services/library_sharing_store.dart";
import "package:photos/services/location_service.dart";
import "package:photos/services/machine_learning/compute_controller.dart";
+import "package:photos/services/machine_learning/ml_decryption_record_store.dart";
import "package:photos/services/magic_cache_service.dart";
import "package:photos/services/memories_cache_service.dart";
import "package:photos/services/permission/service.dart";
@@ -62,6 +63,7 @@ class ServiceLocator {
late final LocalSettings localSettings;
late final BackupSettings backupSettings;
late final EnteWakeLockService wakeLockService;
+ late final MlDecryptionRecordStore mlDecryptionRecordStore;
ServiceLocator._privateConstructor();
@@ -83,6 +85,7 @@ class ServiceLocator {
localSettings = LocalSettings(prefs);
backupSettings = BackupSettings(prefs);
wakeLockService = EnteWakeLockService();
+ mlDecryptionRecordStore = MlDecryptionRecordStore(prefs);
}
}
@@ -123,6 +126,9 @@ BackupSettings get backupSettings => ServiceLocator.instance.backupSettings;
EnteWakeLockService get wakeLockService =>
ServiceLocator.instance.wakeLockService;
+MlDecryptionRecordStore get mlDecryptionRecordStore =>
+ ServiceLocator.instance.mlDecryptionRecordStore;
+
// True when showing local-device photos instead of an Ente account. Network
// access may still be used.
bool get isLocalGalleryMode => localSettings.isLocalGalleryMode;
diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_decryption_record_store.dart b/mobile/apps/photos/lib/services/machine_learning/ml_decryption_record_store.dart
new file mode 100644
index 0000000000..c17c9d4dda
--- /dev/null
+++ b/mobile/apps/photos/lib/services/machine_learning/ml_decryption_record_store.dart
@@ -0,0 +1,58 @@
+import "package:logging/logging.dart";
+import "package:shared_preferences/shared_preferences.dart";
+import "package:synchronized/synchronized.dart";
+
+class MlDecryptionRecordStore {
+ static const _preferenceKey = "ml_decryption_record_file_ids";
+
+ final SharedPreferences _preferences;
+ final Lock _lock = Lock();
+ final Logger _logger = Logger("MlDecryptionRecordStore");
+
+ MlDecryptionRecordStore(this._preferences);
+
+ List<int> get fileIDs {
+ final result = <int>{};
+ for (final value
+ in _preferences.getStringList(_preferenceKey) ?? const []) {
+ final fileID = int.tryParse(value);
+ if (fileID != null) {
+ result.add(fileID);
+ }
+ }
+ return result.toList()..sort();
+ }
+
+ int get count => fileIDs.length;
+
+ Future<void> add(int fileID) async {
+ await _lock.synchronized(() async {
+ final updatedFileIDs = fileIDs.toSet();
+ if (!updatedFileIDs.add(fileID)) {
+ return;
+ }
+ final values = updatedFileIDs.toList()..sort();
+ try {
+ final stored = await _preferences.setStringList(
+ _preferenceKey,
+ values.map((id) => id.toString()).toList(),
+ );
+ if (!stored) {
+ _logger.warning(
+ "Failed to store ML decryption record for fileID $fileID",
+ );
+ }
+ } catch (error, stackTrace) {
+ _logger.warning(
+ "Failed to store ML decryption record for fileID $fileID",
+ error,
+ stackTrace,
+ );
+ }
+ });
+ }
+
+ void logFileIDs() {
+ _logger.info("ML decryption record fileIDs: $fileIDs");
+ }
+}
diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
index 67e4bc7ce8..15b92546a0 100644
--- a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
@@ -27,6 +27,7 @@ import "package:photos/services/machine_learning/face_ml/face_clustering/face_cl
import "package:photos/services/machine_learning/face_ml/face_clustering/face_db_info_for_clustering.dart";
import "package:photos/services/machine_learning/face_ml/face_detection/detection.dart";
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
+import "package:photos/services/machine_learning/ml_exceptions.dart";
import "package:photos/services/machine_learning/ml_indexing_isolate.dart";
import "package:photos/services/machine_learning/ml_model_download_service.dart";
import "package:photos/services/machine_learning/ml_process_lock.dart";
@@ -1081,6 +1082,9 @@ class MLService {
_logger.info(
"Stored empty ML result markers for fileID ${instruction.fileKey}: ${storedMarkers.join(', ')}",
);
+ if (e is RepeatedFileDecryptionError) {
+ await mlDecryptionRecordStore.add(instruction.fileKey);
+ }
indexedOrSkipped = true;
return true;
}
diff --git a/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dart b/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dart
index fb10ca3c5c..093bf501ab 100644
--- a/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dart
@@ -18,6 +18,7 @@ import "package:photos/services/remote_assets_service.dart";
import "package:photos/services/wake_lock_service.dart";
import "package:photos/ui/common/web_page.dart";
import "package:photos/ui/settings/ml/ml_user_dev_screen.dart";
+import "package:photos/utils/email_util.dart";
import "package:photos/utils/ml_util.dart";
import "package:photos/utils/network_util.dart";
@@ -40,6 +41,7 @@ class _MachineLearningSettingsPageState
@override
void initState() {
super.initState();
+ mlDecryptionRecordStore.logFileIDs();
wakeLockService.updateWakeLock(
enable: true,
wakeLockFor: WakeLockFor.machineLearningSettingsScreen,
@@ -483,6 +485,7 @@ class MLStatusWidgetState extends State<MLStatusWidget> {
@override
Widget build(BuildContext context) {
final colors = context.componentColors;
+ final decryptionIssueCount = mlDecryptionRecordStore.count;
return Column(
children: [
Padding(
@@ -564,7 +567,65 @@ class MLStatusWidgetState extends State<MLStatusWidget> {
return const EnteLoadingWidget();
},
),
+ if (decryptionIssueCount > 0) ...[
+ const SizedBox(height: 8),
+ _MLProcessingIssuesBlurb(itemCount: decryptionIssueCount),
+ ],
],
);
}
}
+
+class _MLProcessingIssuesBlurb extends StatelessWidget {
+ final int itemCount;
+
+ const _MLProcessingIssuesBlurb({required this.itemCount});
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+ return DecoratedBox(
+ decoration: BoxDecoration(
+ color: colors.fillLight,
+ borderRadius: BorderRadius.circular(Radii.button),
+ ),
+ child: Padding(
+ padding: const EdgeInsets.all(Spacing.lg),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ context.strings.mlCouldNotProcessItems(count: itemCount),
+ style: TextStyles.bodyBold.copyWith(color: colors.warning),
+ ),
+ const SizedBox(height: Spacing.xs),
+ Text(
+ context.strings.mlItemsCouldNotBeProcessed(count: itemCount),
+ style: TextStyles.mini.copyWith(color: colors.textLight),
+ ),
+ const SizedBox(height: Spacing.sm),
+ ButtonComponent(
+ label: context.strings.contactUs,
+ variant: ButtonComponentVariant.link,
+ size: ButtonComponentSize.small,
+ shouldSurfaceExecutionStates: false,
+ onTap: () async {
+ mlDecryptionRecordStore.logFileIDs();
+ await sendLogs(
+ context,
+ context.strings.contactUs,
+ postShare: () {},
+ subject: "Machine learning processing issue",
+ body: context.strings.mlItemsCouldNotBeProcessed(
+ count: itemCount,
+ ),
+ );
+ },
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
index 47312b9870..1a1e42ce3f 100644
--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb
+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
@@ -798,6 +798,10 @@
"@contactSupport": {
"description": "Contact support button label"
},
+ "contactUs": "Contact us",
+ "@contactUs": {
+ "description": "Button label for contacting Ente support"
+ },
"contactToManageSubscription": "Please contact us at [email protected] to manage your {provider} subscription.",
"@contactToManageSubscription": {
"placeholders": {
@@ -2539,7 +2543,25 @@
"mlConsentConfirmation": "I understand, and wish to enable machine learning",
"mlConsentDescription": "If you enable machine learning, Ente will extract information like face geometry from files, including those shared with you.\n\nThis will happen on your device, and any generated biometric information will be end-to-end encrypted.",
"mlConsentPrivacy": "Please click here for more details about this feature in our privacy policy",
+ "mlCouldNotProcessItems": "{count, plural, one{Could not process {count} item.} other{Could not process {count} items.}}",
+ "@mlCouldNotProcessItems": {
+ "description": "Title shown when machine learning could not process one or more items",
+ "placeholders": {
+ "count": {
+ "type": "int"
+ }
+ }
+ },
"mlIndexingDescription": "Please note that machine learning will result in higher bandwidth and battery usage until all items are processed. Consider using the desktop app for faster processing, and all results will be synced automatically.",
+ "mlItemsCouldNotBeProcessed": "{count, plural, one{{count} item could not be processed for machine learning. Please reach out to us so we can help.} other{{count} items could not be processed for machine learning. Please reach out to us so we can help.}}",
+ "@mlItemsCouldNotBeProcessed": {
+ "description": "Description shown when machine learning could not process one or more items",
+ "placeholders": {
+ "count": {
+ "type": "int"
+ }
+ }
+ },
"mlProgressBannerDescription": "Your photos are getting processed on device to detect faces, objects and more.",
"mlProgressBannerStatus": "{indexed} out of {total} photos processed",
"@mlProgressBannerStatus": {