blob: 7f7b33cc3e4ae7e1d9d9eb4db09e9c1af9e441d2 [file] [log] [blame]
Prabir Pradhanbaa5c822019-08-30 15:27:05 -07001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Michael Wrightfe3de7d2020-07-02 19:05:30 +010017// clang-format off
Prabir Pradhan9244aea2020-02-05 20:31:40 -080018#include "../Macros.h"
Michael Wrightfe3de7d2020-07-02 19:05:30 +010019// clang-format on
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070020
21#include "CursorInputMapper.h"
22
23#include "CursorButtonAccumulator.h"
24#include "CursorScrollAccumulator.h"
Michael Wrightca5bede2020-07-02 00:00:29 +010025#include "PointerControllerInterface.h"
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070026#include "TouchCursorInputMapperCommon.h"
27
28namespace android {
29
30// --- CursorMotionAccumulator ---
31
32CursorMotionAccumulator::CursorMotionAccumulator() {
33 clearRelativeAxes();
34}
35
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080036void CursorMotionAccumulator::reset(InputDeviceContext& deviceContext) {
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070037 clearRelativeAxes();
38}
39
40void CursorMotionAccumulator::clearRelativeAxes() {
41 mRelX = 0;
42 mRelY = 0;
43}
44
45void CursorMotionAccumulator::process(const RawEvent* rawEvent) {
46 if (rawEvent->type == EV_REL) {
47 switch (rawEvent->code) {
48 case REL_X:
49 mRelX = rawEvent->value;
50 break;
51 case REL_Y:
52 mRelY = rawEvent->value;
53 break;
54 }
55 }
56}
57
58void CursorMotionAccumulator::finishSync() {
59 clearRelativeAxes();
60}
61
62// --- CursorInputMapper ---
63
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080064CursorInputMapper::CursorInputMapper(InputDeviceContext& deviceContext)
65 : InputMapper(deviceContext) {}
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070066
67CursorInputMapper::~CursorInputMapper() {}
68
69uint32_t CursorInputMapper::getSources() {
70 return mSource;
71}
72
73void CursorInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
74 InputMapper::populateDeviceInfo(info);
75
76 if (mParameters.mode == Parameters::MODE_POINTER) {
77 float minX, minY, maxX, maxY;
78 if (mPointerController->getBounds(&minX, &minY, &maxX, &maxY)) {
79 info->addMotionRange(AMOTION_EVENT_AXIS_X, mSource, minX, maxX, 0.0f, 0.0f, 0.0f);
80 info->addMotionRange(AMOTION_EVENT_AXIS_Y, mSource, minY, maxY, 0.0f, 0.0f, 0.0f);
81 }
82 } else {
83 info->addMotionRange(AMOTION_EVENT_AXIS_X, mSource, -1.0f, 1.0f, 0.0f, mXScale, 0.0f);
84 info->addMotionRange(AMOTION_EVENT_AXIS_Y, mSource, -1.0f, 1.0f, 0.0f, mYScale, 0.0f);
Nathaniel R. Lewis2e8f2d42019-08-21 04:56:10 +000085 info->addMotionRange(AMOTION_EVENT_AXIS_RELATIVE_X, mSource, -1.0f, 1.0f, 0.0f, mXScale,
86 0.0f);
87 info->addMotionRange(AMOTION_EVENT_AXIS_RELATIVE_Y, mSource, -1.0f, 1.0f, 0.0f, mYScale,
88 0.0f);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070089 }
90 info->addMotionRange(AMOTION_EVENT_AXIS_PRESSURE, mSource, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f);
91
92 if (mCursorScrollAccumulator.haveRelativeVWheel()) {
93 info->addMotionRange(AMOTION_EVENT_AXIS_VSCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
94 }
95 if (mCursorScrollAccumulator.haveRelativeHWheel()) {
96 info->addMotionRange(AMOTION_EVENT_AXIS_HSCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
97 }
98}
99
100void CursorInputMapper::dump(std::string& dump) {
101 dump += INDENT2 "Cursor Input Mapper:\n";
102 dumpParameters(dump);
103 dump += StringPrintf(INDENT3 "XScale: %0.3f\n", mXScale);
104 dump += StringPrintf(INDENT3 "YScale: %0.3f\n", mYScale);
105 dump += StringPrintf(INDENT3 "XPrecision: %0.3f\n", mXPrecision);
106 dump += StringPrintf(INDENT3 "YPrecision: %0.3f\n", mYPrecision);
107 dump += StringPrintf(INDENT3 "HaveVWheel: %s\n",
108 toString(mCursorScrollAccumulator.haveRelativeVWheel()));
109 dump += StringPrintf(INDENT3 "HaveHWheel: %s\n",
110 toString(mCursorScrollAccumulator.haveRelativeHWheel()));
111 dump += StringPrintf(INDENT3 "VWheelScale: %0.3f\n", mVWheelScale);
112 dump += StringPrintf(INDENT3 "HWheelScale: %0.3f\n", mHWheelScale);
113 dump += StringPrintf(INDENT3 "Orientation: %d\n", mOrientation);
114 dump += StringPrintf(INDENT3 "ButtonState: 0x%08x\n", mButtonState);
115 dump += StringPrintf(INDENT3 "Down: %s\n", toString(isPointerDown(mButtonState)));
116 dump += StringPrintf(INDENT3 "DownTime: %" PRId64 "\n", mDownTime);
117}
118
119void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration* config,
120 uint32_t changes) {
121 InputMapper::configure(when, config, changes);
122
123 if (!changes) { // first time only
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800124 mCursorScrollAccumulator.configure(getDeviceContext());
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700125
126 // Configure basic parameters.
127 configureParameters();
128
129 // Configure device mode.
130 switch (mParameters.mode) {
131 case Parameters::MODE_POINTER_RELATIVE:
132 // Should not happen during first time configuration.
133 ALOGE("Cannot start a device in MODE_POINTER_RELATIVE, starting in MODE_POINTER");
134 mParameters.mode = Parameters::MODE_POINTER;
135 [[fallthrough]];
136 case Parameters::MODE_POINTER:
137 mSource = AINPUT_SOURCE_MOUSE;
138 mXPrecision = 1.0f;
139 mYPrecision = 1.0f;
140 mXScale = 1.0f;
141 mYScale = 1.0f;
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800142 mPointerController = getContext()->getPointerController(getDeviceId());
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700143 break;
144 case Parameters::MODE_NAVIGATION:
145 mSource = AINPUT_SOURCE_TRACKBALL;
146 mXPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
147 mYPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
148 mXScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
149 mYScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
150 break;
151 }
152
153 mVWheelScale = 1.0f;
154 mHWheelScale = 1.0f;
155 }
156
157 if ((!changes && config->pointerCapture) ||
158 (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE)) {
159 if (config->pointerCapture) {
160 if (mParameters.mode == Parameters::MODE_POINTER) {
161 mParameters.mode = Parameters::MODE_POINTER_RELATIVE;
162 mSource = AINPUT_SOURCE_MOUSE_RELATIVE;
163 // Keep PointerController around in order to preserve the pointer position.
Michael Wrightca5bede2020-07-02 00:00:29 +0100164 mPointerController->fade(PointerControllerInterface::Transition::IMMEDIATE);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700165 } else {
166 ALOGE("Cannot request pointer capture, device is not in MODE_POINTER");
167 }
168 } else {
169 if (mParameters.mode == Parameters::MODE_POINTER_RELATIVE) {
170 mParameters.mode = Parameters::MODE_POINTER;
171 mSource = AINPUT_SOURCE_MOUSE;
172 } else {
173 ALOGE("Cannot release pointer capture, device is not in MODE_POINTER_RELATIVE");
174 }
175 }
176 bumpGeneration();
177 if (changes) {
Siarhei Vishniakoucec3f6a2020-11-10 15:42:39 -0600178 getContext()->notifyDeviceReset(when, getDeviceId());
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700179 }
180 }
181
182 if (!changes || (changes & InputReaderConfiguration::CHANGE_POINTER_SPEED)) {
183 mPointerVelocityControl.setParameters(config->pointerVelocityControlParameters);
184 mWheelXVelocityControl.setParameters(config->wheelVelocityControlParameters);
185 mWheelYVelocityControl.setParameters(config->wheelVelocityControlParameters);
186 }
187
188 if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
189 mOrientation = DISPLAY_ORIENTATION_0;
190 if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
191 std::optional<DisplayViewport> internalViewport =
Michael Wrightfe3de7d2020-07-02 19:05:30 +0100192 config->getDisplayViewportByType(ViewportType::INTERNAL);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700193 if (internalViewport) {
194 mOrientation = internalViewport->orientation;
195 }
196 }
197
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700198 bumpGeneration();
199 }
200}
201
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700202void CursorInputMapper::configureParameters() {
203 mParameters.mode = Parameters::MODE_POINTER;
204 String8 cursorModeString;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800205 if (getDeviceContext().getConfiguration().tryGetProperty(String8("cursor.mode"),
206 cursorModeString)) {
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700207 if (cursorModeString == "navigation") {
208 mParameters.mode = Parameters::MODE_NAVIGATION;
209 } else if (cursorModeString != "pointer" && cursorModeString != "default") {
210 ALOGW("Invalid value for cursor.mode: '%s'", cursorModeString.string());
211 }
212 }
213
214 mParameters.orientationAware = false;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800215 getDeviceContext().getConfiguration().tryGetProperty(String8("cursor.orientationAware"),
216 mParameters.orientationAware);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700217
218 mParameters.hasAssociatedDisplay = false;
219 if (mParameters.mode == Parameters::MODE_POINTER || mParameters.orientationAware) {
220 mParameters.hasAssociatedDisplay = true;
221 }
222}
223
224void CursorInputMapper::dumpParameters(std::string& dump) {
225 dump += INDENT3 "Parameters:\n";
226 dump += StringPrintf(INDENT4 "HasAssociatedDisplay: %s\n",
227 toString(mParameters.hasAssociatedDisplay));
228
229 switch (mParameters.mode) {
230 case Parameters::MODE_POINTER:
231 dump += INDENT4 "Mode: pointer\n";
232 break;
233 case Parameters::MODE_POINTER_RELATIVE:
234 dump += INDENT4 "Mode: relative pointer\n";
235 break;
236 case Parameters::MODE_NAVIGATION:
237 dump += INDENT4 "Mode: navigation\n";
238 break;
239 default:
240 ALOG_ASSERT(false);
241 }
242
243 dump += StringPrintf(INDENT4 "OrientationAware: %s\n", toString(mParameters.orientationAware));
244}
245
246void CursorInputMapper::reset(nsecs_t when) {
247 mButtonState = 0;
248 mDownTime = 0;
249
250 mPointerVelocityControl.reset();
251 mWheelXVelocityControl.reset();
252 mWheelYVelocityControl.reset();
253
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800254 mCursorButtonAccumulator.reset(getDeviceContext());
255 mCursorMotionAccumulator.reset(getDeviceContext());
256 mCursorScrollAccumulator.reset(getDeviceContext());
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700257
258 InputMapper::reset(when);
259}
260
261void CursorInputMapper::process(const RawEvent* rawEvent) {
262 mCursorButtonAccumulator.process(rawEvent);
263 mCursorMotionAccumulator.process(rawEvent);
264 mCursorScrollAccumulator.process(rawEvent);
265
266 if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
267 sync(rawEvent->when);
268 }
269}
270
271void CursorInputMapper::sync(nsecs_t when) {
272 int32_t lastButtonState = mButtonState;
273 int32_t currentButtonState = mCursorButtonAccumulator.getButtonState();
274 mButtonState = currentButtonState;
275
276 bool wasDown = isPointerDown(lastButtonState);
277 bool down = isPointerDown(currentButtonState);
278 bool downChanged;
279 if (!wasDown && down) {
280 mDownTime = when;
281 downChanged = true;
282 } else if (wasDown && !down) {
283 downChanged = true;
284 } else {
285 downChanged = false;
286 }
287 nsecs_t downTime = mDownTime;
288 bool buttonsChanged = currentButtonState != lastButtonState;
289 int32_t buttonsPressed = currentButtonState & ~lastButtonState;
290 int32_t buttonsReleased = lastButtonState & ~currentButtonState;
291
292 float deltaX = mCursorMotionAccumulator.getRelativeX() * mXScale;
293 float deltaY = mCursorMotionAccumulator.getRelativeY() * mYScale;
294 bool moved = deltaX != 0 || deltaY != 0;
295
296 // Rotate delta according to orientation if needed.
297 if (mParameters.orientationAware && mParameters.hasAssociatedDisplay &&
298 (deltaX != 0.0f || deltaY != 0.0f)) {
299 rotateDelta(mOrientation, &deltaX, &deltaY);
300 }
301
302 // Move the pointer.
303 PointerProperties pointerProperties;
304 pointerProperties.clear();
305 pointerProperties.id = 0;
306 pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_MOUSE;
307
308 PointerCoords pointerCoords;
309 pointerCoords.clear();
310
311 float vscroll = mCursorScrollAccumulator.getRelativeVWheel();
312 float hscroll = mCursorScrollAccumulator.getRelativeHWheel();
313 bool scrolled = vscroll != 0 || hscroll != 0;
314
315 mWheelYVelocityControl.move(when, nullptr, &vscroll);
316 mWheelXVelocityControl.move(when, &hscroll, nullptr);
317
318 mPointerVelocityControl.move(when, &deltaX, &deltaY);
319
Chris Ye364fdb52020-08-05 15:07:56 -0700320 int32_t displayId = ADISPLAY_ID_NONE;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700321 float xCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
322 float yCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
323 if (mSource == AINPUT_SOURCE_MOUSE) {
324 if (moved || scrolled || buttonsChanged) {
Michael Wrightca5bede2020-07-02 00:00:29 +0100325 mPointerController->setPresentation(PointerControllerInterface::Presentation::POINTER);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700326
327 if (moved) {
328 mPointerController->move(deltaX, deltaY);
329 }
330
331 if (buttonsChanged) {
332 mPointerController->setButtonState(currentButtonState);
333 }
334
Michael Wrightca5bede2020-07-02 00:00:29 +0100335 mPointerController->unfade(PointerControllerInterface::Transition::IMMEDIATE);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700336 }
337
338 mPointerController->getPosition(&xCursorPosition, &yCursorPosition);
339 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, xCursorPosition);
340 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition);
341 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX);
342 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY);
343 displayId = mPointerController->getDisplayId();
Chris Ye364fdb52020-08-05 15:07:56 -0700344 } else if (mSource == AINPUT_SOURCE_MOUSE_RELATIVE) {
345 // Pointer capture mode
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700346 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, deltaX);
347 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, deltaY);
Nathaniel R. Lewis2e8f2d42019-08-21 04:56:10 +0000348 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX);
349 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700350 }
351
352 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, down ? 1.0f : 0.0f);
353
354 // Moving an external trackball or mouse should wake the device.
355 // We don't do this for internal cursor devices to prevent them from waking up
356 // the device in your pocket.
357 // TODO: Use the input device configuration to control this behavior more finely.
358 uint32_t policyFlags = 0;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800359 if ((buttonsPressed || moved || scrolled) && getDeviceContext().isExternal()) {
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700360 policyFlags |= POLICY_FLAG_WAKE;
361 }
362
363 // Synthesize key down from buttons if needed.
364 synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_DOWN, when, getDeviceId(), mSource,
365 displayId, policyFlags, lastButtonState, currentButtonState);
366
367 // Send motion event.
368 if (downChanged || moved || scrolled || buttonsChanged) {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800369 int32_t metaState = getContext()->getGlobalMetaState();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700370 int32_t buttonState = lastButtonState;
371 int32_t motionEventAction;
372 if (downChanged) {
373 motionEventAction = down ? AMOTION_EVENT_ACTION_DOWN : AMOTION_EVENT_ACTION_UP;
374 } else if (down || (mSource != AINPUT_SOURCE_MOUSE)) {
375 motionEventAction = AMOTION_EVENT_ACTION_MOVE;
376 } else {
377 motionEventAction = AMOTION_EVENT_ACTION_HOVER_MOVE;
378 }
379
380 if (buttonsReleased) {
381 BitSet32 released(buttonsReleased);
382 while (!released.isEmpty()) {
383 int32_t actionButton = BitSet32::valueForBit(released.clearFirstMarkedBit());
384 buttonState &= ~actionButton;
Siarhei Vishniakoucec3f6a2020-11-10 15:42:39 -0600385 getContext()->notifyMotion(when, getDeviceId(), mSource, displayId, policyFlags,
386 AMOTION_EVENT_ACTION_BUTTON_RELEASE, actionButton, 0,
387 metaState, buttonState, MotionClassification::NONE,
388 AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
389 &pointerCoords, mXPrecision, mYPrecision,
390 xCursorPosition, yCursorPosition, downTime,
391 /* videoFrames */ {});
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700392 }
393 }
394
Siarhei Vishniakoucec3f6a2020-11-10 15:42:39 -0600395 getContext()->notifyMotion(when, getDeviceId(), mSource, displayId, policyFlags,
396 motionEventAction, 0, 0, metaState, currentButtonState,
397 MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 1,
398 &pointerProperties, &pointerCoords, mXPrecision, mYPrecision,
399 xCursorPosition, yCursorPosition, downTime,
400 /* videoFrames */ {});
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700401
402 if (buttonsPressed) {
403 BitSet32 pressed(buttonsPressed);
404 while (!pressed.isEmpty()) {
405 int32_t actionButton = BitSet32::valueForBit(pressed.clearFirstMarkedBit());
406 buttonState |= actionButton;
Siarhei Vishniakoucec3f6a2020-11-10 15:42:39 -0600407 getContext()->notifyMotion(when, getDeviceId(), mSource, displayId, policyFlags,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700408 AMOTION_EVENT_ACTION_BUTTON_PRESS, actionButton, 0,
409 metaState, buttonState, MotionClassification::NONE,
410 AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
411 &pointerCoords, mXPrecision, mYPrecision,
412 xCursorPosition, yCursorPosition, downTime,
413 /* videoFrames */ {});
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700414 }
415 }
416
417 ALOG_ASSERT(buttonState == currentButtonState);
418
419 // Send hover move after UP to tell the application that the mouse is hovering now.
420 if (motionEventAction == AMOTION_EVENT_ACTION_UP && (mSource == AINPUT_SOURCE_MOUSE)) {
Siarhei Vishniakoucec3f6a2020-11-10 15:42:39 -0600421 getContext()->notifyMotion(when, getDeviceId(), mSource, displayId, policyFlags,
422 AMOTION_EVENT_ACTION_HOVER_MOVE, 0, 0, metaState,
423 currentButtonState, MotionClassification::NONE,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700424 AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
425 &pointerCoords, mXPrecision, mYPrecision, xCursorPosition,
426 yCursorPosition, downTime, /* videoFrames */ {});
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700427 }
428
429 // Send scroll events.
430 if (scrolled) {
431 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_VSCROLL, vscroll);
432 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_HSCROLL, hscroll);
433
Siarhei Vishniakoucec3f6a2020-11-10 15:42:39 -0600434 getContext()->notifyMotion(when, getDeviceId(), mSource, displayId, policyFlags,
435 AMOTION_EVENT_ACTION_SCROLL, 0, 0, metaState,
436 currentButtonState, MotionClassification::NONE,
437 AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
438 &pointerCoords, mXPrecision, mYPrecision, xCursorPosition,
439 yCursorPosition, downTime, /* videoFrames */ {});
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700440 }
441 }
442
443 // Synthesize key up from buttons if needed.
444 synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_UP, when, getDeviceId(), mSource,
445 displayId, policyFlags, lastButtonState, currentButtonState);
446
447 mCursorMotionAccumulator.finishSync();
448 mCursorScrollAccumulator.finishSync();
449}
450
451int32_t CursorInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
452 if (scanCode >= BTN_MOUSE && scanCode < BTN_JOYSTICK) {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800453 return getDeviceContext().getScanCodeState(scanCode);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700454 } else {
455 return AKEY_STATE_UNKNOWN;
456 }
457}
458
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700459std::optional<int32_t> CursorInputMapper::getAssociatedDisplayId() {
460 if (mParameters.hasAssociatedDisplay) {
461 if (mParameters.mode == Parameters::MODE_POINTER) {
462 return std::make_optional(mPointerController->getDisplayId());
463 } else {
464 // If the device is orientationAware and not a mouse,
465 // it expects to dispatch events to any display
466 return std::make_optional(ADISPLAY_ID_NONE);
467 }
468 }
469 return std::nullopt;
470}
471
472} // namespace android