diff --git a/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/AuthRequestNotificationManagerImpl.kt b/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/AuthRequestNotificationManagerImpl.kt index f2752a54d81..2f382a8b062 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/AuthRequestNotificationManagerImpl.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/AuthRequestNotificationManagerImpl.kt @@ -3,6 +3,7 @@ package com.x8bit.bitwarden.data.auth.manager import android.annotation.SuppressLint import android.app.PendingIntent import android.content.Context +import android.content.Intent import androidx.compose.ui.graphics.Color import androidx.core.app.NotificationChannelCompat import androidx.core.app.NotificationCompat @@ -12,8 +13,10 @@ import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource import com.x8bit.bitwarden.data.auth.util.createPasswordlessRequestDataIntent import com.x8bit.bitwarden.data.autofill.util.toPendingIntentMutabilityFlag import com.x8bit.bitwarden.data.platform.annotation.OmitFromCoverage +import com.x8bit.bitwarden.data.platform.manager.AppStateManager import com.x8bit.bitwarden.data.platform.manager.PushManager import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager +import com.x8bit.bitwarden.data.platform.manager.model.AppForegroundState import com.x8bit.bitwarden.data.platform.manager.model.PasswordlessRequestData import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.launchIn @@ -26,6 +29,7 @@ import kotlinx.coroutines.flow.onEach class AuthRequestNotificationManagerImpl( private val context: Context, private val authDiskSource: AuthDiskSource, + private val appStateManager: AppStateManager, pushManager: PushManager, dispatcherManager: DispatcherManager, ) : AuthRequestNotificationManager { @@ -40,6 +44,14 @@ class AuthRequestNotificationManagerImpl( @SuppressLint("MissingPermission") private fun handlePasswordlessRequestData(data: PasswordlessRequestData) { + if (appStateManager.appForegroundStateFlow.value == AppForegroundState.FOREGROUNDED && + data.userId == authDiskSource.userState?.activeUserId + ) { + context.startActivity( + createPasswordlessRequestDataIntent(context, data) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), + ) + } val notificationManager = NotificationManagerCompat.from(context) // Construct the channel, calling this more than once is safe notificationManager.createNotificationChannel( diff --git a/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/di/AuthManagerModule.kt b/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/di/AuthManagerModule.kt index 0b84837ee73..d561436c6fd 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/di/AuthManagerModule.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/di/AuthManagerModule.kt @@ -21,6 +21,7 @@ import com.x8bit.bitwarden.data.auth.manager.UserLogoutManager import com.x8bit.bitwarden.data.auth.manager.UserLogoutManagerImpl import com.x8bit.bitwarden.data.platform.datasource.disk.PushDiskSource import com.x8bit.bitwarden.data.platform.datasource.disk.SettingsDiskSource +import com.x8bit.bitwarden.data.platform.manager.AppStateManager import com.x8bit.bitwarden.data.platform.manager.PushManager import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager import com.x8bit.bitwarden.data.tools.generator.datasource.disk.GeneratorDiskSource @@ -47,12 +48,14 @@ object AuthManagerModule { fun provideAuthRequestNotificationManager( @ApplicationContext context: Context, authDiskSource: AuthDiskSource, + appStateManager: AppStateManager, pushManager: PushManager, dispatcherManager: DispatcherManager, ): AuthRequestNotificationManager = AuthRequestNotificationManagerImpl( context = context, authDiskSource = authDiskSource, + appStateManager = appStateManager, pushManager = pushManager, dispatcherManager = dispatcherManager, )