InputReader_test.cpp revision 2120617f2fb10035022d1a3e76836a278a0e6a18
1/* 2 * Copyright (C) 2010 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 17#include "../InputReader.h" 18 19#include <utils/List.h> 20#include <gtest/gtest.h> 21#include <math.h> 22 23namespace android { 24 25// An arbitrary time value. 26static const nsecs_t ARBITRARY_TIME = 1234; 27 28// Arbitrary display properties. 29static const int32_t DISPLAY_ID = 0; 30static const int32_t DISPLAY_WIDTH = 480; 31static const int32_t DISPLAY_HEIGHT = 800; 32 33// Error tolerance for floating point assertions. 34static const float EPSILON = 0.001f; 35 36template<typename T> 37static inline T min(T a, T b) { 38 return a < b ? a : b; 39} 40 41static inline float avg(float x, float y) { 42 return (x + y) / 2; 43} 44 45 46// --- FakePointerController --- 47 48class FakePointerController : public PointerControllerInterface { 49 bool mHaveBounds; 50 float mMinX, mMinY, mMaxX, mMaxY; 51 52protected: 53 virtual ~FakePointerController() { } 54 55public: 56 FakePointerController() : 57 mHaveBounds(false), mMinX(0), mMinY(0), mMaxX(0), mMaxY(0) { 58 } 59 60 void setBounds(float minX, float minY, float maxX, float maxY) { 61 mHaveBounds = true; 62 mMinX = minX; 63 mMinY = minY; 64 mMaxX = maxX; 65 mMaxY = maxY; 66 } 67 68private: 69 virtual bool getBounds(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const { 70 *outMinX = mMinX; 71 *outMinY = mMinY; 72 *outMaxX = mMaxX; 73 *outMaxY = mMaxY; 74 return mHaveBounds; 75 } 76 77 virtual void move(float deltaX, float deltaY) { 78 } 79 80 virtual void setButtonState(uint32_t buttonState) { 81 } 82 83 virtual uint32_t getButtonState() const { 84 return 0; 85 } 86 87 virtual void setPosition(float x, float y) { 88 } 89 90 virtual void getPosition(float* outX, float* outY) const { 91 *outX = 0; 92 *outY = 0; 93 } 94 95 virtual void fade() { 96 } 97 98 virtual void unfade() { 99 } 100}; 101 102 103// --- FakeInputReaderPolicy --- 104 105class FakeInputReaderPolicy : public InputReaderPolicyInterface { 106 struct DisplayInfo { 107 int32_t width; 108 int32_t height; 109 int32_t orientation; 110 }; 111 112 KeyedVector<int32_t, DisplayInfo> mDisplayInfos; 113 bool mFilterTouchEvents; 114 bool mFilterJumpyTouchEvents; 115 Vector<String8> mExcludedDeviceNames; 116 KeyedVector<int32_t, sp<FakePointerController> > mPointerControllers; 117 118protected: 119 virtual ~FakeInputReaderPolicy() { } 120 121public: 122 FakeInputReaderPolicy() : 123 mFilterTouchEvents(false), mFilterJumpyTouchEvents(false) { 124 } 125 126 void removeDisplayInfo(int32_t displayId) { 127 mDisplayInfos.removeItem(displayId); 128 } 129 130 void setDisplayInfo(int32_t displayId, int32_t width, int32_t height, int32_t orientation) { 131 removeDisplayInfo(displayId); 132 133 DisplayInfo info; 134 info.width = width; 135 info.height = height; 136 info.orientation = orientation; 137 mDisplayInfos.add(displayId, info); 138 } 139 140 void setFilterTouchEvents(bool enabled) { 141 mFilterTouchEvents = enabled; 142 } 143 144 void setFilterJumpyTouchEvents(bool enabled) { 145 mFilterJumpyTouchEvents = enabled; 146 } 147 148 virtual nsecs_t getVirtualKeyQuietTime() { 149 return 0; 150 } 151 152 void addExcludedDeviceName(const String8& deviceName) { 153 mExcludedDeviceNames.push(deviceName); 154 } 155 156 void setPointerController(int32_t deviceId, const sp<FakePointerController>& controller) { 157 mPointerControllers.add(deviceId, controller); 158 } 159 160private: 161 virtual bool getDisplayInfo(int32_t displayId, 162 int32_t* width, int32_t* height, int32_t* orientation) { 163 ssize_t index = mDisplayInfos.indexOfKey(displayId); 164 if (index >= 0) { 165 const DisplayInfo& info = mDisplayInfos.valueAt(index); 166 if (width) { 167 *width = info.width; 168 } 169 if (height) { 170 *height = info.height; 171 } 172 if (orientation) { 173 *orientation = info.orientation; 174 } 175 return true; 176 } 177 return false; 178 } 179 180 virtual bool filterTouchEvents() { 181 return mFilterTouchEvents; 182 } 183 184 virtual bool filterJumpyTouchEvents() { 185 return mFilterJumpyTouchEvents; 186 } 187 188 virtual void getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames) { 189 outExcludedDeviceNames.appendVector(mExcludedDeviceNames); 190 } 191 192 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) { 193 return mPointerControllers.valueFor(deviceId); 194 } 195}; 196 197 198// --- FakeInputDispatcher --- 199 200class FakeInputDispatcher : public InputDispatcherInterface { 201public: 202 struct NotifyConfigurationChangedArgs { 203 NotifyConfigurationChangedArgs() : eventTime(0) { } 204 205 nsecs_t eventTime; 206 }; 207 208 struct NotifyKeyArgs { 209 nsecs_t eventTime; 210 int32_t deviceId; 211 uint32_t source; 212 uint32_t policyFlags; 213 int32_t action; 214 int32_t flags; 215 int32_t keyCode; 216 int32_t scanCode; 217 int32_t metaState; 218 nsecs_t downTime; 219 }; 220 221 struct NotifyMotionArgs { 222 nsecs_t eventTime; 223 int32_t deviceId; 224 uint32_t source; 225 uint32_t policyFlags; 226 int32_t action; 227 int32_t flags; 228 int32_t metaState; 229 int32_t edgeFlags; 230 uint32_t pointerCount; 231 Vector<int32_t> pointerIds; 232 Vector<PointerCoords> pointerCoords; 233 float xPrecision; 234 float yPrecision; 235 nsecs_t downTime; 236 }; 237 238 struct NotifySwitchArgs { 239 nsecs_t when; 240 int32_t switchCode; 241 int32_t switchValue; 242 uint32_t policyFlags; 243 }; 244 245private: 246 List<NotifyConfigurationChangedArgs> mNotifyConfigurationChangedArgs; 247 List<NotifyKeyArgs> mNotifyKeyArgs; 248 List<NotifyMotionArgs> mNotifyMotionArgs; 249 List<NotifySwitchArgs> mNotifySwitchArgs; 250 251protected: 252 virtual ~FakeInputDispatcher() { } 253 254public: 255 FakeInputDispatcher() { 256 } 257 258 void assertNotifyConfigurationChangedWasCalled(NotifyConfigurationChangedArgs* outArgs = NULL) { 259 ASSERT_FALSE(mNotifyConfigurationChangedArgs.empty()) 260 << "Expected notifyConfigurationChanged() to have been called."; 261 if (outArgs) { 262 *outArgs = *mNotifyConfigurationChangedArgs.begin(); 263 } 264 mNotifyConfigurationChangedArgs.erase(mNotifyConfigurationChangedArgs.begin()); 265 } 266 267 void assertNotifyKeyWasCalled(NotifyKeyArgs* outArgs = NULL) { 268 ASSERT_FALSE(mNotifyKeyArgs.empty()) 269 << "Expected notifyKey() to have been called."; 270 if (outArgs) { 271 *outArgs = *mNotifyKeyArgs.begin(); 272 } 273 mNotifyKeyArgs.erase(mNotifyKeyArgs.begin()); 274 } 275 276 void assertNotifyKeyWasNotCalled() { 277 ASSERT_TRUE(mNotifyKeyArgs.empty()) 278 << "Expected notifyKey() to not have been called."; 279 } 280 281 void assertNotifyMotionWasCalled(NotifyMotionArgs* outArgs = NULL) { 282 ASSERT_FALSE(mNotifyMotionArgs.empty()) 283 << "Expected notifyMotion() to have been called."; 284 if (outArgs) { 285 *outArgs = *mNotifyMotionArgs.begin(); 286 } 287 mNotifyMotionArgs.erase(mNotifyMotionArgs.begin()); 288 } 289 290 void assertNotifyMotionWasNotCalled() { 291 ASSERT_TRUE(mNotifyMotionArgs.empty()) 292 << "Expected notifyMotion() to not have been called."; 293 } 294 295 void assertNotifySwitchWasCalled(NotifySwitchArgs* outArgs = NULL) { 296 ASSERT_FALSE(mNotifySwitchArgs.empty()) 297 << "Expected notifySwitch() to have been called."; 298 if (outArgs) { 299 *outArgs = *mNotifySwitchArgs.begin(); 300 } 301 mNotifySwitchArgs.erase(mNotifySwitchArgs.begin()); 302 } 303 304private: 305 virtual void notifyConfigurationChanged(nsecs_t eventTime) { 306 NotifyConfigurationChangedArgs args; 307 args.eventTime = eventTime; 308 mNotifyConfigurationChangedArgs.push_back(args); 309 } 310 311 virtual void notifyKey(nsecs_t eventTime, int32_t deviceId, uint32_t source, 312 uint32_t policyFlags, int32_t action, int32_t flags, int32_t keyCode, 313 int32_t scanCode, int32_t metaState, nsecs_t downTime) { 314 NotifyKeyArgs args; 315 args.eventTime = eventTime; 316 args.deviceId = deviceId; 317 args.source = source; 318 args.policyFlags = policyFlags; 319 args.action = action; 320 args.flags = flags; 321 args.keyCode = keyCode; 322 args.scanCode = scanCode; 323 args.metaState = metaState; 324 args.downTime = downTime; 325 mNotifyKeyArgs.push_back(args); 326 } 327 328 virtual void notifyMotion(nsecs_t eventTime, int32_t deviceId, uint32_t source, 329 uint32_t policyFlags, int32_t action, int32_t flags, 330 int32_t metaState, int32_t edgeFlags, 331 uint32_t pointerCount, const int32_t* pointerIds, const PointerCoords* pointerCoords, 332 float xPrecision, float yPrecision, nsecs_t downTime) { 333 NotifyMotionArgs args; 334 args.eventTime = eventTime; 335 args.deviceId = deviceId; 336 args.source = source; 337 args.policyFlags = policyFlags; 338 args.action = action; 339 args.flags = flags; 340 args.metaState = metaState; 341 args.edgeFlags = edgeFlags; 342 args.pointerCount = pointerCount; 343 args.pointerIds.clear(); 344 args.pointerIds.appendArray(pointerIds, pointerCount); 345 args.pointerCoords.clear(); 346 args.pointerCoords.appendArray(pointerCoords, pointerCount); 347 args.xPrecision = xPrecision; 348 args.yPrecision = yPrecision; 349 args.downTime = downTime; 350 mNotifyMotionArgs.push_back(args); 351 } 352 353 virtual void notifySwitch(nsecs_t when, 354 int32_t switchCode, int32_t switchValue, uint32_t policyFlags) { 355 NotifySwitchArgs args; 356 args.when = when; 357 args.switchCode = switchCode; 358 args.switchValue = switchValue; 359 args.policyFlags = policyFlags; 360 mNotifySwitchArgs.push_back(args); 361 } 362 363 virtual void dump(String8& dump) { 364 ADD_FAILURE() << "Should never be called by input reader."; 365 } 366 367 virtual void dispatchOnce() { 368 ADD_FAILURE() << "Should never be called by input reader."; 369 } 370 371 virtual int32_t injectInputEvent(const InputEvent* event, 372 int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis) { 373 ADD_FAILURE() << "Should never be called by input reader."; 374 return INPUT_EVENT_INJECTION_FAILED; 375 } 376 377 virtual void setInputWindows(const Vector<InputWindow>& inputWindows) { 378 ADD_FAILURE() << "Should never be called by input reader."; 379 } 380 381 virtual void setFocusedApplication(const InputApplication* inputApplication) { 382 ADD_FAILURE() << "Should never be called by input reader."; 383 } 384 385 virtual void setInputDispatchMode(bool enabled, bool frozen) { 386 ADD_FAILURE() << "Should never be called by input reader."; 387 } 388 389 virtual bool transferTouchFocus(const sp<InputChannel>& fromChannel, 390 const sp<InputChannel>& toChannel) { 391 ADD_FAILURE() << "Should never be called by input reader."; 392 return 0; 393 } 394 395 virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel, 396 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) { 397 ADD_FAILURE() << "Should never be called by input reader."; 398 return 0; 399 } 400 401 virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel) { 402 ADD_FAILURE() << "Should never be called by input reader."; 403 return 0; 404 } 405}; 406 407 408// --- FakeEventHub --- 409 410class FakeEventHub : public EventHubInterface { 411 struct KeyInfo { 412 int32_t keyCode; 413 uint32_t flags; 414 }; 415 416 struct Device { 417 String8 name; 418 uint32_t classes; 419 PropertyMap configuration; 420 KeyedVector<int, RawAbsoluteAxisInfo> absoluteAxes; 421 KeyedVector<int, bool> relativeAxes; 422 KeyedVector<int32_t, int32_t> keyCodeStates; 423 KeyedVector<int32_t, int32_t> scanCodeStates; 424 KeyedVector<int32_t, int32_t> switchStates; 425 KeyedVector<int32_t, KeyInfo> keys; 426 KeyedVector<int32_t, bool> leds; 427 Vector<VirtualKeyDefinition> virtualKeys; 428 429 Device(const String8& name, uint32_t classes) : 430 name(name), classes(classes) { 431 } 432 }; 433 434 KeyedVector<int32_t, Device*> mDevices; 435 Vector<String8> mExcludedDevices; 436 List<RawEvent> mEvents; 437 438protected: 439 virtual ~FakeEventHub() { 440 for (size_t i = 0; i < mDevices.size(); i++) { 441 delete mDevices.valueAt(i); 442 } 443 } 444 445public: 446 FakeEventHub() { } 447 448 void addDevice(int32_t deviceId, const String8& name, uint32_t classes) { 449 Device* device = new Device(name, classes); 450 mDevices.add(deviceId, device); 451 452 enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_ADDED, 0, 0, 0, 0); 453 } 454 455 void removeDevice(int32_t deviceId) { 456 delete mDevices.valueFor(deviceId); 457 mDevices.removeItem(deviceId); 458 459 enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_REMOVED, 0, 0, 0, 0); 460 } 461 462 void finishDeviceScan() { 463 enqueueEvent(ARBITRARY_TIME, 0, EventHubInterface::FINISHED_DEVICE_SCAN, 0, 0, 0, 0); 464 } 465 466 void addConfigurationProperty(int32_t deviceId, const String8& key, const String8& value) { 467 Device* device = getDevice(deviceId); 468 device->configuration.addProperty(key, value); 469 } 470 471 void addConfigurationMap(int32_t deviceId, const PropertyMap* configuration) { 472 Device* device = getDevice(deviceId); 473 device->configuration.addAll(configuration); 474 } 475 476 void addAbsoluteAxis(int32_t deviceId, int axis, 477 int32_t minValue, int32_t maxValue, int flat, int fuzz) { 478 Device* device = getDevice(deviceId); 479 480 RawAbsoluteAxisInfo info; 481 info.valid = true; 482 info.minValue = minValue; 483 info.maxValue = maxValue; 484 info.flat = flat; 485 info.fuzz = fuzz; 486 device->absoluteAxes.add(axis, info); 487 } 488 489 void addRelativeAxis(int32_t deviceId, int32_t axis) { 490 Device* device = getDevice(deviceId); 491 device->relativeAxes.add(axis, true); 492 } 493 494 void setKeyCodeState(int32_t deviceId, int32_t keyCode, int32_t state) { 495 Device* device = getDevice(deviceId); 496 device->keyCodeStates.replaceValueFor(keyCode, state); 497 } 498 499 void setScanCodeState(int32_t deviceId, int32_t scanCode, int32_t state) { 500 Device* device = getDevice(deviceId); 501 device->scanCodeStates.replaceValueFor(scanCode, state); 502 } 503 504 void setSwitchState(int32_t deviceId, int32_t switchCode, int32_t state) { 505 Device* device = getDevice(deviceId); 506 device->switchStates.replaceValueFor(switchCode, state); 507 } 508 509 void addKey(int32_t deviceId, int32_t scanCode, int32_t keyCode, uint32_t flags) { 510 Device* device = getDevice(deviceId); 511 KeyInfo info; 512 info.keyCode = keyCode; 513 info.flags = flags; 514 device->keys.add(scanCode, info); 515 } 516 517 void addLed(int32_t deviceId, int32_t led, bool initialState) { 518 Device* device = getDevice(deviceId); 519 device->leds.add(led, initialState); 520 } 521 522 bool getLedState(int32_t deviceId, int32_t led) { 523 Device* device = getDevice(deviceId); 524 return device->leds.valueFor(led); 525 } 526 527 Vector<String8>& getExcludedDevices() { 528 return mExcludedDevices; 529 } 530 531 void addVirtualKeyDefinition(int32_t deviceId, const VirtualKeyDefinition& definition) { 532 Device* device = getDevice(deviceId); 533 device->virtualKeys.push(definition); 534 } 535 536 void enqueueEvent(nsecs_t when, int32_t deviceId, int32_t type, 537 int32_t scanCode, int32_t keyCode, int32_t value, uint32_t flags) { 538 RawEvent event; 539 event.when = when; 540 event.deviceId = deviceId; 541 event.type = type; 542 event.scanCode = scanCode; 543 event.keyCode = keyCode; 544 event.value = value; 545 event.flags = flags; 546 mEvents.push_back(event); 547 } 548 549 void assertQueueIsEmpty() { 550 ASSERT_EQ(size_t(0), mEvents.size()) 551 << "Expected the event queue to be empty (fully consumed)."; 552 } 553 554private: 555 Device* getDevice(int32_t deviceId) const { 556 ssize_t index = mDevices.indexOfKey(deviceId); 557 return index >= 0 ? mDevices.valueAt(index) : NULL; 558 } 559 560 virtual uint32_t getDeviceClasses(int32_t deviceId) const { 561 Device* device = getDevice(deviceId); 562 return device ? device->classes : 0; 563 } 564 565 virtual String8 getDeviceName(int32_t deviceId) const { 566 Device* device = getDevice(deviceId); 567 return device ? device->name : String8("unknown"); 568 } 569 570 virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const { 571 Device* device = getDevice(deviceId); 572 if (device) { 573 *outConfiguration = device->configuration; 574 } 575 } 576 577 virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, 578 RawAbsoluteAxisInfo* outAxisInfo) const { 579 Device* device = getDevice(deviceId); 580 if (device) { 581 ssize_t index = device->absoluteAxes.indexOfKey(axis); 582 if (index >= 0) { 583 *outAxisInfo = device->absoluteAxes.valueAt(index); 584 return OK; 585 } 586 } 587 return -1; 588 } 589 590 virtual bool hasRelativeAxis(int32_t deviceId, int axis) const { 591 Device* device = getDevice(deviceId); 592 if (device) { 593 return device->relativeAxes.indexOfKey(axis) >= 0; 594 } 595 return false; 596 } 597 598 virtual status_t mapKey(int32_t deviceId, int scancode, 599 int32_t* outKeycode, uint32_t* outFlags) const { 600 Device* device = getDevice(deviceId); 601 if (device) { 602 ssize_t index = device->keys.indexOfKey(scancode); 603 if (index >= 0) { 604 if (outKeycode) { 605 *outKeycode = device->keys.valueAt(index).keyCode; 606 } 607 if (outFlags) { 608 *outFlags = device->keys.valueAt(index).flags; 609 } 610 return OK; 611 } 612 } 613 return NAME_NOT_FOUND; 614 } 615 616 virtual status_t mapAxis(int32_t deviceId, int scancode, 617 AxisInfo* outAxisInfo) const { 618 return NAME_NOT_FOUND; 619 } 620 621 virtual void addExcludedDevice(const char* deviceName) { 622 mExcludedDevices.add(String8(deviceName)); 623 } 624 625 virtual bool getEvent(RawEvent* outEvent) { 626 if (mEvents.empty()) { 627 return false; 628 } 629 630 *outEvent = *mEvents.begin(); 631 mEvents.erase(mEvents.begin()); 632 return true; 633 } 634 635 virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const { 636 Device* device = getDevice(deviceId); 637 if (device) { 638 ssize_t index = device->scanCodeStates.indexOfKey(scanCode); 639 if (index >= 0) { 640 return device->scanCodeStates.valueAt(index); 641 } 642 } 643 return AKEY_STATE_UNKNOWN; 644 } 645 646 virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const { 647 Device* device = getDevice(deviceId); 648 if (device) { 649 ssize_t index = device->keyCodeStates.indexOfKey(keyCode); 650 if (index >= 0) { 651 return device->keyCodeStates.valueAt(index); 652 } 653 } 654 return AKEY_STATE_UNKNOWN; 655 } 656 657 virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const { 658 Device* device = getDevice(deviceId); 659 if (device) { 660 ssize_t index = device->switchStates.indexOfKey(sw); 661 if (index >= 0) { 662 return device->switchStates.valueAt(index); 663 } 664 } 665 return AKEY_STATE_UNKNOWN; 666 } 667 668 virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes, 669 uint8_t* outFlags) const { 670 bool result = false; 671 Device* device = getDevice(deviceId); 672 if (device) { 673 for (size_t i = 0; i < numCodes; i++) { 674 for (size_t j = 0; j < device->keys.size(); j++) { 675 if (keyCodes[i] == device->keys.valueAt(j).keyCode) { 676 outFlags[i] = 1; 677 result = true; 678 } 679 } 680 } 681 } 682 return result; 683 } 684 685 virtual bool hasLed(int32_t deviceId, int32_t led) const { 686 Device* device = getDevice(deviceId); 687 return device && device->leds.indexOfKey(led) >= 0; 688 } 689 690 virtual void setLedState(int32_t deviceId, int32_t led, bool on) { 691 Device* device = getDevice(deviceId); 692 if (device) { 693 ssize_t index = device->leds.indexOfKey(led); 694 if (index >= 0) { 695 device->leds.replaceValueAt(led, on); 696 } else { 697 ADD_FAILURE() 698 << "Attempted to set the state of an LED that the EventHub declared " 699 "was not present. led=" << led; 700 } 701 } 702 } 703 704 virtual void getVirtualKeyDefinitions(int32_t deviceId, 705 Vector<VirtualKeyDefinition>& outVirtualKeys) const { 706 outVirtualKeys.clear(); 707 708 Device* device = getDevice(deviceId); 709 if (device) { 710 outVirtualKeys.appendVector(device->virtualKeys); 711 } 712 } 713 714 virtual bool isExternal(int32_t deviceId) const { 715 return false; 716 } 717 718 virtual void dump(String8& dump) { 719 } 720}; 721 722 723// --- FakeInputReaderContext --- 724 725class FakeInputReaderContext : public InputReaderContext { 726 sp<EventHubInterface> mEventHub; 727 sp<InputReaderPolicyInterface> mPolicy; 728 sp<InputDispatcherInterface> mDispatcher; 729 int32_t mGlobalMetaState; 730 bool mUpdateGlobalMetaStateWasCalled; 731 732public: 733 FakeInputReaderContext(const sp<EventHubInterface>& eventHub, 734 const sp<InputReaderPolicyInterface>& policy, 735 const sp<InputDispatcherInterface>& dispatcher) : 736 mEventHub(eventHub), mPolicy(policy), mDispatcher(dispatcher), 737 mGlobalMetaState(0) { 738 } 739 740 virtual ~FakeInputReaderContext() { } 741 742 void assertUpdateGlobalMetaStateWasCalled() { 743 ASSERT_TRUE(mUpdateGlobalMetaStateWasCalled) 744 << "Expected updateGlobalMetaState() to have been called."; 745 mUpdateGlobalMetaStateWasCalled = false; 746 } 747 748 void setGlobalMetaState(int32_t state) { 749 mGlobalMetaState = state; 750 } 751 752private: 753 virtual void updateGlobalMetaState() { 754 mUpdateGlobalMetaStateWasCalled = true; 755 } 756 757 virtual int32_t getGlobalMetaState() { 758 return mGlobalMetaState; 759 } 760 761 virtual EventHubInterface* getEventHub() { 762 return mEventHub.get(); 763 } 764 765 virtual InputReaderPolicyInterface* getPolicy() { 766 return mPolicy.get(); 767 } 768 769 virtual InputDispatcherInterface* getDispatcher() { 770 return mDispatcher.get(); 771 } 772 773 virtual void disableVirtualKeysUntil(nsecs_t time) { 774 } 775 776 virtual bool shouldDropVirtualKey(nsecs_t now, 777 InputDevice* device, int32_t keyCode, int32_t scanCode) { 778 return false; 779 } 780 781 virtual void fadePointer() { 782 } 783}; 784 785 786// --- FakeInputMapper --- 787 788class FakeInputMapper : public InputMapper { 789 uint32_t mSources; 790 int32_t mKeyboardType; 791 int32_t mMetaState; 792 KeyedVector<int32_t, int32_t> mKeyCodeStates; 793 KeyedVector<int32_t, int32_t> mScanCodeStates; 794 KeyedVector<int32_t, int32_t> mSwitchStates; 795 Vector<int32_t> mSupportedKeyCodes; 796 RawEvent mLastEvent; 797 798 bool mConfigureWasCalled; 799 bool mResetWasCalled; 800 bool mProcessWasCalled; 801 802public: 803 FakeInputMapper(InputDevice* device, uint32_t sources) : 804 InputMapper(device), 805 mSources(sources), mKeyboardType(AINPUT_KEYBOARD_TYPE_NONE), 806 mMetaState(0), 807 mConfigureWasCalled(false), mResetWasCalled(false), mProcessWasCalled(false) { 808 } 809 810 virtual ~FakeInputMapper() { } 811 812 void setKeyboardType(int32_t keyboardType) { 813 mKeyboardType = keyboardType; 814 } 815 816 void setMetaState(int32_t metaState) { 817 mMetaState = metaState; 818 } 819 820 void assertConfigureWasCalled() { 821 ASSERT_TRUE(mConfigureWasCalled) 822 << "Expected configure() to have been called."; 823 mConfigureWasCalled = false; 824 } 825 826 void assertResetWasCalled() { 827 ASSERT_TRUE(mResetWasCalled) 828 << "Expected reset() to have been called."; 829 mResetWasCalled = false; 830 } 831 832 void assertProcessWasCalled(RawEvent* outLastEvent = NULL) { 833 ASSERT_TRUE(mProcessWasCalled) 834 << "Expected process() to have been called."; 835 if (outLastEvent) { 836 *outLastEvent = mLastEvent; 837 } 838 mProcessWasCalled = false; 839 } 840 841 void setKeyCodeState(int32_t keyCode, int32_t state) { 842 mKeyCodeStates.replaceValueFor(keyCode, state); 843 } 844 845 void setScanCodeState(int32_t scanCode, int32_t state) { 846 mScanCodeStates.replaceValueFor(scanCode, state); 847 } 848 849 void setSwitchState(int32_t switchCode, int32_t state) { 850 mSwitchStates.replaceValueFor(switchCode, state); 851 } 852 853 void addSupportedKeyCode(int32_t keyCode) { 854 mSupportedKeyCodes.add(keyCode); 855 } 856 857private: 858 virtual uint32_t getSources() { 859 return mSources; 860 } 861 862 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo) { 863 InputMapper::populateDeviceInfo(deviceInfo); 864 865 if (mKeyboardType != AINPUT_KEYBOARD_TYPE_NONE) { 866 deviceInfo->setKeyboardType(mKeyboardType); 867 } 868 } 869 870 virtual void configure() { 871 mConfigureWasCalled = true; 872 } 873 874 virtual void reset() { 875 mResetWasCalled = true; 876 } 877 878 virtual void process(const RawEvent* rawEvent) { 879 mLastEvent = *rawEvent; 880 mProcessWasCalled = true; 881 } 882 883 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode) { 884 ssize_t index = mKeyCodeStates.indexOfKey(keyCode); 885 return index >= 0 ? mKeyCodeStates.valueAt(index) : AKEY_STATE_UNKNOWN; 886 } 887 888 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) { 889 ssize_t index = mScanCodeStates.indexOfKey(scanCode); 890 return index >= 0 ? mScanCodeStates.valueAt(index) : AKEY_STATE_UNKNOWN; 891 } 892 893 virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode) { 894 ssize_t index = mSwitchStates.indexOfKey(switchCode); 895 return index >= 0 ? mSwitchStates.valueAt(index) : AKEY_STATE_UNKNOWN; 896 } 897 898 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, 899 const int32_t* keyCodes, uint8_t* outFlags) { 900 bool result = false; 901 for (size_t i = 0; i < numCodes; i++) { 902 for (size_t j = 0; j < mSupportedKeyCodes.size(); j++) { 903 if (keyCodes[i] == mSupportedKeyCodes[j]) { 904 outFlags[i] = 1; 905 result = true; 906 } 907 } 908 } 909 return result; 910 } 911 912 virtual int32_t getMetaState() { 913 return mMetaState; 914 } 915 916 virtual void fadePointer() { 917 } 918}; 919 920 921// --- InstrumentedInputReader --- 922 923class InstrumentedInputReader : public InputReader { 924 InputDevice* mNextDevice; 925 926public: 927 InstrumentedInputReader(const sp<EventHubInterface>& eventHub, 928 const sp<InputReaderPolicyInterface>& policy, 929 const sp<InputDispatcherInterface>& dispatcher) : 930 InputReader(eventHub, policy, dispatcher), 931 mNextDevice(NULL) { 932 } 933 934 virtual ~InstrumentedInputReader() { 935 if (mNextDevice) { 936 delete mNextDevice; 937 } 938 } 939 940 void setNextDevice(InputDevice* device) { 941 mNextDevice = device; 942 } 943 944protected: 945 virtual InputDevice* createDevice(int32_t deviceId, const String8& name, uint32_t classes) { 946 if (mNextDevice) { 947 InputDevice* device = mNextDevice; 948 mNextDevice = NULL; 949 return device; 950 } 951 return InputReader::createDevice(deviceId, name, classes); 952 } 953 954 friend class InputReaderTest; 955}; 956 957 958// --- InputReaderTest --- 959 960class InputReaderTest : public testing::Test { 961protected: 962 sp<FakeInputDispatcher> mFakeDispatcher; 963 sp<FakeInputReaderPolicy> mFakePolicy; 964 sp<FakeEventHub> mFakeEventHub; 965 sp<InstrumentedInputReader> mReader; 966 967 virtual void SetUp() { 968 mFakeEventHub = new FakeEventHub(); 969 mFakePolicy = new FakeInputReaderPolicy(); 970 mFakeDispatcher = new FakeInputDispatcher(); 971 972 mReader = new InstrumentedInputReader(mFakeEventHub, mFakePolicy, mFakeDispatcher); 973 } 974 975 virtual void TearDown() { 976 mReader.clear(); 977 978 mFakeDispatcher.clear(); 979 mFakePolicy.clear(); 980 mFakeEventHub.clear(); 981 } 982 983 void addDevice(int32_t deviceId, const String8& name, uint32_t classes, 984 const PropertyMap* configuration) { 985 mFakeEventHub->addDevice(deviceId, name, classes); 986 if (configuration) { 987 mFakeEventHub->addConfigurationMap(deviceId, configuration); 988 } 989 mFakeEventHub->finishDeviceScan(); 990 mReader->loopOnce(); 991 mReader->loopOnce(); 992 mFakeEventHub->assertQueueIsEmpty(); 993 } 994 995 FakeInputMapper* addDeviceWithFakeInputMapper(int32_t deviceId, 996 const String8& name, uint32_t classes, uint32_t sources, 997 const PropertyMap* configuration) { 998 InputDevice* device = new InputDevice(mReader.get(), deviceId, name); 999 FakeInputMapper* mapper = new FakeInputMapper(device, sources); 1000 device->addMapper(mapper); 1001 mReader->setNextDevice(device); 1002 addDevice(deviceId, name, classes, configuration); 1003 return mapper; 1004 } 1005}; 1006 1007TEST_F(InputReaderTest, GetInputConfiguration_WhenNoDevices_ReturnsDefaults) { 1008 InputConfiguration config; 1009 mReader->getInputConfiguration(&config); 1010 1011 ASSERT_EQ(InputConfiguration::KEYBOARD_NOKEYS, config.keyboard); 1012 ASSERT_EQ(InputConfiguration::NAVIGATION_NONAV, config.navigation); 1013 ASSERT_EQ(InputConfiguration::TOUCHSCREEN_NOTOUCH, config.touchScreen); 1014} 1015 1016TEST_F(InputReaderTest, GetInputConfiguration_WhenAlphabeticKeyboardPresent_ReturnsQwertyKeyboard) { 1017 ASSERT_NO_FATAL_FAILURE(addDevice(0, String8("keyboard"), 1018 INPUT_DEVICE_CLASS_KEYBOARD | INPUT_DEVICE_CLASS_ALPHAKEY, NULL)); 1019 1020 InputConfiguration config; 1021 mReader->getInputConfiguration(&config); 1022 1023 ASSERT_EQ(InputConfiguration::KEYBOARD_QWERTY, config.keyboard); 1024 ASSERT_EQ(InputConfiguration::NAVIGATION_NONAV, config.navigation); 1025 ASSERT_EQ(InputConfiguration::TOUCHSCREEN_NOTOUCH, config.touchScreen); 1026} 1027 1028TEST_F(InputReaderTest, GetInputConfiguration_WhenTouchScreenPresent_ReturnsFingerTouchScreen) { 1029 PropertyMap configuration; 1030 configuration.addProperty(String8("touch.deviceType"), String8("touchScreen")); 1031 ASSERT_NO_FATAL_FAILURE(addDevice(0, String8("touchscreen"), 1032 INPUT_DEVICE_CLASS_TOUCH, &configuration)); 1033 1034 InputConfiguration config; 1035 mReader->getInputConfiguration(&config); 1036 1037 ASSERT_EQ(InputConfiguration::KEYBOARD_NOKEYS, config.keyboard); 1038 ASSERT_EQ(InputConfiguration::NAVIGATION_NONAV, config.navigation); 1039 ASSERT_EQ(InputConfiguration::TOUCHSCREEN_FINGER, config.touchScreen); 1040} 1041 1042TEST_F(InputReaderTest, GetInputConfiguration_WhenTouchPadPresent_ReturnsFingerNoTouch) { 1043 ASSERT_NO_FATAL_FAILURE(addDevice(0, String8("touchpad"), 1044 INPUT_DEVICE_CLASS_TOUCH, NULL)); 1045 1046 InputConfiguration config; 1047 mReader->getInputConfiguration(&config); 1048 1049 ASSERT_EQ(InputConfiguration::KEYBOARD_NOKEYS, config.keyboard); 1050 ASSERT_EQ(InputConfiguration::NAVIGATION_NONAV, config.navigation); 1051 ASSERT_EQ(InputConfiguration::TOUCHSCREEN_NOTOUCH, config.touchScreen); 1052} 1053 1054TEST_F(InputReaderTest, GetInputConfiguration_WhenMousePresent_ReturnsNoNavigation) { 1055 sp<FakePointerController> controller = new FakePointerController(); 1056 mFakePolicy->setPointerController(0, controller); 1057 1058 PropertyMap configuration; 1059 configuration.addProperty(String8("cursor.mode"), String8("pointer")); 1060 ASSERT_NO_FATAL_FAILURE(addDevice(0, String8("mouse"), 1061 INPUT_DEVICE_CLASS_CURSOR, &configuration)); 1062 1063 InputConfiguration config; 1064 mReader->getInputConfiguration(&config); 1065 1066 ASSERT_EQ(InputConfiguration::KEYBOARD_NOKEYS, config.keyboard); 1067 ASSERT_EQ(InputConfiguration::NAVIGATION_NONAV, config.navigation); 1068 ASSERT_EQ(InputConfiguration::TOUCHSCREEN_NOTOUCH, config.touchScreen); 1069} 1070 1071TEST_F(InputReaderTest, GetInputConfiguration_WhenTrackballPresent_ReturnsTrackballNavigation) { 1072 PropertyMap configuration; 1073 configuration.addProperty(String8("cursor.mode"), String8("navigation")); 1074 ASSERT_NO_FATAL_FAILURE(addDevice(0, String8("trackball"), 1075 INPUT_DEVICE_CLASS_CURSOR, &configuration)); 1076 1077 InputConfiguration config; 1078 mReader->getInputConfiguration(&config); 1079 1080 ASSERT_EQ(InputConfiguration::KEYBOARD_NOKEYS, config.keyboard); 1081 ASSERT_EQ(InputConfiguration::NAVIGATION_TRACKBALL, config.navigation); 1082 ASSERT_EQ(InputConfiguration::TOUCHSCREEN_NOTOUCH, config.touchScreen); 1083} 1084 1085TEST_F(InputReaderTest, GetInputConfiguration_WhenDPadPresent_ReturnsDPadNavigation) { 1086 ASSERT_NO_FATAL_FAILURE(addDevice(0, String8("dpad"), 1087 INPUT_DEVICE_CLASS_DPAD, NULL)); 1088 1089 InputConfiguration config; 1090 mReader->getInputConfiguration(&config); 1091 1092 ASSERT_EQ(InputConfiguration::KEYBOARD_NOKEYS, config.keyboard); 1093 ASSERT_EQ(InputConfiguration::NAVIGATION_DPAD, config.navigation); 1094 ASSERT_EQ(InputConfiguration::TOUCHSCREEN_NOTOUCH, config.touchScreen); 1095} 1096 1097TEST_F(InputReaderTest, GetInputDeviceInfo_WhenDeviceIdIsValid) { 1098 ASSERT_NO_FATAL_FAILURE(addDevice(1, String8("keyboard"), 1099 INPUT_DEVICE_CLASS_KEYBOARD, NULL)); 1100 1101 InputDeviceInfo info; 1102 status_t result = mReader->getInputDeviceInfo(1, &info); 1103 1104 ASSERT_EQ(OK, result); 1105 ASSERT_EQ(1, info.getId()); 1106 ASSERT_STREQ("keyboard", info.getName().string()); 1107 ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, info.getKeyboardType()); 1108 ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, info.getSources()); 1109 ASSERT_EQ(size_t(0), info.getMotionRanges().size()); 1110} 1111 1112TEST_F(InputReaderTest, GetInputDeviceInfo_WhenDeviceIdIsInvalid) { 1113 InputDeviceInfo info; 1114 status_t result = mReader->getInputDeviceInfo(-1, &info); 1115 1116 ASSERT_EQ(NAME_NOT_FOUND, result); 1117} 1118 1119TEST_F(InputReaderTest, GetInputDeviceInfo_WhenDeviceIdIsIgnored) { 1120 addDevice(1, String8("ignored"), 0, NULL); // no classes so device will be ignored 1121 1122 InputDeviceInfo info; 1123 status_t result = mReader->getInputDeviceInfo(1, &info); 1124 1125 ASSERT_EQ(NAME_NOT_FOUND, result); 1126} 1127 1128TEST_F(InputReaderTest, GetInputDeviceIds) { 1129 sp<FakePointerController> controller = new FakePointerController(); 1130 mFakePolicy->setPointerController(2, controller); 1131 1132 ASSERT_NO_FATAL_FAILURE(addDevice(1, String8("keyboard"), 1133 INPUT_DEVICE_CLASS_KEYBOARD | INPUT_DEVICE_CLASS_ALPHAKEY, NULL)); 1134 ASSERT_NO_FATAL_FAILURE(addDevice(2, String8("mouse"), 1135 INPUT_DEVICE_CLASS_CURSOR, NULL)); 1136 1137 Vector<int32_t> ids; 1138 mReader->getInputDeviceIds(ids); 1139 1140 ASSERT_EQ(size_t(2), ids.size()); 1141 ASSERT_EQ(1, ids[0]); 1142 ASSERT_EQ(2, ids[1]); 1143} 1144 1145TEST_F(InputReaderTest, GetKeyCodeState_ForwardsRequestsToMappers) { 1146 FakeInputMapper* mapper = NULL; 1147 ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, String8("fake"), 1148 INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL)); 1149 mapper->setKeyCodeState(AKEYCODE_A, AKEY_STATE_DOWN); 1150 1151 ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getKeyCodeState(0, 1152 AINPUT_SOURCE_ANY, AKEYCODE_A)) 1153 << "Should return unknown when the device id is >= 0 but unknown."; 1154 1155 ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getKeyCodeState(1, 1156 AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) 1157 << "Should return unknown when the device id is valid but the sources are not supported by the device."; 1158 1159 ASSERT_EQ(AKEY_STATE_DOWN, mReader->getKeyCodeState(1, 1160 AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) 1161 << "Should return value provided by mapper when device id is valid and the device supports some of the sources."; 1162 1163 ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getKeyCodeState(-1, 1164 AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) 1165 << "Should return unknown when the device id is < 0 but the sources are not supported by any device."; 1166 1167 ASSERT_EQ(AKEY_STATE_DOWN, mReader->getKeyCodeState(-1, 1168 AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) 1169 << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources."; 1170} 1171 1172TEST_F(InputReaderTest, GetScanCodeState_ForwardsRequestsToMappers) { 1173 FakeInputMapper* mapper = NULL; 1174 ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, String8("fake"), 1175 INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL)); 1176 mapper->setScanCodeState(KEY_A, AKEY_STATE_DOWN); 1177 1178 ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getScanCodeState(0, 1179 AINPUT_SOURCE_ANY, KEY_A)) 1180 << "Should return unknown when the device id is >= 0 but unknown."; 1181 1182 ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getScanCodeState(1, 1183 AINPUT_SOURCE_TRACKBALL, KEY_A)) 1184 << "Should return unknown when the device id is valid but the sources are not supported by the device."; 1185 1186 ASSERT_EQ(AKEY_STATE_DOWN, mReader->getScanCodeState(1, 1187 AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, KEY_A)) 1188 << "Should return value provided by mapper when device id is valid and the device supports some of the sources."; 1189 1190 ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getScanCodeState(-1, 1191 AINPUT_SOURCE_TRACKBALL, KEY_A)) 1192 << "Should return unknown when the device id is < 0 but the sources are not supported by any device."; 1193 1194 ASSERT_EQ(AKEY_STATE_DOWN, mReader->getScanCodeState(-1, 1195 AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, KEY_A)) 1196 << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources."; 1197} 1198 1199TEST_F(InputReaderTest, GetSwitchState_ForwardsRequestsToMappers) { 1200 FakeInputMapper* mapper = NULL; 1201 ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, String8("fake"), 1202 INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL)); 1203 mapper->setSwitchState(SW_LID, AKEY_STATE_DOWN); 1204 1205 ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getSwitchState(0, 1206 AINPUT_SOURCE_ANY, SW_LID)) 1207 << "Should return unknown when the device id is >= 0 but unknown."; 1208 1209 ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getSwitchState(1, 1210 AINPUT_SOURCE_TRACKBALL, SW_LID)) 1211 << "Should return unknown when the device id is valid but the sources are not supported by the device."; 1212 1213 ASSERT_EQ(AKEY_STATE_DOWN, mReader->getSwitchState(1, 1214 AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, SW_LID)) 1215 << "Should return value provided by mapper when device id is valid and the device supports some of the sources."; 1216 1217 ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getSwitchState(-1, 1218 AINPUT_SOURCE_TRACKBALL, SW_LID)) 1219 << "Should return unknown when the device id is < 0 but the sources are not supported by any device."; 1220 1221 ASSERT_EQ(AKEY_STATE_DOWN, mReader->getSwitchState(-1, 1222 AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, SW_LID)) 1223 << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources."; 1224} 1225 1226TEST_F(InputReaderTest, MarkSupportedKeyCodes_ForwardsRequestsToMappers) { 1227 FakeInputMapper* mapper = NULL; 1228 ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, String8("fake"), 1229 INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL)); 1230 mapper->addSupportedKeyCode(AKEYCODE_A); 1231 mapper->addSupportedKeyCode(AKEYCODE_B); 1232 1233 const int32_t keyCodes[4] = { AKEYCODE_A, AKEYCODE_B, AKEYCODE_1, AKEYCODE_2 }; 1234 uint8_t flags[4] = { 0, 0, 0, 1 }; 1235 1236 ASSERT_FALSE(mReader->hasKeys(0, AINPUT_SOURCE_ANY, 4, keyCodes, flags)) 1237 << "Should return false when device id is >= 0 but unknown."; 1238 ASSERT_TRUE(!flags[0] && !flags[1] && !flags[2] && !flags[3]); 1239 1240 flags[3] = 1; 1241 ASSERT_FALSE(mReader->hasKeys(1, AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags)) 1242 << "Should return false when device id is valid but the sources are not supported by the device."; 1243 ASSERT_TRUE(!flags[0] && !flags[1] && !flags[2] && !flags[3]); 1244 1245 flags[3] = 1; 1246 ASSERT_TRUE(mReader->hasKeys(1, AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags)) 1247 << "Should return value provided by mapper when device id is valid and the device supports some of the sources."; 1248 ASSERT_TRUE(flags[0] && flags[1] && !flags[2] && !flags[3]); 1249 1250 flags[3] = 1; 1251 ASSERT_FALSE(mReader->hasKeys(-1, AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags)) 1252 << "Should return false when the device id is < 0 but the sources are not supported by any device."; 1253 ASSERT_TRUE(!flags[0] && !flags[1] && !flags[2] && !flags[3]); 1254 1255 flags[3] = 1; 1256 ASSERT_TRUE(mReader->hasKeys(-1, AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags)) 1257 << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources."; 1258 ASSERT_TRUE(flags[0] && flags[1] && !flags[2] && !flags[3]); 1259} 1260 1261TEST_F(InputReaderTest, LoopOnce_WhenDeviceScanFinished_SendsConfigurationChanged) { 1262 addDevice(1, String8("ignored"), INPUT_DEVICE_CLASS_KEYBOARD, NULL); 1263 1264 FakeInputDispatcher::NotifyConfigurationChangedArgs args; 1265 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyConfigurationChangedWasCalled(&args)); 1266 ASSERT_EQ(ARBITRARY_TIME, args.eventTime); 1267} 1268 1269TEST_F(InputReaderTest, LoopOnce_ForwardsRawEventsToMappers) { 1270 FakeInputMapper* mapper = NULL; 1271 ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, String8("fake"), 1272 INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL)); 1273 1274 mFakeEventHub->enqueueEvent(0, 1, EV_KEY, KEY_A, AKEYCODE_A, 1, POLICY_FLAG_WAKE); 1275 mReader->loopOnce(); 1276 ASSERT_NO_FATAL_FAILURE(mFakeEventHub->assertQueueIsEmpty()); 1277 1278 RawEvent event; 1279 ASSERT_NO_FATAL_FAILURE(mapper->assertProcessWasCalled(&event)); 1280 ASSERT_EQ(0, event.when); 1281 ASSERT_EQ(1, event.deviceId); 1282 ASSERT_EQ(EV_KEY, event.type); 1283 ASSERT_EQ(KEY_A, event.scanCode); 1284 ASSERT_EQ(AKEYCODE_A, event.keyCode); 1285 ASSERT_EQ(1, event.value); 1286 ASSERT_EQ(POLICY_FLAG_WAKE, event.flags); 1287} 1288 1289 1290// --- InputDeviceTest --- 1291 1292class InputDeviceTest : public testing::Test { 1293protected: 1294 static const char* DEVICE_NAME; 1295 static const int32_t DEVICE_ID; 1296 1297 sp<FakeEventHub> mFakeEventHub; 1298 sp<FakeInputReaderPolicy> mFakePolicy; 1299 sp<FakeInputDispatcher> mFakeDispatcher; 1300 FakeInputReaderContext* mFakeContext; 1301 1302 InputDevice* mDevice; 1303 1304 virtual void SetUp() { 1305 mFakeEventHub = new FakeEventHub(); 1306 mFakePolicy = new FakeInputReaderPolicy(); 1307 mFakeDispatcher = new FakeInputDispatcher(); 1308 mFakeContext = new FakeInputReaderContext(mFakeEventHub, mFakePolicy, mFakeDispatcher); 1309 1310 mFakeEventHub->addDevice(DEVICE_ID, String8(DEVICE_NAME), 0); 1311 mDevice = new InputDevice(mFakeContext, DEVICE_ID, String8(DEVICE_NAME)); 1312 } 1313 1314 virtual void TearDown() { 1315 delete mDevice; 1316 1317 delete mFakeContext; 1318 mFakeDispatcher.clear(); 1319 mFakePolicy.clear(); 1320 mFakeEventHub.clear(); 1321 } 1322}; 1323 1324const char* InputDeviceTest::DEVICE_NAME = "device"; 1325const int32_t InputDeviceTest::DEVICE_ID = 1; 1326 1327TEST_F(InputDeviceTest, ImmutableProperties) { 1328 ASSERT_EQ(DEVICE_ID, mDevice->getId()); 1329 ASSERT_STREQ(DEVICE_NAME, mDevice->getName()); 1330} 1331 1332TEST_F(InputDeviceTest, WhenNoMappersAreRegistered_DeviceIsIgnored) { 1333 // Configuration. 1334 mDevice->configure(); 1335 1336 // Metadata. 1337 ASSERT_TRUE(mDevice->isIgnored()); 1338 ASSERT_EQ(AINPUT_SOURCE_UNKNOWN, mDevice->getSources()); 1339 1340 InputDeviceInfo info; 1341 mDevice->getDeviceInfo(&info); 1342 ASSERT_EQ(DEVICE_ID, info.getId()); 1343 ASSERT_STREQ(DEVICE_NAME, info.getName().string()); 1344 ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NONE, info.getKeyboardType()); 1345 ASSERT_EQ(AINPUT_SOURCE_UNKNOWN, info.getSources()); 1346 1347 // State queries. 1348 ASSERT_EQ(0, mDevice->getMetaState()); 1349 1350 ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getKeyCodeState(AINPUT_SOURCE_KEYBOARD, 0)) 1351 << "Ignored device should return unknown key code state."; 1352 ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getScanCodeState(AINPUT_SOURCE_KEYBOARD, 0)) 1353 << "Ignored device should return unknown scan code state."; 1354 ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getSwitchState(AINPUT_SOURCE_KEYBOARD, 0)) 1355 << "Ignored device should return unknown switch state."; 1356 1357 const int32_t keyCodes[2] = { AKEYCODE_A, AKEYCODE_B }; 1358 uint8_t flags[2] = { 0, 1 }; 1359 ASSERT_FALSE(mDevice->markSupportedKeyCodes(AINPUT_SOURCE_KEYBOARD, 2, keyCodes, flags)) 1360 << "Ignored device should never mark any key codes."; 1361 ASSERT_EQ(0, flags[0]) << "Flag for unsupported key should be unchanged."; 1362 ASSERT_EQ(1, flags[1]) << "Flag for unsupported key should be unchanged."; 1363 1364 // Reset. 1365 mDevice->reset(); 1366} 1367 1368TEST_F(InputDeviceTest, WhenMappersAreRegistered_DeviceIsNotIgnoredAndForwardsRequestsToMappers) { 1369 // Configuration. 1370 mFakeEventHub->addConfigurationProperty(DEVICE_ID, String8("key"), String8("value")); 1371 1372 FakeInputMapper* mapper1 = new FakeInputMapper(mDevice, AINPUT_SOURCE_KEYBOARD); 1373 mapper1->setKeyboardType(AINPUT_KEYBOARD_TYPE_ALPHABETIC); 1374 mapper1->setMetaState(AMETA_ALT_ON); 1375 mapper1->addSupportedKeyCode(AKEYCODE_A); 1376 mapper1->addSupportedKeyCode(AKEYCODE_B); 1377 mapper1->setKeyCodeState(AKEYCODE_A, AKEY_STATE_DOWN); 1378 mapper1->setKeyCodeState(AKEYCODE_B, AKEY_STATE_UP); 1379 mapper1->setScanCodeState(2, AKEY_STATE_DOWN); 1380 mapper1->setScanCodeState(3, AKEY_STATE_UP); 1381 mapper1->setSwitchState(4, AKEY_STATE_DOWN); 1382 mDevice->addMapper(mapper1); 1383 1384 FakeInputMapper* mapper2 = new FakeInputMapper(mDevice, AINPUT_SOURCE_TOUCHSCREEN); 1385 mapper2->setMetaState(AMETA_SHIFT_ON); 1386 mDevice->addMapper(mapper2); 1387 1388 mDevice->configure(); 1389 1390 String8 propertyValue; 1391 ASSERT_TRUE(mDevice->getConfiguration().tryGetProperty(String8("key"), propertyValue)) 1392 << "Device should have read configuration during configuration phase."; 1393 ASSERT_STREQ("value", propertyValue.string()); 1394 1395 ASSERT_NO_FATAL_FAILURE(mapper1->assertConfigureWasCalled()); 1396 ASSERT_NO_FATAL_FAILURE(mapper2->assertConfigureWasCalled()); 1397 1398 // Metadata. 1399 ASSERT_FALSE(mDevice->isIgnored()); 1400 ASSERT_EQ(uint32_t(AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TOUCHSCREEN), mDevice->getSources()); 1401 1402 InputDeviceInfo info; 1403 mDevice->getDeviceInfo(&info); 1404 ASSERT_EQ(DEVICE_ID, info.getId()); 1405 ASSERT_STREQ(DEVICE_NAME, info.getName().string()); 1406 ASSERT_EQ(AINPUT_KEYBOARD_TYPE_ALPHABETIC, info.getKeyboardType()); 1407 ASSERT_EQ(uint32_t(AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TOUCHSCREEN), info.getSources()); 1408 1409 // State queries. 1410 ASSERT_EQ(AMETA_ALT_ON | AMETA_SHIFT_ON, mDevice->getMetaState()) 1411 << "Should query mappers and combine meta states."; 1412 1413 ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getKeyCodeState(AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) 1414 << "Should return unknown key code state when source not supported."; 1415 ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getScanCodeState(AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) 1416 << "Should return unknown scan code state when source not supported."; 1417 ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getSwitchState(AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) 1418 << "Should return unknown switch state when source not supported."; 1419 1420 ASSERT_EQ(AKEY_STATE_DOWN, mDevice->getKeyCodeState(AINPUT_SOURCE_KEYBOARD, AKEYCODE_A)) 1421 << "Should query mapper when source is supported."; 1422 ASSERT_EQ(AKEY_STATE_UP, mDevice->getScanCodeState(AINPUT_SOURCE_KEYBOARD, 3)) 1423 << "Should query mapper when source is supported."; 1424 ASSERT_EQ(AKEY_STATE_DOWN, mDevice->getSwitchState(AINPUT_SOURCE_KEYBOARD, 4)) 1425 << "Should query mapper when source is supported."; 1426 1427 const int32_t keyCodes[4] = { AKEYCODE_A, AKEYCODE_B, AKEYCODE_1, AKEYCODE_2 }; 1428 uint8_t flags[4] = { 0, 0, 0, 1 }; 1429 ASSERT_FALSE(mDevice->markSupportedKeyCodes(AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags)) 1430 << "Should do nothing when source is unsupported."; 1431 ASSERT_EQ(0, flags[0]) << "Flag should be unchanged when source is unsupported."; 1432 ASSERT_EQ(0, flags[1]) << "Flag should be unchanged when source is unsupported."; 1433 ASSERT_EQ(0, flags[2]) << "Flag should be unchanged when source is unsupported."; 1434 ASSERT_EQ(1, flags[3]) << "Flag should be unchanged when source is unsupported."; 1435 1436 ASSERT_TRUE(mDevice->markSupportedKeyCodes(AINPUT_SOURCE_KEYBOARD, 4, keyCodes, flags)) 1437 << "Should query mapper when source is supported."; 1438 ASSERT_EQ(1, flags[0]) << "Flag for supported key should be set."; 1439 ASSERT_EQ(1, flags[1]) << "Flag for supported key should be set."; 1440 ASSERT_EQ(0, flags[2]) << "Flag for unsupported key should be unchanged."; 1441 ASSERT_EQ(1, flags[3]) << "Flag for unsupported key should be unchanged."; 1442 1443 // Event handling. 1444 RawEvent event; 1445 mDevice->process(&event); 1446 1447 ASSERT_NO_FATAL_FAILURE(mapper1->assertProcessWasCalled()); 1448 ASSERT_NO_FATAL_FAILURE(mapper2->assertProcessWasCalled()); 1449 1450 // Reset. 1451 mDevice->reset(); 1452 1453 ASSERT_NO_FATAL_FAILURE(mapper1->assertResetWasCalled()); 1454 ASSERT_NO_FATAL_FAILURE(mapper2->assertResetWasCalled()); 1455} 1456 1457 1458// --- InputMapperTest --- 1459 1460class InputMapperTest : public testing::Test { 1461protected: 1462 static const char* DEVICE_NAME; 1463 static const int32_t DEVICE_ID; 1464 1465 sp<FakeEventHub> mFakeEventHub; 1466 sp<FakeInputReaderPolicy> mFakePolicy; 1467 sp<FakeInputDispatcher> mFakeDispatcher; 1468 FakeInputReaderContext* mFakeContext; 1469 InputDevice* mDevice; 1470 1471 virtual void SetUp() { 1472 mFakeEventHub = new FakeEventHub(); 1473 mFakePolicy = new FakeInputReaderPolicy(); 1474 mFakeDispatcher = new FakeInputDispatcher(); 1475 mFakeContext = new FakeInputReaderContext(mFakeEventHub, mFakePolicy, mFakeDispatcher); 1476 mDevice = new InputDevice(mFakeContext, DEVICE_ID, String8(DEVICE_NAME)); 1477 1478 mFakeEventHub->addDevice(DEVICE_ID, String8(DEVICE_NAME), 0); 1479 } 1480 1481 virtual void TearDown() { 1482 delete mDevice; 1483 delete mFakeContext; 1484 mFakeDispatcher.clear(); 1485 mFakePolicy.clear(); 1486 mFakeEventHub.clear(); 1487 } 1488 1489 void addConfigurationProperty(const char* key, const char* value) { 1490 mFakeEventHub->addConfigurationProperty(DEVICE_ID, String8(key), String8(value)); 1491 } 1492 1493 void addMapperAndConfigure(InputMapper* mapper) { 1494 mDevice->addMapper(mapper); 1495 mDevice->configure(); 1496 } 1497 1498 static void process(InputMapper* mapper, nsecs_t when, int32_t deviceId, int32_t type, 1499 int32_t scanCode, int32_t keyCode, int32_t value, uint32_t flags) { 1500 RawEvent event; 1501 event.when = when; 1502 event.deviceId = deviceId; 1503 event.type = type; 1504 event.scanCode = scanCode; 1505 event.keyCode = keyCode; 1506 event.value = value; 1507 event.flags = flags; 1508 mapper->process(&event); 1509 } 1510 1511 static void assertMotionRange(const InputDeviceInfo& info, 1512 int32_t axis, uint32_t source, float min, float max, float flat, float fuzz) { 1513 const InputDeviceInfo::MotionRange* range = info.getMotionRange(axis, source); 1514 ASSERT_TRUE(range != NULL) << "Axis: " << axis << " Source: " << source; 1515 ASSERT_EQ(axis, range->axis) << "Axis: " << axis << " Source: " << source; 1516 ASSERT_EQ(source, range->source) << "Axis: " << axis << " Source: " << source; 1517 ASSERT_NEAR(min, range->min, EPSILON) << "Axis: " << axis << " Source: " << source; 1518 ASSERT_NEAR(max, range->max, EPSILON) << "Axis: " << axis << " Source: " << source; 1519 ASSERT_NEAR(flat, range->flat, EPSILON) << "Axis: " << axis << " Source: " << source; 1520 ASSERT_NEAR(fuzz, range->fuzz, EPSILON) << "Axis: " << axis << " Source: " << source; 1521 } 1522 1523 static void assertPointerCoords(const PointerCoords& coords, 1524 float x, float y, float pressure, float size, 1525 float touchMajor, float touchMinor, float toolMajor, float toolMinor, 1526 float orientation) { 1527 ASSERT_NEAR(x, coords.getAxisValue(AMOTION_EVENT_AXIS_X), 1); 1528 ASSERT_NEAR(y, coords.getAxisValue(AMOTION_EVENT_AXIS_Y), 1); 1529 ASSERT_NEAR(pressure, coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), EPSILON); 1530 ASSERT_NEAR(size, coords.getAxisValue(AMOTION_EVENT_AXIS_SIZE), EPSILON); 1531 ASSERT_NEAR(touchMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), 1); 1532 ASSERT_NEAR(touchMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), 1); 1533 ASSERT_NEAR(toolMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), 1); 1534 ASSERT_NEAR(toolMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), 1); 1535 ASSERT_NEAR(orientation, coords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION), EPSILON); 1536 } 1537}; 1538 1539const char* InputMapperTest::DEVICE_NAME = "device"; 1540const int32_t InputMapperTest::DEVICE_ID = 1; 1541 1542 1543// --- SwitchInputMapperTest --- 1544 1545class SwitchInputMapperTest : public InputMapperTest { 1546protected: 1547}; 1548 1549TEST_F(SwitchInputMapperTest, GetSources) { 1550 SwitchInputMapper* mapper = new SwitchInputMapper(mDevice); 1551 addMapperAndConfigure(mapper); 1552 1553 ASSERT_EQ(uint32_t(AINPUT_SOURCE_SWITCH), mapper->getSources()); 1554} 1555 1556TEST_F(SwitchInputMapperTest, GetSwitchState) { 1557 SwitchInputMapper* mapper = new SwitchInputMapper(mDevice); 1558 addMapperAndConfigure(mapper); 1559 1560 mFakeEventHub->setSwitchState(DEVICE_ID, SW_LID, 1); 1561 ASSERT_EQ(1, mapper->getSwitchState(AINPUT_SOURCE_ANY, SW_LID)); 1562 1563 mFakeEventHub->setSwitchState(DEVICE_ID, SW_LID, 0); 1564 ASSERT_EQ(0, mapper->getSwitchState(AINPUT_SOURCE_ANY, SW_LID)); 1565} 1566 1567TEST_F(SwitchInputMapperTest, Process) { 1568 SwitchInputMapper* mapper = new SwitchInputMapper(mDevice); 1569 addMapperAndConfigure(mapper); 1570 1571 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_LID, 0, 1, 0); 1572 1573 FakeInputDispatcher::NotifySwitchArgs args; 1574 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifySwitchWasCalled(&args)); 1575 ASSERT_EQ(ARBITRARY_TIME, args.when); 1576 ASSERT_EQ(SW_LID, args.switchCode); 1577 ASSERT_EQ(1, args.switchValue); 1578 ASSERT_EQ(uint32_t(0), args.policyFlags); 1579} 1580 1581 1582// --- KeyboardInputMapperTest --- 1583 1584class KeyboardInputMapperTest : public InputMapperTest { 1585protected: 1586 void testDPadKeyRotation(KeyboardInputMapper* mapper, 1587 int32_t originalScanCode, int32_t originalKeyCode, int32_t rotatedKeyCode); 1588}; 1589 1590void KeyboardInputMapperTest::testDPadKeyRotation(KeyboardInputMapper* mapper, 1591 int32_t originalScanCode, int32_t originalKeyCode, int32_t rotatedKeyCode) { 1592 FakeInputDispatcher::NotifyKeyArgs args; 1593 1594 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, originalScanCode, originalKeyCode, 1, 0); 1595 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&args)); 1596 ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); 1597 ASSERT_EQ(originalScanCode, args.scanCode); 1598 ASSERT_EQ(rotatedKeyCode, args.keyCode); 1599 1600 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, originalScanCode, originalKeyCode, 0, 0); 1601 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&args)); 1602 ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); 1603 ASSERT_EQ(originalScanCode, args.scanCode); 1604 ASSERT_EQ(rotatedKeyCode, args.keyCode); 1605} 1606 1607 1608TEST_F(KeyboardInputMapperTest, GetSources) { 1609 KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, 1610 AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); 1611 addMapperAndConfigure(mapper); 1612 1613 ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, mapper->getSources()); 1614} 1615 1616TEST_F(KeyboardInputMapperTest, Process_SimpleKeyPress) { 1617 KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, 1618 AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); 1619 addMapperAndConfigure(mapper); 1620 1621 // Key down. 1622 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1623 EV_KEY, KEY_HOME, AKEYCODE_HOME, 1, POLICY_FLAG_WAKE); 1624 FakeInputDispatcher::NotifyKeyArgs args; 1625 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&args)); 1626 ASSERT_EQ(DEVICE_ID, args.deviceId); 1627 ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); 1628 ASSERT_EQ(ARBITRARY_TIME, args.eventTime); 1629 ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); 1630 ASSERT_EQ(AKEYCODE_HOME, args.keyCode); 1631 ASSERT_EQ(KEY_HOME, args.scanCode); 1632 ASSERT_EQ(AMETA_NONE, args.metaState); 1633 ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); 1634 ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); 1635 ASSERT_EQ(ARBITRARY_TIME, args.downTime); 1636 1637 // Key up. 1638 process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, 1639 EV_KEY, KEY_HOME, AKEYCODE_HOME, 0, POLICY_FLAG_WAKE); 1640 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&args)); 1641 ASSERT_EQ(DEVICE_ID, args.deviceId); 1642 ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); 1643 ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime); 1644 ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); 1645 ASSERT_EQ(AKEYCODE_HOME, args.keyCode); 1646 ASSERT_EQ(KEY_HOME, args.scanCode); 1647 ASSERT_EQ(AMETA_NONE, args.metaState); 1648 ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); 1649 ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); 1650 ASSERT_EQ(ARBITRARY_TIME, args.downTime); 1651} 1652 1653TEST_F(KeyboardInputMapperTest, Reset_WhenKeysAreNotDown_DoesNotSynthesizeKeyUp) { 1654 KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, 1655 AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); 1656 addMapperAndConfigure(mapper); 1657 1658 // Key down. 1659 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1660 EV_KEY, KEY_HOME, AKEYCODE_HOME, 1, POLICY_FLAG_WAKE); 1661 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled()); 1662 1663 // Key up. 1664 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1665 EV_KEY, KEY_HOME, AKEYCODE_HOME, 0, POLICY_FLAG_WAKE); 1666 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled()); 1667 1668 // Reset. Since no keys still down, should not synthesize any key ups. 1669 mapper->reset(); 1670 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasNotCalled()); 1671} 1672 1673TEST_F(KeyboardInputMapperTest, Reset_WhenKeysAreDown_SynthesizesKeyUps) { 1674 KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, 1675 AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); 1676 addMapperAndConfigure(mapper); 1677 1678 // Metakey down. 1679 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1680 EV_KEY, KEY_LEFTSHIFT, AKEYCODE_SHIFT_LEFT, 1, 0); 1681 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled()); 1682 1683 // Key down. 1684 process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, 1685 EV_KEY, KEY_A, AKEYCODE_A, 1, 0); 1686 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled()); 1687 1688 // Reset. Since two keys are still down, should synthesize two key ups in reverse order. 1689 mapper->reset(); 1690 1691 FakeInputDispatcher::NotifyKeyArgs args; 1692 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&args)); 1693 ASSERT_EQ(DEVICE_ID, args.deviceId); 1694 ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); 1695 ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); 1696 ASSERT_EQ(AKEYCODE_A, args.keyCode); 1697 ASSERT_EQ(KEY_A, args.scanCode); 1698 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); 1699 ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); 1700 ASSERT_EQ(uint32_t(0), args.policyFlags); 1701 ASSERT_EQ(ARBITRARY_TIME + 1, args.downTime); 1702 1703 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&args)); 1704 ASSERT_EQ(DEVICE_ID, args.deviceId); 1705 ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); 1706 ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); 1707 ASSERT_EQ(AKEYCODE_SHIFT_LEFT, args.keyCode); 1708 ASSERT_EQ(KEY_LEFTSHIFT, args.scanCode); 1709 ASSERT_EQ(AMETA_NONE, args.metaState); 1710 ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); 1711 ASSERT_EQ(uint32_t(0), args.policyFlags); 1712 ASSERT_EQ(ARBITRARY_TIME + 1, args.downTime); 1713 1714 // And that's it. 1715 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasNotCalled()); 1716} 1717 1718TEST_F(KeyboardInputMapperTest, Process_ShouldUpdateMetaState) { 1719 KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, 1720 AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); 1721 addMapperAndConfigure(mapper); 1722 1723 // Initial metastate. 1724 ASSERT_EQ(AMETA_NONE, mapper->getMetaState()); 1725 1726 // Metakey down. 1727 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1728 EV_KEY, KEY_LEFTSHIFT, AKEYCODE_SHIFT_LEFT, 1, 0); 1729 FakeInputDispatcher::NotifyKeyArgs args; 1730 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&args)); 1731 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); 1732 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper->getMetaState()); 1733 ASSERT_NO_FATAL_FAILURE(mFakeContext->assertUpdateGlobalMetaStateWasCalled()); 1734 1735 // Key down. 1736 process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, 1737 EV_KEY, KEY_A, AKEYCODE_A, 1, 0); 1738 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&args)); 1739 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); 1740 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper->getMetaState()); 1741 1742 // Key up. 1743 process(mapper, ARBITRARY_TIME + 2, DEVICE_ID, 1744 EV_KEY, KEY_A, AKEYCODE_A, 0, 0); 1745 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&args)); 1746 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); 1747 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper->getMetaState()); 1748 1749 // Metakey up. 1750 process(mapper, ARBITRARY_TIME + 3, DEVICE_ID, 1751 EV_KEY, KEY_LEFTSHIFT, AKEYCODE_SHIFT_LEFT, 0, 0); 1752 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&args)); 1753 ASSERT_EQ(AMETA_NONE, args.metaState); 1754 ASSERT_EQ(AMETA_NONE, mapper->getMetaState()); 1755 ASSERT_NO_FATAL_FAILURE(mFakeContext->assertUpdateGlobalMetaStateWasCalled()); 1756} 1757 1758TEST_F(KeyboardInputMapperTest, Process_WhenNotOrientationAware_ShouldNotRotateDPad) { 1759 KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, 1760 AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); 1761 addMapperAndConfigure(mapper); 1762 1763 mFakePolicy->setDisplayInfo(DISPLAY_ID, 1764 DISPLAY_WIDTH, DISPLAY_HEIGHT, 1765 DISPLAY_ORIENTATION_90); 1766 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1767 KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP)); 1768 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1769 KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_RIGHT)); 1770 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1771 KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_DOWN)); 1772 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1773 KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_LEFT)); 1774} 1775 1776TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) { 1777 KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, 1778 AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); 1779 addConfigurationProperty("keyboard.orientationAware", "1"); 1780 addMapperAndConfigure(mapper); 1781 1782 mFakePolicy->setDisplayInfo(DISPLAY_ID, 1783 DISPLAY_WIDTH, DISPLAY_HEIGHT, 1784 DISPLAY_ORIENTATION_0); 1785 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1786 KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP)); 1787 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1788 KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_RIGHT)); 1789 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1790 KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_DOWN)); 1791 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1792 KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_LEFT)); 1793 1794 mFakePolicy->setDisplayInfo(DISPLAY_ID, 1795 DISPLAY_WIDTH, DISPLAY_HEIGHT, 1796 DISPLAY_ORIENTATION_90); 1797 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1798 KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT)); 1799 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1800 KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP)); 1801 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1802 KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT)); 1803 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1804 KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN)); 1805 1806 mFakePolicy->setDisplayInfo(DISPLAY_ID, 1807 DISPLAY_WIDTH, DISPLAY_HEIGHT, 1808 DISPLAY_ORIENTATION_180); 1809 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1810 KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_DOWN)); 1811 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1812 KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_LEFT)); 1813 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1814 KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_UP)); 1815 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1816 KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_RIGHT)); 1817 1818 mFakePolicy->setDisplayInfo(DISPLAY_ID, 1819 DISPLAY_WIDTH, DISPLAY_HEIGHT, 1820 DISPLAY_ORIENTATION_270); 1821 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1822 KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_RIGHT)); 1823 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1824 KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_DOWN)); 1825 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1826 KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_LEFT)); 1827 ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, 1828 KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_UP)); 1829 1830 // Special case: if orientation changes while key is down, we still emit the same keycode 1831 // in the key up as we did in the key down. 1832 FakeInputDispatcher::NotifyKeyArgs args; 1833 1834 mFakePolicy->setDisplayInfo(DISPLAY_ID, 1835 DISPLAY_WIDTH, DISPLAY_HEIGHT, 1836 DISPLAY_ORIENTATION_270); 1837 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, AKEYCODE_DPAD_UP, 1, 0); 1838 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&args)); 1839 ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); 1840 ASSERT_EQ(KEY_UP, args.scanCode); 1841 ASSERT_EQ(AKEYCODE_DPAD_RIGHT, args.keyCode); 1842 1843 mFakePolicy->setDisplayInfo(DISPLAY_ID, 1844 DISPLAY_WIDTH, DISPLAY_HEIGHT, 1845 DISPLAY_ORIENTATION_180); 1846 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, AKEYCODE_DPAD_UP, 0, 0); 1847 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&args)); 1848 ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); 1849 ASSERT_EQ(KEY_UP, args.scanCode); 1850 ASSERT_EQ(AKEYCODE_DPAD_RIGHT, args.keyCode); 1851} 1852 1853TEST_F(KeyboardInputMapperTest, GetKeyCodeState) { 1854 KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, 1855 AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); 1856 addMapperAndConfigure(mapper); 1857 1858 mFakeEventHub->setKeyCodeState(DEVICE_ID, AKEYCODE_A, 1); 1859 ASSERT_EQ(1, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_A)); 1860 1861 mFakeEventHub->setKeyCodeState(DEVICE_ID, AKEYCODE_A, 0); 1862 ASSERT_EQ(0, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_A)); 1863} 1864 1865TEST_F(KeyboardInputMapperTest, GetScanCodeState) { 1866 KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, 1867 AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); 1868 addMapperAndConfigure(mapper); 1869 1870 mFakeEventHub->setScanCodeState(DEVICE_ID, KEY_A, 1); 1871 ASSERT_EQ(1, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_A)); 1872 1873 mFakeEventHub->setScanCodeState(DEVICE_ID, KEY_A, 0); 1874 ASSERT_EQ(0, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_A)); 1875} 1876 1877TEST_F(KeyboardInputMapperTest, MarkSupportedKeyCodes) { 1878 KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, 1879 AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); 1880 addMapperAndConfigure(mapper); 1881 1882 mFakeEventHub->addKey(DEVICE_ID, KEY_A, AKEYCODE_A, 0); 1883 1884 const int32_t keyCodes[2] = { AKEYCODE_A, AKEYCODE_B }; 1885 uint8_t flags[2] = { 0, 0 }; 1886 ASSERT_TRUE(mapper->markSupportedKeyCodes(AINPUT_SOURCE_ANY, 1, keyCodes, flags)); 1887 ASSERT_TRUE(flags[0]); 1888 ASSERT_FALSE(flags[1]); 1889} 1890 1891TEST_F(KeyboardInputMapperTest, Process_LockedKeysShouldToggleMetaStateAndLeds) { 1892 mFakeEventHub->addLed(DEVICE_ID, LED_CAPSL, true /*initially on*/); 1893 mFakeEventHub->addLed(DEVICE_ID, LED_NUML, false /*initially off*/); 1894 mFakeEventHub->addLed(DEVICE_ID, LED_SCROLLL, false /*initially off*/); 1895 1896 KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, 1897 AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); 1898 addMapperAndConfigure(mapper); 1899 1900 // Initialization should have turned all of the lights off. 1901 ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); 1902 ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); 1903 ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); 1904 1905 // Toggle caps lock on. 1906 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1907 EV_KEY, KEY_CAPSLOCK, AKEYCODE_CAPS_LOCK, 1, 0); 1908 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1909 EV_KEY, KEY_CAPSLOCK, AKEYCODE_CAPS_LOCK, 0, 0); 1910 ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); 1911 ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); 1912 ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); 1913 ASSERT_EQ(AMETA_CAPS_LOCK_ON, mapper->getMetaState()); 1914 1915 // Toggle num lock on. 1916 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1917 EV_KEY, KEY_NUMLOCK, AKEYCODE_NUM_LOCK, 1, 0); 1918 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1919 EV_KEY, KEY_NUMLOCK, AKEYCODE_NUM_LOCK, 0, 0); 1920 ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); 1921 ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); 1922 ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); 1923 ASSERT_EQ(AMETA_CAPS_LOCK_ON | AMETA_NUM_LOCK_ON, mapper->getMetaState()); 1924 1925 // Toggle caps lock off. 1926 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1927 EV_KEY, KEY_CAPSLOCK, AKEYCODE_CAPS_LOCK, 1, 0); 1928 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1929 EV_KEY, KEY_CAPSLOCK, AKEYCODE_CAPS_LOCK, 0, 0); 1930 ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); 1931 ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); 1932 ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); 1933 ASSERT_EQ(AMETA_NUM_LOCK_ON, mapper->getMetaState()); 1934 1935 // Toggle scroll lock on. 1936 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1937 EV_KEY, KEY_SCROLLLOCK, AKEYCODE_SCROLL_LOCK, 1, 0); 1938 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1939 EV_KEY, KEY_SCROLLLOCK, AKEYCODE_SCROLL_LOCK, 0, 0); 1940 ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); 1941 ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); 1942 ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); 1943 ASSERT_EQ(AMETA_NUM_LOCK_ON | AMETA_SCROLL_LOCK_ON, mapper->getMetaState()); 1944 1945 // Toggle num lock off. 1946 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1947 EV_KEY, KEY_NUMLOCK, AKEYCODE_NUM_LOCK, 1, 0); 1948 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1949 EV_KEY, KEY_NUMLOCK, AKEYCODE_NUM_LOCK, 0, 0); 1950 ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); 1951 ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); 1952 ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); 1953 ASSERT_EQ(AMETA_SCROLL_LOCK_ON, mapper->getMetaState()); 1954 1955 // Toggle scroll lock off. 1956 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1957 EV_KEY, KEY_SCROLLLOCK, AKEYCODE_SCROLL_LOCK, 1, 0); 1958 process(mapper, ARBITRARY_TIME, DEVICE_ID, 1959 EV_KEY, KEY_SCROLLLOCK, AKEYCODE_SCROLL_LOCK, 0, 0); 1960 ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); 1961 ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); 1962 ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); 1963 ASSERT_EQ(AMETA_NONE, mapper->getMetaState()); 1964} 1965 1966 1967// --- CursorInputMapperTest --- 1968 1969class CursorInputMapperTest : public InputMapperTest { 1970protected: 1971 static const int32_t TRACKBALL_MOVEMENT_THRESHOLD; 1972 1973 sp<FakePointerController> mFakePointerController; 1974 1975 virtual void SetUp() { 1976 InputMapperTest::SetUp(); 1977 1978 mFakePointerController = new FakePointerController(); 1979 mFakePolicy->setPointerController(DEVICE_ID, mFakePointerController); 1980 } 1981 1982 void testMotionRotation(CursorInputMapper* mapper, 1983 int32_t originalX, int32_t originalY, int32_t rotatedX, int32_t rotatedY); 1984}; 1985 1986const int32_t CursorInputMapperTest::TRACKBALL_MOVEMENT_THRESHOLD = 6; 1987 1988void CursorInputMapperTest::testMotionRotation(CursorInputMapper* mapper, 1989 int32_t originalX, int32_t originalY, int32_t rotatedX, int32_t rotatedY) { 1990 FakeInputDispatcher::NotifyMotionArgs args; 1991 1992 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 0, originalX, 0); 1993 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, 0, originalY, 0); 1994 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0, 0, 0); 1995 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 1996 ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action); 1997 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 1998 float(rotatedX) / TRACKBALL_MOVEMENT_THRESHOLD, 1999 float(rotatedY) / TRACKBALL_MOVEMENT_THRESHOLD, 2000 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); 2001} 2002 2003TEST_F(CursorInputMapperTest, WhenModeIsPointer_GetSources_ReturnsMouse) { 2004 CursorInputMapper* mapper = new CursorInputMapper(mDevice); 2005 addConfigurationProperty("cursor.mode", "pointer"); 2006 addMapperAndConfigure(mapper); 2007 2008 ASSERT_EQ(AINPUT_SOURCE_MOUSE, mapper->getSources()); 2009} 2010 2011TEST_F(CursorInputMapperTest, WhenModeIsNavigation_GetSources_ReturnsTrackball) { 2012 CursorInputMapper* mapper = new CursorInputMapper(mDevice); 2013 addConfigurationProperty("cursor.mode", "navigation"); 2014 addMapperAndConfigure(mapper); 2015 2016 ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, mapper->getSources()); 2017} 2018 2019TEST_F(CursorInputMapperTest, WhenModeIsPointer_PopulateDeviceInfo_ReturnsRangeFromPointerController) { 2020 CursorInputMapper* mapper = new CursorInputMapper(mDevice); 2021 addConfigurationProperty("cursor.mode", "pointer"); 2022 addMapperAndConfigure(mapper); 2023 2024 InputDeviceInfo info; 2025 mapper->populateDeviceInfo(&info); 2026 2027 // Initially there may not be a valid motion range. 2028 ASSERT_EQ(NULL, info.getMotionRange(AINPUT_MOTION_RANGE_X, AINPUT_SOURCE_MOUSE)); 2029 ASSERT_EQ(NULL, info.getMotionRange(AINPUT_MOTION_RANGE_Y, AINPUT_SOURCE_MOUSE)); 2030 ASSERT_NO_FATAL_FAILURE(assertMotionRange(info, 2031 AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_MOUSE, 0.0f, 1.0f, 0.0f, 0.0f)); 2032 2033 // When the bounds are set, then there should be a valid motion range. 2034 mFakePointerController->setBounds(1, 2, 800 - 1, 480 - 1); 2035 2036 InputDeviceInfo info2; 2037 mapper->populateDeviceInfo(&info2); 2038 2039 ASSERT_NO_FATAL_FAILURE(assertMotionRange(info2, 2040 AINPUT_MOTION_RANGE_X, AINPUT_SOURCE_MOUSE, 2041 1, 800 - 1, 0.0f, 0.0f)); 2042 ASSERT_NO_FATAL_FAILURE(assertMotionRange(info2, 2043 AINPUT_MOTION_RANGE_Y, AINPUT_SOURCE_MOUSE, 2044 2, 480 - 1, 0.0f, 0.0f)); 2045 ASSERT_NO_FATAL_FAILURE(assertMotionRange(info2, 2046 AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_MOUSE, 2047 0.0f, 1.0f, 0.0f, 0.0f)); 2048} 2049 2050TEST_F(CursorInputMapperTest, WhenModeIsNavigation_PopulateDeviceInfo_ReturnsScaledRange) { 2051 CursorInputMapper* mapper = new CursorInputMapper(mDevice); 2052 addConfigurationProperty("cursor.mode", "navigation"); 2053 addMapperAndConfigure(mapper); 2054 2055 InputDeviceInfo info; 2056 mapper->populateDeviceInfo(&info); 2057 2058 ASSERT_NO_FATAL_FAILURE(assertMotionRange(info, 2059 AINPUT_MOTION_RANGE_X, AINPUT_SOURCE_TRACKBALL, 2060 -1.0f, 1.0f, 0.0f, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD)); 2061 ASSERT_NO_FATAL_FAILURE(assertMotionRange(info, 2062 AINPUT_MOTION_RANGE_Y, AINPUT_SOURCE_TRACKBALL, 2063 -1.0f, 1.0f, 0.0f, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD)); 2064 ASSERT_NO_FATAL_FAILURE(assertMotionRange(info, 2065 AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_TRACKBALL, 2066 0.0f, 1.0f, 0.0f, 0.0f)); 2067} 2068 2069TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaState) { 2070 CursorInputMapper* mapper = new CursorInputMapper(mDevice); 2071 addConfigurationProperty("cursor.mode", "navigation"); 2072 addMapperAndConfigure(mapper); 2073 2074 mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); 2075 2076 FakeInputDispatcher::NotifyMotionArgs args; 2077 2078 // Button press. 2079 // Mostly testing non x/y behavior here so we don't need to check again elsewhere. 2080 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0, 1, 0); 2081 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 2082 ASSERT_EQ(ARBITRARY_TIME, args.eventTime); 2083 ASSERT_EQ(DEVICE_ID, args.deviceId); 2084 ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, args.source); 2085 ASSERT_EQ(uint32_t(0), args.policyFlags); 2086 ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action); 2087 ASSERT_EQ(0, args.flags); 2088 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); 2089 ASSERT_EQ(0, args.edgeFlags); 2090 ASSERT_EQ(uint32_t(1), args.pointerCount); 2091 ASSERT_EQ(0, args.pointerIds[0]); 2092 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 2093 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); 2094 ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); 2095 ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); 2096 ASSERT_EQ(ARBITRARY_TIME, args.downTime); 2097 2098 // Button release. Should have same down time. 2099 process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, EV_KEY, BTN_MOUSE, 0, 0, 0); 2100 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 2101 ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime); 2102 ASSERT_EQ(DEVICE_ID, args.deviceId); 2103 ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, args.source); 2104 ASSERT_EQ(uint32_t(0), args.policyFlags); 2105 ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action); 2106 ASSERT_EQ(0, args.flags); 2107 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); 2108 ASSERT_EQ(0, args.edgeFlags); 2109 ASSERT_EQ(uint32_t(1), args.pointerCount); 2110 ASSERT_EQ(0, args.pointerIds[0]); 2111 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 2112 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); 2113 ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); 2114 ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); 2115 ASSERT_EQ(ARBITRARY_TIME, args.downTime); 2116} 2117 2118TEST_F(CursorInputMapperTest, Process_ShouldHandleIndependentXYUpdates) { 2119 CursorInputMapper* mapper = new CursorInputMapper(mDevice); 2120 addConfigurationProperty("cursor.mode", "navigation"); 2121 addMapperAndConfigure(mapper); 2122 2123 FakeInputDispatcher::NotifyMotionArgs args; 2124 2125 // Motion in X but not Y. 2126 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 0, 1, 0); 2127 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0, 0, 0); 2128 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 2129 ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action); 2130 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 2131 1.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); 2132 2133 // Motion in Y but not X. 2134 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, 0, -2, 0); 2135 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0, 0, 0); 2136 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 2137 ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action); 2138 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 2139 0.0f, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); 2140} 2141 2142TEST_F(CursorInputMapperTest, Process_ShouldHandleIndependentButtonUpdates) { 2143 CursorInputMapper* mapper = new CursorInputMapper(mDevice); 2144 addConfigurationProperty("cursor.mode", "navigation"); 2145 addMapperAndConfigure(mapper); 2146 2147 FakeInputDispatcher::NotifyMotionArgs args; 2148 2149 // Button press without following sync. 2150 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0, 1, 0); 2151 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 2152 ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action); 2153 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 2154 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); 2155 2156 // Button release without following sync. 2157 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0, 0, 0); 2158 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 2159 ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action); 2160 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 2161 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); 2162} 2163 2164TEST_F(CursorInputMapperTest, Process_ShouldHandleCombinedXYAndButtonUpdates) { 2165 CursorInputMapper* mapper = new CursorInputMapper(mDevice); 2166 addConfigurationProperty("cursor.mode", "navigation"); 2167 addMapperAndConfigure(mapper); 2168 2169 FakeInputDispatcher::NotifyMotionArgs args; 2170 2171 // Combined X, Y and Button. 2172 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 0, 1, 0); 2173 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, 0, -2, 0); 2174 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0, 1, 0); 2175 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0, 0, 0); 2176 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 2177 ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action); 2178 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 2179 1.0f / TRACKBALL_MOVEMENT_THRESHOLD, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 2180 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); 2181 2182 // Move X, Y a bit while pressed. 2183 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 0, 2, 0); 2184 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, 0, 1, 0); 2185 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0, 0, 0); 2186 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 2187 ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action); 2188 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 2189 2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD, 2190 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); 2191 2192 // Release Button. 2193 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0, 0, 0); 2194 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 2195 ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action); 2196 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 2197 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); 2198} 2199 2200TEST_F(CursorInputMapperTest, Reset_WhenButtonIsNotDown_ShouldNotSynthesizeButtonUp) { 2201 CursorInputMapper* mapper = new CursorInputMapper(mDevice); 2202 addConfigurationProperty("cursor.mode", "navigation"); 2203 addMapperAndConfigure(mapper); 2204 2205 FakeInputDispatcher::NotifyMotionArgs args; 2206 2207 // Button press. 2208 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0, 1, 0); 2209 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 2210 2211 // Button release. 2212 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0, 0, 0); 2213 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 2214 2215 // Reset. Should not synthesize button up since button is not pressed. 2216 mapper->reset(); 2217 2218 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasNotCalled()); 2219} 2220 2221TEST_F(CursorInputMapperTest, Reset_WhenButtonIsDown_ShouldSynthesizeButtonUp) { 2222 CursorInputMapper* mapper = new CursorInputMapper(mDevice); 2223 addConfigurationProperty("cursor.mode", "navigation"); 2224 addMapperAndConfigure(mapper); 2225 2226 FakeInputDispatcher::NotifyMotionArgs args; 2227 2228 // Button press. 2229 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0, 1, 0); 2230 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 2231 2232 // Reset. Should synthesize button up. 2233 mapper->reset(); 2234 2235 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 2236 ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action); 2237 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 2238 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); 2239} 2240 2241TEST_F(CursorInputMapperTest, Process_WhenNotOrientationAware_ShouldNotRotateMotions) { 2242 CursorInputMapper* mapper = new CursorInputMapper(mDevice); 2243 addConfigurationProperty("cursor.mode", "navigation"); 2244 addMapperAndConfigure(mapper); 2245 2246 mFakePolicy->setDisplayInfo(DISPLAY_ID, 2247 DISPLAY_WIDTH, DISPLAY_HEIGHT, 2248 DISPLAY_ORIENTATION_90); 2249 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 0, 1)); 2250 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, 1, 1)); 2251 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 0, 1, 0)); 2252 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, -1, 1, -1)); 2253 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, -1, 0, -1)); 2254 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, -1, -1)); 2255 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 0, -1, 0)); 2256 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, -1, 1)); 2257} 2258 2259TEST_F(CursorInputMapperTest, Process_WhenOrientationAware_ShouldRotateMotions) { 2260 CursorInputMapper* mapper = new CursorInputMapper(mDevice); 2261 addConfigurationProperty("cursor.mode", "navigation"); 2262 addConfigurationProperty("cursor.orientationAware", "1"); 2263 addMapperAndConfigure(mapper); 2264 2265 mFakePolicy->setDisplayInfo(DISPLAY_ID, 2266 DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0); 2267 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 0, 1)); 2268 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, 1, 1)); 2269 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 0, 1, 0)); 2270 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, -1, 1, -1)); 2271 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, -1, 0, -1)); 2272 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, -1, -1)); 2273 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 0, -1, 0)); 2274 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, -1, 1)); 2275 2276 mFakePolicy->setDisplayInfo(DISPLAY_ID, 2277 DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_90); 2278 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 1, 0)); 2279 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, 1, -1)); 2280 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 0, 0, -1)); 2281 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, -1, -1, -1)); 2282 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, -1, -1, 0)); 2283 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, -1, 1)); 2284 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 0, 0, 1)); 2285 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, 1, 1)); 2286 2287 mFakePolicy->setDisplayInfo(DISPLAY_ID, 2288 DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_180); 2289 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 0, -1)); 2290 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, -1, -1)); 2291 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 0, -1, 0)); 2292 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, -1, -1, 1)); 2293 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, -1, 0, 1)); 2294 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, 1, 1)); 2295 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 0, 1, 0)); 2296 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, 1, -1)); 2297 2298 mFakePolicy->setDisplayInfo(DISPLAY_ID, 2299 DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_270); 2300 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, -1, 0)); 2301 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, -1, 1)); 2302 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 0, 0, 1)); 2303 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, -1, 1, 1)); 2304 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, -1, 1, 0)); 2305 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, 1, -1)); 2306 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 0, 0, -1)); 2307 ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, -1, -1)); 2308} 2309 2310 2311// --- TouchInputMapperTest --- 2312 2313class TouchInputMapperTest : public InputMapperTest { 2314protected: 2315 static const int32_t RAW_X_MIN; 2316 static const int32_t RAW_X_MAX; 2317 static const int32_t RAW_Y_MIN; 2318 static const int32_t RAW_Y_MAX; 2319 static const int32_t RAW_TOUCH_MIN; 2320 static const int32_t RAW_TOUCH_MAX; 2321 static const int32_t RAW_TOOL_MIN; 2322 static const int32_t RAW_TOOL_MAX; 2323 static const int32_t RAW_PRESSURE_MIN; 2324 static const int32_t RAW_PRESSURE_MAX; 2325 static const int32_t RAW_ORIENTATION_MIN; 2326 static const int32_t RAW_ORIENTATION_MAX; 2327 static const int32_t RAW_ID_MIN; 2328 static const int32_t RAW_ID_MAX; 2329 static const float X_PRECISION; 2330 static const float Y_PRECISION; 2331 2332 static const VirtualKeyDefinition VIRTUAL_KEYS[2]; 2333 2334 enum Axes { 2335 POSITION = 1 << 0, 2336 TOUCH = 1 << 1, 2337 TOOL = 1 << 2, 2338 PRESSURE = 1 << 3, 2339 ORIENTATION = 1 << 4, 2340 MINOR = 1 << 5, 2341 ID = 1 << 6, 2342 }; 2343 2344 void prepareDisplay(int32_t orientation); 2345 void prepareVirtualKeys(); 2346 int32_t toRawX(float displayX); 2347 int32_t toRawY(float displayY); 2348 float toDisplayX(int32_t rawX); 2349 float toDisplayY(int32_t rawY); 2350}; 2351 2352const int32_t TouchInputMapperTest::RAW_X_MIN = 25; 2353const int32_t TouchInputMapperTest::RAW_X_MAX = 1019; 2354const int32_t TouchInputMapperTest::RAW_Y_MIN = 30; 2355const int32_t TouchInputMapperTest::RAW_Y_MAX = 1009; 2356const int32_t TouchInputMapperTest::RAW_TOUCH_MIN = 0; 2357const int32_t TouchInputMapperTest::RAW_TOUCH_MAX = 31; 2358const int32_t TouchInputMapperTest::RAW_TOOL_MIN = 0; 2359const int32_t TouchInputMapperTest::RAW_TOOL_MAX = 15; 2360const int32_t TouchInputMapperTest::RAW_PRESSURE_MIN = RAW_TOUCH_MIN; 2361const int32_t TouchInputMapperTest::RAW_PRESSURE_MAX = RAW_TOUCH_MAX; 2362const int32_t TouchInputMapperTest::RAW_ORIENTATION_MIN = -7; 2363const int32_t TouchInputMapperTest::RAW_ORIENTATION_MAX = 7; 2364const int32_t TouchInputMapperTest::RAW_ID_MIN = 0; 2365const int32_t TouchInputMapperTest::RAW_ID_MAX = 9; 2366const float TouchInputMapperTest::X_PRECISION = float(RAW_X_MAX - RAW_X_MIN + 1) / DISPLAY_WIDTH; 2367const float TouchInputMapperTest::Y_PRECISION = float(RAW_Y_MAX - RAW_Y_MIN + 1) / DISPLAY_HEIGHT; 2368 2369const VirtualKeyDefinition TouchInputMapperTest::VIRTUAL_KEYS[2] = { 2370 { KEY_HOME, 60, DISPLAY_HEIGHT + 15, 20, 20 }, 2371 { KEY_MENU, DISPLAY_HEIGHT - 60, DISPLAY_WIDTH + 15, 20, 20 }, 2372}; 2373 2374void TouchInputMapperTest::prepareDisplay(int32_t orientation) { 2375 mFakePolicy->setDisplayInfo(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, orientation); 2376} 2377 2378void TouchInputMapperTest::prepareVirtualKeys() { 2379 mFakeEventHub->addVirtualKeyDefinition(DEVICE_ID, VIRTUAL_KEYS[0]); 2380 mFakeEventHub->addVirtualKeyDefinition(DEVICE_ID, VIRTUAL_KEYS[1]); 2381 mFakeEventHub->addKey(DEVICE_ID, KEY_HOME, AKEYCODE_HOME, POLICY_FLAG_WAKE); 2382 mFakeEventHub->addKey(DEVICE_ID, KEY_MENU, AKEYCODE_MENU, POLICY_FLAG_WAKE); 2383} 2384 2385int32_t TouchInputMapperTest::toRawX(float displayX) { 2386 return int32_t(displayX * (RAW_X_MAX - RAW_X_MIN + 1) / DISPLAY_WIDTH + RAW_X_MIN); 2387} 2388 2389int32_t TouchInputMapperTest::toRawY(float displayY) { 2390 return int32_t(displayY * (RAW_Y_MAX - RAW_Y_MIN + 1) / DISPLAY_HEIGHT + RAW_Y_MIN); 2391} 2392 2393float TouchInputMapperTest::toDisplayX(int32_t rawX) { 2394 return float(rawX - RAW_X_MIN) * DISPLAY_WIDTH / (RAW_X_MAX - RAW_X_MIN + 1); 2395} 2396 2397float TouchInputMapperTest::toDisplayY(int32_t rawY) { 2398 return float(rawY - RAW_Y_MIN) * DISPLAY_HEIGHT / (RAW_Y_MAX - RAW_Y_MIN + 1); 2399} 2400 2401 2402// --- SingleTouchInputMapperTest --- 2403 2404class SingleTouchInputMapperTest : public TouchInputMapperTest { 2405protected: 2406 void prepareAxes(int axes); 2407 2408 void processDown(SingleTouchInputMapper* mapper, int32_t x, int32_t y); 2409 void processMove(SingleTouchInputMapper* mapper, int32_t x, int32_t y); 2410 void processUp(SingleTouchInputMapper* mappery); 2411 void processPressure(SingleTouchInputMapper* mapper, int32_t pressure); 2412 void processToolMajor(SingleTouchInputMapper* mapper, int32_t toolMajor); 2413 void processSync(SingleTouchInputMapper* mapper); 2414}; 2415 2416void SingleTouchInputMapperTest::prepareAxes(int axes) { 2417 if (axes & POSITION) { 2418 mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_X, 2419 RAW_X_MIN, RAW_X_MAX, 0, 0); 2420 mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_Y, 2421 RAW_Y_MIN, RAW_Y_MAX, 0, 0); 2422 } 2423 if (axes & PRESSURE) { 2424 mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_PRESSURE, 2425 RAW_PRESSURE_MIN, RAW_PRESSURE_MAX, 0, 0); 2426 } 2427 if (axes & TOOL) { 2428 mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_TOOL_WIDTH, 2429 RAW_TOOL_MIN, RAW_TOOL_MAX, 0, 0); 2430 } 2431} 2432 2433void SingleTouchInputMapperTest::processDown(SingleTouchInputMapper* mapper, int32_t x, int32_t y) { 2434 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_TOUCH, 0, 1, 0); 2435 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_X, 0, x, 0); 2436 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_Y, 0, y, 0); 2437} 2438 2439void SingleTouchInputMapperTest::processMove(SingleTouchInputMapper* mapper, int32_t x, int32_t y) { 2440 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_X, 0, x, 0); 2441 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_Y, 0, y, 0); 2442} 2443 2444void SingleTouchInputMapperTest::processUp(SingleTouchInputMapper* mapper) { 2445 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_TOUCH, 0, 0, 0); 2446} 2447 2448void SingleTouchInputMapperTest::processPressure( 2449 SingleTouchInputMapper* mapper, int32_t pressure) { 2450 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_PRESSURE, 0, pressure, 0); 2451} 2452 2453void SingleTouchInputMapperTest::processToolMajor( 2454 SingleTouchInputMapper* mapper, int32_t toolMajor) { 2455 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_TOOL_WIDTH, 0, toolMajor, 0); 2456} 2457 2458void SingleTouchInputMapperTest::processSync(SingleTouchInputMapper* mapper) { 2459 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0, 0, 0); 2460} 2461 2462 2463TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndNotACursor_ReturnsPointer) { 2464 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 2465 prepareAxes(POSITION); 2466 addMapperAndConfigure(mapper); 2467 2468 ASSERT_EQ(AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, mapper->getSources()); 2469} 2470 2471TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndIsACursor_ReturnsTouchPad) { 2472 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 2473 mFakeEventHub->addRelativeAxis(DEVICE_ID, REL_X); 2474 mFakeEventHub->addRelativeAxis(DEVICE_ID, REL_Y); 2475 prepareAxes(POSITION); 2476 addMapperAndConfigure(mapper); 2477 2478 ASSERT_EQ(AINPUT_SOURCE_TOUCHPAD, mapper->getSources()); 2479} 2480 2481TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsTouchPad_ReturnsTouchPad) { 2482 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 2483 prepareAxes(POSITION); 2484 addConfigurationProperty("touch.deviceType", "touchPad"); 2485 addMapperAndConfigure(mapper); 2486 2487 ASSERT_EQ(AINPUT_SOURCE_TOUCHPAD, mapper->getSources()); 2488} 2489 2490TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsTouchScreen_ReturnsTouchScreen) { 2491 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 2492 prepareAxes(POSITION); 2493 addConfigurationProperty("touch.deviceType", "touchScreen"); 2494 addMapperAndConfigure(mapper); 2495 2496 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, mapper->getSources()); 2497} 2498 2499TEST_F(SingleTouchInputMapperTest, GetKeyCodeState) { 2500 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 2501 addConfigurationProperty("touch.deviceType", "touchScreen"); 2502 prepareDisplay(DISPLAY_ORIENTATION_0); 2503 prepareAxes(POSITION); 2504 prepareVirtualKeys(); 2505 addMapperAndConfigure(mapper); 2506 2507 // Unknown key. 2508 ASSERT_EQ(AKEY_STATE_UNKNOWN, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_A)); 2509 2510 // Virtual key is down. 2511 int32_t x = toRawX(VIRTUAL_KEYS[0].centerX); 2512 int32_t y = toRawY(VIRTUAL_KEYS[0].centerY); 2513 processDown(mapper, x, y); 2514 processSync(mapper); 2515 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled()); 2516 2517 ASSERT_EQ(AKEY_STATE_VIRTUAL, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_HOME)); 2518 2519 // Virtual key is up. 2520 processUp(mapper); 2521 processSync(mapper); 2522 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled()); 2523 2524 ASSERT_EQ(AKEY_STATE_UP, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_HOME)); 2525} 2526 2527TEST_F(SingleTouchInputMapperTest, GetScanCodeState) { 2528 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 2529 addConfigurationProperty("touch.deviceType", "touchScreen"); 2530 prepareDisplay(DISPLAY_ORIENTATION_0); 2531 prepareAxes(POSITION); 2532 prepareVirtualKeys(); 2533 addMapperAndConfigure(mapper); 2534 2535 // Unknown key. 2536 ASSERT_EQ(AKEY_STATE_UNKNOWN, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_A)); 2537 2538 // Virtual key is down. 2539 int32_t x = toRawX(VIRTUAL_KEYS[0].centerX); 2540 int32_t y = toRawY(VIRTUAL_KEYS[0].centerY); 2541 processDown(mapper, x, y); 2542 processSync(mapper); 2543 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled()); 2544 2545 ASSERT_EQ(AKEY_STATE_VIRTUAL, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_HOME)); 2546 2547 // Virtual key is up. 2548 processUp(mapper); 2549 processSync(mapper); 2550 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled()); 2551 2552 ASSERT_EQ(AKEY_STATE_UP, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_HOME)); 2553} 2554 2555TEST_F(SingleTouchInputMapperTest, MarkSupportedKeyCodes) { 2556 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 2557 addConfigurationProperty("touch.deviceType", "touchScreen"); 2558 prepareDisplay(DISPLAY_ORIENTATION_0); 2559 prepareAxes(POSITION); 2560 prepareVirtualKeys(); 2561 addMapperAndConfigure(mapper); 2562 2563 const int32_t keys[2] = { AKEYCODE_HOME, AKEYCODE_A }; 2564 uint8_t flags[2] = { 0, 0 }; 2565 ASSERT_TRUE(mapper->markSupportedKeyCodes(AINPUT_SOURCE_ANY, 2, keys, flags)); 2566 ASSERT_TRUE(flags[0]); 2567 ASSERT_FALSE(flags[1]); 2568} 2569 2570TEST_F(SingleTouchInputMapperTest, Reset_WhenVirtualKeysAreDown_SendsUp) { 2571 // Note: Ideally we should send cancels but the implementation is more straightforward 2572 // with up and this will only happen if a device is forcibly removed. 2573 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 2574 addConfigurationProperty("touch.deviceType", "touchScreen"); 2575 prepareDisplay(DISPLAY_ORIENTATION_0); 2576 prepareAxes(POSITION); 2577 prepareVirtualKeys(); 2578 addMapperAndConfigure(mapper); 2579 2580 mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); 2581 2582 // Press virtual key. 2583 int32_t x = toRawX(VIRTUAL_KEYS[0].centerX); 2584 int32_t y = toRawY(VIRTUAL_KEYS[0].centerY); 2585 processDown(mapper, x, y); 2586 processSync(mapper); 2587 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled()); 2588 2589 // Reset. Since key is down, synthesize key up. 2590 mapper->reset(); 2591 2592 FakeInputDispatcher::NotifyKeyArgs args; 2593 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&args)); 2594 //ASSERT_EQ(ARBITRARY_TIME, args.eventTime); 2595 ASSERT_EQ(DEVICE_ID, args.deviceId); 2596 ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); 2597 ASSERT_EQ(POLICY_FLAG_VIRTUAL, args.policyFlags); 2598 ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); 2599 ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, args.flags); 2600 ASSERT_EQ(AKEYCODE_HOME, args.keyCode); 2601 ASSERT_EQ(KEY_HOME, args.scanCode); 2602 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); 2603 ASSERT_EQ(ARBITRARY_TIME, args.downTime); 2604} 2605 2606TEST_F(SingleTouchInputMapperTest, Reset_WhenNothingIsPressed_NothingMuchHappens) { 2607 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 2608 addConfigurationProperty("touch.deviceType", "touchScreen"); 2609 prepareDisplay(DISPLAY_ORIENTATION_0); 2610 prepareAxes(POSITION); 2611 prepareVirtualKeys(); 2612 addMapperAndConfigure(mapper); 2613 2614 // Press virtual key. 2615 int32_t x = toRawX(VIRTUAL_KEYS[0].centerX); 2616 int32_t y = toRawY(VIRTUAL_KEYS[0].centerY); 2617 processDown(mapper, x, y); 2618 processSync(mapper); 2619 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled()); 2620 2621 // Release virtual key. 2622 processUp(mapper); 2623 processSync(mapper); 2624 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled()); 2625 2626 // Reset. Since no key is down, nothing happens. 2627 mapper->reset(); 2628 2629 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasNotCalled()); 2630 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasNotCalled()); 2631} 2632 2633TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndReleasedNormally_SendsKeyDownAndKeyUp) { 2634 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 2635 addConfigurationProperty("touch.deviceType", "touchScreen"); 2636 prepareDisplay(DISPLAY_ORIENTATION_0); 2637 prepareAxes(POSITION); 2638 prepareVirtualKeys(); 2639 addMapperAndConfigure(mapper); 2640 2641 mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); 2642 2643 FakeInputDispatcher::NotifyKeyArgs args; 2644 2645 // Press virtual key. 2646 int32_t x = toRawX(VIRTUAL_KEYS[0].centerX); 2647 int32_t y = toRawY(VIRTUAL_KEYS[0].centerY); 2648 processDown(mapper, x, y); 2649 processSync(mapper); 2650 2651 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&args)); 2652 ASSERT_EQ(ARBITRARY_TIME, args.eventTime); 2653 ASSERT_EQ(DEVICE_ID, args.deviceId); 2654 ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); 2655 ASSERT_EQ(POLICY_FLAG_VIRTUAL, args.policyFlags); 2656 ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); 2657 ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, args.flags); 2658 ASSERT_EQ(AKEYCODE_HOME, args.keyCode); 2659 ASSERT_EQ(KEY_HOME, args.scanCode); 2660 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); 2661 ASSERT_EQ(ARBITRARY_TIME, args.downTime); 2662 2663 // Release virtual key. 2664 processUp(mapper); 2665 processSync(mapper); 2666 2667 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&args)); 2668 ASSERT_EQ(ARBITRARY_TIME, args.eventTime); 2669 ASSERT_EQ(DEVICE_ID, args.deviceId); 2670 ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); 2671 ASSERT_EQ(POLICY_FLAG_VIRTUAL, args.policyFlags); 2672 ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); 2673 ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, args.flags); 2674 ASSERT_EQ(AKEYCODE_HOME, args.keyCode); 2675 ASSERT_EQ(KEY_HOME, args.scanCode); 2676 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); 2677 ASSERT_EQ(ARBITRARY_TIME, args.downTime); 2678 2679 // Should not have sent any motions. 2680 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasNotCalled()); 2681} 2682 2683TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndMovedOutOfBounds_SendsKeyDownAndKeyCancel) { 2684 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 2685 addConfigurationProperty("touch.deviceType", "touchScreen"); 2686 prepareDisplay(DISPLAY_ORIENTATION_0); 2687 prepareAxes(POSITION); 2688 prepareVirtualKeys(); 2689 addMapperAndConfigure(mapper); 2690 2691 mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); 2692 2693 FakeInputDispatcher::NotifyKeyArgs keyArgs; 2694 2695 // Press virtual key. 2696 int32_t x = toRawX(VIRTUAL_KEYS[0].centerX); 2697 int32_t y = toRawY(VIRTUAL_KEYS[0].centerY); 2698 processDown(mapper, x, y); 2699 processSync(mapper); 2700 2701 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&keyArgs)); 2702 ASSERT_EQ(ARBITRARY_TIME, keyArgs.eventTime); 2703 ASSERT_EQ(DEVICE_ID, keyArgs.deviceId); 2704 ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, keyArgs.source); 2705 ASSERT_EQ(POLICY_FLAG_VIRTUAL, keyArgs.policyFlags); 2706 ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); 2707 ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, keyArgs.flags); 2708 ASSERT_EQ(AKEYCODE_HOME, keyArgs.keyCode); 2709 ASSERT_EQ(KEY_HOME, keyArgs.scanCode); 2710 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, keyArgs.metaState); 2711 ASSERT_EQ(ARBITRARY_TIME, keyArgs.downTime); 2712 2713 // Move out of bounds. This should generate a cancel and a pointer down since we moved 2714 // into the display area. 2715 y -= 100; 2716 processMove(mapper, x, y); 2717 processSync(mapper); 2718 2719 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasCalled(&keyArgs)); 2720 ASSERT_EQ(ARBITRARY_TIME, keyArgs.eventTime); 2721 ASSERT_EQ(DEVICE_ID, keyArgs.deviceId); 2722 ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, keyArgs.source); 2723 ASSERT_EQ(POLICY_FLAG_VIRTUAL, keyArgs.policyFlags); 2724 ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); 2725 ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY 2726 | AKEY_EVENT_FLAG_CANCELED, keyArgs.flags); 2727 ASSERT_EQ(AKEYCODE_HOME, keyArgs.keyCode); 2728 ASSERT_EQ(KEY_HOME, keyArgs.scanCode); 2729 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, keyArgs.metaState); 2730 ASSERT_EQ(ARBITRARY_TIME, keyArgs.downTime); 2731 2732 FakeInputDispatcher::NotifyMotionArgs motionArgs; 2733 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 2734 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 2735 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 2736 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 2737 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 2738 ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); 2739 ASSERT_EQ(0, motionArgs.flags); 2740 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 2741 ASSERT_EQ(0, motionArgs.edgeFlags); 2742 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 2743 ASSERT_EQ(0, motionArgs.pointerIds[0]); 2744 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 2745 toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0)); 2746 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 2747 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 2748 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 2749 2750 // Keep moving out of bounds. Should generate a pointer move. 2751 y -= 50; 2752 processMove(mapper, x, y); 2753 processSync(mapper); 2754 2755 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 2756 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 2757 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 2758 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 2759 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 2760 ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); 2761 ASSERT_EQ(0, motionArgs.flags); 2762 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 2763 ASSERT_EQ(0, motionArgs.edgeFlags); 2764 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 2765 ASSERT_EQ(0, motionArgs.pointerIds[0]); 2766 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 2767 toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0)); 2768 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 2769 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 2770 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 2771 2772 // Release out of bounds. Should generate a pointer up. 2773 processUp(mapper); 2774 processSync(mapper); 2775 2776 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 2777 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 2778 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 2779 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 2780 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 2781 ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); 2782 ASSERT_EQ(0, motionArgs.flags); 2783 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 2784 ASSERT_EQ(0, motionArgs.edgeFlags); 2785 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 2786 ASSERT_EQ(0, motionArgs.pointerIds[0]); 2787 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 2788 toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0)); 2789 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 2790 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 2791 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 2792 2793 // Should not have sent any more keys or motions. 2794 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasNotCalled()); 2795 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasNotCalled()); 2796} 2797 2798TEST_F(SingleTouchInputMapperTest, Process_WhenTouchStartsOutsideDisplayAndMovesIn_SendsDownAsTouchEntersDisplay) { 2799 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 2800 addConfigurationProperty("touch.deviceType", "touchScreen"); 2801 prepareDisplay(DISPLAY_ORIENTATION_0); 2802 prepareAxes(POSITION); 2803 prepareVirtualKeys(); 2804 addMapperAndConfigure(mapper); 2805 2806 mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); 2807 2808 FakeInputDispatcher::NotifyMotionArgs motionArgs; 2809 2810 // Initially go down out of bounds. 2811 int32_t x = -10; 2812 int32_t y = -10; 2813 processDown(mapper, x, y); 2814 processSync(mapper); 2815 2816 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasNotCalled()); 2817 2818 // Move into the display area. Should generate a pointer down. 2819 x = 50; 2820 y = 75; 2821 processMove(mapper, x, y); 2822 processSync(mapper); 2823 2824 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 2825 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 2826 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 2827 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 2828 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 2829 ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); 2830 ASSERT_EQ(0, motionArgs.flags); 2831 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 2832 ASSERT_EQ(0, motionArgs.edgeFlags); 2833 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 2834 ASSERT_EQ(0, motionArgs.pointerIds[0]); 2835 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 2836 toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0)); 2837 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 2838 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 2839 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 2840 2841 // Release. Should generate a pointer up. 2842 processUp(mapper); 2843 processSync(mapper); 2844 2845 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 2846 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 2847 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 2848 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 2849 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 2850 ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); 2851 ASSERT_EQ(0, motionArgs.flags); 2852 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 2853 ASSERT_EQ(0, motionArgs.edgeFlags); 2854 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 2855 ASSERT_EQ(0, motionArgs.pointerIds[0]); 2856 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 2857 toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0)); 2858 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 2859 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 2860 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 2861 2862 // Should not have sent any more keys or motions. 2863 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasNotCalled()); 2864 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasNotCalled()); 2865} 2866 2867TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture) { 2868 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 2869 addConfigurationProperty("touch.deviceType", "touchScreen"); 2870 prepareDisplay(DISPLAY_ORIENTATION_0); 2871 prepareAxes(POSITION); 2872 prepareVirtualKeys(); 2873 addMapperAndConfigure(mapper); 2874 2875 mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); 2876 2877 FakeInputDispatcher::NotifyMotionArgs motionArgs; 2878 2879 // Down. 2880 int32_t x = 100; 2881 int32_t y = 125; 2882 processDown(mapper, x, y); 2883 processSync(mapper); 2884 2885 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 2886 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 2887 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 2888 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 2889 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 2890 ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); 2891 ASSERT_EQ(0, motionArgs.flags); 2892 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 2893 ASSERT_EQ(0, motionArgs.edgeFlags); 2894 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 2895 ASSERT_EQ(0, motionArgs.pointerIds[0]); 2896 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 2897 toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0)); 2898 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 2899 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 2900 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 2901 2902 // Move. 2903 x += 50; 2904 y += 75; 2905 processMove(mapper, x, y); 2906 processSync(mapper); 2907 2908 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 2909 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 2910 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 2911 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 2912 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 2913 ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); 2914 ASSERT_EQ(0, motionArgs.flags); 2915 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 2916 ASSERT_EQ(0, motionArgs.edgeFlags); 2917 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 2918 ASSERT_EQ(0, motionArgs.pointerIds[0]); 2919 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 2920 toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0)); 2921 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 2922 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 2923 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 2924 2925 // Up. 2926 processUp(mapper); 2927 processSync(mapper); 2928 2929 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 2930 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 2931 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 2932 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 2933 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 2934 ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); 2935 ASSERT_EQ(0, motionArgs.flags); 2936 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 2937 ASSERT_EQ(0, motionArgs.edgeFlags); 2938 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 2939 ASSERT_EQ(0, motionArgs.pointerIds[0]); 2940 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 2941 toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0)); 2942 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 2943 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 2944 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 2945 2946 // Should not have sent any more keys or motions. 2947 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasNotCalled()); 2948 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasNotCalled()); 2949} 2950 2951TEST_F(SingleTouchInputMapperTest, Process_WhenNotOrientationAware_DoesNotRotateMotions) { 2952 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 2953 addConfigurationProperty("touch.deviceType", "touchScreen"); 2954 prepareAxes(POSITION); 2955 addConfigurationProperty("touch.orientationAware", "0"); 2956 addMapperAndConfigure(mapper); 2957 2958 FakeInputDispatcher::NotifyMotionArgs args; 2959 2960 // Rotation 90. 2961 prepareDisplay(DISPLAY_ORIENTATION_90); 2962 processDown(mapper, toRawX(50), toRawY(75)); 2963 processSync(mapper); 2964 2965 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 2966 ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1); 2967 ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1); 2968 2969 processUp(mapper); 2970 processSync(mapper); 2971 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled()); 2972} 2973 2974TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationAware_RotatesMotions) { 2975 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 2976 addConfigurationProperty("touch.deviceType", "touchScreen"); 2977 prepareAxes(POSITION); 2978 addMapperAndConfigure(mapper); 2979 2980 FakeInputDispatcher::NotifyMotionArgs args; 2981 2982 // Rotation 0. 2983 prepareDisplay(DISPLAY_ORIENTATION_0); 2984 processDown(mapper, toRawX(50), toRawY(75)); 2985 processSync(mapper); 2986 2987 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 2988 ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1); 2989 ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1); 2990 2991 processUp(mapper); 2992 processSync(mapper); 2993 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled()); 2994 2995 // Rotation 90. 2996 prepareDisplay(DISPLAY_ORIENTATION_90); 2997 processDown(mapper, RAW_X_MAX - toRawX(75) + RAW_X_MIN, toRawY(50)); 2998 processSync(mapper); 2999 3000 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 3001 ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1); 3002 ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1); 3003 3004 processUp(mapper); 3005 processSync(mapper); 3006 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled()); 3007 3008 // Rotation 180. 3009 prepareDisplay(DISPLAY_ORIENTATION_180); 3010 processDown(mapper, RAW_X_MAX - toRawX(50) + RAW_X_MIN, RAW_Y_MAX - toRawY(75) + RAW_Y_MIN); 3011 processSync(mapper); 3012 3013 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 3014 ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1); 3015 ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1); 3016 3017 processUp(mapper); 3018 processSync(mapper); 3019 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled()); 3020 3021 // Rotation 270. 3022 prepareDisplay(DISPLAY_ORIENTATION_270); 3023 processDown(mapper, toRawX(75), RAW_Y_MAX - toRawY(50) + RAW_Y_MIN); 3024 processSync(mapper); 3025 3026 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 3027 ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1); 3028 ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1); 3029 3030 processUp(mapper); 3031 processSync(mapper); 3032 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled()); 3033} 3034 3035TEST_F(SingleTouchInputMapperTest, Process_AllAxes_DefaultCalibration) { 3036 SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); 3037 addConfigurationProperty("touch.deviceType", "touchScreen"); 3038 prepareDisplay(DISPLAY_ORIENTATION_0); 3039 prepareAxes(POSITION | PRESSURE | TOOL); 3040 addMapperAndConfigure(mapper); 3041 3042 // These calculations are based on the input device calibration documentation. 3043 int32_t rawX = 100; 3044 int32_t rawY = 200; 3045 int32_t rawPressure = 10; 3046 int32_t rawToolMajor = 12; 3047 3048 float x = toDisplayX(rawX); 3049 float y = toDisplayY(rawY); 3050 float pressure = float(rawPressure) / RAW_PRESSURE_MAX; 3051 float size = float(rawToolMajor) / RAW_TOOL_MAX; 3052 float tool = min(DISPLAY_WIDTH, DISPLAY_HEIGHT) * size; 3053 float touch = min(tool * pressure, tool); 3054 3055 processDown(mapper, rawX, rawY); 3056 processPressure(mapper, rawPressure); 3057 processToolMajor(mapper, rawToolMajor); 3058 processSync(mapper); 3059 3060 FakeInputDispatcher::NotifyMotionArgs args; 3061 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 3062 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 3063 x, y, pressure, size, touch, touch, tool, tool, 0)); 3064} 3065 3066 3067// --- MultiTouchInputMapperTest --- 3068 3069class MultiTouchInputMapperTest : public TouchInputMapperTest { 3070protected: 3071 void prepareAxes(int axes); 3072 3073 void processPosition(MultiTouchInputMapper* mapper, int32_t x, int32_t y); 3074 void processTouchMajor(MultiTouchInputMapper* mapper, int32_t touchMajor); 3075 void processTouchMinor(MultiTouchInputMapper* mapper, int32_t touchMinor); 3076 void processToolMajor(MultiTouchInputMapper* mapper, int32_t toolMajor); 3077 void processToolMinor(MultiTouchInputMapper* mapper, int32_t toolMinor); 3078 void processOrientation(MultiTouchInputMapper* mapper, int32_t orientation); 3079 void processPressure(MultiTouchInputMapper* mapper, int32_t pressure); 3080 void processId(MultiTouchInputMapper* mapper, int32_t id); 3081 void processMTSync(MultiTouchInputMapper* mapper); 3082 void processSync(MultiTouchInputMapper* mapper); 3083}; 3084 3085void MultiTouchInputMapperTest::prepareAxes(int axes) { 3086 if (axes & POSITION) { 3087 mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_POSITION_X, 3088 RAW_X_MIN, RAW_X_MAX, 0, 0); 3089 mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_POSITION_Y, 3090 RAW_Y_MIN, RAW_Y_MAX, 0, 0); 3091 } 3092 if (axes & TOUCH) { 3093 mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TOUCH_MAJOR, 3094 RAW_TOUCH_MIN, RAW_TOUCH_MAX, 0, 0); 3095 if (axes & MINOR) { 3096 mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TOUCH_MINOR, 3097 RAW_TOUCH_MIN, RAW_TOUCH_MAX, 0, 0); 3098 } 3099 } 3100 if (axes & TOOL) { 3101 mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_WIDTH_MAJOR, 3102 RAW_TOOL_MIN, RAW_TOOL_MAX, 0, 0); 3103 if (axes & MINOR) { 3104 mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_WIDTH_MINOR, 3105 RAW_TOOL_MAX, RAW_TOOL_MAX, 0, 0); 3106 } 3107 } 3108 if (axes & ORIENTATION) { 3109 mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_ORIENTATION, 3110 RAW_ORIENTATION_MIN, RAW_ORIENTATION_MAX, 0, 0); 3111 } 3112 if (axes & PRESSURE) { 3113 mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_PRESSURE, 3114 RAW_PRESSURE_MIN, RAW_PRESSURE_MAX, 0, 0); 3115 } 3116 if (axes & ID) { 3117 mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TRACKING_ID, 3118 RAW_ID_MIN, RAW_ID_MAX, 0, 0); 3119 } 3120} 3121 3122void MultiTouchInputMapperTest::processPosition( 3123 MultiTouchInputMapper* mapper, int32_t x, int32_t y) { 3124 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_POSITION_X, 0, x, 0); 3125 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_POSITION_Y, 0, y, 0); 3126} 3127 3128void MultiTouchInputMapperTest::processTouchMajor( 3129 MultiTouchInputMapper* mapper, int32_t touchMajor) { 3130 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TOUCH_MAJOR, 0, touchMajor, 0); 3131} 3132 3133void MultiTouchInputMapperTest::processTouchMinor( 3134 MultiTouchInputMapper* mapper, int32_t touchMinor) { 3135 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TOUCH_MINOR, 0, touchMinor, 0); 3136} 3137 3138void MultiTouchInputMapperTest::processToolMajor( 3139 MultiTouchInputMapper* mapper, int32_t toolMajor) { 3140 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_WIDTH_MAJOR, 0, toolMajor, 0); 3141} 3142 3143void MultiTouchInputMapperTest::processToolMinor( 3144 MultiTouchInputMapper* mapper, int32_t toolMinor) { 3145 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_WIDTH_MINOR, 0, toolMinor, 0); 3146} 3147 3148void MultiTouchInputMapperTest::processOrientation( 3149 MultiTouchInputMapper* mapper, int32_t orientation) { 3150 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_ORIENTATION, 0, orientation, 0); 3151} 3152 3153void MultiTouchInputMapperTest::processPressure( 3154 MultiTouchInputMapper* mapper, int32_t pressure) { 3155 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_PRESSURE, 0, pressure, 0); 3156} 3157 3158void MultiTouchInputMapperTest::processId( 3159 MultiTouchInputMapper* mapper, int32_t id) { 3160 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TRACKING_ID, 0, id, 0); 3161} 3162 3163void MultiTouchInputMapperTest::processMTSync(MultiTouchInputMapper* mapper) { 3164 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_MT_REPORT, 0, 0, 0); 3165} 3166 3167void MultiTouchInputMapperTest::processSync(MultiTouchInputMapper* mapper) { 3168 process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0, 0, 0); 3169} 3170 3171 3172TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackingIds) { 3173 MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); 3174 addConfigurationProperty("touch.deviceType", "touchScreen"); 3175 prepareDisplay(DISPLAY_ORIENTATION_0); 3176 prepareAxes(POSITION); 3177 prepareVirtualKeys(); 3178 addMapperAndConfigure(mapper); 3179 3180 mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); 3181 3182 FakeInputDispatcher::NotifyMotionArgs motionArgs; 3183 3184 // Two fingers down at once. 3185 int32_t x1 = 100, y1 = 125, x2 = 300, y2 = 500; 3186 processPosition(mapper, x1, y1); 3187 processMTSync(mapper); 3188 processPosition(mapper, x2, y2); 3189 processMTSync(mapper); 3190 processSync(mapper); 3191 3192 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3193 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 3194 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 3195 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 3196 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 3197 ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); 3198 ASSERT_EQ(0, motionArgs.flags); 3199 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 3200 ASSERT_EQ(0, motionArgs.edgeFlags); 3201 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 3202 ASSERT_EQ(0, motionArgs.pointerIds[0]); 3203 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3204 toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0)); 3205 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 3206 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 3207 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 3208 3209 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3210 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 3211 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 3212 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 3213 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 3214 ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), 3215 motionArgs.action); 3216 ASSERT_EQ(0, motionArgs.flags); 3217 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 3218 ASSERT_EQ(0, motionArgs.edgeFlags); 3219 ASSERT_EQ(size_t(2), motionArgs.pointerCount); 3220 ASSERT_EQ(0, motionArgs.pointerIds[0]); 3221 ASSERT_EQ(1, motionArgs.pointerIds[1]); 3222 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3223 toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0)); 3224 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], 3225 toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0)); 3226 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 3227 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 3228 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 3229 3230 // Move. 3231 x1 += 10; y1 += 15; x2 += 5; y2 -= 10; 3232 processPosition(mapper, x1, y1); 3233 processMTSync(mapper); 3234 processPosition(mapper, x2, y2); 3235 processMTSync(mapper); 3236 processSync(mapper); 3237 3238 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3239 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 3240 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 3241 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 3242 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 3243 ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); 3244 ASSERT_EQ(0, motionArgs.flags); 3245 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 3246 ASSERT_EQ(0, motionArgs.edgeFlags); 3247 ASSERT_EQ(size_t(2), motionArgs.pointerCount); 3248 ASSERT_EQ(0, motionArgs.pointerIds[0]); 3249 ASSERT_EQ(1, motionArgs.pointerIds[1]); 3250 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3251 toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0)); 3252 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], 3253 toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0)); 3254 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 3255 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 3256 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 3257 3258 // First finger up. 3259 x2 += 15; y2 -= 20; 3260 processPosition(mapper, x2, y2); 3261 processMTSync(mapper); 3262 processSync(mapper); 3263 3264 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3265 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 3266 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 3267 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 3268 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 3269 ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), 3270 motionArgs.action); 3271 ASSERT_EQ(0, motionArgs.flags); 3272 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 3273 ASSERT_EQ(0, motionArgs.edgeFlags); 3274 ASSERT_EQ(size_t(2), motionArgs.pointerCount); 3275 ASSERT_EQ(0, motionArgs.pointerIds[0]); 3276 ASSERT_EQ(1, motionArgs.pointerIds[1]); 3277 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3278 toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0)); 3279 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], 3280 toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0)); 3281 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 3282 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 3283 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 3284 3285 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3286 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 3287 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 3288 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 3289 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 3290 ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); 3291 ASSERT_EQ(0, motionArgs.flags); 3292 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 3293 ASSERT_EQ(0, motionArgs.edgeFlags); 3294 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 3295 ASSERT_EQ(1, motionArgs.pointerIds[0]); 3296 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3297 toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0)); 3298 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 3299 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 3300 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 3301 3302 // Move. 3303 x2 += 20; y2 -= 25; 3304 processPosition(mapper, x2, y2); 3305 processMTSync(mapper); 3306 processSync(mapper); 3307 3308 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3309 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 3310 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 3311 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 3312 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 3313 ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); 3314 ASSERT_EQ(0, motionArgs.flags); 3315 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 3316 ASSERT_EQ(0, motionArgs.edgeFlags); 3317 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 3318 ASSERT_EQ(1, motionArgs.pointerIds[0]); 3319 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3320 toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0)); 3321 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 3322 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 3323 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 3324 3325 // New finger down. 3326 int32_t x3 = 700, y3 = 300; 3327 processPosition(mapper, x2, y2); 3328 processMTSync(mapper); 3329 processPosition(mapper, x3, y3); 3330 processMTSync(mapper); 3331 processSync(mapper); 3332 3333 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3334 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 3335 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 3336 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 3337 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 3338 ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), 3339 motionArgs.action); 3340 ASSERT_EQ(0, motionArgs.flags); 3341 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 3342 ASSERT_EQ(0, motionArgs.edgeFlags); 3343 ASSERT_EQ(size_t(2), motionArgs.pointerCount); 3344 ASSERT_EQ(0, motionArgs.pointerIds[0]); 3345 ASSERT_EQ(1, motionArgs.pointerIds[1]); 3346 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3347 toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0)); 3348 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], 3349 toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0)); 3350 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 3351 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 3352 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 3353 3354 // Second finger up. 3355 x3 += 30; y3 -= 20; 3356 processPosition(mapper, x3, y3); 3357 processMTSync(mapper); 3358 processSync(mapper); 3359 3360 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3361 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 3362 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 3363 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 3364 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 3365 ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), 3366 motionArgs.action); 3367 ASSERT_EQ(0, motionArgs.flags); 3368 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 3369 ASSERT_EQ(0, motionArgs.edgeFlags); 3370 ASSERT_EQ(size_t(2), motionArgs.pointerCount); 3371 ASSERT_EQ(0, motionArgs.pointerIds[0]); 3372 ASSERT_EQ(1, motionArgs.pointerIds[1]); 3373 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3374 toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0)); 3375 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], 3376 toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0)); 3377 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 3378 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 3379 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 3380 3381 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3382 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 3383 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 3384 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 3385 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 3386 ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); 3387 ASSERT_EQ(0, motionArgs.flags); 3388 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 3389 ASSERT_EQ(0, motionArgs.edgeFlags); 3390 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 3391 ASSERT_EQ(0, motionArgs.pointerIds[0]); 3392 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3393 toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0)); 3394 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 3395 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 3396 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 3397 3398 // Last finger up. 3399 processMTSync(mapper); 3400 processSync(mapper); 3401 3402 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3403 ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); 3404 ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); 3405 ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); 3406 ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); 3407 ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); 3408 ASSERT_EQ(0, motionArgs.flags); 3409 ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); 3410 ASSERT_EQ(0, motionArgs.edgeFlags); 3411 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 3412 ASSERT_EQ(0, motionArgs.pointerIds[0]); 3413 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3414 toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0)); 3415 ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); 3416 ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); 3417 ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); 3418 3419 // Should not have sent any more keys or motions. 3420 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasNotCalled()); 3421 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasNotCalled()); 3422} 3423 3424TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingIds) { 3425 MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); 3426 addConfigurationProperty("touch.deviceType", "touchScreen"); 3427 prepareDisplay(DISPLAY_ORIENTATION_0); 3428 prepareAxes(POSITION | ID); 3429 prepareVirtualKeys(); 3430 addMapperAndConfigure(mapper); 3431 3432 mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); 3433 3434 FakeInputDispatcher::NotifyMotionArgs motionArgs; 3435 3436 // Two fingers down at once. 3437 int32_t x1 = 100, y1 = 125, x2 = 300, y2 = 500; 3438 processPosition(mapper, x1, y1); 3439 processId(mapper, 1); 3440 processMTSync(mapper); 3441 processPosition(mapper, x2, y2); 3442 processId(mapper, 2); 3443 processMTSync(mapper); 3444 processSync(mapper); 3445 3446 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3447 ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); 3448 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 3449 ASSERT_EQ(1, motionArgs.pointerIds[0]); 3450 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3451 toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0)); 3452 3453 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3454 ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), 3455 motionArgs.action); 3456 ASSERT_EQ(size_t(2), motionArgs.pointerCount); 3457 ASSERT_EQ(1, motionArgs.pointerIds[0]); 3458 ASSERT_EQ(2, motionArgs.pointerIds[1]); 3459 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3460 toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0)); 3461 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], 3462 toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0)); 3463 3464 // Move. 3465 x1 += 10; y1 += 15; x2 += 5; y2 -= 10; 3466 processPosition(mapper, x1, y1); 3467 processId(mapper, 1); 3468 processMTSync(mapper); 3469 processPosition(mapper, x2, y2); 3470 processId(mapper, 2); 3471 processMTSync(mapper); 3472 processSync(mapper); 3473 3474 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3475 ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); 3476 ASSERT_EQ(size_t(2), motionArgs.pointerCount); 3477 ASSERT_EQ(1, motionArgs.pointerIds[0]); 3478 ASSERT_EQ(2, motionArgs.pointerIds[1]); 3479 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3480 toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0)); 3481 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], 3482 toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0)); 3483 3484 // First finger up. 3485 x2 += 15; y2 -= 20; 3486 processPosition(mapper, x2, y2); 3487 processId(mapper, 2); 3488 processMTSync(mapper); 3489 processSync(mapper); 3490 3491 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3492 ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), 3493 motionArgs.action); 3494 ASSERT_EQ(size_t(2), motionArgs.pointerCount); 3495 ASSERT_EQ(1, motionArgs.pointerIds[0]); 3496 ASSERT_EQ(2, motionArgs.pointerIds[1]); 3497 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3498 toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0)); 3499 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], 3500 toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0)); 3501 3502 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3503 ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); 3504 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 3505 ASSERT_EQ(2, motionArgs.pointerIds[0]); 3506 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3507 toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0)); 3508 3509 // Move. 3510 x2 += 20; y2 -= 25; 3511 processPosition(mapper, x2, y2); 3512 processId(mapper, 2); 3513 processMTSync(mapper); 3514 processSync(mapper); 3515 3516 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3517 ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); 3518 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 3519 ASSERT_EQ(2, motionArgs.pointerIds[0]); 3520 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3521 toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0)); 3522 3523 // New finger down. 3524 int32_t x3 = 700, y3 = 300; 3525 processPosition(mapper, x2, y2); 3526 processId(mapper, 2); 3527 processMTSync(mapper); 3528 processPosition(mapper, x3, y3); 3529 processId(mapper, 3); 3530 processMTSync(mapper); 3531 processSync(mapper); 3532 3533 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3534 ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), 3535 motionArgs.action); 3536 ASSERT_EQ(size_t(2), motionArgs.pointerCount); 3537 ASSERT_EQ(2, motionArgs.pointerIds[0]); 3538 ASSERT_EQ(3, motionArgs.pointerIds[1]); 3539 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3540 toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0)); 3541 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], 3542 toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0)); 3543 3544 // Second finger up. 3545 x3 += 30; y3 -= 20; 3546 processPosition(mapper, x3, y3); 3547 processId(mapper, 3); 3548 processMTSync(mapper); 3549 processSync(mapper); 3550 3551 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3552 ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), 3553 motionArgs.action); 3554 ASSERT_EQ(size_t(2), motionArgs.pointerCount); 3555 ASSERT_EQ(2, motionArgs.pointerIds[0]); 3556 ASSERT_EQ(3, motionArgs.pointerIds[1]); 3557 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3558 toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0)); 3559 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], 3560 toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0)); 3561 3562 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3563 ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); 3564 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 3565 ASSERT_EQ(3, motionArgs.pointerIds[0]); 3566 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3567 toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0)); 3568 3569 // Last finger up. 3570 processMTSync(mapper); 3571 processSync(mapper); 3572 3573 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&motionArgs)); 3574 ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); 3575 ASSERT_EQ(size_t(1), motionArgs.pointerCount); 3576 ASSERT_EQ(3, motionArgs.pointerIds[0]); 3577 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 3578 toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0)); 3579 3580 // Should not have sent any more keys or motions. 3581 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyKeyWasNotCalled()); 3582 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasNotCalled()); 3583} 3584 3585TEST_F(MultiTouchInputMapperTest, Process_AllAxes_WithDefaultCalibration) { 3586 MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); 3587 addConfigurationProperty("touch.deviceType", "touchScreen"); 3588 prepareDisplay(DISPLAY_ORIENTATION_0); 3589 prepareAxes(POSITION | TOUCH | TOOL | PRESSURE | ORIENTATION | ID | MINOR); 3590 addMapperAndConfigure(mapper); 3591 3592 // These calculations are based on the input device calibration documentation. 3593 int32_t rawX = 100; 3594 int32_t rawY = 200; 3595 int32_t rawTouchMajor = 7; 3596 int32_t rawTouchMinor = 6; 3597 int32_t rawToolMajor = 9; 3598 int32_t rawToolMinor = 8; 3599 int32_t rawPressure = 11; 3600 int32_t rawOrientation = 3; 3601 int32_t id = 5; 3602 3603 float x = toDisplayX(rawX); 3604 float y = toDisplayY(rawY); 3605 float pressure = float(rawPressure) / RAW_PRESSURE_MAX; 3606 float size = avg(rawToolMajor, rawToolMinor) / RAW_TOOL_MAX; 3607 float toolMajor = float(min(DISPLAY_WIDTH, DISPLAY_HEIGHT)) * rawToolMajor / RAW_TOOL_MAX; 3608 float toolMinor = float(min(DISPLAY_WIDTH, DISPLAY_HEIGHT)) * rawToolMinor / RAW_TOOL_MAX; 3609 float touchMajor = min(toolMajor * pressure, toolMajor); 3610 float touchMinor = min(toolMinor * pressure, toolMinor); 3611 float orientation = float(rawOrientation) / RAW_ORIENTATION_MAX * M_PI_2; 3612 3613 processPosition(mapper, rawX, rawY); 3614 processTouchMajor(mapper, rawTouchMajor); 3615 processTouchMinor(mapper, rawTouchMinor); 3616 processToolMajor(mapper, rawToolMajor); 3617 processToolMinor(mapper, rawToolMinor); 3618 processPressure(mapper, rawPressure); 3619 processOrientation(mapper, rawOrientation); 3620 processId(mapper, id); 3621 processMTSync(mapper); 3622 processSync(mapper); 3623 3624 FakeInputDispatcher::NotifyMotionArgs args; 3625 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 3626 ASSERT_EQ(id, args.pointerIds[0]); 3627 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 3628 x, y, pressure, size, touchMajor, touchMinor, toolMajor, toolMinor, orientation)); 3629} 3630 3631TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_GeometricCalibration) { 3632 MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); 3633 addConfigurationProperty("touch.deviceType", "touchScreen"); 3634 prepareDisplay(DISPLAY_ORIENTATION_0); 3635 prepareAxes(POSITION | TOUCH | TOOL | MINOR); 3636 addConfigurationProperty("touch.touchSize.calibration", "geometric"); 3637 addConfigurationProperty("touch.toolSize.calibration", "geometric"); 3638 addMapperAndConfigure(mapper); 3639 3640 // These calculations are based on the input device calibration documentation. 3641 int32_t rawX = 100; 3642 int32_t rawY = 200; 3643 int32_t rawTouchMajor = 140; 3644 int32_t rawTouchMinor = 120; 3645 int32_t rawToolMajor = 180; 3646 int32_t rawToolMinor = 160; 3647 3648 float x = toDisplayX(rawX); 3649 float y = toDisplayY(rawY); 3650 float pressure = float(rawTouchMajor) / RAW_TOUCH_MAX; 3651 float size = avg(rawToolMajor, rawToolMinor) / RAW_TOOL_MAX; 3652 float scale = avg(float(DISPLAY_WIDTH) / (RAW_X_MAX - RAW_X_MIN + 1), 3653 float(DISPLAY_HEIGHT) / (RAW_Y_MAX - RAW_Y_MIN + 1)); 3654 float toolMajor = float(rawToolMajor) * scale; 3655 float toolMinor = float(rawToolMinor) * scale; 3656 float touchMajor = min(float(rawTouchMajor) * scale, toolMajor); 3657 float touchMinor = min(float(rawTouchMinor) * scale, toolMinor); 3658 3659 processPosition(mapper, rawX, rawY); 3660 processTouchMajor(mapper, rawTouchMajor); 3661 processTouchMinor(mapper, rawTouchMinor); 3662 processToolMajor(mapper, rawToolMajor); 3663 processToolMinor(mapper, rawToolMinor); 3664 processMTSync(mapper); 3665 processSync(mapper); 3666 3667 FakeInputDispatcher::NotifyMotionArgs args; 3668 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 3669 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 3670 x, y, pressure, size, touchMajor, touchMinor, toolMajor, toolMinor, 0)); 3671} 3672 3673TEST_F(MultiTouchInputMapperTest, Process_TouchToolPressureSizeAxes_SummedLinearCalibration) { 3674 MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); 3675 addConfigurationProperty("touch.deviceType", "touchScreen"); 3676 prepareDisplay(DISPLAY_ORIENTATION_0); 3677 prepareAxes(POSITION | TOUCH | TOOL); 3678 addConfigurationProperty("touch.touchSize.calibration", "pressure"); 3679 addConfigurationProperty("touch.toolSize.calibration", "linear"); 3680 addConfigurationProperty("touch.toolSize.linearScale", "10"); 3681 addConfigurationProperty("touch.toolSize.linearBias", "160"); 3682 addConfigurationProperty("touch.toolSize.isSummed", "1"); 3683 addConfigurationProperty("touch.pressure.calibration", "amplitude"); 3684 addConfigurationProperty("touch.pressure.source", "touch"); 3685 addConfigurationProperty("touch.pressure.scale", "0.01"); 3686 addMapperAndConfigure(mapper); 3687 3688 // These calculations are based on the input device calibration documentation. 3689 // Note: We only provide a single common touch/tool value because the device is assumed 3690 // not to emit separate values for each pointer (isSummed = 1). 3691 int32_t rawX = 100; 3692 int32_t rawY = 200; 3693 int32_t rawX2 = 150; 3694 int32_t rawY2 = 250; 3695 int32_t rawTouchMajor = 60; 3696 int32_t rawToolMajor = 5; 3697 3698 float x = toDisplayX(rawX); 3699 float y = toDisplayY(rawY); 3700 float x2 = toDisplayX(rawX2); 3701 float y2 = toDisplayY(rawY2); 3702 float pressure = float(rawTouchMajor) * 0.01f; 3703 float size = float(rawToolMajor) / RAW_TOOL_MAX; 3704 float tool = (float(rawToolMajor) * 10.0f + 160.0f) / 2; 3705 float touch = min(tool * pressure, tool); 3706 3707 processPosition(mapper, rawX, rawY); 3708 processTouchMajor(mapper, rawTouchMajor); 3709 processToolMajor(mapper, rawToolMajor); 3710 processMTSync(mapper); 3711 processPosition(mapper, rawX2, rawY2); 3712 processTouchMajor(mapper, rawTouchMajor); 3713 processToolMajor(mapper, rawToolMajor); 3714 processMTSync(mapper); 3715 processSync(mapper); 3716 3717 FakeInputDispatcher::NotifyMotionArgs args; 3718 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 3719 ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action); 3720 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 3721 ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), 3722 args.action); 3723 ASSERT_EQ(size_t(2), args.pointerCount); 3724 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 3725 x, y, pressure, size, touch, touch, tool, tool, 0)); 3726 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[1], 3727 x2, y2, pressure, size, touch, touch, tool, tool, 0)); 3728} 3729 3730TEST_F(MultiTouchInputMapperTest, Process_TouchToolPressureSizeAxes_AreaCalibration) { 3731 MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); 3732 addConfigurationProperty("touch.deviceType", "touchScreen"); 3733 prepareDisplay(DISPLAY_ORIENTATION_0); 3734 prepareAxes(POSITION | TOUCH | TOOL); 3735 addConfigurationProperty("touch.touchSize.calibration", "pressure"); 3736 addConfigurationProperty("touch.toolSize.calibration", "area"); 3737 addConfigurationProperty("touch.toolSize.areaScale", "22"); 3738 addConfigurationProperty("touch.toolSize.areaBias", "1"); 3739 addConfigurationProperty("touch.toolSize.linearScale", "9.2"); 3740 addConfigurationProperty("touch.toolSize.linearBias", "3"); 3741 addConfigurationProperty("touch.pressure.calibration", "amplitude"); 3742 addConfigurationProperty("touch.pressure.source", "touch"); 3743 addConfigurationProperty("touch.pressure.scale", "0.01"); 3744 addMapperAndConfigure(mapper); 3745 3746 // These calculations are based on the input device calibration documentation. 3747 int32_t rawX = 100; 3748 int32_t rawY = 200; 3749 int32_t rawTouchMajor = 60; 3750 int32_t rawToolMajor = 5; 3751 3752 float x = toDisplayX(rawX); 3753 float y = toDisplayY(rawY); 3754 float pressure = float(rawTouchMajor) * 0.01f; 3755 float size = float(rawToolMajor) / RAW_TOOL_MAX; 3756 float tool = sqrtf(float(rawToolMajor) * 22.0f + 1.0f) * 9.2f + 3.0f; 3757 float touch = min(tool * pressure, tool); 3758 3759 processPosition(mapper, rawX, rawY); 3760 processTouchMajor(mapper, rawTouchMajor); 3761 processToolMajor(mapper, rawToolMajor); 3762 processMTSync(mapper); 3763 processSync(mapper); 3764 3765 FakeInputDispatcher::NotifyMotionArgs args; 3766 ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); 3767 ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 3768 x, y, pressure, size, touch, touch, tool, tool, 0)); 3769} 3770 3771} // namespace android 3772