summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Prabir Pradhan <prabirmsp@google.com> 2025-01-02 18:01:27 -0800
committer Android Build Cherrypicker Worker <android-build-cherrypicker-worker@google.com> 2025-01-02 18:01:27 -0800
commit351a1a8cc243ade12215959bf3f680f23611595d (patch)
treecdfa52f172cc01e790ee4f6dac4bfcefc56c4962
parent719ba1da8d7cb2a822cbd4fe3fd52056b931692a (diff)
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 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:321799491df0b2ac7d64137c5d8ce38f65dbbdc0) Merged-In: Ic9a78db6dbe2e880e321465f797298ae624d6f4d Change-Id: Ic9a78db6dbe2e880e321465f797298ae624d6f4d
-rw-r--r--core/jni/android_view_MotionEvent.cpp3
-rw-r--r--core/tests/coretests/src/android/view/MotionEventTest.java25
2 files changed, 27 insertions, 1 deletions
diff --git a/core/jni/android_view_MotionEvent.cpp b/core/jni/android_view_MotionEvent.cpp
index 240be3fe5534..c105a6098870 100644
--- a/core/jni/android_view_MotionEvent.cpp
+++ b/core/jni/android_view_MotionEvent.cpp
@@ -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) {
diff --git a/core/tests/coretests/src/android/view/MotionEventTest.java b/core/tests/coretests/src/android/view/MotionEventTest.java
index d0f9a38720bf..419c05f5b8c1 100644
--- a/core/tests/coretests/src/android/view/MotionEventTest.java
+++ b/core/tests/coretests/src/android/view/MotionEventTest.java
@@ -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);
+ }
}