Skip to content

armgit / ente

Public Imported from GitHub
0

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

clean stuff

Prateek Sunale965d66df3d8
diff --git a/mobile/apps/photos/ios/Podfile.lock b/mobile/apps/photos/ios/Podfile.lock
index d74e766b18..8896f1c714 100644
--- a/mobile/apps/photos/ios/Podfile.lock
+++ b/mobile/apps/photos/ios/Podfile.lock
@@ -215,28 +215,31 @@ PODS:
- sqflite_darwin (0.0.4):
- Flutter
- FlutterMacOS
- - sqlite3 (3.50.4):
- - sqlite3/common (= 3.50.4)
- - sqlite3/common (3.50.4)
- - sqlite3/dbstatvtab (3.50.4):
+ - sqlite3 (3.51.1):
+ - sqlite3/common (= 3.51.1)
+ - sqlite3/common (3.51.1)
+ - sqlite3/dbstatvtab (3.51.1):
- sqlite3/common
- - sqlite3/fts5 (3.50.4):
+ - sqlite3/fts5 (3.51.1):
- sqlite3/common
- - sqlite3/math (3.50.4):
+ - sqlite3/math (3.51.1):
- sqlite3/common
- - sqlite3/perf-threadsafe (3.50.4):
+ - sqlite3/perf-threadsafe (3.51.1):
- sqlite3/common
- - sqlite3/rtree (3.50.4):
+ - sqlite3/rtree (3.51.1):
+ - sqlite3/common
+ - sqlite3/session (3.51.1):
- sqlite3/common
- sqlite3_flutter_libs (0.0.1):
- Flutter
- FlutterMacOS
- - sqlite3 (~> 3.50.1)
+ - sqlite3 (~> 3.51.1)
- sqlite3/dbstatvtab
- sqlite3/fts5
- sqlite3/math
- sqlite3/perf-threadsafe
- sqlite3/rtree
+ - sqlite3/session
- system_info_plus (0.0.1):
- Flutter
- thermal (0.0.1):
@@ -550,8 +553,8 @@ SPEC CHECKSUMS:
share_plus: 50da8cb520a8f0f65671c6c6a99b3617ed10a58a
shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7
sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
- sqlite3: 73513155ec6979715d3904ef53a8d68892d4032b
- sqlite3_flutter_libs: e7fc8c9ea2200ff3271f08f127842131746b70e2
+ sqlite3: 8d708bc63e9f4ce48f0ad9d6269e478c5ced1d9b
+ sqlite3_flutter_libs: d13b8b3003f18f596e542bcb9482d105577eff41
system_info_plus: 555ce7047fbbf29154726db942ae785c29211740
thermal: d4c48be750d1ddbab36b0e2dcb2471531bc8df41
ua_client_hints: 92fe0d139619b73ec9fcb46cc7e079a26178f586
diff --git a/mobile/apps/photos/lib/main.dart b/mobile/apps/photos/lib/main.dart
index 8073b97a8d..c9108ac6a8 100644
--- a/mobile/apps/photos/lib/main.dart
+++ b/mobile/apps/photos/lib/main.dart
@@ -137,7 +137,7 @@ Future<void> runBackgroundTask(
// Check if foreground is recently active to avoid conflicts
final isRunningInFG = await _isRunningInForeground();
- // If FG was active in last 30 seconds, skip BG work
+ // If FG was active recently, skip BG work
if (isRunningInFG) {
_logger.info(
"[BG TASK] Foreground recently active, skipping background work",
@@ -156,6 +156,11 @@ Future<void> runBackgroundTask(
Future<void> _runMinimally(String taskId, TimeLogger tlog) async {
try {
+ // Background worker can run in a process/isolate where Rust has been
+ // disposed or not initialized; always initialize before ML usage.
+ await EntePhotosRust.init();
+ _logger.info("Rust bridge initialized in background via: workmanager");
+
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
final SharedPreferences prefs = await SharedPreferences.getInstance();
await _scheduleHeartBeat(prefs, true);
@@ -216,11 +221,13 @@ Future<void> _runMinimally(String taskId, TimeLogger tlog) async {
_logger.info("[BG TASK] home widget sync");
await _homeWidgetSync(true);
- final isDeviceHealthy = await computeController.isDeviceHealthyFuture();
- if (isDeviceHealthy) {
- await MLService.instance.init();
- await PersonService.init(entityService, MLDataDB.instance, prefs);
- await MLService.instance.runAllML(force: true);
+ if (flagService.enableMLInBackground) {
+ final isDeviceHealthy = await computeController.isDeviceHealthyFuture();
+ if (isDeviceHealthy) {
+ await MLService.instance.init();
+ await PersonService.init(entityService, MLDataDB.instance, prefs);
+ await MLService.instance.runAllML(force: true);
+ }
}
_logger.info("[BG TASK] smart albums sync");
await smartAlbumsService.syncSmartAlbums();
diff --git a/mobile/apps/photos/lib/services/machine_learning/face_ml/face_detection/face_detection_service.dart b/mobile/apps/photos/lib/services/machine_learning/face_ml/face_detection/face_detection_service.dart
index bb3b50c6b0..2fc7c82b47 100644
--- a/mobile/apps/photos/lib/services/machine_learning/face_ml/face_detection/face_detection_service.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/face_ml/face_detection/face_detection_service.dart
@@ -54,19 +54,12 @@ class FaceDetectionService extends MlModel {
'sessionAddress should be valid',
);
- _logger.info(
- "Running face detection for image with size ${dimensions.width}x${dimensions.height}",
- );
-
final startTime = DateTime.now();
final (inputImageList, scaledSize) = await preprocessImageYoloFace(
dimensions,
rawRgbaBytes,
);
- _logger.info(
- "Preprocessed image to input list of size ${inputImageList.length} with scaled size $scaledSize",
- );
final preprocessingTime = DateTime.now();
final preprocessingMs =
preprocessingTime.difference(startTime).inMilliseconds;
@@ -75,14 +68,8 @@ class FaceDetectionService extends MlModel {
List<List<List<double>>>? nestedResults = [];
try {
if (MlModel.usePlatformPlugin) {
- _logger.info(
- "Running inference using platform plugin",
- );
nestedResults = await _runPlatformPluginPredict(inputImageList);
} else {
- _logger.info(
- "Running inference using ONNX runtime",
- );
nestedResults = _runFFIBasedPredict(
sessionAddress,
inputImageList,
@@ -129,15 +116,9 @@ class FaceDetectionService extends MlModel {
final inputs = {'input': inputOrt};
final runOptions = OrtRunOptions();
final session = OrtSession.fromAddress(sessionAddress);
- _logger.info(
- "Running face detection using ONNX runtime with input size ${inputImageList.length}",
- );
final List<OrtValue?> outputs = session.run(runOptions, inputs);
final result =
outputs[0]?.value as List<List<List<double>>>; // [1, 25200, 16]
- _logger.info(
- "Finished running face detection using ONNX runtime",
- );
inputOrt.release();
runOptions.release();
for (var element in outputs) {
@@ -151,18 +132,11 @@ class FaceDetectionService extends MlModel {
Float32List inputImageList,
) async {
final OnnxDart plugin = OnnxDart();
- _logger.info(
- "Running face detection using OnnxDart plugin with input size ${inputImageList.length}",
- );
final result = await plugin.predict(
inputImageList,
_modelName,
);
- _logger.info(
- "Finished running face detection using OnnxDart plugin",
- );
-
final int resultLength = result!.length;
assert(resultLength % 25200 * 16 == 0);
const int outerLength = 1;
diff --git a/mobile/apps/photos/lib/services/machine_learning/face_ml/face_recognition_service.dart b/mobile/apps/photos/lib/services/machine_learning/face_ml/face_recognition_service.dart
index 9d10902997..714be89ea0 100644
--- a/mobile/apps/photos/lib/services/machine_learning/face_ml/face_recognition_service.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/face_ml/face_recognition_service.dart
@@ -86,9 +86,6 @@ class FaceRecognitionService {
final faceResults = <FaceResult>[];
final startTime = DateTime.now();
- _logger.info(
- "Starting runFacesPipeline with fileID $enteFileID",
- );
// Get the faces
final List<FaceDetectionRelative> faceDetectionResult =
await _detectFacesSync(
@@ -98,9 +95,6 @@ class FaceRecognitionService {
faceDetectionAddress,
faceResults,
);
- _logger.info(
- "Detected ${faceDetectionResult.length} faces in image with fileID $enteFileID",
- );
final detectFacesTime = DateTime.now();
final detectFacesMs = detectFacesTime.difference(startTime).inMilliseconds;
@@ -112,9 +106,6 @@ class FaceRecognitionService {
return [];
}
- _logger.info(
- "Detected ${faceDetectionResult.length} faces, proceeding to alignment and embedding",
- );
// Align the faces
final Float32List faceAlignmentResult = await _alignFacesSync(
dim,
@@ -126,9 +117,6 @@ class FaceRecognitionService {
final alignFacesMs =
alignFacesTime.difference(detectFacesTime).inMilliseconds;
- _logger.info(
- "Aligned ${faceDetectionResult.length} faces in image with fileID $enteFileID",
- );
// Get the embeddings of the faces
await _embedFacesSync(
faceAlignmentResult,
@@ -156,9 +144,6 @@ class FaceRecognitionService {
List<FaceResult> faceResults,
) async {
try {
- _logger.info(
- "Running face detection for fileID $fileID with interpreter at $interpreterAddress",
- );
// Get the bounding boxes of the faces
final List<FaceDetectionRelative> faces =
await FaceDetectionService.predict(
@@ -167,10 +152,6 @@ class FaceRecognitionService {
interpreterAddress,
);
- _logger.info(
- "Detected ${faces.length} faces in image with fileID $fileID",
- );
-
// Add detected faces to the faceResults
for (var i = 0; i < faces.length; i++) {
faceResults.add(
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 9fe96604db..0592d5e856 100644
--- a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
@@ -303,7 +303,8 @@ class MLService {
break stream;
} else {
await MLIndexingIsolate.instance.ensureDownloadedModels();
- if ((flagService.useRustForML || isOfflineMode) && !rustRuntimePrepared) {
+ if ((flagService.useRustForML || isOfflineMode) &&
+ !rustRuntimePrepared) {
await MLIndexingIsolate.instance.prepareRustRuntime();
rustRuntimePrepared = true;
}
diff --git a/mobile/apps/photos/lib/services/machine_learning/semantic_search/clip/clip_image_encoder.dart b/mobile/apps/photos/lib/services/machine_learning/semantic_search/clip/clip_image_encoder.dart
index 8d6fdf56c8..88ff7f691c 100644
--- a/mobile/apps/photos/lib/services/machine_learning/semantic_search/clip/clip_image_encoder.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/semantic_search/clip/clip_image_encoder.dart
@@ -86,9 +86,6 @@ class ClipImageEncoder extends MlModel {
Float32List inputList,
) async {
final OnnxDart plugin = OnnxDart();
- _logger.info(
- "Running Clip image predict using OnnxDart plugin with input size ${inputList.length}",
- );
final result = await plugin.predict(
inputList,
_modelName,
diff --git a/mobile/apps/photos/lib/services/machine_learning/semantic_search/semantic_search_service.dart b/mobile/apps/photos/lib/services/machine_learning/semantic_search/semantic_search_service.dart
index 4fcfa0d671..9a4c6be837 100644
--- a/mobile/apps/photos/lib/services/machine_learning/semantic_search/semantic_search_service.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/semantic_search/semantic_search_service.dart
@@ -471,9 +471,6 @@ class SemanticSearchService {
Uint8List rawRgbaBytes,
int clipImageAddress,
) async {
- _logger.info(
- "Running Clip image encoding for file ID: $enteFileID",
- );
final embedding = await ClipImageEncoder.predict(
dimensions,
rawRgbaBytes,
@@ -481,10 +478,6 @@ class SemanticSearchService {
enteFileID,
);
- _logger.info(
- "Clip image encoding completed for file ID: $enteFileID",
- );
-
final clipResult = ClipResult(fileID: enteFileID, embedding: embedding);
return clipResult;
diff --git a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart b/mobile/apps/photos/lib/services/sync/remote_sync_service.dart
index 59b6e84582..423dd71bc0 100644
--- a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart
+++ b/mobile/apps/photos/lib/services/sync/remote_sync_service.dart
@@ -100,10 +100,6 @@ class RemoteSyncService {
}
Future<void> sync({bool silently = false}) async {
- // TODO: remove
- // if (!isProcessBg) {
- // return;
- // }
if (!_config.hasConfiguredAccount()) {
_logger.info("Skipping remote sync since account is not configured");
return;
diff --git a/mobile/apps/photos/lib/utils/bg_task_utils.dart b/mobile/apps/photos/lib/utils/bg_task_utils.dart
index 9bbfa50246..7cf7c67681 100644
--- a/mobile/apps/photos/lib/utils/bg_task_utils.dart
+++ b/mobile/apps/photos/lib/utils/bg_task_utils.dart
@@ -22,8 +22,7 @@ void callbackDispatcher() {
try {
BgTaskUtils.$.info('Task started $tlog');
await runBackgroundTask(taskName, tlog).timeout(
- // TODO: For testing don't do seppuku
- Platform.isIOS && false ? kBGTaskTimeout : const Duration(hours: 1),
+ Platform.isIOS ? kBGTaskTimeout : const Duration(hours: 1),
onTimeout: () async {
BgTaskUtils.$.warning(
"TLE, committing seppuku for taskID: $taskName",
diff --git a/mobile/apps/photos/lib/utils/image_ml_util.dart b/mobile/apps/photos/lib/utils/image_ml_util.dart
index 6ac04892fc..387cc80e38 100644
--- a/mobile/apps/photos/lib/utils/image_ml_util.dart
+++ b/mobile/apps/photos/lib/utils/image_ml_util.dart
@@ -84,16 +84,11 @@ Future<DecodedImage> decodeImageFromPath(
);
}
- Uint8List? bytes;
- for (final order in img_pkg.ChannelOrder.values) {
- bytes = imageData.getBytes(order: order);
- _logger.info("Bytes length is: ${bytes.length}, for order: : $order");
- }
+ final bytes = imageData.getBytes(order: img_pkg.ChannelOrder.rgba);
final dimensions = Dimensions(
width: image!.width,
height: image.height,
);
- _logger.info("Dimensions are: $dimensions");
return DecodedImage(
dimensions: dimensions,
rawRgbaBytes: bytes,
@@ -123,9 +118,6 @@ Future<DecodedImage> decodeImageFromPath(
}
late Image image;
- _logger.info(
- 'Decoding image at path: $imagePath, format: $format, includeRgbaBytes: $includeRgbaBytes',
- );
try {
image = await decodeImageFromData(imageData);
} catch (e, s) {
@@ -159,18 +151,12 @@ Future<DecodedImage> decodeImageFromPath(
);
}
}
- _logger.info(
- "Decoded image at path: $imagePath [i]",
- );
if (!includeRgbaBytes) {
return DecodedImage(
dimensions: Dimensions(width: image.width, height: image.height),
image: includeDartUiImage ? image : null,
);
}
- _logger.info(
- "Getting Raw RGBA",
- );
final rawRgbaBytes = await _getRawRgbaBytes(image);
return DecodedImage(
dimensions: Dimensions(width: image.width, height: image.height),
diff --git a/mobile/apps/photos/lib/utils/ml_util.dart b/mobile/apps/photos/lib/utils/ml_util.dart
index e8bb6b54db..0745f9ac4e 100644
--- a/mobile/apps/photos/lib/utils/ml_util.dart
+++ b/mobile/apps/photos/lib/utils/ml_util.dart
@@ -9,7 +9,6 @@ import "package:photos/db/files_db.dart";
import "package:photos/db/ml/db.dart";
import "package:photos/db/ml/filedata.dart";
import "package:photos/db/offline_files_db.dart";
-import "package:photos/extensions/list.dart";
import "package:photos/main.dart";
import "package:photos/models/file/extensions/file_props.dart";
import "package:photos/models/file/file.dart";
@@ -539,7 +538,6 @@ Future<MLResult> analyzeImageStatic(Map args) async {
);
final startTime = DateTime.now();
- _logger.info("Decoding image at path: $imagePath");
// Decode the image once to use for both face detection and alignment
final decodedImage = await decodeImageFromPath(
imagePath,
@@ -549,18 +547,11 @@ Future<MLResult> analyzeImageStatic(Map args) async {
);
final rawRgbaBytes = decodedImage.rawRgbaBytes!;
final imageDimensions = decodedImage.dimensions;
- _logger.info(
- "Decoded image with rgbaLength: ${rawRgbaBytes.length}, dimensions: $imageDimensions",
- );
final result = MLResult.fromEnteFileID(enteFileID);
result.decodedImageSize = imageDimensions;
final decodeTime = DateTime.now();
final decodeMs = decodeTime.difference(startTime).inMilliseconds;
- _logger.info(
- "Decoded image at path: $imagePath, in $decodeMs ms",
- );
-
String faceMsString = "", clipMsString = "";
final pipelines = await Future.wait([
runFaces
diff --git a/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart b/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart
index 2309a58c2e..d472999106 100644
--- a/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart
+++ b/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart
@@ -104,6 +104,8 @@ class FlagService {
bool get useRustForML => internalUser;
+ bool get enableMLInBackground => internalUser;
+
bool get useRustForFaceThumbnails => internalUser;
Future<void> tryRefreshFlags() async {
diff --git a/mobile/apps/photos/rust_builder/cargokit/build_pod.sh b/mobile/apps/photos/rust_builder/cargokit/build_pod.sh
index 2350e72a54..01fc73cafe 100755
--- a/mobile/apps/photos/rust_builder/cargokit/build_pod.sh
+++ b/mobile/apps/photos/rust_builder/cargokit/build_pod.sh
@@ -43,22 +43,36 @@ if [[ -n "$PODS_ROOT" ]] && [[ -d "$PODS_ROOT/onnxruntime-c/onnxruntime.xcframew
ORT_XCFWK_LOCATION="$PODS_ROOT/onnxruntime-c/onnxruntime.xcframework"
export ORT_IOS_XCFWK_LOCATION="$ORT_XCFWK_LOCATION"
- # ort-sys currently does not handle x86_64 iOS simulator triples for
- # ORT_IOS_XCFWK_LOCATION, so provide ORT_LIB_LOCATION with a thin archive.
- if [[ "$CARGOKIT_DARWIN_PLATFORM_NAME" == "iphonesimulator" ]] && [[ "$CARGOKIT_DARWIN_ARCHS" == "x86_64" ]]; then
- ORT_SIM_LIB="$ORT_XCFWK_LOCATION/ios-arm64_x86_64-simulator/onnxruntime.framework/onnxruntime"
- if [[ -f "$ORT_SIM_LIB" ]]; then
- ORT_LIB_TEMP_DIR="$TARGET_TEMP_DIR/ort_sys_sim_x86_64"
+ # ort-sys v2.0.0-rc.4 uses ORT_LIB_LOCATION for linking. Build a thin
+ # libonnxruntime.a from the xcframework slice that matches the current SDK.
+ ORT_FRAMEWORK_SLICE=""
+ if [[ "$CARGOKIT_DARWIN_PLATFORM_NAME" == "iphoneos" ]]; then
+ ORT_FRAMEWORK_SLICE="ios-arm64"
+ elif [[ "$CARGOKIT_DARWIN_PLATFORM_NAME" == "iphonesimulator" ]]; then
+ ORT_FRAMEWORK_SLICE="ios-arm64_x86_64-simulator"
+ fi
+
+ if [[ -n "$ORT_FRAMEWORK_SLICE" ]]; then
+ ORT_FRAMEWORK_BIN="$ORT_XCFWK_LOCATION/$ORT_FRAMEWORK_SLICE/onnxruntime.framework/onnxruntime"
+ if [[ -f "$ORT_FRAMEWORK_BIN" ]]; then
+ ORT_LIB_TEMP_DIR="$TARGET_TEMP_DIR/ort_sys_${CARGOKIT_DARWIN_PLATFORM_NAME}_${CARGOKIT_DARWIN_ARCHS// /_}"
mkdir -p "$ORT_LIB_TEMP_DIR"
- lipo -thin x86_64 "$ORT_SIM_LIB" -output "$ORT_LIB_TEMP_DIR/libonnxruntime.a"
- export ORT_LIB_LOCATION="$ORT_LIB_TEMP_DIR"
- # Link the simulator clang runtime; ort-sys links the device variant for
- # x86_64-apple-ios, which misses simulator-only symbols.
- CLANG_RESOURCE_DIR="$(xcrun clang --print-resource-dir 2>/dev/null || true)"
- if [[ -n "$CLANG_RESOURCE_DIR" ]] && [[ -d "$CLANG_RESOURCE_DIR/lib/darwin" ]]; then
- export RUSTFLAGS="${RUSTFLAGS} -L native=${CLANG_RESOURCE_DIR}/lib/darwin -l clang_rt.iossim"
+ if [[ "$CARGOKIT_DARWIN_ARCHS" == *" "* ]]; then
+ cp "$ORT_FRAMEWORK_BIN" "$ORT_LIB_TEMP_DIR/libonnxruntime.a"
+ else
+ lipo -thin "$CARGOKIT_DARWIN_ARCHS" "$ORT_FRAMEWORK_BIN" -output "$ORT_LIB_TEMP_DIR/libonnxruntime.a"
fi
+ export ORT_LIB_LOCATION="$ORT_LIB_TEMP_DIR"
+ fi
+ fi
+
+ if [[ "$CARGOKIT_DARWIN_PLATFORM_NAME" == "iphonesimulator" ]] && [[ "$CARGOKIT_DARWIN_ARCHS" == "x86_64" ]]; then
+ # Link the simulator clang runtime; ort-sys links the device variant for
+ # x86_64-apple-ios, which misses simulator-only symbols.
+ CLANG_RESOURCE_DIR="$(xcrun clang --print-resource-dir 2>/dev/null || true)"
+ if [[ -n "$CLANG_RESOURCE_DIR" ]] && [[ -d "$CLANG_RESOURCE_DIR/lib/darwin" ]]; then
+ export RUSTFLAGS="${RUSTFLAGS} -L native=${CLANG_RESOURCE_DIR}/lib/darwin -l clang_rt.iossim"
fi
fi
fi