Fingerprint user canceled message should not be delayed

The user canceled message is different than the other fingerprint errors
since it is caused by the user explicitly tapping on the UI at which
point the dialog will be already dismissing/dismissed. So the error
should be sent immediately to the application.

Test: manual test with FingerprintDialog, modified to show when the
      error messages are received

Change-Id: Ia2a3b0a7ac9c8cfcbd6055045a95fc06aa02c61a
Fixes: 77337939
diff --git a/core/java/android/hardware/fingerprint/FingerprintManager.java b/core/java/android/hardware/fingerprint/FingerprintManager.java
index 5e28570..a6c8c67 100644
--- a/core/java/android/hardware/fingerprint/FingerprintManager.java
+++ b/core/java/android/hardware/fingerprint/FingerprintManager.java
@@ -1158,14 +1158,22 @@
         @Override // binder call
         public void onError(long deviceId, int error, int vendorCode) {
             if (mExecutor != null) {
-                // BiometricDialog case, post a delayed runnable on the FingerprintManager handler
-                // that sends the error message after FingerprintDialog.HIDE_DIALOG_DELAY to send
-                // the error to the application.
-                mHandler.postDelayed(() -> {
+                // BiometricDialog case
+                if (error == FingerprintManager.FINGERPRINT_ERROR_USER_CANCELED) {
+                    // User tapped somewhere to cancel, the biometric dialog is already dismissed.
                     mExecutor.execute(() -> {
                         sendErrorResult(deviceId, error, vendorCode);
                     });
-                }, BiometricDialog.HIDE_DIALOG_DELAY);
+                } else {
+                    // User got an error that needs to be displayed on the dialog, post a delayed
+                    // runnable on the FingerprintManager handler that sends the error message after
+                    // FingerprintDialog.HIDE_DIALOG_DELAY to send the error to the application.
+                    mHandler.postDelayed(() -> {
+                        mExecutor.execute(() -> {
+                            sendErrorResult(deviceId, error, vendorCode);
+                        });
+                    }, BiometricDialog.HIDE_DIALOG_DELAY);
+                }
             } else {
                 mHandler.obtainMessage(MSG_ERROR, error, vendorCode, deviceId).sendToTarget();
             }