Add FOREGROUND_SERVICE_TYPE_MICROPHONE to status notification only if RECORD_AUDIO permission has been granted
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.tutpro.baresip
|
package com.tutpro.baresip
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
|
import android.Manifest.permission.RECORD_AUDIO
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Notification
|
import android.app.Notification
|
||||||
import android.app.NotificationChannel
|
import android.app.NotificationChannel
|
||||||
@@ -831,7 +832,7 @@ class BaresipService: Service() {
|
|||||||
"incoming call" -> {
|
"incoming call" -> {
|
||||||
val peerUri = ev[1]
|
val peerUri = ev[1]
|
||||||
val bevent = ev[2].toLong()
|
val bevent = ev[2].toLong()
|
||||||
val toastMsg = if (!Utils.checkPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO)))
|
val toastMsg = if (!Utils.checkPermissions(this, arrayOf(RECORD_AUDIO)))
|
||||||
getString(R.string.no_calls)
|
getString(R.string.no_calls)
|
||||||
else if (!requestAudioFocus(applicationContext))
|
else if (!requestAudioFocus(applicationContext))
|
||||||
// request fails if there is an active telephony call
|
// request fails if there is an active telephony call
|
||||||
@@ -1324,10 +1325,14 @@ class BaresipService: Service() {
|
|||||||
if (VERSION.SDK_INT >= 29)
|
if (VERSION.SDK_INT >= 29)
|
||||||
startForeground(
|
startForeground(
|
||||||
STATUS_NOTIFICATION_ID, snb.build(),
|
STATUS_NOTIFICATION_ID, snb.build(),
|
||||||
if (VERSION.SDK_INT >= 30)
|
if (VERSION.SDK_INT >= 30) {
|
||||||
|
if (ContextCompat.checkSelfPermission(this, RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED)
|
||||||
FOREGROUND_SERVICE_TYPE_PHONE_CALL or FOREGROUND_SERVICE_TYPE_MICROPHONE
|
FOREGROUND_SERVICE_TYPE_PHONE_CALL or FOREGROUND_SERVICE_TYPE_MICROPHONE
|
||||||
else
|
else
|
||||||
FOREGROUND_SERVICE_TYPE_PHONE_CALL
|
FOREGROUND_SERVICE_TYPE_PHONE_CALL
|
||||||
|
}
|
||||||
|
else
|
||||||
|
FOREGROUND_SERVICE_TYPE_PHONE_CALL
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
startForeground(STATUS_NOTIFICATION_ID, snb.build())
|
startForeground(STATUS_NOTIFICATION_ID, snb.build())
|
||||||
|
|||||||
Reference in New Issue
Block a user