Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PM-13425: Auto-navigate to Login Approval screen when app is foregrounded #4348

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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