Skip to content

Commit

Permalink
Merge pull request #3395 from owncloud/new_arch/biometric
Browse files Browse the repository at this point in the history
[New arch] Biometric activity
  • Loading branch information
JuancaG05 authored Oct 5, 2021
2 parents a34fef5 + 914120b commit a2c0f2b
Show file tree
Hide file tree
Showing 16 changed files with 416 additions and 398 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
appCompat = "1.2.0"
sqliteVersion = "2.1.0"
lifecycleLiveData = "2.3.1"
biometricVersion="1.0.1"
biometricVersion="1.1.0"

// Kotlin
kotlinVersion = "1.5.21"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ import androidx.test.espresso.matcher.ViewMatchers.isEnabled
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry
import com.owncloud.android.R
import com.owncloud.android.authentication.BiometricManager
import com.owncloud.android.presentation.ui.security.BiometricManager
import com.owncloud.android.presentation.ui.security.PREFERENCE_LOCK_TIMEOUT
import com.owncloud.android.presentation.ui.settings.fragments.SettingsSecurityFragment
import com.owncloud.android.presentation.viewmodels.settings.SettingsSecurityViewModel
import com.owncloud.android.ui.activity.BiometricActivity
import com.owncloud.android.presentation.ui.security.BiometricActivity
import com.owncloud.android.presentation.ui.security.PassCodeActivity
import com.owncloud.android.presentation.ui.security.PatternActivity
import com.owncloud.android.utils.matchers.verifyPreference
import com.owncloud.android.utils.mockIntent
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.mockkObject
import org.hamcrest.Matchers.not
import org.junit.After
import org.junit.Assert.assertFalse
Expand All @@ -72,8 +72,6 @@ class SettingsSecurityFragmentTest {
private lateinit var prefLockApplication: ListPreference
private lateinit var prefTouchesWithOtherVisibleWindows: CheckBoxPreference

private lateinit var biometricManager: BiometricManager

private lateinit var securityViewModel: SettingsSecurityViewModel
private lateinit var context: Context

Expand All @@ -83,10 +81,7 @@ class SettingsSecurityFragmentTest {
fun setUp() {
context = InstrumentationRegistry.getInstrumentation().targetContext
securityViewModel = mockk(relaxUnitFun = true)
mockkStatic(BiometricManager::class)
biometricManager = mockk(relaxUnitFun = true)

every { BiometricManager.getBiometricManager(any()) } returns biometricManager
mockkObject(BiometricManager)

stopKoin()

Expand All @@ -111,7 +106,7 @@ class SettingsSecurityFragmentTest {
}

private fun launchTest(withBiometrics: Boolean = true) {
every { biometricManager.isHardwareDetected } returns withBiometrics
every { BiometricManager.isHardwareDetected() } returns withBiometrics

fragmentScenario = launchFragmentInContainer(themeResId = R.style.Theme_ownCloud)
fragmentScenario.onFragment { fragment ->
Expand Down Expand Up @@ -311,7 +306,7 @@ class SettingsSecurityFragmentTest {

@Test
fun enableBiometricLockWithPasscodeEnabled() {
every { biometricManager.hasEnrolledBiometric() } returns true
every { BiometricManager.hasEnrolledBiometric() } returns true

launchTest()

Expand All @@ -322,7 +317,7 @@ class SettingsSecurityFragmentTest {

@Test
fun enableBiometricLockWithPatternEnabled() {
every { biometricManager.hasEnrolledBiometric() } returns true
every { BiometricManager.hasEnrolledBiometric() } returns true

launchTest()

Expand All @@ -333,7 +328,7 @@ class SettingsSecurityFragmentTest {

@Test
fun enableBiometricLockNoEnrolledBiometric() {
every { biometricManager.hasEnrolledBiometric() } returns false
every { BiometricManager.hasEnrolledBiometric() } returns false

launchTest()

Expand All @@ -345,7 +340,7 @@ class SettingsSecurityFragmentTest {

@Test
fun disableBiometricLock() {
every { biometricManager.hasEnrolledBiometric() } returns true
every { BiometricManager.hasEnrolledBiometric() } returns true

launchTest()

Expand Down
2 changes: 1 addition & 1 deletion owncloudApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode"
android:theme="@style/Theme.ownCloud.Fullscreen" />
<activity android:name=".presentation.ui.security.PatternActivity" />
<activity android:name=".ui.activity.BiometricActivity" />
<activity android:name=".presentation.ui.security.BiometricActivity" />
<activity
android:name=".presentation.ui.authentication.LoginActivity"
android:exported="true"
Expand Down
8 changes: 4 additions & 4 deletions owncloudApp/src/main/java/com/owncloud/android/MainApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.view.WindowManager
import com.owncloud.android.authentication.BiometricManager
import com.owncloud.android.presentation.ui.security.BiometricManager
import com.owncloud.android.presentation.ui.security.PassCodeManager
import com.owncloud.android.presentation.ui.security.PatternManager
import com.owncloud.android.datamodel.ThumbnailsCacheManager
Expand All @@ -46,7 +46,7 @@ import com.owncloud.android.lib.common.OwnCloudClient
import com.owncloud.android.lib.common.SingleSessionManager
import com.owncloud.android.presentation.ui.settings.fragments.SettingsLogsFragment
import com.owncloud.android.providers.LogsProvider
import com.owncloud.android.ui.activity.BiometricActivity
import com.owncloud.android.presentation.ui.security.BiometricActivity
import com.owncloud.android.presentation.ui.security.PassCodeActivity
import com.owncloud.android.presentation.ui.security.PatternActivity
import com.owncloud.android.ui.activity.WhatsNewActivity
Expand Down Expand Up @@ -118,7 +118,7 @@ class MainApp : Application() {
PassCodeManager.onActivityStarted(activity)
PatternManager.onActivityStarted(activity)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
BiometricManager.getBiometricManager(activity).onActivityStarted(activity)
BiometricManager.onActivityStarted(activity)
}
}

Expand All @@ -135,7 +135,7 @@ class MainApp : Application() {
PassCodeManager.onActivityStopped(activity)
PatternManager.onActivityStopped(activity)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
BiometricManager.getBiometricManager(activity).onActivityStopped(activity)
BiometricManager.onActivityStopped(activity)
}
if (activity is PassCodeActivity ||
activity is PatternActivity ||
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import android.content.Context;
import android.content.SharedPreferences;

import com.owncloud.android.ui.activity.BiometricActivity;
import com.owncloud.android.presentation.ui.security.BiometricActivity;
import com.owncloud.android.utils.FileStorageUtils;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.owncloud.android.presentation.viewmodels.authentication.OCAuthenticat
import com.owncloud.android.presentation.viewmodels.capabilities.OCCapabilityViewModel
import com.owncloud.android.presentation.viewmodels.drawer.DrawerViewModel
import com.owncloud.android.presentation.viewmodels.oauth.OAuthViewModel
import com.owncloud.android.presentation.viewmodels.security.BiometricViewModel
import com.owncloud.android.presentation.viewmodels.security.PassCodeViewModel
import com.owncloud.android.presentation.viewmodels.security.PatternViewModel
import com.owncloud.android.presentation.viewmodels.settings.SettingsLogsViewModel
Expand Down Expand Up @@ -61,4 +62,5 @@ val viewModelModule = module {
viewModel { RemoveAccountDialogViewModel(get(), get(), get(), get()) }
viewModel { PassCodeViewModel(get()) }
viewModel { PatternViewModel(get()) }
viewModel { BiometricViewModel(get()) }
}
Loading

0 comments on commit a2c0f2b

Please sign in to comment.