Skip to content

Commit

Permalink
fix: can not interact with second incoming call (WPB-9965) (#3251)
Browse files Browse the repository at this point in the history
  • Loading branch information
yamilmedina authored Aug 1, 2024
1 parent 0a90c93 commit 29fb931
Show file tree
Hide file tree
Showing 22 changed files with 493 additions and 234 deletions.
11 changes: 10 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,23 @@
android:theme="@style/AppTheme" />

<activity
android:name=".ui.calling.CallActivity"
android:name=".ui.calling.ongoing.OngoingCallActivity"
android:exported="true"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:taskAffinity="wire.call"
android:theme="@style/AppTheme" />

<activity
android:name=".ui.calling.StartingCallActivity"
android:exported="true"
android:hardwareAccelerated="true"
android:launchMode="singleInstance"
android:screenOrientation="portrait"
android:taskAffinity="wire.call"
android:theme="@style/AppTheme" />

<activity
android:name=".ui.WireActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.wire.android.migration.feature.MigrateServerConfigUseCase
import com.wire.android.migration.feature.MigrateUsersUseCase
import com.wire.android.migration.util.ScalaDBNameProvider
import com.wire.android.notification.NotificationConstants
import com.wire.android.notification.NotificationIds
import com.wire.android.notification.openAppPendingIntent
import com.wire.android.notification.openMigrationLoginPendingIntent
import com.wire.android.util.EMPTY
Expand Down Expand Up @@ -95,6 +96,7 @@ class MigrationManager @Inject constructor(
.getDatabasePath(ScalaDBNameProvider.globalDB())
.let { it.isFile && it.exists() }
}

suspend fun shouldMigrate(): Boolean = when {
// already migrated
globalDataStore.isMigrationCompleted() -> false
Expand Down Expand Up @@ -316,7 +318,7 @@ class MigrationManager @Inject constructor(
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContentIntent(pendingIntent)
.build()
notificationManager.notify(NotificationConstants.MIGRATION_ERROR_NOTIFICATION_ID, notification)
notificationManager.notify(NotificationIds.MIGRATION_ERROR_NOTIFICATION_ID.ordinal, notification)
}

private fun showAccountAnyNotification() {
Expand All @@ -338,7 +340,7 @@ class MigrationManager @Inject constructor(
}

fun dismissMigrationFailureNotification() {
notificationManager.cancel(NotificationConstants.MIGRATION_ERROR_NOTIFICATION_ID)
notificationManager.cancel(NotificationIds.MIGRATION_ERROR_NOTIFICATION_ID.ordinal)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ class CallNotificationManager @Inject constructor(
// cancelling vibration as probably when we were cancelling, the vibration object was still being created and started and thus
// never stopped.
TimeUnit.MILLISECONDS.sleep(CANCEL_CALL_NOTIFICATION_DELAY)
notificationManager.cancel(NotificationConstants.CALL_INCOMING_NOTIFICATION_ID)
notificationManager.cancel(NotificationIds.CALL_INCOMING_NOTIFICATION_ID.ordinal)
}

private fun hideOutgoingCallNotification() {
appLogger.i("$TAG: hiding outgoing call")
notificationManager.cancel(NotificationConstants.CALL_OUTGOING_NOTIFICATION_ID)
notificationManager.cancel(NotificationIds.CALL_OUTGOING_NOTIFICATION_ID.ordinal)
}

@SuppressLint("MissingPermission")
Expand All @@ -160,7 +160,7 @@ class CallNotificationManager @Inject constructor(
appLogger.i("$TAG: showing incoming call notification for user ${data.userId.toLogString()}")
val notification = builder.getIncomingCallNotification(data)
notificationManager.notify(
NotificationConstants.CALL_INCOMING_NOTIFICATION_ID,
NotificationIds.CALL_INCOMING_NOTIFICATION_ID.ordinal,
notification
)
}
Expand All @@ -171,7 +171,7 @@ class CallNotificationManager @Inject constructor(
appLogger.i("$TAG: showing outgoing call notification for user ${data.userId.toLogString()}")
val notification = builder.getOutgoingCallNotification(data)
notificationManager.notify(
NotificationConstants.CALL_OUTGOING_NOTIFICATION_ID,
NotificationIds.CALL_OUTGOING_NOTIFICATION_ID.ordinal,
notification
)
}
Expand All @@ -186,7 +186,7 @@ class CallNotificationManager @Inject constructor(
internal const val DEBOUNCE_TIME = 200L

fun hideIncomingCallNotification(context: Context) {
NotificationManagerCompat.from(context).cancel(NotificationConstants.CALL_INCOMING_NOTIFICATION_ID)
NotificationManagerCompat.from(context).cancel(NotificationIds.CALL_INCOMING_NOTIFICATION_ID.ordinal)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,6 @@ object NotificationConstants {

private const val CHANNEL_GROUP_ID_PREFIX = "com.wire.notification_channel_group"

// Notification IDs (has to be unique!)
val CALL_INCOMING_NOTIFICATION_ID = "wire_incoming_call_notification".hashCode()
val CALL_OUTGOING_NOTIFICATION_ID = "wire_outgoing_call_notification".hashCode()
val CALL_ONGOING_NOTIFICATION_ID = "wire_ongoing_call_notification".hashCode()
val PERSISTENT_NOTIFICATION_ID = "wire_persistent_web_socket_notification".hashCode()
val MESSAGE_SYNC_NOTIFICATION_ID = "wire_notification_fetch_notification".hashCode()
val MIGRATION_NOTIFICATION_ID = "wire_migration_notification".hashCode()
val SINGLE_USER_MIGRATION_NOTIFICATION_ID = "wire_single_user_migration_notification".hashCode()
val MIGRATION_ERROR_NOTIFICATION_ID = "wire_migration_error_notification".hashCode()

// MessagesSummaryNotification ID depends on User, use fun getMessagesSummaryId(userId: UserId) to get it
private const val MESSAGE_SUMMARY_ID_STRING = "wire_messages_summary_notification"

Expand All @@ -79,3 +69,15 @@ object NotificationConstants {
*/
private fun getChanelIdForUser(userId: UserId, channelIdPrefix: String): String = "$channelIdPrefix.$userId"
}

// Notification IDs (has to be unique!)
enum class NotificationIds {
CALL_INCOMING_NOTIFICATION_ID,
CALL_OUTGOING_NOTIFICATION_ID,
CALL_ONGOING_NOTIFICATION_ID,
PERSISTENT_NOTIFICATION_ID,
MESSAGE_SYNC_NOTIFICATION_ID,
MIGRATION_NOTIFICATION_ID,
SINGLE_USER_MIGRATION_NOTIFICATION_ID,
MIGRATION_ERROR_NOTIFICATION_ID
}
22 changes: 12 additions & 10 deletions app/src/main/kotlin/com/wire/android/notification/PendingIntents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ import com.wire.android.notification.broadcastreceivers.DeclineIncomingCallRecei
import com.wire.android.notification.broadcastreceivers.EndOngoingCallReceiver
import com.wire.android.notification.broadcastreceivers.NotificationReplyReceiver
import com.wire.android.ui.WireActivity
import com.wire.android.ui.calling.CallActivity
import com.wire.android.ui.calling.CallScreenType
import com.wire.android.ui.calling.CallActivity.Companion.EXTRA_CONVERSATION_ID
import com.wire.android.ui.calling.CallActivity.Companion.EXTRA_SCREEN_TYPE
import com.wire.android.ui.calling.StartingCallActivity
import com.wire.android.ui.calling.StartingCallScreenType
import com.wire.android.ui.calling.getIncomingCallIntent
import com.wire.android.ui.calling.ongoing.OngoingCallActivity
import com.wire.android.util.deeplink.DeepLinkProcessor

fun messagePendingIntent(context: Context, conversationId: String, userId: String?): PendingIntent {
Expand Down Expand Up @@ -134,22 +137,21 @@ fun fullScreenIncomingCallPendingIntent(context: Context, conversationId: String

return PendingIntent.getActivity(
context,
FULL_SCREEN_REQUEST_CODE,
getRequestCode(conversationId, FULL_SCREEN_REQUEST_CODE),
intent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
}

private fun openOutgoingCallIntent(context: Context, conversationId: String) =
Intent(context.applicationContext, CallActivity::class.java).apply {
putExtra(CallActivity.EXTRA_CONVERSATION_ID, conversationId)
putExtra(CallActivity.EXTRA_SCREEN_TYPE, CallScreenType.Outgoing.name)
Intent(context.applicationContext, StartingCallActivity::class.java).apply {
putExtra(EXTRA_CONVERSATION_ID, conversationId)
putExtra(EXTRA_SCREEN_TYPE, StartingCallScreenType.Outgoing.name)
}

private fun openOngoingCallIntent(context: Context, conversationId: String) =
Intent(context.applicationContext, CallActivity::class.java).apply {
putExtra(CallActivity.EXTRA_CONVERSATION_ID, conversationId)
putExtra(CallActivity.EXTRA_SCREEN_TYPE, CallScreenType.Ongoing.name)
Intent(context.applicationContext, OngoingCallActivity::class.java).apply {
putExtra(EXTRA_CONVERSATION_ID, conversationId)
}

fun callNotificationDismissedPendingIntent(context: Context, userId: String, conversationId: String): PendingIntent =
Expand Down Expand Up @@ -193,7 +195,7 @@ fun openAppPendingIntent(context: Context): PendingIntent {

private const val MESSAGE_NOTIFICATIONS_SUMMARY_REQUEST_CODE = 0
private const val DECLINE_CALL_REQUEST_CODE = "decline_call_"
private const val FULL_SCREEN_REQUEST_CODE = 3
private const val FULL_SCREEN_REQUEST_CODE = "incoming_call_"
private const val OPEN_ONGOING_CALL_REQUEST_CODE = 4
private const val OPEN_MIGRATION_LOGIN_REQUEST_CODE = 5
private const val OUTGOING_CALL_REQUEST_CODE = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import com.wire.android.di.KaliumCoreLogic
import com.wire.android.di.NoSession
import com.wire.android.notification.CallNotificationData
import com.wire.android.notification.CallNotificationManager
import com.wire.android.notification.NotificationConstants.CALL_ONGOING_NOTIFICATION_ID
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.id.QualifiedIdMapper
Expand Down Expand Up @@ -138,7 +138,7 @@ class OngoingCallService : Service() {
val notification: Notification = callNotificationManager.builder.getOngoingCallNotification(data)
ServiceCompat.startForeground(
this,
CALL_ONGOING_NOTIFICATION_ID,
NotificationIds.CALL_ONGOING_NOTIFICATION_ID.ordinal,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL or ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
)
Expand All @@ -152,7 +152,7 @@ class OngoingCallService : Service() {
callNotificationManager.builder.getOngoingCallPlaceholderNotification()
ServiceCompat.startForeground(
this,
CALL_ONGOING_NOTIFICATION_ID,
NotificationIds.CALL_ONGOING_NOTIFICATION_ID.ordinal,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL or ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import com.wire.android.appLogger
import com.wire.android.di.CurrentSessionFlowService
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.notification.NotificationChannelsManager
import com.wire.android.notification.NotificationConstants.PERSISTENT_NOTIFICATION_ID
import com.wire.android.notification.NotificationConstants.WEB_SOCKET_CHANNEL_ID
import com.wire.android.notification.NotificationConstants.WEB_SOCKET_CHANNEL_NAME
import com.wire.android.notification.NotificationIds
import com.wire.android.notification.WireNotificationManager
import com.wire.android.notification.openAppPendingIntent
import com.wire.android.util.dispatchers.DispatcherProvider
Expand Down Expand Up @@ -129,7 +129,12 @@ class PersistentWebSocketService : Service() {
.setOngoing(true)
.build()

ServiceCompat.startForeground(this, PERSISTENT_NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
ServiceCompat.startForeground(
this,
NotificationIds.PERSISTENT_NOTIFICATION_ID.ordinal,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
)
}

override fun onDestroy() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import com.wire.android.navigation.NavigationGraph
import com.wire.android.navigation.navigateToItem
import com.wire.android.navigation.rememberNavigator
import com.wire.android.ui.calling.getIncomingCallIntent
import com.wire.android.ui.calling.getOngoingCallIntent
import com.wire.android.ui.calling.ongoing.getOngoingCallIntent
import com.wire.android.ui.calling.getOutgoingCallIntent
import com.wire.android.ui.common.snackbar.LocalSnackbarHostState
import com.wire.android.ui.common.topappbar.CommonTopAppBar
Expand Down
Loading

0 comments on commit 29fb931

Please sign in to comment.