Loading core/jni/android_view_MotionEvent.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -704,7 +704,8 @@ static void android_view_MotionEvent_nativeSetFlags(CRITICAL_JNI_PARAMS_COMMA jl jint flags) { jint flags) { MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); // Prevent private flags from being used from Java. // Prevent private flags from being used from Java. event->setFlags(flags & ~AMOTION_EVENT_PRIVATE_FLAG_MASK); const int32_t privateFlags = event->getFlags() & AMOTION_EVENT_PRIVATE_FLAG_MASK; event->setFlags((flags & ~AMOTION_EVENT_PRIVATE_FLAG_MASK) | privateFlags); } } static jint android_view_MotionEvent_nativeGetEdgeFlags(CRITICAL_JNI_PARAMS_COMMA jlong nativePtr) { static jint android_view_MotionEvent_nativeGetEdgeFlags(CRITICAL_JNI_PARAMS_COMMA jlong nativePtr) { Loading core/tests/coretests/src/android/view/MotionEventTest.java +25 −0 Original line number Original line Diff line number Diff line Loading @@ -49,9 +49,14 @@ public class MotionEventTest { private static final int ID_SOURCE_MASK = 0x3 << 30; private static final int ID_SOURCE_MASK = 0x3 << 30; private PointerCoords pointerCoords(float x, float y) { private PointerCoords pointerCoords(float x, float y) { return pointerCoords(x, y, 0f /*orientation*/); } private PointerCoords pointerCoords(float x, float y, float orientation) { final var coords = new PointerCoords(); final var coords = new PointerCoords(); coords.x = x; coords.x = x; coords.y = y; coords.y = y; coords.orientation = orientation; return coords; return coords; } } Loading Loading @@ -295,4 +300,24 @@ public class MotionEventTest { // Expected // Expected } } } } @Test public void testAxesAreNotAffectedByFlagChanges() { final int pointerCount = 1; final var properties = new PointerProperties[]{fingerProperties(0)}; final var coords = new PointerCoords[]{pointerCoords(20, 60, 0.1234f)}; final MotionEvent event = MotionEvent.obtain(0 /* downTime */, 0 /* eventTime */, MotionEvent.ACTION_MOVE, pointerCount, properties, coords, 0 /* metaState */, 0 /* buttonState */, 1 /* xPrecision */, 1 /* yPrecision */, 0 /* deviceId */, 0 /* edgeFlags */, InputDevice.SOURCE_TOUCHSCREEN, 0 /* flags */); // Mark the event as tainted to update the MotionEvent flags. event.setTainted(true); assertEquals(20f, event.getX(), 0.0001); assertEquals(60f, event.getY(), 0.0001); assertEquals(0.1234f, event.getOrientation(), 0.0001); } } } Loading
core/jni/android_view_MotionEvent.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -704,7 +704,8 @@ static void android_view_MotionEvent_nativeSetFlags(CRITICAL_JNI_PARAMS_COMMA jl jint flags) { jint flags) { MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); // Prevent private flags from being used from Java. // Prevent private flags from being used from Java. event->setFlags(flags & ~AMOTION_EVENT_PRIVATE_FLAG_MASK); const int32_t privateFlags = event->getFlags() & AMOTION_EVENT_PRIVATE_FLAG_MASK; event->setFlags((flags & ~AMOTION_EVENT_PRIVATE_FLAG_MASK) | privateFlags); } } static jint android_view_MotionEvent_nativeGetEdgeFlags(CRITICAL_JNI_PARAMS_COMMA jlong nativePtr) { static jint android_view_MotionEvent_nativeGetEdgeFlags(CRITICAL_JNI_PARAMS_COMMA jlong nativePtr) { Loading
core/tests/coretests/src/android/view/MotionEventTest.java +25 −0 Original line number Original line Diff line number Diff line Loading @@ -49,9 +49,14 @@ public class MotionEventTest { private static final int ID_SOURCE_MASK = 0x3 << 30; private static final int ID_SOURCE_MASK = 0x3 << 30; private PointerCoords pointerCoords(float x, float y) { private PointerCoords pointerCoords(float x, float y) { return pointerCoords(x, y, 0f /*orientation*/); } private PointerCoords pointerCoords(float x, float y, float orientation) { final var coords = new PointerCoords(); final var coords = new PointerCoords(); coords.x = x; coords.x = x; coords.y = y; coords.y = y; coords.orientation = orientation; return coords; return coords; } } Loading Loading @@ -295,4 +300,24 @@ public class MotionEventTest { // Expected // Expected } } } } @Test public void testAxesAreNotAffectedByFlagChanges() { final int pointerCount = 1; final var properties = new PointerProperties[]{fingerProperties(0)}; final var coords = new PointerCoords[]{pointerCoords(20, 60, 0.1234f)}; final MotionEvent event = MotionEvent.obtain(0 /* downTime */, 0 /* eventTime */, MotionEvent.ACTION_MOVE, pointerCount, properties, coords, 0 /* metaState */, 0 /* buttonState */, 1 /* xPrecision */, 1 /* yPrecision */, 0 /* deviceId */, 0 /* edgeFlags */, InputDevice.SOURCE_TOUCHSCREEN, 0 /* flags */); // Mark the event as tainted to update the MotionEvent flags. event.setTainted(true); assertEquals(20f, event.getX(), 0.0001); assertEquals(60f, event.getY(), 0.0001); assertEquals(0.1234f, event.getOrientation(), 0.0001); } } }