diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f0347aae669..3e74e1c19d7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -109,13 +109,13 @@ android:theme="@style/AppTheme" /> + android:name=".ui.WireActivity" + android:exported="true" + android:hardwareAccelerated="true" + android:launchMode="singleTask" + android:screenOrientation="portrait" + android:theme="@style/AppTheme.SplashScreen" + android:windowSoftInputMode="adjustResize|stateHidden"> @@ -149,12 +149,12 @@ android:scheme="wire" /> + android:host="conversation" + android:scheme="wire" /> + android:host="user" + android:scheme="wire" /> diff --git a/app/src/main/kotlin/com/wire/android/notification/CallNotificationManager.kt b/app/src/main/kotlin/com/wire/android/notification/CallNotificationManager.kt index 91fffbaa932..0b34dfa403a 100644 --- a/app/src/main/kotlin/com/wire/android/notification/CallNotificationManager.kt +++ b/app/src/main/kotlin/com/wire/android/notification/CallNotificationManager.kt @@ -27,6 +27,7 @@ import com.wire.android.R import com.wire.android.appLogger import com.wire.android.util.dispatchers.DispatcherProvider import com.wire.kalium.logic.data.call.Call +import com.wire.kalium.logic.data.call.CallStatus import com.wire.kalium.logic.data.conversation.Conversation import com.wire.kalium.logic.data.id.ConversationId import com.wire.kalium.logic.data.id.QualifiedID @@ -62,7 +63,6 @@ class CallNotificationManager @Inject constructor( private val notificationManager = NotificationManagerCompat.from(context) private val scope = CoroutineScope(SupervisorJob() + dispatcherProvider.default()) private val incomingCallsForUsers = MutableStateFlow>(mapOf()) - private val outgoingCallForUsers = MutableStateFlow>(mapOf()) private val reloadCallNotification = MutableSharedFlow() init { @@ -81,25 +81,6 @@ class CallNotificationManager @Inject constructor( } } } - scope.launch { - outgoingCallForUsers - .map { it.entries.firstOrNull()?.toCallNotificationData() } - .distinctUntilChanged() - .reloadIfNeeded() - .collectLatest { outgoingCallData -> - if (outgoingCallData == null) { - hideOutgoingCallNotification() - } else { - appLogger.i("$TAG: showing outgoing call") - showOutgoingCallNotification( - outgoingCallData.copy( - conversationName = outgoingCallData.conversationName - ?: context.getString(R.string.username_unavailable_label) - ) - ) - } - } - } } fun reloadIfNeeded(data: CallNotificationData): Flow = reloadCallNotification @@ -126,14 +107,6 @@ class CallNotificationManager @Inject constructor( } } - fun handleOutgoingCallNotifications(calls: List, userId: UserId) { - if (calls.isEmpty()) { - outgoingCallForUsers.update { it.filter { it.key != userId } } - } else { - outgoingCallForUsers.update { it.filter { it.key != userId } + (userId to calls.first()) } - } - } - fun hideAllNotifications() { hideIncomingCallNotification() } @@ -149,11 +122,6 @@ class CallNotificationManager @Inject constructor( notificationManager.cancel(NotificationIds.CALL_INCOMING_NOTIFICATION_ID.ordinal) } - private fun hideOutgoingCallNotification() { - appLogger.i("$TAG: hiding outgoing call") - notificationManager.cancel(NotificationIds.CALL_OUTGOING_NOTIFICATION_ID.ordinal) - } - @SuppressLint("MissingPermission") @VisibleForTesting internal fun showIncomingCallNotification(data: CallNotificationData) { @@ -165,17 +133,6 @@ class CallNotificationManager @Inject constructor( ) } - @SuppressLint("MissingPermission") - @VisibleForTesting - internal fun showOutgoingCallNotification(data: CallNotificationData) { - appLogger.i("$TAG: showing outgoing call notification for user ${data.userId.toLogString()}") - val notification = builder.getOutgoingCallNotification(data) - notificationManager.notify( - NotificationIds.CALL_OUTGOING_NOTIFICATION_ID.ordinal, - notification - ) - } - // Notifications companion object { @@ -199,7 +156,7 @@ class CallNotificationBuilder @Inject constructor( fun getOutgoingCallNotification(data: CallNotificationData): Notification { val userIdString = data.userId.toString() val conversationIdString = data.conversationId.toString() - val channelId = NotificationConstants.getIncomingChannelId(data.userId) + val channelId = NotificationConstants.getOutgoingChannelId(data.userId) return NotificationCompat.Builder(context, channelId) .setPriority(NotificationCompat.PRIORITY_DEFAULT) @@ -263,6 +220,7 @@ class CallNotificationBuilder @Inject constructor( .setSmallIcon(R.drawable.notification_icon_small) .setAutoCancel(true) .setOngoing(true) + .setUsesChronometer(true) .addAction(getHangUpCallAction(context, conversationIdString, userIdString)) .addAction(getOpenOngoingCallAction(context, conversationIdString)) .setFullScreenIntent(openOngoingCallPendingIntent(context, conversationIdString), true) @@ -272,15 +230,15 @@ class CallNotificationBuilder @Inject constructor( } /** - * @return placeholder Notification for OngoingCall, that can be shown immediately after starting the Service + * @return placeholder Notification for CallService, that can be shown immediately after starting the Service * (e.g. in [android.app.Service.onCreate]). It has no any [NotificationCompat.Action], on click - just opens the app. * This notification should be replace by the user-specific notification (with corresponding [NotificationCompat.Action], * [android.content.Intent] and title) once it's possible (e.g. in [android.app.Service.onStartCommand]) */ - fun getOngoingCallPlaceholderNotification(): Notification { + fun getCallServicePlaceholderNotification(): Notification { val channelId = NotificationConstants.ONGOING_CALL_CHANNEL_ID return NotificationCompat.Builder(context, channelId) - .setContentText(context.getString(R.string.notification_ongoing_call_content)) + .setContentText(context.getString(R.string.notification_outgoing_call_tap_to_return)) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setCategory(NotificationCompat.CATEGORY_CALL) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) @@ -326,6 +284,7 @@ data class CallNotificationData( val conversationType: Conversation.Type, val callerName: String?, val callerTeamName: String?, + val callStatus: CallStatus ) { constructor(userId: UserId, call: Call) : this( userId, @@ -334,6 +293,7 @@ data class CallNotificationData( call.conversationType, call.callerName, call.callerTeamName, + call.status ) } diff --git a/app/src/main/kotlin/com/wire/android/notification/NotificationConstants.kt b/app/src/main/kotlin/com/wire/android/notification/NotificationConstants.kt index c82d375e185..186cc6dbf92 100644 --- a/app/src/main/kotlin/com/wire/android/notification/NotificationConstants.kt +++ b/app/src/main/kotlin/com/wire/android/notification/NotificationConstants.kt @@ -73,8 +73,7 @@ object NotificationConstants { // Notification IDs (has to be unique!) enum class NotificationIds { CALL_INCOMING_NOTIFICATION_ID, - CALL_OUTGOING_NOTIFICATION_ID, - CALL_ONGOING_NOTIFICATION_ID, + CALL_OUTGOING_ONGOING_NOTIFICATION_ID, PERSISTENT_NOTIFICATION_ID, MESSAGE_SYNC_NOTIFICATION_ID, MIGRATION_NOTIFICATION_ID, diff --git a/app/src/main/kotlin/com/wire/android/notification/WireNotificationManager.kt b/app/src/main/kotlin/com/wire/android/notification/WireNotificationManager.kt index 9a0e23d37a4..a2361e0e7ae 100644 --- a/app/src/main/kotlin/com/wire/android/notification/WireNotificationManager.kt +++ b/app/src/main/kotlin/com/wire/android/notification/WireNotificationManager.kt @@ -49,6 +49,7 @@ import kotlinx.coroutines.cancel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.cancellable +import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf @@ -162,7 +163,10 @@ class WireNotificationManager @Inject constructor( val observeCallsJob = observeCallNotificationsOnceJob(userId) appLogger.d("$TAG start syncing") - connectionPolicyManager.handleConnectionOnPushNotification(userId, STAY_ALIVE_TIME_ON_PUSH_MS) + connectionPolicyManager.handleConnectionOnPushNotification( + userId, + STAY_ALIVE_TIME_ON_PUSH_MS + ) observeMessagesJob?.cancel("$TAG checked the notifications once, canceling observing.") observeCallsJob?.cancel("$TAG checked the calls once, canceling observing.") @@ -179,7 +183,12 @@ class WireNotificationManager @Inject constructor( appLogger.d("$TAG checking the notifications once, but notifications are already observed, no need to start a new job") null } else { - scope.launch { observeMessageNotifications(userId, MutableStateFlow(CurrentScreen.InBackground)) } + scope.launch { + observeMessageNotifications( + userId, + MutableStateFlow(CurrentScreen.InBackground) + ) + } } } @@ -241,7 +250,7 @@ class WireNotificationManager @Inject constructor( appLogger.i("$TAG no Users -> hide all the notifications") messagesNotificationManager.hideAllNotifications() callNotificationManager.hideAllNotifications() - servicesManager.stopOngoingCallService() + servicesManager.stopCallService() return } @@ -256,9 +265,6 @@ class WireNotificationManager @Inject constructor( incomingCallsJob = scope.launch(dispatcherProvider.default()) { observeIncomingCalls(userId) }, - outgoingCallJob = scope.launch(dispatcherProvider.default()) { - observeOutgoingCalls(userId) - }, messagesJob = scope.launch(dispatcherProvider.default()) { observeMessageNotifications(userId, currentScreenState) }, @@ -266,12 +272,12 @@ class WireNotificationManager @Inject constructor( observingJobs.userJobs[userId] = jobs } - // start observing ongoing calls for all users, but only if not yet started - if (observingJobs.ongoingCallJob.get().let { it == null || !it.isActive }) { + // start observing outgoing and ongoing calls for all users, but only if not yet started + if (observingJobs.outgoingOngoingCallJob.get().let { it == null || !it.isActive }) { val job = scope.launch(dispatcherProvider.default()) { - observeOngoingCalls() + observeOutgoingOngoingCalls() } - observingJobs.ongoingCallJob.set(job) + observingJobs.outgoingOngoingCallJob.set(job) } } @@ -305,8 +311,16 @@ class WireNotificationManager @Inject constructor( currentScreenState .collect { screens -> when (screens) { - is CurrentScreen.Conversation -> messagesNotificationManager.hideNotification(screens.id, userId) - is CurrentScreen.OtherUserProfile -> messagesNotificationManager.hideNotification(screens.id, userId) + is CurrentScreen.Conversation -> messagesNotificationManager.hideNotification( + screens.id, + userId + ) + + is CurrentScreen.OtherUserProfile -> messagesNotificationManager.hideNotification( + screens.id, + userId + ) + else -> {} } } @@ -338,15 +352,6 @@ class WireNotificationManager @Inject constructor( } } - private suspend fun observeOutgoingCalls( - userId: UserId - ) { - appLogger.d("$TAG observing outgoing calls") - coreLogic.getSessionScope(userId).calls.observeOutgoingCall().collect { - callNotificationManager.handleOutgoingCallNotifications(it, userId) - } - } - /** * Infinitely listen for the new Message notifications and show it. * Can be used for listening for the Notifications when the app is running. @@ -394,7 +399,11 @@ class WireNotificationManager @Inject constructor( if (isBlockedByE2EIRequiredState.value) { appLogger.d("$TAG notifications were skipped as E2EI is required") } else { - messagesNotificationManager.handleNotification(newNotifications, userId, selfUserNameState.value) + messagesNotificationManager.handleNotification( + newNotifications, + userId, + selfUserNameState.value + ) } markMessagesAsNotified(userId) markConnectionAsNotified(userId) @@ -402,26 +411,39 @@ class WireNotificationManager @Inject constructor( } /** - * Infinitely listen for the established calls of a current user and run OngoingCall foreground Service + * Infinitely listen for outgoing and established calls of a current user and run the call on foreground Service * to show corresponding notification and do not lose a call. */ - private suspend fun observeOngoingCalls() { + private suspend fun observeOutgoingOngoingCalls() { coreLogic.getGlobalScope().session.currentSessionFlow() .flatMapLatest { if (it is CurrentSessionResult.Success && it.accountInfo.isValid()) { - coreLogic.getSessionScope(it.accountInfo.userId).calls.establishedCall() - .map { it.isNotEmpty() } + combine( + coreLogic.getSessionScope(it.accountInfo.userId).calls.establishedCall(), + coreLogic.getSessionScope(it.accountInfo.userId).calls.observeOutgoingCall() + ) { establishedCalls, outgoingCalls -> + if (establishedCalls.isNotEmpty()) { + return@combine true + } + if (outgoingCalls.isNotEmpty()) { + return@combine true + } + return@combine false + } } else { flowOf(false) } } .distinctUntilChanged() .onCompletion { - servicesManager.stopOngoingCallService() + servicesManager.stopCallService() } - .collect { isOngoingCall -> - if (isOngoingCall) servicesManager.startOngoingCallService() - else servicesManager.stopOngoingCallService() + .collect { isOnCall -> + if (isOnCall) { + servicesManager.startCallService() + } else { + servicesManager.stopCallService() + } } } @@ -437,7 +459,10 @@ class WireNotificationManager @Inject constructor( newNotifications } - private suspend fun markMessagesAsNotified(userId: QualifiedID, conversationId: ConversationId? = null) { + private suspend fun markMessagesAsNotified( + userId: QualifiedID, + conversationId: ConversationId? = null + ) { val markNotified = conversationId?.let { MarkMessagesAsNotifiedUseCase.UpdateTarget.SingleConversation(conversationId) } ?: MarkMessagesAsNotifiedUseCase.UpdateTarget.AllConversations @@ -446,7 +471,10 @@ class WireNotificationManager @Inject constructor( .markMessagesAsNotified(markNotified) } - private suspend fun markConnectionAsNotified(userId: QualifiedID?, connectionRequestUserId: QualifiedID? = null) { + private suspend fun markConnectionAsNotified( + userId: QualifiedID?, + connectionRequestUserId: QualifiedID? = null + ) { appLogger.d("$TAG markConnectionAsNotified") userId?.let { coreLogic.getSessionScope(it) @@ -483,22 +511,20 @@ class WireNotificationManager @Inject constructor( private data class UserObservingJobs( val currentScreenJob: Job, val incomingCallsJob: Job, - val outgoingCallJob: Job, val messagesJob: Job, ) { fun cancelAll() { currentScreenJob.cancel() incomingCallsJob.cancel() - outgoingCallJob.cancel() messagesJob.cancel() } fun isAllActive(): Boolean = - currentScreenJob.isActive && incomingCallsJob.isActive && messagesJob.isActive && outgoingCallJob.isActive + currentScreenJob.isActive && incomingCallsJob.isActive && messagesJob.isActive } private data class ObservingJobs( - val ongoingCallJob: AtomicReference = AtomicReference(), + val outgoingOngoingCallJob: AtomicReference = AtomicReference(), val userJobs: ConcurrentHashMap = ConcurrentHashMap() ) diff --git a/app/src/main/kotlin/com/wire/android/services/OngoingCallService.kt b/app/src/main/kotlin/com/wire/android/services/CallService.kt similarity index 78% rename from app/src/main/kotlin/com/wire/android/services/OngoingCallService.kt rename to app/src/main/kotlin/com/wire/android/services/CallService.kt index 460a1dee6c8..5acf885cd6f 100644 --- a/app/src/main/kotlin/com/wire/android/services/OngoingCallService.kt +++ b/app/src/main/kotlin/com/wire/android/services/CallService.kt @@ -33,6 +33,7 @@ import com.wire.android.notification.CallNotificationManager import com.wire.android.notification.NotificationIds import com.wire.android.util.dispatchers.DispatcherProvider import com.wire.kalium.logic.CoreLogic +import com.wire.kalium.logic.data.call.CallStatus import com.wire.kalium.logic.data.id.QualifiedIdMapper import com.wire.kalium.logic.feature.session.CurrentSessionResult import com.wire.kalium.logic.functional.Either @@ -43,16 +44,19 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf -import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import java.util.concurrent.atomic.AtomicReference import javax.inject.Inject +/** + * Service that will be started when we have an outgoing/established call. + */ @AndroidEntryPoint -class OngoingCallService : Service() { +class CallService : Service() { @Inject @KaliumCoreLogic @@ -76,7 +80,6 @@ class OngoingCallService : Service() { override fun onCreate() { serviceState.set(ServiceState.STARTED) super.onCreate() - generatePlaceholderForegroundNotification() } override fun onBind(intent: Intent?): IBinder? { @@ -97,18 +100,27 @@ class OngoingCallService : Service() { .flatMapLatest { if (it is CurrentSessionResult.Success && it.accountInfo.isValid()) { val userId = it.accountInfo.userId - coreLogic.getSessionScope(userId).calls.establishedCall().map { - it.firstOrNull()?.let { call -> - Either.Right(CallNotificationData(userId = userId, call = call)) - } ?: Either.Left("no ongoing calls") + val outgoingCallsFlow = + coreLogic.getSessionScope(userId).calls.observeOutgoingCall() + val establishedCallsFlow = + coreLogic.getSessionScope(userId).calls.establishedCall() + + combine( + outgoingCallsFlow, + establishedCallsFlow + ) { outgoingCalls, establishedCalls -> + val calls = outgoingCalls + establishedCalls + calls.firstOrNull()?.let { call -> + Either.Right(CallNotificationData(userId, call)) + } ?: Either.Left("no calls") } } else { flowOf(Either.Left("no valid current session")) } } .distinctUntilChanged() - .flatMapRight { ongoingCallData -> - callNotificationManager.reloadIfNeeded(ongoingCallData) + .flatMapRight { callData -> + callNotificationManager.reloadIfNeeded(callData) } .collectLatest { it.fold( @@ -135,10 +147,14 @@ class OngoingCallService : Service() { private fun generateForegroundNotification(data: CallNotificationData) { appLogger.i("$TAG: generating foregroundNotification...") - val notification: Notification = callNotificationManager.builder.getOngoingCallNotification(data) + val notification = if (data.callStatus == CallStatus.STARTED) { + callNotificationManager.builder.getOutgoingCallNotification(data) + } else { + callNotificationManager.builder.getOngoingCallNotification(data) + } ServiceCompat.startForeground( this, - NotificationIds.CALL_ONGOING_NOTIFICATION_ID.ordinal, + NotificationIds.CALL_OUTGOING_ONGOING_NOTIFICATION_ID.ordinal, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL or ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE ) @@ -149,10 +165,10 @@ class OngoingCallService : Service() { private fun generatePlaceholderForegroundNotification() { appLogger.i("$TAG: generating foregroundNotification placeholder...") val notification: Notification = - callNotificationManager.builder.getOngoingCallPlaceholderNotification() + callNotificationManager.builder.getCallServicePlaceholderNotification() ServiceCompat.startForeground( this, - NotificationIds.CALL_ONGOING_NOTIFICATION_ID.ordinal, + NotificationIds.CALL_OUTGOING_ONGOING_NOTIFICATION_ID.ordinal, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL or ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE ) @@ -161,13 +177,13 @@ class OngoingCallService : Service() { } companion object { - private const val TAG = "OngoingCallService" + private const val TAG = "CallService" private const val EXTRA_STOP_SERVICE = "stop_service" - fun newIntent(context: Context): Intent = Intent(context, OngoingCallService::class.java) + fun newIntent(context: Context): Intent = Intent(context, CallService::class.java) fun newIntentToStop(context: Context): Intent = - Intent(context, OngoingCallService::class.java).apply { + Intent(context, CallService::class.java).apply { putExtra(EXTRA_STOP_SERVICE, true) } diff --git a/app/src/main/kotlin/com/wire/android/services/ServicesManager.kt b/app/src/main/kotlin/com/wire/android/services/ServicesManager.kt index d410ebcd924..595b767ab5d 100644 --- a/app/src/main/kotlin/com/wire/android/services/ServicesManager.kt +++ b/app/src/main/kotlin/com/wire/android/services/ServicesManager.kt @@ -47,57 +47,56 @@ class ServicesManager @Inject constructor( dispatcherProvider: DispatcherProvider, ) { private val scope = CoroutineScope(SupervisorJob() + dispatcherProvider.default()) - private val ongoingCallServiceEvents = MutableStateFlow(false) + private val callServiceEvents = MutableStateFlow(false) init { scope.launch { - ongoingCallServiceEvents + callServiceEvents .debounce { if (!it) 0L else DEBOUNCE_TIME } // debounce to avoid starting and stopping service too fast .distinctUntilChanged() .collectLatest { shouldBeStarted -> if (!shouldBeStarted) { - appLogger.i("ServicesManager: stopping OngoingCallService because there are no ongoing calls") - when (OngoingCallService.serviceState.get()) { - OngoingCallService.ServiceState.STARTED -> { - // Instead of simply calling stopService(OngoingCallService::class), which can end up with a crash if it + appLogger.i("ServicesManager: stopping CallService because there are no calls") + when (CallService.serviceState.get()) { + CallService.ServiceState.STARTED -> { + // Instead of simply calling stopService(CallService::class), which can end up with a crash if it // happens before the service calls startForeground, we call the startService command with an empty data // or some specific argument that tells the service that it should stop itself right after startForeground. // This way, when this service is killed and recreated by the system, it will stop itself right after // recreating so it won't cause any problems. - startService(OngoingCallService.newIntentToStop(context)) - appLogger.i("ServicesManager: OngoingCallService stopped by passing stop argument") + startService(CallService.newIntentToStop(context)) + appLogger.i("ServicesManager: CallService stopped by passing stop argument") } - OngoingCallService.ServiceState.FOREGROUND -> { + CallService.ServiceState.FOREGROUND -> { // we can just stop the service, because it's already in foreground - context.stopService(OngoingCallService.newIntent(context)) - appLogger.i("ServicesManager: OngoingCallService stopped by calling stopService") + context.stopService(CallService.newIntent(context)) + appLogger.i("ServicesManager: CallService stopped by calling stopService") } else -> { - appLogger.i("ServicesManager: OngoingCallService not running, nothing to stop") + appLogger.i("ServicesManager: CallService not running, nothing to stop") } } } else { - appLogger.i("ServicesManager: starting OngoingCallService") - startService(OngoingCallService.newIntent(context)) + appLogger.i("ServicesManager: starting CallService") + startService(CallService.newIntent(context)) } } } } - // Ongoing call - fun startOngoingCallService() { - appLogger.i("ServicesManager: start OngoingCallService event") + fun startCallService() { + appLogger.i("ServicesManager: start CallService event") scope.launch { - ongoingCallServiceEvents.emit(true) + callServiceEvents.emit(true) } } - fun stopOngoingCallService() { - appLogger.i("ServicesManager: stop OngoingCallService event") + fun stopCallService() { + appLogger.i("ServicesManager: stop CallService event") scope.launch { - ongoingCallServiceEvents.emit(false) + callServiceEvents.emit(false) } } diff --git a/app/src/test/kotlin/com/wire/android/notification/CallNotificationManagerTest.kt b/app/src/test/kotlin/com/wire/android/notification/CallNotificationManagerTest.kt index a21a1dbafdc..ca449cd21e1 100644 --- a/app/src/test/kotlin/com/wire/android/notification/CallNotificationManagerTest.kt +++ b/app/src/test/kotlin/com/wire/android/notification/CallNotificationManagerTest.kt @@ -63,23 +63,6 @@ class CallNotificationManagerTest { } } - @Test - fun `given no outgoing calls, when handling notifications, then hide outgoing call notification`() = - runTest(dispatcherProvider.main()) { - // given - val (arrangement, callNotificationManager) = Arrangement() - .arrange() - callNotificationManager.handleOutgoingCallNotifications(listOf(), TEST_USER_ID1) - advanceUntilIdle() - // then - verify(exactly = 0) { - arrangement.notificationManager.notify(NotificationIds.CALL_OUTGOING_NOTIFICATION_ID.ordinal, any()) - } - verify(exactly = 1) { - arrangement.notificationManager.cancel(NotificationIds.CALL_OUTGOING_NOTIFICATION_ID.ordinal) - } - } - @Test fun `given an incoming call for one user, then show notification for that call`() = runTest(dispatcherProvider.main()) { @@ -97,27 +80,6 @@ class CallNotificationManagerTest { verify(exactly = 0) { arrangement.notificationManager.cancel(any()) } } - @Test - fun `given an outgoing call for one user, when handling notifications, then show notification for that call`() = - runTest(dispatcherProvider.main()) { - val notification = mockk() - val callNotificationData = provideCallNotificationData(TEST_USER_ID1, TEST_CALL1) - val (arrangement, callNotificationManager) = Arrangement() - .withOutgoingNotificationForUserAndCall(notification, callNotificationData) - .arrange() - - arrangement.clearRecordedCallsForNotificationManager() // clear first empty list recorded call - callNotificationManager.handleOutgoingCallNotifications(listOf(TEST_CALL1), TEST_USER_ID1) - advanceUntilIdle() - - verify(exactly = 1) { - arrangement.notificationManager.notify(NotificationIds.CALL_OUTGOING_NOTIFICATION_ID.ordinal, notification) - } - verify(exactly = 0) { - arrangement.notificationManager.cancel(NotificationIds.CALL_OUTGOING_NOTIFICATION_ID.ordinal) - } - } - @Test fun `given incoming calls for two users, then show notification for the first call`() = runTest(dispatcherProvider.main()) { @@ -301,6 +263,7 @@ class CallNotificationManagerTest { conversationType = call.conversationType, callerName = call.callerName, callerTeamName = call.callerTeamName, + callStatus = call.status ) } } diff --git a/app/src/test/kotlin/com/wire/android/notification/WireNotificationManagerTest.kt b/app/src/test/kotlin/com/wire/android/notification/WireNotificationManagerTest.kt index 366357fd63c..6fdcb2215d0 100644 --- a/app/src/test/kotlin/com/wire/android/notification/WireNotificationManagerTest.kt +++ b/app/src/test/kotlin/com/wire/android/notification/WireNotificationManagerTest.kt @@ -186,26 +186,6 @@ class WireNotificationManagerTest { } } - @Test - fun givenOutgoingCall_whenCurrentUserIsDifferentFromCallReceiver_thenCallNotificationIsShown() = - runTestWithCancellation(dispatcherProvider.main()) { - val user1 = provideUserId("user1") - val user2 = provideUserId("user2") - val outgoingCalls = listOf(provideCall().copy(status = CallStatus.STARTED)) - val (arrangement, manager) = Arrangement() - .withSpecificUserSession(userId = user1) - .withSpecificUserSession(userId = user2, outgoingCalls = outgoingCalls) - .withMessageNotifications(listOf()) - .withCurrentScreen(CurrentScreen.SomeOther) - .withCurrentUserSession(CurrentSessionResult.Success(provideAccountInfo(user1.value))) - .arrange() - - manager.observeNotificationsAndCallsWhileRunning(listOf(user1, user2), this) - runCurrent() - - verify(exactly = 1) { arrangement.callNotificationManager.handleOutgoingCallNotifications(outgoingCalls, user2) } - } - @Test fun givenSomeNotifications_whenAppIsInForegroundAndNoUserLoggedIn_thenMessageNotificationNotShowed() = runTestWithCancellation(dispatcherProvider.main()) { @@ -463,7 +443,7 @@ class WireNotificationManagerTest { } @Test - fun givenAppInBackground_withValidCurrentAccountAndOngoingCall_whenObserving_thenStartOngoingCallService() = + fun givenAppInBackground_withValidCurrentAccountAndOngoingCall_whenObserving_thenStartCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId = provideUserId() val call = provideCall().copy(status = CallStatus.ESTABLISHED) @@ -479,32 +459,53 @@ class WireNotificationManagerTest { manager.observeNotificationsAndCallsWhileRunning(listOf(userId), this) advanceUntilIdle() - verify(exactly = 1) { arrangement.servicesManager.startOngoingCallService() } - verify(exactly = 0) { arrangement.servicesManager.stopOngoingCallService() } + verify(exactly = 1) { arrangement.servicesManager.startCallService() } + verify(exactly = 0) { arrangement.servicesManager.stopCallService() } } @Test - fun givenAppInBackground_withValidCurrentAccountAndNoOngoingCall_whenObserving_thenStopOngoingCallService() = + fun givenAppInBackground_withValidCurrentAccountAndOutgoingCall_whenObserving_thenStartCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId = provideUserId() + val call = provideCall().copy(status = CallStatus.STARTED) val (arrangement, manager) = Arrangement() .withIncomingCalls(listOf()) - .withOutgoingCalls(listOf()) + .withOutgoingCalls(listOf(call)) .withMessageNotifications(listOf()) .withCurrentScreen(CurrentScreen.InBackground) .withEstablishedCall(listOf()) .withCurrentUserSession(CurrentSessionResult.Success(TEST_AUTH_TOKEN)) .arrange() + manager.observeNotificationsAndCallsWhileRunning(listOf(userId), this) + advanceUntilIdle() + + verify(exactly = 1) { arrangement.servicesManager.startCallService() } + verify(exactly = 0) { arrangement.servicesManager.stopCallService() } + } + + @Test + fun givenAppInBackground_withValidCurrentAccountAndNoOngoingOrOutgoingCall_whenObserving_thenStopCallService() = + runTestWithCancellation(dispatcherProvider.main()) { + val userId = provideUserId() + val (arrangement, manager) = Arrangement() + .withIncomingCalls(listOf()) + .withOutgoingCalls(listOf()) + .withEstablishedCall(listOf()) + .withMessageNotifications(listOf()) + .withCurrentScreen(CurrentScreen.InBackground) + .withCurrentUserSession(CurrentSessionResult.Success(TEST_AUTH_TOKEN)) + .arrange() + manager.observeNotificationsAndCallsWhileRunning(listOf(userId), this) runCurrent() - verify(exactly = 0) { arrangement.servicesManager.startOngoingCallService() } - verify(exactly = 1) { arrangement.servicesManager.stopOngoingCallService() } + verify(exactly = 0) { arrangement.servicesManager.startCallService() } + verify(exactly = 1) { arrangement.servicesManager.stopCallService() } } @Test - fun givenAppInBackground_withInvalidCurrentAccountAndOngoingCall_whenObserving_thenStopOngoingCallService() = + fun givenAppInBackground_withInvalidCurrentAccountAndOngoingCall_whenObserving_thenStopCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId = provideUserId() val call = provideCall().copy(status = CallStatus.ESTABLISHED) @@ -520,12 +521,33 @@ class WireNotificationManagerTest { manager.observeNotificationsAndCallsWhileRunning(listOf(userId), this) runCurrent() - verify(exactly = 0) { arrangement.servicesManager.startOngoingCallService() } - verify(exactly = 1) { arrangement.servicesManager.stopOngoingCallService() } + verify(exactly = 0) { arrangement.servicesManager.startCallService() } + verify(exactly = 1) { arrangement.servicesManager.stopCallService() } } @Test - fun givenAppInBackground_withInvalidCurrentAccountAndNoOngoingCall_whenObserving_thenStopOngoingCallService() = + fun givenAppInBackground_withInvalidCurrentAccountAndOutgoingCall_whenObserving_thenStopCallService() = + runTestWithCancellation(dispatcherProvider.main()) { + val userId = provideUserId() + val call = provideCall().copy(status = CallStatus.STARTED) + val (arrangement, manager) = Arrangement() + .withIncomingCalls(listOf()) + .withEstablishedCall(listOf()) + .withOutgoingCalls(listOf(call)) + .withMessageNotifications(listOf()) + .withCurrentScreen(CurrentScreen.InBackground) + .withCurrentUserSession(CurrentSessionResult.Success(provideInvalidAccountInfo(userId.value))) + .arrange() + + manager.observeNotificationsAndCallsWhileRunning(listOf(userId), this) + runCurrent() + + verify(exactly = 0) { arrangement.servicesManager.startCallService() } + verify(exactly = 1) { arrangement.servicesManager.stopCallService() } + } + + @Test + fun givenAppInBackground_withInvalidCurrentAccountAndNoOngoingCall_whenObserving_thenStopCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId = provideUserId() val (arrangement, manager) = Arrangement() @@ -540,12 +562,12 @@ class WireNotificationManagerTest { manager.observeNotificationsAndCallsWhileRunning(listOf(userId), this) runCurrent() - verify(exactly = 0) { arrangement.servicesManager.startOngoingCallService() } - verify(exactly = 1) { arrangement.servicesManager.stopOngoingCallService() } + verify(exactly = 0) { arrangement.servicesManager.startCallService() } + verify(exactly = 1) { arrangement.servicesManager.stopCallService() } } @Test - fun givenAppInBackground_withTwoValidAccountsAndOngoingCallForNotCurrentOne_whenObserving_thenStopOngoingCallService() = + fun givenAppInBackground_withTwoValidAccountsAndOngoingCallForNotCurrentOne_whenObserving_thenStopCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId1 = UserId("value1", "domain") val userId2 = UserId("value2", "domain") @@ -560,11 +582,11 @@ class WireNotificationManagerTest { manager.observeNotificationsAndCallsWhileRunning(listOf(userId1, userId2), this) advanceUntilIdle() - verify(exactly = 1) { arrangement.servicesManager.stopOngoingCallService() } + verify(exactly = 1) { arrangement.servicesManager.stopCallService() } } @Test - fun givenAppInBackground_withTwoValidAccountsAndOngoingCallForNotCurrentOne_whenCurrentAccountChanges_thenStartOngoingCallService() = + fun givenAppInBackground_withTwoValidAccountsAndOngoingCallForNotCurrentOne_whenCurrentAccountChanges_thenStartCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId1 = UserId("value1", "domain") val userId2 = UserId("value2", "domain") @@ -582,11 +604,11 @@ class WireNotificationManagerTest { arrangement.withCurrentUserSession(CurrentSessionResult.Success(provideAccountInfo(userId2.value))) advanceUntilIdle() - verify(exactly = 1) { arrangement.servicesManager.startOngoingCallService() } + verify(exactly = 1) { arrangement.servicesManager.startCallService() } } @Test - fun givenAppInBackground_withTwoValidAccountsAndOngoingCallForCurrentOne_whenCurrentAccountChanges_thenStopOngoingCallService() = + fun givenAppInBackground_withTwoValidAccountsAndOngoingCallForCurrentOne_whenCurrentAccountChanges_thenStopCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId1 = UserId("value1", "domain") val userId2 = UserId("value2", "domain") @@ -604,11 +626,11 @@ class WireNotificationManagerTest { arrangement.withCurrentUserSession(CurrentSessionResult.Success(provideAccountInfo(userId2.value))) advanceUntilIdle() - verify(exactly = 1) { arrangement.servicesManager.stopOngoingCallService() } + verify(exactly = 1) { arrangement.servicesManager.stopCallService() } } @Test - fun givenAppInBackground_withValidCurrentAccountAndOngoingCall_whenAccountBecomesInvalid_thenStopOngoingCallService() = + fun givenAppInBackground_withValidCurrentAccountAndOngoingCall_whenAccountBecomesInvalid_thenStopCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId = provideUserId() val call = provideCall().copy(status = CallStatus.ESTABLISHED) @@ -627,11 +649,11 @@ class WireNotificationManagerTest { arrangement.withCurrentUserSession(CurrentSessionResult.Success(provideInvalidAccountInfo(userId.value))) advanceUntilIdle() - verify(exactly = 1) { arrangement.servicesManager.stopOngoingCallService() } + verify(exactly = 1) { arrangement.servicesManager.stopCallService() } } @Test - fun givenAppInBackground_whenValidCurrentAccountAndOngoingCall_whenThisCallChangesSomeState_thenDoNotStartOngoingCallServiceAgain() = + fun givenAppInBackground_whenValidCurrentAccountAndOngoingCall_whenThisCallChangesSomeState_thenDoNotStartCallServiceAgain() = runTestWithCancellation(dispatcherProvider.main()) { val userId = provideUserId() val call = provideCall().copy(status = CallStatus.ESTABLISHED, isMuted = false) @@ -648,17 +670,17 @@ class WireNotificationManagerTest { manager.observeNotificationsAndCallsWhileRunning(listOf(userId), this) advanceUntilIdle() - verify(exactly = 1) { arrangement.servicesManager.startOngoingCallService() } + verify(exactly = 1) { arrangement.servicesManager.startCallService() } val updatedCall = call.copy(isMuted = true) callFlow.value = listOf(updatedCall) advanceUntilIdle() - verify(exactly = 1) { arrangement.servicesManager.startOngoingCallService() } // started only once + verify(exactly = 1) { arrangement.servicesManager.startCallService() } // started only once } @Test - fun givenAppInForeground_withValidCurrentAccountAndOngoingCall_whenObserving_thenStartOngoingCallService() = + fun givenAppInForeground_withValidCurrentAccountAndOngoingCall_whenObserving_thenStartCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId = provideUserId() val call = provideCall().copy(status = CallStatus.ESTABLISHED) @@ -674,12 +696,33 @@ class WireNotificationManagerTest { manager.observeNotificationsAndCallsWhileRunning(listOf(userId), this) runCurrent() - verify(exactly = 1) { arrangement.servicesManager.startOngoingCallService() } - verify(exactly = 0) { arrangement.servicesManager.stopOngoingCallService() } + verify(exactly = 1) { arrangement.servicesManager.startCallService() } + verify(exactly = 0) { arrangement.servicesManager.stopCallService() } + } + + @Test + fun givenAppInForeground_withValidCurrentAccountAndOutgoingCall_whenObserving_thenStartCallService() = + runTestWithCancellation(dispatcherProvider.main()) { + val userId = provideUserId() + val call = provideCall().copy(status = CallStatus.STARTED) + val (arrangement, manager) = Arrangement() + .withIncomingCalls(listOf()) + .withOutgoingCalls(listOf(call)) + .withMessageNotifications(listOf()) + .withCurrentScreen(CurrentScreen.Home) + .withEstablishedCall(listOf()) + .withCurrentUserSession(CurrentSessionResult.Success(provideAccountInfo(userId.value))) + .arrange() + + manager.observeNotificationsAndCallsWhileRunning(listOf(userId), this) + runCurrent() + + verify(exactly = 1) { arrangement.servicesManager.startCallService() } + verify(exactly = 0) { arrangement.servicesManager.stopCallService() } } @Test - fun givenAppInForeground_withValidCurrentAccountAndNoOngoingCall_whenObserving_thenStopOngoingCallService() = + fun givenAppInForeground_withValidCurrentAccountAndNoOngoingCall_whenObserving_thenStopCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId = provideUserId() val (arrangement, manager) = Arrangement() @@ -694,12 +737,12 @@ class WireNotificationManagerTest { manager.observeNotificationsAndCallsWhileRunning(listOf(userId), this) runCurrent() - verify(exactly = 0) { arrangement.servicesManager.startOngoingCallService() } - verify(exactly = 1) { arrangement.servicesManager.stopOngoingCallService() } + verify(exactly = 0) { arrangement.servicesManager.startCallService() } + verify(exactly = 1) { arrangement.servicesManager.stopCallService() } } @Test - fun givenAppInForeground_withInvalidCurrentAccountAndOngoingCall_whenObserving_thenStopOngoingCallService() = + fun givenAppInForeground_withInvalidCurrentAccountAndOngoingCall_whenObserving_thenStopCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId = provideUserId() val call = provideCall().copy(status = CallStatus.ESTABLISHED) @@ -715,12 +758,12 @@ class WireNotificationManagerTest { manager.observeNotificationsAndCallsWhileRunning(listOf(userId), this) runCurrent() - verify(exactly = 0) { arrangement.servicesManager.startOngoingCallService() } - verify(exactly = 1) { arrangement.servicesManager.stopOngoingCallService() } + verify(exactly = 0) { arrangement.servicesManager.startCallService() } + verify(exactly = 1) { arrangement.servicesManager.stopCallService() } } @Test - fun givenAppInForeground_withInvalidCurrentAccountAndNoOngoingCall_whenObserving_thenStopOngoingCallService() = + fun givenAppInForeground_withInvalidCurrentAccountAndNoOngoingCall_whenObserving_thenStopCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId = provideUserId() val (arrangement, manager) = Arrangement() @@ -735,12 +778,12 @@ class WireNotificationManagerTest { manager.observeNotificationsAndCallsWhileRunning(listOf(userId), this) runCurrent() - verify(exactly = 0) { arrangement.servicesManager.startOngoingCallService() } - verify(exactly = 1) { arrangement.servicesManager.stopOngoingCallService() } + verify(exactly = 0) { arrangement.servicesManager.startCallService() } + verify(exactly = 1) { arrangement.servicesManager.stopCallService() } } @Test - fun givenAppInForeground_withTwoValidAccountsAndOngoingCallForNotCurrentOne_whenObserving_thenStopOngoingCallService() = + fun givenAppInForeground_withTwoValidAccountsAndOngoingCallForNotCurrentOne_whenObserving_thenStopCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId1 = UserId("value1", "domain") val userId2 = UserId("value2", "domain") @@ -755,11 +798,11 @@ class WireNotificationManagerTest { manager.observeNotificationsAndCallsWhileRunning(listOf(userId1, userId2), this) advanceUntilIdle() - verify(exactly = 1) { arrangement.servicesManager.stopOngoingCallService() } + verify(exactly = 1) { arrangement.servicesManager.stopCallService() } } @Test - fun givenAppInForeground_withTwoValidAccountsAndOngoingCallForNotCurrentOne_whenCurrentAccountChanges_thenStartOngoingCallService() = + fun givenAppInForeground_withTwoValidAccountsAndOngoingCallForNotCurrentOne_whenCurrentAccountChanges_thenStartCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId1 = UserId("value1", "domain") val userId2 = UserId("value2", "domain") @@ -777,11 +820,11 @@ class WireNotificationManagerTest { arrangement.withCurrentUserSession(CurrentSessionResult.Success(provideAccountInfo(userId2.value))) advanceUntilIdle() - verify(exactly = 1) { arrangement.servicesManager.startOngoingCallService() } + verify(exactly = 1) { arrangement.servicesManager.startCallService() } } @Test - fun givenAppInForeground_withTwoValidAccountsAndOngoingCallForCurrentOne_whenCurrentAccountChanges_thenStopOngoingCallService() = + fun givenAppInForeground_withTwoValidAccountsAndOngoingCallForCurrentOne_whenCurrentAccountChanges_thenStopCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId1 = UserId("value1", "domain") val userId2 = UserId("value2", "domain") @@ -799,11 +842,11 @@ class WireNotificationManagerTest { arrangement.withCurrentUserSession(CurrentSessionResult.Success(provideAccountInfo(userId2.value))) advanceUntilIdle() - verify(exactly = 1) { arrangement.servicesManager.stopOngoingCallService() } + verify(exactly = 1) { arrangement.servicesManager.stopCallService() } } @Test - fun givenAppInForeground_withValidCurrentAccountAndOngoingCall_whenAccountBecomesInvalid_thenStopOngoingCallService() = + fun givenAppInForeground_withValidCurrentAccountAndOngoingCall_whenAccountBecomesInvalid_thenStopCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId = provideUserId() val call = provideCall().copy(status = CallStatus.ESTABLISHED) @@ -822,11 +865,11 @@ class WireNotificationManagerTest { arrangement.withCurrentUserSession(CurrentSessionResult.Success(provideInvalidAccountInfo(userId.value))) advanceUntilIdle() - verify(exactly = 1) { arrangement.servicesManager.stopOngoingCallService() } + verify(exactly = 1) { arrangement.servicesManager.stopCallService() } } @Test - fun givenAppInForeground_whenValidCurrentAccountAndOngoingCall_whenThisCallChangesSomeState_thenDoNotStartOngoingCallServiceAgain() = + fun givenAppInForeground_whenValidCurrentAccountAndOngoingCall_whenThisCallChangesSomeState_thenDoNotStartCallServiceAgain() = runTestWithCancellation(dispatcherProvider.main()) { val userId = provideUserId() val call = provideCall().copy(status = CallStatus.ESTABLISHED, isMuted = false) @@ -843,17 +886,17 @@ class WireNotificationManagerTest { manager.observeNotificationsAndCallsWhileRunning(listOf(userId), this) advanceUntilIdle() - verify(exactly = 1) { arrangement.servicesManager.startOngoingCallService() } + verify(exactly = 1) { arrangement.servicesManager.startCallService() } val updatedCall = call.copy(isMuted = true) callFlow.value = listOf(updatedCall) advanceUntilIdle() - verify(exactly = 1) { arrangement.servicesManager.startOngoingCallService() } // started only once + verify(exactly = 1) { arrangement.servicesManager.startCallService() } // started only once } @Test - fun givenAppInForegroundAndValidCurrentAccountAndOngoingCall_whenAppGoesIntoBackground_thenDoNotStartOngoingCallServiceAgain() = + fun givenAppInForegroundAndValidCurrentAccountAndOngoingCall_whenAppGoesIntoBackground_thenDoNotStartCallServiceAgain() = runTestWithCancellation(dispatcherProvider.main()) { val userId = provideUserId() val call = provideCall().copy(status = CallStatus.ESTABLISHED) @@ -870,16 +913,16 @@ class WireNotificationManagerTest { manager.observeNotificationsAndCallsWhileRunning(listOf(userId), this) advanceUntilIdle() - verify(exactly = 1) { arrangement.servicesManager.startOngoingCallService() } + verify(exactly = 1) { arrangement.servicesManager.startCallService() } currentScreenFlow.value = CurrentScreen.InBackground advanceUntilIdle() - verify(exactly = 1) { arrangement.servicesManager.startOngoingCallService() } // started only once + verify(exactly = 1) { arrangement.servicesManager.startCallService() } // started only once } @Test - fun givenAppInBackgroundAndValidCurrentAccountAndOngoingCall_whenAppGoesIntoForeground_thenDoNotStopOngoingCallService() = + fun givenAppInBackgroundAndValidCurrentAccountAndOngoingCall_whenAppGoesIntoForeground_thenDoNotStopCallService() = runTestWithCancellation(dispatcherProvider.main()) { val userId = provideUserId() val call = provideCall().copy(status = CallStatus.ESTABLISHED) @@ -899,7 +942,7 @@ class WireNotificationManagerTest { currentScreenFlow.value = CurrentScreen.Home advanceUntilIdle() - verify(exactly = 0) { arrangement.servicesManager.stopOngoingCallService() } + verify(exactly = 0) { arrangement.servicesManager.stopCallService() } } @Test @@ -1096,8 +1139,8 @@ class WireNotificationManagerTest { coEvery { globalKaliumScope.session.currentSessionFlow } returns currentSessionFlowUseCase coEvery { currentSessionFlowUseCase() } returns currentSessionChannel.consumeAsFlow() coEvery { getSelfUser.invoke() } returns flowOf(TestUser.SELF_USER) - every { servicesManager.startOngoingCallService() } returns Unit - every { servicesManager.stopOngoingCallService() } returns Unit + every { servicesManager.startCallService() } returns Unit + every { servicesManager.stopCallService() } returns Unit every { pingRinger.ping(any(), any()) } returns Unit coEvery { globalKaliumScope.doesValidSessionExist.invoke(any()) } returns DoesValidSessionExistResult.Success(true) } diff --git a/app/src/test/kotlin/com/wire/android/services/ServicesManagerTest.kt b/app/src/test/kotlin/com/wire/android/services/ServicesManagerTest.kt index 8e729d3700c..8f9d51ec833 100644 --- a/app/src/test/kotlin/com/wire/android/services/ServicesManagerTest.kt +++ b/app/src/test/kotlin/com/wire/android/services/ServicesManagerTest.kt @@ -43,12 +43,12 @@ class ServicesManagerTest { runTest(dispatcherProvider.main()) { // given val (arrangement, servicesManager) = Arrangement() - .withServiceState(OngoingCallService.ServiceState.FOREGROUND) + .withServiceState(CallService.ServiceState.FOREGROUND) .arrange() // when - servicesManager.startOngoingCallService() + servicesManager.startCallService() advanceTimeBy((ServicesManager.DEBOUNCE_TIME - 50).milliseconds) - servicesManager.stopOngoingCallService() + servicesManager.stopCallService() // then verify(exactly = 0) { arrangement.context.startService(arrangement.ongoingCallServiceIntent) } verify(exactly = 1) { arrangement.context.stopService(arrangement.ongoingCallServiceIntent) } @@ -59,13 +59,13 @@ class ServicesManagerTest { runTest(dispatcherProvider.main()) { // given val (arrangement, servicesManager) = Arrangement() - .withServiceState(OngoingCallService.ServiceState.FOREGROUND) + .withServiceState(CallService.ServiceState.FOREGROUND) .arrange() arrangement.clearRecordedCallsForContext() // clear calls recorded when initializing the state // when - servicesManager.startOngoingCallService() + servicesManager.startCallService() advanceTimeBy((ServicesManager.DEBOUNCE_TIME + 50).milliseconds) - servicesManager.stopOngoingCallService() + servicesManager.stopCallService() // then verify(exactly = 1) { arrangement.context.startService(arrangement.ongoingCallServiceIntent) } verify(exactly = 1) { arrangement.context.stopService(arrangement.ongoingCallServiceIntent) } @@ -76,13 +76,13 @@ class ServicesManagerTest { runTest(dispatcherProvider.main()) { // given val (arrangement, servicesManager) = Arrangement() - .withServiceState(OngoingCallService.ServiceState.FOREGROUND) + .withServiceState(CallService.ServiceState.FOREGROUND) .arrange() - servicesManager.startOngoingCallService() + servicesManager.startCallService() advanceUntilIdle() arrangement.clearRecordedCallsForContext() // clear calls recorded when initializing the state // when - servicesManager.stopOngoingCallService() + servicesManager.stopCallService() // then verify(exactly = 0) { arrangement.context.startService(arrangement.ongoingCallServiceIntentWithStopArgument) } verify(exactly = 1) { arrangement.context.stopService(arrangement.ongoingCallServiceIntent) } @@ -93,13 +93,13 @@ class ServicesManagerTest { runTest(dispatcherProvider.main()) { // given val (arrangement, servicesManager) = Arrangement() - .withServiceState(OngoingCallService.ServiceState.STARTED) + .withServiceState(CallService.ServiceState.STARTED) .arrange() - servicesManager.startOngoingCallService() + servicesManager.startCallService() advanceUntilIdle() arrangement.clearRecordedCallsForContext() // clear calls recorded when initializing the state // when - servicesManager.stopOngoingCallService() + servicesManager.stopCallService() // then verify(exactly = 1) { arrangement.context.startService(arrangement.ongoingCallServiceIntentWithStopArgument) } verify(exactly = 0) { arrangement.context.stopService(arrangement.ongoingCallServiceIntent) } @@ -110,13 +110,13 @@ class ServicesManagerTest { runTest(dispatcherProvider.main()) { // given val (arrangement, servicesManager) = Arrangement() - .withServiceState(OngoingCallService.ServiceState.NOT_STARTED) + .withServiceState(CallService.ServiceState.NOT_STARTED) .arrange() - servicesManager.startOngoingCallService() + servicesManager.startCallService() advanceUntilIdle() arrangement.clearRecordedCallsForContext() // clear calls recorded when initializing the state // when - servicesManager.startOngoingCallService() + servicesManager.startCallService() // then verify(exactly = 0) { arrangement.context.startService(arrangement.ongoingCallServiceIntentWithStopArgument) } verify(exactly = 0) { arrangement.context.stopService(arrangement.ongoingCallServiceIntent) } @@ -137,9 +137,9 @@ class ServicesManagerTest { init { MockKAnnotations.init(this, relaxUnitFun = true) - mockkObject(OngoingCallService.Companion) - every { OngoingCallService.Companion.newIntent(context) } returns ongoingCallServiceIntent - every { OngoingCallService.Companion.newIntentToStop(context) } returns ongoingCallServiceIntentWithStopArgument + mockkObject(CallService.Companion) + every { CallService.Companion.newIntent(context) } returns ongoingCallServiceIntent + every { CallService.Companion.newIntentToStop(context) } returns ongoingCallServiceIntentWithStopArgument } fun clearRecordedCallsForContext() { @@ -153,9 +153,9 @@ class ServicesManagerTest { ) } - fun withServiceState(state: OngoingCallService.ServiceState) = apply { - every { OngoingCallService.Companion.serviceState.get() } returns state - every { OngoingCallService.serviceState.get() } returns state + fun withServiceState(state: CallService.ServiceState) = apply { + every { CallService.Companion.serviceState.get() } returns state + every { CallService.serviceState.get() } returns state } fun arrange() = this to servicesManager