Add fallback to synchronous fetch when onCreate() fails

Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-07 15:58:54 +00:00
parent 2297a72e29
commit e68bb791f7
@@ -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;
}