|
|
|
|
@ -43,6 +43,9 @@ class CallService : Service() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val audio = CallAudioEngine() |
|
|
|
|
var video: CallVideoEngine? = null |
|
|
|
|
private set |
|
|
|
|
private var cameraForeground = false |
|
|
|
|
private var callId = 0L |
|
|
|
|
private var wakeLock: PowerManager.WakeLock? = null |
|
|
|
|
private var powerEventsRegistered = false |
|
|
|
|
@ -137,7 +140,8 @@ class CallService : Service() {
|
|
|
|
|
val micType = if (microphone && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) |
|
|
|
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE else 0 |
|
|
|
|
val types = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { |
|
|
|
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL or micType |
|
|
|
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL or micType or |
|
|
|
|
(if (cameraForeground && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA else 0) |
|
|
|
|
} else 0 |
|
|
|
|
ServiceCompat.startForeground(this, NOTIFICATION_ID, notification(), types) |
|
|
|
|
LogManager.addLog("INFO", "CallService", "foreground notification id=$callId phase=${CallController.state.value?.phase}") |
|
|
|
|
@ -149,7 +153,14 @@ class CallService : Service() {
|
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
audio.router.setPreferredRoute(ChatApplication.instance.configProvider.getCallAudioRoute()) |
|
|
|
|
return audio.start(id) |
|
|
|
|
if (!audio.start(id)) return false |
|
|
|
|
video = CallVideoEngine(this, id) |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun setVideoCapture(enabled: Boolean): Boolean { |
|
|
|
|
return try { cameraForeground = enabled; promote(true); true } |
|
|
|
|
catch (e: Exception) { cameraForeground = false; LogManager.addLog("ERROR", "call", "camera foreground failed: ${e.message}"); false } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun updateNotification() { |
|
|
|
|
@ -202,6 +213,7 @@ class CallService : Service() {
|
|
|
|
|
|
|
|
|
|
private fun releaseResources() { |
|
|
|
|
val id = callId |
|
|
|
|
video?.stop(); video = null; cameraForeground = false |
|
|
|
|
if (powerEventsRegistered) { |
|
|
|
|
try { unregisterReceiver(powerEvents) } |
|
|
|
|
catch (e: Exception) { LogManager.addLog("WARN", "CallService", "power receiver cleanup failed id=$id: ${e.message}") } |
|
|
|
|
|