Skip to content

Commit

Permalink
Revert "Added Add Biometric Dialog and removed extra screens in swift."
Browse files Browse the repository at this point in the history
This reverts commit ee5a271.
  • Loading branch information
therajanmaurya committed Sep 9, 2024
1 parent fe6f1fa commit c336796
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 189 deletions.
9 changes: 4 additions & 5 deletions androidApp/src/main/java/com/mifos/passcode/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,30 @@ import com.mifos.shared.component.PasscodeScreen


class MainActivity : FragmentActivity() {

private val bioMetricUtil by lazy {
BiometricUtilAndroidImpl(this, CipherUtilAndroidImpl())
}
private lateinit var passcodeRepository: PasscodeRepository

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

bioMetricUtil.preparePrompt(
title= getString(R.string.biometric_auth_title),
subtitle = "",
description = getString(R.string.biometric_auth_description)
)
passcodeRepository = PasscodeRepositoryImpl(PreferenceManager())

setContent {
val biometricViewModel: BiometricAuthorizationViewModel = viewModel()

PasscodeScreen(
onForgotButton = { onPasscodeForgot() },
onSkipButton = { onPasscodeSkip() },
onPasscodeConfirm = { onPassCodeReceive(it) },
onPasscodeRejected = { onPasscodeReject() },
enableBiometric = true,
bioMetricUtil = bioMetricUtil,
onBiometricAuthSuccess = { launchNextActivity() },
biometricAuthorizationViewModel = biometricViewModel,
onBiometricAuthSuccess = { launchNextActivity() }
)
}
}
Expand Down
9 changes: 4 additions & 5 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iOSApp.swift */; };
233D688A2C65FB740071A8DB /* BiometricUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 233D68892C65FB740071A8DB /* BiometricUtil.swift */; };
233D688C2C65FBB00071A8DB /* CipherUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 233D688B2C65FBB00071A8DB /* CipherUtil.swift */; };
238E63B22C43A6CA009CC6DA /* SetPublicKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 238E63B12C43A6CA009CC6DA /* SetPublicKey.swift */; };
238E63B42C43A92C009CC6DA /* VerifyBiometric.swift in Sources */ = {isa = PBXBuildFile; fileRef = 238E63B32C43A92C009CC6DA /* VerifyBiometric.swift */; };
7555FF83242A565900829871 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* ContentView.swift */; };
B4058FFAC578793E917A8C84 /* Pods_iosApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AEF023C9E821DAC5AA81FB02 /* Pods_iosApp.framework */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -139,9 +141,6 @@
7555FF73242A565900829871 /* Project object */ = {
isa = PBXProject;
attributes = {
KnownAssetTags = (
New,
);
LastSwiftUpdateCheck = 1130;
LastUpgradeCheck = 1130;
ORGANIZATIONNAME = orgName;
Expand Down Expand Up @@ -229,9 +228,11 @@
buildActionMask = 2147483647;
files = (
233D688A2C65FB740071A8DB /* BiometricUtil.swift in Sources */,
238E63B22C43A6CA009CC6DA /* SetPublicKey.swift in Sources */,
233D688C2C65FBB00071A8DB /* CipherUtil.swift in Sources */,
2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */,
7555FF83242A565900829871 /* ContentView.swift in Sources */,
238E63B42C43A92C009CC6DA /* VerifyBiometric.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -296,7 +297,6 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
};
Expand Down Expand Up @@ -352,7 +352,6 @@
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
VALIDATE_PRODUCT = YES;
TARGETED_DEVICE_FAMILY = 1;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "mifos_logo.jpg",
"filename" : "biometric.png",
"idiom" : "universal",
"scale" : "1x"
},
Expand Down
21 changes: 21 additions & 0 deletions iosApp/iosApp/SetPublicKey.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation
import SwiftUI

struct SetPublicKey: View {

@Binding var path: NavigationPath

var body: some View {
VStack {
Image("biometric")
.resizable()
.scaledToFit()
Spacer()
Button(action: {

}, label: {
Text("Set Biometric")
})
}.padding()
}
}
21 changes: 21 additions & 0 deletions iosApp/iosApp/VerifyBiometric.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation
import SwiftUI

struct VerifyBiometric: View {

@Binding var path: NavigationPath

var body: some View {
VStack {
Image("biometric")
.resizable()
.scaledToFit()
Spacer()
Button(action: {

}, label: {
Text("Veify Biometric")
})
}.padding()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BiometricUtilAndroidImpl(

@RequiresApi(Build.VERSION_CODES.O)
override fun getPublicKey(): String? {
return cipherUtil.getPublicKey()?.encoded?.toBase64Encoded()?.toPemFormat()?.toBase64Encoded()
return cipherUtil.getPublicKey().encoded?.toBase64Encoded()?.toPemFormat()?.toBase64Encoded()
}

override fun isValidCrypto(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class CipherUtilAndroidImpl: ICipherUtil {
return keyPairGenerator.genKeyPair()
}

override fun getPublicKey(): PublicKey? = getKeyPair()?.public
override fun getPublicKey(): PublicKey = getKeyPair().public

private fun getKeyPair(): KeyPair? {
private fun getKeyPair(): KeyPair {
val keyStore = KeyStore.getInstance("AndroidKeyStore")
keyStore.load(null)
keyStore?.getCertificate(KEY_NAME).let { return KeyPair(it?.publicKey, null) }
Expand Down
5 changes: 0 additions & 5 deletions shared/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,4 @@
<string name="authentication_not_set">Authentication not set</string>
<string name="authentication_not_available">Feature unavailable</string>
<string name="biometric_registration_success">Biometric Registration Successful !</string>
<string name="enable_biometric_dialog_title">Do you want to enable app lock ?</string>
<string name="enable_biometric_dialog_description">Use your existing PIN, pattern, face ID, or fingerprint to unlock this app.</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="ok">Ok</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface ICipherUtil {
@Throws(Exception::class)
fun generateKeyPair(): CommonKeyPair

fun getPublicKey(): CommonPublicKey?
fun getPublicKey(): CommonPublicKey

@Throws(Exception::class)
fun getCrypto(): Crypto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.mifos.shared.Platform
import com.mifos.shared.getPlatform
import com.mifos.shared.utility.BioMetricUtil
import com.mifos.shared.utility.PreferenceManager
import com.mifos.shared.theme.blueTint
import com.mifos.shared.utility.Constants.PASSCODE_LENGTH
import com.mifos.shared.utility.ShakeAnimation.performShakeAnimation
import com.mifos.shared.utility.Step
import com.mifos.shared.viewmodels.BiometricAuthorizationViewModel
import com.mifos.shared.viewmodels.BiometricEffect
import com.mifos.shared.viewmodels.PasscodeViewModel
import com.mifos.shared.resources.Res
import com.mifos.shared.resources.biometric_registration_success
import com.mifos.shared.resources.ok
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.getString
Expand All @@ -60,14 +62,13 @@ import org.jetbrains.compose.resources.getString
@Composable
fun PasscodeScreen(
viewModel: PasscodeViewModel = viewModel { PasscodeViewModel() },
biometricAuthorizationViewModel: BiometricAuthorizationViewModel,
bioMetricUtil: BioMetricUtil,
onForgotButton: () -> Unit,
onSkipButton: () -> Unit,
onPasscodeConfirm: (String) -> Unit,
onPasscodeRejected: () -> Unit,
enableBiometric: Boolean = false,
onBiometricAuthSuccess: () -> Unit = {},
biometricAuthorizationViewModel: BiometricAuthorizationViewModel = viewModel(),
bioMetricUtil: BioMetricUtil? = null,
onBiometricAuthSuccess: () -> Unit
) {
val preferenceManager = remember { PreferenceManager() }
val activeStep by viewModel.activeStep.collectAsState()
Expand All @@ -79,40 +80,19 @@ fun PasscodeScreen(
val biometricState by biometricAuthorizationViewModel.state.collectAsState()
var biometricMessage by rememberSaveable { mutableStateOf("") }
val coroutineScope = rememberCoroutineScope()
var showBiometricDialog by rememberSaveable{ mutableStateOf(false) }


if(showBiometricDialog)
{
PasscodeBiometricConfirmDialog(
setBiometric = {
biometricAuthorizationViewModel.setBiometricAuthorization(bioMetricUtil!!)
},
cancelBiometric = {
showBiometricDialog = false
}
)
}

if(enableBiometric) {
biometricState.error?.let {
biometricMessage = it
}
biometricState.error?.let {
biometricMessage = it
}

LaunchedEffect(key1 = Unit) {
if(enableBiometric) {
biometricAuthorizationViewModel.effect.collectLatest {
when (it) {
BiometricEffect.BiometricAuthSuccess -> {
onBiometricAuthSuccess.invoke()
showBiometricDialog = false
}

BiometricEffect.BiometricSetSuccess -> {
biometricMessage = getString(Res.string.biometric_registration_success)
showBiometricDialog = false
}
biometricAuthorizationViewModel.effect.collectLatest {
when (it) {
BiometricEffect.BiometricAuthSuccess -> {
onBiometricAuthSuccess.invoke()
}
BiometricEffect.BiometricSetSuccess -> {
biometricMessage = getString( Res.string.biometric_registration_success )
}
}
}
Expand All @@ -132,15 +112,17 @@ fun PasscodeScreen(
}
}

LaunchedEffect(true) {
if(preferenceManager.hasPasscode && enableBiometric) {
if(bioMetricUtil!!.isBiometricSet())
biometricAuthorizationViewModel.authorizeBiometric(bioMetricUtil)
else
showBiometricDialog = true
LaunchedEffect(activeStep) {
if (activeStep == Step.Confirm) {
biometricAuthorizationViewModel.setBiometricAuthorization(bioMetricUtil)
}
}

LaunchedEffect(true){
if(preferenceManager.hasPasscode)
biometricAuthorizationViewModel.authorizeBiometric(bioMetricUtil)
}

val snackBarHostState = remember {
SnackbarHostState()
}
Expand Down Expand Up @@ -193,16 +175,14 @@ fun PasscodeScreen(
onForgotButton = { onForgotButton.invoke() },
hasPassCode = preferenceManager.hasPasscode
)

UseTouchIdButton(
onClick = {
if ( bioMetricUtil!!.isBiometricSet() )
if(bioMetricUtil.isBiometricSet())
biometricAuthorizationViewModel.authorizeBiometric(bioMetricUtil)
else
showBiometricDialog = true
biometricAuthorizationViewModel.setBiometricAuthorization(bioMetricUtil)
},
hasPassCode = preferenceManager.hasPasscode,
enableBiometric = enableBiometric
hasPassCode = preferenceManager.hasPasscode
)

LaunchedEffect ( biometricMessage ) {
Expand All @@ -212,7 +192,7 @@ fun PasscodeScreen(
message = biometricMessage,
duration = SnackbarDuration.Short,
withDismissAction = false,
actionLabel = getString(Res.string.ok)
actionLabel = "Ok"
)
}
}
Expand Down
Loading

0 comments on commit c336796

Please sign in to comment.