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

Commit 32179949 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

MotionEvent: Don't update private flags when setting flags from Java

Previously, setting any MotionEvent flags from Java would result in the
private flags (which are only used in cpp) getting cleared.

Ensure private flags are not changed when setting flags from Java.

Bug: 361261924
Test: atest MotionEventTest
Flag: EXEMPT bug fix
Change-Id: Ic9a78db6dbe2e880e321465f797298ae624d6f4d
parent b97acd8e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -704,7 +704,8 @@ static void android_view_MotionEvent_nativeSetFlags(CRITICAL_JNI_PARAMS_COMMA jl
                                                    jint flags) {
    MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
    // 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) {
+25 −0
Original line number Diff line number Diff line
@@ -49,9 +49,14 @@ public class MotionEventTest {
    private static final int ID_SOURCE_MASK = 0x3 << 30;

    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();
        coords.x = x;
        coords.y = y;
        coords.orientation = orientation;
        return coords;
    }

@@ -295,4 +300,24 @@ public class MotionEventTest {
            // 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);
    }
}