Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Keep the screen awake while Search shows ML progress

r4khulffed3c6f02bc
diff --git a/mobile/apps/photos/changes/ml-consent-screen.md b/mobile/apps/photos/changes/ml-consent-screen.md
index 3b236ed5d8..146fd119b7 100644
--- a/mobile/apps/photos/changes/ml-consent-screen.md
+++ b/mobile/apps/photos/changes/ml-consent-screen.md
@@ -1 +1 @@
-- Refreshed the machine learning consent screen and added a consent sheet for the home banner and People widgets. The People widget setup page now shows machine learning progress. Search now shows it when signed in too.
+- Refreshed the machine learning consent screen and added a consent sheet for the home banner and People widgets. The People widget setup page now shows machine learning progress. Search now shows it when signed in too, and keeps the screen on while photos are processed.
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 e79511e87a..6e086fdae2 100644
--- a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
@@ -69,7 +69,7 @@ class MLService {
static const _kPredownloadLocalModelsDelay = Duration(seconds: 10);
static const _kDeniedRunRetryDelay = Duration(seconds: 15);
- bool get _isRunningML =>
+ bool get isRunningML =>
MlProcessLock.instance.activeOperation == MlOperation.fullRun;
static const _kForceClusteringFaceCount = 8000;
@@ -354,7 +354,7 @@ class MLService {
);
return MlRunDisposition.stopped;
}
- if (_isRunningML) {
+ if (isRunningML) {
_logger.info("runAllML called while already running, skipping");
_scheduleDeniedRunRetry();
return MlRunDisposition.denied;
diff --git a/mobile/apps/photos/lib/services/wake_lock_service.dart b/mobile/apps/photos/lib/services/wake_lock_service.dart
index 6a79b27403..e820e75b94 100644
--- a/mobile/apps/photos/lib/services/wake_lock_service.dart
+++ b/mobile/apps/photos/lib/services/wake_lock_service.dart
@@ -7,6 +7,7 @@ enum WakeLockFor {
rewindViewer,
largeBackupStandbyScreen,
albumSlideshow,
+ mlProgressBanner,
}
class EnteWakeLockService {
diff --git a/mobile/apps/photos/lib/ui/components/banners/ml_progress_banner.dart b/mobile/apps/photos/lib/ui/components/banners/ml_progress_banner.dart
index 673fdc6881..9dea4e4efc 100644
--- a/mobile/apps/photos/lib/ui/components/banners/ml_progress_banner.dart
+++ b/mobile/apps/photos/lib/ui/components/banners/ml_progress_banner.dart
@@ -12,6 +12,8 @@ import "package:photos/events/local_photos_updated_event.dart";
import "package:photos/events/notification_event.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/machine_learning/ml_model_download_service.dart";
+import "package:photos/services/machine_learning/ml_service.dart";
+import "package:photos/services/wake_lock_service.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/settings/ml/machine_learning_settings_page.dart";
import "package:photos/utils/ml_util.dart";
@@ -25,11 +27,13 @@ class MLProgressBanner extends StatefulWidget {
State<MLProgressBanner> createState() => _MLProgressBannerState();
}
-class _MLProgressBannerState extends State<MLProgressBanner> {
+class _MLProgressBannerState extends State<MLProgressBanner>
+ with WidgetsBindingObserver {
IndexStatus? _indexStatus;
Timer? _timer;
bool _dismissed = false;
bool _indexingComplete = false;
+ bool _keepsScreenAwake = false;
late final StreamSubscription<LocalPhotosUpdatedEvent>
_localPhotosUpdatedSubscription;
late final StreamSubscription<NotificationEvent> _notificationSubscription;
@@ -39,6 +43,7 @@ class _MLProgressBannerState extends State<MLProgressBanner> {
@override
void initState() {
super.initState();
+ WidgetsBinding.instance.addObserver(this);
widget.isOnSearchTab?.addListener(_onSearchTabChanged);
_localPhotosUpdatedSubscription = Bus.instance
.on<LocalPhotosUpdatedEvent>()
@@ -69,6 +74,7 @@ class _MLProgressBannerState extends State<MLProgressBanner> {
void _stopPolling() {
_timer?.cancel();
_timer = null;
+ _updateWakeLock();
}
void _onSearchTabChanged() {
@@ -106,6 +112,20 @@ class _MLProgressBannerState extends State<MLProgressBanner> {
status.pendingItems > 0;
}
+ void _updateWakeLock() {
+ final keepScreenAwake =
+ (widget.isOnSearchTab?.value ?? false) &&
+ _isShown &&
+ MLService.instance.isRunningML &&
+ WidgetsBinding.instance.lifecycleState == AppLifecycleState.resumed;
+ if (keepScreenAwake == _keepsScreenAwake) return;
+ _keepsScreenAwake = keepScreenAwake;
+ wakeLockService.updateWakeLock(
+ enable: keepScreenAwake,
+ wakeLockFor: WakeLockFor.mlProgressBanner,
+ );
+ }
+
Future<void> _fetchStatus() async {
try {
final status = await getIndexStatus();
@@ -117,10 +137,16 @@ class _MLProgressBannerState extends State<MLProgressBanner> {
_indexingComplete = true;
_stopPolling();
}
+ _updateWakeLock();
}
} catch (_) {}
}
+ @override
+ void didChangeAppLifecycleState(AppLifecycleState state) {
+ _updateWakeLock();
+ }
+
@override
void didUpdateWidget(MLProgressBanner oldWidget) {
super.didUpdateWidget(oldWidget);
@@ -133,10 +159,17 @@ class _MLProgressBannerState extends State<MLProgressBanner> {
@override
void dispose() {
+ WidgetsBinding.instance.removeObserver(this);
widget.isOnSearchTab?.removeListener(_onSearchTabChanged);
_localPhotosUpdatedSubscription.cancel();
_notificationSubscription.cancel();
_timer?.cancel();
+ if (_keepsScreenAwake) {
+ wakeLockService.updateWakeLock(
+ enable: false,
+ wakeLockFor: WakeLockFor.mlProgressBanner,
+ );
+ }
super.dispose();
}