[PM-28352] Add logging to Credential Manager and Origin Manager flows (#6229)

This commit is contained in:
Patrick Honkonen 2025-12-04 13:22:45 -05:00 committed by GitHub
parent 4905358adb
commit 593bfbf8cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 4 deletions

View File

@ -49,6 +49,7 @@ class OriginManagerImpl(
)
.fold(
onSuccess = {
Timber.d("Digital asset link validation result: linked = ${it.linked}")
if (it.linked) {
ValidateOriginResult.Success(null)
} else {
@ -56,6 +57,7 @@ class OriginManagerImpl(
}
},
onFailure = {
Timber.e("Failed to validate origin for calling app")
ValidateOriginResult.Error.AssetLinkNotFound
},
)
@ -105,7 +107,7 @@ class OriginManagerImpl(
.fold(
onSuccess = { it },
onFailure = {
Timber.e(it, "Failed to validate privileged app: ${callingAppInfo.packageName}")
Timber.e(it, "Failed to validate calling app is privileged.")
ValidateOriginResult.Error.Unknown
},
)

View File

@ -37,6 +37,7 @@ import com.x8bit.bitwarden.data.credentials.model.GetCredentialsRequest
import com.x8bit.bitwarden.data.platform.manager.BiometricsEncryptionManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import timber.log.Timber
import java.time.Clock
import javax.crypto.Cipher
@ -63,8 +64,10 @@ class CredentialProviderProcessorImpl(
cancellationSignal: CancellationSignal,
callback: OutcomeReceiver<BeginCreateCredentialResponse, CreateCredentialException>,
) {
Timber.d("Create credential request received.")
val userId = authRepository.activeUserId
if (userId == null) {
Timber.w("No active user. Cannot create credential.")
callback.onError(CreateCredentialUnknownException("Active user is required."))
return
}
@ -72,12 +75,16 @@ class CredentialProviderProcessorImpl(
val createCredentialJob = ioScope.launch {
(handleCreatePasskeyQuery(request) ?: handleCreatePasswordQuery(request))
?.let { callback.onResult(it) }
?: callback.onError(CreateCredentialUnknownException())
?: run {
Timber.w("Unknown create credential request.")
callback.onError(CreateCredentialUnknownException())
}
}
cancellationSignal.setOnCancelListener {
if (createCredentialJob.isActive) {
createCredentialJob.cancel()
}
Timber.d("Create credential request cancelled by system.")
callback.onError(CreateCredentialCancellationException())
}
}
@ -87,15 +94,18 @@ class CredentialProviderProcessorImpl(
cancellationSignal: CancellationSignal,
callback: OutcomeReceiver<BeginGetCredentialResponse, GetCredentialException>,
) {
Timber.d("Get credential request received.")
// If the user is not logged in, return an error.
val userState = authRepository.userStateFlow.value
if (userState == null) {
Timber.w("No active user. Cannot get credentials.")
callback.onError(GetCredentialUnknownException("Active user is required."))
return
}
// Return an unlock action if the current account is locked.
if (!userState.activeAccount.isVaultUnlocked) {
Timber.d("Vault is locked. Requesting unlock.")
val authenticationAction = AuthenticationAction(
title = context.getString(BitwardenString.unlock),
pendingIntent = pendingIntentManager.createFido2UnlockPendingIntent(
@ -120,10 +130,17 @@ class CredentialProviderProcessorImpl(
BeginGetCredentialRequest.asBundle(request),
),
)
.onSuccess { callback.onResult(BeginGetCredentialResponse(credentialEntries = it)) }
.onFailure { callback.onError(GetCredentialUnknownException(it.message)) }
.onSuccess {
Timber.d("Credentials retrieved.")
callback.onResult(BeginGetCredentialResponse(credentialEntries = it))
}
.onFailure {
Timber.w("Error getting credentials.")
callback.onError(GetCredentialUnknownException(it.message))
}
}
cancellationSignal.setOnCancelListener {
Timber.d("Get credential request cancelled by system.")
callback.onError(GetCredentialCancellationException())
getCredentialJob.cancel()
}
@ -135,6 +152,7 @@ class CredentialProviderProcessorImpl(
callback: OutcomeReceiver<Void?, ClearCredentialException>,
) {
// no-op: RFU
Timber.w("Unsupported clear credential state request received.")
callback.onError(ClearCredentialUnsupportedException())
}