Mitigate T94864568 by dropping TouchEvents that do not have a MotionEvent

Summary:
I suspect that T94864568 is caused by TouchEvents being dispatched after they've been recycled. This needs further analysis, but to stop the bleeding, we can drop events at the point they'd be dispatched before the crash, and log a soft error.

Changelog: [Internal]

Reviewed By: ShikaSD

Differential Revision: D29594749

fbshipit-source-id: f50df8df2125b83126616ceaf4e529127d154c7c
This commit is contained in:
Joshua Gross 2021-07-07 14:35:19 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 28e8c6a716
Коммит 421df26266
1 изменённых файлов: 13 добавлений и 0 удалений

Просмотреть файл

@ -11,6 +11,7 @@ import android.view.MotionEvent;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.util.Pools; import androidx.core.util.Pools;
import com.facebook.infer.annotation.Assertions; import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.ReactSoftException;
import com.facebook.react.bridge.SoftAssertions; import com.facebook.react.bridge.SoftAssertions;
/** /**
@ -22,6 +23,7 @@ import com.facebook.react.bridge.SoftAssertions;
* these coalescing keys are determined. * these coalescing keys are determined.
*/ */
public class TouchEvent extends Event<TouchEvent> { public class TouchEvent extends Event<TouchEvent> {
private static final String TAG = TouchEvent.class.getSimpleName();
private static final int TOUCH_EVENTS_POOL_SIZE = 3; private static final int TOUCH_EVENTS_POOL_SIZE = 3;
@ -163,6 +165,13 @@ public class TouchEvent extends Event<TouchEvent> {
@Override @Override
public void dispatch(RCTEventEmitter rctEventEmitter) { public void dispatch(RCTEventEmitter rctEventEmitter) {
if (!hasMotionEvent()) {
ReactSoftException.logSoftException(
TAG,
new IllegalStateException(
"Cannot dispatch a TouchEvent that has no MotionEvent; the TouchEvent has been recycled"));
return;
}
TouchesHelper.sendTouchEvent( TouchesHelper.sendTouchEvent(
rctEventEmitter, rctEventEmitter,
Assertions.assertNotNull(mTouchEventType), Assertions.assertNotNull(mTouchEventType),
@ -181,6 +190,10 @@ public class TouchEvent extends Event<TouchEvent> {
return mMotionEvent; return mMotionEvent;
} }
private boolean hasMotionEvent() {
return mMotionEvent != null;
}
public float getViewX() { public float getViewX() {
return mViewX; return mViewX;
} }