diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java index dcb6ea3ef5b7c..1cafb4c2c313e 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java @@ -342,8 +342,8 @@ class UdfpsController implements DozeReceiver { Log.v(TAG, "showUdfpsOverlay | adding window"); mView.setShowReason(reason); mWindowManager.addView(mView, computeLayoutParams()); - mIsOverlayShowing = true; mView.setOnTouchListener(mOnTouchListener); + mIsOverlayShowing = true; } catch (RuntimeException e) { Log.e(TAG, "showUdfpsOverlay | failed to add window", e); } @@ -434,19 +434,21 @@ class UdfpsController implements DozeReceiver { } private void onFingerDown(int x, int y, float minor, float major) { - mView.setScrimAlpha(computeScrimOpacity()); - mView.showScrimAndDot(); - try { - if (mHbmSupported) { + if (mHbmSupported) { + try { FileWriter fw = new FileWriter(mHbmPath); fw.write(mHbmEnableCommand); fw.close(); + } catch (IOException e) { + mView.hideScrimAndDot(); + Log.e(TAG, "onFingerDown | failed to enable HBM: " + e.getMessage()); } - mFingerprintManager.onPointerDown(mSensorProps.sensorId, x, y, minor, major); - } catch (IOException e) { - mView.hideScrimAndDot(); - Log.e(TAG, "onFingerDown | failed to enable HBM: " + e.getMessage()); } + mView.setScrimAlpha(computeScrimOpacity()); + mView.setRunAfterShowingScrimAndDot(() -> { + mFingerprintManager.onPointerDown(mSensorProps.sensorId, x, y, minor, major); + }); + mView.showScrimAndDot(); } private void onFingerUp() { diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java index a42ab58487b9a..c2f80d4d2a5ba 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java @@ -89,6 +89,10 @@ public class UdfpsView extends View implements DozeReceiver, private boolean mIsHbmSupported; @Nullable private String mDebugMessage; + // Runnable that will be run after the illumination dot and scrim are shown. + // The runnable is reset to null after it's executed once. + @Nullable private Runnable mRunAfterShowingScrimAndDot; + public UdfpsView(Context context, AttributeSet attrs) { super(context, attrs); @@ -279,6 +283,11 @@ public class UdfpsView extends View implements DozeReceiver, } canvas.restore(); + + if (mShowScrimAndDot && mRunAfterShowingScrimAndDot != null) { + post(mRunAfterShowingScrimAndDot); + mRunAfterShowingScrimAndDot = null; + } } RectF getSensorRect() { @@ -294,6 +303,10 @@ public class UdfpsView extends View implements DozeReceiver, postInvalidate(); } + void setRunAfterShowingScrimAndDot(Runnable runnable) { + mRunAfterShowingScrimAndDot = runnable; + } + boolean isValidTouch(float x, float y, float pressure) { // The X and Y coordinates of the sensor's center. final float cx = mSensorRect.centerX(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java index b24f4ab9880d2..c052563b36a5d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java @@ -106,6 +106,7 @@ public class UdfpsControllerTest extends SysuiTestCase { @Captor private ArgumentCaptor mOverlayCaptor; private IUdfpsOverlayController mOverlayController; @Captor private ArgumentCaptor mTouchListenerCaptor; + @Captor private ArgumentCaptor mRunAfterShowingScrimAndDotCaptor; @Before public void setUp() { @@ -190,11 +191,14 @@ public class UdfpsControllerTest extends SysuiTestCase { MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0); mTouchListenerCaptor.getValue().onTouch(mUdfpsView, event); event.recycle(); - // THEN the event is passed to the FingerprintManager + // THEN the scrim and dot is shown + verify(mUdfpsView).showScrimAndDot(); + // AND a runnable that passes the event to FingerprintManager is set on the view + verify(mUdfpsView).setRunAfterShowingScrimAndDot( + mRunAfterShowingScrimAndDotCaptor.capture()); + mRunAfterShowingScrimAndDotCaptor.getValue().run(); verify(mFingerprintManager).onPointerDown(eq(mUdfpsController.mSensorProps.sensorId), eq(0), eq(0), eq(0f), eq(0f)); - // AND the scrim and dot is shown - verify(mUdfpsView).showScrimAndDot(); } @Test @@ -205,11 +209,14 @@ public class UdfpsControllerTest extends SysuiTestCase { mFgExecutor.runAllReady(); // WHEN fingerprint is requested because of AOD interrupt mUdfpsController.onAodInterrupt(0, 0, 2f, 3f); - // THEN the event is passed to the FingerprintManager + // THEN the scrim and dot is shown + verify(mUdfpsView).showScrimAndDot(); + // AND a runnable that passes the event to FingerprintManager is set on the view + verify(mUdfpsView).setRunAfterShowingScrimAndDot( + mRunAfterShowingScrimAndDotCaptor.capture()); + mRunAfterShowingScrimAndDotCaptor.getValue().run(); verify(mFingerprintManager).onPointerDown(eq(mUdfpsController.mSensorProps.sensorId), eq(0), eq(0), eq(3f) /* minor */, eq(2f) /* major */); - // AND the scrim and dot is shown - verify(mUdfpsView).showScrimAndDot(); } @Test