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

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

Change-Id: If621998bf2e12fa67e3c5eec8e96da485351dea1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Vincent Wang
2022-05-16 09:18:21 +00:00
committed by Automerger Merge Worker
5 changed files with 55 additions and 59 deletions

View File

@@ -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;
}
}

View File

@@ -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);
}

View File

@@ -104,22 +104,17 @@ 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())
&& !client.isAlreadyDone()) {
Slog.e(getTag(), "Stopping background authentication, top: "
+ topPackage + " currentClient: " + client);
mSensors.valueAt(i).getScheduler().cancelAuthenticationOrDetection(
client.getToken(), client.getRequestId());
}
if (Utils.isBackground(client.getOwnerString())
&& !client.isAlreadyDone()) {
Slog.e(getTag(), "Stopping background authentication,"
+ " currentClient: " + client);
mSensors.valueAt(i).getScheduler().cancelAuthenticationOrDetection(
client.getToken(), client.getRequestId());
}
}
});

View File

@@ -122,18 +122,12 @@ 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())
&& !client.isAlreadyDone()) {
Slog.e(getTag(), "Stopping background authentication, top: "
+ topPackage + " currentClient: " + client);
mSensors.valueAt(i).getScheduler().cancelAuthenticationOrDetection(
client.getToken(), client.getRequestId());
}
if (Utils.isBackground(client.getOwnerString())
&& !client.isAlreadyDone()) {
Slog.e(getTag(), "Stopping background authentication,"
+ " currentClient: " + client);
mSensors.valueAt(i).getScheduler().cancelAuthenticationOrDetection(
client.getToken(), client.getRequestId());
}
}
});

View File

@@ -142,17 +142,12 @@ 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())
&& !client.isAlreadyDone()) {
Slog.e(TAG, "Stopping background authentication, top: "
+ topPackage + " currentClient: " + client);
mScheduler.cancelAuthenticationOrDetection(
client.getToken(), client.getRequestId());
}
if (Utils.isBackground(client.getOwnerString())
&& !client.isAlreadyDone()) {
Slog.e(TAG, "Stopping background authentication,"
+ " currentClient: " + client);
mScheduler.cancelAuthenticationOrDetection(
client.getToken(), client.getRequestId());
}
});
}