mirror of
https://github.com/bitwarden/android.git
synced 2024-11-27 03:49:36 +03:00
Adding screen capture allow key to settings disk source (#780)
This commit is contained in:
parent
2f2f5703a7
commit
cd020f2af9
4 changed files with 92 additions and 2 deletions
|
@ -171,4 +171,14 @@ interface SettingsDiskSource {
|
|||
userId: String,
|
||||
isApprovePasswordlessLoginsEnabled: Boolean?,
|
||||
)
|
||||
|
||||
/**
|
||||
* Gets whether or not the given [userId] has enabled screen capture.
|
||||
*/
|
||||
fun getScreenCaptureAllowed(userId: String): Boolean?
|
||||
|
||||
/**
|
||||
* Stores whether or not [isScreenCaptureAllowed] for the given [userId].
|
||||
*/
|
||||
fun storeScreenCaptureAllowed(userId: String, isScreenCaptureAllowed: Boolean?)
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ private const val DEFAULT_URI_MATCH_TYPE_KEY = "$BASE_KEY:defaultUriMatch"
|
|||
private const val DISABLE_AUTOFILL_SAVE_PROMPT_KEY = "$BASE_KEY:autofillDisableSavePrompt"
|
||||
private const val DISABLE_ICON_LOADING_KEY = "$BASE_KEY:disableFavicon"
|
||||
private const val APPROVE_PASSWORDLESS_LOGINS_KEY = "$BASE_KEY:approvePasswordlessLogins"
|
||||
private const val SCREEN_CAPTURE_ALLOW_KEY = "$BASE_KEY:screenCaptureAllowed"
|
||||
|
||||
/**
|
||||
* Primary implementation of [SettingsDiskSource].
|
||||
|
@ -107,6 +108,7 @@ class SettingsDiskSourceImpl(
|
|||
isApprovePasswordlessLoginsEnabled = null,
|
||||
)
|
||||
storeLastSyncTime(userId = userId, lastSyncTime = null)
|
||||
storeScreenCaptureAllowed(userId = userId, isScreenCaptureAllowed = null)
|
||||
}
|
||||
|
||||
override fun getLastSyncTime(userId: String): Instant? =
|
||||
|
@ -271,4 +273,18 @@ class SettingsDiskSourceImpl(
|
|||
value = isApprovePasswordlessLoginsEnabled,
|
||||
)
|
||||
}
|
||||
|
||||
override fun getScreenCaptureAllowed(userId: String): Boolean? {
|
||||
return getBoolean(key = "${SCREEN_CAPTURE_ALLOW_KEY}_$userId")
|
||||
}
|
||||
|
||||
override fun storeScreenCaptureAllowed(
|
||||
userId: String,
|
||||
isScreenCaptureAllowed: Boolean?,
|
||||
) {
|
||||
putBoolean(
|
||||
key = "${SCREEN_CAPTURE_ALLOW_KEY}_$userId",
|
||||
value = isScreenCaptureAllowed,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,6 +104,10 @@ class SettingsDiskSourceTest {
|
|||
userId = userId,
|
||||
lastSyncTime = Instant.parse("2023-10-27T12:00:00Z"),
|
||||
)
|
||||
settingsDiskSource.storeScreenCaptureAllowed(
|
||||
userId = userId,
|
||||
isScreenCaptureAllowed = true,
|
||||
)
|
||||
|
||||
settingsDiskSource.clearData(userId = userId)
|
||||
|
||||
|
@ -116,6 +120,7 @@ class SettingsDiskSourceTest {
|
|||
assertNull(settingsDiskSource.getBlockedAutofillUris(userId = userId))
|
||||
assertNull(settingsDiskSource.getApprovePasswordlessLoginsEnabled(userId = userId))
|
||||
assertNull(settingsDiskSource.getLastSyncTime(userId = userId))
|
||||
assertNull(settingsDiskSource.getScreenCaptureAllowed(userId = userId))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -717,4 +722,53 @@ class SettingsDiskSourceTest {
|
|||
)
|
||||
assertFalse(fakeSharedPreferences.contains(approvePasswordlessLoginsKey))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getScreenCaptureAllowed should pull from SharedPreferences`() {
|
||||
val screenCaptureAllowBaseKey = "bwPreferencesStorage:screenCaptureAllowed"
|
||||
val mockUserId = "mockUserId"
|
||||
val isScreenCaptureAllowed = true
|
||||
fakeSharedPreferences.edit {
|
||||
putBoolean("${screenCaptureAllowBaseKey}_$mockUserId", isScreenCaptureAllowed)
|
||||
}
|
||||
val actual = settingsDiskSource.getScreenCaptureAllowed(userId = mockUserId)
|
||||
assertEquals(
|
||||
isScreenCaptureAllowed,
|
||||
actual,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `storeScreenCaptureAllowed for non-null values should update SharedPreferences`() {
|
||||
val screenCaptureAllowBaseKey = "bwPreferencesStorage:screenCaptureAllowed"
|
||||
val mockUserId = "mockUserId"
|
||||
val isScreenCaptureAllowed = true
|
||||
settingsDiskSource.storeScreenCaptureAllowed(
|
||||
userId = mockUserId,
|
||||
isScreenCaptureAllowed = isScreenCaptureAllowed,
|
||||
)
|
||||
val actual = fakeSharedPreferences.getBoolean(
|
||||
"${screenCaptureAllowBaseKey}_$mockUserId",
|
||||
false,
|
||||
)
|
||||
assertEquals(
|
||||
isScreenCaptureAllowed,
|
||||
actual,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `storeScreenCaptureAllowed for null values should clear SharedPreferences`() {
|
||||
val screenCaptureAllowBaseKey = "bwPreferencesStorage:screenCaptureAllowed"
|
||||
val mockUserId = "mockUserId"
|
||||
val screenCaptureAllowKey = "${screenCaptureAllowBaseKey}_$mockUserId"
|
||||
fakeSharedPreferences.edit {
|
||||
putBoolean(screenCaptureAllowKey, true)
|
||||
}
|
||||
settingsDiskSource.storeScreenCaptureAllowed(
|
||||
userId = mockUserId,
|
||||
isScreenCaptureAllowed = null,
|
||||
)
|
||||
assertFalse(fakeSharedPreferences.contains(screenCaptureAllowKey))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,10 +42,9 @@ class FakeSettingsDiskSource : SettingsDiskSource {
|
|||
private val storedPullToRefreshEnabled = mutableMapOf<String, Boolean?>()
|
||||
private val storedInlineAutofillEnabled = mutableMapOf<String, Boolean?>()
|
||||
private val storedBlockedAutofillUris = mutableMapOf<String, List<String>?>()
|
||||
|
||||
private var storedIsIconLoadingDisabled: Boolean? = null
|
||||
|
||||
private val storedApprovePasswordLoginsEnabled = mutableMapOf<String, Boolean?>()
|
||||
private val storedScreenCaptureAllowed = mutableMapOf<String, Boolean?>()
|
||||
|
||||
override var appLanguage: AppLanguage? = null
|
||||
|
||||
|
@ -81,6 +80,7 @@ class FakeSettingsDiskSource : SettingsDiskSource {
|
|||
storedPullToRefreshEnabled.remove(userId)
|
||||
storedInlineAutofillEnabled.remove(userId)
|
||||
storedBlockedAutofillUris.remove(userId)
|
||||
storedScreenCaptureAllowed.remove(userId)
|
||||
|
||||
mutableVaultTimeoutActionsFlowMap.remove(userId)
|
||||
mutableVaultTimeoutInMinutesFlowMap.remove(userId)
|
||||
|
@ -190,6 +190,16 @@ class FakeSettingsDiskSource : SettingsDiskSource {
|
|||
storedApprovePasswordLoginsEnabled[userId] = isApprovePasswordlessLoginsEnabled
|
||||
}
|
||||
|
||||
override fun getScreenCaptureAllowed(userId: String): Boolean? =
|
||||
storedScreenCaptureAllowed[userId]
|
||||
|
||||
override fun storeScreenCaptureAllowed(
|
||||
userId: String,
|
||||
isScreenCaptureAllowed: Boolean?,
|
||||
) {
|
||||
storedScreenCaptureAllowed[userId] = isScreenCaptureAllowed
|
||||
}
|
||||
|
||||
//region Private helper functions
|
||||
|
||||
private fun getMutableLastSyncTimeFlow(
|
||||
|
|
Loading…
Reference in a new issue