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

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

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

Loading…
Cancel
Save