Fix biometric prompt will delay dismiss after long press power key

Bug: b/271958568
Test: Pre-setup
      1. Setup fingerprints
      2. Set the Press & hold power button to Power menu
      Test steps
      1. Go to Setting → Network & internet → internet → Network details → Share
      2. Tap the QR code beside Share name
      3. Invoke the biometric prompt
      4. Long press the power key and will bring out the power menu
      5. atest AuthContollerTest -c

Change-Id: I8aaed2f98169050a6aff6e475ca47aa54d3313eb
This commit is contained in:
Vincent Wang
2023-03-09 06:01:40 +00:00
parent f384185128
commit ca186eec3f
2 changed files with 38 additions and 21 deletions

View File

@@ -198,32 +198,36 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (mCurrentDialog != null
&& Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {
if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {
String reason = intent.getStringExtra("reason");
reason = (reason != null) ? reason : "unknown";
Log.d(TAG, "ACTION_CLOSE_SYSTEM_DIALOGS received, reason: " + reason);
mCurrentDialog.dismissWithoutCallback(true /* animate */);
mCurrentDialog = null;
for (Callback cb : mCallbacks) {
cb.onBiometricPromptDismissed();
}
try {
if (mReceiver != null) {
mReceiver.onDialogDismissed(BiometricPrompt.DISMISSED_REASON_USER_CANCEL,
null /* credentialAttestation */);
mReceiver = null;
}
} catch (RemoteException e) {
Log.e(TAG, "Remote exception", e);
}
closeDioalog(reason);
}
}
};
private void closeDioalog(String reason) {
if (isShowing()) {
Log.i(TAG, "Close BP, reason :" + reason);
mCurrentDialog.dismissWithoutCallback(true /* animate */);
mCurrentDialog = null;
for (Callback cb : mCallbacks) {
cb.onBiometricPromptDismissed();
}
try {
if (mReceiver != null) {
mReceiver.onDialogDismissed(BiometricPrompt.DISMISSED_REASON_USER_CANCEL,
null /* credentialAttestation */);
mReceiver = null;
}
} catch (RemoteException e) {
Log.e(TAG, "Remote exception", e);
}
}
}
private void cancelIfOwnerIsNotInForeground() {
mExecution.assertIsMainThread();
if (mCurrentDialog != null) {
@@ -546,6 +550,11 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
}
}
@Override
public void handleShowGlobalActionsMenu() {
closeDioalog("PowerMenu shown");
}
/**
* @return where the UDFPS exists on the screen in pixels in portrait mode.
*/

View File

@@ -35,7 +35,6 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
@@ -930,6 +929,15 @@ public class AuthControllerTest extends SysuiTestCase {
assertNotSame(firstFpLocation, mAuthController.getFingerprintSensorLocation());
}
@Test
public void testCloseDialog_whenGlobalActionsMenuShown() throws Exception {
showDialog(new int[]{1} /* sensorIds */, false /* credentialAllowed */);
mAuthController.handleShowGlobalActionsMenu();
verify(mReceiver).onDialogDismissed(
eq(BiometricPrompt.DISMISSED_REASON_USER_CANCEL),
eq(null) /* credentialAttestation */);
}
private void showDialog(int[] sensorIds, boolean credentialAllowed) {
mAuthController.showAuthenticationDialog(createTestPromptInfo(),
mReceiver /* receiver */,