diff --git a/lib/app.dart b/lib/app.dart index abb974742..d7e358df2 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -62,6 +62,7 @@ class _EnteAppState extends State with WidgetsBindingObserver { @override void initState() { + _logger.info('init App'); super.initState(); WidgetsBinding.instance.addObserver(this); _configureBackgroundFetch(); @@ -96,7 +97,8 @@ class _EnteAppState extends State with WidgetsBindingObserver { void didChangeAppLifecycleState(AppLifecycleState state) { final String stateChangeReason = 'app -> $state'; if (state == AppLifecycleState.resumed) { - AppLifecycleService.instance.onAppInForeground(stateChangeReason); + AppLifecycleService.instance + .onAppInForeground(stateChangeReason + ': sync now'); SyncService.instance.sync(); } else { AppLifecycleService.instance.onAppInBackground(stateChangeReason); diff --git a/lib/main.dart b/lib/main.dart index e2d195061..f5f879f65 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -55,7 +55,7 @@ Future _runInForeground() async { return await _runWithLogs(() async { _logger.info("Starting app in foreground"); await _init(false, via: 'mainMethod'); - _scheduleFGSync(); + _scheduleFGSync('appStart in FG'); runApp(AppLock( builder: (args) => EnteApp(_runBackgroundTask, _killBGTask), lockScreen: LockScreen(), @@ -68,7 +68,7 @@ Future _runInForeground() async { Future _runBackgroundTask(String taskId) async { if (Platform.isIOS && _isProcessRunning) { _logger.info("Background task triggered when process was already running"); - await _sync(); + await _sync('bgTaskActiveProcess'); BackgroundFetch.finish(taskId); } else { _runWithLogs(() async { @@ -94,7 +94,7 @@ Future _runInBackground(String taskId) async { } await _init(true, via: 'runViaBackgroundTask'); UpdateService.instance.showUpdateNotification(); - await _sync(); + await _sync('bgSync'); BackgroundFetch.finish(taskId); } @@ -141,9 +141,11 @@ Future _init(bool isBackground, {String via = ''}) async { _logger.info("Initialization done"); } -Future _sync() async { +Future _sync(String caller) async { if (!AppLifecycleService.instance.isForeground) { - _logger.info("Syncing in background"); + _logger.info("Syncing in background caller $caller"); + } else { + _logger.info("Syncing in foreground caller $caller"); } try { await SyncService.instance.sync(); @@ -153,7 +155,6 @@ Future _sync() async { } Future _runWithLogs(Function() function, {String prefix = ""}) async { - print('init logs wrapper with prefix = $prefix'); await SuperLogging.main(LogConfig( body: function, logDirPath: (await getTemporaryDirectory()).path + "/logs", @@ -174,10 +175,10 @@ Future _scheduleHeartBeat(bool isBackground) async { }); } -Future _scheduleFGSync() async { - await _sync(); +Future _scheduleFGSync(String caller) async { + await _sync(caller); Future.delayed(kFGSyncFrequency, () async { - _scheduleFGSync(); + _scheduleFGSync('fgSyncCron'); }); } @@ -217,7 +218,7 @@ Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { _logger.info( "Background push received when app is alive and runningInFS: $isRunningInFG"); if (PushService.shouldSync(message)) { - await _sync(); + await _sync('firebaseBgSyncActiveProcess'); } } else { // App is dead @@ -228,7 +229,7 @@ Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { } await _init(true, via: 'firebasePush'); if (PushService.shouldSync(message)) { - await _sync(); + await _sync('firebaseBgSyncNoActiveProcess'); } }, prefix: "[fbg]"); }