Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] Guard ML cleanup during logout

laurenspriem9c69671c0b5a
diff --git a/mobile/apps/photos/lib/core/configuration.dart b/mobile/apps/photos/lib/core/configuration.dart
index ae137712da..c171f97e7b 100644
--- a/mobile/apps/photos/lib/core/configuration.dart
+++ b/mobile/apps/photos/lib/core/configuration.dart
@@ -43,6 +43,8 @@ import 'package:photos/services/favorites_service.dart';
import "package:photos/services/home_widget_service.dart";
import 'package:photos/services/ignored_files_service.dart';
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
+import "package:photos/services/machine_learning/ml_run_control.dart";
+import "package:photos/services/machine_learning/ml_service.dart";
import "package:photos/services/machine_learning/similar_images_service.dart";
import "package:photos/services/memory_share_service.dart";
import "package:photos/services/notification_service.dart";
@@ -194,6 +196,7 @@ class Configuration implements LockScreenHost, AccountDeletionHost {
@override
Future<void> logout({bool autoLogout = false}) async {
_logger.info("Logging out, autoLogout: $autoLogout");
+ MLService.instance.stopActiveRun(MlStopReason.logout);
if (!autoLogout) {
if (flagService.stopStreamProcess) {
VideoPreviewService.instance.stop('logout');
diff --git a/mobile/apps/photos/lib/db/ml/db.dart b/mobile/apps/photos/lib/db/ml/db.dart
index e6393e0b29..a1771ad215 100644
--- a/mobile/apps/photos/lib/db/ml/db.dart
+++ b/mobile/apps/photos/lib/db/ml/db.dart
@@ -598,7 +598,10 @@ class MLDataDB with SqlDbBase implements IMLDataDB<int> {
}
@override
- Future<void> clearTable() async {
+ Future<void> clearTable() =>
+ _runMlOperationExclusive(MlOperation.clearData, _clearTable);
+
+ Future<void> _clearTable() async {
final db = await asyncDB;
await db.execute(deleteFacesTable);
@@ -1859,7 +1862,7 @@ class MLDataDB with SqlDbBase implements IMLDataDB<int> {
if (!force && await _clusterCentroidVectorDB.checkIfMigrationDone()) {
return;
}
- await _runVectorMigrationExclusive(
+ await _runMlOperationExclusive(
MlOperation.clusterCentroidVectorMigration,
() => _checkMigrateFillClusterCentroidVectorDB(force: force),
);
@@ -2168,7 +2171,7 @@ class MLDataDB with SqlDbBase implements IMLDataDB<int> {
if (!force && await _clipVectorDB.checkIfMigrationDone()) {
return;
}
- await _runVectorMigrationExclusive(
+ await _runMlOperationExclusive(
MlOperation.clipVectorMigration,
() => _checkMigrateFillClipVectorDB(force: force),
);
@@ -2319,13 +2322,13 @@ class MLDataDB with SqlDbBase implements IMLDataDB<int> {
});
}
- Future<void> _runVectorMigrationExclusive(
+ Future<void> _runMlOperationExclusive(
MlOperation operation,
- Future<void> Function() migration,
+ Future<void> Function() body,
) async {
final attempt = await MlProcessLock.instance.tryRunExclusive(
operation,
- migration,
+ body,
background: isProcessBg,
waitForAvailability: true,
);
diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_process_lock.dart b/mobile/apps/photos/lib/services/machine_learning/ml_process_lock.dart
index 125c19ca65..c2db471066 100644
--- a/mobile/apps/photos/lib/services/machine_learning/ml_process_lock.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/ml_process_lock.dart
@@ -11,6 +11,7 @@ enum MlOperation {
startupRemoteHydration,
clipVectorMigration,
clusterCentroidVectorMigration,
+ clearData,
}
enum MlLockAttempt {
diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_run_control.dart b/mobile/apps/photos/lib/services/machine_learning/ml_run_control.dart
index 5d90a883b4..a8b17a1b83 100644
--- a/mobile/apps/photos/lib/services/machine_learning/ml_run_control.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/ml_run_control.dart
@@ -4,6 +4,7 @@ enum MlStopReason {
foregroundActive,
backgroundDeadline,
controller,
+ logout,
manual,
corruptModel,
}