blob: 90b954e037622cd2926317284d0a1a90fb89bf3e [file] [log] [blame]
Jeff Brown46b9ac02010-04-22 18:58:52 -07001//
2// Copyright 2010 The Android Open Source Project
3//
4// Provides a pipe-based transport for native events in the NDK.
5//
6#define LOG_TAG "Input"
7
8//#define LOG_NDEBUG 0
9
Jeff Brown47e6b1b2010-11-29 17:37:49 -080010#define DEBUG_PROBE 0
11
12#include <stdlib.h>
13#include <unistd.h>
Jeff Brown90655042010-12-02 13:50:46 -080014#include <ctype.h>
Jeff Brown47e6b1b2010-11-29 17:37:49 -080015
Jeff Brown46b9ac02010-04-22 18:58:52 -070016#include <ui/Input.h>
17
Jeff Brown91c69ab2011-02-14 17:03:18 -080018#include <math.h>
19
20#ifdef HAVE_ANDROID_OS
21#include <binder/Parcel.h>
22
23#include "SkPoint.h"
24#include "SkMatrix.h"
25#include "SkScalar.h"
26#endif
27
Jeff Brown46b9ac02010-04-22 18:58:52 -070028namespace android {
29
Jeff Brown47e6b1b2010-11-29 17:37:49 -080030static const char* CONFIGURATION_FILE_DIR[] = {
31 "idc/",
32 "keylayout/",
33 "keychars/",
34};
35
36static const char* CONFIGURATION_FILE_EXTENSION[] = {
37 ".idc",
38 ".kl",
39 ".kcm",
40};
41
Jeff Brown90655042010-12-02 13:50:46 -080042static bool isValidNameChar(char ch) {
43 return isascii(ch) && (isdigit(ch) || isalpha(ch) || ch == '-' || ch == '_');
44}
45
Jeff Brown47e6b1b2010-11-29 17:37:49 -080046static void appendInputDeviceConfigurationFileRelativePath(String8& path,
47 const String8& name, InputDeviceConfigurationFileType type) {
48 path.append(CONFIGURATION_FILE_DIR[type]);
49 for (size_t i = 0; i < name.length(); i++) {
50 char ch = name[i];
Jeff Brown90655042010-12-02 13:50:46 -080051 if (!isValidNameChar(ch)) {
Jeff Brown47e6b1b2010-11-29 17:37:49 -080052 ch = '_';
53 }
54 path.append(&ch, 1);
55 }
56 path.append(CONFIGURATION_FILE_EXTENSION[type]);
57}
58
Jeff Brown90655042010-12-02 13:50:46 -080059String8 getInputDeviceConfigurationFilePathByDeviceIdentifier(
60 const InputDeviceIdentifier& deviceIdentifier,
61 InputDeviceConfigurationFileType type) {
62 if (deviceIdentifier.vendor !=0 && deviceIdentifier.product != 0) {
63 if (deviceIdentifier.version != 0) {
64 // Try vendor product version.
65 String8 versionPath(getInputDeviceConfigurationFilePathByName(
66 String8::format("Vendor_%04x_Product_%04x_Version_%04x",
67 deviceIdentifier.vendor, deviceIdentifier.product,
68 deviceIdentifier.version),
69 type));
70 if (!versionPath.isEmpty()) {
71 return versionPath;
72 }
73 }
74
75 // Try vendor product.
76 String8 productPath(getInputDeviceConfigurationFilePathByName(
77 String8::format("Vendor_%04x_Product_%04x",
78 deviceIdentifier.vendor, deviceIdentifier.product),
79 type));
80 if (!productPath.isEmpty()) {
81 return productPath;
82 }
83 }
84
85 // Try device name.
86 return getInputDeviceConfigurationFilePathByName(deviceIdentifier.name, type);
87}
88
89String8 getInputDeviceConfigurationFilePathByName(
Jeff Brown47e6b1b2010-11-29 17:37:49 -080090 const String8& name, InputDeviceConfigurationFileType type) {
91 // Search system repository.
92 String8 path;
93 path.setTo(getenv("ANDROID_ROOT"));
94 path.append("/usr/");
95 appendInputDeviceConfigurationFileRelativePath(path, name, type);
96#if DEBUG_PROBE
97 LOGD("Probing for system provided input device configuration file: path='%s'", path.string());
98#endif
99 if (!access(path.string(), R_OK)) {
100#if DEBUG_PROBE
101 LOGD("Found");
102#endif
103 return path;
104 }
105
106 // Search user repository.
107 // TODO Should only look here if not in safe mode.
108 path.setTo(getenv("ANDROID_DATA"));
109 path.append("/system/devices/");
110 appendInputDeviceConfigurationFileRelativePath(path, name, type);
111#if DEBUG_PROBE
112 LOGD("Probing for system user input device configuration file: path='%s'", path.string());
113#endif
114 if (!access(path.string(), R_OK)) {
115#if DEBUG_PROBE
116 LOGD("Found");
117#endif
118 return path;
119 }
120
121 // Not found.
122#if DEBUG_PROBE
123 LOGD("Probe failed to find input device configuration file: name='%s', type=%d",
124 name.string(), type);
125#endif
126 return String8();
127}
128
129
130// --- InputEvent ---
Jeff Brown46b9ac02010-04-22 18:58:52 -0700131
Jeff Brownc5ed5912010-07-14 18:48:53 -0700132void InputEvent::initialize(int32_t deviceId, int32_t source) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700133 mDeviceId = deviceId;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700134 mSource = source;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700135}
136
Dianne Hackborn2c6081c2010-07-15 17:44:53 -0700137void InputEvent::initialize(const InputEvent& from) {
138 mDeviceId = from.mDeviceId;
139 mSource = from.mSource;
140}
141
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800142// --- KeyEvent ---
Jeff Brown46b9ac02010-04-22 18:58:52 -0700143
Dianne Hackborn3c80a4a2010-06-29 19:20:40 -0700144bool KeyEvent::hasDefaultAction(int32_t keyCode) {
145 switch (keyCode) {
Jeff Brownfd035822010-06-30 16:10:35 -0700146 case AKEYCODE_HOME:
147 case AKEYCODE_BACK:
148 case AKEYCODE_CALL:
149 case AKEYCODE_ENDCALL:
150 case AKEYCODE_VOLUME_UP:
151 case AKEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -0700152 case AKEYCODE_VOLUME_MUTE:
Jeff Brownfd035822010-06-30 16:10:35 -0700153 case AKEYCODE_POWER:
154 case AKEYCODE_CAMERA:
155 case AKEYCODE_HEADSETHOOK:
156 case AKEYCODE_MENU:
157 case AKEYCODE_NOTIFICATION:
158 case AKEYCODE_FOCUS:
159 case AKEYCODE_SEARCH:
Jeff Brownb0418da2010-11-01 15:24:01 -0700160 case AKEYCODE_MEDIA_PLAY:
161 case AKEYCODE_MEDIA_PAUSE:
Jeff Brownfd035822010-06-30 16:10:35 -0700162 case AKEYCODE_MEDIA_PLAY_PAUSE:
163 case AKEYCODE_MEDIA_STOP:
164 case AKEYCODE_MEDIA_NEXT:
165 case AKEYCODE_MEDIA_PREVIOUS:
166 case AKEYCODE_MEDIA_REWIND:
Jeff Brownb0418da2010-11-01 15:24:01 -0700167 case AKEYCODE_MEDIA_RECORD:
Jeff Brownfd035822010-06-30 16:10:35 -0700168 case AKEYCODE_MEDIA_FAST_FORWARD:
169 case AKEYCODE_MUTE:
Dianne Hackborn3c80a4a2010-06-29 19:20:40 -0700170 return true;
171 }
172
173 return false;
174}
175
176bool KeyEvent::hasDefaultAction() const {
177 return hasDefaultAction(getKeyCode());
178}
179
180bool KeyEvent::isSystemKey(int32_t keyCode) {
181 switch (keyCode) {
Jeff Brownfd035822010-06-30 16:10:35 -0700182 case AKEYCODE_MENU:
183 case AKEYCODE_SOFT_RIGHT:
184 case AKEYCODE_HOME:
185 case AKEYCODE_BACK:
186 case AKEYCODE_CALL:
187 case AKEYCODE_ENDCALL:
188 case AKEYCODE_VOLUME_UP:
189 case AKEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -0700190 case AKEYCODE_VOLUME_MUTE:
Jeff Brownfd035822010-06-30 16:10:35 -0700191 case AKEYCODE_MUTE:
192 case AKEYCODE_POWER:
193 case AKEYCODE_HEADSETHOOK:
Jeff Brownb0418da2010-11-01 15:24:01 -0700194 case AKEYCODE_MEDIA_PLAY:
195 case AKEYCODE_MEDIA_PAUSE:
Jeff Brownfd035822010-06-30 16:10:35 -0700196 case AKEYCODE_MEDIA_PLAY_PAUSE:
197 case AKEYCODE_MEDIA_STOP:
198 case AKEYCODE_MEDIA_NEXT:
199 case AKEYCODE_MEDIA_PREVIOUS:
200 case AKEYCODE_MEDIA_REWIND:
Jeff Brownb0418da2010-11-01 15:24:01 -0700201 case AKEYCODE_MEDIA_RECORD:
Jeff Brownfd035822010-06-30 16:10:35 -0700202 case AKEYCODE_MEDIA_FAST_FORWARD:
203 case AKEYCODE_CAMERA:
204 case AKEYCODE_FOCUS:
205 case AKEYCODE_SEARCH:
Dianne Hackborn3c80a4a2010-06-29 19:20:40 -0700206 return true;
207 }
208
209 return false;
210}
211
212bool KeyEvent::isSystemKey() const {
213 return isSystemKey(getKeyCode());
214}
215
Jeff Brown46b9ac02010-04-22 18:58:52 -0700216void KeyEvent::initialize(
217 int32_t deviceId,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700218 int32_t source,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700219 int32_t action,
220 int32_t flags,
221 int32_t keyCode,
222 int32_t scanCode,
223 int32_t metaState,
224 int32_t repeatCount,
225 nsecs_t downTime,
226 nsecs_t eventTime) {
Jeff Brownc5ed5912010-07-14 18:48:53 -0700227 InputEvent::initialize(deviceId, source);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700228 mAction = action;
229 mFlags = flags;
230 mKeyCode = keyCode;
231 mScanCode = scanCode;
232 mMetaState = metaState;
233 mRepeatCount = repeatCount;
234 mDownTime = downTime;
235 mEventTime = eventTime;
236}
237
Dianne Hackborn2c6081c2010-07-15 17:44:53 -0700238void KeyEvent::initialize(const KeyEvent& from) {
239 InputEvent::initialize(from);
240 mAction = from.mAction;
241 mFlags = from.mFlags;
242 mKeyCode = from.mKeyCode;
243 mScanCode = from.mScanCode;
244 mMetaState = from.mMetaState;
245 mRepeatCount = from.mRepeatCount;
246 mDownTime = from.mDownTime;
247 mEventTime = from.mEventTime;
248}
249
Jeff Brown91c69ab2011-02-14 17:03:18 -0800250
251// --- PointerCoords ---
252
253#ifdef HAVE_ANDROID_OS
254status_t PointerCoords::readFromParcel(Parcel* parcel) {
255 bits = parcel->readInt32();
256
257 uint32_t count = __builtin_popcount(bits);
258 if (count > MAX_AXES) {
259 return BAD_VALUE;
260 }
261
262 for (uint32_t i = 0; i < count; i++) {
263 values[i] = parcel->readInt32();
264 }
265 return OK;
266}
267
268status_t PointerCoords::writeToParcel(Parcel* parcel) const {
269 parcel->writeInt32(bits);
270
271 uint32_t count = __builtin_popcount(bits);
272 for (uint32_t i = 0; i < count; i++) {
273 parcel->writeInt32(values[i]);
274 }
275 return OK;
276}
277#endif
278
279void PointerCoords::tooManyAxes(int axis) {
280 LOGW("Could not set value for axis %d because the PointerCoords structure is full and "
281 "cannot contain more than %d axis values.", axis, int(MAX_AXES));
282}
283
284
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800285// --- MotionEvent ---
Jeff Brown46b9ac02010-04-22 18:58:52 -0700286
287void MotionEvent::initialize(
288 int32_t deviceId,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700289 int32_t source,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700290 int32_t action,
Jeff Brown85a31762010-09-01 17:01:00 -0700291 int32_t flags,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700292 int32_t edgeFlags,
293 int32_t metaState,
Jeff Brown5c225b12010-06-16 01:53:36 -0700294 float xOffset,
295 float yOffset,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700296 float xPrecision,
297 float yPrecision,
298 nsecs_t downTime,
299 nsecs_t eventTime,
300 size_t pointerCount,
301 const int32_t* pointerIds,
302 const PointerCoords* pointerCoords) {
Jeff Brownc5ed5912010-07-14 18:48:53 -0700303 InputEvent::initialize(deviceId, source);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700304 mAction = action;
Jeff Brown85a31762010-09-01 17:01:00 -0700305 mFlags = flags;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700306 mEdgeFlags = edgeFlags;
307 mMetaState = metaState;
Jeff Brown5c225b12010-06-16 01:53:36 -0700308 mXOffset = xOffset;
309 mYOffset = yOffset;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700310 mXPrecision = xPrecision;
311 mYPrecision = yPrecision;
312 mDownTime = downTime;
313 mPointerIds.clear();
314 mPointerIds.appendArray(pointerIds, pointerCount);
315 mSampleEventTimes.clear();
316 mSamplePointerCoords.clear();
317 addSample(eventTime, pointerCoords);
318}
319
Jeff Brown91c69ab2011-02-14 17:03:18 -0800320void MotionEvent::copyFrom(const MotionEvent* other, bool keepHistory) {
321 InputEvent::initialize(other->mDeviceId, other->mSource);
322 mAction = other->mAction;
323 mFlags = other->mFlags;
324 mEdgeFlags = other->mEdgeFlags;
325 mMetaState = other->mMetaState;
326 mXOffset = other->mXOffset;
327 mYOffset = other->mYOffset;
328 mXPrecision = other->mXPrecision;
329 mYPrecision = other->mYPrecision;
330 mDownTime = other->mDownTime;
331 mPointerIds = other->mPointerIds;
332
333 if (keepHistory) {
334 mSampleEventTimes = other->mSampleEventTimes;
335 mSamplePointerCoords = other->mSamplePointerCoords;
336 } else {
337 mSampleEventTimes.clear();
338 mSampleEventTimes.push(other->getEventTime());
339 mSamplePointerCoords.clear();
340 size_t pointerCount = other->getPointerCount();
341 size_t historySize = other->getHistorySize();
342 mSamplePointerCoords.appendArray(other->mSamplePointerCoords.array()
343 + (historySize * pointerCount), pointerCount);
344 }
345}
346
Jeff Brown46b9ac02010-04-22 18:58:52 -0700347void MotionEvent::addSample(
348 int64_t eventTime,
349 const PointerCoords* pointerCoords) {
350 mSampleEventTimes.push(eventTime);
351 mSamplePointerCoords.appendArray(pointerCoords, getPointerCount());
352}
353
Jeff Brown91c69ab2011-02-14 17:03:18 -0800354const PointerCoords* MotionEvent::getRawPointerCoords(size_t pointerIndex) const {
355 return &mSamplePointerCoords[getHistorySize() * getPointerCount() + pointerIndex];
356}
357
358float MotionEvent::getRawAxisValue(int32_t axis, size_t pointerIndex) const {
359 return getRawPointerCoords(pointerIndex)->getAxisValue(axis);
360}
361
362float MotionEvent::getAxisValue(int32_t axis, size_t pointerIndex) const {
363 float value = getRawPointerCoords(pointerIndex)->getAxisValue(axis);
364 switch (axis) {
365 case AINPUT_MOTION_AXIS_X:
366 value += mXOffset;
367 break;
368 case AINPUT_MOTION_AXIS_Y:
369 value += mYOffset;
370 break;
371 }
372 return value;
373}
374
375const PointerCoords* MotionEvent::getHistoricalRawPointerCoords(
376 size_t pointerIndex, size_t historicalIndex) const {
377 return &mSamplePointerCoords[historicalIndex * getPointerCount() + pointerIndex];
378}
379
380float MotionEvent::getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
381 size_t historicalIndex) const {
382 return getHistoricalRawPointerCoords(pointerIndex, historicalIndex)->getAxisValue(axis);
383}
384
385float MotionEvent::getHistoricalAxisValue(int32_t axis, size_t pointerIndex,
386 size_t historicalIndex) const {
387 float value = getHistoricalRawPointerCoords(pointerIndex, historicalIndex)->getAxisValue(axis);
388 switch (axis) {
389 case AINPUT_MOTION_AXIS_X:
390 value += mXOffset;
391 break;
392 case AINPUT_MOTION_AXIS_Y:
393 value += mYOffset;
394 break;
395 }
396 return value;
397}
398
Jeff Brown46b9ac02010-04-22 18:58:52 -0700399void MotionEvent::offsetLocation(float xOffset, float yOffset) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700400 mXOffset += xOffset;
401 mYOffset += yOffset;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700402}
403
Jeff Brown91c69ab2011-02-14 17:03:18 -0800404static inline void scaleAxisValue(PointerCoords& c, int axis, float scaleFactor) {
405 float* value = c.editAxisValue(axis);
406 if (value) {
407 *value *= scaleFactor;
408 }
409}
410
411void MotionEvent::scale(float scaleFactor) {
412 mXOffset *= scaleFactor;
413 mYOffset *= scaleFactor;
414 mXPrecision *= scaleFactor;
415 mYPrecision *= scaleFactor;
416
417 size_t numSamples = mSamplePointerCoords.size();
418 for (size_t i = 0; i < numSamples; i++) {
419 PointerCoords& c = mSamplePointerCoords.editItemAt(i);
420 // No need to scale pressure or size since they are normalized.
421 // No need to scale orientation since it is meaningless to do so.
422 scaleAxisValue(c, AINPUT_MOTION_AXIS_X, scaleFactor);
423 scaleAxisValue(c, AINPUT_MOTION_AXIS_Y, scaleFactor);
424 scaleAxisValue(c, AINPUT_MOTION_AXIS_TOUCH_MAJOR, scaleFactor);
425 scaleAxisValue(c, AINPUT_MOTION_AXIS_TOUCH_MINOR, scaleFactor);
426 scaleAxisValue(c, AINPUT_MOTION_AXIS_TOOL_MAJOR, scaleFactor);
427 scaleAxisValue(c, AINPUT_MOTION_AXIS_TOOL_MINOR, scaleFactor);
428 }
429}
430
431#ifdef HAVE_ANDROID_OS
432static inline float transformAngle(const SkMatrix* matrix, float angleRadians) {
433 // Construct and transform a vector oriented at the specified clockwise angle from vertical.
434 // Coordinate system: down is increasing Y, right is increasing X.
435 SkPoint vector;
436 vector.fX = SkFloatToScalar(sinf(angleRadians));
437 vector.fY = SkFloatToScalar(-cosf(angleRadians));
438 matrix->mapVectors(& vector, 1);
439
440 // Derive the transformed vector's clockwise angle from vertical.
441 float result = atan2f(SkScalarToFloat(vector.fX), SkScalarToFloat(-vector.fY));
442 if (result < - M_PI_2) {
443 result += M_PI;
444 } else if (result > M_PI_2) {
445 result -= M_PI;
446 }
447 return result;
448}
449
450void MotionEvent::transform(const SkMatrix* matrix) {
451 float oldXOffset = mXOffset;
452 float oldYOffset = mYOffset;
453
454 // The tricky part of this implementation is to preserve the value of
455 // rawX and rawY. So we apply the transformation to the first point
456 // then derive an appropriate new X/Y offset that will preserve rawX and rawY.
457 SkPoint point;
458 float rawX = getRawX(0);
459 float rawY = getRawY(0);
460 matrix->mapXY(SkFloatToScalar(rawX + oldXOffset), SkFloatToScalar(rawY + oldYOffset),
461 & point);
462 float newX = SkScalarToFloat(point.fX);
463 float newY = SkScalarToFloat(point.fY);
464 float newXOffset = newX - rawX;
465 float newYOffset = newY - rawY;
466
467 mXOffset = newXOffset;
468 mYOffset = newYOffset;
469
470 // Apply the transformation to all samples.
471 size_t numSamples = mSamplePointerCoords.size();
472 for (size_t i = 0; i < numSamples; i++) {
473 PointerCoords& c = mSamplePointerCoords.editItemAt(i);
474 float* xPtr = c.editAxisValue(AINPUT_MOTION_AXIS_X);
475 float* yPtr = c.editAxisValue(AINPUT_MOTION_AXIS_Y);
476 if (xPtr && yPtr) {
477 float x = *xPtr + oldXOffset;
478 float y = *yPtr + oldYOffset;
479 matrix->mapXY(SkFloatToScalar(x), SkFloatToScalar(y), & point);
480 *xPtr = SkScalarToFloat(point.fX) - newXOffset;
481 *yPtr = SkScalarToFloat(point.fY) - newYOffset;
482 }
483
484 float* orientationPtr = c.editAxisValue(AINPUT_MOTION_AXIS_ORIENTATION);
485 if (orientationPtr) {
486 *orientationPtr = transformAngle(matrix, *orientationPtr);
487 }
488 }
489}
490
491status_t MotionEvent::readFromParcel(Parcel* parcel) {
492 size_t pointerCount = parcel->readInt32();
493 size_t sampleCount = parcel->readInt32();
494 if (pointerCount == 0 || pointerCount > MAX_POINTERS || sampleCount == 0) {
495 return BAD_VALUE;
496 }
497
498 mDeviceId = parcel->readInt32();
499 mSource = parcel->readInt32();
500 mAction = parcel->readInt32();
501 mFlags = parcel->readInt32();
502 mEdgeFlags = parcel->readInt32();
503 mMetaState = parcel->readInt32();
504 mXOffset = parcel->readFloat();
505 mYOffset = parcel->readFloat();
506 mXPrecision = parcel->readFloat();
507 mYPrecision = parcel->readFloat();
508 mDownTime = parcel->readInt64();
509
510 mPointerIds.clear();
511 mPointerIds.setCapacity(pointerCount);
512 mSampleEventTimes.clear();
513 mSampleEventTimes.setCapacity(sampleCount);
514 mSamplePointerCoords.clear();
515 mSamplePointerCoords.setCapacity(sampleCount * pointerCount);
516
517 for (size_t i = 0; i < pointerCount; i++) {
518 mPointerIds.push(parcel->readInt32());
519 }
520
521 while (sampleCount-- > 0) {
522 mSampleEventTimes.push(parcel->readInt64());
523 for (size_t i = 0; i < pointerCount; i++) {
524 mSamplePointerCoords.push();
525 status_t status = mSamplePointerCoords.editTop().readFromParcel(parcel);
526 if (!status) {
527 return status;
528 }
529 }
530 }
531 return OK;
532}
533
534status_t MotionEvent::writeToParcel(Parcel* parcel) const {
535 size_t pointerCount = mPointerIds.size();
536 size_t sampleCount = mSampleEventTimes.size();
537
538 parcel->writeInt32(pointerCount);
539 parcel->writeInt32(sampleCount);
540
541 parcel->writeInt32(mDeviceId);
542 parcel->writeInt32(mSource);
543 parcel->writeInt32(mAction);
544 parcel->writeInt32(mFlags);
545 parcel->writeInt32(mEdgeFlags);
546 parcel->writeInt32(mMetaState);
547 parcel->writeFloat(mXOffset);
548 parcel->writeFloat(mYOffset);
549 parcel->writeFloat(mXPrecision);
550 parcel->writeFloat(mYPrecision);
551 parcel->writeInt64(mDownTime);
552
553 for (size_t i = 0; i < pointerCount; i++) {
554 parcel->writeInt32(mPointerIds.itemAt(i));
555 }
556
557 const PointerCoords* pc = mSamplePointerCoords.array();
558 for (size_t h = 0; h < sampleCount; h++) {
559 parcel->writeInt64(mSampleEventTimes.itemAt(h));
560 for (size_t i = 0; i < pointerCount; i++) {
561 status_t status = (pc++)->writeToParcel(parcel);
562 if (!status) {
563 return status;
564 }
565 }
566 }
567 return OK;
568}
569#endif
570
571
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800572// --- InputDeviceInfo ---
Jeff Brown6d0fec22010-07-23 21:28:06 -0700573
574InputDeviceInfo::InputDeviceInfo() {
575 initialize(-1, String8("uninitialized device info"));
576}
577
578InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) :
579 mId(other.mId), mName(other.mName), mSources(other.mSources),
580 mKeyboardType(other.mKeyboardType),
581 mMotionRanges(other.mMotionRanges) {
582}
583
584InputDeviceInfo::~InputDeviceInfo() {
585}
586
587void InputDeviceInfo::initialize(int32_t id, const String8& name) {
588 mId = id;
589 mName = name;
590 mSources = 0;
591 mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE;
592 mMotionRanges.clear();
593}
594
Jeff Brown91c69ab2011-02-14 17:03:18 -0800595const InputDeviceInfo::MotionRange* InputDeviceInfo::getMotionRange(int32_t axis) const {
596 ssize_t index = mMotionRanges.indexOfKey(axis);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700597 return index >= 0 ? & mMotionRanges.valueAt(index) : NULL;
598}
599
600void InputDeviceInfo::addSource(uint32_t source) {
601 mSources |= source;
602}
603
Jeff Brown91c69ab2011-02-14 17:03:18 -0800604void InputDeviceInfo::addMotionRange(int32_t axis, float min, float max,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700605 float flat, float fuzz) {
606 MotionRange range = { min, max, flat, fuzz };
Jeff Brown91c69ab2011-02-14 17:03:18 -0800607 addMotionRange(axis, range);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700608}
609
Jeff Brown91c69ab2011-02-14 17:03:18 -0800610void InputDeviceInfo::addMotionRange(int32_t axis, const MotionRange& range) {
611 mMotionRanges.add(axis, range);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700612}
613
Jeff Brown46b9ac02010-04-22 18:58:52 -0700614} // namespace android