Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit efe440f6 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Merge cherrypicks of ['googleplex-android-review.googlesource.com/28967059'] into 24Q3-release.

Change-Id: I53d434eb787408a4038eed9e581a694606b889dd
parents a26a029a 2c5a13a8
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.content.DialogInterface;
import android.hardware.biometrics.BiometricPrompt.ButtonInfo;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;

@@ -62,6 +63,7 @@ import java.util.concurrent.Executor;
 */
@FlaggedApi(FLAG_CUSTOM_BIOMETRIC_PROMPT)
public final class PromptContentViewWithMoreOptionsButton implements PromptContentViewParcelable {
    private static final String TAG = "PromptContentViewWithMoreOptionsButton";
    @VisibleForTesting
    static final int MAX_DESCRIPTION_CHARACTER_NUMBER = 225;

@@ -149,13 +151,12 @@ public final class PromptContentViewWithMoreOptionsButton implements PromptConte
         *
         * @param description The description to display.
         * @return This builder.
         * @throws IllegalArgumentException If description exceeds certain character limit.
         */
        @NonNull
        @RequiresPermission(SET_BIOMETRIC_DIALOG_ADVANCED)
        public Builder setDescription(@NonNull String description) {
            if (description.length() > MAX_DESCRIPTION_CHARACTER_NUMBER) {
                throw new IllegalArgumentException("The character number of description exceeds "
                Log.w(TAG, "The character number of description exceeds "
                        + MAX_DESCRIPTION_CHARACTER_NUMBER);
            }
            mDescription = description;
+7 −9
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;

@@ -49,6 +50,7 @@ import java.util.List;
 */
@FlaggedApi(FLAG_CUSTOM_BIOMETRIC_PROMPT)
public final class PromptVerticalListContentView implements PromptContentViewParcelable {
    private static final String TAG = "PromptVerticalListContentView";
    @VisibleForTesting
    static final int MAX_ITEM_NUMBER = 20;
    @VisibleForTesting
@@ -155,12 +157,11 @@ public final class PromptVerticalListContentView implements PromptContentViewPar
         *
         * @param description The description to display.
         * @return This builder.
         * @throws IllegalArgumentException If description exceeds certain character limit.
         */
        @NonNull
        public Builder setDescription(@NonNull String description) {
            if (description.length() > MAX_DESCRIPTION_CHARACTER_NUMBER) {
                throw new IllegalArgumentException("The character number of description exceeds "
                Log.w(TAG, "The character number of description exceeds "
                        + MAX_DESCRIPTION_CHARACTER_NUMBER);
            }
            mDescription = description;
@@ -172,8 +173,7 @@ public final class PromptVerticalListContentView implements PromptContentViewPar
         *
         * @param listItem The list item view to display
         * @return This builder.
         * @throws IllegalArgumentException If this list item exceeds certain character limits or
         *                                  the number of list items exceeds certain limit.
         * @throws IllegalArgumentException If the number of list items exceeds certain limit.
         */
        @NonNull
        public Builder addListItem(@NonNull PromptContentItem listItem) {
@@ -188,8 +188,7 @@ public final class PromptVerticalListContentView implements PromptContentViewPar
         * @param listItem The list item view to display
         * @param index    The position at which to add the item
         * @return This builder.
         * @throws IllegalArgumentException If this list item exceeds certain character limits or
         *                                  the number of list items exceeds certain limit.
         * @throws IllegalArgumentException If the number of list items exceeds certain limit.
         */
        @NonNull
        public Builder addListItem(@NonNull PromptContentItem listItem, int index) {
@@ -200,8 +199,7 @@ public final class PromptVerticalListContentView implements PromptContentViewPar

        private void checkItemLimits(@NonNull PromptContentItem listItem) {
            if (doesListItemExceedsCharLimit(listItem)) {
                throw new IllegalArgumentException(
                        "The character number of list item exceeds "
                Log.w(TAG, "The character number of list item exceeds "
                        + MAX_EACH_ITEM_CHARACTER_NUMBER);
            }
            if (mContentList.size() > MAX_ITEM_NUMBER) {
+0 −36
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package android.hardware.biometrics;

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;

import static com.google.common.truth.Truth.assertThat;
@@ -118,17 +116,6 @@ public class BiometricPromptTest {
        assertThat(e).hasMessageThat().isEqualTo("Logo description passed in can not be null");
    }

    @Test
    public void testMoreOptionsButton_descriptionCharLimit() {
        IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
                () -> new PromptContentViewWithMoreOptionsButton.Builder().setDescription(
                        generateRandomString(MAX_DESCRIPTION_CHARACTER_NUMBER + 1))
        );

        assertThat(e).hasMessageThat().contains(
                "The character number of description exceeds ");
    }

    @Test
    public void testMoreOptionsButton_ExecutorNull() {
        PromptContentViewWithMoreOptionsButton.Builder builder =
@@ -156,29 +143,6 @@ public class BiometricPromptTest {
                "The listener of more options button on prompt content must be set");
    }

    @Test
    public void testVerticalList_descriptionCharLimit() {
        IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
                () -> new PromptVerticalListContentView.Builder().setDescription(
                        generateRandomString(MAX_DESCRIPTION_CHARACTER_NUMBER + 1))
        );

        assertThat(e).hasMessageThat().contains(
                "The character number of description exceeds ");
    }

    @Test
    public void testVerticalList_itemCharLimit() {
        IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
                () -> new PromptVerticalListContentView.Builder().addListItem(
                        new PromptContentItemBulletedText(
                                generateRandomString(MAX_EACH_ITEM_CHARACTER_NUMBER + 1)))
        );

        assertThat(e).hasMessageThat().contains(
                "The character number of list item exceeds ");
    }

    @Test
    public void testVerticalList_itemNumLimit() {
        PromptVerticalListContentView.Builder builder = new PromptVerticalListContentView.Builder();
+4 −0
Original line number Diff line number Diff line
@@ -148,4 +148,8 @@ object Utils {
        draw(canvas)
        return bitmap
    }

    @JvmStatic
    fun String.ellipsize(cutOffLength: Int) =
        if (length <= cutOffLength) this else replaceRange(cutOffLength, length, "...")
}
+8 −3
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.widget.Space
import android.widget.TextView
import com.android.settingslib.Utils
import com.android.systemui.biometrics.ui.BiometricPromptLayout
import com.android.systemui.biometrics.Utils.ellipsize
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.res.R
import kotlin.math.ceil
@@ -47,6 +48,8 @@ private const val TAG = "BiometricCustomizedViewBinder"

/** Sub-binder for [BiometricPromptLayout.customized_view_container]. */
object BiometricCustomizedViewBinder {
    const val MAX_DESCRIPTION_CHARACTER_NUMBER = 225

    fun bind(
        customizedViewContainer: LinearLayout,
        contentView: PromptContentView?,
@@ -91,7 +94,8 @@ private fun LayoutInflater.inflateContentView(id: Int, description: String?): Li

    val descriptionView = contentView.requireViewById<TextView>(R.id.customized_view_description)
    if (!description.isNullOrEmpty()) {
        descriptionView.text = description
        descriptionView.text =
            description.ellipsize(BiometricCustomizedViewBinder.MAX_DESCRIPTION_CHARACTER_NUMBER)
    } else {
        descriptionView.visibility = View.GONE
    }
@@ -219,13 +223,14 @@ private fun PromptContentItem.toView(
        inflater.inflate(R.layout.biometric_prompt_content_row_item_text_view, null) as TextView
    val lp = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)
    textView.layoutParams = lp
    val maxCharNumber = PromptVerticalListContentView.getMaxEachItemCharacterNumber()

    when (this) {
        is PromptContentItemPlainText -> {
            textView.text = text
            textView.text = text.ellipsize(maxCharNumber)
        }
        is PromptContentItemBulletedText -> {
            val bulletedText = SpannableString(text)
            val bulletedText = SpannableString(text.ellipsize(maxCharNumber))
            val span =
                BulletSpan(
                    getListItemBulletGapWidth(resources),
Loading