Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] Simplify heartbeat freshness checks and diagnostics

laurenspriem1600bbcbc6cf
diff --git a/mobile/apps/photos/lib/main.dart b/mobile/apps/photos/lib/main.dart
index 4aef6ed774..69d744787b 100644
--- a/mobile/apps/photos/lib/main.dart
+++ b/mobile/apps/photos/lib/main.dart
@@ -727,16 +727,18 @@ Future<void> _handleBackgroundPush(Object message) async {
}
Future<void> _logFGHeartBeatInfo(SharedPreferences prefs) async {
- final bool isDartEngineActive = await isDartForegroundEngineActive();
- final bool isNativeForeground = await isNativeForegroundActive();
await prefs.reload();
- final lastFGTaskHeartBeatTime = prefs.getInt(kLastFGTaskHeartBeatTime) ?? 0;
- final String lastRun = lastFGTaskHeartBeatTime == 0
+ final threshold =
+ DateTime.now().microsecondsSinceEpoch - kEngineDeathTimeoutInMicroseconds;
+ final lastDartBeatTime = prefs.getInt(kLastFGTaskHeartBeatTime) ?? 0;
+ final lastNativeBeatTime = prefs.getInt(kLastNativeFGTaskHeartBeatTime) ?? 0;
+ String describe(int beatTime) => beatTime == 0
? 'never'
- : DateTime.fromMicrosecondsSinceEpoch(lastFGTaskHeartBeatTime).toString();
+ : DateTime.fromMicrosecondsSinceEpoch(beatTime).toString();
_logger.info(
- 'isDartForegroundEngineActive: $isDartEngineActive, '
- 'isNativeForegroundActive: $isNativeForeground, '
- 'last Dart beat: $lastRun',
+ 'dartFGBeatFresh: ${lastDartBeatTime > threshold}, '
+ 'nativeFGBeatFresh: ${lastNativeBeatTime > threshold}, '
+ 'last Dart beat: ${describe(lastDartBeatTime)}, '
+ 'last native beat: ${describe(lastNativeBeatTime)}',
);
}
diff --git a/mobile/apps/photos/lib/services/process_activity.dart b/mobile/apps/photos/lib/services/process_activity.dart
index bdac4775e2..04a14668e4 100644
--- a/mobile/apps/photos/lib/services/process_activity.dart
+++ b/mobile/apps/photos/lib/services/process_activity.dart
@@ -9,21 +9,13 @@ const kEngineDeathTimeoutInMicroseconds = 5000000;
Future<bool> isForegroundEngineActive() =>
_isEngineActive([kLastFGTaskHeartBeatTime, kLastNativeFGTaskHeartBeatTime]);
-Future<bool> isDartForegroundEngineActive() =>
- _isEngineActive([kLastFGTaskHeartBeatTime]);
-
-Future<bool> isNativeForegroundActive() =>
- _isEngineActive([kLastNativeFGTaskHeartBeatTime]);
-
Future<bool> isBackgroundEngineActive() =>
_isEngineActive([kLastBGTaskHeartBeatTime]);
Future<bool> _isEngineActive(List<String> heartBeatKeys) async {
final prefs = await SharedPreferences.getInstance();
await prefs.reload();
- final currentTime = DateTime.now().microsecondsSinceEpoch;
- final lastHeartBeatTime = heartBeatKeys
- .map((key) => prefs.getInt(key) ?? 0)
- .reduce((latest, heartbeat) => latest > heartbeat ? latest : heartbeat);
- return lastHeartBeatTime > (currentTime - kEngineDeathTimeoutInMicroseconds);
+ final threshold =
+ DateTime.now().microsecondsSinceEpoch - kEngineDeathTimeoutInMicroseconds;
+ return heartBeatKeys.any((key) => (prefs.getInt(key) ?? 0) > threshold);
}