Skip to content

Commit 02cde31

Browse files
committed
Fix compile errors, version check logic, & minor formatting tweaks
- BitwardenCredentialManagerImpl.kt: formatting. - CredentialEntryBuilderExtensions.kt: fix compile error. - CredentialEntryBuilderImpl.kt: use generic login icon for password credntial entry icon to match autofill items and better distinguish from passkeys. - CredentialProviderIntentUtils.kt: invert build version check. - provider.xml: Add public key credential capability so debug builds still handle passkeys. - VaultItemListingViewModel.kt: formatting.
1 parent c27639c commit 02cde31

File tree

8 files changed

+47
-53
lines changed

8 files changed

+47
-53
lines changed

app/src/debug/res/xml/provider.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<credential-provider>
33
<capabilities>
44
<capability name="android.credentials.TYPE_PASSWORD_CREDENTIAL" />
5+
<capability name="androidx.credentials.TYPE_PUBLIC_KEY_CREDENTIAL" />
56
</capabilities>
67
</credential-provider>

app/src/main/kotlin/com/x8bit/bitwarden/data/credentials/builder/CredentialEntryBuilderImpl.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,7 @@ class CredentialEntryBuilderImpl(
122122
)
123123
.setDisplayName(cipherView.name)
124124
.setAutoSelectAllowed(this.size == 1)
125-
.setIcon(
126-
getCredentialEntryIcon(
127-
isPassword = true,
128-
),
129-
)
125+
.setIcon(getCredentialEntryIcon())
130126
.also { builder ->
131127
if (!isUserVerified) {
132128
builder.setBiometricPromptDataIfSupported(
@@ -143,13 +139,11 @@ class CredentialEntryBuilderImpl(
143139
// are addressed. See https://issuetracker.google.com/issues/355141766 for details.
144140
private fun getCredentialEntryIcon(
145141
isPasskey: Boolean = false,
146-
isPassword: Boolean = false,
147142
): Icon = IconCompat
148143
.createWithResource(
149144
context,
150145
when {
151146
isPasskey -> BitwardenDrawable.ic_bw_passkey
152-
isPassword -> BitwardenDrawable.ic_key
153147
else -> BitwardenDrawable.ic_globe
154148
},
155149
)

app/src/main/kotlin/com/x8bit/bitwarden/data/credentials/manager/BitwardenCredentialManagerImpl.kt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,20 @@ class BitwardenCredentialManagerImpl(
186186
}
187187
}
188188
.filter { it.isActiveWithFido2Credentials || it.isActiveWithPasswordCredentials }
189-
.ifEmpty {
190-
return@withContext emptyList<CredentialEntry>().asSuccess()
191-
}
189+
.ifEmpty { return@withContext emptyList<CredentialEntry>().asSuccess() }
192190

193-
val passwordCredentialResult =
194-
getCredentialsRequest.callingAppInfo?.packageName?.let { packageName ->
191+
val passwordCredentialResult = getCredentialsRequest
192+
.callingAppInfo
193+
?.packageName
194+
?.let { packageName ->
195195
getCredentialsRequest
196196
.beginGetPasswordOptions
197197
.toPasswordCredentialEntries(
198198
userId = getCredentialsRequest.userId,
199199
packageName = packageName,
200200
)
201-
} ?: emptyList()
201+
}
202+
?: emptyList()
202203

203204
val passkeyCredentialResult = getCredentialsRequest
204205
.beginGetPublicKeyCredentialOptions
@@ -351,11 +352,9 @@ class BitwardenCredentialManagerImpl(
351352
): List<CredentialEntry> {
352353
if (this.isEmpty()) return emptyList()
353354

354-
val ciphers = autofillCipherProvider.getLoginAutofillCiphers(
355-
packageName.toAndroidAppUriString(),
356-
).filter {
357-
it.password.isNotEmpty()
358-
}
355+
val ciphers = autofillCipherProvider
356+
.getLoginAutofillCiphers(packageName.toAndroidAppUriString())
357+
.filter { it.password.isNotEmpty() }
359358

360359
return credentialEntryBuilder
361360
.buildPasswordCredentialEntries(

app/src/main/kotlin/com/x8bit/bitwarden/data/credentials/util/CredentialEntryBuilderExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fun PublicKeyCredentialEntry.Builder.setBiometricPromptDataIfSupported(
3333
fun PasswordCredentialEntry.Builder.setBiometricPromptDataIfSupported(
3434
cipher: Cipher?,
3535
): PasswordCredentialEntry.Builder =
36-
if (!isBuildVersionBelow(Build.VERSION_CODES.VANILLA_ICE_CREAM) && cipher != null) {
36+
if (isBuildVersionAtLeast(Build.VERSION_CODES.VANILLA_ICE_CREAM) && cipher != null) {
3737
setBiometricPromptData(
3838
biometricPromptData = buildPromptDataWithCipher(cipher),
3939
)

app/src/main/kotlin/com/x8bit/bitwarden/data/credentials/util/CredentialProviderIntentUtils.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import com.x8bit.bitwarden.data.credentials.model.CreateCredentialRequest
1212
import com.x8bit.bitwarden.data.credentials.model.Fido2CredentialAssertionRequest
1313
import com.x8bit.bitwarden.data.credentials.model.GetCredentialsRequest
1414
import com.x8bit.bitwarden.data.credentials.model.ProviderGetPasswordCredentialRequest
15-
import com.x8bit.bitwarden.data.platform.util.isBuildVersionBelow
1615
import com.x8bit.bitwarden.ui.platform.manager.intent.EXTRA_KEY_CIPHER_ID
1716
import com.x8bit.bitwarden.ui.platform.manager.intent.EXTRA_KEY_CREDENTIAL_ID
1817
import com.x8bit.bitwarden.ui.platform.manager.intent.EXTRA_KEY_USER_ID
@@ -86,7 +85,7 @@ fun Intent.getFido2AssertionRequestOrNull(): Fido2CredentialAssertionRequest? {
8685
* ongoing password credential GetPassword process.
8786
*/
8887
fun Intent.getProviderGetPasswordRequestOrNull(): ProviderGetPasswordCredentialRequest? {
89-
if (isBuildVersionBelow(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)) return null
88+
if (!isBuildVersionAtLeast(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)) return null
9089

9190
val systemRequest = PendingIntentHandler
9291
.retrieveProviderGetCredentialRequest(this)

app/src/main/kotlin/com/x8bit/bitwarden/ui/vault/feature/itemlisting/VaultItemListingViewModel.kt

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,8 @@ class VaultItemListingViewModel @Inject constructor(
16911691
sendEvent(
16921692
VaultItemListingEvent.CompleteProviderGetPasswordCredentialRequest(
16931693
result = GetPasswordCredentialResult.Success(
1694-
credential = getCipherViewOrNull(cipherId = data.cipherId)?.login
1694+
credential = getCipherViewOrNull(cipherId = data.cipherId)
1695+
?.login
16951696
?: return,
16961697
),
16971698
),
@@ -2161,24 +2162,24 @@ class VaultItemListingViewModel @Inject constructor(
21612162
}
21622163
}
21632164

2164-
data.firstOrNull { it.id == action.data.cipherId }?.let { cipher ->
2165-
if (state.hasMasterPassword &&
2166-
cipher.reprompt == CipherRepromptType.PASSWORD
2167-
) {
2168-
repromptMasterPasswordForProviderGetCredential(action.data.cipherId)
2169-
} else {
2170-
val result = cipher.login?.let {
2171-
GetPasswordCredentialResult.Success(it)
2172-
} ?: GetPasswordCredentialResult.Error(
2173-
R.string.password_operation_failed_because_the_selected_item_does_not_exist
2174-
.asText(),
2175-
)
2176-
2177-
sendEvent(
2178-
VaultItemListingEvent.CompleteProviderGetPasswordCredentialRequest(result),
2179-
)
2165+
data
2166+
.firstOrNull { it.id == action.data.cipherId }
2167+
?.let { cipher ->
2168+
if (state.hasMasterPassword && cipher.reprompt == CipherRepromptType.PASSWORD) {
2169+
repromptMasterPasswordForProviderGetCredential(action.data.cipherId)
2170+
} else {
2171+
val result = cipher.login
2172+
?.let { GetPasswordCredentialResult.Success(it) }
2173+
?: GetPasswordCredentialResult.Error(
2174+
message = R.string
2175+
.password_operation_failed_because_the_selected_item_does_not_exist
2176+
.asText(),
2177+
)
2178+
sendEvent(
2179+
VaultItemListingEvent.CompleteProviderGetPasswordCredentialRequest(result),
2180+
)
2181+
}
21802182
}
2181-
}
21822183
?: run {
21832184
showCredentialManagerErrorDialog(
21842185
R.string.password_operation_failed_because_no_item_was_selected.asText(),
@@ -2250,19 +2251,19 @@ class VaultItemListingViewModel @Inject constructor(
22502251
bitwardenCredentialManager.isUserVerified = false
22512252
clearDialogState()
22522253

2253-
val event = selectedCipher.login?.let { credential ->
2254-
VaultItemListingEvent.CompleteProviderGetPasswordCredentialRequest(
2255-
GetPasswordCredentialResult.Success(
2256-
credential = credential,
2254+
val event = selectedCipher.login
2255+
?.let { credential ->
2256+
VaultItemListingEvent.CompleteProviderGetPasswordCredentialRequest(
2257+
GetPasswordCredentialResult.Success(credential = credential),
2258+
)
2259+
}
2260+
?: VaultItemListingEvent.CompleteProviderGetPasswordCredentialRequest(
2261+
GetPasswordCredentialResult.Error(
2262+
message = R.string
2263+
.password_operation_failed_because_the_selected_item_does_not_exist
2264+
.asText(),
22572265
),
22582266
)
2259-
} ?: VaultItemListingEvent.CompleteProviderGetPasswordCredentialRequest(
2260-
GetPasswordCredentialResult.Error(
2261-
message =
2262-
R.string.password_operation_failed_because_the_selected_item_does_not_exist
2263-
.asText(),
2264-
),
2265-
)
22662267

22672268
sendEvent(event)
22682269
}

app/src/test/kotlin/com/x8bit/bitwarden/data/credentials/builder/CredentialEntryBuilderTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ class CredentialEntryBuilderTest {
334334

335335
@Test
336336
fun `buildPasswordCredentialEntries should set biometric prompt data correctly`() = runTest {
337-
mockkStatic(::isBuildVersionBelow)
337+
mockkStatic(::isBuildVersionAtLeast)
338338
val options = listOf(mockBeginGetPasswordOption)
339339
val passwordAutofillViews: List<AutofillCipher.Login> = listOf(
340340
createMockPasswordCredentialAutofillCipherLogin(),
@@ -343,7 +343,7 @@ class CredentialEntryBuilderTest {
343343
every {
344344
mockBiometricsEncryptionManager.getOrCreateCipher(any())
345345
} returns mockk(relaxed = true)
346-
every { isBuildVersionBelow(any()) } returns false
346+
every { isBuildVersionAtLeast(any()) } returns true
347347

348348
// Verify biometric prompt data is set when buildVersion is >= 35, cipher is
349349
// not null, and user is not verified

app/src/test/kotlin/com/x8bit/bitwarden/data/credentials/util/CredentialManagerIntentUtilsTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ class CredentialManagerIntentUtilsTest {
339339
fun `getProviderGetPasswordRequestOrNull should return null when build version is below 34`() {
340340
val intent = mockk<Intent>()
341341

342-
every { isBuildVersionBelow(34) } returns true
342+
every { isBuildVersionAtLeast(34) } returns false
343343

344344
val assertionRequest = intent.getProviderGetPasswordRequestOrNull()
345345

0 commit comments

Comments
 (0)