diff options
5 files changed, 35 insertions, 31 deletions
diff --git a/core/java/android/hardware/biometrics/BiometricPrompt.java b/core/java/android/hardware/biometrics/BiometricPrompt.java index 37a2df83cc00..5c6039489b6b 100644 --- a/core/java/android/hardware/biometrics/BiometricPrompt.java +++ b/core/java/android/hardware/biometrics/BiometricPrompt.java @@ -240,18 +240,19 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan * * @param logoDescription The logo description text that will be shown on the prompt. * @return This builder. - * @throws IllegalArgumentException If logo description is null or exceeds certain character - * limit. + * @throws IllegalArgumentException If logo description is null. */ @FlaggedApi(FLAG_CUSTOM_BIOMETRIC_PROMPT) @RequiresPermission(SET_BIOMETRIC_DIALOG_ADVANCED) @NonNull public BiometricPrompt.Builder setLogoDescription(@NonNull String logoDescription) { - if (logoDescription == null - || logoDescription.length() > MAX_LOGO_DESCRIPTION_CHARACTER_NUMBER) { - throw new IllegalArgumentException( - "Logo description passed in can not be null or exceed " - + MAX_LOGO_DESCRIPTION_CHARACTER_NUMBER + " character number."); + if (logoDescription == null || logoDescription.isEmpty()) { + throw new IllegalArgumentException("Logo description passed in can not be null"); + } + if (logoDescription.length() > MAX_LOGO_DESCRIPTION_CHARACTER_NUMBER) { + Log.w(TAG, + "Logo description passed in exceeds" + MAX_LOGO_DESCRIPTION_CHARACTER_NUMBER + + " character number and may be truncated."); } mPromptInfo.setLogoDescription(logoDescription); return this; diff --git a/core/tests/coretests/src/android/hardware/biometrics/BiometricPromptTest.java b/core/tests/coretests/src/android/hardware/biometrics/BiometricPromptTest.java index ca9154280a10..a3d0ec623683 100644 --- a/core/tests/coretests/src/android/hardware/biometrics/BiometricPromptTest.java +++ b/core/tests/coretests/src/android/hardware/biometrics/BiometricPromptTest.java @@ -16,7 +16,6 @@ package android.hardware.biometrics; -import static android.hardware.biometrics.BiometricPrompt.MAX_LOGO_DESCRIPTION_CHARACTER_NUMBER; import static android.hardware.biometrics.PromptContentViewWithMoreOptionsButton.MAX_DESCRIPTION_CHARACTER_NUMBER; import static android.hardware.biometrics.PromptVerticalListContentView.MAX_EACH_ITEM_CHARACTER_NUMBER; import static android.hardware.biometrics.PromptVerticalListContentView.MAX_ITEM_NUMBER; @@ -116,19 +115,7 @@ public class BiometricPromptTest { () -> new BiometricPrompt.Builder(mContext).setLogoDescription(null) ); - assertThat(e).hasMessageThat().contains( - "Logo description passed in can not be null or exceed"); - } - - @Test - public void testLogoDescription_charLimit() { - IllegalArgumentException e = assertThrows(IllegalArgumentException.class, - () -> new BiometricPrompt.Builder(mContext).setLogoDescription( - generateRandomString(MAX_LOGO_DESCRIPTION_CHARACTER_NUMBER + 1)) - ); - - assertThat(e).hasMessageThat().contains( - "Logo description passed in can not be null or exceed"); + assertThat(e).hasMessageThat().isEqualTo("Logo description passed in can not be null"); } @Test diff --git a/packages/SystemUI/res/layout/biometric_prompt_two_pane_layout.xml b/packages/SystemUI/res/layout/biometric_prompt_two_pane_layout.xml index c599f9e05b38..18a1544a1d5d 100644 --- a/packages/SystemUI/res/layout/biometric_prompt_two_pane_layout.xml +++ b/packages/SystemUI/res/layout/biometric_prompt_two_pane_layout.xml @@ -87,20 +87,21 @@ android:layout_height="match_parent"> android:id="@+id/logo_description" style="@style/TextAppearance.AuthCredential.LogoDescription" android:layout_width="0dp" - android:layout_height="wrap_content" + android:layout_height="@dimen/biometric_prompt_logo_size" + android:gravity="start|center_vertical" android:textAlignment="viewStart" - android:paddingStart="16dp" - app:layout_constraintBottom_toBottomOf="@+id/logo" + android:layout_marginStart="16dp" + app:layout_goneMarginStart="0dp" + app:layout_constraintBottom_toTopOf="@+id/title" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/logo" - app:layout_constraintTop_toTopOf="@+id/logo" /> + app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/title" style="@style/TextAppearance.AuthCredential.Title" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="12dp" android:gravity="@integer/biometric_dialog_text_gravity" android:paddingHorizontal="0dp" android:textAlignment="viewStart" @@ -108,7 +109,7 @@ android:layout_height="match_parent"> app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/logo" + app:layout_constraintTop_toBottomOf="@+id/logoBarrier" app:layout_constraintVertical_bias="0.0" app:layout_constraintVertical_chainStyle="packed" /> @@ -159,6 +160,15 @@ android:layout_height="match_parent"> app:layout_constraintVertical_bias="0.0" /> <androidx.constraintlayout.widget.Barrier + android:id="@+id/logoBarrier" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + app:barrierMargin="12dp" + app:barrierAllowsGoneWidgets="false" + app:barrierDirection="bottom" + app:constraint_referenced_ids="logo_description, logo" /> + + <androidx.constraintlayout.widget.Barrier android:id="@+id/contentBarrier" android:layout_width="wrap_content" android:layout_height="wrap_content" diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml index 31862d259d7e..6bc674c474a1 100644 --- a/packages/SystemUI/res/values/styles.xml +++ b/packages/SystemUI/res/values/styles.xml @@ -192,11 +192,10 @@ <style name="TextAppearance.AuthCredential.LogoDescription" parent="TextAppearance.Material3.LabelLarge" > <item name="android:fontFamily">@*android:string/config_bodyFontFamilyMedium</item> - <item name="android:ellipsize">marquee</item> <item name="android:gravity">@integer/biometric_dialog_text_gravity</item> - <item name="android:marqueeRepeatLimit">1</item> - <item name="android:singleLine">true</item> + <item name="android:maxLines">1</item> <item name="android:textColor">?androidprv:attr/materialColorOnSurfaceVariant</item> + <item name="android:ellipsize">end</item> </style> <style name="TextAppearance.AuthCredential.Title" parent="TextAppearance.Material3.HeadlineSmall" > diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewBinder.kt b/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewBinder.kt index c868d01de743..8b0891568eea 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewBinder.kt @@ -64,6 +64,7 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch private const val TAG = "BiometricViewBinder" +private const val MAX_LOGO_DESCRIPTION_CHARACTER_NUMBER = 30 /** Top-most view binder for BiometricPrompt views. */ object BiometricViewBinder { @@ -167,7 +168,10 @@ object BiometricViewBinder { } logoView.setImageDrawable(viewModel.logo.first()) - logoDescriptionView.text = viewModel.logoDescription.first() + // The ellipsize effect on xml happens only when the TextView does not have any free + // space on the screen to show the text. So we need to manually truncate. + logoDescriptionView.text = + viewModel.logoDescription.first().ellipsize(MAX_LOGO_DESCRIPTION_CHARACTER_NUMBER) titleView.text = viewModel.title.first() subtitleView.text = viewModel.subtitle.first() descriptionView.text = viewModel.description.first() @@ -684,6 +688,9 @@ private fun BiometricModalities.asDefaultHelpMessage(context: Context): String = else -> "" } +private fun String.ellipsize(cutOffLength: Int) = + if (length <= cutOffLength) this else replaceRange(cutOffLength, length, "...") + private fun Boolean.asVisibleOrGone(): Int = if (this) View.VISIBLE else View.GONE private fun Boolean.asVisibleOrHidden(): Int = if (this) View.VISIBLE else View.INVISIBLE |