diff --git a/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java b/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java index 4777e85fc..e6fc34b5f 100644 --- a/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java +++ b/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java @@ -91,11 +91,22 @@ public final class FetchForegroundService extends Service { try { startForeground(NotificationCenter.ID_FETCH, notification); } catch (Exception e) { - Log.w(TAG, "Failed to start foreground service", e); + Log.w(TAG, "Failed to start foreground service, falling back to synchronous fetch", e); synchronized (SERVICE_LOCK) { service = null; } stopSelf(); + // Fallback to synchronous fetching when foreground service fails + fetchingSynchronously = true; + if (ApplicationContext.getDcAccounts().backgroundFetch(10)) { + synchronized (STOP_NOTIFIER) { + while (fetchingSynchronously) { + try { + STOP_NOTIFIER.wait(); + } catch (InterruptedException ex) {} + } + } + } return; }