|
|
@ -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) { |
|
|
|
val intent = Intent(context, CallForegroundService::class.java) |
|
|
|
if (ContextCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) { |
|
|
|
ContextCompat.startForegroundService(context, intent) |
|
|
|
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) { |
|
|
|
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 |
|
|
|
} |
|
|
|
} |
|
|
|