Skip to content

Commit 221d5bd

Browse files
authored
Merge pull request #5742 from nextcloud/bugfix/noid/fixSecurityExceptionStartForeground
fix SecurityException caused by wrong foregroundServiceType handling
2 parents e19b8b9 + 450c86d commit 221d5bd

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

app/src/main/java/com/nextcloud/talk/services/CallForegroundService.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ class CallForegroundService : Service() {
2929

3030
override fun onBind(intent: Intent?): IBinder? = null
3131

32-
@Suppress("ForegroundServiceType")
3332
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
3433
val conversationName = intent?.getStringExtra(EXTRA_CONVERSATION_NAME)
3534
val callExtras = intent?.getBundleExtra(EXTRA_CALL_INTENT_EXTRAS)
3635
val notification = buildNotification(conversationName, callExtras)
3736

38-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
39-
val foregroundServiceType = resolveForegroundServiceType(callExtras)
37+
val foregroundServiceType = resolveForegroundServiceType(callExtras)
38+
39+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && foregroundServiceType != FOREGROUND_SERVICE_TYPE_ZERO) {
4040
startForeground(NOTIFICATION_ID, notification, foregroundServiceType)
4141
} else {
4242
startForeground(NOTIFICATION_ID, notification)
@@ -107,6 +107,7 @@ class CallForegroundService : Service() {
107107

108108
companion object {
109109
private const val NOTIFICATION_ID = 47001
110+
private const val FOREGROUND_SERVICE_TYPE_ZERO = 0
110111
private const val EXTRA_CONVERSATION_NAME = "extra_conversation_name"
111112
private const val EXTRA_CALL_INTENT_EXTRAS = "extra_call_intent_extras"
112113

0 commit comments

Comments
 (0)