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

Commit cbfa074a authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "MotionEvent: Don't update private flags when setting flags from Java" into main

parents 0fd6b40d 32179949
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -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) {
+25 −0
Original line number Original line Diff line number Diff line
@@ -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;
    }
    }


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