blob: 1a4d5517e20d140a56dffdbfcd2c314b8808f6b0 [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
Prabir Pradhan9244aea2020-02-05 20:31:40 -080017#include "../Macros.h"
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070018
19#include "CursorInputMapper.h"
20
21#include "CursorButtonAccumulator.h"
22#include "CursorScrollAccumulator.h"
Michael Wrightca5bede2020-07-02 00:00:29 +010023#include "PointerControllerInterface.h"
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070024#include "TouchCursorInputMapperCommon.h"
25
26namespace android {
27
28// --- CursorMotionAccumulator ---
29
30CursorMotionAccumulator::CursorMotionAccumulator() {
31 clearRelativeAxes();
32}
33
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080034void CursorMotionAccumulator::reset(InputDeviceContext& deviceContext) {
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070035 clearRelativeAxes();
36}
37
38void CursorMotionAccumulator::clearRelativeAxes() {
39 mRelX = 0;
40 mRelY = 0;
41}
42
43void CursorMotionAccumulator::process(const RawEvent* rawEvent) {
44 if (rawEvent->type == EV_REL) {
45 switch (rawEvent->code) {
46 case REL_X:
47 mRelX = rawEvent->value;
48 break;
49 case REL_Y:
50 mRelY = rawEvent->value;
51 break;
52 }
53 }
54}
55
56void CursorMotionAccumulator::finishSync() {
57 clearRelativeAxes();
58}
59
60// --- CursorInputMapper ---
61
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080062CursorInputMapper::CursorInputMapper(InputDeviceContext& deviceContext)
63 : InputMapper(deviceContext) {}
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070064
65CursorInputMapper::~CursorInputMapper() {}
66
67uint32_t CursorInputMapper::getSources() {
68 return mSource;
69}
70
71void CursorInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
72 InputMapper::populateDeviceInfo(info);
73
74 if (mParameters.mode == Parameters::MODE_POINTER) {
75 float minX, minY, maxX, maxY;
76 if (mPointerController->getBounds(&minX, &minY, &maxX, &maxY)) {
77 info->addMotionRange(AMOTION_EVENT_AXIS_X, mSource, minX, maxX, 0.0f, 0.0f, 0.0f);
78 info->addMotionRange(AMOTION_EVENT_AXIS_Y, mSource, minY, maxY, 0.0f, 0.0f, 0.0f);
79 }
80 } else {
81 info->addMotionRange(AMOTION_EVENT_AXIS_X, mSource, -1.0f, 1.0f, 0.0f, mXScale, 0.0f);
82 info->addMotionRange(AMOTION_EVENT_AXIS_Y, mSource, -1.0f, 1.0f, 0.0f, mYScale, 0.0f);
83 }
84 info->addMotionRange(AMOTION_EVENT_AXIS_PRESSURE, mSource, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f);
85
86 if (mCursorScrollAccumulator.haveRelativeVWheel()) {
87 info->addMotionRange(AMOTION_EVENT_AXIS_VSCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
88 }
89 if (mCursorScrollAccumulator.haveRelativeHWheel()) {
90 info->addMotionRange(AMOTION_EVENT_AXIS_HSCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
91 }
92}
93
94void CursorInputMapper::dump(std::string& dump) {
95 dump += INDENT2 "Cursor Input Mapper:\n";
96 dumpParameters(dump);
97 dump += StringPrintf(INDENT3 "XScale: %0.3f\n", mXScale);
98 dump += StringPrintf(INDENT3 "YScale: %0.3f\n", mYScale);
99 dump += StringPrintf(INDENT3 "XPrecision: %0.3f\n", mXPrecision);
100 dump += StringPrintf(INDENT3 "YPrecision: %0.3f\n", mYPrecision);
101 dump += StringPrintf(INDENT3 "HaveVWheel: %s\n",
102 toString(mCursorScrollAccumulator.haveRelativeVWheel()));
103 dump += StringPrintf(INDENT3 "HaveHWheel: %s\n",
104 toString(mCursorScrollAccumulator.haveRelativeHWheel()));
105 dump += StringPrintf(INDENT3 "VWheelScale: %0.3f\n", mVWheelScale);
106 dump += StringPrintf(INDENT3 "HWheelScale: %0.3f\n", mHWheelScale);
107 dump += StringPrintf(INDENT3 "Orientation: %d\n", mOrientation);
108 dump += StringPrintf(INDENT3 "ButtonState: 0x%08x\n", mButtonState);
109 dump += StringPrintf(INDENT3 "Down: %s\n", toString(isPointerDown(mButtonState)));
110 dump += StringPrintf(INDENT3 "DownTime: %" PRId64 "\n", mDownTime);
111}
112
113void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration* config,
114 uint32_t changes) {
115 InputMapper::configure(when, config, changes);
116
117 if (!changes) { // first time only
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800118 mCursorScrollAccumulator.configure(getDeviceContext());
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700119
120 // Configure basic parameters.
121 configureParameters();
122
123 // Configure device mode.
124 switch (mParameters.mode) {
125 case Parameters::MODE_POINTER_RELATIVE:
126 // Should not happen during first time configuration.
127 ALOGE("Cannot start a device in MODE_POINTER_RELATIVE, starting in MODE_POINTER");
128 mParameters.mode = Parameters::MODE_POINTER;
129 [[fallthrough]];
130 case Parameters::MODE_POINTER:
131 mSource = AINPUT_SOURCE_MOUSE;
132 mXPrecision = 1.0f;
133 mYPrecision = 1.0f;
134 mXScale = 1.0f;
135 mYScale = 1.0f;
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800136 mPointerController = getContext()->getPointerController(getDeviceId());
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700137 break;
138 case Parameters::MODE_NAVIGATION:
139 mSource = AINPUT_SOURCE_TRACKBALL;
140 mXPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
141 mYPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
142 mXScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
143 mYScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
144 break;
145 }
146
147 mVWheelScale = 1.0f;
148 mHWheelScale = 1.0f;
149 }
150
151 if ((!changes && config->pointerCapture) ||
152 (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE)) {
153 if (config->pointerCapture) {
154 if (mParameters.mode == Parameters::MODE_POINTER) {
155 mParameters.mode = Parameters::MODE_POINTER_RELATIVE;
156 mSource = AINPUT_SOURCE_MOUSE_RELATIVE;
157 // Keep PointerController around in order to preserve the pointer position.
Michael Wrightca5bede2020-07-02 00:00:29 +0100158 mPointerController->fade(PointerControllerInterface::Transition::IMMEDIATE);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700159 } else {
160 ALOGE("Cannot request pointer capture, device is not in MODE_POINTER");
161 }
162 } else {
163 if (mParameters.mode == Parameters::MODE_POINTER_RELATIVE) {
164 mParameters.mode = Parameters::MODE_POINTER;
165 mSource = AINPUT_SOURCE_MOUSE;
166 } else {
167 ALOGE("Cannot release pointer capture, device is not in MODE_POINTER_RELATIVE");
168 }
169 }
170 bumpGeneration();
171 if (changes) {
Garfield Tan6a5a14e2020-01-28 13:24:04 -0800172 NotifyDeviceResetArgs args(getContext()->getNextId(), when, getDeviceId());
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800173 getListener()->notifyDeviceReset(&args);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700174 }
175 }
176
177 if (!changes || (changes & InputReaderConfiguration::CHANGE_POINTER_SPEED)) {
178 mPointerVelocityControl.setParameters(config->pointerVelocityControlParameters);
179 mWheelXVelocityControl.setParameters(config->wheelVelocityControlParameters);
180 mWheelYVelocityControl.setParameters(config->wheelVelocityControlParameters);
181 }
182
183 if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
184 mOrientation = DISPLAY_ORIENTATION_0;
185 if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
186 std::optional<DisplayViewport> internalViewport =
187 config->getDisplayViewportByType(ViewportType::VIEWPORT_INTERNAL);
188 if (internalViewport) {
189 mOrientation = internalViewport->orientation;
190 }
191 }
192
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700193 bumpGeneration();
194 }
195}
196
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700197void CursorInputMapper::configureParameters() {
198 mParameters.mode = Parameters::MODE_POINTER;
199 String8 cursorModeString;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800200 if (getDeviceContext().getConfiguration().tryGetProperty(String8("cursor.mode"),
201 cursorModeString)) {
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700202 if (cursorModeString == "navigation") {
203 mParameters.mode = Parameters::MODE_NAVIGATION;
204 } else if (cursorModeString != "pointer" && cursorModeString != "default") {
205 ALOGW("Invalid value for cursor.mode: '%s'", cursorModeString.string());
206 }
207 }
208
209 mParameters.orientationAware = false;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800210 getDeviceContext().getConfiguration().tryGetProperty(String8("cursor.orientationAware"),
211 mParameters.orientationAware);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700212
213 mParameters.hasAssociatedDisplay = false;
214 if (mParameters.mode == Parameters::MODE_POINTER || mParameters.orientationAware) {
215 mParameters.hasAssociatedDisplay = true;
216 }
217}
218
219void CursorInputMapper::dumpParameters(std::string& dump) {
220 dump += INDENT3 "Parameters:\n";
221 dump += StringPrintf(INDENT4 "HasAssociatedDisplay: %s\n",
222 toString(mParameters.hasAssociatedDisplay));
223
224 switch (mParameters.mode) {
225 case Parameters::MODE_POINTER:
226 dump += INDENT4 "Mode: pointer\n";
227 break;
228 case Parameters::MODE_POINTER_RELATIVE:
229 dump += INDENT4 "Mode: relative pointer\n";
230 break;
231 case Parameters::MODE_NAVIGATION:
232 dump += INDENT4 "Mode: navigation\n";
233 break;
234 default:
235 ALOG_ASSERT(false);
236 }
237
238 dump += StringPrintf(INDENT4 "OrientationAware: %s\n", toString(mParameters.orientationAware));
239}
240
241void CursorInputMapper::reset(nsecs_t when) {
242 mButtonState = 0;
243 mDownTime = 0;
244
245 mPointerVelocityControl.reset();
246 mWheelXVelocityControl.reset();
247 mWheelYVelocityControl.reset();
248
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800249 mCursorButtonAccumulator.reset(getDeviceContext());
250 mCursorMotionAccumulator.reset(getDeviceContext());
251 mCursorScrollAccumulator.reset(getDeviceContext());
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700252
253 InputMapper::reset(when);
254}
255
256void CursorInputMapper::process(const RawEvent* rawEvent) {
257 mCursorButtonAccumulator.process(rawEvent);
258 mCursorMotionAccumulator.process(rawEvent);
259 mCursorScrollAccumulator.process(rawEvent);
260
261 if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
262 sync(rawEvent->when);
263 }
264}
265
266void CursorInputMapper::sync(nsecs_t when) {
267 int32_t lastButtonState = mButtonState;
268 int32_t currentButtonState = mCursorButtonAccumulator.getButtonState();
269 mButtonState = currentButtonState;
270
271 bool wasDown = isPointerDown(lastButtonState);
272 bool down = isPointerDown(currentButtonState);
273 bool downChanged;
274 if (!wasDown && down) {
275 mDownTime = when;
276 downChanged = true;
277 } else if (wasDown && !down) {
278 downChanged = true;
279 } else {
280 downChanged = false;
281 }
282 nsecs_t downTime = mDownTime;
283 bool buttonsChanged = currentButtonState != lastButtonState;
284 int32_t buttonsPressed = currentButtonState & ~lastButtonState;
285 int32_t buttonsReleased = lastButtonState & ~currentButtonState;
286
287 float deltaX = mCursorMotionAccumulator.getRelativeX() * mXScale;
288 float deltaY = mCursorMotionAccumulator.getRelativeY() * mYScale;
289 bool moved = deltaX != 0 || deltaY != 0;
290
291 // Rotate delta according to orientation if needed.
292 if (mParameters.orientationAware && mParameters.hasAssociatedDisplay &&
293 (deltaX != 0.0f || deltaY != 0.0f)) {
294 rotateDelta(mOrientation, &deltaX, &deltaY);
295 }
296
297 // Move the pointer.
298 PointerProperties pointerProperties;
299 pointerProperties.clear();
300 pointerProperties.id = 0;
301 pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_MOUSE;
302
303 PointerCoords pointerCoords;
304 pointerCoords.clear();
305
306 float vscroll = mCursorScrollAccumulator.getRelativeVWheel();
307 float hscroll = mCursorScrollAccumulator.getRelativeHWheel();
308 bool scrolled = vscroll != 0 || hscroll != 0;
309
310 mWheelYVelocityControl.move(when, nullptr, &vscroll);
311 mWheelXVelocityControl.move(when, &hscroll, nullptr);
312
313 mPointerVelocityControl.move(when, &deltaX, &deltaY);
314
315 int32_t displayId;
316 float xCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
317 float yCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
318 if (mSource == AINPUT_SOURCE_MOUSE) {
319 if (moved || scrolled || buttonsChanged) {
Michael Wrightca5bede2020-07-02 00:00:29 +0100320 mPointerController->setPresentation(PointerControllerInterface::Presentation::POINTER);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700321
322 if (moved) {
323 mPointerController->move(deltaX, deltaY);
324 }
325
326 if (buttonsChanged) {
327 mPointerController->setButtonState(currentButtonState);
328 }
329
Michael Wrightca5bede2020-07-02 00:00:29 +0100330 mPointerController->unfade(PointerControllerInterface::Transition::IMMEDIATE);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700331 }
332
333 mPointerController->getPosition(&xCursorPosition, &yCursorPosition);
334 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, xCursorPosition);
335 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition);
336 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX);
337 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY);
338 displayId = mPointerController->getDisplayId();
339 } else {
340 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, deltaX);
341 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, deltaY);
342 displayId = ADISPLAY_ID_NONE;
343 }
344
345 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, down ? 1.0f : 0.0f);
346
347 // Moving an external trackball or mouse should wake the device.
348 // We don't do this for internal cursor devices to prevent them from waking up
349 // the device in your pocket.
350 // TODO: Use the input device configuration to control this behavior more finely.
351 uint32_t policyFlags = 0;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800352 if ((buttonsPressed || moved || scrolled) && getDeviceContext().isExternal()) {
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700353 policyFlags |= POLICY_FLAG_WAKE;
354 }
355
356 // Synthesize key down from buttons if needed.
357 synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_DOWN, when, getDeviceId(), mSource,
358 displayId, policyFlags, lastButtonState, currentButtonState);
359
360 // Send motion event.
361 if (downChanged || moved || scrolled || buttonsChanged) {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800362 int32_t metaState = getContext()->getGlobalMetaState();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700363 int32_t buttonState = lastButtonState;
364 int32_t motionEventAction;
365 if (downChanged) {
366 motionEventAction = down ? AMOTION_EVENT_ACTION_DOWN : AMOTION_EVENT_ACTION_UP;
367 } else if (down || (mSource != AINPUT_SOURCE_MOUSE)) {
368 motionEventAction = AMOTION_EVENT_ACTION_MOVE;
369 } else {
370 motionEventAction = AMOTION_EVENT_ACTION_HOVER_MOVE;
371 }
372
373 if (buttonsReleased) {
374 BitSet32 released(buttonsReleased);
375 while (!released.isEmpty()) {
376 int32_t actionButton = BitSet32::valueForBit(released.clearFirstMarkedBit());
377 buttonState &= ~actionButton;
Garfield Tan6a5a14e2020-01-28 13:24:04 -0800378 NotifyMotionArgs releaseArgs(getContext()->getNextId(), when, getDeviceId(),
379 mSource, displayId, policyFlags,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700380 AMOTION_EVENT_ACTION_BUTTON_RELEASE, actionButton, 0,
381 metaState, buttonState, MotionClassification::NONE,
382 AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
383 &pointerCoords, mXPrecision, mYPrecision,
384 xCursorPosition, yCursorPosition, downTime,
385 /* videoFrames */ {});
386 getListener()->notifyMotion(&releaseArgs);
387 }
388 }
389
Garfield Tan6a5a14e2020-01-28 13:24:04 -0800390 NotifyMotionArgs args(getContext()->getNextId(), when, getDeviceId(), mSource, displayId,
391 policyFlags, motionEventAction, 0, 0, metaState, currentButtonState,
392 MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 1,
393 &pointerProperties, &pointerCoords, mXPrecision, mYPrecision,
394 xCursorPosition, yCursorPosition, downTime,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700395 /* videoFrames */ {});
396 getListener()->notifyMotion(&args);
397
398 if (buttonsPressed) {
399 BitSet32 pressed(buttonsPressed);
400 while (!pressed.isEmpty()) {
401 int32_t actionButton = BitSet32::valueForBit(pressed.clearFirstMarkedBit());
402 buttonState |= actionButton;
Garfield Tan6a5a14e2020-01-28 13:24:04 -0800403 NotifyMotionArgs pressArgs(getContext()->getNextId(), when, getDeviceId(), mSource,
404 displayId, policyFlags,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700405 AMOTION_EVENT_ACTION_BUTTON_PRESS, actionButton, 0,
406 metaState, buttonState, MotionClassification::NONE,
407 AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
408 &pointerCoords, mXPrecision, mYPrecision,
409 xCursorPosition, yCursorPosition, downTime,
410 /* videoFrames */ {});
411 getListener()->notifyMotion(&pressArgs);
412 }
413 }
414
415 ALOG_ASSERT(buttonState == currentButtonState);
416
417 // Send hover move after UP to tell the application that the mouse is hovering now.
418 if (motionEventAction == AMOTION_EVENT_ACTION_UP && (mSource == AINPUT_SOURCE_MOUSE)) {
Garfield Tan6a5a14e2020-01-28 13:24:04 -0800419 NotifyMotionArgs hoverArgs(getContext()->getNextId(), when, getDeviceId(), mSource,
420 displayId, policyFlags, AMOTION_EVENT_ACTION_HOVER_MOVE, 0,
421 0, metaState, currentButtonState, MotionClassification::NONE,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700422 AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
423 &pointerCoords, mXPrecision, mYPrecision, xCursorPosition,
424 yCursorPosition, downTime, /* videoFrames */ {});
425 getListener()->notifyMotion(&hoverArgs);
426 }
427
428 // Send scroll events.
429 if (scrolled) {
430 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_VSCROLL, vscroll);
431 pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_HSCROLL, hscroll);
432
Garfield Tan6a5a14e2020-01-28 13:24:04 -0800433 NotifyMotionArgs scrollArgs(getContext()->getNextId(), when, getDeviceId(), mSource,
434 displayId, policyFlags, AMOTION_EVENT_ACTION_SCROLL, 0, 0,
435 metaState, currentButtonState, MotionClassification::NONE,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700436 AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
437 &pointerCoords, mXPrecision, mYPrecision, xCursorPosition,
438 yCursorPosition, downTime, /* videoFrames */ {});
439 getListener()->notifyMotion(&scrollArgs);
440 }
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