π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Replace device health dependencies
Neeraj Gupta4261447cf806
diff --git a/mobile/apps/photos/integration_test/device_health_test.dart b/mobile/apps/photos/integration_test/device_health_test.dartnew file mode 100644index 0000000000..19de7305a3--- /dev/null+++ b/mobile/apps/photos/integration_test/device_health_test.dart@@ -0,0 +1,28 @@+import 'dart:io';++import 'package:ente_photos_platform/ente_photos_platform.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:integration_test/integration_test.dart';++void main() {+ IntegrationTestWidgetsFlutterBinding.ensureInitialized();++ testWidgets('native device health snapshot is current and usable', (+ tester,+ ) async {+ final snapshot = await EntePhotosDeviceHealth.instance.getSnapshot();+ final memory = await EntePhotosDeviceHealth.instance.getMemorySnapshot();+ final now = DateTime.now();++ expect(snapshot.isFreshAt(now, const Duration(seconds: 10)), isTrue);+ expect(memory.status, DeviceSignalStatus.available);+ expect(memory.totalBytes, greaterThan(0));+ expect(snapshot.thermal.status, isNot(DeviceSignalStatus.unavailable));+ if (Platform.isAndroid) {+ expect(snapshot.platform, DeviceHealthPlatform.android);+ expect(snapshot.battery.status, DeviceSignalStatus.available);+ } else if (Platform.isIOS) {+ expect(snapshot.platform, DeviceHealthPlatform.ios);+ }+ });+}diff --git a/mobile/apps/photos/ios/Podfile.lock b/mobile/apps/photos/ios/Podfile.lockindex 2e6d5b92d8..c1e96792be 100644--- a/mobile/apps/photos/ios/Podfile.lock+++ b/mobile/apps/photos/ios/Podfile.lock@@ -5,8 +5,6 @@ PODS:- Flutter- backup_exclusion (1.0.0):- Flutter- - battery_info (0.0.1):- - Flutter- camera_avfoundation (0.0.1):- Flutter- connectivity_plus (0.0.1):@@ -20,6 +18,8 @@ PODS:- Flutter- ente_panorama_viewer (0.0.1):- Flutter+ - ente_photos_platform (0.0.1):+ - Flutter- ente_photos_rust (0.0.1):- Flutter- ente_qr (0.0.1):@@ -231,10 +231,6 @@ PODS:- sqlite3/perf-threadsafe- sqlite3/rtree- sqlite3/session- - system_info_plus (0.0.1):- - Flutter- - thermal (0.0.1):- - Flutter- ua_client_hints (1.4.1):- Flutter- url_launcher_ios (0.0.1):@@ -251,13 +247,13 @@ DEPENDENCIES:- app_links (from `.symlinks/plugins/app_links/ios`)- audio_session (from `.symlinks/plugins/audio_session/ios`)- backup_exclusion (from `.symlinks/plugins/backup_exclusion/ios`)- - battery_info (from `.symlinks/plugins/battery_info/ios`)- camera_avfoundation (from `.symlinks/plugins/camera_avfoundation/ios`)- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)- cupertino_http (from `.symlinks/plugins/cupertino_http/darwin`)- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)- ente_cast (from `.symlinks/plugins/ente_cast/ios`)- ente_panorama_viewer (from `.symlinks/plugins/ente_panorama_viewer/ios`)+ - ente_photos_platform (from `.symlinks/plugins/ente_photos_platform/ios`)- ente_photos_rust (from `.symlinks/plugins/ente_photos_rust/ios`)- ente_qr (from `.symlinks/plugins/ente_qr/ios`)- ente_rust (from `.symlinks/plugins/ente_rust/ios`)@@ -302,8 +298,6 @@ DEPENDENCIES:- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)- sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`)- sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/darwin`)- - system_info_plus (from `.symlinks/plugins/system_info_plus/ios`)- - thermal (from `.symlinks/plugins/thermal/ios`)- ua_client_hints (from `.symlinks/plugins/ua_client_hints/ios`)- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)- video_player_avfoundation (from `.symlinks/plugins/video_player_avfoundation/darwin`)@@ -338,8 +332,6 @@ EXTERNAL SOURCES::path: ".symlinks/plugins/audio_session/ios"backup_exclusion::path: ".symlinks/plugins/backup_exclusion/ios"- battery_info:- :path: ".symlinks/plugins/battery_info/ios"camera_avfoundation::path: ".symlinks/plugins/camera_avfoundation/ios"connectivity_plus:@@ -352,6 +344,8 @@ EXTERNAL SOURCES::path: ".symlinks/plugins/ente_cast/ios"ente_panorama_viewer::path: ".symlinks/plugins/ente_panorama_viewer/ios"+ ente_photos_platform:+ :path: ".symlinks/plugins/ente_photos_platform/ios"ente_photos_rust::path: ".symlinks/plugins/ente_photos_rust/ios"ente_qr:@@ -440,10 +434,6 @@ EXTERNAL SOURCES::path: ".symlinks/plugins/sqflite_darwin/darwin"sqlite3_flutter_libs::path: ".symlinks/plugins/sqlite3_flutter_libs/darwin"- system_info_plus:- :path: ".symlinks/plugins/system_info_plus/ios"- thermal:- :path: ".symlinks/plugins/thermal/ios"ua_client_hints::path: ".symlinks/plugins/ua_client_hints/ios"url_launcher_ios:@@ -459,13 +449,13 @@ SPEC CHECKSUMS:app_links: 3dbc685f76b1693c66a6d9dd1e9ab6f73d97dc0aaudio_session: 9bb7f6c970f21241b19f5a3658097ae459681ba0backup_exclusion: 7aa8535339e746fb217cfdfe8fb8f8a718e4cb0b- battery_info: 83f3aae7be2fccefab1d2bf06b8aa96f11c8bcddcamera_avfoundation: 5675ca25298b6f81fa0a325188e7df62cc217741connectivity_plus: cb623214f4e1f6ef8fe7403d580fdad517d2f7ddcupertino_http: 94ac07f5ff090b8effa6c5e2c47871d48ab7c86cdevice_info_plus: 21fcca2080fbcd348be798aa36c3e5ed849eefbeente_cast: a25feb3127397e5fc6aff03a12120916707757d4ente_panorama_viewer: 87bb22e7868c3005314f80c05ee0787aa07edcd8+ ente_photos_platform: 9a5d62b4008563bdfefe6a42cc4297c5c19bf70cente_photos_rust: 2db1f31cbe3f13ef0f52909a52b1f885b880a6ecente_qr: 86beaf5d2644705db9b565b32dd8b82c05fb36afente_rust: d0197ebd5460e8f67576579452b073d698404abe@@ -527,8 +517,6 @@ SPEC CHECKSUMS:sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0sqlite3: 8d708bc63e9f4ce48f0ad9d6269e478c5ced1d9bsqlite3_flutter_libs: d13b8b3003f18f596e542bcb9482d105577eff41- system_info_plus: 555ce7047fbbf29154726db942ae785c29211740- thermal: d4c48be750d1ddbab36b0e2dcb2471531bc8df41ua_client_hints: 92fe0d139619b73ec9fcb46cc7e079a26178f586url_launcher_ios: 7a95fa5b60cc718a708b8f2966718e93db0cef1bvideo_player_avfoundation: 33f12ee023e354af9d062d2c366503424a914d10diff --git a/mobile/apps/photos/ios/Runner.xcodeproj/project.pbxproj b/mobile/apps/photos/ios/Runner.xcodeproj/project.pbxprojindex 8d9fb67bb9..dd3a2d5362 100644--- a/mobile/apps/photos/ios/Runner.xcodeproj/project.pbxproj+++ b/mobile/apps/photos/ios/Runner.xcodeproj/project.pbxproj@@ -631,13 +631,13 @@"${BUILT_PRODUCTS_DIR}/app_links/app_links.framework","${BUILT_PRODUCTS_DIR}/audio_session/audio_session.framework","${BUILT_PRODUCTS_DIR}/backup_exclusion/backup_exclusion.framework",- "${BUILT_PRODUCTS_DIR}/battery_info/battery_info.framework","${BUILT_PRODUCTS_DIR}/camera_avfoundation/camera_avfoundation.framework","${BUILT_PRODUCTS_DIR}/connectivity_plus/connectivity_plus.framework","${BUILT_PRODUCTS_DIR}/cupertino_http/cupertino_http.framework","${BUILT_PRODUCTS_DIR}/device_info_plus/device_info_plus.framework","${BUILT_PRODUCTS_DIR}/ente_cast/ente_cast.framework","${BUILT_PRODUCTS_DIR}/ente_panorama_viewer/ente_panorama_viewer.framework",+ "${BUILT_PRODUCTS_DIR}/ente_photos_platform/ente_photos_platform.framework","${BUILT_PRODUCTS_DIR}/ente_photos_rust/ente_photos_rust.framework","${BUILT_PRODUCTS_DIR}/ente_qr/ente_qr.framework","${BUILT_PRODUCTS_DIR}/ente_rust/ente_rust.framework",@@ -679,8 +679,6 @@"${BUILT_PRODUCTS_DIR}/sqflite_darwin/sqflite_darwin.framework","${BUILT_PRODUCTS_DIR}/sqlite3/sqlite3.framework","${BUILT_PRODUCTS_DIR}/sqlite3_flutter_libs/sqlite3_flutter_libs.framework",- "${BUILT_PRODUCTS_DIR}/system_info_plus/system_info_plus.framework",- "${BUILT_PRODUCTS_DIR}/thermal/thermal.framework","${BUILT_PRODUCTS_DIR}/ua_client_hints/ua_client_hints.framework","${BUILT_PRODUCTS_DIR}/url_launcher_ios/url_launcher_ios.framework","${BUILT_PRODUCTS_DIR}/video_player_avfoundation/video_player_avfoundation.framework",@@ -730,13 +728,13 @@"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/app_links.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/audio_session.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/backup_exclusion.framework",- "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/battery_info.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/camera_avfoundation.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/connectivity_plus.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/cupertino_http.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/device_info_plus.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ente_cast.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ente_panorama_viewer.framework",+ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ente_photos_platform.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ente_photos_rust.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ente_qr.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ente_rust.framework",@@ -778,8 +776,6 @@"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/sqflite_darwin.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/sqlite3.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/sqlite3_flutter_libs.framework",- "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/system_info_plus.framework",- "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/thermal.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ua_client_hints.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/url_launcher_ios.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/video_player_avfoundation.framework",diff --git a/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart b/mobile/apps/photos/lib/services/machine_learning/compute_controller.dartindex 25abf6558e..c64502f85b 100644--- a/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart+++ b/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart@@ -1,35 +1,31 @@import "dart:async";import "dart:io";-import "package:battery_info/battery_info_plugin.dart";-import "package:battery_info/model/android_battery_info.dart";-import "package:battery_info/model/iso_battery_info.dart";-import "package:flutter/foundation.dart";+import "package:ente_photos_platform/ente_photos_platform.dart";import "package:logging/logging.dart";import "package:photos/core/event_bus.dart";import "package:photos/events/compute_control_event.dart";import "package:photos/events/device_health_changed_event.dart";import "package:photos/main.dart";+import "package:photos/services/machine_learning/device_health_policy.dart";import "package:photos/settings/local_settings.dart";-import "package:thermal/thermal.dart";enum ComputeRunState { idle, runningML, generatingStream }class ComputeController {final _logger = Logger("ComputeController");- static const kMaximumTemperatureAndroid = 42; // 42 degree celsius- static const kMinimumBatteryLevel = 20; // 20%+ static const _healthRequestTimeout = Duration(seconds: 5);final kDefaultInteractionTimeout = Duration(seconds: Platform.isIOS ? 5 : 15);- static const kUnhealthyStates = ["over_heat", "over_voltage", "dead"];final LocalSettings _localSettings;-- static final _thermal = Thermal();- IosBatteryInfo? _iosLastBatteryInfo;- AndroidBatteryInfo? _androidLastBatteryInfo;- ThermalStatus? _lastThermalStatus;-- bool _isDeviceHealthy = true;+ final DeviceHealthSource _deviceHealthSource;+ final DeviceHealthPolicy _deviceHealthPolicy;+ // Process-lifetime subscription owned by this singleton.+ // ignore: cancel_subscriptions+ StreamSubscription<DeviceHealthSnapshot>? _deviceHealthSubscription;+ Timer? _deviceHealthRefreshTimer;++ bool _isDeviceHealthy = false;bool _isUserInteracting = true;bool _canRunCompute = false;bool _hasCompletedInitialHealthChecks = false;@@ -64,7 +60,13 @@ class ComputeController {Bus.instance.fire(DeviceHealthChangedEvent(healthy));}- ComputeController(this._localSettings) {+ ComputeController(+ this._localSettings, {+ DeviceHealthSource? deviceHealthSource,+ DeviceHealthPolicy deviceHealthPolicy = const DeviceHealthPolicy(),+ }) : _deviceHealthSource =+ deviceHealthSource ?? EntePhotosDeviceHealth.instance,+ _deviceHealthPolicy = deviceHealthPolicy {_logger.info('ComputeController constructor');unawaited(init());_logger.info('init done ');@@ -89,38 +91,15 @@ class ComputeController {_isUserInteracting = false;}- // Thermal related- _onThermalStateUpdate(await _thermal.thermalStatus);- _thermal.onThermalStatusChanged.listen((ThermalStatus thermalState) {- _onThermalStateUpdate(thermalState);- });-- // Battery State- if (Platform.isIOS) {- if (kDebugMode) {- _logger.fine(- "iOS battery info stream is not available in simulator, disabling in debug mode",- );- } else {- // Update Battery state for iOS- _oniOSBatteryStateUpdate(await BatteryInfoPlugin().iosBatteryInfo);- BatteryInfoPlugin().iosBatteryInfoStream.listen((- IosBatteryInfo? batteryInfo,- ) {- _oniOSBatteryStateUpdate(batteryInfo);- });- }- } else if (Platform.isAndroid) {- // Update Battery state for Android- _onAndroidBatteryStateUpdate(- await BatteryInfoPlugin().androidBatteryInfo,- );- BatteryInfoPlugin().androidBatteryInfoStream.listen((- AndroidBatteryInfo? batteryInfo,- ) {- _onAndroidBatteryStateUpdate(batteryInfo);- });- }+ _deviceHealthSubscription ??= _deviceHealthSource.updates.listen(+ _onDeviceHealthUpdate,+ onError: _onDeviceHealthError,+ );+ await _refreshDeviceHealth();+ _deviceHealthRefreshTimer ??= Timer.periodic(+ DeviceHealthPolicy.refreshInterval,+ (_) => unawaited(_refreshDeviceHealth()),+ );_hasCompletedInitialHealthChecks = true;_fireControlEvent();@@ -294,76 +273,34 @@ class ComputeController {_startInteractionTimer(kDefaultInteractionTimeout);}- void _onAndroidBatteryStateUpdate(AndroidBatteryInfo? batteryInfo) {- _androidLastBatteryInfo = batteryInfo;- _setDeviceHealth(_computeIsAndroidDeviceHealthy());- _fireControlEvent();- }-- void _oniOSBatteryStateUpdate(IosBatteryInfo? batteryInfo) {- _iosLastBatteryInfo = batteryInfo;- _setDeviceHealth(_computeIsiOSDeviceHealthy());- _fireControlEvent();- }-- void _onThermalStateUpdate(ThermalStatus? thermalStatus) {- final changed = _lastThermalStatus != thermalStatus;- _lastThermalStatus = thermalStatus;- if (changed) {- _logger.info("Thermal status changed, status: $thermalStatus");+ Future<void> _refreshDeviceHealth() async {+ try {+ final snapshot = await _deviceHealthSource.getSnapshot().timeout(+ _healthRequestTimeout,+ );+ _onDeviceHealthUpdate(snapshot);+ } catch (error, stackTrace) {+ _onDeviceHealthError(error, stackTrace);}- _setDeviceHealth(- Platform.isAndroid- ? _computeIsAndroidDeviceHealthy()- : _computeIsiOSDeviceHealthy(),- );- _fireControlEvent();- }-- bool _computeIsAndroidDeviceHealthy() {- return _hasSufficientBattery(- _androidLastBatteryInfo?.batteryLevel ?? kMinimumBatteryLevel,- ) &&- _isAcceptableTemperatureAndroid() &&- _isBatteryHealthyAndroid() &&- _isAcceptableThermalState();}- bool _computeIsiOSDeviceHealthy() {- return _hasSufficientBattery(- _iosLastBatteryInfo?.batteryLevel ?? kMinimumBatteryLevel,- ) &&- _isAcceptableThermalState();- }-- bool _isAcceptableThermalState() {- switch (_lastThermalStatus) {- case null:- return true;- case ThermalStatus.none:- case ThermalStatus.light:- case ThermalStatus.moderate:- return true;- case ThermalStatus.severe:- case ThermalStatus.critical:- case ThermalStatus.emergency:- case ThermalStatus.shutdown:- _logger.warning("Thermal status is unacceptable: $_lastThermalStatus");- return false;+ void _onDeviceHealthUpdate(DeviceHealthSnapshot snapshot) {+ final evaluation = _deviceHealthPolicy.evaluate(+ snapshot,+ now: DateTime.now(),+ );+ if (!evaluation.isHealthy) {+ _logger.warning(+ 'Device health is unacceptable: ${evaluation.issues.map((e) => e.name).join(', ')}',+ );}+ _setDeviceHealth(evaluation.isHealthy);+ _fireControlEvent();}- bool _hasSufficientBattery(int batteryLevel) {- return batteryLevel >= kMinimumBatteryLevel;- }-- bool _isAcceptableTemperatureAndroid() {- return (_androidLastBatteryInfo?.temperature ??- kMaximumTemperatureAndroid) <=- kMaximumTemperatureAndroid;- }-- bool _isBatteryHealthyAndroid() {- return !kUnhealthyStates.contains(_androidLastBatteryInfo?.health ?? "");+ void _onDeviceHealthError(Object error, [StackTrace? stackTrace]) {+ _logger.warning('Failed to observe device health', error, stackTrace);+ _setDeviceHealth(false);+ _fireControlEvent();}}diff --git a/mobile/apps/photos/lib/services/machine_learning/device_health_policy.dart b/mobile/apps/photos/lib/services/machine_learning/device_health_policy.dartnew file mode 100644index 0000000000..fd6c9d259b--- /dev/null+++ b/mobile/apps/photos/lib/services/machine_learning/device_health_policy.dart@@ -0,0 +1,94 @@+import 'package:ente_photos_platform/ente_photos_platform.dart';++enum DeviceHealthIssue {+ staleObservation,+ batteryUnavailable,+ lowBattery,+ batteryTemperatureUnavailable,+ batteryTooHot,+ batteryHealthUnavailable,+ batteryUnhealthy,+ thermalUnavailable,+ thermalTooHigh,+}++class DeviceHealthEvaluation {+ const DeviceHealthEvaluation(this.issues);++ final Set<DeviceHealthIssue> issues;++ bool get isHealthy => issues.isEmpty;+}++class DeviceHealthPolicy {+ const DeviceHealthPolicy({+ this.minimumBatteryLevel = 20,+ this.maximumAndroidBatteryTemperature = 42,+ this.maximumObservationAge = const Duration(minutes: 2),+ });++ static const refreshInterval = Duration(minutes: 1);++ final int minimumBatteryLevel;+ final double maximumAndroidBatteryTemperature;+ final Duration maximumObservationAge;++ DeviceHealthEvaluation evaluate(+ DeviceHealthSnapshot snapshot, {+ required DateTime now,+ }) {+ if (!snapshot.isFreshAt(now, maximumObservationAge)) {+ return const DeviceHealthEvaluation({DeviceHealthIssue.staleObservation});+ }++ final issues = <DeviceHealthIssue>{};+ final battery = snapshot.battery;+ if (battery.status != DeviceSignalStatus.available) {+ issues.add(DeviceHealthIssue.batteryUnavailable);+ } else if (battery.levelPercent! < minimumBatteryLevel) {+ issues.add(DeviceHealthIssue.lowBattery);+ }++ if (snapshot.platform == DeviceHealthPlatform.android &&+ battery.status == DeviceSignalStatus.available) {+ final temperature = battery.temperatureCelsius;+ if (temperature == null) {+ issues.add(DeviceHealthIssue.batteryTemperatureUnavailable);+ } else if (temperature > maximumAndroidBatteryTemperature) {+ issues.add(DeviceHealthIssue.batteryTooHot);+ }++ final health = battery.health;+ if (health == null || health == DeviceBatteryHealth.unknown) {+ issues.add(DeviceHealthIssue.batteryHealthUnavailable);+ } else if (health != DeviceBatteryHealth.good) {+ issues.add(DeviceHealthIssue.batteryUnhealthy);+ }+ }++ final thermal = snapshot.thermal;+ if (thermal.status == DeviceSignalStatus.available) {+ if (!_isAcceptableThermalState(thermal.state!)) {+ issues.add(DeviceHealthIssue.thermalTooHigh);+ }+ } else if (!(snapshot.platform == DeviceHealthPlatform.android &&+ thermal.status == DeviceSignalStatus.unsupported &&+ battery.temperatureCelsius != null &&+ battery.health != null &&+ battery.health != DeviceBatteryHealth.unknown)) {+ issues.add(DeviceHealthIssue.thermalUnavailable);+ }++ return DeviceHealthEvaluation(Set.unmodifiable(issues));+ }++ bool _isAcceptableThermalState(DeviceThermalState state) => switch (state) {+ DeviceThermalState.nominal ||+ DeviceThermalState.light ||+ DeviceThermalState.moderate => true,+ DeviceThermalState.serious ||+ DeviceThermalState.critical ||+ DeviceThermalState.emergency ||+ DeviceThermalState.shutdown => false,+ };+}diff --git a/mobile/apps/photos/lib/utils/ram_check_util.dart b/mobile/apps/photos/lib/utils/ram_check_util.dartindex 1593c3164b..8fd64c489a 100644--- a/mobile/apps/photos/lib/utils/ram_check_util.dart+++ b/mobile/apps/photos/lib/utils/ram_check_util.dart@@ -1,4 +1,4 @@-import "package:system_info_plus/system_info_plus.dart";+import "package:ente_photos_platform/ente_photos_platform.dart";/// The total amount of RAM in the device in MBint? deviceTotalRAM;@@ -14,6 +14,14 @@ bool get enoughRamForLocalGalleryLocalIndexing =>/// Return the total amount of RAM in the device in MBFuture<int?> checkDeviceTotalRAM() async {- deviceTotalRAM ??= await SystemInfoPlus.physicalMemory; // returns in MB+ if (deviceTotalRAM != null) return deviceTotalRAM;+ try {+ final memory = await EntePhotosDeviceHealth.instance.getMemorySnapshot();+ if (memory.status == DeviceSignalStatus.available) {+ deviceTotalRAM = memory.totalBytes! ~/ (1024 * 1024);+ }+ } catch (_) {+ return null;+ }return deviceTotalRAM;}diff --git a/mobile/apps/photos/pubspec.yaml b/mobile/apps/photos/pubspec.yamlindex 54c165f712..96c4f48445 100644--- a/mobile/apps/photos/pubspec.yaml+++ b/mobile/apps/photos/pubspec.yaml@@ -27,10 +27,6 @@ dependencies:audio_session: 0.2.2backup_exclusion:path: ../../packages/backup_exclusion- battery_info: # replace with battery_plus- git:- url: https://github.com/ente/battery_info- ref: 95c7a9f0400b968b3bfdc98c8c10a07fb4a62ea2bip39: 1.0.6cached_network_image: 3.4.1camera: 0.11.2+1@@ -72,6 +68,8 @@ dependencies:path: ../../packages/lock_screenente_panorama_viewer:path: plugins/ente_panorama_viewer+ ente_photos_platform:+ path: plugins/ente_photos_platformente_photos_rust:path: rust_builderente_pure_utils:@@ -214,8 +212,6 @@ dependencies:sqlite_async: 0.11.7styled_text: 8.1.0synchronized: 3.4.0- system_info_plus: 0.0.6- thermal: 1.1.11timezone: 0.10.1tuple: 2.0.2ua_client_hints: 1.4.1diff --git a/mobile/apps/photos/test/services/machine_learning/device_health_policy_test.dart b/mobile/apps/photos/test/services/machine_learning/device_health_policy_test.dartnew file mode 100644index 0000000000..5ac371285c--- /dev/null+++ b/mobile/apps/photos/test/services/machine_learning/device_health_policy_test.dart@@ -0,0 +1,179 @@+import 'package:ente_photos_platform/ente_photos_platform.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:photos/services/machine_learning/device_health_policy.dart';++void main() {+ const policy = DeviceHealthPolicy();+ final now = DateTime(2026, 8, 6, 12);++ test('accepts fresh healthy Android evidence', () {+ expect(policy.evaluate(_snapshot(now), now: now).issues, isEmpty);+ });++ test('rejects stale and future observations', () {+ expect(+ policy+ .evaluate(+ _snapshot(now.subtract(const Duration(minutes: 3))),+ now: now,+ )+ .issues,+ {DeviceHealthIssue.staleObservation},+ );+ expect(+ policy+ .evaluate(+ _snapshot(now.add(const Duration(milliseconds: 1))),+ now: now,+ )+ .issues,+ {DeviceHealthIssue.staleObservation},+ );+ });++ test('rejects unavailable or low battery evidence', () {+ expect(+ policy+ .evaluate(+ _snapshot(+ now,+ battery: const DeviceBatterySnapshot(+ status: DeviceSignalStatus.unavailable,+ errorCode: 'battery_read_failed',+ ),+ ),+ now: now,+ )+ .issues,+ contains(DeviceHealthIssue.batteryUnavailable),+ );+ expect(+ policy+ .evaluate(+ _snapshot(now, battery: _androidBattery(level: 19)),+ now: now,+ )+ .issues,+ contains(DeviceHealthIssue.lowBattery),+ );+ });++ test('rejects hot or unknown Android battery evidence', () {+ expect(+ policy+ .evaluate(+ _snapshot(now, battery: _androidBattery(temperature: 42.1)),+ now: now,+ )+ .issues,+ contains(DeviceHealthIssue.batteryTooHot),+ );+ expect(+ policy+ .evaluate(+ _snapshot(+ now,+ battery: _androidBattery(health: DeviceBatteryHealth.unknown),+ ),+ now: now,+ )+ .issues,+ contains(DeviceHealthIssue.batteryHealthUnavailable),+ );+ });++ test('rejects serious thermal state', () {+ expect(+ policy+ .evaluate(+ _snapshot(+ now,+ thermal: const DeviceThermalSnapshot(+ status: DeviceSignalStatus.available,+ state: DeviceThermalState.serious,+ ),+ ),+ now: now,+ )+ .issues,+ contains(DeviceHealthIssue.thermalTooHigh),+ );+ });++ test('uses Android battery evidence when thermal APIs are unsupported', () {+ final evaluation = policy.evaluate(+ _snapshot(+ now,+ thermal: const DeviceThermalSnapshot(+ status: DeviceSignalStatus.unsupported,+ ),+ ),+ now: now,+ );++ expect(evaluation.issues, isEmpty);+ });++ test('accepts iOS without Android-only battery metrics', () {+ final evaluation = policy.evaluate(+ _snapshot(+ now,+ platform: DeviceHealthPlatform.ios,+ battery: const DeviceBatterySnapshot(+ status: DeviceSignalStatus.available,+ levelPercent: 80,+ ),+ ),+ now: now,+ );++ expect(evaluation.issues, isEmpty);+ });++ test('does not treat unsupported iOS thermal evidence as healthy', () {+ final evaluation = policy.evaluate(+ _snapshot(+ now,+ platform: DeviceHealthPlatform.ios,+ battery: const DeviceBatterySnapshot(+ status: DeviceSignalStatus.available,+ levelPercent: 80,+ ),+ thermal: const DeviceThermalSnapshot(+ status: DeviceSignalStatus.unsupported,+ ),+ ),+ now: now,+ );++ expect(evaluation.issues, contains(DeviceHealthIssue.thermalUnavailable));+ });+}++DeviceHealthSnapshot _snapshot(+ DateTime observedAt, {+ DeviceHealthPlatform platform = DeviceHealthPlatform.android,+ DeviceBatterySnapshot? battery,+ DeviceThermalSnapshot? thermal,+}) => DeviceHealthSnapshot(+ platform: platform,+ observedAt: observedAt,+ battery: battery ?? _androidBattery(),+ thermal:+ thermal ??+ const DeviceThermalSnapshot(+ status: DeviceSignalStatus.available,+ state: DeviceThermalState.nominal,+ ),+);++DeviceBatterySnapshot _androidBattery({+ int level = 80,+ double temperature = 30,+ DeviceBatteryHealth health = DeviceBatteryHealth.good,+}) => DeviceBatterySnapshot(+ status: DeviceSignalStatus.available,+ levelPercent: level,+ temperatureCelsius: temperature,+ health: health,+);diff --git a/mobile/pubspec.lock b/mobile/pubspec.lockindex 074e09d232..d1e9abee6e 100644--- a/mobile/pubspec.lock+++ b/mobile/pubspec.lock@@ -153,15 +153,6 @@ packages:url: "https://pub.dev"source: hostedversion: "2.1.3"- battery_info:- dependency: transitive- description:- path: "."- ref: "95c7a9f0400b968b3bfdc98c8c10a07fb4a62ea2"- resolved-ref: "95c7a9f0400b968b3bfdc98c8c10a07fb4a62ea2"- url: "https://github.com/ente/battery_info"- source: git- version: "1.1.1"bidi:dependency: transitivedescription:@@ -2798,14 +2789,6 @@ packages:url: "https://pub.dev"source: hostedversion: "3.4.0"- system_info_plus:- dependency: transitive- description:- name: system_info_plus- sha256: df94187e95527f9cb459e6a9f6e0b1ea20c157d8029bc233de34b3c1e17e1c48- url: "https://pub.dev"- source: hosted- version: "0.0.6"term_glyph:dependency: transitivedescription:@@ -2838,14 +2821,6 @@ packages:url: "https://pub.dev"source: hostedversion: "0.6.12"- thermal:- dependency: transitive- description:- name: thermal- sha256: c6275ebc609e75f1bbbfc354d56d6c559a0c6045a06a8e8c3939c03306a07e18- url: "https://pub.dev"- source: hosted- version: "1.1.11"timezone:dependency: transitivedescription: