mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 00:59:49 +01:00
Fix for ForegroundServiceDidNotStartInTimeException for FcmFetchForegroundService.
This commit is contained in:
@@ -72,6 +72,13 @@ object FcmFetchManager {
|
||||
return true
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isForegroundStarted(): Boolean {
|
||||
synchronized(this) {
|
||||
return startedForeground
|
||||
}
|
||||
}
|
||||
|
||||
private fun fetch(context: Context) {
|
||||
retrieveMessages(context)
|
||||
|
||||
@@ -95,6 +102,25 @@ object FcmFetchManager {
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun tryLegacyFallback(context: Context) {
|
||||
synchronized(this) {
|
||||
if (startedForeground) {
|
||||
val performedReplace = EXECUTOR.enqueue { fetch(context) }
|
||||
|
||||
if (performedReplace) {
|
||||
Log.i(TAG, "Legacy fallback: already have one running and one enqueued. Ignoring.")
|
||||
} else {
|
||||
activeCount++
|
||||
Log.i(TAG, "Legacy fallback: Incrementing active count to $activeCount")
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
Log.i(TAG, "No foreground running, performing legacy fallback")
|
||||
retrieveMessages(context)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun retrieveMessages(context: Context) {
|
||||
val success = ApplicationDependencies.getBackgroundMessageRetriever().retrieveMessages(context, WebSocketStrategy())
|
||||
|
||||
@@ -102,7 +102,7 @@ public class FcmReceiveService extends FirebaseMessagingService {
|
||||
|
||||
if (!enqueueSuccessful) {
|
||||
Log.w(TAG, "Unable to start service. Falling back to legacy approach.");
|
||||
FcmFetchManager.retrieveMessages(context);
|
||||
FcmFetchManager.tryLegacyFallback(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user