diff options
author | 2024-05-22 23:04:53 +0000 | |
---|---|---|
committer | 2024-05-31 08:51:50 +0000 | |
commit | 66b370ef5940bf32f364e5391ef08a2e63a70cf6 (patch) | |
tree | 258edf7eecc64c3b64bd9c79ee06e2be788577f3 | |
parent | 6978db2e5378ccc6218202d9209ade7c000998c8 (diff) |
Align with Jetpack Changes (toBundle/FW Flag)
Recently, we added a change to Jetpack to bundle BPData properties
within a bundle, rather than directly imbue it into the slice.
This requires us to re-structure our slice parsing, to:
1. Read the bundle from the slice.
2. Parse the bundle after reading from the slice.
Along this change, we also need to know, for a whole many use cases,
when the framework prompt was the originator for the codes of the BP.
This is also a Jetpack decision, so a small bit was added so it can be
utilized in JP.
Bug: 339650358
Test: Build and device tests
Change-Id: I6c3392fb96e6d5409310ba4b840f229444942803
7 files changed, 35 insertions, 26 deletions
diff --git a/packages/CredentialManager/shared/src/com/android/credentialmanager/ktx/CredentialKtx.kt b/packages/CredentialManager/shared/src/com/android/credentialmanager/ktx/CredentialKtx.kt index 9c8ec3b56813..3022fa01cd8d 100644 --- a/packages/CredentialManager/shared/src/com/android/credentialmanager/ktx/CredentialKtx.kt +++ b/packages/CredentialManager/shared/src/com/android/credentialmanager/ktx/CredentialKtx.kt @@ -27,6 +27,7 @@ import android.credentials.selection.AuthenticationEntry import android.credentials.selection.Entry import android.credentials.selection.GetCredentialProviderData import android.graphics.drawable.Drawable +import android.os.Bundle import android.text.TextUtils import android.util.Log import androidx.activity.result.IntentSenderRequest @@ -227,26 +228,31 @@ private fun getCredentialOptionInfoList( * and get flows utilize slice params; includes the final '.' before the name of the type (e.g. * androidx.credentials.provider.credentialEntry.SLICE_HINT_ALLOWED_AUTHENTICATORS must have * 'hintPrefix' up to "androidx.credentials.provider.credentialEntry.") - * // TODO(b/326243754) : Presently, due to dependencies, the opId bit is parsed but is never - * // expected to be used. When it is added, it should be lightly validated. */ fun retrieveEntryBiometricRequest( entry: Entry, - hintPrefix: String, + hintPrefix: String ): BiometricRequestInfo? { - // TODO(b/326243754) : When available, use the official jetpack structured type - val allowedAuthenticators: Int? = entry.slice.items.firstOrNull { - it.hasHint(hintPrefix + "SLICE_HINT_ALLOWED_AUTHENTICATORS") - }?.int + // TODO(b/326243754) : When available, use the official jetpack structured typLo + val biometricPromptDataBundleKey = "SLICE_HINT_BIOMETRIC_PROMPT_DATA" + val biometricPromptDataBundle: Bundle = entry.slice.items.firstOrNull { + it.hasHint(hintPrefix + biometricPromptDataBundleKey) + }?.bundle ?: return null - // This is optional and does not affect validating the biometric flow in any case - val opId: Int? = entry.slice.items.firstOrNull { - it.hasHint(hintPrefix + "SLICE_HINT_CRYPTO_OP_ID") - }?.int - if (allowedAuthenticators != null) { - return BiometricRequestInfo(opId = opId, allowedAuthenticators = allowedAuthenticators) + val allowedAuthConstantKey = "androidx.credentials.provider.BUNDLE_HINT_ALLOWED_AUTHENTICATORS" + val cryptoOpIdKey = "androidx.credentials.provider.BUNDLE_HINT_CRYPTO_OP_ID" + + if (!biometricPromptDataBundle.containsKey(allowedAuthConstantKey)) { + return null } - return null + + val allowedAuthenticators: Int = biometricPromptDataBundle.getInt(allowedAuthConstantKey) + + // This is optional and does not affect validating the biometric flow in any case + val opId: Long? = if (biometricPromptDataBundle.containsKey(cryptoOpIdKey)) + biometricPromptDataBundle.getLong(cryptoOpIdKey) else null + + return BiometricRequestInfo(opId = opId, allowedAuthenticators = allowedAuthenticators) } val Slice.credentialEntry: CredentialEntry? diff --git a/packages/CredentialManager/shared/src/com/android/credentialmanager/model/BiometricRequestInfo.kt b/packages/CredentialManager/shared/src/com/android/credentialmanager/model/BiometricRequestInfo.kt index 486cfe7123dd..fe4beadfa9ec 100644 --- a/packages/CredentialManager/shared/src/com/android/credentialmanager/model/BiometricRequestInfo.kt +++ b/packages/CredentialManager/shared/src/com/android/credentialmanager/model/BiometricRequestInfo.kt @@ -23,6 +23,6 @@ package com.android.credentialmanager.model * null. */ data class BiometricRequestInfo( - val opId: Int? = null, + val opId: Long? = null, val allowedAuthenticators: Int )
\ No newline at end of file diff --git a/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorViewModel.kt b/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorViewModel.kt index 7bc25ed81089..894d5ef24ebd 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorViewModel.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorViewModel.kt @@ -135,16 +135,18 @@ class CredentialSelectorViewModel( Log.w(Constants.LOG_TAG, "Unexpected biometric result exists when " + "autoSelect is preferred.") } - // TODO(b/333445754) : Decide whether to propagate info on prompt launch + // TODO(b/333445754) : Change the fm option to false in qpr after discussion if (biometricState.biometricResult != null) { entryIntent?.putExtra(Constants.BIOMETRIC_AUTH_RESULT, biometricState.biometricResult.biometricAuthenticationResult .authenticationType) + entryIntent?.putExtra(Constants.BIOMETRIC_FRAMEWORK_OPTION, true) } else if (biometricState.biometricError != null){ entryIntent?.putExtra(Constants.BIOMETRIC_AUTH_ERROR_CODE, biometricState.biometricError.errorCode) entryIntent?.putExtra(Constants.BIOMETRIC_AUTH_ERROR_MESSAGE, biometricState.biometricError.errorMessage) + entryIntent?.putExtra(Constants.BIOMETRIC_FRAMEWORK_OPTION, true) } } val intentSenderRequest = IntentSenderRequest.Builder(pendingIntent) diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/BiometricHandler.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/BiometricHandler.kt index 373b3e8b068d..c35721c11741 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/common/BiometricHandler.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/common/BiometricHandler.kt @@ -230,7 +230,7 @@ private fun runBiometricFlow( val cryptoOpId = getCryptoOpId(biometricDisplayInfo) if (cryptoOpId != null) { biometricPrompt.authenticate( - BiometricPrompt.CryptoObject(cryptoOpId.toLong()), + BiometricPrompt.CryptoObject(cryptoOpId), cancellationSignal, executor, callback) } else { biometricPrompt.authenticate(cancellationSignal, executor, callback) @@ -243,7 +243,7 @@ private fun runBiometricFlow( return true } -private fun getCryptoOpId(biometricDisplayInfo: BiometricDisplayInfo): Int? { +private fun getCryptoOpId(biometricDisplayInfo: BiometricDisplayInfo): Long? { return biometricDisplayInfo.biometricRequestInfo.opId } diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/Constants.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/Constants.kt index 3c80113134b1..cb089adf750e 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/common/Constants.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/common/Constants.kt @@ -22,9 +22,12 @@ class Constants { const val BUNDLE_KEY_PREFER_IMMEDIATELY_AVAILABLE_CREDENTIALS = "androidx.credentials.BUNDLE_KEY_IS_AUTO_SELECT_ALLOWED" const val IS_AUTO_SELECTED_KEY = "IS_AUTO_SELECTED" - // TODO(b/333445772) : Qualify error codes fully for propagation - const val BIOMETRIC_AUTH_RESULT = "BIOMETRIC_AUTH_RESULT" - const val BIOMETRIC_AUTH_ERROR_CODE = "BIOMETRIC_AUTH_ERROR_CODE" - const val BIOMETRIC_AUTH_ERROR_MESSAGE = "BIOMETRIC_AUTH_ERROR_MESSAGE" + const val BIOMETRIC_AUTH_RESULT = "androidx.credentials.provider.BIOMETRIC_AUTH_RESULT" + const val BIOMETRIC_AUTH_ERROR_CODE = + "androidx.credentials.provider.BIOMETRIC_AUTH_ERROR_CODE" + const val BIOMETRIC_AUTH_ERROR_MESSAGE = + "androidx.credentials.provider.BIOMETRIC_AUTH_ERROR_MESSAGE" + const val BIOMETRIC_FRAMEWORK_OPTION = + "androidx.credentials.provider.BIOMETRIC_FRAMEWORK_OPTION" } } diff --git a/packages/CredentialManager/src/com/android/credentialmanager/logging/CreateCredentialEvent.kt b/packages/CredentialManager/src/com/android/credentialmanager/logging/CreateCredentialEvent.kt index 39f2fcee6a0a..dac25fa165af 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/logging/CreateCredentialEvent.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/logging/CreateCredentialEvent.kt @@ -17,7 +17,6 @@ package com.android.credentialmanager.logging import com.android.internal.logging.UiEvent import com.android.internal.logging.UiEventLogger -import com.android.internal.logging.UiEventLogger.UiEventEnum.RESERVE_NEW_UI_EVENT_ID enum class CreateCredentialEvent(private val id: Int) : UiEventLogger.UiEventEnum { @@ -56,7 +55,7 @@ enum class CreateCredentialEvent(private val id: Int) : UiEventLogger.UiEventEnu CREDMAN_CREATE_CRED_MORE_ABOUT_PASSKEYS_INTRO(1328), @UiEvent(doc = "The single tap biometric flow is launched.") - CREDMAN_CREATE_CRED_BIOMETRIC_FLOW_LAUNCHED(RESERVE_NEW_UI_EVENT_ID); + CREDMAN_CREATE_CRED_BIOMETRIC_FLOW_LAUNCHED(1800); override fun getId(): Int { return this.id diff --git a/packages/CredentialManager/src/com/android/credentialmanager/logging/GetCredentialEvent.kt b/packages/CredentialManager/src/com/android/credentialmanager/logging/GetCredentialEvent.kt index 89fd72cdc8cc..8870f28b9fcc 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/logging/GetCredentialEvent.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/logging/GetCredentialEvent.kt @@ -17,7 +17,6 @@ package com.android.credentialmanager.logging import com.android.internal.logging.UiEvent import com.android.internal.logging.UiEventLogger -import com.android.internal.logging.UiEventLogger.UiEventEnum.RESERVE_NEW_UI_EVENT_ID enum class GetCredentialEvent(private val id: Int) : UiEventLogger.UiEventEnum { @@ -58,7 +57,7 @@ enum class GetCredentialEvent(private val id: Int) : UiEventLogger.UiEventEnum { CREDMAN_GET_CRED_ALL_SIGN_IN_OPTION_CARD(1342), @UiEvent(doc = "The single tap biometric flow is launched.") - CREDMAN_GET_CRED_BIOMETRIC_FLOW_LAUNCHED(RESERVE_NEW_UI_EVENT_ID); + CREDMAN_GET_CRED_BIOMETRIC_FLOW_LAUNCHED(1801); override fun getId(): Int { return this.id |