π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Toggle to let ML run continuously
laurenspriem686706b4529b
diff --git a/mobile/apps/photos/lib/service_locator.dart b/mobile/apps/photos/lib/service_locator.dartindex e2f46bc91f..eafb4e5d3c 100644--- a/mobile/apps/photos/lib/service_locator.dart+++ b/mobile/apps/photos/lib/service_locator.dart@@ -213,7 +213,7 @@ BillingService get billingService {ComputeController? _computeController;ComputeController get computeController {- _computeController ??= ComputeController();+ _computeController ??= ComputeController(localSettings);return _computeController!;}diff --git a/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart b/mobile/apps/photos/lib/services/machine_learning/compute_controller.dartindex fabad2a55a..4a9fb1ac2a 100644--- a/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart+++ b/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart@@ -9,6 +9,7 @@ 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/utils/local_settings.dart";import "package:thermal/thermal.dart";enum ComputeRunState {@@ -24,6 +25,7 @@ class ComputeController {static const kMinimumBatteryLevel = 20; // 20%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;@@ -33,9 +35,12 @@ class ComputeController {bool _isDeviceHealthy = true;bool _isUserInteracting = true;bool _canRunCompute = false;+ bool _temporaryInteractionOverride = false;+ bool _debugInteractionOverride = false;/// If true, user interaction is ignored and compute tasks can run regardless of user activity.- bool interactionOverride = false;+ bool get interactionOverride =>+ _temporaryInteractionOverride || _debugInteractionOverride;/// If true, compute tasks are paused regardless of device health or user activity.bool get computeBlocked => _computeBlocks.isNotEmpty;@@ -54,7 +59,7 @@ class ComputeController {Bus.instance.fire(DeviceHealthChangedEvent(healthy));}- ComputeController() {+ ComputeController(this._localSettings) {_logger.info('ComputeController constructor');init();_logger.info('init done ');@@ -62,9 +67,14 @@ class ComputeController {// Directly assign the values + Attach listener for compute controllerFuture<void> init() async {- // Interaction Timer+ // Initialize interaction tracking before any await to avoid first-tap races._startInteractionTimer(kDefaultInteractionTimeout);+ await setMLDebugInteractionOverride(+ turnOn: _localSettings.runMLDuringInteractionOverride,+ persist: false,+ );+// Thermal related_onThermalStateUpdate(await _thermal.thermalStatus);_thermal.onThermalStatusChanged.listen((ThermalStatus thermalState) {@@ -112,9 +122,15 @@ class ComputeController {_logger.info("Device not healthy, denying request.");return false;}- if (!bypassInteractionCheck && !_canRunGivenUserInteraction()) {- _logger.info("User interacting, denying request.");- return false;+ if (!bypassInteractionCheck) {+ if (ml && !_canRunMLGivenUserInteraction()) {+ _logger.info("User interacting, denying ML request.");+ return false;+ }+ if (stream && !_canRunStreamGivenUserInteraction()) {+ _logger.info("User interacting, denying stream request.");+ return false;+ }}if (computeBlocked) {_logger.info("Compute is blocked by: $_computeBlocks, denying request.");@@ -190,13 +206,29 @@ class ComputeController {_resetTimer();}- bool _canRunGivenUserInteraction() {+ bool _canRunMLGivenUserInteraction() {return !_isUserInteracting || interactionOverride;}+ bool _canRunStreamGivenUserInteraction() {+ return !_isUserInteracting;+ }+void forceOverrideML({required bool turnOn}) {_logger.info("Forcing to turn on ML: $turnOn");- interactionOverride = turnOn;+ _temporaryInteractionOverride = turnOn;+ _fireControlEvent();+ }++ Future<void> setMLDebugInteractionOverride({+ required bool turnOn,+ bool persist = true,+ }) async {+ if (persist) {+ await _localSettings.setRunMLDuringInteractionOverride(turnOn);+ }+ _debugInteractionOverride = turnOn;+ _logger.info("ML debug interaction override set to: $turnOn");_fireControlEvent();}@@ -214,7 +246,7 @@ class ComputeController {void _fireControlEvent() {final shouldRunCompute =- _isDeviceHealthy && _canRunGivenUserInteraction() && !computeBlocked;+ _isDeviceHealthy && _canRunMLGivenUserInteraction() && !computeBlocked;if (shouldRunCompute != _canRunCompute) {_canRunCompute = shouldRunCompute;_logger.info(diff --git a/mobile/apps/photos/lib/ui/settings/debug/ml_debug_settings_page.dart b/mobile/apps/photos/lib/ui/settings/debug/ml_debug_settings_page.dartindex bd2405e567..79bebf66c6 100644--- a/mobile/apps/photos/lib/ui/settings/debug/ml_debug_settings_page.dart+++ b/mobile/apps/photos/lib/ui/settings/debug/ml_debug_settings_page.dart@@ -181,6 +181,17 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {onChanged: _onAutoIndexingChanged,),),+ MenuItemWidgetNew(+ title: "Run ML on interactions",+ leadingIconWidget: _buildIconWidget(+ context,+ HugeIcons.strokeRoundedPlay,+ ),+ trailingWidget: ToggleSwitchWidget(+ value: () => localSettings.runMLDuringInteractionOverride,+ onChanged: _onRunMLDuringInteractionChanged,+ ),+ ),],);}@@ -685,6 +696,24 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {}}+ Future<void> _onRunMLDuringInteractionChanged() async {+ try {+ final enabled = !localSettings.runMLDuringInteractionOverride;+ await computeController.setMLDebugInteractionOverride(turnOn: enabled);+ logger.info(+ 'run ML during interaction is turned ${enabled ? 'on' : 'off'}',+ );+ if (mounted) {+ setState(() {});+ }+ } catch (e, s) {+ logger.warning('run ML during interaction toggle failed ', e, s);+ if (mounted) {+ await showGenericErrorDialog(context: context, error: e);+ }+ }+ }+Future<void> _onTriggerRunML(BuildContext context) async {try {MLService.instance.debugIndexingDisabled = false;diff --git a/mobile/apps/photos/lib/utils/local_settings.dart b/mobile/apps/photos/lib/utils/local_settings.dartindex f1bcd5948d..d7832823df 100644--- a/mobile/apps/photos/lib/utils/local_settings.dart+++ b/mobile/apps/photos/lib/utils/local_settings.dart@@ -81,6 +81,8 @@ class LocalSettings {static const _kAutoMergeThresholdOverride = "ml_debug.auto_merge_threshold";static const _kDefaultClusteringDistanceOverride ="ml_debug.default_clustering_distance";+ static const _kRunMLDuringInteractionOverride =+ "ml_debug.run_ml_during_interaction";static const _kAppMode = "ls.app_mode";static const _kShowOfflineModeOption = "ls.show_offline_mode_option";@@ -281,6 +283,13 @@ class LocalSettings {await _prefs.setDouble(_kDefaultClusteringDistanceOverride, value);}+ bool get runMLDuringInteractionOverride =>+ _prefs.getBool(_kRunMLDuringInteractionOverride) ?? false;++ Future<void> setRunMLDuringInteractionOverride(bool value) async {+ await _prefs.setBool(_kRunMLDuringInteractionOverride, value);+ }+Future<bool> setSmartMemories(bool value) async {await _prefs.setBool(kCuratedMemoriesEnabled, value);return value;