mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-02 00:17:41 +01:00
Fix attachment service crash due to timeout.
This commit is contained in:
@@ -9,6 +9,7 @@ import android.app.Notification
|
|||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -112,7 +113,16 @@ class AttachmentProgressService : SafeForegroundService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val listener = {
|
val listener = {
|
||||||
startForeground(notificationId, getForegroundNotification(Intent()))
|
try {
|
||||||
|
startForeground(notificationId, getForegroundNotification(Intent()))
|
||||||
|
} 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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val tag: String = TAG
|
override val tag: String = TAG
|
||||||
@@ -141,7 +151,10 @@ class AttachmentProgressService : SafeForegroundService() {
|
|||||||
|
|
||||||
override fun onTimeout(startId: Int, fgsType: Int) {
|
override fun onTimeout(startId: Int, fgsType: Int) {
|
||||||
Log.w(TAG, "AttachmentProgressService has timed out. Removing all controllers. startId: $startId, foregroundServiceType: $fgsType")
|
Log.w(TAG, "AttachmentProgressService has timed out. Removing all controllers. startId: $startId, foregroundServiceType: $fgsType")
|
||||||
|
stopDueToTimeout()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopDueToTimeout() {
|
||||||
controllerLock.withLock {
|
controllerLock.withLock {
|
||||||
controllers.forEach { it.closeFromTimeout() }
|
controllers.forEach { it.closeFromTimeout() }
|
||||||
stop(context = this, fromTimeout = true)
|
stop(context = this, fromTimeout = true)
|
||||||
|
|||||||
Reference in New Issue
Block a user