Merge "Don't show biometric prompt if owner is not in foreground" into udc-qpr-dev

This commit is contained in:
Diya Bera
2023-06-01 23:38:51 +00:00
committed by Android (Google) Code Review
2 changed files with 51 additions and 25 deletions

View File

@@ -201,7 +201,9 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
final TaskStackListener mTaskStackListener = new TaskStackListener() { final TaskStackListener mTaskStackListener = new TaskStackListener() {
@Override @Override
public void onTaskStackChanged() { public void onTaskStackChanged() {
mHandler.post(AuthController.this::cancelIfOwnerIsNotInForeground); if (!isOwnerInForeground()) {
mHandler.post(AuthController.this::cancelIfOwnerIsNotInForeground);
}
} }
}; };
@@ -239,33 +241,37 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
} }
} }
private boolean isOwnerInForeground() {
final String clientPackage = mCurrentDialog.getOpPackageName();
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.w(TAG, "Evicting client due to: " + topPackage);
return false;
}
}
return true;
}
private void cancelIfOwnerIsNotInForeground() { private void cancelIfOwnerIsNotInForeground() {
mExecution.assertIsMainThread(); mExecution.assertIsMainThread();
if (mCurrentDialog != null) { if (mCurrentDialog != null) {
try { try {
final String clientPackage = mCurrentDialog.getOpPackageName(); mCurrentDialog.dismissWithoutCallback(true /* animate */);
Log.w(TAG, "Task stack changed, current client: " + clientPackage); mCurrentDialog = null;
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);
mCurrentDialog.dismissWithoutCallback(true /* animate */);
mCurrentDialog = null;
for (Callback cb : mCallbacks) { for (Callback cb : mCallbacks) {
cb.onBiometricPromptDismissed(); cb.onBiometricPromptDismissed();
} }
if (mReceiver != null) { if (mReceiver != null) {
mReceiver.onDialogDismissed( mReceiver.onDialogDismissed(
BiometricPrompt.DISMISSED_REASON_USER_CANCEL, BiometricPrompt.DISMISSED_REASON_USER_CANCEL,
null /* credentialAttestation */); null /* credentialAttestation */);
mReceiver = null; mReceiver = null;
}
}
} }
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "Remote exception", e); Log.e(TAG, "Remote exception", e);
@@ -1253,10 +1259,11 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
cb.onBiometricPromptShown(); cb.onBiometricPromptShown();
} }
mCurrentDialog = newDialog; mCurrentDialog = newDialog;
mCurrentDialog.show(mWindowManager, savedState);
if (!promptInfo.isAllowBackgroundAuthentication()) { if (!promptInfo.isAllowBackgroundAuthentication() && !isOwnerInForeground()) {
mHandler.post(this::cancelIfOwnerIsNotInForeground); cancelIfOwnerIsNotInForeground();
} else {
mCurrentDialog.show(mWindowManager, savedState);
} }
} }

View File

@@ -954,6 +954,25 @@ public class AuthControllerTest extends SysuiTestCase {
eq(null) /* credentialAttestation */); eq(null) /* credentialAttestation */);
} }
@Test
public void testShowDialog_whenOwnerNotInForeground() {
PromptInfo promptInfo = createTestPromptInfo();
promptInfo.setAllowBackgroundAuthentication(false);
switchTask("other_package");
mAuthController.showAuthenticationDialog(promptInfo,
mReceiver /* receiver */,
new int[]{1} /* sensorIds */,
false /* credentialAllowed */,
true /* requireConfirmation */,
0 /* userId */,
0 /* operationId */,
"testPackage",
REQUEST_ID);
assertNull(mAuthController.mCurrentDialog);
verify(mDialog1, never()).show(any(), any());
}
private void showDialog(int[] sensorIds, boolean credentialAllowed) { private void showDialog(int[] sensorIds, boolean credentialAllowed) {
mAuthController.showAuthenticationDialog(createTestPromptInfo(), mAuthController.showAuthenticationDialog(createTestPromptInfo(),
mReceiver /* receiver */, mReceiver /* receiver */,