Only stop the FCM foreground service if it was used.

fork-5.53.8
Greyson Parrelli 2022-05-13 09:12:02 -04:00
rodzic ad626fe7ee
commit a9bdc1abfc
1 zmienionych plików z 9 dodań i 1 usunięć

Wyświetl plik

@ -36,12 +36,16 @@ object FcmFetchManager {
@Volatile
private var activeCount = 0
@Volatile
private var startedForeground = false
@JvmStatic
fun enqueue(context: Context, foreground: Boolean) {
synchronized(this) {
if (foreground) {
Log.i(TAG, "Starting in the foreground.")
ContextCompat.startForegroundService(context, Intent(context, FcmFetchForegroundService::class.java))
startedForeground = true
} else {
Log.i(TAG, "Starting in the background.")
context.startService(Intent(context, FcmFetchBackgroundService::class.java))
@ -67,7 +71,11 @@ object FcmFetchManager {
if (activeCount <= 0) {
Log.i(TAG, "No more active. Stopping.")
context.stopService(Intent(context, FcmFetchBackgroundService::class.java))
context.startService(FcmFetchForegroundService.buildStopIntent(context))
if (startedForeground) {
context.startService(FcmFetchForegroundService.buildStopIntent(context))
startedForeground = false
}
}
}
}