mirror of
https://github.com/bitwarden/android.git
synced 2024-11-26 11:26:09 +03:00
BIT-2022: Autofill crash (#1126)
This commit is contained in:
parent
3e680b9703
commit
b3e4d3807c
4 changed files with 19 additions and 14 deletions
|
@ -31,7 +31,7 @@ class FilledDataBuilderImpl(
|
|||
// Use getOrLastOrNull so if the list has run dry take the last spec.
|
||||
autofillRequest
|
||||
.inlinePresentationSpecs
|
||||
.getOrLastOrNull(inlineSuggestionsAdded)
|
||||
?.getOrLastOrNull(inlineSuggestionsAdded)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ class FilledDataBuilderImpl(
|
|||
// Use getOrLastOrNull so if the list has run dry take the last spec.
|
||||
val vaultItemInlinePresentationSpec = autofillRequest
|
||||
.inlinePresentationSpecs
|
||||
.getOrLastOrNull(inlineSuggestionsAdded)
|
||||
?.getOrLastOrNull(inlineSuggestionsAdded)
|
||||
|
||||
return FilledData(
|
||||
filledPartitions = filledPartitions,
|
||||
|
|
|
@ -13,7 +13,7 @@ sealed class AutofillRequest {
|
|||
*/
|
||||
data class Fillable(
|
||||
val ignoreAutofillIds: List<AutofillId>,
|
||||
val inlinePresentationSpecs: List<InlinePresentationSpec>,
|
||||
val inlinePresentationSpecs: List<InlinePresentationSpec>?,
|
||||
val maxInlineSuggestionsCount: Int,
|
||||
val packageName: String?,
|
||||
val partition: AutofillPartition,
|
||||
|
|
|
@ -13,12 +13,13 @@ import com.x8bit.bitwarden.data.autofill.model.AutofillAppInfo
|
|||
fun FillRequest?.getInlinePresentationSpecs(
|
||||
autofillAppInfo: AutofillAppInfo,
|
||||
isInlineAutofillEnabled: Boolean,
|
||||
): List<InlinePresentationSpec> =
|
||||
if (this != null &&
|
||||
isInlineAutofillEnabled &&
|
||||
autofillAppInfo.sdkInt >= Build.VERSION_CODES.R
|
||||
) {
|
||||
inlineSuggestionsRequest?.inlinePresentationSpecs ?: emptyList()
|
||||
): List<InlinePresentationSpec>? =
|
||||
if (autofillAppInfo.sdkInt < Build.VERSION_CODES.R) {
|
||||
// When SDK version is bellow 30, InlinePresentationSpec is not available and null
|
||||
// must be returned.
|
||||
null
|
||||
} else if (isInlineAutofillEnabled) {
|
||||
this?.inlineSuggestionsRequest?.inlinePresentationSpecs.orEmpty()
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.x8bit.bitwarden.data.autofill.model.AutofillAppInfo
|
|||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertNull
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class FillRequestExtensionsTest {
|
||||
|
@ -22,7 +23,9 @@ class FillRequestExtensionsTest {
|
|||
@Test
|
||||
fun `getInlinePresentationSpecs should return empty list when request is null`() {
|
||||
// Setup
|
||||
val autofillAppInfo: AutofillAppInfo = mockk()
|
||||
val autofillAppInfo: AutofillAppInfo = mockk {
|
||||
every { sdkInt } returns 30
|
||||
}
|
||||
val expected: List<InlinePresentationSpec> = emptyList()
|
||||
|
||||
// Test
|
||||
|
@ -38,7 +41,9 @@ class FillRequestExtensionsTest {
|
|||
@Test
|
||||
fun `getInlinePresentationSpecs should return empty list when disabled`() {
|
||||
// Setup
|
||||
val autofillAppInfo: AutofillAppInfo = mockk()
|
||||
val autofillAppInfo: AutofillAppInfo = mockk {
|
||||
every { sdkInt } returns 30
|
||||
}
|
||||
val expected: List<InlinePresentationSpec> = emptyList()
|
||||
|
||||
// Test
|
||||
|
@ -52,14 +57,13 @@ class FillRequestExtensionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `getInlinePresentationSpecs should return empty list when enabled pre-R`() {
|
||||
fun `getInlinePresentationSpecs should return null when enabled pre-R`() {
|
||||
// Setup
|
||||
val autofillAppInfo = AutofillAppInfo(
|
||||
context = mockk(),
|
||||
packageName = "com.x8bit.bitwarden",
|
||||
sdkInt = 17,
|
||||
)
|
||||
val expected: List<InlinePresentationSpec> = emptyList()
|
||||
|
||||
// Test
|
||||
val actual = fillRequest.getInlinePresentationSpecs(
|
||||
|
@ -68,7 +72,7 @@ class FillRequestExtensionsTest {
|
|||
)
|
||||
|
||||
// Verify
|
||||
assertEquals(expected, actual)
|
||||
assertNull(actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue