mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 20:48:43 +00:00
Add additional foreground service timeout check.
This commit is contained in:
@@ -178,6 +178,10 @@ class GenericForegroundService : Service() {
|
||||
|
||||
override fun onTimeout(startId: Int, foregroundServiceType: Int) {
|
||||
Log.i(TAG, "[onTimeout] startId: $startId, fgsType: $foregroundServiceType")
|
||||
stopDueToTimeout()
|
||||
}
|
||||
|
||||
private fun stopDueToTimeout() {
|
||||
lock.withLock {
|
||||
hasTimedOut = true
|
||||
allActiveMessages.clear()
|
||||
@@ -217,16 +221,25 @@ class GenericForegroundService : Service() {
|
||||
private fun postObligatoryForegroundNotification(active: Entry) {
|
||||
lastPosted = active
|
||||
|
||||
startForeground(
|
||||
NOTIFICATION_ID,
|
||||
NotificationCompat.Builder(this, active.channelId)
|
||||
.setSmallIcon(active.iconRes)
|
||||
.setContentTitle(active.title)
|
||||
.setProgress(active.progressMax, active.progress, active.indeterminate)
|
||||
.setContentIntent(PendingIntent.getActivity(this, 0, MainActivity.clearTop(this), mutable()))
|
||||
.setVibrate(longArrayOf(0))
|
||||
.build()
|
||||
)
|
||||
try {
|
||||
startForeground(
|
||||
NOTIFICATION_ID,
|
||||
NotificationCompat.Builder(this, active.channelId)
|
||||
.setSmallIcon(active.iconRes)
|
||||
.setContentTitle(active.title)
|
||||
.setProgress(active.progressMax, active.progress, active.indeterminate)
|
||||
.setContentIntent(PendingIntent.getActivity(this, 0, MainActivity.clearTop(this), mutable()))
|
||||
.setVibrate(longArrayOf(0))
|
||||
.build()
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
if (Build.VERSION.SDK_INT >= 31 && e.message?.contains("Time limit", ignoreCase = true) == true) {
|
||||
Log.w(TAG, "Foreground service timed out, but not in onTimeout call", e)
|
||||
stopDueToTimeout()
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateEntry(id: Int, transform: (Entry) -> Entry) {
|
||||
|
||||
Reference in New Issue
Block a user