Skip to content

Commit

Permalink
Merge pull request #369 from tangem/merge_5.9_dev
Browse files Browse the repository at this point in the history
Merge 5.9 dev
  • Loading branch information
kozarezvlad authored Apr 17, 2024
2 parents e62d562 + 69549ec commit 6b91964
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.tangem.sdk

import android.app.Activity
import android.os.Build
import androidx.core.app.ComponentActivity
import com.tangem.Log
import com.tangem.Message
import com.tangem.SessionViewDelegate
Expand All @@ -27,7 +28,7 @@ import com.tangem.sdk.ui.NfcSessionDialog
*/
class DefaultSessionViewDelegate(
private val nfcManager: NfcManager,
private val activity: Activity,
private val activity: ComponentActivity,
) : SessionViewDelegate {

var sdkConfig: Config = Config()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ internal class AndroidAuthenticationManager(
.build()
}

private val biometricsStatus = MutableStateFlow(BiometricsStatus.UNINITIALIZED)
private val biometricsStatus = MutableStateFlow(BiometricsStatus.NOT_INITIALIZED)

override val canAuthenticate: Boolean
get() {
if (biometricsStatus.value == BiometricsStatus.UNAVAILABLE) {
if (biometricsStatus.value == BiometricsStatus.NOT_INITIALIZED) {
error("Biometrics status must be initialized before checking if biometrics can authenticate")
}

Expand All @@ -56,7 +56,7 @@ internal class AndroidAuthenticationManager(

override val needEnrollBiometrics: Boolean
get() {
if (biometricsStatus.value == BiometricsStatus.UNAVAILABLE) {
if (biometricsStatus.value == BiometricsStatus.NOT_INITIALIZED) {
error("Biometrics status must be initialized before checking if biometrics need to be enrolled")
}

Expand All @@ -74,7 +74,7 @@ internal class AndroidAuthenticationManager(
override fun onPause(owner: LifecycleOwner) {
Log.biometric { "Owner has been paused, biometrics was uninitialized" }

biometricsStatus.value = BiometricsStatus.UNINITIALIZED
biometricsStatus.value = BiometricsStatus.NOT_INITIALIZED
}

override suspend fun authenticate(
Expand Down Expand Up @@ -106,7 +106,7 @@ internal class AndroidAuthenticationManager(

throw TangemSdkError.AuthenticationUnavailable()
}
BiometricsStatus.UNINITIALIZED -> {
BiometricsStatus.NOT_INITIALIZED -> {
Log.biometric { "Awaiting for the biometrics status to be initialized" }

awaitBiometricsInititialization()
Expand Down Expand Up @@ -164,7 +164,7 @@ internal class AndroidAuthenticationManager(
)

private suspend fun awaitBiometricsInititialization() {
biometricsStatus.first { it != BiometricsStatus.UNINITIALIZED }
biometricsStatus.first { it != BiometricsStatus.NOT_INITIALIZED }
}

@Suppress("LongMethod")
Expand Down Expand Up @@ -258,7 +258,7 @@ internal class AndroidAuthenticationManager(
AUTHENTICATING,
UNAVAILABLE,
NEED_ENROLL,
UNINITIALIZED,
NOT_INITIALIZED,
}

private sealed interface BiometricAuthenticationResult {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.tangem.sdk.ui

import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Intent
import android.provider.Settings
import androidx.appcompat.app.AlertDialog
import androidx.core.app.ComponentActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.tangem.sdk.R
import com.tangem.sdk.extensions.sdkThemeContext
Expand All @@ -13,15 +15,17 @@ class NfcEnableDialog {

private var dialog: AlertDialog? = null

fun show(activity: Activity) {
fun show(activity: ComponentActivity) {
val builder = MaterialAlertDialogBuilder(activity.sdkThemeContext())
builder.setCancelable(false)
.setIcon(R.drawable.ic_action_nfc_gray)
.setTitle(R.string.dialog_nfc_enable_title)
.setMessage(R.string.dialog_nfc_enable_text)
.setPositiveButton(R.string.common_ok) { _, _ ->
try {
activity.startActivity(Intent(Settings.ACTION_NFC_SETTINGS))
if ((activity as? LifecycleOwner)?.lifecycle?.currentState == Lifecycle.State.STARTED) {
activity.startActivity(Intent(Settings.ACTION_NFC_SETTINGS))
}
} catch (ex: ActivityNotFoundException) {
print(ex.toString())
}
Expand Down
6 changes: 3 additions & 3 deletions tangem-sdk-core/src/main/java/com/tangem/TangemSdk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1157,8 +1157,8 @@ class TangemSdk(
keystoreManager: KeystoreManager,
secureStorage: SecureStorage,
config: Config,
): UserCodeRepository? {
return if (authenticationManager.canAuthenticate &&
): UserCodeRepository? = runCatching {
if (authenticationManager.canAuthenticate &&
config.userCodeRequestPolicy is UserCodeRequestPolicy.AlwaysWithBiometrics
) {
UserCodeRepository(
Expand All @@ -1168,7 +1168,7 @@ class TangemSdk(
} else {
null
}
}
}.getOrNull()

private fun makeSession(
cardId: String? = null,
Expand Down

0 comments on commit 6b91964

Please # to comment.