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

Commit af4095c1 authored by Vincent Wang's avatar Vincent Wang Committed by Automerger Merge Worker
Browse files

Merge "Fix face unlock does not work for top app in split screen" into tm-dev...

Merge "Fix face unlock does not work for top app in split screen" into tm-dev am: 16ebd44e am: b32cf8c8

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



Change-Id: I90ae55f9c4486e0e8bb08009bd7f25ea553dcda9
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 828c6dce b32cf8c8
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import static com.android.server.biometrics.PreAuthInfo.CREDENTIAL_NOT_ENROLLED;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -544,4 +545,37 @@ public class Utils {
                throw new IllegalArgumentException("Unknown strength: " + strength);
        }
    }

    /**
     * Checks if a client package is running in the background.
     *
     * @param clientPackage The name of the package to be checked.
     * @return Whether the client package is running in background
     */
    public static boolean isBackground(String clientPackage) {
        Slog.v(TAG, "Checking if the authenticating is in background,"
                + " clientPackage:" + clientPackage);
        final List<ActivityManager.RunningTaskInfo> tasks =
                ActivityTaskManager.getInstance().getTasks(Integer.MAX_VALUE);

        if (tasks == null || tasks.isEmpty()) {
            Slog.d(TAG, "No running tasks reported");
            return true;
        }

        for (ActivityManager.RunningTaskInfo taskInfo : tasks) {
            final ComponentName topActivity = taskInfo.topActivity;
            if (topActivity != null) {
                final String topPackage = topActivity.getPackageName();
                if (topPackage.contentEquals(clientPackage) && taskInfo.isVisible()) {
                    return false;
                } else {
                    Slog.i(TAG, "Running task, top: " + topPackage
                            + ", isVisible: " + taskInfo.isVisible());
                }
            }
        }

        return true;
    }
}
+1 −23
Original line number Diff line number Diff line
@@ -19,10 +19,8 @@ package com.android.server.biometrics.sensors;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.app.TaskStackListener;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.hardware.biometrics.BiometricAuthenticator;
@@ -42,7 +40,6 @@ import com.android.server.biometrics.log.BiometricContext;
import com.android.server.biometrics.log.BiometricLogger;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

/**
@@ -202,25 +199,7 @@ public abstract class AuthenticationClient<T> extends AcquisitionClient<T>
        if (!mAllowBackgroundAuthentication && authenticated
                && !Utils.isKeyguard(getContext(), getOwnerString())
                && !Utils.isSystem(getContext(), getOwnerString())) {
            final List<ActivityManager.RunningTaskInfo> tasks =
                    mActivityTaskManager.getTasks(1);
            if (tasks == null || tasks.isEmpty()) {
                Slog.e(TAG, "No running tasks reported");
                isBackgroundAuth = true;
            } else {
                final ComponentName topActivity = tasks.get(0).topActivity;
                if (topActivity == null) {
                    Slog.e(TAG, "Unable to get top activity");
                    isBackgroundAuth = true;
                } else {
                    final String topPackage = topActivity.getPackageName();
                    if (!topPackage.contentEquals(getOwnerString())) {
                        Slog.e(TAG, "Background authentication detected, top: " + topPackage
                                + ", client: " + getOwnerString());
                        isBackgroundAuth = true;
                    }
                }
            }
            isBackgroundAuth = Utils.isBackground(getOwnerString());
        }

        // Fail authentication if we can't confirm the client activity is on top.
@@ -465,7 +444,6 @@ public abstract class AuthenticationClient<T> extends AcquisitionClient<T>
    @Override
    public void cancel() {
        super.cancel();

        if (mTaskStackListener != null) {
            mActivityTaskManager.unregisterTaskStackListener(mTaskStackListener);
        }
+8 −13
Original line number Diff line number Diff line
@@ -104,24 +104,19 @@ public class FaceProvider implements IBinder.DeathRecipient, ServiceProvider {
                        Slog.e(getTag(), "Task stack changed for client: " + client);
                        continue;
                    }
                    if (Utils.isKeyguard(mContext, client.getOwnerString())) {
                    if (Utils.isKeyguard(mContext, client.getOwnerString())
                            || Utils.isSystem(mContext, client.getOwnerString())) {
                        continue; // Keyguard is always allowed
                    }

                    final List<ActivityManager.RunningTaskInfo> runningTasks =
                            mActivityTaskManager.getTasks(1);
                    if (!runningTasks.isEmpty()) {
                        final String topPackage =
                                runningTasks.get(0).topActivity.getPackageName();
                        if (!topPackage.contentEquals(client.getOwnerString())
                    if (Utils.isBackground(client.getOwnerString())
                            && !client.isAlreadyDone()) {
                            Slog.e(getTag(), "Stopping background authentication, top: "
                                    + topPackage + " currentClient: " + client);
                        Slog.e(getTag(), "Stopping background authentication,"
                                + " currentClient: " + client);
                        mSensors.valueAt(i).getScheduler().cancelAuthenticationOrDetection(
                                client.getToken(), client.getRequestId());
                    }
                }
                }
            });
        }
    }
+6 −12
Original line number Diff line number Diff line
@@ -122,20 +122,14 @@ public class FingerprintProvider implements IBinder.DeathRecipient, ServiceProvi
                        continue; // Keyguard is always allowed
                    }

                    final List<ActivityManager.RunningTaskInfo> runningTasks =
                            mActivityTaskManager.getTasks(1);
                    if (!runningTasks.isEmpty()) {
                        final String topPackage =
                                runningTasks.get(0).topActivity.getPackageName();
                        if (!topPackage.contentEquals(client.getOwnerString())
                    if (Utils.isBackground(client.getOwnerString())
                            && !client.isAlreadyDone()) {
                            Slog.e(getTag(), "Stopping background authentication, top: "
                                    + topPackage + " currentClient: " + client);
                        Slog.e(getTag(), "Stopping background authentication,"
                                + " currentClient: " + client);
                        mSensors.valueAt(i).getScheduler().cancelAuthenticationOrDetection(
                                client.getToken(), client.getRequestId());
                    }
                }
                }
            });
        }
    }
+6 −11
Original line number Diff line number Diff line
@@ -142,18 +142,13 @@ public class Fingerprint21 implements IHwBinder.DeathRecipient, ServiceProvider
                    return; // Keyguard is always allowed
                }

                final List<ActivityManager.RunningTaskInfo> runningTasks =
                        mActivityTaskManager.getTasks(1);
                if (!runningTasks.isEmpty()) {
                    final String topPackage = runningTasks.get(0).topActivity.getPackageName();
                    if (!topPackage.contentEquals(client.getOwnerString())
                if (Utils.isBackground(client.getOwnerString())
                        && !client.isAlreadyDone()) {
                        Slog.e(TAG, "Stopping background authentication, top: "
                                + topPackage + " currentClient: " + client);
                    Slog.e(TAG, "Stopping background authentication,"
                            + " currentClient: " + client);
                    mScheduler.cancelAuthenticationOrDetection(
                            client.getToken(), client.getRequestId());
                }
                }
            });
        }
    }