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

Commit be991489 authored by Hao Dong's avatar Hao Dong Committed by Android (Google) Code Review
Browse files

Merge "Add setLogo() API on Biometric Prompt." into main

parents 007cee95 e5914396
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -18679,6 +18679,8 @@ package android.hardware.biometrics {
    method @Nullable public int getAllowedAuthenticators();
    method @Nullable public int getAllowedAuthenticators();
    method @FlaggedApi("android.hardware.biometrics.custom_biometric_prompt") @Nullable public android.hardware.biometrics.PromptContentView getContentView();
    method @FlaggedApi("android.hardware.biometrics.custom_biometric_prompt") @Nullable public android.hardware.biometrics.PromptContentView getContentView();
    method @Nullable public CharSequence getDescription();
    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 getNegativeButtonText();
    method @Nullable public CharSequence getSubtitle();
    method @Nullable public CharSequence getSubtitle();
    method @NonNull public CharSequence getTitle();
    method @NonNull public CharSequence getTitle();
@@ -18728,6 +18730,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 @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 @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setDescription(@NonNull CharSequence);
    method @Deprecated @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setDeviceCredentialAllowed(boolean);
    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 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 setSubtitle(@NonNull CharSequence);
    method @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setTitle(@NonNull CharSequence);
    method @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setTitle(@NonNull CharSequence);
+70 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package android.hardware.biometrics;
package android.hardware.biometrics;


import static android.Manifest.permission.MANAGE_BIOMETRIC_DIALOG;
import static android.Manifest.permission.TEST_BIOMETRIC;
import static android.Manifest.permission.TEST_BIOMETRIC;
import static android.Manifest.permission.USE_BIOMETRIC;
import static android.Manifest.permission.USE_BIOMETRIC;
import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL;
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 static android.hardware.biometrics.Flags.FLAG_CUSTOM_BIOMETRIC_PROMPT;


import android.annotation.CallbackExecutor;
import android.annotation.CallbackExecutor;
import android.annotation.DrawableRes;
import android.annotation.FlaggedApi;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
@@ -33,6 +35,7 @@ import android.annotation.RequiresPermission;
import android.annotation.TestApi;
import android.annotation.TestApi;
import android.content.Context;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.hardware.face.FaceManager;
import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Binder;
import android.os.Binder;
@@ -159,6 +162,45 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
            mContext = context;
            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.
         * Required: Sets the title that will be shown on the prompt.
         * @param title The title to display.
         * @param title The title to display.
@@ -675,6 +717,34 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
        mIsPromptShowing = false;
        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)}.
     * 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.
     * @return The title of the prompt, which is guaranteed to be non-null.
+44 −0
Original line number Original line Diff line number Diff line
@@ -16,8 +16,10 @@


package android.hardware.biometrics;
package android.hardware.biometrics;


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


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


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


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


    @Override
    @Override
    public void writeToParcel(Parcel dest, int flags) {
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mLogoRes);
        dest.writeTypedObject(mLogoBitmap, 0);
        dest.writeCharSequence(mTitle);
        dest.writeCharSequence(mTitle);
        dest.writeBoolean(mUseDefaultTitle);
        dest.writeBoolean(mUseDefaultTitle);
        dest.writeCharSequence(mSubtitle);
        dest.writeCharSequence(mSubtitle);
@@ -156,9 +164,30 @@ public class PromptInfo implements Parcelable {
        }
        }
        return false;
        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)
    // LINT.ThenChange(frameworks/base/core/java/android/hardware/biometrics/BiometricPrompt.java)


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

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


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


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

    public Bitmap getLogoBitmap() {
        return mLogoBitmap;
    }


    public CharSequence getTitle() {
    public CharSequence getTitle() {
        return mTitle;
        return mTitle;
@@ -337,4 +374,11 @@ public class PromptInfo implements Parcelable {
    public boolean isShowEmergencyCallButton() {
    public boolean isShowEmergencyCallButton() {
        return mShowEmergencyCallButton;
        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 Original line Diff line number Diff line
@@ -426,6 +426,7 @@ applications that come with the platform
        <!-- Permissions required for CTS test - android.server.biometrics -->
        <!-- Permissions required for CTS test - android.server.biometrics -->
        <permission name="android.permission.USE_BIOMETRIC" />
        <permission name="android.permission.USE_BIOMETRIC" />
        <permission name="android.permission.TEST_BIOMETRIC" />
        <permission name="android.permission.TEST_BIOMETRIC" />
        <permission name="android.permission.MANAGE_BIOMETRIC_DIALOG" />
        <!-- Permissions required for CTS test - CtsContactsProviderTestCases -->
        <!-- Permissions required for CTS test - CtsContactsProviderTestCases -->
        <permission name="android.contacts.permission.MANAGE_SIM_ACCOUNTS" />
        <permission name="android.contacts.permission.MANAGE_SIM_ACCOUNTS" />
        <!-- Permissions required for CTS test - CtsHdmiCecHostTestCases -->
        <!-- Permissions required for CTS test - CtsHdmiCecHostTestCases -->
+3 −0
Original line number Original line Diff line number Diff line
@@ -559,6 +559,9 @@
    <!-- Permission required for CTS test - android.server.biometrics -->
    <!-- Permission required for CTS test - android.server.biometrics -->
    <uses-permission android:name="android.permission.TEST_BIOMETRIC" />
    <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 -->
    <!-- Permissions required for CTS test - NotificationManagerTest -->
    <uses-permission android:name="android.permission.MANAGE_NOTIFICATION_LISTENERS" />
    <uses-permission android:name="android.permission.MANAGE_NOTIFICATION_LISTENERS" />


Loading