Refactor use of services in InputMappers.
Create InputDeviceContext class to hide direct EventHub and
InputDevice accesses from InputMappers.
Test: atest inputflinger_tests libinput_tests
Change-Id: I05f9c808fc1a6f4c9207bd29fde50b76ec5655bb
diff --git a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp
index 50adf73..57c85b6 100644
--- a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp
@@ -20,7 +20,8 @@
namespace android {
-JoystickInputMapper::JoystickInputMapper(InputDevice* device) : InputMapper(device) {}
+JoystickInputMapper::JoystickInputMapper(InputDeviceContext& deviceContext)
+ : InputMapper(deviceContext) {}
JoystickInputMapper::~JoystickInputMapper() {}
@@ -112,7 +113,8 @@
if (!changes) { // first time only
// Collect all axes.
for (int32_t abs = 0; abs <= ABS_MAX; abs++) {
- if (!(getAbsAxisUsage(abs, getDevice()->getClasses()) & INPUT_DEVICE_CLASS_JOYSTICK)) {
+ if (!(getAbsAxisUsage(abs, getDeviceContext().getDeviceClasses()) &
+ INPUT_DEVICE_CLASS_JOYSTICK)) {
continue; // axis must be claimed by a different device
}
@@ -121,7 +123,7 @@
if (rawAxisInfo.valid) {
// Map axis.
AxisInfo axisInfo;
- bool explicitlyMapped = !getEventHub()->mapAxis(getDeviceId(), abs, &axisInfo);
+ bool explicitlyMapped = !getDeviceContext().mapAxis(abs, &axisInfo);
if (!explicitlyMapped) {
// Axis is not explicitly mapped, will choose a generic axis later.
axisInfo.mode = AxisInfo::MODE_NORMAL;
@@ -304,7 +306,7 @@
return;
}
- int32_t metaState = mContext->getGlobalMetaState();
+ int32_t metaState = getContext()->getGlobalMetaState();
int32_t buttonState = 0;
PointerProperties pointerProperties;
@@ -331,7 +333,7 @@
// TODO: Use the input device configuration to control this behavior more finely.
uint32_t policyFlags = 0;
- NotifyMotionArgs args(mContext->getNextSequenceNum(), when, getDeviceId(),
+ NotifyMotionArgs args(getContext()->getNextSequenceNum(), when, getDeviceId(),
AINPUT_SOURCE_JOYSTICK, ADISPLAY_ID_NONE, policyFlags,
AMOTION_EVENT_ACTION_MOVE, 0, 0, metaState, buttonState,
MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 1,