Browse Source

ElementCall: CallForegroundService now use the Microphone permissions.

pull/3685/head
Benoit Marty 3 days ago
parent
commit
5f42b7732b
  1. 6
      features/call/impl/src/main/AndroidManifest.xml
  2. 10
      features/call/impl/src/main/kotlin/io/element/android/features/call/impl/services/CallForegroundService.kt

6
features/call/impl/src/main/AndroidManifest.xml

@ -21,8 +21,8 @@ @@ -21,8 +21,8 @@
<!-- Permissions for call foreground services -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_PHONE_CALL" />
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<application>
@ -80,7 +80,7 @@ @@ -80,7 +80,7 @@
android:name=".services.CallForegroundService"
android:enabled="true"
android:exported="false"
android:foregroundServiceType="phoneCall" />
android:foregroundServiceType="microphone" />
<receiver
android:name=".receivers.DeclineCallBroadcastReceiver"

10
features/call/impl/src/main/kotlin/io/element/android/features/call/impl/services/CallForegroundService.kt

@ -7,9 +7,11 @@ @@ -7,9 +7,11 @@
package io.element.android.features.call.impl.services
import android.Manifest
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.ServiceInfo
import android.os.Build
import android.os.IBinder
@ -33,8 +35,12 @@ import timber.log.Timber @@ -33,8 +35,12 @@ import timber.log.Timber
class CallForegroundService : Service() {
companion object {
fun start(context: Context) {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) {
val intent = Intent(context, CallForegroundService::class.java)
ContextCompat.startForegroundService(context, intent)
} else {
Timber.w("Microphone permission is not granted, cannot start the call foreground service")
}
}
fun stop(context: Context) {
@ -67,8 +73,8 @@ class CallForegroundService : Service() { @@ -67,8 +73,8 @@ class CallForegroundService : Service() {
.setContentIntent(pendingIntent)
.build()
val notificationId = NotificationIdProvider.getForegroundServiceNotificationId(ForegroundServiceType.ONGOING_CALL)
val serviceType = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL
val serviceType = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
} else {
0
}

Loading…
Cancel
Save