Sync up to v300.i

This commit is contained in:
Andy CrossGate Yan
2020-12-13 01:56:05 +00:00
parent 1bc6933877
commit 4048bfed3a
11 changed files with 887 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
From 06f3a285cd8f61a94df27fc1b062160aa73ec909 Mon Sep 17 00:00:00 2001
From: Pierre-Hugues Husson <phh@phh.me>
Date: Thu, 22 Oct 2020 23:22:46 +0200
Subject: [PATCH 09/10] Matching an input with a display uses uniqueId
Not all devices have a `location`, notably bluetooth devices.
However, we might still want to associate them with a screen,
so match them with uniqueId indeed.
This is useful to have bluetooth keyboard in desktop mode for instance.
Change-Id: Ifcbc8329d54386f58e013270d9888316c0f516b6
---
services/inputflinger/reader/InputDevice.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp
index 4b19e5e35..8f2d3a685 100644
--- a/services/inputflinger/reader/InputDevice.cpp
+++ b/services/inputflinger/reader/InputDevice.cpp
@@ -275,7 +275,10 @@ void InputDevice::configure(nsecs_t when, const InputReaderConfiguration* config
mAssociatedDisplayPort = std::nullopt;
mAssociatedViewport = std::nullopt;
// Find the display port that corresponds to the current input port.
- const std::string& inputPort = mIdentifier.location;
+ std::string inputPort = mIdentifier.location;
+ if (inputPort.empty()) {
+ inputPort = mIdentifier.uniqueId;
+ }
if (!inputPort.empty()) {
const std::unordered_map<std::string, uint8_t>& ports = config->portAssociations;
const auto& displayPort = ports.find(inputPort);
--
2.17.1

View File

@@ -0,0 +1,173 @@
From c8dc151cee2395313b510f07119696717b73f4ef Mon Sep 17 00:00:00 2001
From: Pierre-Hugues Husson <phh@phh.me>
Date: Mon, 26 Oct 2020 23:16:30 +0100
Subject: [PATCH 10/10] Apply associated display for joysticks
Change-Id: I5f6c237e6bf53312aff3dc02a46ce1c779063203
---
.../reader/mapper/JoystickInputMapper.cpp | 4 +-
.../reader/mapper/JoystickInputMapper.h | 2 +
.../inputflinger/tests/InputReader_test.cpp | 100 ++++++++++++++++++
3 files changed, 105 insertions(+), 1 deletion(-)
diff --git a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp
index 030a84672..929bfc5f9 100644
--- a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp
@@ -196,6 +196,8 @@ void JoystickInputMapper::configure(nsecs_t when, const InputReaderConfiguration
}
}
}
+ std::optional<DisplayViewport> viewport = getDeviceContext().getAssociatedViewport();
+ mDisplayId = viewport ? viewport->displayId : ADISPLAY_ID_NONE;
}
bool JoystickInputMapper::haveAxis(int32_t axisId) {
@@ -334,7 +336,7 @@ void JoystickInputMapper::sync(nsecs_t when, bool force) {
uint32_t policyFlags = 0;
NotifyMotionArgs args(getContext()->getNextId(), when, getDeviceId(), AINPUT_SOURCE_JOYSTICK,
- ADISPLAY_ID_NONE, policyFlags, AMOTION_EVENT_ACTION_MOVE, 0, 0, metaState,
+ mDisplayId, policyFlags, AMOTION_EVENT_ACTION_MOVE, 0, 0, metaState,
buttonState, MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 1,
&pointerProperties, &pointerCoords, 0, 0,
AMOTION_EVENT_INVALID_CURSOR_POSITION,
diff --git a/services/inputflinger/reader/mapper/JoystickInputMapper.h b/services/inputflinger/reader/mapper/JoystickInputMapper.h
index 823a096d6..cf864ba75 100644
--- a/services/inputflinger/reader/mapper/JoystickInputMapper.h
+++ b/services/inputflinger/reader/mapper/JoystickInputMapper.h
@@ -105,6 +105,8 @@ private:
static void addMotionRange(int32_t axisId, const Axis& axis, InputDeviceInfo* info);
static void setPointerCoordsAxisValue(PointerCoords* pointerCoords, int32_t axis, float value);
+
+ int32_t mDisplayId = ADISPLAY_ID_NONE;
};
} // namespace android
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index c457a1525..c9b704993 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -20,6 +20,7 @@
#include <InputReader.h>
#include <InputReaderBase.h>
#include <InputReaderFactory.h>
+#include <JoystickInputMapper.h>
#include <KeyboardInputMapper.h>
#include <MultiTouchInputMapper.h>
#include <SingleTouchInputMapper.h>
@@ -252,6 +253,10 @@ public:
mConfig.portAssociations.insert({inputPort, displayPort});
}
+ void removeInputPortAssociation(const std::string& inputPort) {
+ mConfig.portAssociations.erase(inputPort);
+ }
+
void addDisabledDevice(int32_t deviceId) { mConfig.disabledDevices.insert(deviceId); }
void removeDisabledDevice(int32_t deviceId) { mConfig.disabledDevices.erase(deviceId); }
@@ -7336,4 +7341,99 @@ TEST_F(MultiTouchInputMapperTest_SurfaceRange, Viewports_SurfaceRange_270) {
constexpr int32_t yExpected = (x + 1) - DISPLAY_WIDTH / 4;
processPositionAndVerify(mapper, x - 1, y, x + 1, y, xExpected, yExpected);
}
+class JoystickInputMapperTest : public InputMapperTest {
+ protected:
+ const std::string PRIMARY_UNIQUE_ID = "local:0";
+ const std::string SECONDARY_UNIQUE_ID = "local:1";
+ static const uint8_t HDMI1;
+ static const uint8_t HDMI2;
+ virtual void SetUp() override {
+ InputMapperTest::SetUp(INPUT_DEVICE_CLASS_JOYSTICK);
+ }
+
+ static void process(InputMapper& mapper, nsecs_t when, int32_t type, int32_t code,
+ int32_t value) {
+ RawEvent event;
+ event.when = when;
+ event.deviceId = mapper.getDeviceContext().getEventHubId();
+ event.type = type;
+ event.code = code;
+ event.value = value;
+ mapper.process(&event);
+ }
+
+ static void process(InputMapper& mapper, int x, int y) {
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_X, x);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_Y, y);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
+ }
+};
+
+const uint8_t JoystickInputMapperTest::HDMI1 = 0;
+const uint8_t JoystickInputMapperTest::HDMI2 = 1;
+TEST_F(JoystickInputMapperTest, Configure_AssignsDisplayPort) {
+ NotifyMotionArgs args;
+
+ // Prepare test
+ setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0,
+ PRIMARY_UNIQUE_ID, HDMI1, ViewportType::VIEWPORT_INTERNAL);
+
+ mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_X, 0, 255, 15, 0, 0);
+ mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_Y, 0, 255, 15, 0, 0);
+
+ JoystickInputMapper& mapper =
+ addMapperAndConfigure<JoystickInputMapper>();
+ // 1. Ensure when initially unmapped, that event goes to focused display
+ // Center joystick
+ process(mapper, 127, 127);
+ ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+
+ // Joystick hasn't been mapped to any display yet, so it goes where the focus is
+ ASSERT_EQ(args.displayId, ADISPLAY_ID_NONE);
+ ASSERT_TRUE(mDevice->isEnabled());
+
+ // 2. Ensure that when mapping joystick to non-existing display, device is disabled
+
+ // Assign joystick to a non-existing display
+ mFakePolicy->addInputPortAssociation(DEVICE_LOCATION, HDMI2);
+ configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
+
+ // We don't test mapper's return value here, because it may or may not have a notion
+ // of whether the viewport exists
+ ASSERT_FALSE(mDevice->isEnabled());
+
+ // 3. Ensure that when joystick is mapped and screen is attached, events go to correct display
+ // Prepare second display.
+ constexpr int32_t newDisplayId = 37;
+ setDisplayInfoAndReconfigure(newDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0,
+ SECONDARY_UNIQUE_ID, HDMI2, ViewportType::VIEWPORT_EXTERNAL);
+ configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
+
+ // Device should be enabled after the associated display is found.
+ ASSERT_TRUE(mDevice->isEnabled());
+
+ // Send an event and ensure it goes to the correct display
+ process(mapper, 40, 127);
+
+ ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+
+ ASSERT_EQ(args.displayId, newDisplayId);
+ ASSERT_EQ(args.pointerCount, 1U);
+
+ // ABS_{X,Y} are mapped to GENERIC_{1,2} because FakeInputReaderContext does no axis mapping
+ ASSERT_NEAR(args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_GENERIC_1), 0.16, 0.02f);
+ ASSERT_NEAR(args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_GENERIC_2), 0.5, 0.02f);
+
+ // 4. Ensure that when removing association again, joystick goes back to focus-based display
+ // Remove association
+ mFakePolicy->removeInputPortAssociation(DEVICE_LOCATION);
+ configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
+
+ process(mapper, 127, 127);
+
+ ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+
+ // And check we're back to focus-based
+ ASSERT_EQ(args.displayId, ADISPLAY_ID_NONE);
+}
} // namespace android
--
2.17.1