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

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

[conflict] Merge "Fix settings activity showing background bp when...

[conflict] Merge "Fix settings activity showing background bp when createConfirmDeviceCredentialIntent() API is used." into udc-dev am: c2ac83fd

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/28784459



Bug: 388628639
Change-Id: I41397c509f9f3eaf408676147d9a962bc6e477ee
Merged-In: I722e285cd15869799b9fadd2324014cf3c6d44ad
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents a8751acb c2ac83fd
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -459,6 +459,20 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
            return this;
        }

        /**
         * Set the class name of ConfirmDeviceCredentialActivity.
         *
         * @return This builder.
         * @hide
         */
        @NonNull
        @RequiresPermission(anyOf = {TEST_BIOMETRIC, USE_BIOMETRIC_INTERNAL})
        public Builder setClassNameIfItIsConfirmDeviceCredentialActivity() {
            mPromptInfo.setClassNameIfItIsConfirmDeviceCredentialActivity(
                    mContext.getClass().getName());
            return this;
        }

        /**
         * Creates a {@link BiometricPrompt}.
         *
+20 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ public class PromptInfo implements Parcelable {
    private boolean mAllowBackgroundAuthentication;
    private boolean mIgnoreEnrollmentState;
    private boolean mIsForLegacyFingerprintManager = false;
    private String mClassNameIfItIsConfirmDeviceCredentialActivity = null;

    public PromptInfo() {

@@ -72,6 +73,7 @@ public class PromptInfo implements Parcelable {
        mAllowBackgroundAuthentication = in.readBoolean();
        mIgnoreEnrollmentState = in.readBoolean();
        mIsForLegacyFingerprintManager = in.readBoolean();
        mClassNameIfItIsConfirmDeviceCredentialActivity = in.readString();
    }

    public static final Creator<PromptInfo> CREATOR = new Creator<PromptInfo>() {
@@ -111,6 +113,7 @@ public class PromptInfo implements Parcelable {
        dest.writeBoolean(mAllowBackgroundAuthentication);
        dest.writeBoolean(mIgnoreEnrollmentState);
        dest.writeBoolean(mIsForLegacyFingerprintManager);
        dest.writeString(mClassNameIfItIsConfirmDeviceCredentialActivity);
    }

    public boolean containsTestConfigurations() {
@@ -122,6 +125,8 @@ public class PromptInfo implements Parcelable {
            return true;
        } else if (mAllowBackgroundAuthentication) {
            return true;
        } else if (mClassNameIfItIsConfirmDeviceCredentialActivity != null) {
            return true;
        }
        return false;
    }
@@ -222,6 +227,13 @@ public class PromptInfo implements Parcelable {
        mAllowedSensorIds.add(sensorId);
    }

    /**
     * Set the class name of ConfirmDeviceCredentialActivity.
     */
    void setClassNameIfItIsConfirmDeviceCredentialActivity(String className) {
        mClassNameIfItIsConfirmDeviceCredentialActivity = className;
    }

    // Getters

    public CharSequence getTitle() {
@@ -303,4 +315,12 @@ public class PromptInfo implements Parcelable {
    public boolean isForLegacyFingerprintManager() {
        return mIsForLegacyFingerprintManager;
    }

    /**
     * Get the class name of ConfirmDeviceCredentialActivity. Returns null if the direct caller is
     * not ConfirmDeviceCredentialActivity.
     */
    public String getClassNameIfItIsConfirmDeviceCredentialActivity() {
        return mClassNameIfItIsConfirmDeviceCredentialActivity;
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -818,6 +818,11 @@ public class AuthContainerView extends LinearLayout
        return mConfig.mRequestId;
    }

    @Override
    public String getClassNameIfItIsConfirmDeviceCredentialActivity() {
        return  mConfig.mPromptInfo.getClassNameIfItIsConfirmDeviceCredentialActivity();
    }

    @Override
    public void animateToCredentialUI(boolean isError) {
        if (mBiometricView != null) {
+54 −21
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.app.TaskStackListener;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -231,15 +232,9 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
        mExecution.assertIsMainThread();
        if (mCurrentDialog != null) {
            try {
                final String clientPackage = mCurrentDialog.getOpPackageName();
                Log.w(TAG, "Task stack changed, current client: " + clientPackage);
                final List<ActivityManager.RunningTaskInfo> runningTasks =
                        mActivityTaskManager.getTasks(1);
                if (!runningTasks.isEmpty()) {
                    final String topPackage = runningTasks.get(0).topActivity.getPackageName();
                    if (!topPackage.contentEquals(clientPackage)
                            && !Utils.isSystem(mContext, clientPackage)) {
                        Log.e(TAG, "Evicting client due to: " + topPackage);
                if (isOwnerInBackground()) {
                    Log.w(TAG, "Evicting client due to top activity is not : "
                            + mCurrentDialog.getOpPackageName());
                    mCurrentDialog.dismissWithoutCallback(true /* animate */);
                    mCurrentDialog = null;

@@ -254,13 +249,51 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
                        mReceiver = null;
                    }
                }
                }
            } catch (RemoteException e) {
                Log.e(TAG, "Remote exception", e);
            }
        }
    }

    private boolean isOwnerInBackground() {
        if (mCurrentDialog != null) {
            final String clientPackage = mCurrentDialog.getOpPackageName();

            final List<ActivityManager.RunningTaskInfo> runningTasks =
                    mActivityTaskManager.getTasks(1);
            if (runningTasks == null || runningTasks.isEmpty()) {
                Log.w(TAG, "No running tasks reported");
                return false;
            }

            final boolean isSystemApp = Utils.isSystem(mContext, clientPackage);

            final ComponentName topActivity = runningTasks.get(0).topActivity;
            final String topPackage =  topActivity.getPackageName();
            final boolean topPackageEqualsToClient =
                    topPackage == null
                            || topActivity.getPackageName().contentEquals(clientPackage);

            // b/339532378: If it's ConfirmDeviceCredentialActivity, we need to check further on
            // class name.
            final String clientClassNameForCDCA =
                    mCurrentDialog.getClassNameIfItIsConfirmDeviceCredentialActivity();
            final boolean isClientCDCA = clientClassNameForCDCA != null;
            final String topClassName = topActivity.getClassName();
            final boolean isCDCAWithWrongTopClass =
                    isClientCDCA
                            && !(topClassName == null
                                    || topClassName.contentEquals(clientClassNameForCDCA));

            final boolean isInBackground =
                    !(isSystemApp || topPackageEqualsToClient) || isCDCAWithWrongTopClass;

            Log.w(TAG, "isInBackground " + isInBackground);
            return isInBackground;
        }
        return false;
    }

    /**
     * Whether all fingerprint authentictors have been registered.
     */
+6 −0
Original line number Diff line number Diff line
@@ -159,6 +159,12 @@ public interface AuthDialog extends Dumpable {
    /** The requestId of the underlying operation within the framework. */
    long getRequestId();

    /**
     * Get the class name of ConfirmDeviceCredentialActivity. Returns null if the direct caller is
     * not ConfirmDeviceCredentialActivity.
     */
    String getClassNameIfItIsConfirmDeviceCredentialActivity();

    /**
     * Animate to credential UI. Typically called after biometric is locked out.
     */