Loading packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java +33 −26 Original line number Diff line number Diff line Loading @@ -201,8 +201,10 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks, final TaskStackListener mTaskStackListener = new TaskStackListener() { @Override public void onTaskStackChanged() { if (!isOwnerInForeground()) { mHandler.post(AuthController.this::cancelIfOwnerIsNotInForeground); } } }; @VisibleForTesting Loading Loading @@ -239,19 +241,25 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks, } } private void cancelIfOwnerIsNotInForeground() { mExecution.assertIsMainThread(); if (mCurrentDialog != null) { try { private boolean isOwnerInForeground() { 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); Log.w(TAG, "Evicting client due to: " + topPackage); return false; } } return true; } private void cancelIfOwnerIsNotInForeground() { mExecution.assertIsMainThread(); if (mCurrentDialog != null) { try { mCurrentDialog.dismissWithoutCallback(true /* animate */); mCurrentDialog = null; Loading @@ -265,8 +273,6 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks, null /* credentialAttestation */); mReceiver = null; } } } } catch (RemoteException e) { Log.e(TAG, "Remote exception", e); } Loading Loading @@ -1253,10 +1259,11 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks, cb.onBiometricPromptShown(); } mCurrentDialog = newDialog; mCurrentDialog.show(mWindowManager, savedState); if (!promptInfo.isAllowBackgroundAuthentication()) { mHandler.post(this::cancelIfOwnerIsNotInForeground); if (!promptInfo.isAllowBackgroundAuthentication() && !isOwnerInForeground()) { cancelIfOwnerIsNotInForeground(); } else { mCurrentDialog.show(mWindowManager, savedState); } } Loading packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -954,6 +954,25 @@ public class AuthControllerTest extends SysuiTestCase { 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) { mAuthController.showAuthenticationDialog(createTestPromptInfo(), mReceiver /* receiver */, Loading Loading
packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java +33 −26 Original line number Diff line number Diff line Loading @@ -201,8 +201,10 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks, final TaskStackListener mTaskStackListener = new TaskStackListener() { @Override public void onTaskStackChanged() { if (!isOwnerInForeground()) { mHandler.post(AuthController.this::cancelIfOwnerIsNotInForeground); } } }; @VisibleForTesting Loading Loading @@ -239,19 +241,25 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks, } } private void cancelIfOwnerIsNotInForeground() { mExecution.assertIsMainThread(); if (mCurrentDialog != null) { try { private boolean isOwnerInForeground() { 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); Log.w(TAG, "Evicting client due to: " + topPackage); return false; } } return true; } private void cancelIfOwnerIsNotInForeground() { mExecution.assertIsMainThread(); if (mCurrentDialog != null) { try { mCurrentDialog.dismissWithoutCallback(true /* animate */); mCurrentDialog = null; Loading @@ -265,8 +273,6 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks, null /* credentialAttestation */); mReceiver = null; } } } } catch (RemoteException e) { Log.e(TAG, "Remote exception", e); } Loading Loading @@ -1253,10 +1259,11 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks, cb.onBiometricPromptShown(); } mCurrentDialog = newDialog; mCurrentDialog.show(mWindowManager, savedState); if (!promptInfo.isAllowBackgroundAuthentication()) { mHandler.post(this::cancelIfOwnerIsNotInForeground); if (!promptInfo.isAllowBackgroundAuthentication() && !isOwnerInForeground()) { cancelIfOwnerIsNotInForeground(); } else { mCurrentDialog.show(mWindowManager, savedState); } } Loading
packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -954,6 +954,25 @@ public class AuthControllerTest extends SysuiTestCase { 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) { mAuthController.showAuthenticationDialog(createTestPromptInfo(), mReceiver /* receiver */, Loading