From 2836bccfce05ade33587de0694d6d509254cee9c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 17 Jun 2026 11:11:26 +0200 Subject: [PATCH] Handle PR reviews. --- .../linknewdevice/impl/LinkNewDeviceFlowNode.kt | 2 +- .../lockscreen/api/DeviceUnlockEntryPoint.kt | 2 +- .../impl/biometric/BiometricAuthenticator.kt | 1 + .../impl/biometric/BiometricAuthenticatorManager.kt | 2 +- .../DefaultBiometricAuthenticatorManager.kt | 2 +- .../lockscreen/impl/device/DeviceUnlockNode.kt | 4 ++-- .../lockscreen/impl/device/DeviceUnlockPresenter.kt | 13 +++++-------- .../impl/device/DeviceUnlockPresenterTest.kt | 2 +- .../test/FakeDeviceUnlockEntryPointCallback.kt | 2 +- 9 files changed, 14 insertions(+), 16 deletions(-) diff --git a/features/linknewdevice/impl/src/main/kotlin/io/element/android/features/linknewdevice/impl/LinkNewDeviceFlowNode.kt b/features/linknewdevice/impl/src/main/kotlin/io/element/android/features/linknewdevice/impl/LinkNewDeviceFlowNode.kt index 8f434384c4..d686b22860 100644 --- a/features/linknewdevice/impl/src/main/kotlin/io/element/android/features/linknewdevice/impl/LinkNewDeviceFlowNode.kt +++ b/features/linknewdevice/impl/src/main/kotlin/io/element/android/features/linknewdevice/impl/LinkNewDeviceFlowNode.kt @@ -242,7 +242,7 @@ class LinkNewDeviceFlowNode( override fun onUnlockDevice(type: LinkDeviceType) { val callback = object : DeviceUnlockEntryPoint.Callback { override fun onCancel() = Unit - override fun onUnlocked() = when (type) { + override fun onUnlock() = when (type) { LinkDeviceType.Mobile -> { linkNewMobileHandler.reset() linkNewMobileHandler.createAndStartNewHandler() diff --git a/features/lockscreen/api/src/main/kotlin/io/element/android/features/lockscreen/api/DeviceUnlockEntryPoint.kt b/features/lockscreen/api/src/main/kotlin/io/element/android/features/lockscreen/api/DeviceUnlockEntryPoint.kt index 2953688a84..d67668caf1 100644 --- a/features/lockscreen/api/src/main/kotlin/io/element/android/features/lockscreen/api/DeviceUnlockEntryPoint.kt +++ b/features/lockscreen/api/src/main/kotlin/io/element/android/features/lockscreen/api/DeviceUnlockEntryPoint.kt @@ -30,6 +30,6 @@ interface DeviceUnlockEntryPoint : FeatureEntryPoint { interface Callback { fun onCancel() - fun onUnlocked() + fun onUnlock() } } diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/BiometricAuthenticator.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/BiometricAuthenticator.kt index 097049c97a..74d36b0834 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/BiometricAuthenticator.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/BiometricAuthenticator.kt @@ -59,6 +59,7 @@ class DefaultBiometricAuthentication( private var cryptoObject: CryptoObject? = null override suspend fun setup() { + if (cryptoObject != null) return try { val secretKey = ensureKey() val cipher = encryptionDecryptionService.createEncryptionCipher(secretKey) diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/BiometricAuthenticatorManager.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/BiometricAuthenticatorManager.kt index 6234e65284..cccfa143b9 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/BiometricAuthenticatorManager.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/BiometricAuthenticatorManager.kt @@ -22,7 +22,7 @@ interface BiometricAuthenticatorManager { val hasAvailableAuthenticator: Boolean /** - * If the device is secured for example with a pin, pattern or password, and the user has enrolled at least one biometric. + * If the device is secured for example with a pin, a pattern, a password, or biometric. */ val canUseDeviceUnlock: Boolean diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/DefaultBiometricAuthenticatorManager.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/DefaultBiometricAuthenticatorManager.kt index 27408c919a..80ea43b44d 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/DefaultBiometricAuthenticatorManager.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/DefaultBiometricAuthenticatorManager.kt @@ -71,7 +71,7 @@ class DefaultBiometricAuthenticatorManager( biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG) == BiometricManager.BIOMETRIC_SUCCESS /** - * Returns true if a strong biometric method (i.e.: fingerprint, some face or iris unlock implementations) can be used. + * Returns true if a device credential method (i.e.: pattern, pin) can be used. */ private val canUseDeviceCredentialAuth: Boolean get() = biometricManager.canAuthenticate(BiometricManager.Authenticators.DEVICE_CREDENTIAL) == BiometricManager.BIOMETRIC_SUCCESS diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/device/DeviceUnlockNode.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/device/DeviceUnlockNode.kt index 2df706abe7..9b73239725 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/device/DeviceUnlockNode.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/device/DeviceUnlockNode.kt @@ -26,14 +26,14 @@ class DeviceUnlockNode( @Assisted buildContext: BuildContext, @Assisted plugins: List, private val presenter: DeviceUnlockPresenter, - private val presenterFactory: PinUnlockPresenter.Factory, + private val pinUnlockPresenterFactory: PinUnlockPresenter.Factory, ) : Node(buildContext, plugins = plugins) { @Composable override fun View(modifier: Modifier) { val state = presenter.present() if (state.showApplicationPinCode) { val pinUnlockPresenter = remember { - presenterFactory.create(forDeviceUnlock = true) + pinUnlockPresenterFactory.create(forDeviceUnlock = true) } val pinState = pinUnlockPresenter.present() PinUnlockView( diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/device/DeviceUnlockPresenter.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/device/DeviceUnlockPresenter.kt index 4cc2bb8fd1..676340764e 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/device/DeviceUnlockPresenter.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/device/DeviceUnlockPresenter.kt @@ -13,7 +13,6 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import dev.zacsweers.metro.Inject import io.element.android.features.lockscreen.impl.biometric.BiometricAuthenticatorManager @@ -21,36 +20,34 @@ import io.element.android.features.lockscreen.impl.pin.PinCodeManager import io.element.android.features.lockscreen.impl.unlock.PinUnlockHelper import io.element.android.libraries.architecture.Presenter import kotlinx.coroutines.flow.first -import kotlinx.coroutines.launch @Inject class DeviceUnlockPresenter( private val pinUnlockHelper: PinUnlockHelper, private val biometricAuthenticatorManager: BiometricAuthenticatorManager, - private val biometricRequester: DeviceUnlockCallbackHolder, + private val deviceUnlockCallbackHolder: DeviceUnlockCallbackHolder, private val pinCodeManager: PinCodeManager, ) : Presenter { @Composable override fun present(): DeviceUnlockState { - val coroutineScope = rememberCoroutineScope() var showApplicationPinCode by remember { mutableStateOf(false) } val biometricUnlock = biometricAuthenticatorManager.rememberUnlockDeviceBiometricAuthenticator() - val deviceUnlockCallback by biometricRequester.deviceUnlockCallback.collectAsState() + val deviceUnlockCallback by deviceUnlockCallbackHolder.deviceUnlockCallback.collectAsState() val canUseDeviceUnlock = biometricAuthenticatorManager.canUseDeviceUnlock - fun setUnlock(isUnlock: Boolean) = coroutineScope.launch { + fun setUnlock(isUnlock: Boolean) { deviceUnlockCallback?.let { if (isUnlock) { - it.onUnlocked() + it.onUnlock() } else { it.onCancel() } } showApplicationPinCode = false - biometricRequester.onDone() + deviceUnlockCallbackHolder.onDone() } LaunchedEffect(biometricUnlock, canUseDeviceUnlock, deviceUnlockCallback) { diff --git a/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/device/DeviceUnlockPresenterTest.kt b/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/device/DeviceUnlockPresenterTest.kt index 4b1cdf645d..52aeaa04a8 100644 --- a/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/device/DeviceUnlockPresenterTest.kt +++ b/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/device/DeviceUnlockPresenterTest.kt @@ -145,7 +145,7 @@ class DeviceUnlockPresenterTest { return DeviceUnlockPresenter( pinUnlockHelper = pinUnlockHelper, biometricAuthenticatorManager = biometricAuthenticatorManager, - biometricRequester = callbackHolder, + deviceUnlockCallbackHolder = callbackHolder, pinCodeManager = pinCodeManager, ) } diff --git a/features/lockscreen/test/src/main/kotlin/io/element/android/features/lockscreen/test/FakeDeviceUnlockEntryPointCallback.kt b/features/lockscreen/test/src/main/kotlin/io/element/android/features/lockscreen/test/FakeDeviceUnlockEntryPointCallback.kt index 9c80caede2..3b7394cae0 100644 --- a/features/lockscreen/test/src/main/kotlin/io/element/android/features/lockscreen/test/FakeDeviceUnlockEntryPointCallback.kt +++ b/features/lockscreen/test/src/main/kotlin/io/element/android/features/lockscreen/test/FakeDeviceUnlockEntryPointCallback.kt @@ -15,5 +15,5 @@ class FakeDeviceUnlockEntryPointCallback( private val onUnlockedLambda: () -> Unit = EnsureNeverCalled(), ) : DeviceUnlockEntryPoint.Callback { override fun onCancel() = onCancelLambda() - override fun onUnlocked() = onUnlockedLambda() + override fun onUnlock() = onUnlockedLambda() }