Fix for ForegroundServiceDidNotStartInTimeException for FcmFetchForegroundService.
This commit is contained in:
parent
2d6b16b2ce
commit
8971ff9057
2 changed files with 27 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue