π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Integrate thermal state in check
laurensprieme493702c6450
diff --git a/mobile/lib/services/machine_learning/machine_learning_controller.dart b/mobile/lib/services/machine_learning/machine_learning_controller.dartindex 6db75a232d..c1c61d804f 100644--- a/mobile/lib/services/machine_learning/machine_learning_controller.dart+++ b/mobile/lib/services/machine_learning/machine_learning_controller.dart@@ -8,6 +8,7 @@ import "package:flutter/foundation.dart";import "package:logging/logging.dart";import "package:photos/core/event_bus.dart";import "package:photos/events/machine_learning_control_event.dart";+import "package:thermal/thermal.dart";class MachineLearningController {final _logger = Logger("MachineLearningController");@@ -17,6 +18,11 @@ class MachineLearningController {final kDefaultInteractionTimeout = Duration(seconds: Platform.isIOS ? 5 : 15);static const kUnhealthyStates = ["over_heat", "over_voltage", "dead"];+ static final _thermal = Thermal();+ IosBatteryInfo? _iosLastBatteryInfo;+ AndroidBatteryInfo? _androidLastBatteryInfo;+ ThermalStatus? _lastThermalStatus;+bool _isDeviceHealthy = true;bool _isUserInteracting = true;bool _canRunML = false;@@ -49,6 +55,9 @@ class MachineLearningController {_onAndroidBatteryStateUpdate(batteryInfo);});}+ _thermal.onThermalStatusChanged.listen((ThermalStatus thermalState) {+ _onThermalStateUpdate(thermalState);+ });_logger.info('init done ');}@@ -96,27 +105,61 @@ class MachineLearningController {}void _onAndroidBatteryStateUpdate(AndroidBatteryInfo? batteryInfo) {+ _androidLastBatteryInfo = batteryInfo;_logger.info("Battery info: ${batteryInfo!.toJson()}");- _isDeviceHealthy = _computeIsAndroidDeviceHealthy(batteryInfo);+ _isDeviceHealthy = _computeIsAndroidDeviceHealthy();_fireControlEvent();}void _oniOSBatteryStateUpdate(IosBatteryInfo? batteryInfo) {+ _iosLastBatteryInfo = batteryInfo;_logger.info("Battery info: ${batteryInfo!.toJson()}");- _isDeviceHealthy = _computeIsiOSDeviceHealthy(batteryInfo);+ _isDeviceHealthy = _computeIsiOSDeviceHealthy();+ _fireControlEvent();+ }++ void _onThermalStateUpdate(ThermalStatus? thermalStatus) {+ _lastThermalStatus = thermalStatus;+ _logger.info("Thermal status: $thermalStatus");+ _isDeviceHealthy = _computeIsAndroidDeviceHealthy();_fireControlEvent();}- bool _computeIsAndroidDeviceHealthy(AndroidBatteryInfo info) {- return _hasSufficientBattery(info.batteryLevel ?? kMinimumBatteryLevel) &&+ bool _computeIsAndroidDeviceHealthy() {+ return _hasSufficientBattery(+ _androidLastBatteryInfo?.batteryLevel ?? kMinimumBatteryLevel,+ ) &&_isAcceptableTemperatureAndroid(- info.temperature ?? kMaximumTemperatureAndroid,+ _androidLastBatteryInfo?.temperature ?? kMaximumTemperatureAndroid,) &&- _isBatteryHealthy(info.health ?? "");+ _isBatteryHealthyAndroid(_androidLastBatteryInfo?.health ?? "") &&+ _isAcceptableThermalState();}- bool _computeIsiOSDeviceHealthy(IosBatteryInfo info) {- return _hasSufficientBattery(info.batteryLevel ?? kMinimumBatteryLevel);+ bool _computeIsiOSDeviceHealthy() {+ return _hasSufficientBattery(+ _iosLastBatteryInfo?.batteryLevel ?? kMinimumBatteryLevel,+ ) &&+ _isAcceptableThermalState();+ }++ bool _isAcceptableThermalState() {+ switch (_lastThermalStatus) {+ case null:+ _logger.info("Thermal status is null, assuming acceptable temperature");+ return true;+ case ThermalStatus.none:+ case ThermalStatus.light:+ case ThermalStatus.moderate:+ _logger.info("Thermal status is acceptable: $_lastThermalStatus");+ return true;+ case ThermalStatus.severe:+ case ThermalStatus.critical:+ case ThermalStatus.emergency:+ case ThermalStatus.shutdown:+ _logger.warning("Thermal status is unacceptable: $_lastThermalStatus");+ return false;+ }}bool _hasSufficientBattery(int batteryLevel) {@@ -127,7 +170,7 @@ class MachineLearningController {return temperature <= kMaximumTemperatureAndroid;}- bool _isBatteryHealthy(String health) {+ bool _isBatteryHealthyAndroid(String health) {return !kUnhealthyStates.contains(health);}}diff --git a/mobile/pubspec.lock b/mobile/pubspec.lockindex 14ad1f5347..3e8a1e8b31 100644--- a/mobile/pubspec.lock+++ b/mobile/pubspec.lock@@ -2525,6 +2525,14 @@ packages:url: "https://pub.dev"source: hostedversion: "0.6.4"+ thermal:+ dependency: "direct main"+ description:+ name: thermal+ sha256: c6275ebc609e75f1bbbfc354d56d6c559a0c6045a06a8e8c3939c03306a07e18+ url: "https://pub.dev"+ source: hosted+ version: "1.1.11"timezone:dependency: "direct main"description:diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yamlindex 25701c6c44..aecaee0afe 100644--- a/mobile/pubspec.yaml+++ b/mobile/pubspec.yaml@@ -190,6 +190,7 @@ dependencies:syncfusion_flutter_sliders: ^25.2.5synchronized: ^3.3.0+3system_info_plus: ^0.0.6+ thermal: ^1.1.11timezone: ^0.9.4tuple: ^2.0.0ua_client_hints: ^1.4.0