Skip to content

Commit

Permalink
fix(calling): microphone restricted when the app goes into background…
Browse files Browse the repository at this point in the history
… on Android 14 (WPB-6307) (#2782)

Co-authored-by: Oussama Hassine <[email protected]>
  • Loading branch information
AndroidBob and ohassine authored Mar 12, 2024
1 parent 79c1384 commit eba05a8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

Expand Down Expand Up @@ -320,8 +321,7 @@
<service
android:name=".services.OngoingCallService"
android:exported="false"
android:foregroundServiceType="phoneCall" />

android:foregroundServiceType="phoneCall|microphone" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.wire.android.notification

import android.os.Build
import androidx.annotation.VisibleForTesting
import com.wire.android.R
import com.wire.android.appLogger
Expand Down Expand Up @@ -399,7 +400,7 @@ class WireNotificationManager @Inject constructor(
private suspend fun observeOngoingCalls(currentScreenState: StateFlow<CurrentScreen>) {
currentScreenState
.flatMapLatest { currentScreen ->
if (currentScreen !is CurrentScreen.InBackground) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE && currentScreen !is CurrentScreen.InBackground) {
flowOf(null)
} else {
coreLogic.getGlobalScope().session.currentSessionFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.app.Notification
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo
import android.os.IBinder
import com.wire.android.appLogger
import com.wire.android.di.KaliumCoreLogic
Expand All @@ -47,6 +48,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import java.util.concurrent.atomic.AtomicReference
import javax.inject.Inject
import androidx.core.app.ServiceCompat

@AndroidEntryPoint
class OngoingCallService : Service() {
Expand Down Expand Up @@ -131,17 +133,38 @@ class OngoingCallService : Service() {
scope.cancel()
}

private fun generateForegroundNotification(callName: String, conversationId: String, userId: UserId) {
private fun generateForegroundNotification(
callName: String,
conversationId: String,
userId: UserId
) {
appLogger.i("$TAG: generating foregroundNotification...")
val notification: Notification = callNotificationManager.builder.getOngoingCallNotification(callName, conversationId, userId)
startForeground(CALL_ONGOING_NOTIFICATION_ID, notification)
val notification: Notification = callNotificationManager.builder.getOngoingCallNotification(
callName,
conversationId,
userId
)
ServiceCompat.startForeground(
this,
CALL_ONGOING_NOTIFICATION_ID,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL or ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
)

appLogger.i("$TAG: started foreground with proper notification")
}

private fun generatePlaceholderForegroundNotification() {
appLogger.i("$TAG: generating foregroundNotification placeholder...")
val notification: Notification = callNotificationManager.builder.getOngoingCallPlaceholderNotification()
startForeground(CALL_ONGOING_NOTIFICATION_ID, notification)
val notification: Notification =
callNotificationManager.builder.getOngoingCallPlaceholderNotification()
ServiceCompat.startForeground(
this,
CALL_ONGOING_NOTIFICATION_ID,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL or ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
)

appLogger.i("$TAG: started foreground with placeholder notification")
}

Expand Down

0 comments on commit eba05a8

Please sign in to comment.