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

Commit e5914396 authored by Hao Dong's avatar Hao Dong
Browse files

Add setLogo() API on Biometric Prompt.

Adds APIs to set the logo on Biometric Prompt for internal apps. For
other apps, show the app launcher logo by default.

Test: atest PromptViewModelTest
Test: atest BiometricPromptRequestTest
Test: atest PromptSelectorInteractorImplTest
Test: atest PromptRepositoryImplTest
Test: manual test on biometric test app
Flag: ACONFIG android.hardware.biometrics.custom_biometric_prompt DEVELOPMENT
Bug: 302735104
API-Coverage-Bug: 302735104

Change-Id: Ic2fbd243c0ba3fe6813addf52270019e68fbee73
parent 1890941b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -18683,6 +18683,8 @@ package android.hardware.biometrics {
    method @Nullable public int getAllowedAuthenticators();
    method @FlaggedApi("android.hardware.biometrics.custom_biometric_prompt") @Nullable public android.hardware.biometrics.PromptContentView getContentView();
    method @Nullable public CharSequence getDescription();
    method @FlaggedApi("android.hardware.biometrics.custom_biometric_prompt") @Nullable @RequiresPermission("android.permission.MANAGE_BIOMETRIC_DIALOG") public android.graphics.Bitmap getLogoBitmap();
    method @FlaggedApi("android.hardware.biometrics.custom_biometric_prompt") @DrawableRes @RequiresPermission("android.permission.MANAGE_BIOMETRIC_DIALOG") public int getLogoRes();
    method @Nullable public CharSequence getNegativeButtonText();
    method @Nullable public CharSequence getSubtitle();
    method @NonNull public CharSequence getTitle();
@@ -18732,6 +18734,8 @@ package android.hardware.biometrics {
    method @FlaggedApi("android.hardware.biometrics.custom_biometric_prompt") @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setContentView(@NonNull android.hardware.biometrics.PromptContentView);
    method @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setDescription(@NonNull CharSequence);
    method @Deprecated @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setDeviceCredentialAllowed(boolean);
    method @FlaggedApi("android.hardware.biometrics.custom_biometric_prompt") @NonNull @RequiresPermission("android.permission.MANAGE_BIOMETRIC_DIALOG") public android.hardware.biometrics.BiometricPrompt.Builder setLogo(@DrawableRes int);
    method @FlaggedApi("android.hardware.biometrics.custom_biometric_prompt") @NonNull @RequiresPermission("android.permission.MANAGE_BIOMETRIC_DIALOG") public android.hardware.biometrics.BiometricPrompt.Builder setLogo(@NonNull android.graphics.Bitmap);
    method @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setNegativeButton(@NonNull CharSequence, @NonNull java.util.concurrent.Executor, @NonNull android.content.DialogInterface.OnClickListener);
    method @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setSubtitle(@NonNull CharSequence);
    method @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setTitle(@NonNull CharSequence);
+70 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.hardware.biometrics;

import static android.Manifest.permission.MANAGE_BIOMETRIC_DIALOG;
import static android.Manifest.permission.TEST_BIOMETRIC;
import static android.Manifest.permission.USE_BIOMETRIC;
import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL;
@@ -25,6 +26,7 @@ import static android.hardware.biometrics.Flags.FLAG_GET_OP_ID_CRYPTO_OBJECT;
import static android.hardware.biometrics.Flags.FLAG_CUSTOM_BIOMETRIC_PROMPT;

import android.annotation.CallbackExecutor;
import android.annotation.DrawableRes;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -33,6 +35,7 @@ import android.annotation.RequiresPermission;
import android.annotation.TestApi;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Binder;
@@ -159,6 +162,45 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
            mContext = context;
        }

        /**
         * Optional: Sets the drawable resource of the logo that will be shown on the prompt.
         *
         * <p> Note that using this method is not recommended in most scenarios because the calling
         * application's icon will be used by default. Setting the logo is intended for large
         * bundled applications that perform a wide range of functions and need to show distinct
         * icons for each function.
         *
         * @param logoRes A drawable resource of the logo that will be shown on the prompt.
         * @return This builder.
         */
        @FlaggedApi(FLAG_CUSTOM_BIOMETRIC_PROMPT)
        @RequiresPermission(MANAGE_BIOMETRIC_DIALOG)
        @NonNull
        public BiometricPrompt.Builder setLogo(@DrawableRes int logoRes) {
            mPromptInfo.setLogoRes(logoRes);
            return this;
        }

        /**
         * Optional: Sets the bitmap drawable of the logo that will be shown on the prompt.
         *
         * <p> Note that using this method is not recommended in most scenarios because the calling
         * application's icon will be used by default. Setting the logo is intended for large
         * bundled applications that perform a wide range of functions and need to show distinct
         * icons for each function.
         *
         * @param logoBitmap A bitmap drawable of the logo that will be shown on the prompt.
         * @return This builder.
         */
        @FlaggedApi(FLAG_CUSTOM_BIOMETRIC_PROMPT)
        @RequiresPermission(MANAGE_BIOMETRIC_DIALOG)
        @NonNull
        public BiometricPrompt.Builder setLogo(@NonNull Bitmap logoBitmap) {
            mPromptInfo.setLogoBitmap(logoBitmap);
            return this;
        }


        /**
         * Required: Sets the title that will be shown on the prompt.
         * @param title The title to display.
@@ -675,6 +717,34 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
        mIsPromptShowing = false;
    }

    /**
     * Gets the drawable resource of the logo for the prompt, as set by
     * {@link Builder#setLogo(int)}. Currently for system applications use only.
     *
     * @return The drawable resource of the logo, or -1 if the prompt has no logo resource set.
     */
    @FlaggedApi(FLAG_CUSTOM_BIOMETRIC_PROMPT)
    @RequiresPermission(MANAGE_BIOMETRIC_DIALOG)
    @DrawableRes
    public int getLogoRes() {
        return mPromptInfo.getLogoRes();
    }

    /**
     * Gets the logo bitmap for the prompt, as set by {@link Builder#setLogo(Bitmap)}. Currently for
     * system applications use only.
     *
     * @return The logo bitmap of the prompt, or null if the prompt has no logo bitmap set.
     */
    @FlaggedApi(FLAG_CUSTOM_BIOMETRIC_PROMPT)
    @RequiresPermission(MANAGE_BIOMETRIC_DIALOG)
    @Nullable
    public Bitmap getLogoBitmap() {
        return mPromptInfo.getLogoBitmap();
    }



    /**
     * Gets the title for the prompt, as set by {@link Builder#setTitle(CharSequence)}.
     * @return The title of the prompt, which is guaranteed to be non-null.
+44 −0
Original line number Diff line number Diff line
@@ -16,8 +16,10 @@

package android.hardware.biometrics;

import android.annotation.DrawableRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;

@@ -30,6 +32,8 @@ import java.util.List;
 */
public class PromptInfo implements Parcelable {

    @DrawableRes private int mLogoRes = -1;
    @Nullable private Bitmap mLogoBitmap;
    @NonNull private CharSequence mTitle;
    private boolean mUseDefaultTitle;
    @Nullable private CharSequence mSubtitle;
@@ -56,6 +60,8 @@ public class PromptInfo implements Parcelable {
    }

    PromptInfo(Parcel in) {
        mLogoRes = in.readInt();
        mLogoBitmap = in.readTypedObject(Bitmap.CREATOR);
        mTitle = in.readCharSequence();
        mUseDefaultTitle = in.readBoolean();
        mSubtitle = in.readCharSequence();
@@ -98,6 +104,8 @@ public class PromptInfo implements Parcelable {

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mLogoRes);
        dest.writeTypedObject(mLogoBitmap, 0);
        dest.writeCharSequence(mTitle);
        dest.writeBoolean(mUseDefaultTitle);
        dest.writeCharSequence(mSubtitle);
@@ -156,9 +164,30 @@ public class PromptInfo implements Parcelable {
        }
        return false;
    }

    /**
     * Returns whether MANAGE_BIOMETRIC_DIALOG is contained.
     */
    public boolean containsManageBioApiConfigurations() {
        if (mLogoRes != -1) {
            return true;
        } else if (mLogoBitmap != null) {
            return true;
        }
        return false;
    }
    // LINT.ThenChange(frameworks/base/core/java/android/hardware/biometrics/BiometricPrompt.java)

    // Setters
    public void setLogoRes(@DrawableRes int logoRes) {
        mLogoRes = logoRes;
        checkOnlyOneLogoSet();
    }

    public void setLogoBitmap(@NonNull Bitmap logoBitmap) {
        mLogoBitmap = logoBitmap;
        checkOnlyOneLogoSet();
    }

    public void setTitle(CharSequence title) {
        mTitle = title;
@@ -244,6 +273,14 @@ public class PromptInfo implements Parcelable {
    }

    // Getters
    @DrawableRes
    public int getLogoRes() {
        return mLogoRes;
    }

    public Bitmap getLogoBitmap() {
        return mLogoBitmap;
    }

    public CharSequence getTitle() {
        return mTitle;
@@ -337,4 +374,11 @@ public class PromptInfo implements Parcelable {
    public boolean isShowEmergencyCallButton() {
        return mShowEmergencyCallButton;
    }

    private void checkOnlyOneLogoSet() {
        if (mLogoRes != -1 && mLogoBitmap != null) {
            throw new IllegalStateException(
                    "Exclusively one of logo resource or logo bitmap can be set");
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -426,6 +426,7 @@ applications that come with the platform
        <!-- Permissions required for CTS test - android.server.biometrics -->
        <permission name="android.permission.USE_BIOMETRIC" />
        <permission name="android.permission.TEST_BIOMETRIC" />
        <permission name="android.permission.MANAGE_BIOMETRIC_DIALOG" />
        <!-- Permissions required for CTS test - CtsContactsProviderTestCases -->
        <permission name="android.contacts.permission.MANAGE_SIM_ACCOUNTS" />
        <!-- Permissions required for CTS test - CtsHdmiCecHostTestCases -->
+3 −0
Original line number Diff line number Diff line
@@ -559,6 +559,9 @@
    <!-- Permission required for CTS test - android.server.biometrics -->
    <uses-permission android:name="android.permission.TEST_BIOMETRIC" />

    <!-- Permission required for CTS test - android.server.biometrics -->
    <uses-permission android:name="android.permission.MANAGE_BIOMETRIC_DIALOG" />

    <!-- Permissions required for CTS test - NotificationManagerTest -->
    <uses-permission android:name="android.permission.MANAGE_NOTIFICATION_LISTENERS" />

Loading