Try not blocking main threads to start foreground service.

This commit is contained in:
Clark
2023-05-17 13:43:01 -04:00
committed by Greyson Parrelli
parent 99d3f9918f
commit 534c5c3c64
4 changed files with 16 additions and 5 deletions

View File

@@ -25,6 +25,7 @@ import org.thoughtcrime.securesms.jobmanager.JobTracker
import org.thoughtcrime.securesms.jobmanager.JobTracker.JobListener
import org.thoughtcrime.securesms.jobmanager.impl.BackoffUtil
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
import org.thoughtcrime.securesms.jobs.ForegroundServiceUtil
import org.thoughtcrime.securesms.jobs.ForegroundServiceUtil.startWhenCapable
import org.thoughtcrime.securesms.jobs.PushDecryptMessageJob
import org.thoughtcrime.securesms.jobs.PushProcessMessageJob
@@ -94,9 +95,16 @@ class IncomingMessageObserver(private val context: Application) {
if (!SignalStore.account().fcmEnabled || SignalStore.internalValues().isWebsocketModeForced) {
try {
startWhenCapable(context, Intent(context, ForegroundService::class.java))
ForegroundServiceUtil.start(context, Intent(context, ForegroundService::class.java))
} catch (e: UnableToStartException) {
Log.w(TAG, "Unable to start foreground service for websocket!", e)
Log.w(TAG, "Unable to start foreground service for websocket. Deferring to background to try with blocking")
SignalExecutors.UNBOUNDED.execute {
try {
startWhenCapable(context, Intent(context, ForegroundService::class.java))
} catch (e: UnableToStartException) {
Log.w(TAG, "Unable to start foreground service for websocket!", e)
}
}
}
}