diff --git a/appconfig/build.gradle.kts b/appconfig/build.gradle.kts index a6e66f1462..bb3f16e3b4 100644 --- a/appconfig/build.gradle.kts +++ b/appconfig/build.gradle.kts @@ -15,20 +15,13 @@ */ plugins { id("io.element.android-library") - alias(libs.plugins.anvil) } android { namespace = "io.element.android.appconfig" } -anvil { - generateDaggerFactories.set(true) -} - dependencies { implementation(libs.androidx.annotationjvm) - implementation(libs.dagger) - implementation(projects.libraries.di) implementation(projects.libraries.matrix.api) } diff --git a/appconfig/src/main/kotlin/io/element/android/appconfig/LockScreenConfig.kt b/appconfig/src/main/kotlin/io/element/android/appconfig/LockScreenConfig.kt index 02586bea0d..0312265366 100644 --- a/appconfig/src/main/kotlin/io/element/android/appconfig/LockScreenConfig.kt +++ b/appconfig/src/main/kotlin/io/element/android/appconfig/LockScreenConfig.kt @@ -16,44 +16,28 @@ package io.element.android.appconfig -import com.squareup.anvil.annotations.ContributesTo -import dagger.Module -import dagger.Provides -import io.element.android.libraries.di.AppScope import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds -/** - * Configuration for the lock screen feature. - * @property isPinMandatory Whether the PIN is mandatory or not. - * @property pinBlacklist Some PINs are forbidden. - * @property pinSize The size of the PIN. - * @property maxPinCodeAttemptsBeforeLogout Number of attempts before the user is logged out. - * @property gracePeriod Time period before locking the app once backgrounded. - * @property isStrongBiometricsEnabled Authentication with strong methods (fingerprint, some face/iris unlock implementations) is supported. - * @property isWeakBiometricsEnabled Authentication with weak methods (most face/iris unlock implementations) is supported. - */ -data class LockScreenConfig( - val isPinMandatory: Boolean, - val pinBlacklist: Set, - val pinSize: Int, - val maxPinCodeAttemptsBeforeLogout: Int, - val gracePeriod: Duration, - val isStrongBiometricsEnabled: Boolean, - val isWeakBiometricsEnabled: Boolean, -) +object LockScreenConfig { + /** Whether the PIN is mandatory or not. */ + const val IS_PIN_MANDATORY: Boolean = false -@ContributesTo(AppScope::class) -@Module -object LockScreenConfigModule { - @Provides - fun providesLockScreenConfig(): LockScreenConfig = LockScreenConfig( - isPinMandatory = false, - pinBlacklist = setOf("0000", "1234"), - pinSize = 4, - maxPinCodeAttemptsBeforeLogout = 3, - gracePeriod = 0.seconds, - isStrongBiometricsEnabled = true, - isWeakBiometricsEnabled = true, - ) + /** Set of forbidden PIN. */ + val PIN_BLACKLIST: Set = setOf("0000", "1234") + + /** The size of the PIN */ + const val PIN_SIZE: Int = 4 + + /** Number of attempts before the user is logged out. */ + const val MAX_PIN_CODE_ATTEMPTS_BEFORE_LOGOUT: Int = 3 + + /** Time period before locking the app once backgrounded. */ + val GRACE_PERIOD: Duration = 0.seconds + + /** Authentication with strong methods (fingerprint, some face/iris unlock implementations) is supported. */ + const val IS_STRONG_BIOMETRICS_ENABLED: Boolean = true + + /** Authentication with weak methods (most face/iris unlock implementations) is supported. */ + const val IS_WEAK_BIOMETRICS_ENABLED: Boolean = true } diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/DefaultLockScreenService.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/DefaultLockScreenService.kt index b0b7ab75b3..a72649a125 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/DefaultLockScreenService.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/DefaultLockScreenService.kt @@ -17,7 +17,6 @@ package io.element.android.features.lockscreen.impl import com.squareup.anvil.annotations.ContributesBinding -import io.element.android.appconfig.LockScreenConfig import io.element.android.features.lockscreen.api.LockScreenLockState import io.element.android.features.lockscreen.api.LockScreenService import io.element.android.features.lockscreen.impl.biometric.BiometricUnlockManager diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/LockScreenConfig.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/LockScreenConfig.kt new file mode 100644 index 0000000000..15eaaaab08 --- /dev/null +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/LockScreenConfig.kt @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.lockscreen.impl + +import com.squareup.anvil.annotations.ContributesTo +import dagger.Module +import dagger.Provides +import io.element.android.libraries.di.AppScope +import kotlin.time.Duration +import io.element.android.appconfig.LockScreenConfig as AppConfigLockScreenConfig + +data class LockScreenConfig( + val isPinMandatory: Boolean, + val pinBlacklist: Set, + val pinSize: Int, + val maxPinCodeAttemptsBeforeLogout: Int, + val gracePeriod: Duration, + val isStrongBiometricsEnabled: Boolean, + val isWeakBiometricsEnabled: Boolean, +) + +@ContributesTo(AppScope::class) +@Module +object LockScreenConfigModule { + @Provides + fun providesLockScreenConfig(): LockScreenConfig = LockScreenConfig( + isPinMandatory = AppConfigLockScreenConfig.IS_PIN_MANDATORY, + pinBlacklist = AppConfigLockScreenConfig.PIN_BLACKLIST, + pinSize = AppConfigLockScreenConfig.PIN_SIZE, + maxPinCodeAttemptsBeforeLogout = AppConfigLockScreenConfig.MAX_PIN_CODE_ATTEMPTS_BEFORE_LOGOUT, + gracePeriod = AppConfigLockScreenConfig.GRACE_PERIOD, + isStrongBiometricsEnabled = AppConfigLockScreenConfig.IS_STRONG_BIOMETRICS_ENABLED, + isWeakBiometricsEnabled = AppConfigLockScreenConfig.IS_WEAK_BIOMETRICS_ENABLED, + ) +} diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/DefaultBiometricUnlockManager.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/DefaultBiometricUnlockManager.kt index 95951866f3..68020ba20a 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/DefaultBiometricUnlockManager.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/DefaultBiometricUnlockManager.kt @@ -32,7 +32,7 @@ import androidx.compose.ui.res.stringResource import androidx.core.content.getSystemService import androidx.fragment.app.FragmentActivity import com.squareup.anvil.annotations.ContributesBinding -import io.element.android.appconfig.LockScreenConfig +import io.element.android.features.lockscreen.impl.LockScreenConfig import io.element.android.features.lockscreen.impl.R import io.element.android.features.lockscreen.impl.storage.LockScreenStore import io.element.android.libraries.cryptography.api.EncryptionDecryptionService diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/settings/LockScreenSettingsPresenter.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/settings/LockScreenSettingsPresenter.kt index fbbe0442c1..b0cb97350a 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/settings/LockScreenSettingsPresenter.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/settings/LockScreenSettingsPresenter.kt @@ -23,7 +23,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.produceState import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import io.element.android.appconfig.LockScreenConfig +import io.element.android.features.lockscreen.impl.LockScreenConfig import io.element.android.features.lockscreen.impl.biometric.BiometricUnlockManager import io.element.android.features.lockscreen.impl.pin.PinCodeManager import io.element.android.features.lockscreen.impl.storage.LockScreenStore diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/pin/SetupPinPresenter.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/pin/SetupPinPresenter.kt index ff2bdc56db..ac87d8b2f7 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/pin/SetupPinPresenter.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/pin/SetupPinPresenter.kt @@ -22,7 +22,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import io.element.android.appconfig.LockScreenConfig +import io.element.android.features.lockscreen.impl.LockScreenConfig import io.element.android.features.lockscreen.impl.pin.PinCodeManager import io.element.android.features.lockscreen.impl.pin.model.PinEntry import io.element.android.features.lockscreen.impl.setup.pin.validation.PinValidator diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/pin/validation/PinValidator.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/pin/validation/PinValidator.kt index 22e6275079..602ff4ccf0 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/pin/validation/PinValidator.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/pin/validation/PinValidator.kt @@ -16,7 +16,7 @@ package io.element.android.features.lockscreen.impl.setup.pin.validation -import io.element.android.appconfig.LockScreenConfig +import io.element.android.features.lockscreen.impl.LockScreenConfig import io.element.android.features.lockscreen.impl.pin.model.PinEntry import javax.inject.Inject diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/storage/PreferencesLockScreenStore.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/storage/PreferencesLockScreenStore.kt index b32ef8fd4c..dd0e4c67f6 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/storage/PreferencesLockScreenStore.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/storage/PreferencesLockScreenStore.kt @@ -25,7 +25,7 @@ import androidx.datastore.preferences.core.intPreferencesKey import androidx.datastore.preferences.core.stringPreferencesKey import androidx.datastore.preferences.preferencesDataStore import com.squareup.anvil.annotations.ContributesBinding -import io.element.android.appconfig.LockScreenConfig +import io.element.android.features.lockscreen.impl.LockScreenConfig import io.element.android.libraries.di.AppScope import io.element.android.libraries.di.ApplicationContext import io.element.android.libraries.di.SingleIn diff --git a/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/fixtures/LockScreenConfig.kt b/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/fixtures/LockScreenConfig.kt index aa575eabd4..cf95830539 100644 --- a/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/fixtures/LockScreenConfig.kt +++ b/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/fixtures/LockScreenConfig.kt @@ -16,7 +16,7 @@ package io.element.android.features.lockscreen.impl.fixtures -import io.element.android.appconfig.LockScreenConfig +import io.element.android.features.lockscreen.impl.LockScreenConfig import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds diff --git a/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/settings/LockScreenSettingsPresenterTest.kt b/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/settings/LockScreenSettingsPresenterTest.kt index c3358c471c..46baf620f4 100644 --- a/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/settings/LockScreenSettingsPresenterTest.kt +++ b/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/settings/LockScreenSettingsPresenterTest.kt @@ -20,7 +20,7 @@ import app.cash.molecule.RecompositionMode import app.cash.molecule.moleculeFlow import app.cash.turbine.test import com.google.common.truth.Truth.assertThat -import io.element.android.appconfig.LockScreenConfig +import io.element.android.features.lockscreen.impl.LockScreenConfig import io.element.android.features.lockscreen.impl.biometric.FakeBiometricUnlockManager import io.element.android.features.lockscreen.impl.fixtures.aLockScreenConfig import io.element.android.features.lockscreen.impl.fixtures.aPinCodeManager diff --git a/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/setup/pin/SetupPinPresenterTest.kt b/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/setup/pin/SetupPinPresenterTest.kt index 36774d9ef4..10f1a6abc5 100644 --- a/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/setup/pin/SetupPinPresenterTest.kt +++ b/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/setup/pin/SetupPinPresenterTest.kt @@ -20,7 +20,7 @@ import app.cash.molecule.RecompositionMode import app.cash.molecule.moleculeFlow import app.cash.turbine.test import com.google.common.truth.Truth.assertThat -import io.element.android.appconfig.LockScreenConfig +import io.element.android.features.lockscreen.impl.LockScreenConfig import io.element.android.features.lockscreen.impl.fixtures.aLockScreenConfig import io.element.android.features.lockscreen.impl.fixtures.aPinCodeManager import io.element.android.features.lockscreen.impl.pin.DefaultPinCodeManagerCallback