-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/candidate' into fix/app_lock_dialog_blinking
- Loading branch information
Showing
12 changed files
with
274 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/src/main/kotlin/com/wire/android/feature/AppLockSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android.feature | ||
|
||
sealed interface AppLockSource { | ||
val code: Int | ||
get() = when (this) { | ||
is Manual -> 0 | ||
is TeamEnforced -> 1 | ||
} | ||
data object Manual : AppLockSource | ||
data object TeamEnforced : AppLockSource | ||
|
||
companion object { | ||
fun fromInt(value: Int): AppLockSource { | ||
return when (value) { | ||
0 -> Manual | ||
1 -> TeamEnforced | ||
else -> throw IllegalArgumentException("Unknown AppLockSource value: $value") | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
app/src/main/kotlin/com/wire/android/feature/DisableAppLockUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android.feature | ||
|
||
import com.wire.android.datastore.GlobalDataStore | ||
import com.wire.kalium.logic.feature.featureConfig.IsAppLockEditableUseCase | ||
import dagger.hilt.android.scopes.ViewModelScoped | ||
import javax.inject.Inject | ||
|
||
@ViewModelScoped | ||
class DisableAppLockUseCase @Inject constructor( | ||
private val dataStore: GlobalDataStore, | ||
private val isAppLockEditableUseCase: IsAppLockEditableUseCase | ||
) { | ||
suspend operator fun invoke(): Boolean = if (isAppLockEditableUseCase()) { | ||
dataStore.clearAppLockPasscode() | ||
true | ||
} else { | ||
false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
app/src/test/kotlin/com/wire/android/feature/DisableAppLockUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android.feature | ||
|
||
import com.wire.android.datastore.GlobalDataStore | ||
import com.wire.kalium.logic.feature.featureConfig.IsAppLockEditableUseCase | ||
import io.mockk.MockKAnnotations | ||
import io.mockk.coEvery | ||
import io.mockk.coVerify | ||
import io.mockk.impl.annotations.MockK | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.jupiter.api.Test | ||
|
||
class DisableAppLockUseCaseTest { | ||
|
||
@Test | ||
fun `given app lock is editable when disable app lock is called then clear app lock passcode`() = runTest { | ||
val (arrangement, useCase) = Arrangement() | ||
.withAppLockEditable(true) | ||
.withClearAppLockPasscode() | ||
.arrange() | ||
|
||
useCase() | ||
|
||
coVerify(exactly = 1) { arrangement.dataStore.clearAppLockPasscode() } | ||
} | ||
|
||
@Test | ||
fun `given app lock is not editable when disable app lock is called then do not clear app lock passcode`() = runTest { | ||
val (arrangement, useCase) = Arrangement() | ||
.withAppLockEditable(false) | ||
.arrange() | ||
|
||
useCase() | ||
|
||
coVerify(exactly = 0) { arrangement.dataStore.clearAppLockPasscode() } | ||
} | ||
private class Arrangement { | ||
|
||
init { | ||
MockKAnnotations.init(this, relaxUnitFun = true) | ||
} | ||
|
||
@MockK | ||
lateinit var dataStore: GlobalDataStore | ||
|
||
@MockK | ||
lateinit var isAppLockEditableUseCase: IsAppLockEditableUseCase | ||
|
||
private val useCase = DisableAppLockUseCase( | ||
dataStore, | ||
isAppLockEditableUseCase | ||
) | ||
|
||
fun withAppLockEditable(result: Boolean) = apply { | ||
coEvery { isAppLockEditableUseCase() } returns result | ||
} | ||
|
||
fun withClearAppLockPasscode() = apply { | ||
coEvery { dataStore.clearAppLockPasscode() } returns Unit | ||
} | ||
|
||
fun arrange() = Pair(this, useCase) | ||
} | ||
} |
Oops, something went wrong.