Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore android call service #1134

Merged
merged 2 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion vector/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

<!-- For CallAndroidService -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_PHONE_CALL" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />

<!-- For VectorSyncAndroidService -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
Expand All @@ -58,6 +57,9 @@
<!-- Jitsi SDK is now API23+ -->
<uses-sdk tools:overrideLibrary="com.swmansion.gesturehandler,org.jitsi.meet.sdk,com.oney.WebRTCModule,com.learnium.RNDeviceInfo,com.reactnativecommunity.asyncstorage,com.ocetnik.timer,com.calendarevents,com.reactnativecommunity.netinfo,com.kevinresol.react_native_default_preference,com.rnimmersive,com.corbt.keepawake,com.BV.LinearGradient,com.horcrux.svg,com.oblador.performance,com.reactnativecommunity.slider,com.brentvatne.react,com.reactnativecommunity.clipboard,com.swmansion.gesturehandler.react,org.linusu,org.reactnative.maskedview,com.reactnativepagerview,com.swmansion.reanimated,com.th3rdwave.safeareacontext,com.swmansion.rnscreens,org.devio.rn.splashscreen,com.reactnativecommunity.webview,org.wonday.orientation" />

<!-- For MicrophoneAccessService -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />

<!-- Tchap: Jitsi libs adds CALENDAR permissions, but we can remove them safely
according to https://github.com/jitsi/jitsi-meet/issues/4068#issuecomment-480482481 -->
<uses-permission android:name="android.permission.READ_CALENDAR" tools:node="remove" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,11 @@ class CallAndroidService : VectorAndroidService() {
title = callInformation.opponentMatrixItem?.getBestName() ?: callInformation.opponentUserId,
fromBg = fromBg
)
// TCHAP fix crash when a call incoming on Androd 14 and higher
notificationManager.notify(callId.hashCode(), notification)
if (knownCalls.isEmpty()) {
startForegroundCompat(callId.hashCode(), notification)
} else {
notificationManager.notify(callId.hashCode(), notification)
}
knownCalls[callId] = callInformation
}

Expand All @@ -200,8 +203,7 @@ class CallAndroidService : VectorAndroidService() {
}
val notification = notificationUtils.buildCallEndedNotification(false)
val notificationId = callId.hashCode()
// TCHAP fix crash when a call incoming on Androd 14 and higher
notificationManager.notify(notificationId, notification)
startForegroundCompat(notificationId, notification)
if (knownCalls.isEmpty()) {
Timber.tag(loggerTag.value).v("No more call, stop the service")
stopForegroundCompat()
Expand Down Expand Up @@ -262,8 +264,11 @@ class CallAndroidService : VectorAndroidService() {
call = call,
title = callInformation.opponentMatrixItem?.getBestName() ?: callInformation.opponentUserId
)
// TCHAP fix crash when a call incoming on Androd 14 and higher
startForegroundCompat(callId.hashCode(), notification)
if (knownCalls.isEmpty()) {
startForegroundCompat(callId.hashCode(), notification)
} else {
notificationManager.notify(callId.hashCode(), notification)
}
knownCalls[callId] = callInformation
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -292,6 +290,7 @@ class VectorCallActivity :
turnScreenOffAndKeyguardOn()
removeOnPictureInPictureModeChangedListener(pictureInPictureModeChangedInfoConsumer)
screenCaptureServiceConnection.unbind()
stopMicrophoneService()
super.onDestroy()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -292,6 +290,7 @@ class VectorCallActivity :
turnScreenOffAndKeyguardOn()
removeOnPictureInPictureModeChangedListener(pictureInPictureModeChangedInfoConsumer)
screenCaptureServiceConnection.unbind()
stopMicrophoneService()
super.onDestroy()
}

Expand Down
Loading