Skip to content

Commit

Permalink
PM-13425: Auto-navigate to Login Approval screen when app is foregrou…
Browse files Browse the repository at this point in the history
…nded
  • Loading branch information
david-livefront committed Nov 20, 2024
1 parent 96bd25e commit e41c0b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)
Expand Down

0 comments on commit e41c0b6

Please sign in to comment.