summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrabir Pradhan <prabirmsp@google.com>2021-07-23 21:01:55 +0000
committerPrabir Pradhan <prabirmsp@google.com>2021-07-26 11:13:47 +0000
commit7e1443fba3f81742b29e28f246e8d6b236c251a7 (patch)
tree23a79721365503cf8a68452e29c272f85194b4b2
parent4d56aeed596b259d2355478c5d4505bb429a5634 (diff)
downloadnative-7e1443fba3f81742b29e28f246e8d6b236c251a7.tar.gz
MotionEvent: Guard getRawX/Y compatibility logic using feature flag
The getRawX/Y API contains compatibility logic that should only be used when the per-window-input-rotation feature is enabled. The compatibility logic was previously unguarded because it was assumed that the logic was a no-op when the flag was not enabled. However, this turned out to be untrue, resulting in the bug. Bug: 187686656 Test: manual: using repro steps listed in the bug. Change-Id: I6603694f9872e7df4b6f72c7fb2555b3249687a6
-rw-r--r--libs/input/Input.cpp12
-rw-r--r--libs/input/tests/InputEvent_test.cpp22
2 files changed, 34 insertions, 0 deletions
diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp
index 70ed438112..d954d23507 100644
--- a/libs/input/Input.cpp
+++ b/libs/input/Input.cpp
@@ -23,6 +23,7 @@
#include <limits.h>
#include <string.h>
+#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <input/Input.h>
#include <input/InputDevice.h>
@@ -41,6 +42,15 @@ namespace android {
namespace {
+// When per-window-input-rotation is enabled, InputFlinger works in the un-rotated display
+// coordinates and SurfaceFlinger includes the display rotation in the input window transforms.
+bool isPerWindowInputRotationEnabled() {
+ static const bool PER_WINDOW_INPUT_ROTATION =
+ base::GetBoolProperty("persist.debug.per_window_input_rotation", false);
+
+ return PER_WINDOW_INPUT_ROTATION;
+}
+
float transformAngle(const ui::Transform& transform, float angleRadians) {
// Construct and transform a vector oriented at the specified clockwise angle from vertical.
// Coordinate system: down is increasing Y, right is increasing X.
@@ -506,6 +516,8 @@ float MotionEvent::getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
size_t historicalIndex) const {
const PointerCoords* coords = getHistoricalRawPointerCoords(pointerIndex, historicalIndex);
+ if (!isPerWindowInputRotationEnabled()) return coords->getAxisValue(axis);
+
if (axis == AMOTION_EVENT_AXIS_X || axis == AMOTION_EVENT_AXIS_Y) {
// For compatibility, convert raw coordinates into "oriented screen space". Once app
// developers are educated about getRaw, we can consider removing this.
diff --git a/libs/input/tests/InputEvent_test.cpp b/libs/input/tests/InputEvent_test.cpp
index 32b72ba616..3b76ddbb7c 100644
--- a/libs/input/tests/InputEvent_test.cpp
+++ b/libs/input/tests/InputEvent_test.cpp
@@ -17,6 +17,7 @@
#include <array>
#include <math.h>
+#include <android-base/properties.h>
#include <attestation/HmacKeyManager.h>
#include <binder/Parcel.h>
#include <gtest/gtest.h>
@@ -225,13 +226,34 @@ protected:
static constexpr float X_OFFSET = 1;
static constexpr float Y_OFFSET = 1.1;
+ static const std::optional<bool> INITIAL_PER_WINDOW_INPUT_ROTATION_FLAG_VALUE;
+
int32_t mId;
ui::Transform mTransform;
+ void SetUp() override;
+ void TearDown() override;
+
void initializeEventWithHistory(MotionEvent* event);
void assertEqualsEventWithHistory(const MotionEvent* event);
};
+const std::optional<bool> MotionEventTest::INITIAL_PER_WINDOW_INPUT_ROTATION_FLAG_VALUE =
+ !base::GetProperty("persist.debug.per_window_input_rotation", "").empty()
+ ? std::optional(base::GetBoolProperty("persist.debug.per_window_input_rotation", false))
+ : std::nullopt;
+
+void MotionEventTest::SetUp() {
+ // Ensure per_window_input_rotation is enabled.
+ base::SetProperty("persist.debug.per_window_input_rotation", "true");
+}
+
+void MotionEventTest::TearDown() {
+ const auto val = INITIAL_PER_WINDOW_INPUT_ROTATION_FLAG_VALUE.has_value()
+ ? (*INITIAL_PER_WINDOW_INPUT_ROTATION_FLAG_VALUE ? "true" : "false")
+ : "";
+ base::SetProperty("persist.debug.per_window_input_rotation", val);
+}
void MotionEventTest::initializeEventWithHistory(MotionEvent* event) {
mId = InputEvent::nextId();