From 7e7038e1cd4921b53dcd9bb1b90e1f2f67407061 Mon Sep 17 00:00:00 2001 From: Helen Qin Date: Wed, 22 Mar 2023 23:35:51 +0000 Subject: [PATCH] [CredManUi] Display provider info for single entry sign-in. Per partner request, display the provider icon + name for the sign-in flows that only has one provider. Bug: 273772959 Test: manual (see screenshots in bug) Change-Id: I41e41b0507b0a274896cf0c13218409c8f878ff2 --- .../getflow/GetCredentialComponents.kt | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt index 56324581c0200..c27ac943bca7a 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt @@ -59,6 +59,8 @@ import com.android.credentialmanager.common.ui.SheetContainerCard import com.android.credentialmanager.common.ui.SnackbarActionText import com.android.credentialmanager.common.ui.HeadlineText import com.android.credentialmanager.common.ui.CredentialListSectionHeader +import com.android.credentialmanager.common.ui.HeadlineIcon +import com.android.credentialmanager.common.ui.LargeLabelTextOnSurfaceVariant import com.android.credentialmanager.common.ui.Snackbar import com.android.credentialmanager.common.ui.setTransparentSystemBarsColor import com.android.credentialmanager.common.ui.setBottomSheetSystemBarsColor @@ -167,22 +169,42 @@ fun PrimarySelectionCard( providerDisplayInfo.sortedUserNameToCredentialEntryList val authenticationEntryList = providerDisplayInfo.authenticationEntryList SheetContainerCard { + // When only one provider (not counting the remote-only provider) exists, display that + // provider's icon + name up top. + if (providerInfoList.size <= 2) { // It's only possible to be the single provider case + // if we are started with no more than 2 providers. + val nonRemoteProviderList = providerInfoList.filter( + { it.credentialEntryList.isNotEmpty() || it.authenticationEntryList.isNotEmpty() } + ) + if (nonRemoteProviderList.size == 1) { + val providerInfo = nonRemoteProviderList.firstOrNull() // First should always work + // but just to be safe. + if (providerInfo != null) { + item { + HeadlineIcon( + bitmap = providerInfo.icon.toBitmap().asImageBitmap(), + tint = Color.Unspecified, + ) + } + item { Divider(thickness = 4.dp, color = Color.Transparent) } + item { LargeLabelTextOnSurfaceVariant(text = providerInfo.displayName) } + item { Divider(thickness = 16.dp, color = Color.Transparent) } + } + } + } + + val hasSingleEntry = (sortedUserNameToCredentialEntryList.size == 1 && + authenticationEntryList.isEmpty()) || (sortedUserNameToCredentialEntryList.isEmpty() && + authenticationEntryList.size == 1) item { HeadlineText( text = stringResource( - if (sortedUserNameToCredentialEntryList - .size == 1 && authenticationEntryList.isEmpty() - ) { - if (sortedUserNameToCredentialEntryList.first() - .sortedCredentialEntryList.first().credentialType + if (hasSingleEntry) { + if (sortedUserNameToCredentialEntryList.firstOrNull() + ?.sortedCredentialEntryList?.first()?.credentialType == CredentialType.PASSKEY ) R.string.get_dialog_title_use_passkey_for else R.string.get_dialog_title_use_sign_in_for - } else if ( - sortedUserNameToCredentialEntryList - .isEmpty() && authenticationEntryList.size == 1 - ) { - R.string.get_dialog_title_use_sign_in_for } else R.string.get_dialog_title_choose_sign_in_for, requestDisplayInfo.appName ),