diff options
author | 2024-03-20 21:23:22 +0000 | |
---|---|---|
committer | 2024-03-26 18:55:43 +0000 | |
commit | 2b5f3cdc09c30dc62f59c4eeddc20a0519d8dc1b (patch) | |
tree | f46763198a9ac3d93d502c3425505670d5a37d13 /packages/CredentialManager/src | |
parent | 60e05d601c6d38aa50776146bd92c4e1eef0a920 (diff) |
Handle unknown credential type in RemoteViewFactory
Bug: 330587182
Change-Id: Ieecd6192f99f83c1be8d7941fb5ca90ee68fd977
Diffstat (limited to 'packages/CredentialManager/src')
-rw-r--r-- | packages/CredentialManager/src/com/android/credentialmanager/common/ui/RemoteViewsFactory.kt | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/RemoteViewsFactory.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/RemoteViewsFactory.kt index 3fb915226963..7bb08d2c26e8 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/RemoteViewsFactory.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/RemoteViewsFactory.kt @@ -17,6 +17,8 @@ package com.android.credentialmanager.common.ui import android.content.Context +import android.util.Log +import com.android.credentialmanager.common.Constants import android.widget.RemoteViews import androidx.core.content.ContextCompat import com.android.credentialmanager.model.get.CredentialEntryInfo @@ -29,7 +31,8 @@ class RemoteViewsFactory { private const val SET_ADJUST_VIEW_BOUNDS_METHOD_NAME = "setAdjustViewBounds" private const val SET_MAX_HEIGHT_METHOD_NAME = "setMaxHeight" private const val SET_BACKGROUND_RESOURCE_METHOD_NAME = "setBackgroundResource" - private const val BULLET_POINT = "\u2022" + private const val SEPARATOR = " " + "\u2022" + " " + // TODO(jbabs): RemoteViews#setViewPadding renders this as 8dp on the display. Debug why. private const val END_ITEMS_PADDING = 28 @@ -43,20 +46,14 @@ class RemoteViewsFactory { var layoutId: Int = com.android.credentialmanager.R.layout .credman_dropdown_presentation_layout val remoteViews = RemoteViews(context.packageName, layoutId) - if (credentialEntryInfo.credentialType == CredentialType.UNKNOWN) { - return remoteViews - } val displayName = credentialEntryInfo.displayName ?: credentialEntryInfo.userName remoteViews.setTextViewText(android.R.id.text1, displayName) - val secondaryText = - if (credentialEntryInfo.displayName != null - && (credentialEntryInfo.displayName != credentialEntryInfo.userName)) - (credentialEntryInfo.userName + " " + BULLET_POINT + " " - + credentialEntryInfo.credentialTypeDisplayName - + " " + BULLET_POINT + " " + credentialEntryInfo.providerDisplayName) - else (credentialEntryInfo.credentialTypeDisplayName + " " + BULLET_POINT + " " - + credentialEntryInfo.providerDisplayName) - remoteViews.setTextViewText(android.R.id.text2, secondaryText) + val secondaryText = getSecondaryText(credentialEntryInfo) + if (secondaryText.isNullOrBlank()) { + Log.w(Constants.LOG_TAG, "Secondary text for dropdown is null") + } else { + remoteViews.setTextViewText(android.R.id.text2, secondaryText) + } remoteViews.setImageViewIcon(android.R.id.icon1, icon); remoteViews.setBoolean( android.R.id.icon1, SET_ADJUST_VIEW_BOUNDS_METHOD_NAME, true); @@ -88,6 +85,26 @@ class RemoteViewsFactory { return remoteViews } + /** + * Computes the secondary text for dropdown presentation based on available fields. + * + * <p> Format for secondary text is [username] . [credentialType] . [providerDisplayName] + * If display name and username are the same, we do not display username + * If credential type is missing as in the case with SiwG, we just display + * providerDisplayName. Both credential type and provider display name should not be empty. + */ + private fun getSecondaryText(credentialEntryInfo: CredentialEntryInfo): String? { + return listOf(if (credentialEntryInfo.displayName != null + && (credentialEntryInfo.displayName != credentialEntryInfo.userName)) + (credentialEntryInfo.userName) else null, + credentialEntryInfo.credentialTypeDisplayName, + credentialEntryInfo.providerDisplayName).filterNot { it.isNullOrBlank() } + .let { itemsToDisplay -> + if (itemsToDisplay.isEmpty()) null + else itemsToDisplay.joinToString(separator = SEPARATOR) + } + } + fun createMoreSignInOptionsPresentation(context: Context): RemoteViews { var layoutId: Int = com.android.credentialmanager.R.layout .credman_dropdown_bottom_sheet |