Merge "Send onPointerDown after onDraw has finished"

This commit is contained in:
TreeHugger Robot
2021-01-16 05:45:02 +00:00
committed by Android (Google) Code Review
3 changed files with 37 additions and 15 deletions

View File

@@ -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() {

View File

@@ -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();

View File

@@ -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