blob: 0af7f8043c35d9721b45e1be5a1b1982d6782497 [file] [log] [blame]
Jeff Browne839a582010-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 Brownfa773aa2011-03-09 17:39:48 -080010// Log debug messages about keymap probing.
Jeff Brown66888372010-11-29 17:37:49 -080011#define DEBUG_PROBE 0
12
Jeff Brownfa773aa2011-03-09 17:39:48 -080013// Log debug messages about velocity tracking.
14#define DEBUG_VELOCITY 0
15
Jeff Brownadab6202011-06-01 12:33:19 -070016// Log debug messages about acceleration.
17#define DEBUG_ACCELERATION 0
18
19
Jeff Brown66888372010-11-29 17:37:49 -080020#include <stdlib.h>
21#include <unistd.h>
Jeff Browndb360642010-12-02 13:50:46 -080022#include <ctype.h>
Jeff Brown66888372010-11-29 17:37:49 -080023
Jeff Browne839a582010-04-22 18:58:52 -070024#include <ui/Input.h>
25
Jeff Brown3e341462011-02-14 17:03:18 -080026#include <math.h>
Jeff Brownadab6202011-06-01 12:33:19 -070027#include <limits.h>
Jeff Brown3e341462011-02-14 17:03:18 -080028
29#ifdef HAVE_ANDROID_OS
30#include <binder/Parcel.h>
31
32#include "SkPoint.h"
33#include "SkMatrix.h"
34#include "SkScalar.h"
35#endif
36
Jeff Browne839a582010-04-22 18:58:52 -070037namespace android {
38
Jeff Brown66888372010-11-29 17:37:49 -080039static const char* CONFIGURATION_FILE_DIR[] = {
40 "idc/",
41 "keylayout/",
42 "keychars/",
43};
44
45static const char* CONFIGURATION_FILE_EXTENSION[] = {
46 ".idc",
47 ".kl",
48 ".kcm",
49};
50
Jeff Browndb360642010-12-02 13:50:46 -080051static bool isValidNameChar(char ch) {
52 return isascii(ch) && (isdigit(ch) || isalpha(ch) || ch == '-' || ch == '_');
53}
54
Jeff Brown66888372010-11-29 17:37:49 -080055static void appendInputDeviceConfigurationFileRelativePath(String8& path,
56 const String8& name, InputDeviceConfigurationFileType type) {
57 path.append(CONFIGURATION_FILE_DIR[type]);
58 for (size_t i = 0; i < name.length(); i++) {
59 char ch = name[i];
Jeff Browndb360642010-12-02 13:50:46 -080060 if (!isValidNameChar(ch)) {
Jeff Brown66888372010-11-29 17:37:49 -080061 ch = '_';
62 }
63 path.append(&ch, 1);
64 }
65 path.append(CONFIGURATION_FILE_EXTENSION[type]);
66}
67
Jeff Browndb360642010-12-02 13:50:46 -080068String8 getInputDeviceConfigurationFilePathByDeviceIdentifier(
69 const InputDeviceIdentifier& deviceIdentifier,
70 InputDeviceConfigurationFileType type) {
71 if (deviceIdentifier.vendor !=0 && deviceIdentifier.product != 0) {
72 if (deviceIdentifier.version != 0) {
73 // Try vendor product version.
74 String8 versionPath(getInputDeviceConfigurationFilePathByName(
75 String8::format("Vendor_%04x_Product_%04x_Version_%04x",
76 deviceIdentifier.vendor, deviceIdentifier.product,
77 deviceIdentifier.version),
78 type));
79 if (!versionPath.isEmpty()) {
80 return versionPath;
81 }
82 }
83
84 // Try vendor product.
85 String8 productPath(getInputDeviceConfigurationFilePathByName(
86 String8::format("Vendor_%04x_Product_%04x",
87 deviceIdentifier.vendor, deviceIdentifier.product),
88 type));
89 if (!productPath.isEmpty()) {
90 return productPath;
91 }
92 }
93
94 // Try device name.
95 return getInputDeviceConfigurationFilePathByName(deviceIdentifier.name, type);
96}
97
98String8 getInputDeviceConfigurationFilePathByName(
Jeff Brown66888372010-11-29 17:37:49 -080099 const String8& name, InputDeviceConfigurationFileType type) {
100 // Search system repository.
101 String8 path;
102 path.setTo(getenv("ANDROID_ROOT"));
103 path.append("/usr/");
104 appendInputDeviceConfigurationFileRelativePath(path, name, type);
105#if DEBUG_PROBE
106 LOGD("Probing for system provided input device configuration file: path='%s'", path.string());
107#endif
108 if (!access(path.string(), R_OK)) {
109#if DEBUG_PROBE
110 LOGD("Found");
111#endif
112 return path;
113 }
114
115 // Search user repository.
116 // TODO Should only look here if not in safe mode.
117 path.setTo(getenv("ANDROID_DATA"));
118 path.append("/system/devices/");
119 appendInputDeviceConfigurationFileRelativePath(path, name, type);
120#if DEBUG_PROBE
121 LOGD("Probing for system user input device configuration file: path='%s'", path.string());
122#endif
123 if (!access(path.string(), R_OK)) {
124#if DEBUG_PROBE
125 LOGD("Found");
126#endif
127 return path;
128 }
129
130 // Not found.
131#if DEBUG_PROBE
132 LOGD("Probe failed to find input device configuration file: name='%s', type=%d",
133 name.string(), type);
134#endif
135 return String8();
136}
137
138
139// --- InputEvent ---
Jeff Browne839a582010-04-22 18:58:52 -0700140
Jeff Brown5c1ed842010-07-14 18:48:53 -0700141void InputEvent::initialize(int32_t deviceId, int32_t source) {
Jeff Browne839a582010-04-22 18:58:52 -0700142 mDeviceId = deviceId;
Jeff Brown5c1ed842010-07-14 18:48:53 -0700143 mSource = source;
Jeff Browne839a582010-04-22 18:58:52 -0700144}
145
Dianne Hackborn0e885272010-07-15 17:44:53 -0700146void InputEvent::initialize(const InputEvent& from) {
147 mDeviceId = from.mDeviceId;
148 mSource = from.mSource;
149}
150
Jeff Brown66888372010-11-29 17:37:49 -0800151// --- KeyEvent ---
Jeff Browne839a582010-04-22 18:58:52 -0700152
Dianne Hackborn189ed232010-06-29 19:20:40 -0700153bool KeyEvent::hasDefaultAction(int32_t keyCode) {
154 switch (keyCode) {
Jeff Brown8575a872010-06-30 16:10:35 -0700155 case AKEYCODE_HOME:
156 case AKEYCODE_BACK:
157 case AKEYCODE_CALL:
158 case AKEYCODE_ENDCALL:
159 case AKEYCODE_VOLUME_UP:
160 case AKEYCODE_VOLUME_DOWN:
Jeff Brown7e5660f2010-11-01 15:24:01 -0700161 case AKEYCODE_VOLUME_MUTE:
Jeff Brown8575a872010-06-30 16:10:35 -0700162 case AKEYCODE_POWER:
163 case AKEYCODE_CAMERA:
164 case AKEYCODE_HEADSETHOOK:
165 case AKEYCODE_MENU:
166 case AKEYCODE_NOTIFICATION:
167 case AKEYCODE_FOCUS:
168 case AKEYCODE_SEARCH:
Jeff Brown7e5660f2010-11-01 15:24:01 -0700169 case AKEYCODE_MEDIA_PLAY:
170 case AKEYCODE_MEDIA_PAUSE:
Jeff Brown8575a872010-06-30 16:10:35 -0700171 case AKEYCODE_MEDIA_PLAY_PAUSE:
172 case AKEYCODE_MEDIA_STOP:
173 case AKEYCODE_MEDIA_NEXT:
174 case AKEYCODE_MEDIA_PREVIOUS:
175 case AKEYCODE_MEDIA_REWIND:
Jeff Brown7e5660f2010-11-01 15:24:01 -0700176 case AKEYCODE_MEDIA_RECORD:
Jeff Brown8575a872010-06-30 16:10:35 -0700177 case AKEYCODE_MEDIA_FAST_FORWARD:
178 case AKEYCODE_MUTE:
Dianne Hackborn189ed232010-06-29 19:20:40 -0700179 return true;
180 }
181
182 return false;
183}
184
185bool KeyEvent::hasDefaultAction() const {
186 return hasDefaultAction(getKeyCode());
187}
188
189bool KeyEvent::isSystemKey(int32_t keyCode) {
190 switch (keyCode) {
Jeff Brown8575a872010-06-30 16:10:35 -0700191 case AKEYCODE_MENU:
192 case AKEYCODE_SOFT_RIGHT:
193 case AKEYCODE_HOME:
194 case AKEYCODE_BACK:
195 case AKEYCODE_CALL:
196 case AKEYCODE_ENDCALL:
197 case AKEYCODE_VOLUME_UP:
198 case AKEYCODE_VOLUME_DOWN:
Jeff Brown7e5660f2010-11-01 15:24:01 -0700199 case AKEYCODE_VOLUME_MUTE:
Jeff Brown8575a872010-06-30 16:10:35 -0700200 case AKEYCODE_MUTE:
201 case AKEYCODE_POWER:
202 case AKEYCODE_HEADSETHOOK:
Jeff Brown7e5660f2010-11-01 15:24:01 -0700203 case AKEYCODE_MEDIA_PLAY:
204 case AKEYCODE_MEDIA_PAUSE:
Jeff Brown8575a872010-06-30 16:10:35 -0700205 case AKEYCODE_MEDIA_PLAY_PAUSE:
206 case AKEYCODE_MEDIA_STOP:
207 case AKEYCODE_MEDIA_NEXT:
208 case AKEYCODE_MEDIA_PREVIOUS:
209 case AKEYCODE_MEDIA_REWIND:
Jeff Brown7e5660f2010-11-01 15:24:01 -0700210 case AKEYCODE_MEDIA_RECORD:
Jeff Brown8575a872010-06-30 16:10:35 -0700211 case AKEYCODE_MEDIA_FAST_FORWARD:
212 case AKEYCODE_CAMERA:
213 case AKEYCODE_FOCUS:
214 case AKEYCODE_SEARCH:
Dianne Hackborn189ed232010-06-29 19:20:40 -0700215 return true;
216 }
217
218 return false;
219}
220
221bool KeyEvent::isSystemKey() const {
222 return isSystemKey(getKeyCode());
223}
224
Jeff Browne839a582010-04-22 18:58:52 -0700225void KeyEvent::initialize(
226 int32_t deviceId,
Jeff Brown5c1ed842010-07-14 18:48:53 -0700227 int32_t source,
Jeff Browne839a582010-04-22 18:58:52 -0700228 int32_t action,
229 int32_t flags,
230 int32_t keyCode,
231 int32_t scanCode,
232 int32_t metaState,
233 int32_t repeatCount,
234 nsecs_t downTime,
235 nsecs_t eventTime) {
Jeff Brown5c1ed842010-07-14 18:48:53 -0700236 InputEvent::initialize(deviceId, source);
Jeff Browne839a582010-04-22 18:58:52 -0700237 mAction = action;
238 mFlags = flags;
239 mKeyCode = keyCode;
240 mScanCode = scanCode;
241 mMetaState = metaState;
242 mRepeatCount = repeatCount;
243 mDownTime = downTime;
244 mEventTime = eventTime;
245}
246
Dianne Hackborn0e885272010-07-15 17:44:53 -0700247void KeyEvent::initialize(const KeyEvent& from) {
248 InputEvent::initialize(from);
249 mAction = from.mAction;
250 mFlags = from.mFlags;
251 mKeyCode = from.mKeyCode;
252 mScanCode = from.mScanCode;
253 mMetaState = from.mMetaState;
254 mRepeatCount = from.mRepeatCount;
255 mDownTime = from.mDownTime;
256 mEventTime = from.mEventTime;
257}
258
Jeff Brown3e341462011-02-14 17:03:18 -0800259
260// --- PointerCoords ---
261
Jeff Brown3ea4de82011-02-19 01:08:02 -0800262float PointerCoords::getAxisValue(int32_t axis) const {
263 if (axis < 0 || axis > 63) {
264 return 0;
265 }
266
267 uint64_t axisBit = 1LL << axis;
268 if (!(bits & axisBit)) {
269 return 0;
270 }
271 uint32_t index = __builtin_popcountll(bits & (axisBit - 1LL));
272 return values[index];
273}
274
275status_t PointerCoords::setAxisValue(int32_t axis, float value) {
276 if (axis < 0 || axis > 63) {
277 return NAME_NOT_FOUND;
278 }
279
280 uint64_t axisBit = 1LL << axis;
281 uint32_t index = __builtin_popcountll(bits & (axisBit - 1LL));
282 if (!(bits & axisBit)) {
283 uint32_t count = __builtin_popcountll(bits);
284 if (count >= MAX_AXES) {
285 tooManyAxes(axis);
286 return NO_MEMORY;
287 }
288 bits |= axisBit;
289 for (uint32_t i = count; i > index; i--) {
290 values[i] = values[i - 1];
291 }
292 }
293 values[index] = value;
294 return OK;
295}
296
297float* PointerCoords::editAxisValue(int32_t axis) {
298 if (axis < 0 || axis > 63) {
299 return NULL;
300 }
301
302 uint64_t axisBit = 1LL << axis;
303 if (!(bits & axisBit)) {
304 return NULL;
305 }
306 uint32_t index = __builtin_popcountll(bits & (axisBit - 1LL));
307 return &values[index];
308}
309
Dianne Hackborn16fe3c22011-04-27 18:52:56 -0400310static inline void scaleAxisValue(PointerCoords& c, int axis, float scaleFactor) {
311 float* value = c.editAxisValue(axis);
312 if (value) {
313 *value *= scaleFactor;
314 }
315}
316
317void PointerCoords::scale(float scaleFactor) {
318 // No need to scale pressure or size since they are normalized.
319 // No need to scale orientation since it is meaningless to do so.
320 scaleAxisValue(*this, AMOTION_EVENT_AXIS_X, scaleFactor);
321 scaleAxisValue(*this, AMOTION_EVENT_AXIS_Y, scaleFactor);
322 scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOUCH_MAJOR, scaleFactor);
323 scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOUCH_MINOR, scaleFactor);
324 scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOOL_MAJOR, scaleFactor);
325 scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOOL_MINOR, scaleFactor);
326}
327
Jeff Brown3e341462011-02-14 17:03:18 -0800328#ifdef HAVE_ANDROID_OS
329status_t PointerCoords::readFromParcel(Parcel* parcel) {
Jeff Brown3ea4de82011-02-19 01:08:02 -0800330 bits = parcel->readInt64();
Jeff Brown3e341462011-02-14 17:03:18 -0800331
Jeff Brown3ea4de82011-02-19 01:08:02 -0800332 uint32_t count = __builtin_popcountll(bits);
Jeff Brown3e341462011-02-14 17:03:18 -0800333 if (count > MAX_AXES) {
334 return BAD_VALUE;
335 }
336
337 for (uint32_t i = 0; i < count; i++) {
338 values[i] = parcel->readInt32();
339 }
340 return OK;
341}
342
343status_t PointerCoords::writeToParcel(Parcel* parcel) const {
Jeff Brown3ea4de82011-02-19 01:08:02 -0800344 parcel->writeInt64(bits);
Jeff Brown3e341462011-02-14 17:03:18 -0800345
Jeff Brown3ea4de82011-02-19 01:08:02 -0800346 uint32_t count = __builtin_popcountll(bits);
Jeff Brown3e341462011-02-14 17:03:18 -0800347 for (uint32_t i = 0; i < count; i++) {
348 parcel->writeInt32(values[i]);
349 }
350 return OK;
351}
352#endif
353
354void PointerCoords::tooManyAxes(int axis) {
355 LOGW("Could not set value for axis %d because the PointerCoords structure is full and "
356 "cannot contain more than %d axis values.", axis, int(MAX_AXES));
357}
358
Jeff Brownfa773aa2011-03-09 17:39:48 -0800359bool PointerCoords::operator==(const PointerCoords& other) const {
360 if (bits != other.bits) {
361 return false;
362 }
363 uint32_t count = __builtin_popcountll(bits);
364 for (uint32_t i = 0; i < count; i++) {
365 if (values[i] != other.values[i]) {
366 return false;
367 }
368 }
369 return true;
370}
371
372void PointerCoords::copyFrom(const PointerCoords& other) {
373 bits = other.bits;
374 uint32_t count = __builtin_popcountll(bits);
375 for (uint32_t i = 0; i < count; i++) {
376 values[i] = other.values[i];
377 }
378}
379
Jeff Brown3e341462011-02-14 17:03:18 -0800380
Jeff Browne959ed22011-05-06 18:20:01 -0700381// --- PointerProperties ---
382
383bool PointerProperties::operator==(const PointerProperties& other) const {
384 return id == other.id
385 && toolType == other.toolType;
386}
387
388void PointerProperties::copyFrom(const PointerProperties& other) {
389 id = other.id;
390 toolType = other.toolType;
391}
392
393
Jeff Brown66888372010-11-29 17:37:49 -0800394// --- MotionEvent ---
Jeff Browne839a582010-04-22 18:58:52 -0700395
396void MotionEvent::initialize(
397 int32_t deviceId,
Jeff Brown5c1ed842010-07-14 18:48:53 -0700398 int32_t source,
Jeff Browne839a582010-04-22 18:58:52 -0700399 int32_t action,
Jeff Brownaf30ff62010-09-01 17:01:00 -0700400 int32_t flags,
Jeff Browne839a582010-04-22 18:58:52 -0700401 int32_t edgeFlags,
402 int32_t metaState,
Jeff Browne959ed22011-05-06 18:20:01 -0700403 int32_t buttonState,
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700404 float xOffset,
405 float yOffset,
Jeff Browne839a582010-04-22 18:58:52 -0700406 float xPrecision,
407 float yPrecision,
408 nsecs_t downTime,
409 nsecs_t eventTime,
410 size_t pointerCount,
Jeff Browne959ed22011-05-06 18:20:01 -0700411 const PointerProperties* pointerProperties,
Jeff Browne839a582010-04-22 18:58:52 -0700412 const PointerCoords* pointerCoords) {
Jeff Brown5c1ed842010-07-14 18:48:53 -0700413 InputEvent::initialize(deviceId, source);
Jeff Browne839a582010-04-22 18:58:52 -0700414 mAction = action;
Jeff Brownaf30ff62010-09-01 17:01:00 -0700415 mFlags = flags;
Jeff Browne839a582010-04-22 18:58:52 -0700416 mEdgeFlags = edgeFlags;
417 mMetaState = metaState;
Jeff Browne959ed22011-05-06 18:20:01 -0700418 mButtonState = buttonState;
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700419 mXOffset = xOffset;
420 mYOffset = yOffset;
Jeff Browne839a582010-04-22 18:58:52 -0700421 mXPrecision = xPrecision;
422 mYPrecision = yPrecision;
423 mDownTime = downTime;
Jeff Browne959ed22011-05-06 18:20:01 -0700424 mPointerProperties.clear();
425 mPointerProperties.appendArray(pointerProperties, pointerCount);
Jeff Browne839a582010-04-22 18:58:52 -0700426 mSampleEventTimes.clear();
427 mSamplePointerCoords.clear();
428 addSample(eventTime, pointerCoords);
429}
430
Jeff Brown3e341462011-02-14 17:03:18 -0800431void MotionEvent::copyFrom(const MotionEvent* other, bool keepHistory) {
432 InputEvent::initialize(other->mDeviceId, other->mSource);
433 mAction = other->mAction;
434 mFlags = other->mFlags;
435 mEdgeFlags = other->mEdgeFlags;
436 mMetaState = other->mMetaState;
Jeff Browne959ed22011-05-06 18:20:01 -0700437 mButtonState = other->mButtonState;
Jeff Brown3e341462011-02-14 17:03:18 -0800438 mXOffset = other->mXOffset;
439 mYOffset = other->mYOffset;
440 mXPrecision = other->mXPrecision;
441 mYPrecision = other->mYPrecision;
442 mDownTime = other->mDownTime;
Jeff Browne959ed22011-05-06 18:20:01 -0700443 mPointerProperties = other->mPointerProperties;
Jeff Brown3e341462011-02-14 17:03:18 -0800444
445 if (keepHistory) {
446 mSampleEventTimes = other->mSampleEventTimes;
447 mSamplePointerCoords = other->mSamplePointerCoords;
448 } else {
449 mSampleEventTimes.clear();
450 mSampleEventTimes.push(other->getEventTime());
451 mSamplePointerCoords.clear();
452 size_t pointerCount = other->getPointerCount();
453 size_t historySize = other->getHistorySize();
454 mSamplePointerCoords.appendArray(other->mSamplePointerCoords.array()
455 + (historySize * pointerCount), pointerCount);
456 }
457}
458
Jeff Browne839a582010-04-22 18:58:52 -0700459void MotionEvent::addSample(
460 int64_t eventTime,
461 const PointerCoords* pointerCoords) {
462 mSampleEventTimes.push(eventTime);
463 mSamplePointerCoords.appendArray(pointerCoords, getPointerCount());
464}
465
Jeff Brown3e341462011-02-14 17:03:18 -0800466const PointerCoords* MotionEvent::getRawPointerCoords(size_t pointerIndex) const {
467 return &mSamplePointerCoords[getHistorySize() * getPointerCount() + pointerIndex];
468}
469
470float MotionEvent::getRawAxisValue(int32_t axis, size_t pointerIndex) const {
471 return getRawPointerCoords(pointerIndex)->getAxisValue(axis);
472}
473
474float MotionEvent::getAxisValue(int32_t axis, size_t pointerIndex) const {
475 float value = getRawPointerCoords(pointerIndex)->getAxisValue(axis);
476 switch (axis) {
Jeff Brownb2d44352011-02-17 13:01:34 -0800477 case AMOTION_EVENT_AXIS_X:
Dianne Hackborn16fe3c22011-04-27 18:52:56 -0400478 return value + mXOffset;
Jeff Brownb2d44352011-02-17 13:01:34 -0800479 case AMOTION_EVENT_AXIS_Y:
Dianne Hackborn16fe3c22011-04-27 18:52:56 -0400480 return value + mYOffset;
Jeff Brown3e341462011-02-14 17:03:18 -0800481 }
482 return value;
483}
484
485const PointerCoords* MotionEvent::getHistoricalRawPointerCoords(
486 size_t pointerIndex, size_t historicalIndex) const {
487 return &mSamplePointerCoords[historicalIndex * getPointerCount() + pointerIndex];
488}
489
490float MotionEvent::getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
491 size_t historicalIndex) const {
492 return getHistoricalRawPointerCoords(pointerIndex, historicalIndex)->getAxisValue(axis);
493}
494
495float MotionEvent::getHistoricalAxisValue(int32_t axis, size_t pointerIndex,
496 size_t historicalIndex) const {
497 float value = getHistoricalRawPointerCoords(pointerIndex, historicalIndex)->getAxisValue(axis);
498 switch (axis) {
Jeff Brownb2d44352011-02-17 13:01:34 -0800499 case AMOTION_EVENT_AXIS_X:
Dianne Hackborn16fe3c22011-04-27 18:52:56 -0400500 return value + mXOffset;
Jeff Brownb2d44352011-02-17 13:01:34 -0800501 case AMOTION_EVENT_AXIS_Y:
Dianne Hackborn16fe3c22011-04-27 18:52:56 -0400502 return value + mYOffset;
Jeff Brown3e341462011-02-14 17:03:18 -0800503 }
504 return value;
505}
506
Jeff Brown15933542011-03-14 19:39:54 -0700507ssize_t MotionEvent::findPointerIndex(int32_t pointerId) const {
Jeff Browne959ed22011-05-06 18:20:01 -0700508 size_t pointerCount = mPointerProperties.size();
Jeff Brown15933542011-03-14 19:39:54 -0700509 for (size_t i = 0; i < pointerCount; i++) {
Jeff Browne959ed22011-05-06 18:20:01 -0700510 if (mPointerProperties.itemAt(i).id == pointerId) {
Jeff Brown15933542011-03-14 19:39:54 -0700511 return i;
512 }
513 }
514 return -1;
515}
516
Jeff Browne839a582010-04-22 18:58:52 -0700517void MotionEvent::offsetLocation(float xOffset, float yOffset) {
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700518 mXOffset += xOffset;
519 mYOffset += yOffset;
Jeff Browne839a582010-04-22 18:58:52 -0700520}
521
Jeff Brown3e341462011-02-14 17:03:18 -0800522void MotionEvent::scale(float scaleFactor) {
523 mXOffset *= scaleFactor;
524 mYOffset *= scaleFactor;
525 mXPrecision *= scaleFactor;
526 mYPrecision *= scaleFactor;
527
528 size_t numSamples = mSamplePointerCoords.size();
529 for (size_t i = 0; i < numSamples; i++) {
Dianne Hackborn16fe3c22011-04-27 18:52:56 -0400530 mSamplePointerCoords.editItemAt(i).scale(scaleFactor);
Jeff Brown3e341462011-02-14 17:03:18 -0800531 }
532}
533
534#ifdef HAVE_ANDROID_OS
535static inline float transformAngle(const SkMatrix* matrix, float angleRadians) {
536 // Construct and transform a vector oriented at the specified clockwise angle from vertical.
537 // Coordinate system: down is increasing Y, right is increasing X.
538 SkPoint vector;
539 vector.fX = SkFloatToScalar(sinf(angleRadians));
540 vector.fY = SkFloatToScalar(-cosf(angleRadians));
541 matrix->mapVectors(& vector, 1);
542
543 // Derive the transformed vector's clockwise angle from vertical.
544 float result = atan2f(SkScalarToFloat(vector.fX), SkScalarToFloat(-vector.fY));
545 if (result < - M_PI_2) {
546 result += M_PI;
547 } else if (result > M_PI_2) {
548 result -= M_PI;
549 }
550 return result;
551}
552
553void MotionEvent::transform(const SkMatrix* matrix) {
554 float oldXOffset = mXOffset;
555 float oldYOffset = mYOffset;
556
557 // The tricky part of this implementation is to preserve the value of
558 // rawX and rawY. So we apply the transformation to the first point
559 // then derive an appropriate new X/Y offset that will preserve rawX and rawY.
560 SkPoint point;
561 float rawX = getRawX(0);
562 float rawY = getRawY(0);
563 matrix->mapXY(SkFloatToScalar(rawX + oldXOffset), SkFloatToScalar(rawY + oldYOffset),
564 & point);
565 float newX = SkScalarToFloat(point.fX);
566 float newY = SkScalarToFloat(point.fY);
567 float newXOffset = newX - rawX;
568 float newYOffset = newY - rawY;
569
570 mXOffset = newXOffset;
571 mYOffset = newYOffset;
572
573 // Apply the transformation to all samples.
574 size_t numSamples = mSamplePointerCoords.size();
575 for (size_t i = 0; i < numSamples; i++) {
576 PointerCoords& c = mSamplePointerCoords.editItemAt(i);
Jeff Brownb2d44352011-02-17 13:01:34 -0800577 float* xPtr = c.editAxisValue(AMOTION_EVENT_AXIS_X);
578 float* yPtr = c.editAxisValue(AMOTION_EVENT_AXIS_Y);
Jeff Brown3e341462011-02-14 17:03:18 -0800579 if (xPtr && yPtr) {
580 float x = *xPtr + oldXOffset;
581 float y = *yPtr + oldYOffset;
582 matrix->mapXY(SkFloatToScalar(x), SkFloatToScalar(y), & point);
583 *xPtr = SkScalarToFloat(point.fX) - newXOffset;
584 *yPtr = SkScalarToFloat(point.fY) - newYOffset;
585 }
586
Jeff Brownb2d44352011-02-17 13:01:34 -0800587 float* orientationPtr = c.editAxisValue(AMOTION_EVENT_AXIS_ORIENTATION);
Jeff Brown3e341462011-02-14 17:03:18 -0800588 if (orientationPtr) {
589 *orientationPtr = transformAngle(matrix, *orientationPtr);
590 }
591 }
592}
593
594status_t MotionEvent::readFromParcel(Parcel* parcel) {
595 size_t pointerCount = parcel->readInt32();
596 size_t sampleCount = parcel->readInt32();
597 if (pointerCount == 0 || pointerCount > MAX_POINTERS || sampleCount == 0) {
598 return BAD_VALUE;
599 }
600
601 mDeviceId = parcel->readInt32();
602 mSource = parcel->readInt32();
603 mAction = parcel->readInt32();
604 mFlags = parcel->readInt32();
605 mEdgeFlags = parcel->readInt32();
606 mMetaState = parcel->readInt32();
Jeff Browne959ed22011-05-06 18:20:01 -0700607 mButtonState = parcel->readInt32();
Jeff Brown3e341462011-02-14 17:03:18 -0800608 mXOffset = parcel->readFloat();
609 mYOffset = parcel->readFloat();
610 mXPrecision = parcel->readFloat();
611 mYPrecision = parcel->readFloat();
612 mDownTime = parcel->readInt64();
613
Jeff Browne959ed22011-05-06 18:20:01 -0700614 mPointerProperties.clear();
615 mPointerProperties.setCapacity(pointerCount);
Jeff Brown3e341462011-02-14 17:03:18 -0800616 mSampleEventTimes.clear();
617 mSampleEventTimes.setCapacity(sampleCount);
618 mSamplePointerCoords.clear();
619 mSamplePointerCoords.setCapacity(sampleCount * pointerCount);
620
621 for (size_t i = 0; i < pointerCount; i++) {
Jeff Browne959ed22011-05-06 18:20:01 -0700622 mPointerProperties.push();
623 PointerProperties& properties = mPointerProperties.editTop();
624 properties.id = parcel->readInt32();
625 properties.toolType = parcel->readInt32();
Jeff Brown3e341462011-02-14 17:03:18 -0800626 }
627
628 while (sampleCount-- > 0) {
629 mSampleEventTimes.push(parcel->readInt64());
630 for (size_t i = 0; i < pointerCount; i++) {
631 mSamplePointerCoords.push();
632 status_t status = mSamplePointerCoords.editTop().readFromParcel(parcel);
Jeff Brownb2d44352011-02-17 13:01:34 -0800633 if (status) {
Jeff Brown3e341462011-02-14 17:03:18 -0800634 return status;
635 }
636 }
637 }
638 return OK;
639}
640
641status_t MotionEvent::writeToParcel(Parcel* parcel) const {
Jeff Browne959ed22011-05-06 18:20:01 -0700642 size_t pointerCount = mPointerProperties.size();
Jeff Brown3e341462011-02-14 17:03:18 -0800643 size_t sampleCount = mSampleEventTimes.size();
644
645 parcel->writeInt32(pointerCount);
646 parcel->writeInt32(sampleCount);
647
648 parcel->writeInt32(mDeviceId);
649 parcel->writeInt32(mSource);
650 parcel->writeInt32(mAction);
651 parcel->writeInt32(mFlags);
652 parcel->writeInt32(mEdgeFlags);
653 parcel->writeInt32(mMetaState);
Jeff Browne959ed22011-05-06 18:20:01 -0700654 parcel->writeInt32(mButtonState);
Jeff Brown3e341462011-02-14 17:03:18 -0800655 parcel->writeFloat(mXOffset);
656 parcel->writeFloat(mYOffset);
657 parcel->writeFloat(mXPrecision);
658 parcel->writeFloat(mYPrecision);
659 parcel->writeInt64(mDownTime);
660
661 for (size_t i = 0; i < pointerCount; i++) {
Jeff Browne959ed22011-05-06 18:20:01 -0700662 const PointerProperties& properties = mPointerProperties.itemAt(i);
663 parcel->writeInt32(properties.id);
664 parcel->writeInt32(properties.toolType);
Jeff Brown3e341462011-02-14 17:03:18 -0800665 }
666
667 const PointerCoords* pc = mSamplePointerCoords.array();
668 for (size_t h = 0; h < sampleCount; h++) {
669 parcel->writeInt64(mSampleEventTimes.itemAt(h));
670 for (size_t i = 0; i < pointerCount; i++) {
671 status_t status = (pc++)->writeToParcel(parcel);
Jeff Brownb2d44352011-02-17 13:01:34 -0800672 if (status) {
Jeff Brown3e341462011-02-14 17:03:18 -0800673 return status;
674 }
675 }
676 }
677 return OK;
678}
679#endif
680
Jeff Brownd5ed2852011-03-02 19:23:13 -0800681bool MotionEvent::isTouchEvent(int32_t source, int32_t action) {
682 if (source & AINPUT_SOURCE_CLASS_POINTER) {
683 // Specifically excludes HOVER_MOVE and SCROLL.
684 switch (action & AMOTION_EVENT_ACTION_MASK) {
685 case AMOTION_EVENT_ACTION_DOWN:
686 case AMOTION_EVENT_ACTION_MOVE:
687 case AMOTION_EVENT_ACTION_UP:
688 case AMOTION_EVENT_ACTION_POINTER_DOWN:
689 case AMOTION_EVENT_ACTION_POINTER_UP:
690 case AMOTION_EVENT_ACTION_CANCEL:
691 case AMOTION_EVENT_ACTION_OUTSIDE:
692 return true;
693 }
694 }
695 return false;
696}
697
Jeff Brown3e341462011-02-14 17:03:18 -0800698
Jeff Brownfa773aa2011-03-09 17:39:48 -0800699// --- VelocityTracker ---
700
Jeff Brownadab6202011-06-01 12:33:19 -0700701const uint32_t VelocityTracker::HISTORY_SIZE;
702const nsecs_t VelocityTracker::MAX_AGE;
Jeff Brownadab6202011-06-01 12:33:19 -0700703const nsecs_t VelocityTracker::MIN_DURATION;
704
Jeff Brownfa773aa2011-03-09 17:39:48 -0800705VelocityTracker::VelocityTracker() {
706 clear();
707}
708
709void VelocityTracker::clear() {
710 mIndex = 0;
711 mMovements[0].idBits.clear();
Jeff Brown15933542011-03-14 19:39:54 -0700712 mActivePointerId = -1;
713}
714
715void VelocityTracker::clearPointers(BitSet32 idBits) {
716 BitSet32 remainingIdBits(mMovements[mIndex].idBits.value & ~idBits.value);
717 mMovements[mIndex].idBits = remainingIdBits;
718
719 if (mActivePointerId >= 0 && idBits.hasBit(mActivePointerId)) {
720 mActivePointerId = !remainingIdBits.isEmpty() ? remainingIdBits.firstMarkedBit() : -1;
721 }
Jeff Brownfa773aa2011-03-09 17:39:48 -0800722}
723
724void VelocityTracker::addMovement(nsecs_t eventTime, BitSet32 idBits, const Position* positions) {
725 if (++mIndex == HISTORY_SIZE) {
726 mIndex = 0;
727 }
Jeff Brown15933542011-03-14 19:39:54 -0700728
729 while (idBits.count() > MAX_POINTERS) {
730 idBits.clearBit(idBits.lastMarkedBit());
731 }
732
Jeff Brownfa773aa2011-03-09 17:39:48 -0800733 Movement& movement = mMovements[mIndex];
734 movement.eventTime = eventTime;
735 movement.idBits = idBits;
736 uint32_t count = idBits.count();
737 for (uint32_t i = 0; i < count; i++) {
738 movement.positions[i] = positions[i];
739 }
740
Jeff Brown15933542011-03-14 19:39:54 -0700741 if (mActivePointerId < 0 || !idBits.hasBit(mActivePointerId)) {
742 mActivePointerId = count != 0 ? idBits.firstMarkedBit() : -1;
743 }
744
Jeff Brownfa773aa2011-03-09 17:39:48 -0800745#if DEBUG_VELOCITY
Jeff Brown15933542011-03-14 19:39:54 -0700746 LOGD("VelocityTracker: addMovement eventTime=%lld, idBits=0x%08x, activePointerId=%d",
747 eventTime, idBits.value, mActivePointerId);
Jeff Brownfa773aa2011-03-09 17:39:48 -0800748 for (BitSet32 iterBits(idBits); !iterBits.isEmpty(); ) {
749 uint32_t id = iterBits.firstMarkedBit();
750 uint32_t index = idBits.getIndexOfBit(id);
751 iterBits.clearBit(id);
752 float vx, vy;
753 bool available = getVelocity(id, &vx, &vy);
754 if (available) {
Jeff Brown15933542011-03-14 19:39:54 -0700755 LOGD(" %d: position (%0.3f, %0.3f), vx=%0.3f, vy=%0.3f, speed=%0.3f",
Jeff Brownfa773aa2011-03-09 17:39:48 -0800756 id, positions[index].x, positions[index].y, vx, vy, sqrtf(vx * vx + vy * vy));
757 } else {
Jeff Brown23e0c8c2011-04-01 16:15:13 -0700758 LOG_ASSERT(vx == 0 && vy == 0);
Jeff Brownfa773aa2011-03-09 17:39:48 -0800759 LOGD(" %d: position (%0.3f, %0.3f), velocity not available",
760 id, positions[index].x, positions[index].y);
761 }
762 }
763#endif
764}
765
Jeff Brown15933542011-03-14 19:39:54 -0700766void VelocityTracker::addMovement(const MotionEvent* event) {
767 int32_t actionMasked = event->getActionMasked();
768
769 switch (actionMasked) {
770 case AMOTION_EVENT_ACTION_DOWN:
771 // Clear all pointers on down before adding the new movement.
772 clear();
773 break;
774 case AMOTION_EVENT_ACTION_POINTER_DOWN: {
775 // Start a new movement trace for a pointer that just went down.
776 // We do this on down instead of on up because the client may want to query the
777 // final velocity for a pointer that just went up.
778 BitSet32 downIdBits;
779 downIdBits.markBit(event->getActionIndex());
780 clearPointers(downIdBits);
781 break;
782 }
783 case AMOTION_EVENT_ACTION_OUTSIDE:
784 case AMOTION_EVENT_ACTION_CANCEL:
785 case AMOTION_EVENT_ACTION_SCROLL:
786 case AMOTION_EVENT_ACTION_UP:
787 case AMOTION_EVENT_ACTION_POINTER_UP:
788 // Ignore these actions because they do not convey any new information about
789 // pointer movement. We also want to preserve the last known velocity of the pointers.
790 // Note that ACTION_UP and ACTION_POINTER_UP always report the last known position
791 // of the pointers that went up. ACTION_POINTER_UP does include the new position of
792 // pointers that remained down but we will also receive an ACTION_MOVE with this
793 // information if any of them actually moved. Since we don't know how many pointers
794 // will be going up at once it makes sense to just wait for the following ACTION_MOVE
795 // before adding the movement.
796 return;
797 }
798
799 size_t pointerCount = event->getPointerCount();
800 if (pointerCount > MAX_POINTERS) {
801 pointerCount = MAX_POINTERS;
802 }
803
804 BitSet32 idBits;
805 for (size_t i = 0; i < pointerCount; i++) {
806 idBits.markBit(event->getPointerId(i));
807 }
808
809 nsecs_t eventTime;
810 Position positions[pointerCount];
811
812 size_t historySize = event->getHistorySize();
813 for (size_t h = 0; h < historySize; h++) {
814 eventTime = event->getHistoricalEventTime(h);
815 for (size_t i = 0; i < pointerCount; i++) {
816 positions[i].x = event->getHistoricalX(i, h);
817 positions[i].y = event->getHistoricalY(i, h);
818 }
819 addMovement(eventTime, idBits, positions);
820 }
821
822 eventTime = event->getEventTime();
823 for (size_t i = 0; i < pointerCount; i++) {
824 positions[i].x = event->getX(i);
825 positions[i].y = event->getY(i);
826 }
827 addMovement(eventTime, idBits, positions);
828}
829
Jeff Brownfa773aa2011-03-09 17:39:48 -0800830bool VelocityTracker::getVelocity(uint32_t id, float* outVx, float* outVy) const {
831 const Movement& newestMovement = mMovements[mIndex];
832 if (newestMovement.idBits.hasBit(id)) {
833 // Find the oldest sample that contains the pointer and that is not older than MAX_AGE.
834 nsecs_t minTime = newestMovement.eventTime - MAX_AGE;
835 uint32_t oldestIndex = mIndex;
836 uint32_t numTouches = 1;
837 do {
838 uint32_t nextOldestIndex = (oldestIndex == 0 ? HISTORY_SIZE : oldestIndex) - 1;
839 const Movement& nextOldestMovement = mMovements[nextOldestIndex];
840 if (!nextOldestMovement.idBits.hasBit(id)
841 || nextOldestMovement.eventTime < minTime) {
842 break;
843 }
844 oldestIndex = nextOldestIndex;
845 } while (++numTouches < HISTORY_SIZE);
846
Jeff Brown15933542011-03-14 19:39:54 -0700847 // Calculate an exponentially weighted moving average of the velocity estimate
848 // at different points in time measured relative to the oldest sample.
849 // This is essentially an IIR filter. Newer samples are weighted more heavily
850 // than older samples. Samples at equal time points are weighted more or less
851 // equally.
Jeff Brownfa773aa2011-03-09 17:39:48 -0800852 //
Jeff Brown15933542011-03-14 19:39:54 -0700853 // One tricky problem is that the sample data may be poorly conditioned.
Jeff Brownfa773aa2011-03-09 17:39:48 -0800854 // Sometimes samples arrive very close together in time which can cause us to
855 // overestimate the velocity at that time point. Most samples might be measured
Jeff Brown15933542011-03-14 19:39:54 -0700856 // 16ms apart but some consecutive samples could be only 0.5sm apart because
857 // the hardware or driver reports them irregularly or in bursts.
Jeff Brownfa773aa2011-03-09 17:39:48 -0800858 float accumVx = 0;
859 float accumVy = 0;
860 uint32_t index = oldestIndex;
861 uint32_t samplesUsed = 0;
862 const Movement& oldestMovement = mMovements[oldestIndex];
863 const Position& oldestPosition =
864 oldestMovement.positions[oldestMovement.idBits.getIndexOfBit(id)];
Jeff Brown15933542011-03-14 19:39:54 -0700865 nsecs_t lastDuration = 0;
Jeff Brown4815f2a2011-04-12 22:39:53 -0700866
Jeff Brownfa773aa2011-03-09 17:39:48 -0800867 while (numTouches-- > 1) {
868 if (++index == HISTORY_SIZE) {
869 index = 0;
870 }
871 const Movement& movement = mMovements[index];
872 nsecs_t duration = movement.eventTime - oldestMovement.eventTime;
Jeff Brown15933542011-03-14 19:39:54 -0700873
874 // If the duration between samples is small, we may significantly overestimate
875 // the velocity. Consequently, we impose a minimum duration constraint on the
876 // samples that we include in the calculation.
877 if (duration >= MIN_DURATION) {
Jeff Brownfa773aa2011-03-09 17:39:48 -0800878 const Position& position = movement.positions[movement.idBits.getIndexOfBit(id)];
879 float scale = 1000000000.0f / duration; // one over time delta in seconds
880 float vx = (position.x - oldestPosition.x) * scale;
881 float vy = (position.y - oldestPosition.y) * scale;
Jeff Brown15933542011-03-14 19:39:54 -0700882
883 accumVx = (accumVx * lastDuration + vx * duration) / (duration + lastDuration);
884 accumVy = (accumVy * lastDuration + vy * duration) / (duration + lastDuration);
885
886 lastDuration = duration;
Jeff Brownfa773aa2011-03-09 17:39:48 -0800887 samplesUsed += 1;
888 }
889 }
890
891 // Make sure we used at least one sample.
892 if (samplesUsed != 0) {
893 *outVx = accumVx;
894 *outVy = accumVy;
895 return true;
896 }
897 }
898
899 // No data available for this pointer.
900 *outVx = 0;
901 *outVy = 0;
902 return false;
903}
904
905
Jeff Brownadab6202011-06-01 12:33:19 -0700906// --- VelocityControl ---
907
908const nsecs_t VelocityControl::STOP_TIME;
909
910VelocityControl::VelocityControl() {
911 reset();
912}
913
914void VelocityControl::setParameters(const VelocityControlParameters& parameters) {
915 mParameters = parameters;
916 reset();
917}
918
919void VelocityControl::reset() {
920 mLastMovementTime = LLONG_MIN;
921 mRawPosition.x = 0;
922 mRawPosition.y = 0;
923 mVelocityTracker.clear();
924}
925
926void VelocityControl::move(nsecs_t eventTime, float* deltaX, float* deltaY) {
927 if ((deltaX && *deltaX) || (deltaY && *deltaY)) {
928 if (eventTime >= mLastMovementTime + STOP_TIME) {
929#if DEBUG_ACCELERATION
930 LOGD("VelocityControl: stopped, last movement was %0.3fms ago",
931 (eventTime - mLastMovementTime) * 0.000001f);
932#endif
933 reset();
934 }
935
936 mLastMovementTime = eventTime;
937 if (deltaX) {
938 mRawPosition.x += *deltaX;
939 }
940 if (deltaY) {
941 mRawPosition.y += *deltaY;
942 }
943 mVelocityTracker.addMovement(eventTime, BitSet32(BitSet32::valueForBit(0)), &mRawPosition);
944
945 float vx, vy;
946 float scale = mParameters.scale;
947 if (mVelocityTracker.getVelocity(0, &vx, &vy)) {
948 float speed = hypotf(vx, vy) * scale;
949 if (speed >= mParameters.highThreshold) {
950 // Apply full acceleration above the high speed threshold.
951 scale *= mParameters.acceleration;
952 } else if (speed > mParameters.lowThreshold) {
953 // Linearly interpolate the acceleration to apply between the low and high
954 // speed thresholds.
955 scale *= 1 + (speed - mParameters.lowThreshold)
956 / (mParameters.highThreshold - mParameters.lowThreshold)
957 * (mParameters.acceleration - 1);
958 }
959
960#if DEBUG_ACCELERATION
961 LOGD("VelocityControl(%0.3f, %0.3f, %0.3f, %0.3f): "
962 "vx=%0.3f, vy=%0.3f, speed=%0.3f, accel=%0.3f",
963 mParameters.scale, mParameters.lowThreshold, mParameters.highThreshold,
964 mParameters.acceleration,
965 vx, vy, speed, scale / mParameters.scale);
966#endif
967 } else {
968#if DEBUG_ACCELERATION
969 LOGD("VelocityControl(%0.3f, %0.3f, %0.3f, %0.3f): unknown velocity",
970 mParameters.scale, mParameters.lowThreshold, mParameters.highThreshold,
971 mParameters.acceleration);
972#endif
973 }
974
975 if (deltaX) {
976 *deltaX *= scale;
977 }
978 if (deltaY) {
979 *deltaY *= scale;
980 }
981 }
982}
983
984
Jeff Brown66888372010-11-29 17:37:49 -0800985// --- InputDeviceInfo ---
Jeff Browne57e8952010-07-23 21:28:06 -0700986
987InputDeviceInfo::InputDeviceInfo() {
988 initialize(-1, String8("uninitialized device info"));
989}
990
991InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) :
992 mId(other.mId), mName(other.mName), mSources(other.mSources),
993 mKeyboardType(other.mKeyboardType),
994 mMotionRanges(other.mMotionRanges) {
995}
996
997InputDeviceInfo::~InputDeviceInfo() {
998}
999
1000void InputDeviceInfo::initialize(int32_t id, const String8& name) {
1001 mId = id;
1002 mName = name;
1003 mSources = 0;
1004 mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE;
1005 mMotionRanges.clear();
1006}
1007
Jeff Brown46689da2011-03-08 15:13:06 -08001008const InputDeviceInfo::MotionRange* InputDeviceInfo::getMotionRange(
1009 int32_t axis, uint32_t source) const {
1010 size_t numRanges = mMotionRanges.size();
1011 for (size_t i = 0; i < numRanges; i++) {
1012 const MotionRange& range = mMotionRanges.itemAt(i);
1013 if (range.axis == axis && range.source == source) {
1014 return &range;
1015 }
1016 }
1017 return NULL;
Jeff Browne57e8952010-07-23 21:28:06 -07001018}
1019
1020void InputDeviceInfo::addSource(uint32_t source) {
1021 mSources |= source;
1022}
1023
Jeff Brown46689da2011-03-08 15:13:06 -08001024void InputDeviceInfo::addMotionRange(int32_t axis, uint32_t source, float min, float max,
Jeff Browne57e8952010-07-23 21:28:06 -07001025 float flat, float fuzz) {
Jeff Brown46689da2011-03-08 15:13:06 -08001026 MotionRange range = { axis, source, min, max, flat, fuzz };
1027 mMotionRanges.add(range);
Jeff Browne57e8952010-07-23 21:28:06 -07001028}
1029
Jeff Brown46689da2011-03-08 15:13:06 -08001030void InputDeviceInfo::addMotionRange(const MotionRange& range) {
1031 mMotionRanges.add(range);
Jeff Browne57e8952010-07-23 21:28:06 -07001032}
1033
Jeff Browne839a582010-04-22 18:58:52 -07001034} // namespace android