Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66197824 authored by Ilya Matyukhin's avatar Ilya Matyukhin
Browse files

Send onPointerDown after onDraw has finished

Bug: 177108379
Test: onPointerDown is consistently sent after drawing the dot
Test: atest UdfpsControllerTest
Change-Id: I782e2d108d50211f0f2e3fe103f8ad13aa423ecf
parent 41903dfe
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -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,20 +434,22 @@ class UdfpsController implements DozeReceiver {
    }

    private void onFingerDown(int x, int y, float minor, float major) {
        mView.setScrimAlpha(computeScrimOpacity());
        mView.showScrimAndDot();
        try {
        if (mHbmSupported) {
            try {
                FileWriter fw = new FileWriter(mHbmPath);
                fw.write(mHbmEnableCommand);
                fw.close();
            }
            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() {
        mFingerprintManager.onPointerUp(mSensorProps.sensorId);
+13 −0
Original line number Diff line number Diff line
@@ -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();
+13 −6
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ public class UdfpsControllerTest extends SysuiTestCase {
    @Captor private ArgumentCaptor<IUdfpsOverlayController> mOverlayCaptor;
    private IUdfpsOverlayController mOverlayController;
    @Captor private ArgumentCaptor<UdfpsView.OnTouchListener> mTouchListenerCaptor;
    @Captor private ArgumentCaptor<Runnable> 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