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

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

Fix default logo is wrong for some apps.

1. Use the new api setComponentNameForConfirmDeviceCredentialActivity()
   to set component name for ConfirmDeviceCredentialActivity to the
   calling activity's info.
   This solves the issue that when
   KeyguardManager.createConfirmDeviceCredentialIntent() is used, the
   top activity will be ConfirmDeviceCredentialActivity, and logo will
   be settings logo.

2. Update getting logo logic. Current order is:
   a. Check componentNameForConfirmDeviceCredentialActivity, if it's not
   null, use componentNameForConfirmDeviceCredentialActivity.
   b. Check top activity is the same as opPackageName, if so, use top
   activity.
   c. Check allowBackgroundAuthentication or isSystem, if so, use
   opPackageName.

   d. Check whether it's one of
   biometric_dialog_package_names_for_logo_with_overrides, if so, use
   IconProvider.getIcon() to get the logo with overrides; Otherwise use
   packageManager.getApplicationIcon() to get default logo.

3. Rename contains*Configurations() to requires*Permission() and add
   tests.

Test: atest PromptViewModelTest
Test: atest PromptSelectorInteractorImplTest
Test: atest AuthServiceTest
Flag: ACONFIG android.hardware.biometrics.custom_biometric_prompt NEXTFOOD
Bug: 337082634
Bug: 336403662

Change-Id: I87b9760cf55552c388902443f47ddcdd8786e010
parent a1de1721
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.TestApi;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
@@ -603,7 +604,6 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
            mPromptInfo.setIsForLegacyFingerprintManager(sensorId);
            return this;
        }
        // LINT.ThenChange(frameworks/base/core/java/android/hardware/biometrics/PromptInfo.java)

        /**
         * Set if emergency call button should show, for example if biometrics are
@@ -613,11 +613,32 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
         * @hide
         */
        @NonNull
        @RequiresPermission(anyOf = {TEST_BIOMETRIC, USE_BIOMETRIC_INTERNAL})
        public Builder setShowEmergencyCallButton(boolean showEmergencyCallButton) {
            mPromptInfo.setShowEmergencyCallButton(showEmergencyCallButton);
            return this;
        }

        /**
         * Set caller's component name for getting logo icon/description. This should only be used
         * by ConfirmDeviceCredentialActivity, see b/337082634 for more context.
         *
         * @param componentNameForConfirmDeviceCredentialActivity set the component name for
         *                                                        ConfirmDeviceCredentialActivity.
         * @return This builder.
         * @hide
         */
        @NonNull
        @RequiresPermission(anyOf = {TEST_BIOMETRIC, USE_BIOMETRIC_INTERNAL})
        public Builder setComponentNameForConfirmDeviceCredentialActivity(
                ComponentName componentNameForConfirmDeviceCredentialActivity) {
            mPromptInfo.setComponentNameForConfirmDeviceCredentialActivity(
                    componentNameForConfirmDeviceCredentialActivity);
            return this;
        }

        // LINT.ThenChange(frameworks/base/core/java/android/hardware/biometrics/PromptInfo.java)

        /**
         * Creates a {@link BiometricPrompt}.
         *
+22 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.hardware.biometrics;
import android.annotation.DrawableRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.ComponentName;
import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;
@@ -56,6 +57,7 @@ public class PromptInfo implements Parcelable {
    private boolean mIsForLegacyFingerprintManager = false;
    private boolean mShowEmergencyCallButton = false;
    private boolean mUseParentProfileForDeviceCredential = false;
    private ComponentName mComponentNameForConfirmDeviceCredentialActivity = null;

    public PromptInfo() {

@@ -87,6 +89,8 @@ public class PromptInfo implements Parcelable {
        mIsForLegacyFingerprintManager = in.readBoolean();
        mShowEmergencyCallButton = in.readBoolean();
        mUseParentProfileForDeviceCredential = in.readBoolean();
        mComponentNameForConfirmDeviceCredentialActivity = in.readParcelable(
                ComponentName.class.getClassLoader(), ComponentName.class);
    }

    public static final Creator<PromptInfo> CREATOR = new Creator<PromptInfo>() {
@@ -132,10 +136,11 @@ public class PromptInfo implements Parcelable {
        dest.writeBoolean(mIsForLegacyFingerprintManager);
        dest.writeBoolean(mShowEmergencyCallButton);
        dest.writeBoolean(mUseParentProfileForDeviceCredential);
        dest.writeParcelable(mComponentNameForConfirmDeviceCredentialActivity, 0);
    }

    // LINT.IfChange
    public boolean containsTestConfigurations() {
    public boolean requiresTestOrInternalPermission() {
        if (mIsForLegacyFingerprintManager
                && mAllowedSensorIds.size() == 1
                && !mAllowBackgroundAuthentication) {
@@ -148,11 +153,15 @@ public class PromptInfo implements Parcelable {
            return true;
        } else if (mIgnoreEnrollmentState) {
            return true;
        } else if (mShowEmergencyCallButton) {
            return true;
        } else if (mComponentNameForConfirmDeviceCredentialActivity != null) {
            return true;
        }
        return false;
    }

    public boolean containsPrivateApiConfigurations() {
    public boolean requiresInternalPermission() {
        if (mDisallowBiometricsIfPolicyExists) {
            return true;
        } else if (mUseDefaultTitle) {
@@ -177,7 +186,7 @@ public class PromptInfo implements Parcelable {
     * Currently, logo res, logo bitmap, logo description, PromptContentViewWithMoreOptions needs
     * this permission.
     */
    public boolean containsAdvancedApiConfigurations() {
    public boolean requiresAdvancedPermission() {
        if (mLogoRes != -1) {
            return true;
        } else if (mLogoBitmap != null) {
@@ -305,6 +314,12 @@ public class PromptInfo implements Parcelable {
        mShowEmergencyCallButton = showEmergencyCallButton;
    }

    public void setComponentNameForConfirmDeviceCredentialActivity(
            ComponentName componentNameForConfirmDeviceCredentialActivity) {
        mComponentNameForConfirmDeviceCredentialActivity =
                componentNameForConfirmDeviceCredentialActivity;
    }

    public void setUseParentProfileForDeviceCredential(
            boolean useParentProfileForDeviceCredential) {
        mUseParentProfileForDeviceCredential = useParentProfileForDeviceCredential;
@@ -417,6 +432,10 @@ public class PromptInfo implements Parcelable {
        return mShowEmergencyCallButton;
    }

    public ComponentName getComponentNameForConfirmDeviceCredentialActivity() {
        return mComponentNameForConfirmDeviceCredentialActivity;
    }

    private void checkOnlyOneLogoSet() {
        if (mLogoRes != -1 && mLogoBitmap != null) {
            throw new IllegalStateException(
+2 −0
Original line number Diff line number Diff line
@@ -384,6 +384,8 @@

    <!-- Content description for the app logo icon on biometric prompt. [CHAR LIMIT=NONE] -->
    <string name="biometric_dialog_logo">App logo</string>
    <!-- List of packages for which we want to show overridden logo. For example, an app overrides its launcher logo, if it's in this array, biometric dialog shows the overridden logo; otherwise biometric dialog still shows the default application info icon. [CHAR LIMIT=NONE] -->
    <string-array name="biometric_dialog_package_names_for_logo_with_overrides" />
    <!-- Message shown when a biometric is authenticated, asking the user to confirm authentication [CHAR LIMIT=30] -->
    <string name="biometric_dialog_confirm">Confirm</string>
    <!-- Button name on BiometricPrompt shown when a biometric is detected but not authenticated. Tapping the button resumes authentication [CHAR LIMIT=30] -->
+2 −0
Original line number Diff line number Diff line
@@ -1249,6 +1249,8 @@ public class AuthController implements
        }
        mCurrentDialog = newDialog;

        // TODO(b/339532378): We should check whether |allowBackgroundAuthentication| should be
        //  removed.
        if (!promptInfo.isAllowBackgroundAuthentication() && !isOwnerInForeground()) {
            cancelIfOwnerIsNotInForeground();
        } else {
+5 −0
Original line number Diff line number Diff line
@@ -16,8 +16,10 @@

package com.android.systemui.biometrics.dagger

import android.content.Context
import android.content.res.Resources
import com.android.internal.R
import com.android.launcher3.icons.IconProvider
import com.android.systemui.CoreStartable
import com.android.systemui.biometrics.AuthController
import com.android.systemui.biometrics.EllipseOverlapDetectorParams
@@ -110,6 +112,9 @@ interface BiometricsModule {

        @Provides fun providesUdfpsUtils(): UdfpsUtils = UdfpsUtils()

        @Provides
        fun provideIconProvider(context: Context): IconProvider = IconProvider(context)

        @Provides
        @SysUISingleton
        fun providesOverlapDetector(): OverlapDetector {
Loading