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

fix: App crash on app unlock with fingerprint (WPB-5110) (WPB-5108) #2348

Merged
merged 2 commits into from
Oct 20, 2023
Merged
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 @@ -43,7 +43,7 @@ object BiometricPromptUtils {
override fun onAuthenticationError(errorCode: Int, errorString: CharSequence) {
super.onAuthenticationError(errorCode, errorString)
appLogger.i("$TAG errorCode is $errorCode and errorString is: $errorString")
if (errorCode == ERROR_NEGATIVE_BUTTON) {
if (errorCode == ERROR_NEGATIVE_BUTTON || errorCode == BiometricPrompt.ERROR_LOCKOUT) {
onRequestPasscode()
} else {
onCancel()
Expand Down Expand Up @@ -78,16 +78,15 @@ fun AppCompatActivity.showBiometricPrompt(
onCancel: () -> Unit,
onRequestPasscode: () -> Unit
) {
appLogger.i("$TAG showing biometrics dialog...")

val canAuthenticate = BiometricManager.from(this)
.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG)
if (canAuthenticate == BiometricManager.BIOMETRIC_SUCCESS) {
appLogger.i("$TAG showing biometrics dialog...")
val biometricPrompt = BiometricPromptUtils.createBiometricPrompt(
this,
onSuccess,
onCancel,
onRequestPasscode,
activity = this,
onSuccess = onSuccess,
onCancel = onCancel,
onRequestPasscode = onRequestPasscode
)
val promptInfo = BiometricPromptUtils.createPromptInfo(this)
biometricPrompt.authenticate(promptInfo)
Expand Down
57 changes: 31 additions & 26 deletions app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.biometric.BiometricManager
import androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.material3.SnackbarHostState
Expand All @@ -40,7 +41,6 @@
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf
Expand All @@ -49,7 +49,10 @@
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.NavController
import androidx.navigation.NavHostController
import com.ramcosta.composedestinations.spec.Route
Expand Down Expand Up @@ -93,12 +96,9 @@
import com.wire.android.util.deeplink.DeepLinkResult
import com.wire.android.util.ui.updateScreenSettings
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onSubscription
import kotlinx.coroutines.launch
import javax.inject.Inject
Expand Down Expand Up @@ -170,7 +170,6 @@
Column(modifier = Modifier.statusBarsPadding()) {
ReportDrawnWhen { isLoaded }
val navigator = rememberNavigator(this@WireActivity::finish)
val scope = rememberCoroutineScope()
CommonTopAppBar(
connectivityUIState = commonTopAppBarViewModel.connectivityState,
onReturnToCallClick = { establishedCall ->
Expand All @@ -184,7 +183,7 @@

// This setup needs to be done after the navigation graph is created, because building the graph takes some time,
// and if any NavigationCommand is executed before the graph is fully built, it will cause a NullPointerException.
setUpNavigation(navigator.navController, onComplete, scope)
setUpNavigation(navigator.navController, onComplete)

Check warning on line 186 in app/src/main/kotlin/com/wire/android/ui/WireActivity.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivity.kt#L186

Added line #L186 was not covered by tests
isLoaded = true
handleScreenshotCensoring()
handleAppLock(navigator::navigate)
Expand All @@ -199,17 +198,20 @@
private fun setUpNavigation(
navController: NavHostController,
onComplete: () -> Unit,
scope: CoroutineScope
) {
val currentKeyboardController by rememberUpdatedState(LocalSoftwareKeyboardController.current)
val currentNavController by rememberUpdatedState(navController)
LaunchedEffect(scope) {
navigationCommands
.onSubscription { onComplete() }
.onEach { command ->
currentKeyboardController?.hide()
currentNavController.navigateToItem(command)
}.launchIn(scope)
LaunchedEffect(Unit) {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
navigationCommands

Check warning on line 207 in app/src/main/kotlin/com/wire/android/ui/WireActivity.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivity.kt#L205-L207

Added lines #L205 - L207 were not covered by tests
.onSubscription { onComplete() }
.collectLatest {
currentKeyboardController?.hide()
currentNavController.navigateToItem(it)
}
}
}

Check warning on line 214 in app/src/main/kotlin/com/wire/android/ui/WireActivity.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivity.kt#L211-L214

Added lines #L211 - L214 were not covered by tests
}

DisposableEffect(navController) {
Expand Down Expand Up @@ -241,19 +243,22 @@
@Composable
private fun handleAppLock(navigate: (NavigationCommand) -> Unit) {
LaunchedEffect(Unit) {
lockCodeTimeManager.isLocked()
.filter { it }
.collectLatest {
val canAuthenticateWithBiometrics = BiometricManager
.from(this@WireActivity)
.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG)

if (canAuthenticateWithBiometrics == BiometricManager.BIOMETRIC_SUCCESS) {
navigate(NavigationCommand(AppUnlockWithBiometricsScreenDestination, BackStackMode.UPDATE_EXISTED))
} else {
navigate(NavigationCommand(EnterLockCodeScreenDestination, BackStackMode.UPDATE_EXISTED))
lifecycleScope.launch {

Check warning on line 246 in app/src/main/kotlin/com/wire/android/ui/WireActivity.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivity.kt#L246

Added line #L246 was not covered by tests
// Listen to one flow in a lifecycle-aware manner using flowWithLifecycle
lockCodeTimeManager.isLocked()
.flowWithLifecycle(lifecycle, Lifecycle.State.STARTED)
.filter { it }

Check warning on line 250 in app/src/main/kotlin/com/wire/android/ui/WireActivity.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivity.kt#L248-L250

Added lines #L248 - L250 were not covered by tests
.collectLatest {
val canAuthenticateWithBiometrics = BiometricManager
.from(this@WireActivity)
.canAuthenticate(BIOMETRIC_STRONG)

Check warning on line 254 in app/src/main/kotlin/com/wire/android/ui/WireActivity.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivity.kt#L252-L254

Added lines #L252 - L254 were not covered by tests
if (canAuthenticateWithBiometrics == BiometricManager.BIOMETRIC_SUCCESS) {
navigate(NavigationCommand(AppUnlockWithBiometricsScreenDestination, BackStackMode.UPDATE_EXISTED))

Check warning on line 256 in app/src/main/kotlin/com/wire/android/ui/WireActivity.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivity.kt#L256

Added line #L256 was not covered by tests
} else {
navigate(NavigationCommand(EnterLockCodeScreenDestination, BackStackMode.UPDATE_EXISTED))

Check warning on line 258 in app/src/main/kotlin/com/wire/android/ui/WireActivity.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivity.kt#L258

Added line #L258 was not covered by tests
}
}
}
}

Check warning on line 261 in app/src/main/kotlin/com/wire/android/ui/WireActivity.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivity.kt#L261

Added line #L261 was not covered by tests
}
}

Expand Down
Loading