diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml index 1f4eb1ef93..a15f56a045 100644 --- a/vector/src/main/AndroidManifest.xml +++ b/vector/src/main/AndroidManifest.xml @@ -44,7 +44,6 @@ - @@ -58,6 +57,9 @@ + + + diff --git a/vector/src/withdmvoip/java/im/vector/app/features/call/VectorCallActivity.kt b/vector/src/withdmvoip/java/im/vector/app/features/call/VectorCallActivity.kt index a688c6caab..7919320871 100644 --- a/vector/src/withdmvoip/java/im/vector/app/features/call/VectorCallActivity.kt +++ b/vector/src/withdmvoip/java/im/vector/app/features/call/VectorCallActivity.kt @@ -251,19 +251,17 @@ class VectorCallActivity : } private fun startMicrophoneService() { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) - == PackageManager.PERMISSION_GRANTED) { - // Only start the service if the app is in the foreground - if (isAppInForeground()) { - Timber.tag(loggerTag.value).v("Starting microphone foreground service") - val intent = Intent(this, MicrophoneAccessService::class.java) - ContextCompat.startForegroundService(this, intent) - } else { - Timber.tag(loggerTag.value).v("App is not in foreground; cannot start microphone service") - } - } else { - Timber.tag(loggerTag.value).v("Microphone permission not granted; cannot start service") + val isConnected = withState(callViewModel) { + val callState = it.callState.invoke() + callState is CallState.Connected } + if (!isAppInForeground()) return + if (!isConnected) return + if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_DENIED) return + + Timber.tag(loggerTag.value).d("Starting microphone foreground service") + val intent = Intent(this, MicrophoneAccessService::class.java) + ContextCompat.startForegroundService(this, intent) } private fun isAppInForeground(): Boolean { @@ -292,6 +290,7 @@ class VectorCallActivity : turnScreenOffAndKeyguardOn() removeOnPictureInPictureModeChangedListener(pictureInPictureModeChangedInfoConsumer) screenCaptureServiceConnection.unbind() + stopMicrophoneService() super.onDestroy() } diff --git a/vector/src/withvoip/java/im/vector/app/features/call/VectorCallActivity.kt b/vector/src/withvoip/java/im/vector/app/features/call/VectorCallActivity.kt index a688c6caab..7919320871 100644 --- a/vector/src/withvoip/java/im/vector/app/features/call/VectorCallActivity.kt +++ b/vector/src/withvoip/java/im/vector/app/features/call/VectorCallActivity.kt @@ -251,19 +251,17 @@ class VectorCallActivity : } private fun startMicrophoneService() { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) - == PackageManager.PERMISSION_GRANTED) { - // Only start the service if the app is in the foreground - if (isAppInForeground()) { - Timber.tag(loggerTag.value).v("Starting microphone foreground service") - val intent = Intent(this, MicrophoneAccessService::class.java) - ContextCompat.startForegroundService(this, intent) - } else { - Timber.tag(loggerTag.value).v("App is not in foreground; cannot start microphone service") - } - } else { - Timber.tag(loggerTag.value).v("Microphone permission not granted; cannot start service") + val isConnected = withState(callViewModel) { + val callState = it.callState.invoke() + callState is CallState.Connected } + if (!isAppInForeground()) return + if (!isConnected) return + if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_DENIED) return + + Timber.tag(loggerTag.value).d("Starting microphone foreground service") + val intent = Intent(this, MicrophoneAccessService::class.java) + ContextCompat.startForegroundService(this, intent) } private fun isAppInForeground(): Boolean { @@ -292,6 +290,7 @@ class VectorCallActivity : turnScreenOffAndKeyguardOn() removeOnPictureInPictureModeChangedListener(pictureInPictureModeChangedInfoConsumer) screenCaptureServiceConnection.unbind() + stopMicrophoneService() super.onDestroy() }