mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-23 11:15:44 +00:00
Dont block main thread when we try to stop FCM fetch service.
This commit is contained in:
@@ -47,6 +47,7 @@ class FcmFetchForegroundService : Service() {
|
||||
return if (intent != null && intent.getBooleanExtra(KEY_STOP_SELF, false)) {
|
||||
stopForeground(true)
|
||||
stopSelf()
|
||||
FcmFetchManager.onForegroundFetchServiceStop()
|
||||
START_NOT_STICKY
|
||||
} else {
|
||||
START_STICKY
|
||||
|
||||
@@ -39,6 +39,9 @@ object FcmFetchManager {
|
||||
@Volatile
|
||||
private var startedForeground = false
|
||||
|
||||
@Volatile
|
||||
private var stoppingForeground = false
|
||||
|
||||
/**
|
||||
* @return True if a service was successfully started, otherwise false.
|
||||
*/
|
||||
@@ -89,6 +92,7 @@ object FcmFetchManager {
|
||||
if (startedForeground) {
|
||||
try {
|
||||
context.startService(FcmFetchForegroundService.buildStopIntent(context))
|
||||
stoppingForeground = true
|
||||
} catch (e: IllegalStateException) {
|
||||
Log.w(TAG, "Failed to stop the foreground notification!", e)
|
||||
}
|
||||
@@ -102,7 +106,10 @@ object FcmFetchManager {
|
||||
@JvmStatic
|
||||
fun tryLegacyFallback(context: Context) {
|
||||
synchronized(this) {
|
||||
if (startedForeground) {
|
||||
if (startedForeground || stoppingForeground) {
|
||||
if (stoppingForeground) {
|
||||
Log.i(TAG, "Legacy fallback: foreground service is stopping, but trying to run in background anyways.")
|
||||
}
|
||||
val performedReplace = EXECUTOR.enqueue { fetch(context) }
|
||||
|
||||
if (performedReplace) {
|
||||
@@ -134,4 +141,11 @@ object FcmFetchManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onForegroundFetchServiceStop() {
|
||||
synchronized(this) {
|
||||
stoppingForeground = false
|
||||
Log.i(TAG, "Foreground service stopped successfully")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user