mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 20:48:43 +00:00
Catch foreground service not allowed exceptions.
This commit is contained in:
committed by
Greyson Parrelli
parent
712616e569
commit
3b715bc461
@@ -1,5 +1,6 @@
|
||||
package org.thoughtcrime.securesms.service
|
||||
|
||||
import android.app.ForegroundServiceStartNotAllowedException
|
||||
import android.app.PendingIntent
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
@@ -190,6 +191,14 @@ class GenericForegroundService : Service() {
|
||||
stopSelf()
|
||||
}
|
||||
|
||||
private fun stop() {
|
||||
lock.withLock {
|
||||
allActiveMessages.clear()
|
||||
}
|
||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||
stopSelf()
|
||||
}
|
||||
|
||||
fun replaceTitle(id: Int, title: String) {
|
||||
lock.withLock {
|
||||
updateEntry(id) { oldEntry ->
|
||||
@@ -236,7 +245,11 @@ class GenericForegroundService : Service() {
|
||||
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 if (Build.VERSION.SDK_INT >= 31 && e is ForegroundServiceStartNotAllowedException) {
|
||||
Log.w(TAG, "Unable to start foreground service", e)
|
||||
stop()
|
||||
} else {
|
||||
Log.w(TAG, "Unhandled exception being thrown when starting a foreground service.", e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user