diff options
author | 2019-08-29 14:12:42 -0700 | |
---|---|---|
committer | 2019-09-19 17:02:10 -0700 | |
commit | da7c00cc01694df1874c4c71ece4aa0364e4d778 (patch) | |
tree | c3c4de403a999d6351c5f9415e42e99d0ca6bd69 | |
parent | 323d89081945901f6aeba4845a8e1f376ee4ab47 (diff) |
Create inputreader directory
In order to start the work to split InputReader.cpp into multiple files,
we first create a reader directory to hold the source files for
libinputreader.
The affected files are also reformatted with clang-format.
Bug: 140139676
Test: libinputflinger and libinputflinger_tests builds successfully for
crosshatch
Change-Id: I62b6b873e2a03e61655eb6214183c984306dcfdb
-rw-r--r-- | services/inputflinger/Android.bp | 32 | ||||
-rw-r--r-- | services/inputflinger/InputManager.h | 2 | ||||
-rw-r--r-- | services/inputflinger/reader/Android.bp | 51 | ||||
-rw-r--r-- | services/inputflinger/reader/EventHub.cpp (renamed from services/inputflinger/EventHub.cpp) | 456 | ||||
-rw-r--r-- | services/inputflinger/reader/InputReader.cpp (renamed from services/inputflinger/InputReader.cpp) | 3136 | ||||
-rw-r--r-- | services/inputflinger/reader/InputReaderFactory.cpp (renamed from services/inputflinger/InputReaderFactory.cpp) | 5 | ||||
-rw-r--r-- | services/inputflinger/reader/TouchVideoDevice.cpp (renamed from services/inputflinger/TouchVideoDevice.cpp) | 50 | ||||
-rw-r--r-- | services/inputflinger/reader/include/EventHub.h (renamed from services/inputflinger/EventHub.h) | 105 | ||||
-rw-r--r-- | services/inputflinger/reader/include/InputReader.h (renamed from services/inputflinger/InputReader.h) | 191 | ||||
-rw-r--r-- | services/inputflinger/reader/include/TouchVideoDevice.h (renamed from services/inputflinger/TouchVideoDevice.h) | 10 | ||||
-rw-r--r-- | services/inputflinger/tests/Android.bp | 3 | ||||
-rw-r--r-- | services/inputflinger/tests/InputReader_test.cpp | 2 |
12 files changed, 1954 insertions, 2089 deletions
diff --git a/services/inputflinger/Android.bp b/services/inputflinger/Android.bp index 32dab17420..11578c393e 100644 --- a/services/inputflinger/Android.bp +++ b/services/inputflinger/Android.bp @@ -76,38 +76,6 @@ cc_library_headers { } cc_library_shared { - name: "libinputreader", - defaults: ["inputflinger_defaults"], - - srcs: [ - "EventHub.cpp", - "InputReader.cpp", - "InputReaderFactory.cpp", - "TouchVideoDevice.cpp", - ], - - shared_libs: [ - "libbase", - "libinputflinger_base", - "libcrypto", - "libcutils", - "libinput", - "liblog", - "libui", - "libutils", - "libhardware_legacy", - ], - - header_libs: [ - "libinputflinger_headers", - ], - - export_header_lib_headers: [ - "libinputflinger_headers", - ], -} - -cc_library_shared { name: "libinputflinger_base", defaults: ["inputflinger_defaults"], diff --git a/services/inputflinger/InputManager.h b/services/inputflinger/InputManager.h index ba0b28786b..f3da324ba4 100644 --- a/services/inputflinger/InputManager.h +++ b/services/inputflinger/InputManager.h @@ -21,9 +21,7 @@ * Native input manager. */ -#include "EventHub.h" #include "InputClassifier.h" -#include "InputReader.h" #include "InputReaderBase.h" #include <InputDispatcherInterface.h> diff --git a/services/inputflinger/reader/Android.bp b/services/inputflinger/reader/Android.bp new file mode 100644 index 0000000000..c3e8ceda56 --- /dev/null +++ b/services/inputflinger/reader/Android.bp @@ -0,0 +1,51 @@ +// Copyright (C) 2019 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +cc_library_headers { + name: "libinputreader_headers", + export_include_dirs: ["include"], +} + +cc_library_shared { + name: "libinputreader", + defaults: ["inputflinger_defaults"], + + srcs: [ + "EventHub.cpp", + "InputReader.cpp", + "InputReaderFactory.cpp", + "TouchVideoDevice.cpp", + ], + + shared_libs: [ + "libbase", + "libinputflinger_base", + "libcrypto", + "libcutils", + "libinput", + "liblog", + "libui", + "libutils", + "libhardware_legacy", + ], + + header_libs: [ + "libinputflinger_headers", + "libinputreader_headers", + ], + + export_header_lib_headers: [ + "libinputflinger_headers", + ], +} diff --git a/services/inputflinger/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp index af023148cc..c15ecfd66b 100644 --- a/services/inputflinger/EventHub.cpp +++ b/services/inputflinger/reader/EventHub.cpp @@ -25,9 +25,9 @@ #include <stdlib.h> #include <string.h> #include <sys/epoll.h> -#include <sys/limits.h> #include <sys/inotify.h> #include <sys/ioctl.h> +#include <sys/limits.h> #include <unistd.h> #define LOG_TAG "EventHub" @@ -41,13 +41,13 @@ #include <android-base/stringprintf.h> #include <cutils/properties.h> #include <openssl/sha.h> +#include <utils/Errors.h> #include <utils/Log.h> #include <utils/Timers.h> #include <utils/threads.h> -#include <utils/Errors.h> -#include <input/KeyLayoutMap.h> #include <input/KeyCharacterMap.h> +#include <input/KeyLayoutMap.h> #include <input/VirtualKeyMap.h> /* this macro is used to tell if "bit" is set in "array" @@ -55,10 +55,10 @@ * operation with a byte that only has the relevant bit set. * eg. to check for the 12th bit, we do (array[1] & 1<<4) */ -#define test_bit(bit, array) ((array)[(bit)/8] & (1<<((bit)%8))) +#define test_bit(bit, array) ((array)[(bit) / 8] & (1 << ((bit) % 8))) /* this macro computes the number of bytes needed to represent a bit array of the specified size */ -#define sizeof_bit_array(bits) (((bits) + 7) / 8) +#define sizeof_bit_array(bits) (((bits) + 7) / 8) #define INDENT " " #define INDENT2 " " @@ -70,10 +70,10 @@ namespace android { static constexpr bool DEBUG = false; -static const char *WAKE_LOCK_ID = "KeyEvents"; -static const char *DEVICE_PATH = "/dev/input"; +static const char* WAKE_LOCK_ID = "KeyEvents"; +static const char* DEVICE_PATH = "/dev/input"; // v4l2 devices go directly into /dev -static const char *VIDEO_DEVICE_PATH = "/dev"; +static const char* VIDEO_DEVICE_PATH = "/dev"; static inline const char* toString(bool value) { return value ? "true" : "false"; @@ -117,7 +117,7 @@ static bool isV4lTouchNode(const char* name) { * directly from /dev. */ static bool isV4lScanningEnabled() { - return property_get_bool("ro.input.video_enabled", true /* default_value */); + return property_get_bool("ro.input.video_enabled", true /* default_value */); } static nsecs_t processEventTimestamp(const struct input_event& event) { @@ -144,27 +144,27 @@ uint32_t getAbsAxisUsage(int32_t axis, uint32_t deviceClasses) { // Touch devices get dibs on touch-related axes. if (deviceClasses & INPUT_DEVICE_CLASS_TOUCH) { switch (axis) { - case ABS_X: - case ABS_Y: - case ABS_PRESSURE: - case ABS_TOOL_WIDTH: - case ABS_DISTANCE: - case ABS_TILT_X: - case ABS_TILT_Y: - case ABS_MT_SLOT: - case ABS_MT_TOUCH_MAJOR: - case ABS_MT_TOUCH_MINOR: - case ABS_MT_WIDTH_MAJOR: - case ABS_MT_WIDTH_MINOR: - case ABS_MT_ORIENTATION: - case ABS_MT_POSITION_X: - case ABS_MT_POSITION_Y: - case ABS_MT_TOOL_TYPE: - case ABS_MT_BLOB_ID: - case ABS_MT_TRACKING_ID: - case ABS_MT_PRESSURE: - case ABS_MT_DISTANCE: - return INPUT_DEVICE_CLASS_TOUCH; + case ABS_X: + case ABS_Y: + case ABS_PRESSURE: + case ABS_TOOL_WIDTH: + case ABS_DISTANCE: + case ABS_TILT_X: + case ABS_TILT_Y: + case ABS_MT_SLOT: + case ABS_MT_TOUCH_MAJOR: + case ABS_MT_TOUCH_MINOR: + case ABS_MT_WIDTH_MAJOR: + case ABS_MT_WIDTH_MINOR: + case ABS_MT_ORIENTATION: + case ABS_MT_POSITION_X: + case ABS_MT_POSITION_Y: + case ABS_MT_TOOL_TYPE: + case ABS_MT_BLOB_ID: + case ABS_MT_TRACKING_ID: + case ABS_MT_PRESSURE: + case ABS_MT_DISTANCE: + return INPUT_DEVICE_CLASS_TOUCH; } } @@ -182,12 +182,20 @@ uint32_t getAbsAxisUsage(int32_t axis, uint32_t deviceClasses) { // --- EventHub::Device --- EventHub::Device::Device(int fd, int32_t id, const std::string& path, - const InputDeviceIdentifier& identifier) : - next(nullptr), - fd(fd), id(id), path(path), identifier(identifier), - classes(0), configuration(nullptr), virtualKeyMap(nullptr), - ffEffectPlaying(false), ffEffectId(-1), controllerNumber(0), - enabled(true), isVirtual(fd < 0) { + const InputDeviceIdentifier& identifier) + : next(nullptr), + fd(fd), + id(id), + path(path), + identifier(identifier), + classes(0), + configuration(nullptr), + virtualKeyMap(nullptr), + ffEffectPlaying(false), + ffEffectId(-1), + controllerNumber(0), + enabled(true), + isVirtual(fd < 0) { memset(keyBitmask, 0, sizeof(keyBitmask)); memset(absBitmask, 0, sizeof(absBitmask)); memset(relBitmask, 0, sizeof(relBitmask)); @@ -211,7 +219,7 @@ void EventHub::Device::close() { status_t EventHub::Device::enable() { fd = open(path.c_str(), O_RDWR | O_CLOEXEC | O_NONBLOCK); - if(fd < 0) { + if (fd < 0) { ALOGE("could not open %s, %s\n", path.c_str(), strerror(errno)); return -errno; } @@ -233,12 +241,18 @@ bool EventHub::Device::hasValidFd() { const int EventHub::EPOLL_MAX_EVENTS; -EventHub::EventHub(void) : - mBuiltInKeyboardId(NO_BUILT_IN_KEYBOARD), mNextDeviceId(1), mControllerNumbers(), - mOpeningDevices(nullptr), mClosingDevices(nullptr), +EventHub::EventHub(void) + : mBuiltInKeyboardId(NO_BUILT_IN_KEYBOARD), + mNextDeviceId(1), + mControllerNumbers(), + mOpeningDevices(nullptr), + mClosingDevices(nullptr), mNeedToSendFinishedDeviceScan(false), - mNeedToReopenDevices(false), mNeedToScanDevices(true), - mPendingEventCount(0), mPendingEventIndex(0), mPendingINotify(false) { + mNeedToReopenDevices(false), + mNeedToScanDevices(true), + mPendingEventCount(0), + mPendingEventIndex(0), + mPendingINotify(false) { acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID); mEpollFd = epoll_create1(EPOLL_CLOEXEC); @@ -246,12 +260,12 @@ EventHub::EventHub(void) : mINotifyFd = inotify_init(); mInputWd = inotify_add_watch(mINotifyFd, DEVICE_PATH, IN_DELETE | IN_CREATE); - LOG_ALWAYS_FATAL_IF(mInputWd < 0, "Could not register INotify for %s: %s", - DEVICE_PATH, strerror(errno)); + LOG_ALWAYS_FATAL_IF(mInputWd < 0, "Could not register INotify for %s: %s", DEVICE_PATH, + strerror(errno)); if (isV4lScanningEnabled()) { mVideoWd = inotify_add_watch(mINotifyFd, VIDEO_DEVICE_PATH, IN_DELETE | IN_CREATE); LOG_ALWAYS_FATAL_IF(mVideoWd < 0, "Could not register INotify for %s: %s", - VIDEO_DEVICE_PATH, strerror(errno)); + VIDEO_DEVICE_PATH, strerror(errno)); } else { mVideoWd = -1; ALOGI("Video device scanning disabled"); @@ -273,16 +287,16 @@ EventHub::EventHub(void) : result = fcntl(mWakeReadPipeFd, F_SETFL, O_NONBLOCK); LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake read pipe non-blocking. errno=%d", - errno); + errno); result = fcntl(mWakeWritePipeFd, F_SETFL, O_NONBLOCK); LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake write pipe non-blocking. errno=%d", - errno); + errno); eventItem.data.fd = mWakeReadPipeFd; result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mWakeReadPipeFd, &eventItem); LOG_ALWAYS_FATAL_IF(result != 0, "Could not add wake read pipe to epoll instance. errno=%d", - errno); + errno); } EventHub::~EventHub(void) { @@ -334,7 +348,7 @@ void EventHub::getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) } status_t EventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis, - RawAbsoluteAxisInfo* outAxisInfo) const { + RawAbsoluteAxisInfo* outAxisInfo) const { outAxisInfo->clear(); if (axis >= 0 && axis <= ABS_MAX) { @@ -343,9 +357,9 @@ status_t EventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis, Device* device = getDeviceLocked(deviceId); if (device && device->hasValidFd() && test_bit(axis, device->absBitmask)) { struct input_absinfo info; - if(ioctl(device->fd, EVIOCGABS(axis), &info)) { - ALOGW("Error reading absolute controller %d for device %s fd %d, errno=%d", - axis, device->identifier.name.c_str(), device->fd, errno); + if (ioctl(device->fd, EVIOCGABS(axis), &info)) { + ALOGW("Error reading absolute controller %d for device %s fd %d, errno=%d", axis, + device->identifier.name.c_str(), device->fd, errno); return -errno; } @@ -452,9 +466,9 @@ status_t EventHub::getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* Device* device = getDeviceLocked(deviceId); if (device && device->hasValidFd() && test_bit(axis, device->absBitmask)) { struct input_absinfo info; - if(ioctl(device->fd, EVIOCGABS(axis), &info)) { - ALOGW("Error reading absolute controller %d for device %s fd %d, errno=%d", - axis, device->identifier.name.c_str(), device->fd, errno); + if (ioctl(device->fd, EVIOCGABS(axis), &info)) { + ALOGW("Error reading absolute controller %d for device %s fd %d, errno=%d", axis, + device->identifier.name.c_str(), device->fd, errno); return -errno; } @@ -465,8 +479,8 @@ status_t EventHub::getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* return -1; } -bool EventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes, - const int32_t* keyCodes, uint8_t* outFlags) const { +bool EventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes, + uint8_t* outFlags) const { AutoMutex _l(mLock); Device* device = getDeviceLocked(deviceId); @@ -475,9 +489,9 @@ bool EventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes, for (size_t codeIndex = 0; codeIndex < numCodes; codeIndex++) { scanCodes.clear(); - status_t err = device->keyMap.keyLayoutMap->findScanCodesForKey( - keyCodes[codeIndex], &scanCodes); - if (! err) { + status_t err = device->keyMap.keyLayoutMap->findScanCodesForKey(keyCodes[codeIndex], + &scanCodes); + if (!err) { // check the possible scan codes identified by the layout map against the // map of codes actually emitted by the driver for (size_t sc = 0; sc < scanCodes.size(); sc++) { @@ -493,9 +507,8 @@ bool EventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes, return false; } -status_t EventHub::mapKey(int32_t deviceId, - int32_t scanCode, int32_t usageCode, int32_t metaState, - int32_t* outKeycode, int32_t* outMetaState, uint32_t* outFlags) const { +status_t EventHub::mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, int32_t metaState, + int32_t* outKeycode, int32_t* outMetaState, uint32_t* outFlags) const { AutoMutex _l(mLock); Device* device = getDeviceLocked(deviceId); status_t status = NAME_NOT_FOUND; @@ -602,7 +615,7 @@ void EventHub::setLedStateLocked(Device* device, int32_t led, bool on) { } void EventHub::getVirtualKeyDefinitions(int32_t deviceId, - std::vector<VirtualKeyDefinition>& outVirtualKeys) const { + std::vector<VirtualKeyDefinition>& outVirtualKeys) const { outVirtualKeys.clear(); AutoMutex _l(mLock); @@ -623,15 +636,13 @@ sp<KeyCharacterMap> EventHub::getKeyCharacterMap(int32_t deviceId) const { return nullptr; } -bool EventHub::setKeyboardLayoutOverlay(int32_t deviceId, - const sp<KeyCharacterMap>& map) { +bool EventHub::setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) { AutoMutex _l(mLock); Device* device = getDeviceLocked(deviceId); if (device) { if (map != device->overlayKeyMap) { device->overlayKeyMap = map; - device->combinedKeyMap = KeyCharacterMap::combine( - device->keyMap.keyCharacterMap, map); + device->combinedKeyMap = KeyCharacterMap::combine(device->keyMap.keyCharacterMap, map); return true; } } @@ -640,8 +651,7 @@ bool EventHub::setKeyboardLayoutOverlay(int32_t deviceId, static std::string generateDescriptor(InputDeviceIdentifier& identifier) { std::string rawDescriptor; - rawDescriptor += StringPrintf(":%04x:%04x:", identifier.vendor, - identifier.product); + rawDescriptor += StringPrintf(":%04x:%04x:", identifier.vendor, identifier.product); // TODO add handling for USB devices to not uniqueify kbs that show up twice if (!identifier.uniqueId.empty()) { rawDescriptor += "uniqueId:"; @@ -680,13 +690,13 @@ void EventHub::assignDescriptorLocked(InputDeviceIdentifier& identifier) { if (identifier.uniqueId.empty()) { // If it didn't have a unique id check for conflicts and enforce // uniqueness if necessary. - while(getDeviceByDescriptorLocked(identifier.descriptor) != nullptr) { + while (getDeviceByDescriptorLocked(identifier.descriptor) != nullptr) { identifier.nonce++; rawDescriptor = generateDescriptor(identifier); } } ALOGV("Created descriptor: raw=%s, cooked=%s", rawDescriptor.c_str(), - identifier.descriptor.c_str()); + identifier.descriptor.c_str()); } void EventHub::vibrate(int32_t deviceId, nsecs_t duration) { @@ -703,7 +713,7 @@ void EventHub::vibrate(int32_t deviceId, nsecs_t duration) { effect.replay.delay = 0; if (ioctl(device->fd, EVIOCSFF, &effect)) { ALOGW("Could not upload force feedback effect to device %s due to error %d.", - device->identifier.name.c_str(), errno); + device->identifier.name.c_str(), errno); return; } device->ffEffectId = effect.id; @@ -716,7 +726,7 @@ void EventHub::vibrate(int32_t deviceId, nsecs_t duration) { ev.value = 1; if (write(device->fd, &ev, sizeof(ev)) != sizeof(ev)) { ALOGW("Could not start force feedback effect on device %s due to error %d.", - device->identifier.name.c_str(), errno); + device->identifier.name.c_str(), errno); return; } device->ffEffectPlaying = true; @@ -738,7 +748,7 @@ void EventHub::cancelVibrate(int32_t deviceId) { ev.value = 0; if (write(device->fd, &ev, sizeof(ev)) != sizeof(ev)) { ALOGW("Could not stop force feedback effect on device %s due to error %d.", - device->identifier.name.c_str(), errno); + device->identifier.name.c_str(), errno); return; } } @@ -825,12 +835,12 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz // Report any devices that had last been added/removed. while (mClosingDevices) { Device* device = mClosingDevices; - ALOGV("Reporting device closed: id=%d, name=%s\n", - device->id, device->path.c_str()); + ALOGV("Reporting device closed: id=%d, name=%s\n", device->id, device->path.c_str()); mClosingDevices = device->next; event->when = now; - event->deviceId = (device->id == mBuiltInKeyboardId) ? - ReservedInputDeviceId::BUILT_IN_KEYBOARD_ID : device->id; + event->deviceId = (device->id == mBuiltInKeyboardId) + ? ReservedInputDeviceId::BUILT_IN_KEYBOARD_ID + : device->id; event->type = DEVICE_REMOVED; event += 1; delete device; @@ -848,8 +858,7 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz while (mOpeningDevices != nullptr) { Device* device = mOpeningDevices; - ALOGV("Reporting device opened: id=%d, name=%s\n", - device->id, device->path.c_str()); + ALOGV("Reporting device opened: id=%d, name=%s\n", device->id, device->path.c_str()); mOpeningDevices = device->next; event->when = now; event->deviceId = device->id == mBuiltInKeyboardId ? 0 : device->id; @@ -895,15 +904,15 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz } while ((nRead == -1 && errno == EINTR) || nRead == sizeof(buffer)); } else { ALOGW("Received unexpected epoll event 0x%08x for wake read pipe.", - eventItem.events); + eventItem.events); } continue; } Device* device = getDeviceByFdLocked(eventItem.data.fd); if (!device) { - ALOGE("Received unexpected epoll event 0x%08x for unknown fd %d.", - eventItem.events, eventItem.data.fd); + ALOGE("Received unexpected epoll event 0x%08x for unknown fd %d.", eventItem.events, + eventItem.data.fd); ALOG_ASSERT(!DEBUG); continue; } @@ -912,30 +921,30 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz size_t numFrames = device->videoDevice->readAndQueueFrames(); if (numFrames == 0) { ALOGE("Received epoll event for video device %s, but could not read frame", - device->videoDevice->getName().c_str()); + device->videoDevice->getName().c_str()); } } else if (eventItem.events & EPOLLHUP) { // TODO(b/121395353) - consider adding EPOLLRDHUP ALOGI("Removing video device %s due to epoll hang-up event.", - device->videoDevice->getName().c_str()); + device->videoDevice->getName().c_str()); unregisterVideoDeviceFromEpollLocked(*device->videoDevice); device->videoDevice = nullptr; } else { - ALOGW("Received unexpected epoll event 0x%08x for device %s.", - eventItem.events, device->videoDevice->getName().c_str()); + ALOGW("Received unexpected epoll event 0x%08x for device %s.", eventItem.events, + device->videoDevice->getName().c_str()); ALOG_ASSERT(!DEBUG); } continue; } // This must be an input event if (eventItem.events & EPOLLIN) { - int32_t readSize = read(device->fd, readBuffer, - sizeof(struct input_event) * capacity); + int32_t readSize = + read(device->fd, readBuffer, sizeof(struct input_event) * capacity); if (readSize == 0 || (readSize < 0 && errno == ENODEV)) { // Device was removed before INotify noticed. ALOGW("could not get event, removed? (fd: %d size: %" PRId32 - " bufferSize: %zu capacity: %zu errno: %d)\n", - device->fd, readSize, bufferSize, capacity, errno); + " bufferSize: %zu capacity: %zu errno: %d)\n", + device->fd, readSize, bufferSize, capacity, errno); deviceChanged = true; closeDeviceLocked(device); } else if (readSize < 0) { @@ -967,12 +976,12 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz } } else if (eventItem.events & EPOLLHUP) { ALOGI("Removing device %s due to epoll hang-up event.", - device->identifier.name.c_str()); + device->identifier.name.c_str()); deviceChanged = true; closeDeviceLocked(device); } else { - ALOGW("Received unexpected epoll event 0x%08x for device %s.", - eventItem.events, device->identifier.name.c_str()); + ALOGW("Received unexpected epoll event 0x%08x for device %s.", eventItem.events, + device->identifier.name.c_str()); } } @@ -1067,7 +1076,7 @@ void EventHub::wake() { void EventHub::scanDevicesLocked() { status_t result = scanDirLocked(DEVICE_PATH); - if(result < 0) { + if (result < 0) { ALOGE("scan dir failed for %s", DEVICE_PATH); } if (isV4lScanningEnabled()) { @@ -1095,12 +1104,12 @@ static bool containsNonZeroByte(const uint8_t* array, uint32_t startIndex, uint3 } static const int32_t GAMEPAD_KEYCODES[] = { - AKEYCODE_BUTTON_A, AKEYCODE_BUTTON_B, AKEYCODE_BUTTON_C, - AKEYCODE_BUTTON_X, AKEYCODE_BUTTON_Y, AKEYCODE_BUTTON_Z, - AKEYCODE_BUTTON_L1, AKEYCODE_BUTTON_R1, - AKEYCODE_BUTTON_L2, AKEYCODE_BUTTON_R2, - AKEYCODE_BUTTON_THUMBL, AKEYCODE_BUTTON_THUMBR, - AKEYCODE_BUTTON_START, AKEYCODE_BUTTON_SELECT, AKEYCODE_BUTTON_MODE, + AKEYCODE_BUTTON_A, AKEYCODE_BUTTON_B, AKEYCODE_BUTTON_C, // + AKEYCODE_BUTTON_X, AKEYCODE_BUTTON_Y, AKEYCODE_BUTTON_Z, // + AKEYCODE_BUTTON_L1, AKEYCODE_BUTTON_R1, // + AKEYCODE_BUTTON_L2, AKEYCODE_BUTTON_R2, // + AKEYCODE_BUTTON_THUMBL, AKEYCODE_BUTTON_THUMBR, // + AKEYCODE_BUTTON_START, AKEYCODE_BUTTON_SELECT, AKEYCODE_BUTTON_MODE, // }; status_t EventHub::registerFdForEpoll(int fd) { @@ -1167,7 +1176,7 @@ void EventHub::unregisterVideoDeviceFromEpollLocked(const TouchVideoDevice& vide status_t result = unregisterFdFromEpoll(videoDevice.getFd()); if (result != OK) { ALOGW("Could not remove video device fd from epoll for device: %s", - videoDevice.getName().c_str()); + videoDevice.getName().c_str()); } } } @@ -1178,7 +1187,7 @@ status_t EventHub::openDeviceLocked(const char* devicePath) { ALOGV("Opening device: %s", devicePath); int fd = open(devicePath, O_RDWR | O_CLOEXEC | O_NONBLOCK); - if(fd < 0) { + if (fd < 0) { ALOGE("could not open %s, %s\n", devicePath, strerror(errno)); return -1; } @@ -1186,7 +1195,7 @@ status_t EventHub::openDeviceLocked(const char* devicePath) { InputDeviceIdentifier identifier; // Get device name. - if(ioctl(fd, EVIOCGNAME(sizeof(buffer) - 1), &buffer) < 1) { + if (ioctl(fd, EVIOCGNAME(sizeof(buffer) - 1), &buffer) < 1) { ALOGE("Could not get device name for %s: %s", devicePath, strerror(errno)); } else { buffer[sizeof(buffer) - 1] = '\0'; @@ -1205,7 +1214,7 @@ status_t EventHub::openDeviceLocked(const char* devicePath) { // Get device driver version. int driverVersion; - if(ioctl(fd, EVIOCGVERSION, &driverVersion)) { + if (ioctl(fd, EVIOCGVERSION, &driverVersion)) { ALOGE("could not get driver version for %s, %s\n", devicePath, strerror(errno)); close(fd); return -1; @@ -1213,7 +1222,7 @@ status_t EventHub::openDeviceLocked(const char* devicePath) { // Get device identifier. struct input_id inputId; - if(ioctl(fd, EVIOCGID, &inputId)) { + if (ioctl(fd, EVIOCGID, &inputId)) { ALOGE("could not get device input id for %s, %s\n", devicePath, strerror(errno)); close(fd); return -1; @@ -1224,16 +1233,16 @@ status_t EventHub::openDeviceLocked(const char* devicePath) { identifier.version = inputId.version; // Get device physical location. - if(ioctl(fd, EVIOCGPHYS(sizeof(buffer) - 1), &buffer) < 1) { - //fprintf(stderr, "could not get location for %s, %s\n", devicePath, strerror(errno)); + if (ioctl(fd, EVIOCGPHYS(sizeof(buffer) - 1), &buffer) < 1) { + // fprintf(stderr, "could not get location for %s, %s\n", devicePath, strerror(errno)); } else { buffer[sizeof(buffer) - 1] = '\0'; identifier.location = buffer; } // Get device unique id. - if(ioctl(fd, EVIOCGUNIQ(sizeof(buffer) - 1), &buffer) < 1) { - //fprintf(stderr, "could not get idstring for %s, %s\n", devicePath, strerror(errno)); + if (ioctl(fd, EVIOCGUNIQ(sizeof(buffer) - 1), &buffer) < 1) { + // fprintf(stderr, "could not get idstring for %s, %s\n", devicePath, strerror(errno)); } else { buffer[sizeof(buffer) - 1] = '\0'; identifier.uniqueId = buffer; @@ -1248,16 +1257,16 @@ status_t EventHub::openDeviceLocked(const char* devicePath) { ALOGV("add device %d: %s\n", deviceId, devicePath); ALOGV(" bus: %04x\n" - " vendor %04x\n" - " product %04x\n" - " version %04x\n", - identifier.bus, identifier.vendor, identifier.product, identifier.version); + " vendor %04x\n" + " product %04x\n" + " version %04x\n", + identifier.bus, identifier.vendor, identifier.product, identifier.version); ALOGV(" name: \"%s\"\n", identifier.name.c_str()); ALOGV(" location: \"%s\"\n", identifier.location.c_str()); ALOGV(" unique id: \"%s\"\n", identifier.uniqueId.c_str()); ALOGV(" descriptor: \"%s\"\n", identifier.descriptor.c_str()); - ALOGV(" driver: v%d.%d.%d\n", - driverVersion >> 16, (driverVersion >> 8) & 0xff, driverVersion & 0xff); + ALOGV(" driver: v%d.%d.%d\n", driverVersion >> 16, (driverVersion >> 8) & 0xff, + driverVersion & 0xff); // Load the configuration file for the device. loadConfigurationLocked(device); @@ -1273,21 +1282,21 @@ status_t EventHub::openDeviceLocked(const char* devicePath) { // See if this is a keyboard. Ignore everything in the button range except for // joystick and gamepad buttons which are handled like keyboards for the most part. - bool haveKeyboardKeys = containsNonZeroByte(device->keyBitmask, 0, sizeof_bit_array(BTN_MISC)) - || containsNonZeroByte(device->keyBitmask, sizeof_bit_array(KEY_OK), - sizeof_bit_array(KEY_MAX + 1)); + bool haveKeyboardKeys = + containsNonZeroByte(device->keyBitmask, 0, sizeof_bit_array(BTN_MISC)) || + containsNonZeroByte(device->keyBitmask, sizeof_bit_array(KEY_OK), + sizeof_bit_array(KEY_MAX + 1)); bool haveGamepadButtons = containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_MISC), - sizeof_bit_array(BTN_MOUSE)) - || containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_JOYSTICK), - sizeof_bit_array(BTN_DIGI)); + sizeof_bit_array(BTN_MOUSE)) || + containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_JOYSTICK), + sizeof_bit_array(BTN_DIGI)); if (haveKeyboardKeys || haveGamepadButtons) { device->classes |= INPUT_DEVICE_CLASS_KEYBOARD; } // See if this is a cursor device such as a trackball or mouse. - if (test_bit(BTN_MOUSE, device->keyBitmask) - && test_bit(REL_X, device->relBitmask) - && test_bit(REL_Y, device->relBitmask)) { + if (test_bit(BTN_MOUSE, device->keyBitmask) && test_bit(REL_X, device->relBitmask) && + test_bit(REL_Y, device->relBitmask)) { device->classes |= INPUT_DEVICE_CLASS_CURSOR; } @@ -1295,31 +1304,29 @@ status_t EventHub::openDeviceLocked(const char* devicePath) { String8 deviceType = String8(); if (device->configuration && device->configuration->tryGetProperty(String8("device.type"), deviceType)) { - if (!deviceType.compare(String8("rotaryEncoder"))) { - device->classes |= INPUT_DEVICE_CLASS_ROTARY_ENCODER; - } + if (!deviceType.compare(String8("rotaryEncoder"))) { + device->classes |= INPUT_DEVICE_CLASS_ROTARY_ENCODER; + } } // See if this is a touch pad. // Is this a new modern multi-touch driver? - if (test_bit(ABS_MT_POSITION_X, device->absBitmask) - && test_bit(ABS_MT_POSITION_Y, device->absBitmask)) { + if (test_bit(ABS_MT_POSITION_X, device->absBitmask) && + test_bit(ABS_MT_POSITION_Y, device->absBitmask)) { // Some joysticks such as the PS3 controller report axes that conflict // with the ABS_MT range. Try to confirm that the device really is // a touch screen. if (test_bit(BTN_TOUCH, device->keyBitmask) || !haveGamepadButtons) { device->classes |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT; } - // Is this an old style single-touch driver? - } else if (test_bit(BTN_TOUCH, device->keyBitmask) - && test_bit(ABS_X, device->absBitmask) - && test_bit(ABS_Y, device->absBitmask)) { + // Is this an old style single-touch driver? + } else if (test_bit(BTN_TOUCH, device->keyBitmask) && test_bit(ABS_X, device->absBitmask) && + test_bit(ABS_Y, device->absBitmask)) { device->classes |= INPUT_DEVICE_CLASS_TOUCH; - // Is this a BT stylus? + // Is this a BT stylus? } else if ((test_bit(ABS_PRESSURE, device->absBitmask) || - test_bit(BTN_TOUCH, device->keyBitmask)) - && !test_bit(ABS_X, device->absBitmask) - && !test_bit(ABS_Y, device->absBitmask)) { + test_bit(BTN_TOUCH, device->keyBitmask)) && + !test_bit(ABS_X, device->absBitmask) && !test_bit(ABS_Y, device->absBitmask)) { device->classes |= INPUT_DEVICE_CLASS_EXTERNAL_STYLUS; // Keyboard will try to claim some of the buttons but we really want to reserve those so we // can fuse it with the touch screen data, so just take them back. Note this means an @@ -1333,8 +1340,8 @@ status_t EventHub::openDeviceLocked(const char* devicePath) { if (haveGamepadButtons) { uint32_t assumedClasses = device->classes | INPUT_DEVICE_CLASS_JOYSTICK; for (int i = 0; i <= ABS_MAX; i++) { - if (test_bit(i, device->absBitmask) - && (getAbsAxisUsage(i, assumedClasses) & INPUT_DEVICE_CLASS_JOYSTICK)) { + if (test_bit(i, device->absBitmask) && + (getAbsAxisUsage(i, assumedClasses) & INPUT_DEVICE_CLASS_JOYSTICK)) { device->classes = assumedClasses; break; } @@ -1375,10 +1382,8 @@ status_t EventHub::openDeviceLocked(const char* devicePath) { // Configure the keyboard, gamepad or virtual keyboard. if (device->classes & INPUT_DEVICE_CLASS_KEYBOARD) { // Register the keyboard as a built-in keyboard if it is eligible. - if (!keyMapStatus - && mBuiltInKeyboardId == NO_BUILT_IN_KEYBOARD - && isEligibleBuiltInKeyboard(device->identifier, - device->configuration, &device->keyMap)) { + if (!keyMapStatus && mBuiltInKeyboardId == NO_BUILT_IN_KEYBOARD && + isEligibleBuiltInKeyboard(device->identifier, device->configuration, &device->keyMap)) { mBuiltInKeyboardId = device->id; } @@ -1389,15 +1394,15 @@ status_t EventHub::openDeviceLocked(const char* devicePath) { // See if this device has a DPAD. if (hasKeycodeLocked(device, AKEYCODE_DPAD_UP) && - hasKeycodeLocked(device, AKEYCODE_DPAD_DOWN) && - hasKeycodeLocked(device, AKEYCODE_DPAD_LEFT) && - hasKeycodeLocked(device, AKEYCODE_DPAD_RIGHT) && - hasKeycodeLocked(device, AKEYCODE_DPAD_CENTER)) { + hasKeycodeLocked(device, AKEYCODE_DPAD_DOWN) && + hasKeycodeLocked(device, AKEYCODE_DPAD_LEFT) && + hasKeycodeLocked(device, AKEYCODE_DPAD_RIGHT) && + hasKeycodeLocked(device, AKEYCODE_DPAD_CENTER)) { device->classes |= INPUT_DEVICE_CLASS_DPAD; } // See if this device has a gamepad. - for (size_t i = 0; i < sizeof(GAMEPAD_KEYCODES)/sizeof(GAMEPAD_KEYCODES[0]); i++) { + for (size_t i = 0; i < sizeof(GAMEPAD_KEYCODES) / sizeof(GAMEPAD_KEYCODES[0]); i++) { if (hasKeycodeLocked(device, GAMEPAD_KEYCODES[i])) { device->classes |= INPUT_DEVICE_CLASS_GAMEPAD; break; @@ -1407,8 +1412,8 @@ status_t EventHub::openDeviceLocked(const char* devicePath) { // If the device isn't recognized as something we handle, don't monitor it. if (device->classes == 0) { - ALOGV("Dropping device: id=%d, path='%s', name='%s'", - deviceId, devicePath, device->identifier.name.c_str()); + ALOGV("Dropping device: id=%d, path='%s', name='%s'", deviceId, devicePath, + device->identifier.name.c_str()); delete device; return -1; } @@ -1423,8 +1428,8 @@ status_t EventHub::openDeviceLocked(const char* devicePath) { device->classes |= INPUT_DEVICE_CLASS_EXTERNAL; } - if (device->classes & (INPUT_DEVICE_CLASS_JOYSTICK | INPUT_DEVICE_CLASS_DPAD) - && device->classes & INPUT_DEVICE_CLASS_GAMEPAD) { + if (device->classes & (INPUT_DEVICE_CLASS_JOYSTICK | INPUT_DEVICE_CLASS_DPAD) && + device->classes & INPUT_DEVICE_CLASS_GAMEPAD) { device->controllerNumber = getNextControllerNumberLocked(device); setLedForControllerLocked(device); } @@ -1437,10 +1442,12 @@ status_t EventHub::openDeviceLocked(const char* devicePath) { break; } } - mUnattachedVideoDevices.erase(std::remove_if(mUnattachedVideoDevices.begin(), - mUnattachedVideoDevices.end(), - [](const std::unique_ptr<TouchVideoDevice>& videoDevice){ - return videoDevice == nullptr; }), mUnattachedVideoDevices.end()); + mUnattachedVideoDevices + .erase(std::remove_if(mUnattachedVideoDevices.begin(), mUnattachedVideoDevices.end(), + [](const std::unique_ptr<TouchVideoDevice>& videoDevice) { + return videoDevice == nullptr; + }), + mUnattachedVideoDevices.end()); if (registerDeviceForEpollLocked(device) != OK) { delete device; @@ -1450,13 +1457,10 @@ status_t EventHub::openDeviceLocked(const char* devicePath) { configureFd(device); ALOGI("New device: id=%d, fd=%d, path='%s', name='%s', classes=0x%x, " - "configuration='%s', keyLayout='%s', keyCharacterMap='%s', builtinKeyboard=%s, ", - deviceId, fd, devicePath, device->identifier.name.c_str(), - device->classes, - device->configurationFile.c_str(), - device->keyMap.keyLayoutFile.c_str(), - device->keyMap.keyCharacterMapFile.c_str(), - toString(mBuiltInKeyboardId == deviceId)); + "configuration='%s', keyLayout='%s', keyCharacterMap='%s', builtinKeyboard=%s, ", + deviceId, fd, devicePath, device->identifier.name.c_str(), device->classes, + device->configurationFile.c_str(), device->keyMap.keyLayoutFile.c_str(), + device->keyMap.keyCharacterMapFile.c_str(), toString(mBuiltInKeyboardId == deviceId)); addDeviceLocked(device); return OK; @@ -1468,8 +1472,8 @@ void EventHub::configureFd(Device* device) { // Disable kernel key repeat since we handle it ourselves unsigned int repeatRate[] = {0, 0}; if (ioctl(device->fd, EVIOCSREP, repeatRate)) { - ALOGW("Unable to disable kernel key repeat for %s: %s", - device->path.c_str(), strerror(errno)); + ALOGW("Unable to disable kernel key repeat for %s: %s", device->path.c_str(), + strerror(errno)); } } @@ -1503,7 +1507,7 @@ void EventHub::openVideoDeviceLocked(const std::string& devicePath) { // Couldn't find a matching input device, so just add it to a temporary holding queue. // A matching input device may appear later. ALOGI("Adding video device %s to list of unattached video devices", - videoDevice->getName().c_str()); + videoDevice->getName().c_str()); mUnattachedVideoDevices.push_back(std::move(videoDevice)); } @@ -1560,12 +1564,10 @@ void EventHub::createVirtualKeyboardLocked() { identifier.uniqueId = "<virtual>"; assignDescriptorLocked(identifier); - Device* device = new Device(-1, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, "<virtual>", - identifier); - device->classes = INPUT_DEVICE_CLASS_KEYBOARD - | INPUT_DEVICE_CLASS_ALPHAKEY - | INPUT_DEVICE_CLASS_DPAD - | INPUT_DEVICE_CLASS_VIRTUAL; + Device* device = + new Device(-1, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, "<virtual>", identifier); + device->classes = INPUT_DEVICE_CLASS_KEYBOARD | INPUT_DEVICE_CLASS_ALPHAKEY | + INPUT_DEVICE_CLASS_DPAD | INPUT_DEVICE_CLASS_VIRTUAL; loadKeyMapLocked(device); addDeviceLocked(device); } @@ -1581,14 +1583,14 @@ void EventHub::loadConfigurationLocked(Device* device) { device->identifier, INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION); if (device->configurationFile.empty()) { ALOGD("No input device configuration file found for device '%s'.", - device->identifier.name.c_str()); + device->identifier.name.c_str()); } else { status_t status = PropertyMap::load(String8(device->configurationFile.c_str()), - &device->configuration); + &device->configuration); if (status) { ALOGE("Error loading input device configuration file for device '%s'. " - "Using default configuration.", - device->identifier.name.c_str()); + "Using default configuration.", + device->identifier.name.c_str()); } } } @@ -1632,7 +1634,7 @@ bool EventHub::deviceHasMicLocked(Device* device) { int32_t EventHub::getNextControllerNumberLocked(Device* device) { if (mControllerNumbers.isFull()) { ALOGI("Maximum number of controllers reached, assigning controller number 0 to device %s", - device->identifier.name.c_str()); + device->identifier.name.c_str()); return 0; } // Since the controller number 0 is reserved for non-controllers, translate all numbers up by @@ -1642,7 +1644,7 @@ int32_t EventHub::getNextControllerNumberLocked(Device* device) { void EventHub::releaseControllerNumberLocked(Device* device) { int32_t num = device->controllerNumber; - device->controllerNumber= 0; + device->controllerNumber = 0; if (num == 0) { return; } @@ -1663,7 +1665,7 @@ bool EventHub::hasKeycodeLocked(Device* device, int keycode) const { std::vector<int32_t> scanCodes; device->keyMap.keyLayoutMap->findScanCodesForKey(keycode, &scanCodes); const size_t N = scanCodes.size(); - for (size_t i=0; i<N && i<=KEY_MAX; i++) { + for (size_t i = 0; i < N && i <= KEY_MAX; i++) { int32_t sc = scanCodes[i]; if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, device->keyBitmask)) { return true; @@ -1679,8 +1681,8 @@ status_t EventHub::mapLed(Device* device, int32_t led, int32_t* outScanCode) con } int32_t scanCode; - if(device->keyMap.keyLayoutMap->findScanCodeForLed(led, &scanCode) != NAME_NOT_FOUND) { - if(scanCode >= 0 && scanCode <= LED_MAX && test_bit(scanCode, device->ledBitmask)) { + if (device->keyMap.keyLayoutMap->findScanCodeForLed(led, &scanCode) != NAME_NOT_FOUND) { + if (scanCode >= 0 && scanCode <= LED_MAX && test_bit(scanCode, device->ledBitmask)) { *outScanCode = scanCode; return NO_ERROR; } @@ -1688,7 +1690,7 @@ status_t EventHub::mapLed(Device* device, int32_t led, int32_t* outScanCode) con return NAME_NOT_FOUND; } -void EventHub::closeDeviceByPathLocked(const char *devicePath) { +void EventHub::closeDeviceByPathLocked(const char* devicePath) { Device* device = getDeviceByPathLocked(devicePath); if (device) { closeDeviceLocked(device); @@ -1713,10 +1715,13 @@ void EventHub::closeVideoDeviceByPathLocked(const std::string& devicePath) { return; } } - mUnattachedVideoDevices.erase(std::remove_if(mUnattachedVideoDevices.begin(), - mUnattachedVideoDevices.end(), [&devicePath]( - const std::unique_ptr<TouchVideoDevice>& videoDevice) { - return videoDevice->getPath() == devicePath; }), mUnattachedVideoDevices.end()); + mUnattachedVideoDevices + .erase(std::remove_if(mUnattachedVideoDevices.begin(), mUnattachedVideoDevices.end(), + [&devicePath]( + const std::unique_ptr<TouchVideoDevice>& videoDevice) { + return videoDevice->getPath() == devicePath; + }), + mUnattachedVideoDevices.end()); } void EventHub::closeAllDevicesLocked() { @@ -1727,13 +1732,12 @@ void EventHub::closeAllDevicesLocked() { } void EventHub::closeDeviceLocked(Device* device) { - ALOGI("Removed device: path=%s name=%s id=%d fd=%d classes=0x%x", - device->path.c_str(), device->identifier.name.c_str(), device->id, - device->fd, device->classes); + ALOGI("Removed device: path=%s name=%s id=%d fd=%d classes=0x%x", device->path.c_str(), + device->identifier.name.c_str(), device->id, device->fd, device->classes); if (device->id == mBuiltInKeyboardId) { ALOGW("built-in keyboard device %s (id=%d) is closing! the apps will not like this", - device->path.c_str(), mBuiltInKeyboardId); + device->path.c_str(), mBuiltInKeyboardId); mBuiltInKeyboardId = NO_BUILT_IN_KEYBOARD; } @@ -1751,7 +1755,7 @@ void EventHub::closeDeviceLocked(Device* device) { // Unlink for opening devices list if it is present. Device* pred = nullptr; bool found = false; - for (Device* entry = mOpeningDevices; entry != nullptr; ) { + for (Device* entry = mOpeningDevices; entry != nullptr;) { if (entry == device) { found = true; break; @@ -1783,30 +1787,28 @@ status_t EventHub::readNotifyLocked() { char event_buf[512]; int event_size; int event_pos = 0; - struct inotify_event *event; + struct inotify_event* event; ALOGV("EventHub::readNotify nfd: %d\n", mINotifyFd); res = read(mINotifyFd, event_buf, sizeof(event_buf)); - if(res < (int)sizeof(*event)) { - if(errno == EINTR) - return 0; + if (res < (int)sizeof(*event)) { + if (errno == EINTR) return 0; ALOGW("could not get event, %s\n", strerror(errno)); return -1; } - while(res >= (int)sizeof(*event)) { - event = (struct inotify_event *)(event_buf + event_pos); - if(event->len) { + while (res >= (int)sizeof(*event)) { + event = (struct inotify_event*)(event_buf + event_pos); + if (event->len) { if (event->wd == mInputWd) { std::string filename = StringPrintf("%s/%s", DEVICE_PATH, event->name); - if(event->mask & IN_CREATE) { + if (event->mask & IN_CREATE) { openDeviceLocked(filename.c_str()); } else { ALOGI("Removing device '%s' due to inotify event\n", filename.c_str()); closeDeviceByPathLocked(filename.c_str()); } - } - else if (event->wd == mVideoWd) { + } else if (event->wd == mVideoWd) { if (isV4lTouchNode(event->name)) { std::string filename = StringPrintf("%s/%s", VIDEO_DEVICE_PATH, event->name); if (event->mask & IN_CREATE) { @@ -1816,8 +1818,7 @@ status_t EventHub::readNotifyLocked() { closeVideoDeviceByPathLocked(filename); } } - } - else { + } else { LOG_ALWAYS_FATAL("Unexpected inotify event, wd = %i", event->wd); } } @@ -1828,22 +1829,19 @@ status_t EventHub::readNotifyLocked() { return 0; } -status_t EventHub::scanDirLocked(const char *dirname) -{ +status_t EventHub::scanDirLocked(const char* dirname) { char devname[PATH_MAX]; - char *filename; - DIR *dir; - struct dirent *de; + char* filename; + DIR* dir; + struct dirent* de; dir = opendir(dirname); - if(dir == nullptr) - return -1; + if (dir == nullptr) return -1; strcpy(devname, dirname); filename = devname + strlen(devname); *filename++ = '/'; - while((de = readdir(dir))) { - if(de->d_name[0] == '.' && - (de->d_name[1] == '\0' || - (de->d_name[1] == '.' && de->d_name[2] == '\0'))) + while ((de = readdir(dir))) { + if (de->d_name[0] == '.' && + (de->d_name[1] == '\0' || (de->d_name[1] == '.' && de->d_name[2] == '\0'))) continue; strcpy(filename, de->d_name); openDeviceLocked(devname); @@ -1855,17 +1853,16 @@ status_t EventHub::scanDirLocked(const char *dirname) /** * Look for all dirname/v4l-touch* devices, and open them. */ -status_t EventHub::scanVideoDirLocked(const std::string& dirname) -{ +status_t EventHub::scanVideoDirLocked(const std::string& dirname) { DIR* dir; struct dirent* de; dir = opendir(dirname.c_str()); - if(!dir) { + if (!dir) { ALOGE("Could not open video directory %s", dirname.c_str()); return BAD_VALUE; } - while((de = readdir(dir))) { + while ((de = readdir(dir))) { const char* name = de->d_name; if (isV4lTouchNode(name)) { ALOGI("Found touch video device %s", name); @@ -1897,10 +1894,10 @@ void EventHub::dump(std::string& dump) { const Device* device = mDevices.valueAt(i); if (mBuiltInKeyboardId == device->id) { dump += StringPrintf(INDENT2 "%d: %s (aka device 0 - built-in keyboard)\n", - device->id, device->identifier.name.c_str()); + device->id, device->identifier.name.c_str()); } else { dump += StringPrintf(INDENT2 "%d: %s\n", device->id, - device->identifier.name.c_str()); + device->identifier.name.c_str()); } dump += StringPrintf(INDENT3 "Classes: 0x%08x\n", device->classes); dump += StringPrintf(INDENT3 "Path: %s\n", device->path.c_str()); @@ -1910,17 +1907,17 @@ void EventHub::dump(std::string& dump) { dump += StringPrintf(INDENT3 "ControllerNumber: %d\n", device->controllerNumber); dump += StringPrintf(INDENT3 "UniqueId: %s\n", device->identifier.uniqueId.c_str()); dump += StringPrintf(INDENT3 "Identifier: bus=0x%04x, vendor=0x%04x, " - "product=0x%04x, version=0x%04x\n", - device->identifier.bus, device->identifier.vendor, - device->identifier.product, device->identifier.version); + "product=0x%04x, version=0x%04x\n", + device->identifier.bus, device->identifier.vendor, + device->identifier.product, device->identifier.version); dump += StringPrintf(INDENT3 "KeyLayoutFile: %s\n", - device->keyMap.keyLayoutFile.c_str()); + device->keyMap.keyLayoutFile.c_str()); dump += StringPrintf(INDENT3 "KeyCharacterMapFile: %s\n", - device->keyMap.keyCharacterMapFile.c_str()); + device->keyMap.keyCharacterMapFile.c_str()); dump += StringPrintf(INDENT3 "ConfigurationFile: %s\n", - device->configurationFile.c_str()); + device->configurationFile.c_str()); dump += StringPrintf(INDENT3 "HaveKeyboardLayoutOverlay: %s\n", - toString(device->overlayKeyMap != nullptr)); + toString(device->overlayKeyMap != nullptr)); dump += INDENT3 "VideoDevice: "; if (device->videoDevice) { dump += device->videoDevice->dump() + "\n"; @@ -1945,5 +1942,4 @@ void EventHub::monitor() { mLock.unlock(); } - }; // namespace android diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp index d59f274ab0..521f621dea 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/reader/InputReader.cpp @@ -86,17 +86,17 @@ static constexpr nsecs_t STYLUS_DATA_LATENCY = ms2ns(10); // --- Static Functions --- -template<typename T> +template <typename T> inline static T abs(const T& value) { - return value < 0 ? - value : value; + return value < 0 ? -value : value; } -template<typename T> +template <typename T> inline static T min(const T& a, const T& b) { return a < b ? a : b; } -template<typename T> +template <typename T> inline static void swap(T& a, T& b) { T temp = a; a = b; @@ -120,7 +120,7 @@ static inline const char* toString(bool value) { } static int32_t rotateValueUsingRotationMap(int32_t value, int32_t orientation, - const int32_t map[][4], size_t mapSize) { + const int32_t map[][4], size_t mapSize) { if (orientation != DISPLAY_ORIENTATION_0) { for (size_t i = 0; i < mapSize; i++) { if (value == map[i][0]) { @@ -134,24 +134,24 @@ static int32_t rotateValueUsingRotationMap(int32_t value, int32_t orientation, static const int32_t keyCodeRotationMap[][4] = { // key codes enumerated counter-clockwise with the original (unrotated) key first // no rotation, 90 degree rotation, 180 degree rotation, 270 degree rotation - { AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT }, - { AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN }, - { AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT }, - { AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP }, - { AKEYCODE_SYSTEM_NAVIGATION_DOWN, AKEYCODE_SYSTEM_NAVIGATION_RIGHT, - AKEYCODE_SYSTEM_NAVIGATION_UP, AKEYCODE_SYSTEM_NAVIGATION_LEFT }, - { AKEYCODE_SYSTEM_NAVIGATION_RIGHT, AKEYCODE_SYSTEM_NAVIGATION_UP, - AKEYCODE_SYSTEM_NAVIGATION_LEFT, AKEYCODE_SYSTEM_NAVIGATION_DOWN }, - { AKEYCODE_SYSTEM_NAVIGATION_UP, AKEYCODE_SYSTEM_NAVIGATION_LEFT, - AKEYCODE_SYSTEM_NAVIGATION_DOWN, AKEYCODE_SYSTEM_NAVIGATION_RIGHT }, - { AKEYCODE_SYSTEM_NAVIGATION_LEFT, AKEYCODE_SYSTEM_NAVIGATION_DOWN, - AKEYCODE_SYSTEM_NAVIGATION_RIGHT, AKEYCODE_SYSTEM_NAVIGATION_UP }, + {AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT}, + {AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN}, + {AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT}, + {AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP}, + {AKEYCODE_SYSTEM_NAVIGATION_DOWN, AKEYCODE_SYSTEM_NAVIGATION_RIGHT, + AKEYCODE_SYSTEM_NAVIGATION_UP, AKEYCODE_SYSTEM_NAVIGATION_LEFT}, + {AKEYCODE_SYSTEM_NAVIGATION_RIGHT, AKEYCODE_SYSTEM_NAVIGATION_UP, + AKEYCODE_SYSTEM_NAVIGATION_LEFT, AKEYCODE_SYSTEM_NAVIGATION_DOWN}, + {AKEYCODE_SYSTEM_NAVIGATION_UP, AKEYCODE_SYSTEM_NAVIGATION_LEFT, + AKEYCODE_SYSTEM_NAVIGATION_DOWN, AKEYCODE_SYSTEM_NAVIGATION_RIGHT}, + {AKEYCODE_SYSTEM_NAVIGATION_LEFT, AKEYCODE_SYSTEM_NAVIGATION_DOWN, + AKEYCODE_SYSTEM_NAVIGATION_RIGHT, AKEYCODE_SYSTEM_NAVIGATION_UP}, }; static const size_t keyCodeRotationMapSize = sizeof(keyCodeRotationMap) / sizeof(keyCodeRotationMap[0]); -static int32_t rotateStemKey(int32_t value, int32_t orientation, - const int32_t map[][2], size_t mapSize) { +static int32_t rotateStemKey(int32_t value, int32_t orientation, const int32_t map[][2], + size_t mapSize) { if (orientation == DISPLAY_ORIENTATION_180) { for (size_t i = 0; i < mapSize; i++) { if (value == map[i][0]) { @@ -166,53 +166,52 @@ static int32_t rotateStemKey(int32_t value, int32_t orientation, static int32_t stemKeyRotationMap[][2] = { // key codes enumerated with the original (unrotated) key first // no rotation, 180 degree rotation - { AKEYCODE_STEM_PRIMARY, AKEYCODE_STEM_PRIMARY }, - { AKEYCODE_STEM_1, AKEYCODE_STEM_1 }, - { AKEYCODE_STEM_2, AKEYCODE_STEM_2 }, - { AKEYCODE_STEM_3, AKEYCODE_STEM_3 }, + {AKEYCODE_STEM_PRIMARY, AKEYCODE_STEM_PRIMARY}, + {AKEYCODE_STEM_1, AKEYCODE_STEM_1}, + {AKEYCODE_STEM_2, AKEYCODE_STEM_2}, + {AKEYCODE_STEM_3, AKEYCODE_STEM_3}, }; static const size_t stemKeyRotationMapSize = sizeof(stemKeyRotationMap) / sizeof(stemKeyRotationMap[0]); static int32_t rotateKeyCode(int32_t keyCode, int32_t orientation) { - keyCode = rotateStemKey(keyCode, orientation, - stemKeyRotationMap, stemKeyRotationMapSize); - return rotateValueUsingRotationMap(keyCode, orientation, - keyCodeRotationMap, keyCodeRotationMapSize); + keyCode = rotateStemKey(keyCode, orientation, stemKeyRotationMap, stemKeyRotationMapSize); + return rotateValueUsingRotationMap(keyCode, orientation, keyCodeRotationMap, + keyCodeRotationMapSize); } static void rotateDelta(int32_t orientation, float* deltaX, float* deltaY) { float temp; switch (orientation) { - case DISPLAY_ORIENTATION_90: - temp = *deltaX; - *deltaX = *deltaY; - *deltaY = -temp; - break; + case DISPLAY_ORIENTATION_90: + temp = *deltaX; + *deltaX = *deltaY; + *deltaY = -temp; + break; - case DISPLAY_ORIENTATION_180: - *deltaX = -*deltaX; - *deltaY = -*deltaY; - break; + case DISPLAY_ORIENTATION_180: + *deltaX = -*deltaX; + *deltaY = -*deltaY; + break; - case DISPLAY_ORIENTATION_270: - temp = *deltaX; - *deltaX = -*deltaY; - *deltaY = temp; - break; + case DISPLAY_ORIENTATION_270: + temp = *deltaX; + *deltaX = -*deltaY; + *deltaY = temp; + break; } } static inline bool sourcesMatchMask(uint32_t sources, uint32_t sourceMask) { - return (sources & sourceMask & ~ AINPUT_SOURCE_CLASS_MASK) != 0; + return (sources & sourceMask & ~AINPUT_SOURCE_CLASS_MASK) != 0; } // Returns true if the pointer should be reported as being down given the specified // button states. This determines whether the event is reported as a touch event. static bool isPointerDown(int32_t buttonState) { return buttonState & - (AMOTION_EVENT_BUTTON_PRIMARY | AMOTION_EVENT_BUTTON_SECONDARY - | AMOTION_EVENT_BUTTON_TERTIARY); + (AMOTION_EVENT_BUTTON_PRIMARY | AMOTION_EVENT_BUTTON_SECONDARY | + AMOTION_EVENT_BUTTON_TERTIARY); } static float calculateCommonVector(float a, float b) { @@ -225,35 +224,32 @@ static float calculateCommonVector(float a, float b) { } } -static void synthesizeButtonKey(InputReaderContext* context, int32_t action, - nsecs_t when, int32_t deviceId, uint32_t source, int32_t displayId, - uint32_t policyFlags, int32_t lastButtonState, int32_t currentButtonState, - int32_t buttonState, int32_t keyCode) { - if ( - (action == AKEY_EVENT_ACTION_DOWN - && !(lastButtonState & buttonState) - && (currentButtonState & buttonState)) - || (action == AKEY_EVENT_ACTION_UP - && (lastButtonState & buttonState) - && !(currentButtonState & buttonState))) { +static void synthesizeButtonKey(InputReaderContext* context, int32_t action, nsecs_t when, + int32_t deviceId, uint32_t source, int32_t displayId, + uint32_t policyFlags, int32_t lastButtonState, + int32_t currentButtonState, int32_t buttonState, int32_t keyCode) { + if ((action == AKEY_EVENT_ACTION_DOWN && !(lastButtonState & buttonState) && + (currentButtonState & buttonState)) || + (action == AKEY_EVENT_ACTION_UP && (lastButtonState & buttonState) && + !(currentButtonState & buttonState))) { NotifyKeyArgs args(context->getNextSequenceNum(), when, deviceId, source, displayId, - policyFlags, action, 0, keyCode, 0, context->getGlobalMetaState(), when); + policyFlags, action, 0, keyCode, 0, context->getGlobalMetaState(), when); context->getListener()->notifyKey(&args); } } -static void synthesizeButtonKeys(InputReaderContext* context, int32_t action, - nsecs_t when, int32_t deviceId, uint32_t source, int32_t displayId, - uint32_t policyFlags, int32_t lastButtonState, int32_t currentButtonState) { +static void synthesizeButtonKeys(InputReaderContext* context, int32_t action, nsecs_t when, + int32_t deviceId, uint32_t source, int32_t displayId, + uint32_t policyFlags, int32_t lastButtonState, + int32_t currentButtonState) { synthesizeButtonKey(context, action, when, deviceId, source, displayId, policyFlags, - lastButtonState, currentButtonState, - AMOTION_EVENT_BUTTON_BACK, AKEYCODE_BACK); + lastButtonState, currentButtonState, AMOTION_EVENT_BUTTON_BACK, + AKEYCODE_BACK); synthesizeButtonKey(context, action, when, deviceId, source, displayId, policyFlags, - lastButtonState, currentButtonState, - AMOTION_EVENT_BUTTON_FORWARD, AKEYCODE_FORWARD); + lastButtonState, currentButtonState, AMOTION_EVENT_BUTTON_FORWARD, + AKEYCODE_FORWARD); } - // --- InputReader --- InputReader::InputReader(std::shared_ptr<EventHubInterface> eventHub, @@ -355,8 +351,8 @@ void InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) { if (type < EventHubInterface::FIRST_SYNTHETIC_EVENT) { int32_t deviceId = rawEvent->deviceId; while (batchSize < count) { - if (rawEvent[batchSize].type >= EventHubInterface::FIRST_SYNTHETIC_EVENT - || rawEvent[batchSize].deviceId != deviceId) { + if (rawEvent[batchSize].type >= EventHubInterface::FIRST_SYNTHETIC_EVENT || + rawEvent[batchSize].deviceId != deviceId) { break; } batchSize += 1; @@ -367,18 +363,18 @@ void InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) { processEventsForDeviceLocked(deviceId, rawEvent, batchSize); } else { switch (rawEvent->type) { - case EventHubInterface::DEVICE_ADDED: - addDeviceLocked(rawEvent->when, rawEvent->deviceId); - break; - case EventHubInterface::DEVICE_REMOVED: - removeDeviceLocked(rawEvent->when, rawEvent->deviceId); - break; - case EventHubInterface::FINISHED_DEVICE_SCAN: - handleConfigurationChangedLocked(rawEvent->when); - break; - default: - ALOG_ASSERT(false); // can't happen - break; + case EventHubInterface::DEVICE_ADDED: + addDeviceLocked(rawEvent->when, rawEvent->deviceId); + break; + case EventHubInterface::DEVICE_REMOVED: + removeDeviceLocked(rawEvent->when, rawEvent->deviceId); + break; + case EventHubInterface::FINISHED_DEVICE_SCAN: + handleConfigurationChangedLocked(rawEvent->when); + break; + default: + ALOG_ASSERT(false); // can't happen + break; } } count -= batchSize; @@ -403,10 +399,10 @@ void InputReader::addDeviceLocked(nsecs_t when, int32_t deviceId) { if (device->isIgnored()) { ALOGI("Device added: id=%d, name='%s' (ignored non-input device)", deviceId, - identifier.name.c_str()); + identifier.name.c_str()); } else { - ALOGI("Device added: id=%d, name='%s', sources=0x%08x", deviceId, - identifier.name.c_str(), device->getSources()); + ALOGI("Device added: id=%d, name='%s', sources=0x%08x", deviceId, identifier.name.c_str(), + device->getSources()); } mDevices.add(deviceId, device); @@ -430,11 +426,11 @@ void InputReader::removeDeviceLocked(nsecs_t when, int32_t deviceId) { bumpGenerationLocked(); if (device->isIgnored()) { - ALOGI("Device removed: id=%d, name='%s' (ignored non-input device)", - device->getId(), device->getName().c_str()); + ALOGI("Device removed: id=%d, name='%s' (ignored non-input device)", device->getId(), + device->getName().c_str()); } else { - ALOGI("Device removed: id=%d, name='%s', sources=0x%08x", - device->getId(), device->getName().c_str(), device->getSources()); + ALOGI("Device removed: id=%d, name='%s', sources=0x%08x", device->getId(), + device->getName().c_str(), device->getSources()); } if (device->getClasses() & INPUT_DEVICE_CLASS_EXTERNAL_STYLUS) { @@ -446,9 +442,10 @@ void InputReader::removeDeviceLocked(nsecs_t when, int32_t deviceId) { } InputDevice* InputReader::createDeviceLocked(int32_t deviceId, int32_t controllerNumber, - const InputDeviceIdentifier& identifier, uint32_t classes) { + const InputDeviceIdentifier& identifier, + uint32_t classes) { InputDevice* device = new InputDevice(&mContext, deviceId, bumpGenerationLocked(), - controllerNumber, identifier, classes); + controllerNumber, identifier, classes); // External devices. if (classes & INPUT_DEVICE_CLASS_EXTERNAL) { @@ -520,8 +517,8 @@ InputDevice* InputReader::createDeviceLocked(int32_t deviceId, int32_t controlle return device; } -void InputReader::processEventsForDeviceLocked(int32_t deviceId, - const RawEvent* rawEvents, size_t count) { +void InputReader::processEventsForDeviceLocked(int32_t deviceId, const RawEvent* rawEvents, + size_t count) { ssize_t deviceIndex = mDevices.indexOfKey(deviceId); if (deviceIndex < 0) { ALOGW("Discarding event for unknown deviceId %d.", deviceId); @@ -530,7 +527,7 @@ void InputReader::processEventsForDeviceLocked(int32_t deviceId, InputDevice* device = mDevices.valueAt(deviceIndex); if (device->isIgnored()) { - //ALOGD("Discarding event for ignored deviceId %d.", deviceId); + // ALOGD("Discarding event for ignored deviceId %d.", deviceId); return; } @@ -614,14 +611,13 @@ void InputReader::disableVirtualKeysUntilLocked(nsecs_t time) { mDisableVirtualKeysTimeout = time; } -bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now, - InputDevice* device, int32_t keyCode, int32_t scanCode) { +bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now, InputDevice* device, int32_t keyCode, + int32_t scanCode) { if (now < mDisableVirtualKeysTimeout) { ALOGI("Dropping virtual key from device %s because virtual keys are " - "temporarily disabled for the next %0.3fms. keyCode=%d, scanCode=%d", - device->getName().c_str(), - (mDisableVirtualKeysTimeout - now) * 0.000001, - keyCode, scanCode); + "temporarily disabled for the next %0.3fms. keyCode=%d, scanCode=%d", + device->getName().c_str(), (mDisableVirtualKeysTimeout - now) * 0.000001, keyCode, + scanCode); return true; } else { return false; @@ -665,15 +661,13 @@ void InputReader::getInputDevicesLocked(std::vector<InputDeviceInfo>& outInputDe } } -int32_t InputReader::getKeyCodeState(int32_t deviceId, uint32_t sourceMask, - int32_t keyCode) { +int32_t InputReader::getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) { AutoMutex _l(mLock); return getStateLocked(deviceId, sourceMask, keyCode, &InputDevice::getKeyCodeState); } -int32_t InputReader::getScanCodeState(int32_t deviceId, uint32_t sourceMask, - int32_t scanCode) { +int32_t InputReader::getScanCodeState(int32_t deviceId, uint32_t sourceMask, int32_t scanCode) { AutoMutex _l(mLock); return getStateLocked(deviceId, sourceMask, scanCode, &InputDevice::getScanCodeState); @@ -686,13 +680,13 @@ int32_t InputReader::getSwitchState(int32_t deviceId, uint32_t sourceMask, int32 } int32_t InputReader::getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code, - GetStateFunc getStateFunc) { + GetStateFunc getStateFunc) { int32_t result = AKEY_STATE_UNKNOWN; if (deviceId >= 0) { ssize_t deviceIndex = mDevices.indexOfKey(deviceId); if (deviceIndex >= 0) { InputDevice* device = mDevices.valueAt(deviceIndex); - if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { + if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { result = (device->*getStateFunc)(sourceMask, code); } } @@ -700,7 +694,7 @@ int32_t InputReader::getStateLocked(int32_t deviceId, uint32_t sourceMask, int32 size_t numDevices = mDevices.size(); for (size_t i = 0; i < numDevices; i++) { InputDevice* device = mDevices.valueAt(i); - if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { + if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { // If any device reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that // value. Otherwise, return AKEY_STATE_UP as long as one device reports it. int32_t currentResult = (device->*getStateFunc)(sourceMask, code); @@ -730,8 +724,8 @@ void InputReader::toggleCapsLockState(int32_t deviceId) { device->updateMetaState(AKEYCODE_CAPS_LOCK); } -bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask, - size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) { +bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask, size_t numCodes, + const int32_t* keyCodes, uint8_t* outFlags) { AutoMutex _l(mLock); memset(outFlags, 0, numCodes); @@ -739,24 +733,23 @@ bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask, } bool InputReader::markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, - size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) { + size_t numCodes, const int32_t* keyCodes, + uint8_t* outFlags) { bool result = false; if (deviceId >= 0) { ssize_t deviceIndex = mDevices.indexOfKey(deviceId); if (deviceIndex >= 0) { InputDevice* device = mDevices.valueAt(deviceIndex); - if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { - result = device->markSupportedKeyCodes(sourceMask, - numCodes, keyCodes, outFlags); + if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { + result = device->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags); } } } else { size_t numDevices = mDevices.size(); for (size_t i = 0; i < numDevices; i++) { InputDevice* device = mDevices.valueAt(i); - if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { - result |= device->markSupportedKeyCodes(sourceMask, - numCodes, keyCodes, outFlags); + if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { + result |= device->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags); } } } @@ -777,7 +770,7 @@ void InputReader::requestRefreshConfiguration(uint32_t changes) { } void InputReader::vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize, - ssize_t repeat, int32_t token) { + ssize_t repeat, int32_t token) { AutoMutex _l(mLock); ssize_t deviceIndex = mDevices.indexOfKey(deviceId); @@ -860,47 +853,46 @@ void InputReader::dump(std::string& dump) { } dump += "]\n"; dump += StringPrintf(INDENT2 "VirtualKeyQuietTime: %0.1fms\n", - mConfig.virtualKeyQuietTime * 0.000001f); + mConfig.virtualKeyQuietTime * 0.000001f); dump += StringPrintf(INDENT2 "PointerVelocityControlParameters: " - "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, acceleration=%0.3f\n", - mConfig.pointerVelocityControlParameters.scale, - mConfig.pointerVelocityControlParameters.lowThreshold, - mConfig.pointerVelocityControlParameters.highThreshold, - mConfig.pointerVelocityControlParameters.acceleration); + "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, " + "acceleration=%0.3f\n", + mConfig.pointerVelocityControlParameters.scale, + mConfig.pointerVelocityControlParameters.lowThreshold, + mConfig.pointerVelocityControlParameters.highThreshold, + mConfig.pointerVelocityControlParameters.acceleration); dump += StringPrintf(INDENT2 "WheelVelocityControlParameters: " - "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, acceleration=%0.3f\n", - mConfig.wheelVelocityControlParameters.scale, - mConfig.wheelVelocityControlParameters.lowThreshold, - mConfig.wheelVelocityControlParameters.highThreshold, - mConfig.wheelVelocityControlParameters.acceleration); + "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, " + "acceleration=%0.3f\n", + mConfig.wheelVelocityControlParameters.scale, + mConfig.wheelVelocityControlParameters.lowThreshold, + mConfig.wheelVelocityControlParameters.highThreshold, + mConfig.wheelVelocityControlParameters.acceleration); dump += StringPrintf(INDENT2 "PointerGesture:\n"); - dump += StringPrintf(INDENT3 "Enabled: %s\n", - toString(mConfig.pointerGesturesEnabled)); + dump += StringPrintf(INDENT3 "Enabled: %s\n", toString(mConfig.pointerGesturesEnabled)); dump += StringPrintf(INDENT3 "QuietInterval: %0.1fms\n", - mConfig.pointerGestureQuietInterval * 0.000001f); + mConfig.pointerGestureQuietInterval * 0.000001f); dump += StringPrintf(INDENT3 "DragMinSwitchSpeed: %0.1fpx/s\n", - mConfig.pointerGestureDragMinSwitchSpeed); + mConfig.pointerGestureDragMinSwitchSpeed); dump += StringPrintf(INDENT3 "TapInterval: %0.1fms\n", - mConfig.pointerGestureTapInterval * 0.000001f); + mConfig.pointerGestureTapInterval * 0.000001f); dump += StringPrintf(INDENT3 "TapDragInterval: %0.1fms\n", - mConfig.pointerGestureTapDragInterval * 0.000001f); - dump += StringPrintf(INDENT3 "TapSlop: %0.1fpx\n", - mConfig.pointerGestureTapSlop); + mConfig.pointerGestureTapDragInterval * 0.000001f); + dump += StringPrintf(INDENT3 "TapSlop: %0.1fpx\n", mConfig.pointerGestureTapSlop); dump += StringPrintf(INDENT3 "MultitouchSettleInterval: %0.1fms\n", - mConfig.pointerGestureMultitouchSettleInterval * 0.000001f); + mConfig.pointerGestureMultitouchSettleInterval * 0.000001f); dump += StringPrintf(INDENT3 "MultitouchMinDistance: %0.1fpx\n", - mConfig.pointerGestureMultitouchMinDistance); + mConfig.pointerGestureMultitouchMinDistance); dump += StringPrintf(INDENT3 "SwipeTransitionAngleCosine: %0.1f\n", - mConfig.pointerGestureSwipeTransitionAngleCosine); + mConfig.pointerGestureSwipeTransitionAngleCosine); dump += StringPrintf(INDENT3 "SwipeMaxWidthRatio: %0.1f\n", - mConfig.pointerGestureSwipeMaxWidthRatio); + mConfig.pointerGestureSwipeMaxWidthRatio); dump += StringPrintf(INDENT3 "MovementSpeedRatio: %0.1f\n", - mConfig.pointerGestureMovementSpeedRatio); - dump += StringPrintf(INDENT3 "ZoomSpeedRatio: %0.1f\n", - mConfig.pointerGestureZoomSpeedRatio); + mConfig.pointerGestureMovementSpeedRatio); + dump += StringPrintf(INDENT3 "ZoomSpeedRatio: %0.1f\n", mConfig.pointerGestureZoomSpeedRatio); dump += INDENT3 "Viewports:\n"; mConfig.dump(dump); @@ -917,12 +909,9 @@ void InputReader::monitor() { mEventHub->monitor(); } - // --- InputReader::ContextImpl --- -InputReader::ContextImpl::ContextImpl(InputReader* reader) : - mReader(reader) { -} +InputReader::ContextImpl::ContextImpl(InputReader* reader) : mReader(reader) {} void InputReader::ContextImpl::updateGlobalMetaState() { // lock is already held by the input loop @@ -939,8 +928,8 @@ void InputReader::ContextImpl::disableVirtualKeysUntil(nsecs_t time) { mReader->disableVirtualKeysUntilLocked(time); } -bool InputReader::ContextImpl::shouldDropVirtualKey(nsecs_t now, - InputDevice* device, int32_t keyCode, int32_t scanCode) { +bool InputReader::ContextImpl::shouldDropVirtualKey(nsecs_t now, InputDevice* device, + int32_t keyCode, int32_t scanCode) { // lock is already held by the input loop return mReader->shouldDropVirtualKeyLocked(now, device, keyCode, scanCode); } @@ -988,11 +977,18 @@ uint32_t InputReader::ContextImpl::getNextSequenceNum() { // --- InputDevice --- InputDevice::InputDevice(InputReaderContext* context, int32_t id, int32_t generation, - int32_t controllerNumber, const InputDeviceIdentifier& identifier, uint32_t classes) : - mContext(context), mId(id), mGeneration(generation), mControllerNumber(controllerNumber), - mIdentifier(identifier), mClasses(classes), - mSources(0), mIsExternal(false), mHasMic(false), mDropUntilNextSync(false) { -} + int32_t controllerNumber, const InputDeviceIdentifier& identifier, + uint32_t classes) + : mContext(context), + mId(id), + mGeneration(generation), + mControllerNumber(controllerNumber), + mIdentifier(identifier), + mClasses(classes), + mSources(0), + mIsExternal(false), + mHasMic(false), + mDropUntilNextSync(false) {} InputDevice::~InputDevice() { size_t numMappers = mMappers.size(); @@ -1034,7 +1030,7 @@ void InputDevice::dump(std::string& dump) { getDeviceInfo(&deviceInfo); dump += StringPrintf(INDENT "Device %d: %s\n", deviceInfo.getId(), - deviceInfo.getDisplayName().c_str()); + deviceInfo.getDisplayName().c_str()); dump += StringPrintf(INDENT2 "Generation: %d\n", mGeneration); dump += StringPrintf(INDENT2 "IsExternal: %s\n", toString(mIsExternal)); dump += StringPrintf(INDENT2 "AssociatedDisplayPort: "); @@ -1060,10 +1056,11 @@ void InputDevice::dump(std::string& dump) { } else { snprintf(name, sizeof(name), "%d", range.axis); } - dump += StringPrintf(INDENT3 "%s: source=0x%08x, " - "min=%0.3f, max=%0.3f, flat=%0.3f, fuzz=%0.3f, resolution=%0.3f\n", - name, range.source, range.min, range.max, range.flat, range.fuzz, - range.resolution); + dump += StringPrintf(INDENT3 + "%s: source=0x%08x, " + "min=%0.3f, max=%0.3f, flat=%0.3f, fuzz=%0.3f, resolution=%0.3f\n", + name, range.source, range.min, range.max, range.flat, range.fuzz, + range.resolution); } } @@ -1078,7 +1075,8 @@ void InputDevice::addMapper(InputMapper* mapper) { mMappers.push_back(mapper); } -void InputDevice::configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes) { +void InputDevice::configure(nsecs_t when, const InputReaderConfiguration* config, + uint32_t changes) { mSources = 0; if (!isIgnored()) { @@ -1113,7 +1111,7 @@ void InputDevice::configure(nsecs_t when, const InputReaderConfiguration* config } if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) { - // In most situations, no port will be specified. + // In most situations, no port will be specified. mAssociatedDisplayPort = std::nullopt; mAssociatedViewport = std::nullopt; // Find the display port that corresponds to the current input port. @@ -1181,8 +1179,7 @@ void InputDevice::process(const RawEvent* rawEvents, size_t count) { for (const RawEvent* rawEvent = rawEvents; count != 0; rawEvent++) { #if DEBUG_RAW_EVENTS ALOGD("Input event: device=%d type=0x%04x code=0x%04x value=0x%08x when=%" PRId64, - rawEvent->deviceId, rawEvent->type, rawEvent->code, rawEvent->value, - rawEvent->when); + rawEvent->deviceId, rawEvent->type, rawEvent->code, rawEvent->value, rawEvent->when); #endif if (mDropUntilNextSync) { @@ -1222,23 +1219,23 @@ void InputDevice::updateExternalStylusState(const StylusState& state) { } void InputDevice::getDeviceInfo(InputDeviceInfo* outDeviceInfo) { - outDeviceInfo->initialize(mId, mGeneration, mControllerNumber, mIdentifier, mAlias, - mIsExternal, mHasMic); + outDeviceInfo->initialize(mId, mGeneration, mControllerNumber, mIdentifier, mAlias, mIsExternal, + mHasMic); for (InputMapper* mapper : mMappers) { mapper->populateDeviceInfo(outDeviceInfo); } } int32_t InputDevice::getKeyCodeState(uint32_t sourceMask, int32_t keyCode) { - return getState(sourceMask, keyCode, & InputMapper::getKeyCodeState); + return getState(sourceMask, keyCode, &InputMapper::getKeyCodeState); } int32_t InputDevice::getScanCodeState(uint32_t sourceMask, int32_t scanCode) { - return getState(sourceMask, scanCode, & InputMapper::getScanCodeState); + return getState(sourceMask, scanCode, &InputMapper::getScanCodeState); } int32_t InputDevice::getSwitchState(uint32_t sourceMask, int32_t switchCode) { - return getState(sourceMask, switchCode, & InputMapper::getSwitchState); + return getState(sourceMask, switchCode, &InputMapper::getSwitchState); } int32_t InputDevice::getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc) { @@ -1259,7 +1256,7 @@ int32_t InputDevice::getState(uint32_t sourceMask, int32_t code, GetStateFunc ge } bool InputDevice::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, - const int32_t* keyCodes, uint8_t* outFlags) { + const int32_t* keyCodes, uint8_t* outFlags) { bool result = false; for (InputMapper* mapper : mMappers) { if (sourcesMatchMask(mapper->getSources(), sourceMask)) { @@ -1270,7 +1267,7 @@ bool InputDevice::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, } void InputDevice::vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, - int32_t token) { + int32_t token) { for (InputMapper* mapper : mMappers) { mapper->vibrate(pattern, patternSize, repeat, token); } @@ -1365,30 +1362,30 @@ void CursorButtonAccumulator::clearButtons() { void CursorButtonAccumulator::process(const RawEvent* rawEvent) { if (rawEvent->type == EV_KEY) { switch (rawEvent->code) { - case BTN_LEFT: - mBtnLeft = rawEvent->value; - break; - case BTN_RIGHT: - mBtnRight = rawEvent->value; - break; - case BTN_MIDDLE: - mBtnMiddle = rawEvent->value; - break; - case BTN_BACK: - mBtnBack = rawEvent->value; - break; - case BTN_SIDE: - mBtnSide = rawEvent->value; - break; - case BTN_FORWARD: - mBtnForward = rawEvent->value; - break; - case BTN_EXTRA: - mBtnExtra = rawEvent->value; - break; - case BTN_TASK: - mBtnTask = rawEvent->value; - break; + case BTN_LEFT: + mBtnLeft = rawEvent->value; + break; + case BTN_RIGHT: + mBtnRight = rawEvent->value; + break; + case BTN_MIDDLE: + mBtnMiddle = rawEvent->value; + break; + case BTN_BACK: + mBtnBack = rawEvent->value; + break; + case BTN_SIDE: + mBtnSide = rawEvent->value; + break; + case BTN_FORWARD: + mBtnForward = rawEvent->value; + break; + case BTN_EXTRA: + mBtnExtra = rawEvent->value; + break; + case BTN_TASK: + mBtnTask = rawEvent->value; + break; } } } @@ -1413,7 +1410,6 @@ uint32_t CursorButtonAccumulator::getButtonState() const { return result; } - // --- CursorMotionAccumulator --- CursorMotionAccumulator::CursorMotionAccumulator() { @@ -1432,12 +1428,12 @@ void CursorMotionAccumulator::clearRelativeAxes() { void CursorMotionAccumulator::process(const RawEvent* rawEvent) { if (rawEvent->type == EV_REL) { switch (rawEvent->code) { - case REL_X: - mRelX = rawEvent->value; - break; - case REL_Y: - mRelY = rawEvent->value; - break; + case REL_X: + mRelX = rawEvent->value; + break; + case REL_Y: + mRelY = rawEvent->value; + break; } } } @@ -1446,11 +1442,9 @@ void CursorMotionAccumulator::finishSync() { clearRelativeAxes(); } - // --- CursorScrollAccumulator --- -CursorScrollAccumulator::CursorScrollAccumulator() : - mHaveRelWheel(false), mHaveRelHWheel(false) { +CursorScrollAccumulator::CursorScrollAccumulator() : mHaveRelWheel(false), mHaveRelHWheel(false) { clearRelativeAxes(); } @@ -1471,12 +1465,12 @@ void CursorScrollAccumulator::clearRelativeAxes() { void CursorScrollAccumulator::process(const RawEvent* rawEvent) { if (rawEvent->type == EV_REL) { switch (rawEvent->code) { - case REL_WHEEL: - mRelWheel = rawEvent->value; - break; - case REL_HWHEEL: - mRelHWheel = rawEvent->value; - break; + case REL_WHEEL: + mRelWheel = rawEvent->value; + break; + case REL_HWHEEL: + mRelHWheel = rawEvent->value; + break; } } } @@ -1485,29 +1479,24 @@ void CursorScrollAccumulator::finishSync() { clearRelativeAxes(); } - // --- TouchButtonAccumulator --- -TouchButtonAccumulator::TouchButtonAccumulator() : - mHaveBtnTouch(false), mHaveStylus(false) { +TouchButtonAccumulator::TouchButtonAccumulator() : mHaveBtnTouch(false), mHaveStylus(false) { clearButtons(); } void TouchButtonAccumulator::configure(InputDevice* device) { mHaveBtnTouch = device->hasKey(BTN_TOUCH); - mHaveStylus = device->hasKey(BTN_TOOL_PEN) - || device->hasKey(BTN_TOOL_RUBBER) - || device->hasKey(BTN_TOOL_BRUSH) - || device->hasKey(BTN_TOOL_PENCIL) - || device->hasKey(BTN_TOOL_AIRBRUSH); + mHaveStylus = device->hasKey(BTN_TOOL_PEN) || device->hasKey(BTN_TOOL_RUBBER) || + device->hasKey(BTN_TOOL_BRUSH) || device->hasKey(BTN_TOOL_PENCIL) || + device->hasKey(BTN_TOOL_AIRBRUSH); } void TouchButtonAccumulator::reset(InputDevice* device) { mBtnTouch = device->isKeyPressed(BTN_TOUCH); mBtnStylus = device->isKeyPressed(BTN_STYLUS); // BTN_0 is what gets mapped for the HID usage Digitizers.SecondaryBarrelSwitch - mBtnStylus2 = - device->isKeyPressed(BTN_STYLUS2) || device->isKeyPressed(BTN_0); + mBtnStylus2 = device->isKeyPressed(BTN_STYLUS2) || device->isKeyPressed(BTN_0); mBtnToolFinger = device->isKeyPressed(BTN_TOOL_FINGER); mBtnToolPen = device->isKeyPressed(BTN_TOOL_PEN); mBtnToolRubber = device->isKeyPressed(BTN_TOOL_RUBBER); @@ -1541,49 +1530,50 @@ void TouchButtonAccumulator::clearButtons() { void TouchButtonAccumulator::process(const RawEvent* rawEvent) { if (rawEvent->type == EV_KEY) { switch (rawEvent->code) { - case BTN_TOUCH: - mBtnTouch = rawEvent->value; - break; - case BTN_STYLUS: - mBtnStylus = rawEvent->value; - break; - case BTN_STYLUS2: - case BTN_0:// BTN_0 is what gets mapped for the HID usage Digitizers.SecondaryBarrelSwitch - mBtnStylus2 = rawEvent->value; - break; - case BTN_TOOL_FINGER: - mBtnToolFinger = rawEvent->value; - break; - case BTN_TOOL_PEN: - mBtnToolPen = rawEvent->value; - break; - case BTN_TOOL_RUBBER: - mBtnToolRubber = rawEvent->value; - break; - case BTN_TOOL_BRUSH: - mBtnToolBrush = rawEvent->value; - break; - case BTN_TOOL_PENCIL: - mBtnToolPencil = rawEvent->value; - break; - case BTN_TOOL_AIRBRUSH: - mBtnToolAirbrush = rawEvent->value; - break; - case BTN_TOOL_MOUSE: - mBtnToolMouse = rawEvent->value; - break; - case BTN_TOOL_LENS: - mBtnToolLens = rawEvent->value; - break; - case BTN_TOOL_DOUBLETAP: - mBtnToolDoubleTap = rawEvent->value; - break; - case BTN_TOOL_TRIPLETAP: - mBtnToolTripleTap = rawEvent->value; - break; - case BTN_TOOL_QUADTAP: - mBtnToolQuadTap = rawEvent->value; - break; + case BTN_TOUCH: + mBtnTouch = rawEvent->value; + break; + case BTN_STYLUS: + mBtnStylus = rawEvent->value; + break; + case BTN_STYLUS2: + case BTN_0: // BTN_0 is what gets mapped for the HID usage + // Digitizers.SecondaryBarrelSwitch + mBtnStylus2 = rawEvent->value; + break; + case BTN_TOOL_FINGER: + mBtnToolFinger = rawEvent->value; + break; + case BTN_TOOL_PEN: + mBtnToolPen = rawEvent->value; + break; + case BTN_TOOL_RUBBER: + mBtnToolRubber = rawEvent->value; + break; + case BTN_TOOL_BRUSH: + mBtnToolBrush = rawEvent->value; + break; + case BTN_TOOL_PENCIL: + mBtnToolPencil = rawEvent->value; + break; + case BTN_TOOL_AIRBRUSH: + mBtnToolAirbrush = rawEvent->value; + break; + case BTN_TOOL_MOUSE: + mBtnToolMouse = rawEvent->value; + break; + case BTN_TOOL_LENS: + mBtnToolLens = rawEvent->value; + break; + case BTN_TOOL_DOUBLETAP: + mBtnToolDoubleTap = rawEvent->value; + break; + case BTN_TOOL_TRIPLETAP: + mBtnToolTripleTap = rawEvent->value; + break; + case BTN_TOOL_QUADTAP: + mBtnToolQuadTap = rawEvent->value; + break; } } } @@ -1616,10 +1606,9 @@ int32_t TouchButtonAccumulator::getToolType() const { } bool TouchButtonAccumulator::isToolActive() const { - return mBtnTouch || mBtnToolFinger || mBtnToolPen || mBtnToolRubber - || mBtnToolBrush || mBtnToolPencil || mBtnToolAirbrush - || mBtnToolMouse || mBtnToolLens - || mBtnToolDoubleTap || mBtnToolTripleTap || mBtnToolQuadTap; + return mBtnTouch || mBtnToolFinger || mBtnToolPen || mBtnToolRubber || mBtnToolBrush || + mBtnToolPencil || mBtnToolAirbrush || mBtnToolMouse || mBtnToolLens || + mBtnToolDoubleTap || mBtnToolTripleTap || mBtnToolQuadTap; } bool TouchButtonAccumulator::isHovering() const { @@ -1630,7 +1619,6 @@ bool TouchButtonAccumulator::hasStylus() const { return mHaveStylus; } - // --- RawPointerAxes --- RawPointerAxes::RawPointerAxes() { @@ -1653,7 +1641,6 @@ void RawPointerAxes::clear() { slot.clear(); } - // --- RawPointerData --- RawPointerData::RawPointerData() { @@ -1682,7 +1669,7 @@ void RawPointerData::getCentroidOfTouchingPointers(float* outX, float* outY) con float x = 0, y = 0; uint32_t count = touchingIdBits.count(); if (count) { - for (BitSet32 idBits(touchingIdBits); !idBits.isEmpty(); ) { + for (BitSet32 idBits(touchingIdBits); !idBits.isEmpty();) { uint32_t id = idBits.clearFirstMarkedBit(); const Pointer& pointer = pointerForId(id); x += pointer.x; @@ -1695,7 +1682,6 @@ void RawPointerData::getCentroidOfTouchingPointers(float* outX, float* outY) con *outY = y; } - // --- CookedPointerData --- CookedPointerData::CookedPointerData() { @@ -1722,7 +1708,6 @@ void CookedPointerData::copyFrom(const CookedPointerData& other) { } } - // --- SingleTouchMotionAccumulator --- SingleTouchMotionAccumulator::SingleTouchMotionAccumulator() { @@ -1752,32 +1737,31 @@ void SingleTouchMotionAccumulator::clearAbsoluteAxes() { void SingleTouchMotionAccumulator::process(const RawEvent* rawEvent) { if (rawEvent->type == EV_ABS) { switch (rawEvent->code) { - case ABS_X: - mAbsX = rawEvent->value; - break; - case ABS_Y: - mAbsY = rawEvent->value; - break; - case ABS_PRESSURE: - mAbsPressure = rawEvent->value; - break; - case ABS_TOOL_WIDTH: - mAbsToolWidth = rawEvent->value; - break; - case ABS_DISTANCE: - mAbsDistance = rawEvent->value; - break; - case ABS_TILT_X: - mAbsTiltX = rawEvent->value; - break; - case ABS_TILT_Y: - mAbsTiltY = rawEvent->value; - break; + case ABS_X: + mAbsX = rawEvent->value; + break; + case ABS_Y: + mAbsY = rawEvent->value; + break; + case ABS_PRESSURE: + mAbsPressure = rawEvent->value; + break; + case ABS_TOOL_WIDTH: + mAbsToolWidth = rawEvent->value; + break; + case ABS_DISTANCE: + mAbsDistance = rawEvent->value; + break; + case ABS_TILT_X: + mAbsTiltX = rawEvent->value; + break; + case ABS_TILT_Y: + mAbsTiltY = rawEvent->value; + break; } } } - // --- MultiTouchMotionAccumulator --- MultiTouchMotionAccumulator::MultiTouchMotionAccumulator() @@ -1791,8 +1775,8 @@ MultiTouchMotionAccumulator::~MultiTouchMotionAccumulator() { delete[] mSlots; } -void MultiTouchMotionAccumulator::configure(InputDevice* device, - size_t slotCount, bool usingSlotsProtocol) { +void MultiTouchMotionAccumulator::configure(InputDevice* device, size_t slotCount, + bool usingSlotsProtocol) { mSlotCount = slotCount; mUsingSlotsProtocol = usingSlotsProtocol; mHaveStylus = device->hasAbsoluteAxis(ABS_MT_TOOL_TYPE); @@ -1815,8 +1799,8 @@ void MultiTouchMotionAccumulator::reset(InputDevice* device) { // This can cause the touch point to "jump", but at least there will be // no stuck touches. int32_t initialSlot; - status_t status = device->getEventHub()->getAbsoluteAxisValue(device->getId(), - ABS_MT_SLOT, &initialSlot); + status_t status = device->getEventHub()->getAbsoluteAxisValue(device->getId(), ABS_MT_SLOT, + &initialSlot); if (status) { ALOGD("Could not retrieve current multitouch slot index. status=%d", status); initialSlot = -1; @@ -1852,67 +1836,67 @@ void MultiTouchMotionAccumulator::process(const RawEvent* rawEvent) { #if DEBUG_POINTERS if (newSlot) { ALOGW("MultiTouch device emitted invalid slot index %d but it " - "should be between 0 and %zd; ignoring this slot.", - mCurrentSlot, mSlotCount - 1); + "should be between 0 and %zd; ignoring this slot.", + mCurrentSlot, mSlotCount - 1); } #endif } else { Slot* slot = &mSlots[mCurrentSlot]; switch (rawEvent->code) { - case ABS_MT_POSITION_X: - slot->mInUse = true; - slot->mAbsMTPositionX = rawEvent->value; - break; - case ABS_MT_POSITION_Y: - slot->mInUse = true; - slot->mAbsMTPositionY = rawEvent->value; - break; - case ABS_MT_TOUCH_MAJOR: - slot->mInUse = true; - slot->mAbsMTTouchMajor = rawEvent->value; - break; - case ABS_MT_TOUCH_MINOR: - slot->mInUse = true; - slot->mAbsMTTouchMinor = rawEvent->value; - slot->mHaveAbsMTTouchMinor = true; - break; - case ABS_MT_WIDTH_MAJOR: - slot->mInUse = true; - slot->mAbsMTWidthMajor = rawEvent->value; - break; - case ABS_MT_WIDTH_MINOR: - slot->mInUse = true; - slot->mAbsMTWidthMinor = rawEvent->value; - slot->mHaveAbsMTWidthMinor = true; - break; - case ABS_MT_ORIENTATION: - slot->mInUse = true; - slot->mAbsMTOrientation = rawEvent->value; - break; - case ABS_MT_TRACKING_ID: - if (mUsingSlotsProtocol && rawEvent->value < 0) { - // The slot is no longer in use but it retains its previous contents, - // which may be reused for subsequent touches. - slot->mInUse = false; - } else { + case ABS_MT_POSITION_X: slot->mInUse = true; - slot->mAbsMTTrackingId = rawEvent->value; - } - break; - case ABS_MT_PRESSURE: - slot->mInUse = true; - slot->mAbsMTPressure = rawEvent->value; - break; - case ABS_MT_DISTANCE: - slot->mInUse = true; - slot->mAbsMTDistance = rawEvent->value; - break; - case ABS_MT_TOOL_TYPE: - slot->mInUse = true; - slot->mAbsMTToolType = rawEvent->value; - slot->mHaveAbsMTToolType = true; - break; + slot->mAbsMTPositionX = rawEvent->value; + break; + case ABS_MT_POSITION_Y: + slot->mInUse = true; + slot->mAbsMTPositionY = rawEvent->value; + break; + case ABS_MT_TOUCH_MAJOR: + slot->mInUse = true; + slot->mAbsMTTouchMajor = rawEvent->value; + break; + case ABS_MT_TOUCH_MINOR: + slot->mInUse = true; + slot->mAbsMTTouchMinor = rawEvent->value; + slot->mHaveAbsMTTouchMinor = true; + break; + case ABS_MT_WIDTH_MAJOR: + slot->mInUse = true; + slot->mAbsMTWidthMajor = rawEvent->value; + break; + case ABS_MT_WIDTH_MINOR: + slot->mInUse = true; + slot->mAbsMTWidthMinor = rawEvent->value; + slot->mHaveAbsMTWidthMinor = true; + break; + case ABS_MT_ORIENTATION: + slot->mInUse = true; + slot->mAbsMTOrientation = rawEvent->value; + break; + case ABS_MT_TRACKING_ID: + if (mUsingSlotsProtocol && rawEvent->value < 0) { + // The slot is no longer in use but it retains its previous contents, + // which may be reused for subsequent touches. + slot->mInUse = false; + } else { + slot->mInUse = true; + slot->mAbsMTTrackingId = rawEvent->value; + } + break; + case ABS_MT_PRESSURE: + slot->mInUse = true; + slot->mAbsMTPressure = rawEvent->value; + break; + case ABS_MT_DISTANCE: + slot->mInUse = true; + slot->mAbsMTDistance = rawEvent->value; + break; + case ABS_MT_TOOL_TYPE: + slot->mInUse = true; + slot->mAbsMTToolType = rawEvent->value; + slot->mHaveAbsMTToolType = true; + break; } } } else if (rawEvent->type == EV_SYN && rawEvent->code == SYN_MT_REPORT) { @@ -1931,7 +1915,6 @@ bool MultiTouchMotionAccumulator::hasStylus() const { return mHaveStylus; } - // --- MultiTouchMotionAccumulator::Slot --- MultiTouchMotionAccumulator::Slot::Slot() { @@ -1959,41 +1942,33 @@ void MultiTouchMotionAccumulator::Slot::clear() { int32_t MultiTouchMotionAccumulator::Slot::getToolType() const { if (mHaveAbsMTToolType) { switch (mAbsMTToolType) { - case MT_TOOL_FINGER: - return AMOTION_EVENT_TOOL_TYPE_FINGER; - case MT_TOOL_PEN: - return AMOTION_EVENT_TOOL_TYPE_STYLUS; + case MT_TOOL_FINGER: + return AMOTION_EVENT_TOOL_TYPE_FINGER; + case MT_TOOL_PEN: + return AMOTION_EVENT_TOOL_TYPE_STYLUS; } } return AMOTION_EVENT_TOOL_TYPE_UNKNOWN; } - // --- InputMapper --- -InputMapper::InputMapper(InputDevice* device) : - mDevice(device), mContext(device->getContext()) { -} +InputMapper::InputMapper(InputDevice* device) : mDevice(device), mContext(device->getContext()) {} -InputMapper::~InputMapper() { -} +InputMapper::~InputMapper() {} void InputMapper::populateDeviceInfo(InputDeviceInfo* info) { info->addSource(getSources()); } -void InputMapper::dump(std::string& dump) { -} +void InputMapper::dump(std::string& dump) {} -void InputMapper::configure(nsecs_t when, - const InputReaderConfiguration* config, uint32_t changes) { -} +void InputMapper::configure(nsecs_t when, const InputReaderConfiguration* config, + uint32_t changes) {} -void InputMapper::reset(nsecs_t when) { -} +void InputMapper::reset(nsecs_t when) {} -void InputMapper::timeoutExpired(nsecs_t when) { -} +void InputMapper::timeoutExpired(nsecs_t when) {} int32_t InputMapper::getKeyCodeState(uint32_t sourceMask, int32_t keyCode) { return AKEY_STATE_UNKNOWN; @@ -2008,33 +1983,26 @@ int32_t InputMapper::getSwitchState(uint32_t sourceMask, int32_t switchCode) { } bool InputMapper::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, - const int32_t* keyCodes, uint8_t* outFlags) { + const int32_t* keyCodes, uint8_t* outFlags) { return false; } void InputMapper::vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, - int32_t token) { -} + int32_t token) {} -void InputMapper::cancelVibrate(int32_t token) { -} +void InputMapper::cancelVibrate(int32_t token) {} -void InputMapper::cancelTouch(nsecs_t when) { -} +void InputMapper::cancelTouch(nsecs_t when) {} int32_t InputMapper::getMetaState() { return 0; } -void InputMapper::updateMetaState(int32_t keyCode) { -} - -void InputMapper::updateExternalStylusState(const StylusState& state) { +void InputMapper::updateMetaState(int32_t keyCode) {} -} +void InputMapper::updateExternalStylusState(const StylusState& state) {} -void InputMapper::fadePointer() { -} +void InputMapper::fadePointer() {} status_t InputMapper::getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo) { return getEventHub()->getAbsoluteAxisInfo(getDeviceId(), axis, axisInfo); @@ -2044,11 +2012,11 @@ void InputMapper::bumpGeneration() { mDevice->bumpGeneration(); } -void InputMapper::dumpRawAbsoluteAxisInfo(std::string& dump, - const RawAbsoluteAxisInfo& axis, const char* name) { +void InputMapper::dumpRawAbsoluteAxisInfo(std::string& dump, const RawAbsoluteAxisInfo& axis, + const char* name) { if (axis.valid) { - dump += StringPrintf(INDENT4 "%s: min=%d, max=%d, flat=%d, fuzz=%d, resolution=%d\n", - name, axis.minValue, axis.maxValue, axis.flat, axis.fuzz, axis.resolution); + dump += StringPrintf(INDENT4 "%s: min=%d, max=%d, flat=%d, fuzz=%d, resolution=%d\n", name, + axis.minValue, axis.maxValue, axis.flat, axis.fuzz, axis.resolution); } else { dump += StringPrintf(INDENT4 "%s: unknown range\n", name); } @@ -2063,12 +2031,10 @@ void InputMapper::dumpStylusState(std::string& dump, const StylusState& state) { // --- SwitchInputMapper --- -SwitchInputMapper::SwitchInputMapper(InputDevice* device) : - InputMapper(device), mSwitchValues(0), mUpdatedSwitchMask(0) { -} +SwitchInputMapper::SwitchInputMapper(InputDevice* device) + : InputMapper(device), mSwitchValues(0), mUpdatedSwitchMask(0) {} -SwitchInputMapper::~SwitchInputMapper() { -} +SwitchInputMapper::~SwitchInputMapper() {} uint32_t SwitchInputMapper::getSources() { return AINPUT_SOURCE_SWITCH; @@ -2076,14 +2042,14 @@ uint32_t SwitchInputMapper::getSources() { void SwitchInputMapper::process(const RawEvent* rawEvent) { switch (rawEvent->type) { - case EV_SW: - processSwitch(rawEvent->code, rawEvent->value); - break; + case EV_SW: + processSwitch(rawEvent->code, rawEvent->value); + break; - case EV_SYN: - if (rawEvent->code == SYN_REPORT) { - sync(rawEvent->when); - } + case EV_SYN: + if (rawEvent->code == SYN_REPORT) { + sync(rawEvent->when); + } } } @@ -2102,7 +2068,7 @@ void SwitchInputMapper::sync(nsecs_t when) { if (mUpdatedSwitchMask) { uint32_t updatedSwitchValues = mSwitchValues & mUpdatedSwitchMask; NotifySwitchArgs args(mContext->getNextSequenceNum(), when, 0, updatedSwitchValues, - mUpdatedSwitchMask); + mUpdatedSwitchMask); getListener()->notifySwitch(&args); mUpdatedSwitchMask = 0; @@ -2120,12 +2086,10 @@ void SwitchInputMapper::dump(std::string& dump) { // --- VibratorInputMapper --- -VibratorInputMapper::VibratorInputMapper(InputDevice* device) : - InputMapper(device), mVibrating(false) { -} +VibratorInputMapper::VibratorInputMapper(InputDevice* device) + : InputMapper(device), mVibrating(false) {} -VibratorInputMapper::~VibratorInputMapper() { -} +VibratorInputMapper::~VibratorInputMapper() {} uint32_t VibratorInputMapper::getSources() { return 0; @@ -2142,7 +2106,7 @@ void VibratorInputMapper::process(const RawEvent* rawEvent) { } void VibratorInputMapper::vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, - int32_t token) { + int32_t token) { #if DEBUG_VIBRATOR std::string patternStr; for (size_t i = 0; i < patternSize; i++) { @@ -2151,8 +2115,8 @@ void VibratorInputMapper::vibrate(const nsecs_t* pattern, size_t patternSize, ss } patternStr += StringPrintf("%" PRId64, pattern[i]); } - ALOGD("vibrate: deviceId=%d, pattern=[%s], repeat=%zd, token=%d", - getDeviceId(), patternStr.c_str(), repeat, token); + ALOGD("vibrate: deviceId=%d, pattern=[%s], repeat=%zd, token=%d", getDeviceId(), + patternStr.c_str(), repeat, token); #endif mVibrating = true; @@ -2230,16 +2194,12 @@ void VibratorInputMapper::dump(std::string& dump) { dump += StringPrintf(INDENT3 "Vibrating: %s\n", toString(mVibrating)); } - // --- KeyboardInputMapper --- -KeyboardInputMapper::KeyboardInputMapper(InputDevice* device, - uint32_t source, int32_t keyboardType) : - InputMapper(device), mSource(source), mKeyboardType(keyboardType) { -} +KeyboardInputMapper::KeyboardInputMapper(InputDevice* device, uint32_t source, int32_t keyboardType) + : InputMapper(device), mSource(source), mKeyboardType(keyboardType) {} -KeyboardInputMapper::~KeyboardInputMapper() { -} +KeyboardInputMapper::~KeyboardInputMapper() {} uint32_t KeyboardInputMapper::getSources() { return mSource; @@ -2292,8 +2252,8 @@ std::optional<DisplayViewport> KeyboardInputMapper::findViewport( return std::nullopt; } -void KeyboardInputMapper::configure(nsecs_t when, - const InputReaderConfiguration* config, uint32_t changes) { +void KeyboardInputMapper::configure(nsecs_t when, const InputReaderConfiguration* config, + uint32_t changes) { InputMapper::configure(when, config, changes); if (!changes) { // first time only @@ -2306,7 +2266,7 @@ void KeyboardInputMapper::configure(nsecs_t when, } } -static void mapStemKey(int32_t keyCode, const PropertyMap& config, char const *property) { +static void mapStemKey(int32_t keyCode, const PropertyMap& config, char const* property) { int32_t mapped = 0; if (config.tryGetProperty(String8(property), mapped) && mapped > 0) { for (size_t i = 0; i < stemKeyRotationMapSize; i++) { @@ -2321,8 +2281,7 @@ static void mapStemKey(int32_t keyCode, const PropertyMap& config, char const *p void KeyboardInputMapper::configureParameters() { mParameters.orientationAware = false; const PropertyMap& config = getDevice()->getConfiguration(); - config.tryGetProperty(String8("keyboard.orientationAware"), - mParameters.orientationAware); + config.tryGetProperty(String8("keyboard.orientationAware"), mParameters.orientationAware); if (mParameters.orientationAware) { mapStemKey(AKEYCODE_STEM_PRIMARY, config, "keyboard.rotated.stem_primary"); @@ -2332,16 +2291,13 @@ void KeyboardInputMapper::configureParameters() { } mParameters.handlesKeyRepeat = false; - config.tryGetProperty(String8("keyboard.handlesKeyRepeat"), - mParameters.handlesKeyRepeat); + config.tryGetProperty(String8("keyboard.handlesKeyRepeat"), mParameters.handlesKeyRepeat); } void KeyboardInputMapper::dumpParameters(std::string& dump) { dump += INDENT3 "Parameters:\n"; - dump += StringPrintf(INDENT4 "OrientationAware: %s\n", - toString(mParameters.orientationAware)); - dump += StringPrintf(INDENT4 "HandlesKeyRepeat: %s\n", - toString(mParameters.handlesKeyRepeat)); + dump += StringPrintf(INDENT4 "OrientationAware: %s\n", toString(mParameters.orientationAware)); + dump += StringPrintf(INDENT4 "HandlesKeyRepeat: %s\n", toString(mParameters.handlesKeyRepeat)); } void KeyboardInputMapper::reset(nsecs_t when) { @@ -2357,74 +2313,72 @@ void KeyboardInputMapper::reset(nsecs_t when) { void KeyboardInputMapper::process(const RawEvent* rawEvent) { switch (rawEvent->type) { - case EV_KEY: { - int32_t scanCode = rawEvent->code; - int32_t usageCode = mCurrentHidUsage; - mCurrentHidUsage = 0; + case EV_KEY: { + int32_t scanCode = rawEvent->code; + int32_t usageCode = mCurrentHidUsage; + mCurrentHidUsage = 0; - if (isKeyboardOrGamepadKey(scanCode)) { - processKey(rawEvent->when, rawEvent->value != 0, scanCode, usageCode); + if (isKeyboardOrGamepadKey(scanCode)) { + processKey(rawEvent->when, rawEvent->value != 0, scanCode, usageCode); + } + break; } - break; - } - case EV_MSC: { - if (rawEvent->code == MSC_SCAN) { - mCurrentHidUsage = rawEvent->value; + case EV_MSC: { + if (rawEvent->code == MSC_SCAN) { + mCurrentHidUsage = rawEvent->value; + } + break; } - break; - } - case EV_SYN: { - if (rawEvent->code == SYN_REPORT) { - mCurrentHidUsage = 0; + case EV_SYN: { + if (rawEvent->code == SYN_REPORT) { + mCurrentHidUsage = 0; + } } } - } } bool KeyboardInputMapper::isKeyboardOrGamepadKey(int32_t scanCode) { - return scanCode < BTN_MOUSE - || scanCode >= KEY_OK - || (scanCode >= BTN_MISC && scanCode < BTN_MOUSE) - || (scanCode >= BTN_JOYSTICK && scanCode < BTN_DIGI); + return scanCode < BTN_MOUSE || scanCode >= KEY_OK || + (scanCode >= BTN_MISC && scanCode < BTN_MOUSE) || + (scanCode >= BTN_JOYSTICK && scanCode < BTN_DIGI); } bool KeyboardInputMapper::isMediaKey(int32_t keyCode) { switch (keyCode) { - case AKEYCODE_MEDIA_PLAY: - case AKEYCODE_MEDIA_PAUSE: - case AKEYCODE_MEDIA_PLAY_PAUSE: - case AKEYCODE_MUTE: - case AKEYCODE_HEADSETHOOK: - case AKEYCODE_MEDIA_STOP: - case AKEYCODE_MEDIA_NEXT: - case AKEYCODE_MEDIA_PREVIOUS: - case AKEYCODE_MEDIA_REWIND: - case AKEYCODE_MEDIA_RECORD: - case AKEYCODE_MEDIA_FAST_FORWARD: - case AKEYCODE_MEDIA_SKIP_FORWARD: - case AKEYCODE_MEDIA_SKIP_BACKWARD: - case AKEYCODE_MEDIA_STEP_FORWARD: - case AKEYCODE_MEDIA_STEP_BACKWARD: - case AKEYCODE_MEDIA_AUDIO_TRACK: - case AKEYCODE_VOLUME_UP: - case AKEYCODE_VOLUME_DOWN: - case AKEYCODE_VOLUME_MUTE: - case AKEYCODE_TV_AUDIO_DESCRIPTION: - case AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP: - case AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN: - return true; + case AKEYCODE_MEDIA_PLAY: + case AKEYCODE_MEDIA_PAUSE: + case AKEYCODE_MEDIA_PLAY_PAUSE: + case AKEYCODE_MUTE: + case AKEYCODE_HEADSETHOOK: + case AKEYCODE_MEDIA_STOP: + case AKEYCODE_MEDIA_NEXT: + case AKEYCODE_MEDIA_PREVIOUS: + case AKEYCODE_MEDIA_REWIND: + case AKEYCODE_MEDIA_RECORD: + case AKEYCODE_MEDIA_FAST_FORWARD: + case AKEYCODE_MEDIA_SKIP_FORWARD: + case AKEYCODE_MEDIA_SKIP_BACKWARD: + case AKEYCODE_MEDIA_STEP_FORWARD: + case AKEYCODE_MEDIA_STEP_BACKWARD: + case AKEYCODE_MEDIA_AUDIO_TRACK: + case AKEYCODE_VOLUME_UP: + case AKEYCODE_VOLUME_DOWN: + case AKEYCODE_VOLUME_MUTE: + case AKEYCODE_TV_AUDIO_DESCRIPTION: + case AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP: + case AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN: + return true; } return false; } -void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t scanCode, - int32_t usageCode) { +void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t scanCode, int32_t usageCode) { int32_t keyCode; int32_t keyMetaState; uint32_t policyFlags; - if (getEventHub()->mapKey(getDeviceId(), scanCode, usageCode, mMetaState, - &keyCode, &keyMetaState, &policyFlags)) { + if (getEventHub()->mapKey(getDeviceId(), scanCode, usageCode, mMetaState, &keyCode, + &keyMetaState, &policyFlags)) { keyCode = AKEYCODE_UNKNOWN; keyMetaState = mMetaState; policyFlags = 0; @@ -2443,9 +2397,8 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t scanCode, keyCode = mKeyDowns[keyDownIndex].keyCode; } else { // key down - if ((policyFlags & POLICY_FLAG_VIRTUAL) - && mContext->shouldDropVirtualKey(when, - getDevice(), keyCode, scanCode)) { + if ((policyFlags & POLICY_FLAG_VIRTUAL) && + mContext->shouldDropVirtualKey(when, getDevice(), keyCode, scanCode)) { return; } if (policyFlags & POLICY_FLAG_GESTURE) { @@ -2469,8 +2422,8 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t scanCode, } else { // key was not actually down ALOGI("Dropping key up from device %s because the key was not down. " - "keyCode=%d, scanCode=%d", - getDeviceName().c_str(), keyCode, scanCode); + "keyCode=%d, scanCode=%d", + getDeviceName().c_str(), keyCode, scanCode); return; } } @@ -2498,9 +2451,9 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t scanCode, policyFlags |= POLICY_FLAG_DISABLE_KEY_REPEAT; } - NotifyKeyArgs args(mContext->getNextSequenceNum(), when, getDeviceId(), mSource, - getDisplayId(), policyFlags, down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP, - AKEY_EVENT_FLAG_FROM_SYSTEM, keyCode, scanCode, keyMetaState, downTime); + NotifyKeyArgs args(mContext->getNextSequenceNum(), when, getDeviceId(), mSource, getDisplayId(), + policyFlags, down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP, + AKEY_EVENT_FLAG_FROM_SYSTEM, keyCode, scanCode, keyMetaState, downTime); getListener()->notifyKey(&args); } @@ -2523,7 +2476,7 @@ int32_t KeyboardInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanC } bool KeyboardInputMapper::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, - const int32_t* keyCodes, uint8_t* outFlags) { + const int32_t* keyCodes, uint8_t* outFlags) { return getEventHub()->markSupportedKeyCodes(getDeviceId(), numCodes, keyCodes, outFlags); } @@ -2563,16 +2516,13 @@ void KeyboardInputMapper::initializeLedState(LedState& ledState, int32_t led) { } void KeyboardInputMapper::updateLedState(bool reset) { - updateLedStateForModifier(mCapsLockLedState, ALED_CAPS_LOCK, - AMETA_CAPS_LOCK_ON, reset); - updateLedStateForModifier(mNumLockLedState, ALED_NUM_LOCK, - AMETA_NUM_LOCK_ON, reset); - updateLedStateForModifier(mScrollLockLedState, ALED_SCROLL_LOCK, - AMETA_SCROLL_LOCK_ON, reset); + updateLedStateForModifier(mCapsLockLedState, ALED_CAPS_LOCK, AMETA_CAPS_LOCK_ON, reset); + updateLedStateForModifier(mNumLockLedState, ALED_NUM_LOCK, AMETA_NUM_LOCK_ON, reset); + updateLedStateForModifier(mScrollLockLedState, ALED_SCROLL_LOCK, AMETA_SCROLL_LOCK_ON, reset); } -void KeyboardInputMapper::updateLedStateForModifier(LedState& ledState, - int32_t led, int32_t modifier, bool reset) { +void KeyboardInputMapper::updateLedStateForModifier(LedState& ledState, int32_t led, + int32_t modifier, bool reset) { if (ledState.avail) { bool desiredState = (mMetaState & modifier) != 0; if (reset || ledState.on != desiredState) { @@ -2591,12 +2541,9 @@ std::optional<int32_t> KeyboardInputMapper::getAssociatedDisplayId() { // --- CursorInputMapper --- -CursorInputMapper::CursorInputMapper(InputDevice* device) : - InputMapper(device) { -} +CursorInputMapper::CursorInputMapper(InputDevice* device) : InputMapper(device) {} -CursorInputMapper::~CursorInputMapper() { -} +CursorInputMapper::~CursorInputMapper() {} uint32_t CursorInputMapper::getSources() { return mSource; @@ -2633,9 +2580,9 @@ void CursorInputMapper::dump(std::string& dump) { dump += StringPrintf(INDENT3 "XPrecision: %0.3f\n", mXPrecision); dump += StringPrintf(INDENT3 "YPrecision: %0.3f\n", mYPrecision); dump += StringPrintf(INDENT3 "HaveVWheel: %s\n", - toString(mCursorScrollAccumulator.haveRelativeVWheel())); + toString(mCursorScrollAccumulator.haveRelativeVWheel())); dump += StringPrintf(INDENT3 "HaveHWheel: %s\n", - toString(mCursorScrollAccumulator.haveRelativeHWheel())); + toString(mCursorScrollAccumulator.haveRelativeHWheel())); dump += StringPrintf(INDENT3 "VWheelScale: %0.3f\n", mVWheelScale); dump += StringPrintf(INDENT3 "HWheelScale: %0.3f\n", mHWheelScale); dump += StringPrintf(INDENT3 "Orientation: %d\n", mOrientation); @@ -2644,8 +2591,8 @@ void CursorInputMapper::dump(std::string& dump) { dump += StringPrintf(INDENT3 "DownTime: %" PRId64 "\n", mDownTime); } -void CursorInputMapper::configure(nsecs_t when, - const InputReaderConfiguration* config, uint32_t changes) { +void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration* config, + uint32_t changes) { InputMapper::configure(when, config, changes); if (!changes) { // first time only @@ -2656,34 +2603,34 @@ void CursorInputMapper::configure(nsecs_t when, // Configure device mode. switch (mParameters.mode) { - case Parameters::MODE_POINTER_RELATIVE: - // Should not happen during first time configuration. - ALOGE("Cannot start a device in MODE_POINTER_RELATIVE, starting in MODE_POINTER"); - mParameters.mode = Parameters::MODE_POINTER; - [[fallthrough]]; - case Parameters::MODE_POINTER: - mSource = AINPUT_SOURCE_MOUSE; - mXPrecision = 1.0f; - mYPrecision = 1.0f; - mXScale = 1.0f; - mYScale = 1.0f; - mPointerController = getPolicy()->obtainPointerController(getDeviceId()); - break; - case Parameters::MODE_NAVIGATION: - mSource = AINPUT_SOURCE_TRACKBALL; - mXPrecision = TRACKBALL_MOVEMENT_THRESHOLD; - mYPrecision = TRACKBALL_MOVEMENT_THRESHOLD; - mXScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD; - mYScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD; - break; + case Parameters::MODE_POINTER_RELATIVE: + // Should not happen during first time configuration. + ALOGE("Cannot start a device in MODE_POINTER_RELATIVE, starting in MODE_POINTER"); + mParameters.mode = Parameters::MODE_POINTER; + [[fallthrough]]; + case Parameters::MODE_POINTER: + mSource = AINPUT_SOURCE_MOUSE; + mXPrecision = 1.0f; + mYPrecision = 1.0f; + mXScale = 1.0f; + mYScale = 1.0f; + mPointerController = getPolicy()->obtainPointerController(getDeviceId()); + break; + case Parameters::MODE_NAVIGATION: + mSource = AINPUT_SOURCE_TRACKBALL; + mXPrecision = TRACKBALL_MOVEMENT_THRESHOLD; + mYPrecision = TRACKBALL_MOVEMENT_THRESHOLD; + mXScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD; + mYScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD; + break; } mVWheelScale = 1.0f; mHWheelScale = 1.0f; } - if ((!changes && config->pointerCapture) - || (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE)) { + if ((!changes && config->pointerCapture) || + (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE)) { if (config->pointerCapture) { if (mParameters.mode == Parameters::MODE_POINTER) { mParameters.mode = Parameters::MODE_POINTER_RELATIVE; @@ -2744,7 +2691,7 @@ void CursorInputMapper::configureParameters() { mParameters.orientationAware = false; getDevice()->getConfiguration().tryGetProperty(String8("cursor.orientationAware"), - mParameters.orientationAware); + mParameters.orientationAware); mParameters.hasAssociatedDisplay = false; if (mParameters.mode == Parameters::MODE_POINTER || mParameters.orientationAware) { @@ -2755,24 +2702,23 @@ void CursorInputMapper::configureParameters() { void CursorInputMapper::dumpParameters(std::string& dump) { dump += INDENT3 "Parameters:\n"; dump += StringPrintf(INDENT4 "HasAssociatedDisplay: %s\n", - toString(mParameters.hasAssociatedDisplay)); + toString(mParameters.hasAssociatedDisplay)); switch (mParameters.mode) { - case Parameters::MODE_POINTER: - dump += INDENT4 "Mode: pointer\n"; - break; - case Parameters::MODE_POINTER_RELATIVE: - dump += INDENT4 "Mode: relative pointer\n"; - break; - case Parameters::MODE_NAVIGATION: - dump += INDENT4 "Mode: navigation\n"; - break; - default: - ALOG_ASSERT(false); + case Parameters::MODE_POINTER: + dump += INDENT4 "Mode: pointer\n"; + break; + case Parameters::MODE_POINTER_RELATIVE: + dump += INDENT4 "Mode: relative pointer\n"; + break; + case Parameters::MODE_NAVIGATION: + dump += INDENT4 "Mode: navigation\n"; + break; + default: + ALOG_ASSERT(false); } - dump += StringPrintf(INDENT4 "OrientationAware: %s\n", - toString(mParameters.orientationAware)); + dump += StringPrintf(INDENT4 "OrientationAware: %s\n", toString(mParameters.orientationAware)); } void CursorInputMapper::reset(nsecs_t when) { @@ -2826,8 +2772,8 @@ void CursorInputMapper::sync(nsecs_t when) { bool moved = deltaX != 0 || deltaY != 0; // Rotate delta according to orientation if needed. - if (mParameters.orientationAware && mParameters.hasAssociatedDisplay - && (deltaX != 0.0f || deltaY != 0.0f)) { + if (mParameters.orientationAware && mParameters.hasAssociatedDisplay && + (deltaX != 0.0f || deltaY != 0.0f)) { rotateDelta(mOrientation, &deltaX, &deltaY); } @@ -2854,8 +2800,7 @@ void CursorInputMapper::sync(nsecs_t when) { float yCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION; if (mSource == AINPUT_SOURCE_MOUSE) { if (moved || scrolled || buttonsChanged) { - mPointerController->setPresentation( - PointerControllerInterface::PRESENTATION_POINTER); + mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_POINTER); if (moved) { mPointerController->move(deltaX, deltaY); @@ -2893,7 +2838,7 @@ void CursorInputMapper::sync(nsecs_t when) { // Synthesize key down from buttons if needed. synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_DOWN, when, getDeviceId(), mSource, - displayId, policyFlags, lastButtonState, currentButtonState); + displayId, policyFlags, lastButtonState, currentButtonState); // Send motion event. if (downChanged || moved || scrolled || buttonsChanged) { @@ -2953,8 +2898,7 @@ void CursorInputMapper::sync(nsecs_t when) { ALOG_ASSERT(buttonState == currentButtonState); // Send hover move after UP to tell the application that the mouse is hovering now. - if (motionEventAction == AMOTION_EVENT_ACTION_UP - && (mSource == AINPUT_SOURCE_MOUSE)) { + if (motionEventAction == AMOTION_EVENT_ACTION_UP && (mSource == AINPUT_SOURCE_MOUSE)) { NotifyMotionArgs hoverArgs(mContext->getNextSequenceNum(), when, getDeviceId(), mSource, displayId, policyFlags, AMOTION_EVENT_ACTION_HOVER_MOVE, 0, 0, metaState, currentButtonState, MotionClassification::NONE, @@ -2982,7 +2926,7 @@ void CursorInputMapper::sync(nsecs_t when) { // Synthesize key up from buttons if needed. synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_UP, when, getDeviceId(), mSource, - displayId, policyFlags, lastButtonState, currentButtonState); + displayId, policyFlags, lastButtonState, currentButtonState); mCursorMotionAccumulator.finishSync(); mCursorScrollAccumulator.finishSync(); @@ -3017,13 +2961,12 @@ std::optional<int32_t> CursorInputMapper::getAssociatedDisplayId() { // --- RotaryEncoderInputMapper --- -RotaryEncoderInputMapper::RotaryEncoderInputMapper(InputDevice* device) : - InputMapper(device), mOrientation(DISPLAY_ORIENTATION_0) { +RotaryEncoderInputMapper::RotaryEncoderInputMapper(InputDevice* device) + : InputMapper(device), mOrientation(DISPLAY_ORIENTATION_0) { mSource = AINPUT_SOURCE_ROTARY_ENCODER; } -RotaryEncoderInputMapper::~RotaryEncoderInputMapper() { -} +RotaryEncoderInputMapper::~RotaryEncoderInputMapper() {} uint32_t RotaryEncoderInputMapper::getSources() { return mSource; @@ -3038,24 +2981,24 @@ void RotaryEncoderInputMapper::populateDeviceInfo(InputDeviceInfo* info) { ALOGW("Rotary Encoder device configuration file didn't specify resolution!\n"); } if (!mDevice->getConfiguration().tryGetProperty(String8("device.scalingFactor"), - mScalingFactor)) { + mScalingFactor)) { ALOGW("Rotary Encoder device configuration file didn't specify scaling factor," - "default to 1.0!\n"); + "default to 1.0!\n"); mScalingFactor = 1.0f; } info->addMotionRange(AMOTION_EVENT_AXIS_SCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f, - res * mScalingFactor); + res * mScalingFactor); } } void RotaryEncoderInputMapper::dump(std::string& dump) { dump += INDENT2 "Rotary Encoder Input Mapper:\n"; dump += StringPrintf(INDENT3 "HaveWheel: %s\n", - toString(mRotaryEncoderScrollAccumulator.haveRelativeVWheel())); + toString(mRotaryEncoderScrollAccumulator.haveRelativeVWheel())); } -void RotaryEncoderInputMapper::configure(nsecs_t when, - const InputReaderConfiguration* config, uint32_t changes) { +void RotaryEncoderInputMapper::configure(nsecs_t when, const InputReaderConfiguration* config, + uint32_t changes) { InputMapper::configure(when, config, changes); if (!changes) { mRotaryEncoderScrollAccumulator.configure(getDevice()); @@ -3129,16 +3072,21 @@ void RotaryEncoderInputMapper::sync(nsecs_t when) { // --- TouchInputMapper --- -TouchInputMapper::TouchInputMapper(InputDevice* device) : - InputMapper(device), - mSource(0), mDeviceMode(DEVICE_MODE_DISABLED), - mSurfaceWidth(-1), mSurfaceHeight(-1), mSurfaceLeft(0), mSurfaceTop(0), - mPhysicalWidth(-1), mPhysicalHeight(-1), mPhysicalLeft(0), mPhysicalTop(0), - mSurfaceOrientation(DISPLAY_ORIENTATION_0) { -} - -TouchInputMapper::~TouchInputMapper() { -} +TouchInputMapper::TouchInputMapper(InputDevice* device) + : InputMapper(device), + mSource(0), + mDeviceMode(DEVICE_MODE_DISABLED), + mSurfaceWidth(-1), + mSurfaceHeight(-1), + mSurfaceLeft(0), + mSurfaceTop(0), + mPhysicalWidth(-1), + mPhysicalHeight(-1), + mPhysicalLeft(0), + mPhysicalTop(0), + mSurfaceOrientation(DISPLAY_ORIENTATION_0) {} + +TouchInputMapper::~TouchInputMapper() {} uint32_t TouchInputMapper::getSources() { return mSource; @@ -3180,23 +3128,23 @@ void TouchInputMapper::populateDeviceInfo(InputDeviceInfo* info) { if (mCursorScrollAccumulator.haveRelativeVWheel()) { info->addMotionRange(AMOTION_EVENT_AXIS_VSCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f, - 0.0f); + 0.0f); } if (mCursorScrollAccumulator.haveRelativeHWheel()) { info->addMotionRange(AMOTION_EVENT_AXIS_HSCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f, - 0.0f); + 0.0f); } if (mCalibration.coverageCalibration == Calibration::COVERAGE_CALIBRATION_BOX) { const InputDeviceInfo::MotionRange& x = mOrientedRanges.x; const InputDeviceInfo::MotionRange& y = mOrientedRanges.y; info->addMotionRange(AMOTION_EVENT_AXIS_GENERIC_1, mSource, x.min, x.max, x.flat, - x.fuzz, x.resolution); + x.fuzz, x.resolution); info->addMotionRange(AMOTION_EVENT_AXIS_GENERIC_2, mSource, y.min, y.max, y.flat, - y.fuzz, y.resolution); + y.fuzz, y.resolution); info->addMotionRange(AMOTION_EVENT_AXIS_GENERIC_3, mSource, x.min, x.max, x.flat, - x.fuzz, x.resolution); + x.fuzz, x.resolution); info->addMotionRange(AMOTION_EVENT_AXIS_GENERIC_4, mSource, y.min, y.max, y.flat, - y.fuzz, y.resolution); + y.fuzz, y.resolution); } info->setButtonUnderPad(mParameters.hasButtonUnderPad); } @@ -3231,88 +3179,82 @@ void TouchInputMapper::dump(std::string& dump) { dump += StringPrintf(INDENT3 "Last Raw Button State: 0x%08x\n", mLastRawState.buttonState); dump += StringPrintf(INDENT3 "Last Raw Touch: pointerCount=%d\n", - mLastRawState.rawPointerData.pointerCount); + mLastRawState.rawPointerData.pointerCount); for (uint32_t i = 0; i < mLastRawState.rawPointerData.pointerCount; i++) { const RawPointerData::Pointer& pointer = mLastRawState.rawPointerData.pointers[i]; dump += StringPrintf(INDENT4 "[%d]: id=%d, x=%d, y=%d, pressure=%d, " - "touchMajor=%d, touchMinor=%d, toolMajor=%d, toolMinor=%d, " - "orientation=%d, tiltX=%d, tiltY=%d, distance=%d, " - "toolType=%d, isHovering=%s\n", i, - pointer.id, pointer.x, pointer.y, pointer.pressure, - pointer.touchMajor, pointer.touchMinor, - pointer.toolMajor, pointer.toolMinor, - pointer.orientation, pointer.tiltX, pointer.tiltY, pointer.distance, - pointer.toolType, toString(pointer.isHovering)); + "touchMajor=%d, touchMinor=%d, toolMajor=%d, toolMinor=%d, " + "orientation=%d, tiltX=%d, tiltY=%d, distance=%d, " + "toolType=%d, isHovering=%s\n", + i, pointer.id, pointer.x, pointer.y, pointer.pressure, + pointer.touchMajor, pointer.touchMinor, pointer.toolMajor, + pointer.toolMinor, pointer.orientation, pointer.tiltX, pointer.tiltY, + pointer.distance, pointer.toolType, toString(pointer.isHovering)); } - dump += StringPrintf(INDENT3 "Last Cooked Button State: 0x%08x\n", mLastCookedState.buttonState); + dump += StringPrintf(INDENT3 "Last Cooked Button State: 0x%08x\n", + mLastCookedState.buttonState); dump += StringPrintf(INDENT3 "Last Cooked Touch: pointerCount=%d\n", - mLastCookedState.cookedPointerData.pointerCount); + mLastCookedState.cookedPointerData.pointerCount); for (uint32_t i = 0; i < mLastCookedState.cookedPointerData.pointerCount; i++) { const PointerProperties& pointerProperties = mLastCookedState.cookedPointerData.pointerProperties[i]; const PointerCoords& pointerCoords = mLastCookedState.cookedPointerData.pointerCoords[i]; dump += StringPrintf(INDENT4 "[%d]: id=%d, x=%0.3f, y=%0.3f, pressure=%0.3f, " - "touchMajor=%0.3f, touchMinor=%0.3f, toolMajor=%0.3f, toolMinor=%0.3f, " - "orientation=%0.3f, tilt=%0.3f, distance=%0.3f, " - "toolType=%d, isHovering=%s\n", i, - pointerProperties.id, - pointerCoords.getX(), - pointerCoords.getY(), - pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), - pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), - pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), - pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), - pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), - pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION), - pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TILT), - pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_DISTANCE), - pointerProperties.toolType, - toString(mLastCookedState.cookedPointerData.isHovering(i))); + "touchMajor=%0.3f, touchMinor=%0.3f, toolMajor=%0.3f, " + "toolMinor=%0.3f, " + "orientation=%0.3f, tilt=%0.3f, distance=%0.3f, " + "toolType=%d, isHovering=%s\n", + i, pointerProperties.id, pointerCoords.getX(), pointerCoords.getY(), + pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), + pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), + pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), + pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), + pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), + pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION), + pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TILT), + pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_DISTANCE), + pointerProperties.toolType, + toString(mLastCookedState.cookedPointerData.isHovering(i))); } dump += INDENT3 "Stylus Fusion:\n"; dump += StringPrintf(INDENT4 "ExternalStylusConnected: %s\n", - toString(mExternalStylusConnected)); + toString(mExternalStylusConnected)); dump += StringPrintf(INDENT4 "External Stylus ID: %" PRId64 "\n", mExternalStylusId); dump += StringPrintf(INDENT4 "External Stylus Data Timeout: %" PRId64 "\n", - mExternalStylusFusionTimeout); + mExternalStylusFusionTimeout); dump += INDENT3 "External Stylus State:\n"; dumpStylusState(dump, mExternalStylusState); if (mDeviceMode == DEVICE_MODE_POINTER) { dump += StringPrintf(INDENT3 "Pointer Gesture Detector:\n"); - dump += StringPrintf(INDENT4 "XMovementScale: %0.3f\n", - mPointerXMovementScale); - dump += StringPrintf(INDENT4 "YMovementScale: %0.3f\n", - mPointerYMovementScale); - dump += StringPrintf(INDENT4 "XZoomScale: %0.3f\n", - mPointerXZoomScale); - dump += StringPrintf(INDENT4 "YZoomScale: %0.3f\n", - mPointerYZoomScale); - dump += StringPrintf(INDENT4 "MaxSwipeWidth: %f\n", - mPointerGestureMaxSwipeWidth); + dump += StringPrintf(INDENT4 "XMovementScale: %0.3f\n", mPointerXMovementScale); + dump += StringPrintf(INDENT4 "YMovementScale: %0.3f\n", mPointerYMovementScale); + dump += StringPrintf(INDENT4 "XZoomScale: %0.3f\n", mPointerXZoomScale); + dump += StringPrintf(INDENT4 "YZoomScale: %0.3f\n", mPointerYZoomScale); + dump += StringPrintf(INDENT4 "MaxSwipeWidth: %f\n", mPointerGestureMaxSwipeWidth); } } const char* TouchInputMapper::modeToString(DeviceMode deviceMode) { switch (deviceMode) { - case DEVICE_MODE_DISABLED: - return "disabled"; - case DEVICE_MODE_DIRECT: - return "direct"; - case DEVICE_MODE_UNSCALED: - return "unscaled"; - case DEVICE_MODE_NAVIGATION: - return "navigation"; - case DEVICE_MODE_POINTER: - return "pointer"; + case DEVICE_MODE_DISABLED: + return "disabled"; + case DEVICE_MODE_DIRECT: + return "direct"; + case DEVICE_MODE_UNSCALED: + return "unscaled"; + case DEVICE_MODE_NAVIGATION: + return "navigation"; + case DEVICE_MODE_POINTER: + return "pointer"; } return "unknown"; } -void TouchInputMapper::configure(nsecs_t when, - const InputReaderConfiguration* config, uint32_t changes) { +void TouchInputMapper::configure(nsecs_t when, const InputReaderConfiguration* config, + uint32_t changes) { InputMapper::configure(when, config, changes); mConfig = *config; @@ -3346,10 +3288,12 @@ void TouchInputMapper::configure(nsecs_t when, } bool resetNeeded = false; - if (!changes || (changes & (InputReaderConfiguration::CHANGE_DISPLAY_INFO - | InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT - | InputReaderConfiguration::CHANGE_SHOW_TOUCHES - | InputReaderConfiguration::CHANGE_EXTERNAL_STYLUS_PRESENCE))) { + if (!changes || + (changes & + (InputReaderConfiguration::CHANGE_DISPLAY_INFO | + InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT | + InputReaderConfiguration::CHANGE_SHOW_TOUCHES | + InputReaderConfiguration::CHANGE_EXTERNAL_STYLUS_PRESENCE))) { // Configure device sources, surface dimensions, orientation and // scaling factors. configureSurface(when, &resetNeeded); @@ -3377,11 +3321,12 @@ void TouchInputMapper::configureParameters() { // multitouch. The spot-based presentation relies on being able to accurately // locate two or more fingers on the touch pad. mParameters.gestureMode = getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_SEMI_MT) - ? Parameters::GESTURE_MODE_SINGLE_TOUCH : Parameters::GESTURE_MODE_MULTI_TOUCH; + ? Parameters::GESTURE_MODE_SINGLE_TOUCH + : Parameters::GESTURE_MODE_MULTI_TOUCH; String8 gestureModeString; if (getDevice()->getConfiguration().tryGetProperty(String8("touch.gestureMode"), - gestureModeString)) { + gestureModeString)) { if (gestureModeString == "single-touch") { mParameters.gestureMode = Parameters::GESTURE_MODE_SINGLE_TOUCH; } else if (gestureModeString == "multi-touch") { @@ -3397,8 +3342,8 @@ void TouchInputMapper::configureParameters() { } else if (getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_POINTER)) { // The device is a pointing device like a track pad. mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER; - } else if (getEventHub()->hasRelativeAxis(getDeviceId(), REL_X) - || getEventHub()->hasRelativeAxis(getDeviceId(), REL_Y)) { + } else if (getEventHub()->hasRelativeAxis(getDeviceId(), REL_X) || + getEventHub()->hasRelativeAxis(getDeviceId(), REL_Y)) { // The device is a cursor device with a touch pad attached. // By default don't use the touch pad to move the pointer. mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_PAD; @@ -3407,12 +3352,12 @@ void TouchInputMapper::configureParameters() { mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER; } - mParameters.hasButtonUnderPad= + mParameters.hasButtonUnderPad = getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_BUTTONPAD); String8 deviceTypeString; if (getDevice()->getConfiguration().tryGetProperty(String8("touch.deviceType"), - deviceTypeString)) { + deviceTypeString)) { if (deviceTypeString == "touchScreen") { mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_SCREEN; } else if (deviceTypeString == "touchPad") { @@ -3428,19 +3373,19 @@ void TouchInputMapper::configureParameters() { mParameters.orientationAware = mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN; getDevice()->getConfiguration().tryGetProperty(String8("touch.orientationAware"), - mParameters.orientationAware); + mParameters.orientationAware); mParameters.hasAssociatedDisplay = false; mParameters.associatedDisplayIsExternal = false; - if (mParameters.orientationAware - || mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN - || mParameters.deviceType == Parameters::DEVICE_TYPE_POINTER) { + if (mParameters.orientationAware || + mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN || + mParameters.deviceType == Parameters::DEVICE_TYPE_POINTER) { mParameters.hasAssociatedDisplay = true; if (mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN) { mParameters.associatedDisplayIsExternal = getDevice()->isExternal(); String8 uniqueDisplayId; getDevice()->getConfiguration().tryGetProperty(String8("touch.displayId"), - uniqueDisplayId); + uniqueDisplayId); mParameters.uniqueDisplayId = uniqueDisplayId.c_str(); } } @@ -3452,48 +3397,46 @@ void TouchInputMapper::configureParameters() { // Normally we don't do this for internal touch screens to prevent them from waking // up in your pocket but you can enable it using the input device configuration. mParameters.wake = getDevice()->isExternal(); - getDevice()->getConfiguration().tryGetProperty(String8("touch.wake"), - mParameters.wake); + getDevice()->getConfiguration().tryGetProperty(String8("touch.wake"), mParameters.wake); } void TouchInputMapper::dumpParameters(std::string& dump) { dump += INDENT3 "Parameters:\n"; switch (mParameters.gestureMode) { - case Parameters::GESTURE_MODE_SINGLE_TOUCH: - dump += INDENT4 "GestureMode: single-touch\n"; - break; - case Parameters::GESTURE_MODE_MULTI_TOUCH: - dump += INDENT4 "GestureMode: multi-touch\n"; - break; - default: - assert(false); + case Parameters::GESTURE_MODE_SINGLE_TOUCH: + dump += INDENT4 "GestureMode: single-touch\n"; + break; + case Parameters::GESTURE_MODE_MULTI_TOUCH: + dump += INDENT4 "GestureMode: multi-touch\n"; + break; + default: + assert(false); } switch (mParameters.deviceType) { - case Parameters::DEVICE_TYPE_TOUCH_SCREEN: - dump += INDENT4 "DeviceType: touchScreen\n"; - break; - case Parameters::DEVICE_TYPE_TOUCH_PAD: - dump += INDENT4 "DeviceType: touchPad\n"; - break; - case Parameters::DEVICE_TYPE_TOUCH_NAVIGATION: - dump += INDENT4 "DeviceType: touchNavigation\n"; - break; - case Parameters::DEVICE_TYPE_POINTER: - dump += INDENT4 "DeviceType: pointer\n"; - break; - default: - ALOG_ASSERT(false); - } - - dump += StringPrintf( - INDENT4 "AssociatedDisplay: hasAssociatedDisplay=%s, isExternal=%s, displayId='%s'\n", - toString(mParameters.hasAssociatedDisplay), - toString(mParameters.associatedDisplayIsExternal), - mParameters.uniqueDisplayId.c_str()); - dump += StringPrintf(INDENT4 "OrientationAware: %s\n", - toString(mParameters.orientationAware)); + case Parameters::DEVICE_TYPE_TOUCH_SCREEN: + dump += INDENT4 "DeviceType: touchScreen\n"; + break; + case Parameters::DEVICE_TYPE_TOUCH_PAD: + dump += INDENT4 "DeviceType: touchPad\n"; + break; + case Parameters::DEVICE_TYPE_TOUCH_NAVIGATION: + dump += INDENT4 "DeviceType: touchNavigation\n"; + break; + case Parameters::DEVICE_TYPE_POINTER: + dump += INDENT4 "DeviceType: pointer\n"; + break; + default: + ALOG_ASSERT(false); + } + + dump += StringPrintf(INDENT4 "AssociatedDisplay: hasAssociatedDisplay=%s, isExternal=%s, " + "displayId='%s'\n", + toString(mParameters.hasAssociatedDisplay), + toString(mParameters.associatedDisplayIsExternal), + mParameters.uniqueDisplayId.c_str()); + dump += StringPrintf(INDENT4 "OrientationAware: %s\n", toString(mParameters.orientationAware)); } void TouchInputMapper::configureRawPointerAxes() { @@ -3553,8 +3496,8 @@ std::optional<DisplayViewport> TouchInputMapper::findViewport() { mConfig.getDisplayViewportByType(viewportTypeToUse); if (!viewport && viewportTypeToUse == ViewportType::VIEWPORT_EXTERNAL) { ALOGW("Input device %s should be associated with external display, " - "fallback to internal one for the external viewport is not found.", - getDeviceName().c_str()); + "fallback to internal one for the external viewport is not found.", + getDeviceName().c_str()); viewport = mConfig.getDisplayViewportByType(ViewportType::VIEWPORT_INTERNAL); } @@ -3576,15 +3519,15 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { resolveExternalStylusPresence(); // Determine device mode. - if (mParameters.deviceType == Parameters::DEVICE_TYPE_POINTER - && mConfig.pointerGesturesEnabled) { + if (mParameters.deviceType == Parameters::DEVICE_TYPE_POINTER && + mConfig.pointerGesturesEnabled) { mSource = AINPUT_SOURCE_MOUSE; mDeviceMode = DEVICE_MODE_POINTER; if (hasStylus()) { mSource |= AINPUT_SOURCE_STYLUS; } - } else if (mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN - && mParameters.hasAssociatedDisplay) { + } else if (mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN && + mParameters.hasAssociatedDisplay) { mSource = AINPUT_SOURCE_TOUCHSCREEN; mDeviceMode = DEVICE_MODE_DIRECT; if (hasStylus()) { @@ -3604,7 +3547,8 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { // Ensure we have valid X and Y axes. if (!mRawPointerAxes.x.valid || !mRawPointerAxes.y.valid) { ALOGW("Touch device '%s' did not report support for X or Y axis! " - "The device will be inoperable.", getDeviceName().c_str()); + "The device will be inoperable.", + getDeviceName().c_str()); mDeviceMode = DEVICE_MODE_DISABLED; return; } @@ -3613,9 +3557,9 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { std::optional<DisplayViewport> newViewport = findViewport(); if (!newViewport) { ALOGI("Touch device '%s' could not query the properties of its associated " - "display. The device will be inoperable until the display size " - "becomes available.", - getDeviceName().c_str()); + "display. The device will be inoperable until the display size " + "becomes available.", + getDeviceName().c_str()); mDeviceMode = DEVICE_MODE_DISABLED; return; } @@ -3635,47 +3579,47 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { int32_t naturalPhysicalLeft, naturalPhysicalTop; int32_t naturalDeviceWidth, naturalDeviceHeight; switch (mViewport.orientation) { - case DISPLAY_ORIENTATION_90: - naturalLogicalWidth = mViewport.logicalBottom - mViewport.logicalTop; - naturalLogicalHeight = mViewport.logicalRight - mViewport.logicalLeft; - naturalPhysicalWidth = mViewport.physicalBottom - mViewport.physicalTop; - naturalPhysicalHeight = mViewport.physicalRight - mViewport.physicalLeft; - naturalPhysicalLeft = mViewport.deviceHeight - mViewport.physicalBottom; - naturalPhysicalTop = mViewport.physicalLeft; - naturalDeviceWidth = mViewport.deviceHeight; - naturalDeviceHeight = mViewport.deviceWidth; - break; - case DISPLAY_ORIENTATION_180: - naturalLogicalWidth = mViewport.logicalRight - mViewport.logicalLeft; - naturalLogicalHeight = mViewport.logicalBottom - mViewport.logicalTop; - naturalPhysicalWidth = mViewport.physicalRight - mViewport.physicalLeft; - naturalPhysicalHeight = mViewport.physicalBottom - mViewport.physicalTop; - naturalPhysicalLeft = mViewport.deviceWidth - mViewport.physicalRight; - naturalPhysicalTop = mViewport.deviceHeight - mViewport.physicalBottom; - naturalDeviceWidth = mViewport.deviceWidth; - naturalDeviceHeight = mViewport.deviceHeight; - break; - case DISPLAY_ORIENTATION_270: - naturalLogicalWidth = mViewport.logicalBottom - mViewport.logicalTop; - naturalLogicalHeight = mViewport.logicalRight - mViewport.logicalLeft; - naturalPhysicalWidth = mViewport.physicalBottom - mViewport.physicalTop; - naturalPhysicalHeight = mViewport.physicalRight - mViewport.physicalLeft; - naturalPhysicalLeft = mViewport.physicalTop; - naturalPhysicalTop = mViewport.deviceWidth - mViewport.physicalRight; - naturalDeviceWidth = mViewport.deviceHeight; - naturalDeviceHeight = mViewport.deviceWidth; - break; - case DISPLAY_ORIENTATION_0: - default: - naturalLogicalWidth = mViewport.logicalRight - mViewport.logicalLeft; - naturalLogicalHeight = mViewport.logicalBottom - mViewport.logicalTop; - naturalPhysicalWidth = mViewport.physicalRight - mViewport.physicalLeft; - naturalPhysicalHeight = mViewport.physicalBottom - mViewport.physicalTop; - naturalPhysicalLeft = mViewport.physicalLeft; - naturalPhysicalTop = mViewport.physicalTop; - naturalDeviceWidth = mViewport.deviceWidth; - naturalDeviceHeight = mViewport.deviceHeight; - break; + case DISPLAY_ORIENTATION_90: + naturalLogicalWidth = mViewport.logicalBottom - mViewport.logicalTop; + naturalLogicalHeight = mViewport.logicalRight - mViewport.logicalLeft; + naturalPhysicalWidth = mViewport.physicalBottom - mViewport.physicalTop; + naturalPhysicalHeight = mViewport.physicalRight - mViewport.physicalLeft; + naturalPhysicalLeft = mViewport.deviceHeight - mViewport.physicalBottom; + naturalPhysicalTop = mViewport.physicalLeft; + naturalDeviceWidth = mViewport.deviceHeight; + naturalDeviceHeight = mViewport.deviceWidth; + break; + case DISPLAY_ORIENTATION_180: + naturalLogicalWidth = mViewport.logicalRight - mViewport.logicalLeft; + naturalLogicalHeight = mViewport.logicalBottom - mViewport.logicalTop; + naturalPhysicalWidth = mViewport.physicalRight - mViewport.physicalLeft; + naturalPhysicalHeight = mViewport.physicalBottom - mViewport.physicalTop; + naturalPhysicalLeft = mViewport.deviceWidth - mViewport.physicalRight; + naturalPhysicalTop = mViewport.deviceHeight - mViewport.physicalBottom; + naturalDeviceWidth = mViewport.deviceWidth; + naturalDeviceHeight = mViewport.deviceHeight; + break; + case DISPLAY_ORIENTATION_270: + naturalLogicalWidth = mViewport.logicalBottom - mViewport.logicalTop; + naturalLogicalHeight = mViewport.logicalRight - mViewport.logicalLeft; + naturalPhysicalWidth = mViewport.physicalBottom - mViewport.physicalTop; + naturalPhysicalHeight = mViewport.physicalRight - mViewport.physicalLeft; + naturalPhysicalLeft = mViewport.physicalTop; + naturalPhysicalTop = mViewport.deviceWidth - mViewport.physicalRight; + naturalDeviceWidth = mViewport.deviceHeight; + naturalDeviceHeight = mViewport.deviceWidth; + break; + case DISPLAY_ORIENTATION_0: + default: + naturalLogicalWidth = mViewport.logicalRight - mViewport.logicalLeft; + naturalLogicalHeight = mViewport.logicalBottom - mViewport.logicalTop; + naturalPhysicalWidth = mViewport.physicalRight - mViewport.physicalLeft; + naturalPhysicalHeight = mViewport.physicalBottom - mViewport.physicalTop; + naturalPhysicalLeft = mViewport.physicalLeft; + naturalPhysicalTop = mViewport.physicalTop; + naturalDeviceWidth = mViewport.deviceWidth; + naturalDeviceHeight = mViewport.deviceHeight; + break; } if (naturalPhysicalHeight == 0 || naturalPhysicalWidth == 0) { @@ -3694,8 +3638,8 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { mSurfaceLeft = naturalPhysicalLeft * naturalLogicalWidth / naturalPhysicalWidth; mSurfaceTop = naturalPhysicalTop * naturalLogicalHeight / naturalPhysicalHeight; - mSurfaceOrientation = mParameters.orientationAware ? - mViewport.orientation : DISPLAY_ORIENTATION_0; + mSurfaceOrientation = + mParameters.orientationAware ? mViewport.orientation : DISPLAY_ORIENTATION_0; } else { mPhysicalWidth = rawWidth; mPhysicalHeight = rawHeight; @@ -3718,7 +3662,7 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { // Create or update pointer controller if needed. if (mDeviceMode == DEVICE_MODE_POINTER || - (mDeviceMode == DEVICE_MODE_DIRECT && mConfig.showTouches)) { + (mDeviceMode == DEVICE_MODE_DIRECT && mConfig.showTouches)) { if (mPointerController == nullptr || viewportChanged) { mPointerController = getPolicy()->obtainPointerController(getDeviceId()); } @@ -3728,9 +3672,9 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { if (viewportChanged || deviceModeChanged) { ALOGI("Device reconfigured: id=%d, name='%s', size %dx%d, orientation %d, mode %d, " - "display id %d", - getDeviceId(), getDeviceName().c_str(), mSurfaceWidth, mSurfaceHeight, - mSurfaceOrientation, mDeviceMode, mViewport.displayId); + "display id %d", + getDeviceId(), getDeviceName().c_str(), mSurfaceWidth, mSurfaceHeight, + mSurfaceOrientation, mDeviceMode, mViewport.displayId); // Configure X and Y factors. mXScale = float(mSurfaceWidth) / rawWidth; @@ -3757,11 +3701,9 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { // Size factors. if (mCalibration.sizeCalibration != Calibration::SIZE_CALIBRATION_NONE) { - if (mRawPointerAxes.touchMajor.valid - && mRawPointerAxes.touchMajor.maxValue != 0) { + if (mRawPointerAxes.touchMajor.valid && mRawPointerAxes.touchMajor.maxValue != 0) { mSizeScale = 1.0f / mRawPointerAxes.touchMajor.maxValue; - } else if (mRawPointerAxes.toolMajor.valid - && mRawPointerAxes.toolMajor.maxValue != 0) { + } else if (mRawPointerAxes.toolMajor.valid && mRawPointerAxes.toolMajor.maxValue != 0) { mSizeScale = 1.0f / mRawPointerAxes.toolMajor.maxValue; } else { mSizeScale = 0.0f; @@ -3807,14 +3749,12 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { // Pressure factors. mPressureScale = 0; float pressureMax = 1.0; - if (mCalibration.pressureCalibration == Calibration::PRESSURE_CALIBRATION_PHYSICAL - || mCalibration.pressureCalibration - == Calibration::PRESSURE_CALIBRATION_AMPLITUDE) { + if (mCalibration.pressureCalibration == Calibration::PRESSURE_CALIBRATION_PHYSICAL || + mCalibration.pressureCalibration == Calibration::PRESSURE_CALIBRATION_AMPLITUDE) { if (mCalibration.havePressureScale) { mPressureScale = mCalibration.pressureScale; pressureMax = mPressureScale * mRawPointerAxes.pressure.maxValue; - } else if (mRawPointerAxes.pressure.valid - && mRawPointerAxes.pressure.maxValue != 0) { + } else if (mRawPointerAxes.pressure.valid && mRawPointerAxes.pressure.maxValue != 0) { mPressureScale = 1.0f / mRawPointerAxes.pressure.maxValue; } } @@ -3834,10 +3774,8 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { mTiltYScale = 0; mHaveTilt = mRawPointerAxes.tiltX.valid && mRawPointerAxes.tiltY.valid; if (mHaveTilt) { - mTiltXCenter = avg(mRawPointerAxes.tiltX.minValue, - mRawPointerAxes.tiltX.maxValue); - mTiltYCenter = avg(mRawPointerAxes.tiltY.minValue, - mRawPointerAxes.tiltY.maxValue); + mTiltXCenter = avg(mRawPointerAxes.tiltX.minValue, mRawPointerAxes.tiltX.maxValue); + mTiltYCenter = avg(mRawPointerAxes.tiltY.minValue, mRawPointerAxes.tiltY.maxValue); mTiltXScale = M_PI / 180; mTiltYScale = M_PI / 180; @@ -3865,9 +3803,9 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { mOrientedRanges.orientation.fuzz = 0; mOrientedRanges.orientation.resolution = 0; } else if (mCalibration.orientationCalibration != - Calibration::ORIENTATION_CALIBRATION_NONE) { - if (mCalibration.orientationCalibration - == Calibration::ORIENTATION_CALIBRATION_INTERPOLATED) { + Calibration::ORIENTATION_CALIBRATION_NONE) { + if (mCalibration.orientationCalibration == + Calibration::ORIENTATION_CALIBRATION_INTERPOLATED) { if (mRawPointerAxes.orientation.valid) { if (mRawPointerAxes.orientation.maxValue > 0) { mOrientationScale = M_PI_2 / mRawPointerAxes.orientation.maxValue; @@ -3893,8 +3831,7 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { // Distance mDistanceScale = 0; if (mCalibration.distanceCalibration != Calibration::DISTANCE_CALIBRATION_NONE) { - if (mCalibration.distanceCalibration - == Calibration::DISTANCE_CALIBRATION_SCALED) { + if (mCalibration.distanceCalibration == Calibration::DISTANCE_CALIBRATION_SCALED) { if (mCalibration.haveDistanceScale) { mDistanceScale = mCalibration.distanceScale; } else { @@ -3906,13 +3843,10 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { mOrientedRanges.distance.axis = AMOTION_EVENT_AXIS_DISTANCE; mOrientedRanges.distance.source = mSource; - mOrientedRanges.distance.min = - mRawPointerAxes.distance.minValue * mDistanceScale; - mOrientedRanges.distance.max = - mRawPointerAxes.distance.maxValue * mDistanceScale; + mOrientedRanges.distance.min = mRawPointerAxes.distance.minValue * mDistanceScale; + mOrientedRanges.distance.max = mRawPointerAxes.distance.maxValue * mDistanceScale; mOrientedRanges.distance.flat = 0; - mOrientedRanges.distance.fuzz = - mRawPointerAxes.distance.fuzz * mDistanceScale; + mOrientedRanges.distance.fuzz = mRawPointerAxes.distance.fuzz * mDistanceScale; mOrientedRanges.distance.resolution = 0; } @@ -3920,40 +3854,40 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { // Note that the maximum value reported is an inclusive maximum value so it is one // unit less than the total width or height of surface. switch (mSurfaceOrientation) { - case DISPLAY_ORIENTATION_90: - case DISPLAY_ORIENTATION_270: - mOrientedXPrecision = mYPrecision; - mOrientedYPrecision = mXPrecision; - - mOrientedRanges.x.min = mYTranslate; - mOrientedRanges.x.max = mSurfaceHeight + mYTranslate - 1; - mOrientedRanges.x.flat = 0; - mOrientedRanges.x.fuzz = 0; - mOrientedRanges.x.resolution = mRawPointerAxes.y.resolution * mYScale; - - mOrientedRanges.y.min = mXTranslate; - mOrientedRanges.y.max = mSurfaceWidth + mXTranslate - 1; - mOrientedRanges.y.flat = 0; - mOrientedRanges.y.fuzz = 0; - mOrientedRanges.y.resolution = mRawPointerAxes.x.resolution * mXScale; - break; + case DISPLAY_ORIENTATION_90: + case DISPLAY_ORIENTATION_270: + mOrientedXPrecision = mYPrecision; + mOrientedYPrecision = mXPrecision; + + mOrientedRanges.x.min = mYTranslate; + mOrientedRanges.x.max = mSurfaceHeight + mYTranslate - 1; + mOrientedRanges.x.flat = 0; + mOrientedRanges.x.fuzz = 0; + mOrientedRanges.x.resolution = mRawPointerAxes.y.resolution * mYScale; + + mOrientedRanges.y.min = mXTranslate; + mOrientedRanges.y.max = mSurfaceWidth + mXTranslate - 1; + mOrientedRanges.y.flat = 0; + mOrientedRanges.y.fuzz = 0; + mOrientedRanges.y.resolution = mRawPointerAxes.x.resolution * mXScale; + break; - default: - mOrientedXPrecision = mXPrecision; - mOrientedYPrecision = mYPrecision; - - mOrientedRanges.x.min = mXTranslate; - mOrientedRanges.x.max = mSurfaceWidth + mXTranslate - 1; - mOrientedRanges.x.flat = 0; - mOrientedRanges.x.fuzz = 0; - mOrientedRanges.x.resolution = mRawPointerAxes.x.resolution * mXScale; - - mOrientedRanges.y.min = mYTranslate; - mOrientedRanges.y.max = mSurfaceHeight + mYTranslate - 1; - mOrientedRanges.y.flat = 0; - mOrientedRanges.y.fuzz = 0; - mOrientedRanges.y.resolution = mRawPointerAxes.y.resolution * mYScale; - break; + default: + mOrientedXPrecision = mXPrecision; + mOrientedYPrecision = mYPrecision; + + mOrientedRanges.x.min = mXTranslate; + mOrientedRanges.x.max = mSurfaceWidth + mXTranslate - 1; + mOrientedRanges.x.flat = 0; + mOrientedRanges.x.fuzz = 0; + mOrientedRanges.x.resolution = mRawPointerAxes.x.resolution * mXScale; + + mOrientedRanges.y.min = mYTranslate; + mOrientedRanges.y.max = mSurfaceHeight + mYTranslate - 1; + mOrientedRanges.y.flat = 0; + mOrientedRanges.y.fuzz = 0; + mOrientedRanges.y.resolution = mRawPointerAxes.y.resolution * mYScale; + break; } // Location @@ -3969,22 +3903,21 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { // is applied. // Assume that the touch pad has a square aspect ratio such that movements in // X and Y of the same number of raw units cover the same physical distance. - mPointerXMovementScale = mConfig.pointerGestureMovementSpeedRatio - * displayDiagonal / rawDiagonal; + mPointerXMovementScale = + mConfig.pointerGestureMovementSpeedRatio * displayDiagonal / rawDiagonal; mPointerYMovementScale = mPointerXMovementScale; // Scale zooms to cover a smaller range of the display than movements do. // This value determines the area around the pointer that is affected by freeform // pointer gestures. - mPointerXZoomScale = mConfig.pointerGestureZoomSpeedRatio - * displayDiagonal / rawDiagonal; + mPointerXZoomScale = + mConfig.pointerGestureZoomSpeedRatio * displayDiagonal / rawDiagonal; mPointerYZoomScale = mPointerXZoomScale; // Max width between pointers to detect a swipe gesture is more than some fraction // of the diagonal axis of the touch pad. Touches that are wider than this are // translated into freeform gestures. - mPointerGestureMaxSwipeWidth = - mConfig.pointerGestureSwipeMaxWidthRatio * rawDiagonal; + mPointerGestureMaxSwipeWidth = mConfig.pointerGestureSwipeMaxWidthRatio * rawDiagonal; // Abort current pointer usages because the state has changed. abortPointerUsage(when, 0 /*policyFlags*/); @@ -4031,10 +3964,9 @@ void TouchInputMapper::configureVirtualKeys() { int32_t keyCode; int32_t dummyKeyMetaState; uint32_t flags; - if (getEventHub()->mapKey(getDeviceId(), virtualKey.scanCode, 0, 0, - &keyCode, &dummyKeyMetaState, &flags)) { - ALOGW(INDENT "VirtualKey %d: could not obtain key code, ignoring", - virtualKey.scanCode); + if (getEventHub()->mapKey(getDeviceId(), virtualKey.scanCode, 0, 0, &keyCode, + &dummyKeyMetaState, &flags)) { + ALOGW(INDENT "VirtualKey %d: could not obtain key code, ignoring", virtualKey.scanCode); continue; // drop the key } @@ -4045,14 +3977,18 @@ void TouchInputMapper::configureVirtualKeys() { int32_t halfWidth = virtualKeyDefinition.width / 2; int32_t halfHeight = virtualKeyDefinition.height / 2; - virtualKey.hitLeft = (virtualKeyDefinition.centerX - halfWidth) - * touchScreenWidth / mSurfaceWidth + touchScreenLeft; - virtualKey.hitRight= (virtualKeyDefinition.centerX + halfWidth) - * touchScreenWidth / mSurfaceWidth + touchScreenLeft; - virtualKey.hitTop = (virtualKeyDefinition.centerY - halfHeight) - * touchScreenHeight / mSurfaceHeight + touchScreenTop; - virtualKey.hitBottom = (virtualKeyDefinition.centerY + halfHeight) - * touchScreenHeight / mSurfaceHeight + touchScreenTop; + virtualKey.hitLeft = + (virtualKeyDefinition.centerX - halfWidth) * touchScreenWidth / mSurfaceWidth + + touchScreenLeft; + virtualKey.hitRight = + (virtualKeyDefinition.centerX + halfWidth) * touchScreenWidth / mSurfaceWidth + + touchScreenLeft; + virtualKey.hitTop = + (virtualKeyDefinition.centerY - halfHeight) * touchScreenHeight / mSurfaceHeight + + touchScreenTop; + virtualKey.hitBottom = + (virtualKeyDefinition.centerY + halfHeight) * touchScreenHeight / mSurfaceHeight + + touchScreenTop; mVirtualKeys.push_back(virtualKey); } } @@ -4064,10 +4000,9 @@ void TouchInputMapper::dumpVirtualKeys(std::string& dump) { for (size_t i = 0; i < mVirtualKeys.size(); i++) { const VirtualKey& virtualKey = mVirtualKeys[i]; dump += StringPrintf(INDENT4 "%zu: scanCode=%d, keyCode=%d, " - "hitLeft=%d, hitRight=%d, hitTop=%d, hitBottom=%d\n", - i, virtualKey.scanCode, virtualKey.keyCode, - virtualKey.hitLeft, virtualKey.hitRight, - virtualKey.hitTop, virtualKey.hitBottom); + "hitLeft=%d, hitRight=%d, hitTop=%d, hitBottom=%d\n", + i, virtualKey.scanCode, virtualKey.keyCode, virtualKey.hitLeft, + virtualKey.hitRight, virtualKey.hitTop, virtualKey.hitBottom); } } } @@ -4091,17 +4026,13 @@ void TouchInputMapper::parseCalibration() { } else if (sizeCalibrationString == "area") { out.sizeCalibration = Calibration::SIZE_CALIBRATION_AREA; } else if (sizeCalibrationString != "default") { - ALOGW("Invalid value for touch.size.calibration: '%s'", - sizeCalibrationString.string()); + ALOGW("Invalid value for touch.size.calibration: '%s'", sizeCalibrationString.string()); } } - out.haveSizeScale = in.tryGetProperty(String8("touch.size.scale"), - out.sizeScale); - out.haveSizeBias = in.tryGetProperty(String8("touch.size.bias"), - out.sizeBias); - out.haveSizeIsSummed = in.tryGetProperty(String8("touch.size.isSummed"), - out.sizeIsSummed); + out.haveSizeScale = in.tryGetProperty(String8("touch.size.scale"), out.sizeScale); + out.haveSizeBias = in.tryGetProperty(String8("touch.size.bias"), out.sizeBias); + out.haveSizeIsSummed = in.tryGetProperty(String8("touch.size.isSummed"), out.sizeIsSummed); // Pressure out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_DEFAULT; @@ -4115,12 +4046,11 @@ void TouchInputMapper::parseCalibration() { out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_AMPLITUDE; } else if (pressureCalibrationString != "default") { ALOGW("Invalid value for touch.pressure.calibration: '%s'", - pressureCalibrationString.string()); + pressureCalibrationString.string()); } } - out.havePressureScale = in.tryGetProperty(String8("touch.pressure.scale"), - out.pressureScale); + out.havePressureScale = in.tryGetProperty(String8("touch.pressure.scale"), out.pressureScale); // Orientation out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_DEFAULT; @@ -4134,7 +4064,7 @@ void TouchInputMapper::parseCalibration() { out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_VECTOR; } else if (orientationCalibrationString != "default") { ALOGW("Invalid value for touch.orientation.calibration: '%s'", - orientationCalibrationString.string()); + orientationCalibrationString.string()); } } @@ -4148,12 +4078,11 @@ void TouchInputMapper::parseCalibration() { out.distanceCalibration = Calibration::DISTANCE_CALIBRATION_SCALED; } else if (distanceCalibrationString != "default") { ALOGW("Invalid value for touch.distance.calibration: '%s'", - distanceCalibrationString.string()); + distanceCalibrationString.string()); } } - out.haveDistanceScale = in.tryGetProperty(String8("touch.distance.scale"), - out.distanceScale); + out.haveDistanceScale = in.tryGetProperty(String8("touch.distance.scale"), out.distanceScale); out.coverageCalibration = Calibration::COVERAGE_CALIBRATION_DEFAULT; String8 coverageCalibrationString; @@ -4164,7 +4093,7 @@ void TouchInputMapper::parseCalibration() { out.coverageCalibration = Calibration::COVERAGE_CALIBRATION_BOX; } else if (coverageCalibrationString != "default") { ALOGW("Invalid value for touch.coverage.calibration: '%s'", - coverageCalibrationString.string()); + coverageCalibrationString.string()); } } } @@ -4217,101 +4146,97 @@ void TouchInputMapper::dumpCalibration(std::string& dump) { // Size switch (mCalibration.sizeCalibration) { - case Calibration::SIZE_CALIBRATION_NONE: - dump += INDENT4 "touch.size.calibration: none\n"; - break; - case Calibration::SIZE_CALIBRATION_GEOMETRIC: - dump += INDENT4 "touch.size.calibration: geometric\n"; - break; - case Calibration::SIZE_CALIBRATION_DIAMETER: - dump += INDENT4 "touch.size.calibration: diameter\n"; - break; - case Calibration::SIZE_CALIBRATION_BOX: - dump += INDENT4 "touch.size.calibration: box\n"; - break; - case Calibration::SIZE_CALIBRATION_AREA: - dump += INDENT4 "touch.size.calibration: area\n"; - break; - default: - ALOG_ASSERT(false); + case Calibration::SIZE_CALIBRATION_NONE: + dump += INDENT4 "touch.size.calibration: none\n"; + break; + case Calibration::SIZE_CALIBRATION_GEOMETRIC: + dump += INDENT4 "touch.size.calibration: geometric\n"; + break; + case Calibration::SIZE_CALIBRATION_DIAMETER: + dump += INDENT4 "touch.size.calibration: diameter\n"; + break; + case Calibration::SIZE_CALIBRATION_BOX: + dump += INDENT4 "touch.size.calibration: box\n"; + break; + case Calibration::SIZE_CALIBRATION_AREA: + dump += INDENT4 "touch.size.calibration: area\n"; + break; + default: + ALOG_ASSERT(false); } if (mCalibration.haveSizeScale) { - dump += StringPrintf(INDENT4 "touch.size.scale: %0.3f\n", - mCalibration.sizeScale); + dump += StringPrintf(INDENT4 "touch.size.scale: %0.3f\n", mCalibration.sizeScale); } if (mCalibration.haveSizeBias) { - dump += StringPrintf(INDENT4 "touch.size.bias: %0.3f\n", - mCalibration.sizeBias); + dump += StringPrintf(INDENT4 "touch.size.bias: %0.3f\n", mCalibration.sizeBias); } if (mCalibration.haveSizeIsSummed) { dump += StringPrintf(INDENT4 "touch.size.isSummed: %s\n", - toString(mCalibration.sizeIsSummed)); + toString(mCalibration.sizeIsSummed)); } // Pressure switch (mCalibration.pressureCalibration) { - case Calibration::PRESSURE_CALIBRATION_NONE: - dump += INDENT4 "touch.pressure.calibration: none\n"; - break; - case Calibration::PRESSURE_CALIBRATION_PHYSICAL: - dump += INDENT4 "touch.pressure.calibration: physical\n"; - break; - case Calibration::PRESSURE_CALIBRATION_AMPLITUDE: - dump += INDENT4 "touch.pressure.calibration: amplitude\n"; - break; - default: - ALOG_ASSERT(false); + case Calibration::PRESSURE_CALIBRATION_NONE: + dump += INDENT4 "touch.pressure.calibration: none\n"; + break; + case Calibration::PRESSURE_CALIBRATION_PHYSICAL: + dump += INDENT4 "touch.pressure.calibration: physical\n"; + break; + case Calibration::PRESSURE_CALIBRATION_AMPLITUDE: + dump += INDENT4 "touch.pressure.calibration: amplitude\n"; + break; + default: + ALOG_ASSERT(false); } if (mCalibration.havePressureScale) { - dump += StringPrintf(INDENT4 "touch.pressure.scale: %0.3f\n", - mCalibration.pressureScale); + dump += StringPrintf(INDENT4 "touch.pressure.scale: %0.3f\n", mCalibration.pressureScale); } // Orientation switch (mCalibration.orientationCalibration) { - case Calibration::ORIENTATION_CALIBRATION_NONE: - dump += INDENT4 "touch.orientation.calibration: none\n"; - break; - case Calibration::ORIENTATION_CALIBRATION_INTERPOLATED: - dump += INDENT4 "touch.orientation.calibration: interpolated\n"; - break; - case Calibration::ORIENTATION_CALIBRATION_VECTOR: - dump += INDENT4 "touch.orientation.calibration: vector\n"; - break; - default: - ALOG_ASSERT(false); + case Calibration::ORIENTATION_CALIBRATION_NONE: + dump += INDENT4 "touch.orientation.calibration: none\n"; + break; + case Calibration::ORIENTATION_CALIBRATION_INTERPOLATED: + dump += INDENT4 "touch.orientation.calibration: interpolated\n"; + break; + case Calibration::ORIENTATION_CALIBRATION_VECTOR: + dump += INDENT4 "touch.orientation.calibration: vector\n"; + break; + default: + ALOG_ASSERT(false); } // Distance switch (mCalibration.distanceCalibration) { - case Calibration::DISTANCE_CALIBRATION_NONE: - dump += INDENT4 "touch.distance.calibration: none\n"; - break; - case Calibration::DISTANCE_CALIBRATION_SCALED: - dump += INDENT4 "touch.distance.calibration: scaled\n"; - break; - default: - ALOG_ASSERT(false); + case Calibration::DISTANCE_CALIBRATION_NONE: + dump += INDENT4 "touch.distance.calibration: none\n"; + break; + case Calibration::DISTANCE_CALIBRATION_SCALED: + dump += INDENT4 "touch.distance.calibration: scaled\n"; + break; + default: + ALOG_ASSERT(false); } if (mCalibration.haveDistanceScale) { - dump += StringPrintf(INDENT4 "touch.distance.scale: %0.3f\n", - mCalibration.distanceScale); + dump += StringPrintf(INDENT4 "touch.distance.scale: %0.3f\n", mCalibration.distanceScale); } switch (mCalibration.coverageCalibration) { - case Calibration::COVERAGE_CALIBRATION_NONE: - dump += INDENT4 "touch.coverage.calibration: none\n"; - break; - case Calibration::COVERAGE_CALIBRATION_BOX: - dump += INDENT4 "touch.coverage.calibration: box\n"; - break; - default: - ALOG_ASSERT(false); + case Calibration::COVERAGE_CALIBRATION_NONE: + dump += INDENT4 "touch.coverage.calibration: none\n"; + break; + case Calibration::COVERAGE_CALIBRATION_BOX: + dump += INDENT4 "touch.coverage.calibration: box\n"; + break; + default: + ALOG_ASSERT(false); } } @@ -4328,7 +4253,7 @@ void TouchInputMapper::dumpAffineTransformation(std::string& dump) { void TouchInputMapper::updateAffineTransformation() { mAffineTransform = getPolicy()->getTouchAffineTransformation(mDevice->getDescriptor(), - mSurfaceOrientation); + mSurfaceOrientation); } void TouchInputMapper::reset(nsecs_t when) { @@ -4388,8 +4313,8 @@ void TouchInputMapper::process(const RawEvent* rawEvent) { } void TouchInputMapper::sync(nsecs_t when) { - const RawState* last = mRawStatesPending.empty() ? - &mCurrentRawState : &mRawStatesPending.back(); + const RawState* last = + mRawStatesPending.empty() ? &mCurrentRawState : &mRawStatesPending.back(); // Push a new state. mRawStatesPending.emplace_back(); @@ -4399,8 +4324,8 @@ void TouchInputMapper::sync(nsecs_t when) { next->when = when; // Sync button state. - next->buttonState = mTouchButtonAccumulator.getButtonState() - | mCursorButtonAccumulator.getButtonState(); + next->buttonState = + mTouchButtonAccumulator.getButtonState() | mCursorButtonAccumulator.getButtonState(); // Sync scroll next->rawVScroll = mCursorScrollAccumulator.getRelativeVWheel(); @@ -4417,13 +4342,10 @@ void TouchInputMapper::sync(nsecs_t when) { #if DEBUG_RAW_EVENTS ALOGD("syncTouch: pointerCount %d -> %d, touching ids 0x%08x -> 0x%08x, " - "hovering ids 0x%08x -> 0x%08x", - last->rawPointerData.pointerCount, - next->rawPointerData.pointerCount, - last->rawPointerData.touchingIdBits.value, - next->rawPointerData.touchingIdBits.value, - last->rawPointerData.hoveringIdBits.value, - next->rawPointerData.hoveringIdBits.value); + "hovering ids 0x%08x -> 0x%08x", + last->rawPointerData.pointerCount, next->rawPointerData.pointerCount, + last->rawPointerData.touchingIdBits.value, next->rawPointerData.touchingIdBits.value, + last->rawPointerData.hoveringIdBits.value, next->rawPointerData.hoveringIdBits.value); #endif processRawTouches(false /*timeout*/); @@ -4443,7 +4365,7 @@ void TouchInputMapper::processRawTouches(bool timeout) { // rest of the pipeline. const size_t N = mRawStatesPending.size(); size_t count; - for(count = 0; count < N; count++) { + for (count = 0; count < N; count++) { const RawState& next = mRawStatesPending[count]; // A failure to assign the stylus id means that we're waiting on stylus data @@ -4488,8 +4410,8 @@ void TouchInputMapper::cookAndDispatch(nsecs_t when) { applyExternalStylusButtonState(when); // Handle policy on initial down or hover events. - bool initialDown = mLastRawState.rawPointerData.pointerCount == 0 - && mCurrentRawState.rawPointerData.pointerCount != 0; + bool initialDown = mLastRawState.rawPointerData.pointerCount == 0 && + mCurrentRawState.rawPointerData.pointerCount != 0; uint32_t policyFlags = 0; bool buttonsPressed = mCurrentRawState.buttonState & ~mLastRawState.buttonState; @@ -4520,33 +4442,31 @@ void TouchInputMapper::cookAndDispatch(nsecs_t when) { // Synthesize key down from raw buttons if needed. synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_DOWN, when, getDeviceId(), mSource, - mViewport.displayId, policyFlags, - mLastCookedState.buttonState, mCurrentCookedState.buttonState); + mViewport.displayId, policyFlags, mLastCookedState.buttonState, + mCurrentCookedState.buttonState); // Dispatch the touches either directly or by translation through a pointer on screen. if (mDeviceMode == DEVICE_MODE_POINTER) { - for (BitSet32 idBits(mCurrentRawState.rawPointerData.touchingIdBits); - !idBits.isEmpty(); ) { + for (BitSet32 idBits(mCurrentRawState.rawPointerData.touchingIdBits); !idBits.isEmpty();) { uint32_t id = idBits.clearFirstMarkedBit(); const RawPointerData::Pointer& pointer = mCurrentRawState.rawPointerData.pointerForId(id); - if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS - || pointer.toolType == AMOTION_EVENT_TOOL_TYPE_ERASER) { + if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || + pointer.toolType == AMOTION_EVENT_TOOL_TYPE_ERASER) { mCurrentCookedState.stylusIdBits.markBit(id); - } else if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_FINGER - || pointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { + } else if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_FINGER || + pointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { mCurrentCookedState.fingerIdBits.markBit(id); } else if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_MOUSE) { mCurrentCookedState.mouseIdBits.markBit(id); } } - for (BitSet32 idBits(mCurrentRawState.rawPointerData.hoveringIdBits); - !idBits.isEmpty(); ) { + for (BitSet32 idBits(mCurrentRawState.rawPointerData.hoveringIdBits); !idBits.isEmpty();) { uint32_t id = idBits.clearFirstMarkedBit(); const RawPointerData::Pointer& pointer = mCurrentRawState.rawPointerData.pointerForId(id); - if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS - || pointer.toolType == AMOTION_EVENT_TOOL_TYPE_ERASER) { + if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || + pointer.toolType == AMOTION_EVENT_TOOL_TYPE_ERASER) { mCurrentCookedState.stylusIdBits.markBit(id); } } @@ -4561,22 +4481,22 @@ void TouchInputMapper::cookAndDispatch(nsecs_t when) { mCurrentCookedState.fingerIdBits.clear(); pointerUsage = POINTER_USAGE_MOUSE; } else if (!mCurrentCookedState.fingerIdBits.isEmpty() || - isPointerDown(mCurrentRawState.buttonState)) { + isPointerDown(mCurrentRawState.buttonState)) { pointerUsage = POINTER_USAGE_GESTURES; } dispatchPointerUsage(when, policyFlags, pointerUsage); } else { - if (mDeviceMode == DEVICE_MODE_DIRECT - && mConfig.showTouches && mPointerController != nullptr) { + if (mDeviceMode == DEVICE_MODE_DIRECT && mConfig.showTouches && + mPointerController != nullptr) { mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_SPOT); mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL); mPointerController->setButtonState(mCurrentRawState.buttonState); mPointerController->setSpots(mCurrentCookedState.cookedPointerData.pointerCoords, - mCurrentCookedState.cookedPointerData.idToIndex, - mCurrentCookedState.cookedPointerData.touchingIdBits, - mViewport.displayId); + mCurrentCookedState.cookedPointerData.idToIndex, + mCurrentCookedState.cookedPointerData.touchingIdBits, + mViewport.displayId); } if (!mCurrentMotionAborted) { @@ -4594,8 +4514,8 @@ void TouchInputMapper::cookAndDispatch(nsecs_t when) { // Synthesize key up from raw buttons if needed. synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_UP, when, getDeviceId(), mSource, - mViewport.displayId, policyFlags, - mLastCookedState.buttonState, mCurrentCookedState.buttonState); + mViewport.displayId, policyFlags, mLastCookedState.buttonState, + mCurrentCookedState.buttonState); // Clear some transient state. mCurrentRawState.rawVScroll = 0; @@ -4638,8 +4558,8 @@ bool TouchInputMapper::assignExternalStylusId(const RawState& state, bool timeou return false; } - const bool initialDown = mLastRawState.rawPointerData.pointerCount == 0 - && state.rawPointerData.pointerCount != 0; + const bool initialDown = mLastRawState.rawPointerData.pointerCount == 0 && + state.rawPointerData.pointerCount != 0; if (initialDown) { if (mExternalStylusState.pressure != 0.0f) { #if DEBUG_STYLUS_FUSION @@ -4657,7 +4577,8 @@ bool TouchInputMapper::assignExternalStylusId(const RawState& state, bool timeou } #if DEBUG_STYLUS_FUSION ALOGD("No stylus data but stylus is connected, requesting timeout " - "(%" PRId64 "ms)", mExternalStylusFusionTimeout); + "(%" PRId64 "ms)", + mExternalStylusFusionTimeout); #endif getContext()->requestTimeoutAtTime(mExternalStylusFusionTimeout); return true; @@ -4665,10 +4586,9 @@ bool TouchInputMapper::assignExternalStylusId(const RawState& state, bool timeou } // Check if the stylus pointer has gone up. - if (mExternalStylusId != -1 && - !state.rawPointerData.touchingIdBits.hasBit(mExternalStylusId)) { + if (mExternalStylusId != -1 && !state.rawPointerData.touchingIdBits.hasBit(mExternalStylusId)) { #if DEBUG_STYLUS_FUSION - ALOGD("Stylus pointer is going up"); + ALOGD("Stylus pointer is going up"); #endif mExternalStylusId = -1; } @@ -4710,11 +4630,10 @@ bool TouchInputMapper::consumeRawTouches(nsecs_t when, uint32_t policyFlags) { if (!mCurrentVirtualKey.ignored) { #if DEBUG_VIRTUAL_KEYS ALOGD("VirtualKeys: Generating key up: keyCode=%d, scanCode=%d", - mCurrentVirtualKey.keyCode, mCurrentVirtualKey.scanCode); + mCurrentVirtualKey.keyCode, mCurrentVirtualKey.scanCode); #endif - dispatchVirtualKey(when, policyFlags, - AKEY_EVENT_ACTION_UP, - AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY); + dispatchVirtualKey(when, policyFlags, AKEY_EVENT_ACTION_UP, + AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY); } return true; } @@ -4737,18 +4656,17 @@ bool TouchInputMapper::consumeRawTouches(nsecs_t when, uint32_t policyFlags) { mCurrentVirtualKey.down = false; if (!mCurrentVirtualKey.ignored) { #if DEBUG_VIRTUAL_KEYS - ALOGD("VirtualKeys: Canceling key: keyCode=%d, scanCode=%d", - mCurrentVirtualKey.keyCode, mCurrentVirtualKey.scanCode); + ALOGD("VirtualKeys: Canceling key: keyCode=%d, scanCode=%d", mCurrentVirtualKey.keyCode, + mCurrentVirtualKey.scanCode); #endif - dispatchVirtualKey(when, policyFlags, - AKEY_EVENT_ACTION_UP, - AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY - | AKEY_EVENT_FLAG_CANCELED); + dispatchVirtualKey(when, policyFlags, AKEY_EVENT_ACTION_UP, + AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY | + AKEY_EVENT_FLAG_CANCELED); } } - if (mLastRawState.rawPointerData.touchingIdBits.isEmpty() - && !mCurrentRawState.rawPointerData.touchingIdBits.isEmpty()) { + if (mLastRawState.rawPointerData.touchingIdBits.isEmpty() && + !mCurrentRawState.rawPointerData.touchingIdBits.isEmpty()) { // Pointer just went down. Check for virtual key press or off-screen touches. uint32_t id = mCurrentRawState.rawPointerData.touchingIdBits.firstMarkedBit(); const RawPointerData::Pointer& pointer = mCurrentRawState.rawPointerData.pointerForId(id); @@ -4762,18 +4680,18 @@ bool TouchInputMapper::consumeRawTouches(nsecs_t when, uint32_t policyFlags) { mCurrentVirtualKey.downTime = when; mCurrentVirtualKey.keyCode = virtualKey->keyCode; mCurrentVirtualKey.scanCode = virtualKey->scanCode; - mCurrentVirtualKey.ignored = mContext->shouldDropVirtualKey( - when, getDevice(), virtualKey->keyCode, virtualKey->scanCode); + mCurrentVirtualKey.ignored = + mContext->shouldDropVirtualKey(when, getDevice(), virtualKey->keyCode, + virtualKey->scanCode); if (!mCurrentVirtualKey.ignored) { #if DEBUG_VIRTUAL_KEYS ALOGD("VirtualKeys: Generating key down: keyCode=%d, scanCode=%d", - mCurrentVirtualKey.keyCode, - mCurrentVirtualKey.scanCode); + mCurrentVirtualKey.keyCode, mCurrentVirtualKey.scanCode); #endif - dispatchVirtualKey(when, policyFlags, - AKEY_EVENT_ACTION_DOWN, - AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY); + dispatchVirtualKey(when, policyFlags, AKEY_EVENT_ACTION_DOWN, + AKEY_EVENT_FLAG_FROM_SYSTEM | + AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY); } } } @@ -4796,14 +4714,14 @@ bool TouchInputMapper::consumeRawTouches(nsecs_t when, uint32_t policyFlags) { // are layed out below the screen near to where the on screen keyboard's space bar // is displayed. if (mConfig.virtualKeyQuietTime > 0 && - !mCurrentRawState.rawPointerData.touchingIdBits.isEmpty()) { + !mCurrentRawState.rawPointerData.touchingIdBits.isEmpty()) { mContext->disableVirtualKeysUntil(when + mConfig.virtualKeyQuietTime); } return false; } void TouchInputMapper::dispatchVirtualKey(nsecs_t when, uint32_t policyFlags, - int32_t keyEventAction, int32_t keyEventFlags) { + int32_t keyEventAction, int32_t keyEventFlags) { int32_t keyCode = mCurrentVirtualKey.keyCode; int32_t scanCode = mCurrentVirtualKey.scanCode; nsecs_t downTime = mCurrentVirtualKey.downTime; @@ -4811,8 +4729,8 @@ void TouchInputMapper::dispatchVirtualKey(nsecs_t when, uint32_t policyFlags, policyFlags |= POLICY_FLAG_VIRTUAL; NotifyKeyArgs args(mContext->getNextSequenceNum(), when, getDeviceId(), AINPUT_SOURCE_KEYBOARD, - mViewport.displayId, - policyFlags, keyEventAction, keyEventFlags, keyCode, scanCode, metaState, downTime); + mViewport.displayId, policyFlags, keyEventAction, keyEventFlags, keyCode, + scanCode, metaState, downTime); getListener()->notifyKey(&args); } @@ -4821,13 +4739,12 @@ void TouchInputMapper::abortTouches(nsecs_t when, uint32_t policyFlags) { if (!currentIdBits.isEmpty()) { int32_t metaState = getContext()->getGlobalMetaState(); int32_t buttonState = mCurrentCookedState.buttonState; - dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_CANCEL, 0, 0, - metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE, - mCurrentCookedState.cookedPointerData.pointerProperties, - mCurrentCookedState.cookedPointerData.pointerCoords, - mCurrentCookedState.cookedPointerData.idToIndex, - currentIdBits, -1, - mOrientedXPrecision, mOrientedYPrecision, mDownTime); + dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_CANCEL, 0, 0, metaState, + buttonState, AMOTION_EVENT_EDGE_FLAG_NONE, + mCurrentCookedState.cookedPointerData.pointerProperties, + mCurrentCookedState.cookedPointerData.pointerCoords, + mCurrentCookedState.cookedPointerData.idToIndex, currentIdBits, -1, + mOrientedXPrecision, mOrientedYPrecision, mDownTime); mCurrentMotionAborted = true; } } @@ -4842,14 +4759,12 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) { if (!currentIdBits.isEmpty()) { // No pointer id changes so this is a move event. // The listener takes care of batching moves so we don't have to deal with that here. - dispatchMotion(when, policyFlags, mSource, - AMOTION_EVENT_ACTION_MOVE, 0, 0, metaState, buttonState, - AMOTION_EVENT_EDGE_FLAG_NONE, - mCurrentCookedState.cookedPointerData.pointerProperties, - mCurrentCookedState.cookedPointerData.pointerCoords, - mCurrentCookedState.cookedPointerData.idToIndex, - currentIdBits, -1, - mOrientedXPrecision, mOrientedYPrecision, mDownTime); + dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_MOVE, 0, 0, metaState, + buttonState, AMOTION_EVENT_EDGE_FLAG_NONE, + mCurrentCookedState.cookedPointerData.pointerProperties, + mCurrentCookedState.cookedPointerData.pointerCoords, + mCurrentCookedState.cookedPointerData.idToIndex, currentIdBits, -1, + mOrientedXPrecision, mOrientedYPrecision, mDownTime); } } else { // There may be pointers going up and pointers going down and pointers moving @@ -4861,14 +4776,13 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) { // Update last coordinates of pointers that have moved so that we observe the new // pointer positions at the same time as other pointers that have just gone up. - bool moveNeeded = updateMovedPointers( - mCurrentCookedState.cookedPointerData.pointerProperties, - mCurrentCookedState.cookedPointerData.pointerCoords, - mCurrentCookedState.cookedPointerData.idToIndex, - mLastCookedState.cookedPointerData.pointerProperties, - mLastCookedState.cookedPointerData.pointerCoords, - mLastCookedState.cookedPointerData.idToIndex, - moveIdBits); + bool moveNeeded = + updateMovedPointers(mCurrentCookedState.cookedPointerData.pointerProperties, + mCurrentCookedState.cookedPointerData.pointerCoords, + mCurrentCookedState.cookedPointerData.idToIndex, + mLastCookedState.cookedPointerData.pointerProperties, + mLastCookedState.cookedPointerData.pointerCoords, + mLastCookedState.cookedPointerData.idToIndex, moveIdBits); if (buttonState != mLastCookedState.buttonState) { moveNeeded = true; } @@ -4877,12 +4791,12 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) { while (!upIdBits.isEmpty()) { uint32_t upId = upIdBits.clearFirstMarkedBit(); - dispatchMotion(when, policyFlags, mSource, - AMOTION_EVENT_ACTION_POINTER_UP, 0, 0, metaState, buttonState, 0, - mLastCookedState.cookedPointerData.pointerProperties, - mLastCookedState.cookedPointerData.pointerCoords, - mLastCookedState.cookedPointerData.idToIndex, - dispatchedIdBits, upId, mOrientedXPrecision, mOrientedYPrecision, mDownTime); + dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_POINTER_UP, 0, 0, + metaState, buttonState, 0, + mLastCookedState.cookedPointerData.pointerProperties, + mLastCookedState.cookedPointerData.pointerCoords, + mLastCookedState.cookedPointerData.idToIndex, dispatchedIdBits, upId, + mOrientedXPrecision, mOrientedYPrecision, mDownTime); dispatchedIdBits.clearBit(upId); } @@ -4891,12 +4805,11 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) { // events, they do not generally handle them except when presented in a move event. if (moveNeeded && !moveIdBits.isEmpty()) { ALOG_ASSERT(moveIdBits.value == dispatchedIdBits.value); - dispatchMotion(when, policyFlags, mSource, - AMOTION_EVENT_ACTION_MOVE, 0, 0, metaState, buttonState, 0, - mCurrentCookedState.cookedPointerData.pointerProperties, - mCurrentCookedState.cookedPointerData.pointerCoords, - mCurrentCookedState.cookedPointerData.idToIndex, - dispatchedIdBits, -1, mOrientedXPrecision, mOrientedYPrecision, mDownTime); + dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_MOVE, 0, 0, metaState, + buttonState, 0, mCurrentCookedState.cookedPointerData.pointerProperties, + mCurrentCookedState.cookedPointerData.pointerCoords, + mCurrentCookedState.cookedPointerData.idToIndex, dispatchedIdBits, -1, + mOrientedXPrecision, mOrientedYPrecision, mDownTime); } // Dispatch pointer down events using the new pointer locations. @@ -4909,55 +4822,54 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) { mDownTime = when; } - dispatchMotion(when, policyFlags, mSource, - AMOTION_EVENT_ACTION_POINTER_DOWN, 0, 0, metaState, buttonState, 0, - mCurrentCookedState.cookedPointerData.pointerProperties, - mCurrentCookedState.cookedPointerData.pointerCoords, - mCurrentCookedState.cookedPointerData.idToIndex, - dispatchedIdBits, downId, mOrientedXPrecision, mOrientedYPrecision, mDownTime); + dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_POINTER_DOWN, 0, 0, + metaState, buttonState, 0, + mCurrentCookedState.cookedPointerData.pointerProperties, + mCurrentCookedState.cookedPointerData.pointerCoords, + mCurrentCookedState.cookedPointerData.idToIndex, dispatchedIdBits, + downId, mOrientedXPrecision, mOrientedYPrecision, mDownTime); } } } void TouchInputMapper::dispatchHoverExit(nsecs_t when, uint32_t policyFlags) { if (mSentHoverEnter && - (mCurrentCookedState.cookedPointerData.hoveringIdBits.isEmpty() - || !mCurrentCookedState.cookedPointerData.touchingIdBits.isEmpty())) { + (mCurrentCookedState.cookedPointerData.hoveringIdBits.isEmpty() || + !mCurrentCookedState.cookedPointerData.touchingIdBits.isEmpty())) { int32_t metaState = getContext()->getGlobalMetaState(); - dispatchMotion(when, policyFlags, mSource, - AMOTION_EVENT_ACTION_HOVER_EXIT, 0, 0, metaState, mLastCookedState.buttonState, 0, - mLastCookedState.cookedPointerData.pointerProperties, - mLastCookedState.cookedPointerData.pointerCoords, - mLastCookedState.cookedPointerData.idToIndex, - mLastCookedState.cookedPointerData.hoveringIdBits, -1, - mOrientedXPrecision, mOrientedYPrecision, mDownTime); + dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_HOVER_EXIT, 0, 0, metaState, + mLastCookedState.buttonState, 0, + mLastCookedState.cookedPointerData.pointerProperties, + mLastCookedState.cookedPointerData.pointerCoords, + mLastCookedState.cookedPointerData.idToIndex, + mLastCookedState.cookedPointerData.hoveringIdBits, -1, mOrientedXPrecision, + mOrientedYPrecision, mDownTime); mSentHoverEnter = false; } } void TouchInputMapper::dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFlags) { - if (mCurrentCookedState.cookedPointerData.touchingIdBits.isEmpty() - && !mCurrentCookedState.cookedPointerData.hoveringIdBits.isEmpty()) { + if (mCurrentCookedState.cookedPointerData.touchingIdBits.isEmpty() && + !mCurrentCookedState.cookedPointerData.hoveringIdBits.isEmpty()) { int32_t metaState = getContext()->getGlobalMetaState(); if (!mSentHoverEnter) { - dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_HOVER_ENTER, - 0, 0, metaState, mCurrentRawState.buttonState, 0, - mCurrentCookedState.cookedPointerData.pointerProperties, - mCurrentCookedState.cookedPointerData.pointerCoords, - mCurrentCookedState.cookedPointerData.idToIndex, - mCurrentCookedState.cookedPointerData.hoveringIdBits, -1, - mOrientedXPrecision, mOrientedYPrecision, mDownTime); + dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_HOVER_ENTER, 0, 0, + metaState, mCurrentRawState.buttonState, 0, + mCurrentCookedState.cookedPointerData.pointerProperties, + mCurrentCookedState.cookedPointerData.pointerCoords, + mCurrentCookedState.cookedPointerData.idToIndex, + mCurrentCookedState.cookedPointerData.hoveringIdBits, -1, + mOrientedXPrecision, mOrientedYPrecision, mDownTime); mSentHoverEnter = true; } - dispatchMotion(when, policyFlags, mSource, - AMOTION_EVENT_ACTION_HOVER_MOVE, 0, 0, metaState, - mCurrentRawState.buttonState, 0, - mCurrentCookedState.cookedPointerData.pointerProperties, - mCurrentCookedState.cookedPointerData.pointerCoords, - mCurrentCookedState.cookedPointerData.idToIndex, - mCurrentCookedState.cookedPointerData.hoveringIdBits, -1, - mOrientedXPrecision, mOrientedYPrecision, mDownTime); + dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_HOVER_MOVE, 0, 0, metaState, + mCurrentRawState.buttonState, 0, + mCurrentCookedState.cookedPointerData.pointerProperties, + mCurrentCookedState.cookedPointerData.pointerCoords, + mCurrentCookedState.cookedPointerData.idToIndex, + mCurrentCookedState.cookedPointerData.hoveringIdBits, -1, + mOrientedXPrecision, mOrientedYPrecision, mDownTime); } } @@ -4969,13 +4881,12 @@ void TouchInputMapper::dispatchButtonRelease(nsecs_t when, uint32_t policyFlags) while (!releasedButtons.isEmpty()) { int32_t actionButton = BitSet32::valueForBit(releasedButtons.clearFirstMarkedBit()); buttonState &= ~actionButton; - dispatchMotion(when, policyFlags, mSource, - AMOTION_EVENT_ACTION_BUTTON_RELEASE, actionButton, - 0, metaState, buttonState, 0, - mCurrentCookedState.cookedPointerData.pointerProperties, - mCurrentCookedState.cookedPointerData.pointerCoords, - mCurrentCookedState.cookedPointerData.idToIndex, idBits, -1, - mOrientedXPrecision, mOrientedYPrecision, mDownTime); + dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_BUTTON_RELEASE, + actionButton, 0, metaState, buttonState, 0, + mCurrentCookedState.cookedPointerData.pointerProperties, + mCurrentCookedState.cookedPointerData.pointerCoords, + mCurrentCookedState.cookedPointerData.idToIndex, idBits, -1, + mOrientedXPrecision, mOrientedYPrecision, mDownTime); } } @@ -4988,11 +4899,11 @@ void TouchInputMapper::dispatchButtonPress(nsecs_t when, uint32_t policyFlags) { int32_t actionButton = BitSet32::valueForBit(pressedButtons.clearFirstMarkedBit()); buttonState |= actionButton; dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_BUTTON_PRESS, actionButton, - 0, metaState, buttonState, 0, - mCurrentCookedState.cookedPointerData.pointerProperties, - mCurrentCookedState.cookedPointerData.pointerCoords, - mCurrentCookedState.cookedPointerData.idToIndex, idBits, -1, - mOrientedXPrecision, mOrientedYPrecision, mDownTime); + 0, metaState, buttonState, 0, + mCurrentCookedState.cookedPointerData.pointerProperties, + mCurrentCookedState.cookedPointerData.pointerCoords, + mCurrentCookedState.cookedPointerData.idToIndex, idBits, -1, + mOrientedXPrecision, mOrientedYPrecision, mDownTime); } } @@ -5027,91 +4938,91 @@ void TouchInputMapper::cookPointerData() { // Size float touchMajor, touchMinor, toolMajor, toolMinor, size; switch (mCalibration.sizeCalibration) { - case Calibration::SIZE_CALIBRATION_GEOMETRIC: - case Calibration::SIZE_CALIBRATION_DIAMETER: - case Calibration::SIZE_CALIBRATION_BOX: - case Calibration::SIZE_CALIBRATION_AREA: - if (mRawPointerAxes.touchMajor.valid && mRawPointerAxes.toolMajor.valid) { - touchMajor = in.touchMajor; - touchMinor = mRawPointerAxes.touchMinor.valid ? in.touchMinor : in.touchMajor; - toolMajor = in.toolMajor; - toolMinor = mRawPointerAxes.toolMinor.valid ? in.toolMinor : in.toolMajor; - size = mRawPointerAxes.touchMinor.valid - ? avg(in.touchMajor, in.touchMinor) : in.touchMajor; - } else if (mRawPointerAxes.touchMajor.valid) { - toolMajor = touchMajor = in.touchMajor; - toolMinor = touchMinor = mRawPointerAxes.touchMinor.valid - ? in.touchMinor : in.touchMajor; - size = mRawPointerAxes.touchMinor.valid - ? avg(in.touchMajor, in.touchMinor) : in.touchMajor; - } else if (mRawPointerAxes.toolMajor.valid) { - touchMajor = toolMajor = in.toolMajor; - touchMinor = toolMinor = mRawPointerAxes.toolMinor.valid - ? in.toolMinor : in.toolMajor; - size = mRawPointerAxes.toolMinor.valid - ? avg(in.toolMajor, in.toolMinor) : in.toolMajor; - } else { - ALOG_ASSERT(false, "No touch or tool axes. " - "Size calibration should have been resolved to NONE."); + case Calibration::SIZE_CALIBRATION_GEOMETRIC: + case Calibration::SIZE_CALIBRATION_DIAMETER: + case Calibration::SIZE_CALIBRATION_BOX: + case Calibration::SIZE_CALIBRATION_AREA: + if (mRawPointerAxes.touchMajor.valid && mRawPointerAxes.toolMajor.valid) { + touchMajor = in.touchMajor; + touchMinor = mRawPointerAxes.touchMinor.valid ? in.touchMinor : in.touchMajor; + toolMajor = in.toolMajor; + toolMinor = mRawPointerAxes.toolMinor.valid ? in.toolMinor : in.toolMajor; + size = mRawPointerAxes.touchMinor.valid ? avg(in.touchMajor, in.touchMinor) + : in.touchMajor; + } else if (mRawPointerAxes.touchMajor.valid) { + toolMajor = touchMajor = in.touchMajor; + toolMinor = touchMinor = + mRawPointerAxes.touchMinor.valid ? in.touchMinor : in.touchMajor; + size = mRawPointerAxes.touchMinor.valid ? avg(in.touchMajor, in.touchMinor) + : in.touchMajor; + } else if (mRawPointerAxes.toolMajor.valid) { + touchMajor = toolMajor = in.toolMajor; + touchMinor = toolMinor = + mRawPointerAxes.toolMinor.valid ? in.toolMinor : in.toolMajor; + size = mRawPointerAxes.toolMinor.valid ? avg(in.toolMajor, in.toolMinor) + : in.toolMajor; + } else { + ALOG_ASSERT(false, + "No touch or tool axes. " + "Size calibration should have been resolved to NONE."); + touchMajor = 0; + touchMinor = 0; + toolMajor = 0; + toolMinor = 0; + size = 0; + } + + if (mCalibration.haveSizeIsSummed && mCalibration.sizeIsSummed) { + uint32_t touchingCount = mCurrentRawState.rawPointerData.touchingIdBits.count(); + if (touchingCount > 1) { + touchMajor /= touchingCount; + touchMinor /= touchingCount; + toolMajor /= touchingCount; + toolMinor /= touchingCount; + size /= touchingCount; + } + } + + if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_GEOMETRIC) { + touchMajor *= mGeometricScale; + touchMinor *= mGeometricScale; + toolMajor *= mGeometricScale; + toolMinor *= mGeometricScale; + } else if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_AREA) { + touchMajor = touchMajor > 0 ? sqrtf(touchMajor) : 0; + touchMinor = touchMajor; + toolMajor = toolMajor > 0 ? sqrtf(toolMajor) : 0; + toolMinor = toolMajor; + } else if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_DIAMETER) { + touchMinor = touchMajor; + toolMinor = toolMajor; + } + + mCalibration.applySizeScaleAndBias(&touchMajor); + mCalibration.applySizeScaleAndBias(&touchMinor); + mCalibration.applySizeScaleAndBias(&toolMajor); + mCalibration.applySizeScaleAndBias(&toolMinor); + size *= mSizeScale; + break; + default: touchMajor = 0; touchMinor = 0; toolMajor = 0; toolMinor = 0; size = 0; - } - - if (mCalibration.haveSizeIsSummed && mCalibration.sizeIsSummed) { - uint32_t touchingCount = - mCurrentRawState.rawPointerData.touchingIdBits.count(); - if (touchingCount > 1) { - touchMajor /= touchingCount; - touchMinor /= touchingCount; - toolMajor /= touchingCount; - toolMinor /= touchingCount; - size /= touchingCount; - } - } - - if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_GEOMETRIC) { - touchMajor *= mGeometricScale; - touchMinor *= mGeometricScale; - toolMajor *= mGeometricScale; - toolMinor *= mGeometricScale; - } else if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_AREA) { - touchMajor = touchMajor > 0 ? sqrtf(touchMajor) : 0; - touchMinor = touchMajor; - toolMajor = toolMajor > 0 ? sqrtf(toolMajor) : 0; - toolMinor = toolMajor; - } else if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_DIAMETER) { - touchMinor = touchMajor; - toolMinor = toolMajor; - } - - mCalibration.applySizeScaleAndBias(&touchMajor); - mCalibration.applySizeScaleAndBias(&touchMinor); - mCalibration.applySizeScaleAndBias(&toolMajor); - mCalibration.applySizeScaleAndBias(&toolMinor); - size *= mSizeScale; - break; - default: - touchMajor = 0; - touchMinor = 0; - toolMajor = 0; - toolMinor = 0; - size = 0; - break; + break; } // Pressure float pressure; switch (mCalibration.pressureCalibration) { - case Calibration::PRESSURE_CALIBRATION_PHYSICAL: - case Calibration::PRESSURE_CALIBRATION_AMPLITUDE: - pressure = in.pressure * mPressureScale; - break; - default: - pressure = in.isHovering ? 0 : 1; - break; + case Calibration::PRESSURE_CALIBRATION_PHYSICAL: + case Calibration::PRESSURE_CALIBRATION_AMPLITUDE: + pressure = in.pressure * mPressureScale; + break; + default: + pressure = in.isHovering ? 0 : 1; + break; } // Tilt and Orientation @@ -5126,52 +5037,52 @@ void TouchInputMapper::cookPointerData() { tilt = 0; switch (mCalibration.orientationCalibration) { - case Calibration::ORIENTATION_CALIBRATION_INTERPOLATED: - orientation = in.orientation * mOrientationScale; - break; - case Calibration::ORIENTATION_CALIBRATION_VECTOR: { - int32_t c1 = signExtendNybble((in.orientation & 0xf0) >> 4); - int32_t c2 = signExtendNybble(in.orientation & 0x0f); - if (c1 != 0 || c2 != 0) { - orientation = atan2f(c1, c2) * 0.5f; - float confidence = hypotf(c1, c2); - float scale = 1.0f + confidence / 16.0f; - touchMajor *= scale; - touchMinor /= scale; - toolMajor *= scale; - toolMinor /= scale; - } else { - orientation = 0; + case Calibration::ORIENTATION_CALIBRATION_INTERPOLATED: + orientation = in.orientation * mOrientationScale; + break; + case Calibration::ORIENTATION_CALIBRATION_VECTOR: { + int32_t c1 = signExtendNybble((in.orientation & 0xf0) >> 4); + int32_t c2 = signExtendNybble(in.orientation & 0x0f); + if (c1 != 0 || c2 != 0) { + orientation = atan2f(c1, c2) * 0.5f; + float confidence = hypotf(c1, c2); + float scale = 1.0f + confidence / 16.0f; + touchMajor *= scale; + touchMinor /= scale; + toolMajor *= scale; + toolMinor /= scale; + } else { + orientation = 0; + } + break; } - break; - } - default: - orientation = 0; + default: + orientation = 0; } } // Distance float distance; switch (mCalibration.distanceCalibration) { - case Calibration::DISTANCE_CALIBRATION_SCALED: - distance = in.distance * mDistanceScale; - break; - default: - distance = 0; + case Calibration::DISTANCE_CALIBRATION_SCALED: + distance = in.distance * mDistanceScale; + break; + default: + distance = 0; } // Coverage int32_t rawLeft, rawTop, rawRight, rawBottom; switch (mCalibration.coverageCalibration) { - case Calibration::COVERAGE_CALIBRATION_BOX: - rawLeft = (in.toolMinor & 0xffff0000) >> 16; - rawRight = in.toolMinor & 0x0000ffff; - rawBottom = in.toolMajor & 0x0000ffff; - rawTop = (in.toolMajor & 0xffff0000) >> 16; - break; - default: - rawLeft = rawTop = rawRight = rawBottom = 0; - break; + case Calibration::COVERAGE_CALIBRATION_BOX: + rawLeft = (in.toolMinor & 0xffff0000) >> 16; + rawRight = in.toolMinor & 0x0000ffff; + rawBottom = in.toolMajor & 0x0000ffff; + rawTop = (in.toolMajor & 0xffff0000) >> 16; + break; + default: + rawLeft = rawTop = rawRight = rawBottom = 0; + break; } // Adjust X,Y coords for device calibration @@ -5184,50 +5095,56 @@ void TouchInputMapper::cookPointerData() { float left, top, right, bottom; switch (mSurfaceOrientation) { - case DISPLAY_ORIENTATION_90: - x = float(yTransformed - mRawPointerAxes.y.minValue) * mYScale + mYTranslate; - y = float(mRawPointerAxes.x.maxValue - xTransformed) * mXScale + mXTranslate; - left = float(rawTop - mRawPointerAxes.y.minValue) * mYScale + mYTranslate; - right = float(rawBottom- mRawPointerAxes.y.minValue) * mYScale + mYTranslate; - bottom = float(mRawPointerAxes.x.maxValue - rawLeft) * mXScale + mXTranslate; - top = float(mRawPointerAxes.x.maxValue - rawRight) * mXScale + mXTranslate; - orientation -= M_PI_2; - if (mOrientedRanges.haveOrientation && orientation < mOrientedRanges.orientation.min) { - orientation += (mOrientedRanges.orientation.max - mOrientedRanges.orientation.min); - } - break; - case DISPLAY_ORIENTATION_180: - x = float(mRawPointerAxes.x.maxValue - xTransformed) * mXScale; - y = float(mRawPointerAxes.y.maxValue - yTransformed) * mYScale + mYTranslate; - left = float(mRawPointerAxes.x.maxValue - rawRight) * mXScale; - right = float(mRawPointerAxes.x.maxValue - rawLeft) * mXScale; - bottom = float(mRawPointerAxes.y.maxValue - rawTop) * mYScale + mYTranslate; - top = float(mRawPointerAxes.y.maxValue - rawBottom) * mYScale + mYTranslate; - orientation -= M_PI; - if (mOrientedRanges.haveOrientation && orientation < mOrientedRanges.orientation.min) { - orientation += (mOrientedRanges.orientation.max - mOrientedRanges.orientation.min); - } - break; - case DISPLAY_ORIENTATION_270: - x = float(mRawPointerAxes.y.maxValue - yTransformed) * mYScale; - y = float(xTransformed - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; - left = float(mRawPointerAxes.y.maxValue - rawBottom) * mYScale; - right = float(mRawPointerAxes.y.maxValue - rawTop) * mYScale; - bottom = float(rawRight - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; - top = float(rawLeft - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; - orientation += M_PI_2; - if (mOrientedRanges.haveOrientation && orientation > mOrientedRanges.orientation.max) { - orientation -= (mOrientedRanges.orientation.max - mOrientedRanges.orientation.min); - } - break; - default: - x = float(xTransformed - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; - y = float(yTransformed - mRawPointerAxes.y.minValue) * mYScale + mYTranslate; - left = float(rawLeft - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; - right = float(rawRight - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; - bottom = float(rawBottom - mRawPointerAxes.y.minValue) * mYScale + mYTranslate; - top = float(rawTop - mRawPointerAxes.y.minValue) * mYScale + mYTranslate; - break; + case DISPLAY_ORIENTATION_90: + x = float(yTransformed - mRawPointerAxes.y.minValue) * mYScale + mYTranslate; + y = float(mRawPointerAxes.x.maxValue - xTransformed) * mXScale + mXTranslate; + left = float(rawTop - mRawPointerAxes.y.minValue) * mYScale + mYTranslate; + right = float(rawBottom - mRawPointerAxes.y.minValue) * mYScale + mYTranslate; + bottom = float(mRawPointerAxes.x.maxValue - rawLeft) * mXScale + mXTranslate; + top = float(mRawPointerAxes.x.maxValue - rawRight) * mXScale + mXTranslate; + orientation -= M_PI_2; + if (mOrientedRanges.haveOrientation && + orientation < mOrientedRanges.orientation.min) { + orientation += + (mOrientedRanges.orientation.max - mOrientedRanges.orientation.min); + } + break; + case DISPLAY_ORIENTATION_180: + x = float(mRawPointerAxes.x.maxValue - xTransformed) * mXScale; + y = float(mRawPointerAxes.y.maxValue - yTransformed) * mYScale + mYTranslate; + left = float(mRawPointerAxes.x.maxValue - rawRight) * mXScale; + right = float(mRawPointerAxes.x.maxValue - rawLeft) * mXScale; + bottom = float(mRawPointerAxes.y.maxValue - rawTop) * mYScale + mYTranslate; + top = float(mRawPointerAxes.y.maxValue - rawBottom) * mYScale + mYTranslate; + orientation -= M_PI; + if (mOrientedRanges.haveOrientation && + orientation < mOrientedRanges.orientation.min) { + orientation += + (mOrientedRanges.orientation.max - mOrientedRanges.orientation.min); + } + break; + case DISPLAY_ORIENTATION_270: + x = float(mRawPointerAxes.y.maxValue - yTransformed) * mYScale; + y = float(xTransformed - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; + left = float(mRawPointerAxes.y.maxValue - rawBottom) * mYScale; + right = float(mRawPointerAxes.y.maxValue - rawTop) * mYScale; + bottom = float(rawRight - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; + top = float(rawLeft - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; + orientation += M_PI_2; + if (mOrientedRanges.haveOrientation && + orientation > mOrientedRanges.orientation.max) { + orientation -= + (mOrientedRanges.orientation.max - mOrientedRanges.orientation.min); + } + break; + default: + x = float(xTransformed - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; + y = float(yTransformed - mRawPointerAxes.y.minValue) * mYScale + mYTranslate; + left = float(rawLeft - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; + right = float(rawRight - mRawPointerAxes.x.minValue) * mXScale + mXTranslate; + bottom = float(rawBottom - mRawPointerAxes.y.minValue) * mYScale + mYTranslate; + top = float(rawTop - mRawPointerAxes.y.minValue) * mYScale + mYTranslate; + break; } // Write output coords. @@ -5253,8 +5170,7 @@ void TouchInputMapper::cookPointerData() { } // Write output properties. - PointerProperties& properties = - mCurrentCookedState.cookedPointerData.pointerProperties[i]; + PointerProperties& properties = mCurrentCookedState.cookedPointerData.pointerProperties[i]; uint32_t id = in.id; properties.clear(); properties.id = id; @@ -5266,51 +5182,50 @@ void TouchInputMapper::cookPointerData() { } void TouchInputMapper::dispatchPointerUsage(nsecs_t when, uint32_t policyFlags, - PointerUsage pointerUsage) { + PointerUsage pointerUsage) { if (pointerUsage != mPointerUsage) { abortPointerUsage(when, policyFlags); mPointerUsage = pointerUsage; } switch (mPointerUsage) { - case POINTER_USAGE_GESTURES: - dispatchPointerGestures(when, policyFlags, false /*isTimeout*/); - break; - case POINTER_USAGE_STYLUS: - dispatchPointerStylus(when, policyFlags); - break; - case POINTER_USAGE_MOUSE: - dispatchPointerMouse(when, policyFlags); - break; - default: - break; + case POINTER_USAGE_GESTURES: + dispatchPointerGestures(when, policyFlags, false /*isTimeout*/); + break; + case POINTER_USAGE_STYLUS: + dispatchPointerStylus(when, policyFlags); + break; + case POINTER_USAGE_MOUSE: + dispatchPointerMouse(when, policyFlags); + break; + default: + break; } } void TouchInputMapper::abortPointerUsage(nsecs_t when, uint32_t policyFlags) { switch (mPointerUsage) { - case POINTER_USAGE_GESTURES: - abortPointerGestures(when, policyFlags); - break; - case POINTER_USAGE_STYLUS: - abortPointerStylus(when, policyFlags); - break; - case POINTER_USAGE_MOUSE: - abortPointerMouse(when, policyFlags); - break; - default: - break; + case POINTER_USAGE_GESTURES: + abortPointerGestures(when, policyFlags); + break; + case POINTER_USAGE_STYLUS: + abortPointerStylus(when, policyFlags); + break; + case POINTER_USAGE_MOUSE: + abortPointerMouse(when, policyFlags); + break; + default: + break; } mPointerUsage = POINTER_USAGE_NONE; } -void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, - bool isTimeout) { +void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout) { // Update current gesture coordinates. bool cancelPreviousGesture, finishPreviousGesture; - bool sendEvents = preparePointerGestures(when, - &cancelPreviousGesture, &finishPreviousGesture, isTimeout); + bool sendEvents = + preparePointerGestures(when, &cancelPreviousGesture, &finishPreviousGesture, isTimeout); if (!sendEvents) { return; } @@ -5327,9 +5242,9 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag if (mPointerGesture.currentGestureMode == PointerGesture::FREEFORM) { mPointerController->setSpots(mPointerGesture.currentGestureCoords, - mPointerGesture.currentGestureIdToIndex, - mPointerGesture.currentGestureIdBits, - mPointerController->getDisplayId()); + mPointerGesture.currentGestureIdToIndex, + mPointerGesture.currentGestureIdBits, + mPointerController->getDisplayId()); } } else { mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_POINTER); @@ -5337,33 +5252,33 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag // Show or hide the pointer if needed. switch (mPointerGesture.currentGestureMode) { - case PointerGesture::NEUTRAL: - case PointerGesture::QUIET: - if (mParameters.gestureMode == Parameters::GESTURE_MODE_MULTI_TOUCH - && mPointerGesture.lastGestureMode == PointerGesture::FREEFORM) { - // Remind the user of where the pointer is after finishing a gesture with spots. - mPointerController->unfade(PointerControllerInterface::TRANSITION_GRADUAL); - } - break; - case PointerGesture::TAP: - case PointerGesture::TAP_DRAG: - case PointerGesture::BUTTON_CLICK_OR_DRAG: - case PointerGesture::HOVER: - case PointerGesture::PRESS: - case PointerGesture::SWIPE: - // Unfade the pointer when the current gesture manipulates the - // area directly under the pointer. - mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE); - break; - case PointerGesture::FREEFORM: - // Fade the pointer when the current gesture manipulates a different - // area and there are spots to guide the user experience. - if (mParameters.gestureMode == Parameters::GESTURE_MODE_MULTI_TOUCH) { - mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL); - } else { + case PointerGesture::NEUTRAL: + case PointerGesture::QUIET: + if (mParameters.gestureMode == Parameters::GESTURE_MODE_MULTI_TOUCH && + mPointerGesture.lastGestureMode == PointerGesture::FREEFORM) { + // Remind the user of where the pointer is after finishing a gesture with spots. + mPointerController->unfade(PointerControllerInterface::TRANSITION_GRADUAL); + } + break; + case PointerGesture::TAP: + case PointerGesture::TAP_DRAG: + case PointerGesture::BUTTON_CLICK_OR_DRAG: + case PointerGesture::HOVER: + case PointerGesture::PRESS: + case PointerGesture::SWIPE: + // Unfade the pointer when the current gesture manipulates the + // area directly under the pointer. mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE); - } - break; + break; + case PointerGesture::FREEFORM: + // Fade the pointer when the current gesture manipulates a different + // area and there are spots to guide the user experience. + if (mParameters.gestureMode == Parameters::GESTURE_MODE_MULTI_TOUCH) { + mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL); + } else { + mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE); + } + break; } // Send events! @@ -5372,23 +5287,24 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag // Update last coordinates of pointers that have moved so that we observe the new // pointer positions at the same time as other pointers that have just gone up. - bool down = mPointerGesture.currentGestureMode == PointerGesture::TAP - || mPointerGesture.currentGestureMode == PointerGesture::TAP_DRAG - || mPointerGesture.currentGestureMode == PointerGesture::BUTTON_CLICK_OR_DRAG - || mPointerGesture.currentGestureMode == PointerGesture::PRESS - || mPointerGesture.currentGestureMode == PointerGesture::SWIPE - || mPointerGesture.currentGestureMode == PointerGesture::FREEFORM; + bool down = mPointerGesture.currentGestureMode == PointerGesture::TAP || + mPointerGesture.currentGestureMode == PointerGesture::TAP_DRAG || + mPointerGesture.currentGestureMode == PointerGesture::BUTTON_CLICK_OR_DRAG || + mPointerGesture.currentGestureMode == PointerGesture::PRESS || + mPointerGesture.currentGestureMode == PointerGesture::SWIPE || + mPointerGesture.currentGestureMode == PointerGesture::FREEFORM; bool moveNeeded = false; - if (down && !cancelPreviousGesture && !finishPreviousGesture - && !mPointerGesture.lastGestureIdBits.isEmpty() - && !mPointerGesture.currentGestureIdBits.isEmpty()) { - BitSet32 movedGestureIdBits(mPointerGesture.currentGestureIdBits.value - & mPointerGesture.lastGestureIdBits.value); + if (down && !cancelPreviousGesture && !finishPreviousGesture && + !mPointerGesture.lastGestureIdBits.isEmpty() && + !mPointerGesture.currentGestureIdBits.isEmpty()) { + BitSet32 movedGestureIdBits(mPointerGesture.currentGestureIdBits.value & + mPointerGesture.lastGestureIdBits.value); moveNeeded = updateMovedPointers(mPointerGesture.currentGestureProperties, - mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex, - mPointerGesture.lastGestureProperties, - mPointerGesture.lastGestureCoords, mPointerGesture.lastGestureIdToIndex, - movedGestureIdBits); + mPointerGesture.currentGestureCoords, + mPointerGesture.currentGestureIdToIndex, + mPointerGesture.lastGestureProperties, + mPointerGesture.lastGestureCoords, + mPointerGesture.lastGestureIdToIndex, movedGestureIdBits); if (buttonState != mLastCookedState.buttonState) { moveNeeded = true; } @@ -5410,19 +5326,18 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag if (finishPreviousGesture) { upGestureIdBits = dispatchedGestureIdBits; } else { - upGestureIdBits.value = dispatchedGestureIdBits.value - & ~mPointerGesture.currentGestureIdBits.value; + upGestureIdBits.value = + dispatchedGestureIdBits.value & ~mPointerGesture.currentGestureIdBits.value; } while (!upGestureIdBits.isEmpty()) { uint32_t id = upGestureIdBits.clearFirstMarkedBit(); - dispatchMotion(when, policyFlags, mSource, - AMOTION_EVENT_ACTION_POINTER_UP, 0, 0, - metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE, - mPointerGesture.lastGestureProperties, - mPointerGesture.lastGestureCoords, mPointerGesture.lastGestureIdToIndex, - dispatchedGestureIdBits, id, - 0, 0, mPointerGesture.downTime); + dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_POINTER_UP, 0, 0, + metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE, + mPointerGesture.lastGestureProperties, + mPointerGesture.lastGestureCoords, + mPointerGesture.lastGestureIdToIndex, dispatchedGestureIdBits, id, 0, + 0, mPointerGesture.downTime); dispatchedGestureIdBits.clearBit(id); } @@ -5441,8 +5356,8 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag // Send motion events for all pointers that went down. if (down) { - BitSet32 downGestureIdBits(mPointerGesture.currentGestureIdBits.value - & ~dispatchedGestureIdBits.value); + BitSet32 downGestureIdBits(mPointerGesture.currentGestureIdBits.value & + ~dispatchedGestureIdBits.value); while (!downGestureIdBits.isEmpty()) { uint32_t id = downGestureIdBits.clearFirstMarkedBit(); dispatchedGestureIdBits.markBit(id); @@ -5451,12 +5366,11 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag mPointerGesture.downTime = when; } - dispatchMotion(when, policyFlags, mSource, - AMOTION_EVENT_ACTION_POINTER_DOWN, 0, 0, metaState, buttonState, 0, - mPointerGesture.currentGestureProperties, - mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex, - dispatchedGestureIdBits, id, - 0, 0, mPointerGesture.downTime); + dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_POINTER_DOWN, 0, 0, + metaState, buttonState, 0, mPointerGesture.currentGestureProperties, + mPointerGesture.currentGestureCoords, + mPointerGesture.currentGestureIdToIndex, dispatchedGestureIdBits, id, 0, + 0, mPointerGesture.downTime); } } @@ -5468,8 +5382,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex, mPointerGesture.currentGestureIdBits, -1, 0, 0, mPointerGesture.downTime); - } else if (dispatchedGestureIdBits.isEmpty() - && !mPointerGesture.lastGestureIdBits.isEmpty()) { + } else if (dispatchedGestureIdBits.isEmpty() && !mPointerGesture.lastGestureIdBits.isEmpty()) { // Synthesize a hover move event after all pointers go up to indicate that // the pointer is hovering again even if the user is not currently touching // the touch pad. This ensures that a view will receive a fresh hover enter @@ -5502,7 +5415,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag mPointerGesture.lastGestureIdBits.clear(); } else { mPointerGesture.lastGestureIdBits = mPointerGesture.currentGestureIdBits; - for (BitSet32 idBits(mPointerGesture.currentGestureIdBits); !idBits.isEmpty(); ) { + for (BitSet32 idBits(mPointerGesture.currentGestureIdBits); !idBits.isEmpty();) { uint32_t id = idBits.clearFirstMarkedBit(); uint32_t index = mPointerGesture.currentGestureIdToIndex[id]; mPointerGesture.lastGestureProperties[index].copyFrom( @@ -5537,8 +5450,8 @@ void TouchInputMapper::abortPointerGestures(nsecs_t when, uint32_t policyFlags) } } -bool TouchInputMapper::preparePointerGestures(nsecs_t when, - bool* outCancelPreviousGesture, bool* outFinishPreviousGesture, bool isTimeout) { +bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPreviousGesture, + bool* outFinishPreviousGesture, bool isTimeout) { *outCancelPreviousGesture = false; *outFinishPreviousGesture = false; @@ -5551,8 +5464,8 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, if (mPointerGesture.lastGestureMode == PointerGesture::TAP) { if (when <= mPointerGesture.tapUpTime + mConfig.pointerGestureTapDragInterval) { // The tap/drag timeout has not yet expired. - getContext()->requestTimeoutAtTime(mPointerGesture.tapUpTime - + mConfig.pointerGestureTapDragInterval); + getContext()->requestTimeoutAtTime(mPointerGesture.tapUpTime + + mConfig.pointerGestureTapDragInterval); } else { // The tap is finished. #if DEBUG_GESTURES @@ -5587,15 +5500,15 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, positions[count].x = pointer.x * mPointerXMovementScale; positions[count].y = pointer.y * mPointerYMovementScale; } - mPointerGesture.velocityTracker.addMovement(when, - mCurrentCookedState.fingerIdBits, positions); + mPointerGesture.velocityTracker.addMovement(when, mCurrentCookedState.fingerIdBits, + positions); } // If the gesture ever enters a mode other than TAP, HOVER or TAP_DRAG, without first returning // to NEUTRAL, then we should not generate tap event. - if (mPointerGesture.lastGestureMode != PointerGesture::HOVER - && mPointerGesture.lastGestureMode != PointerGesture::TAP - && mPointerGesture.lastGestureMode != PointerGesture::TAP_DRAG) { + if (mPointerGesture.lastGestureMode != PointerGesture::HOVER && + mPointerGesture.lastGestureMode != PointerGesture::TAP && + mPointerGesture.lastGestureMode != PointerGesture::TAP_DRAG) { mPointerGesture.resetTap(); } @@ -5628,17 +5541,16 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, } else { isQuietTime = when < mPointerGesture.quietTime + mConfig.pointerGestureQuietInterval; if (!isQuietTime) { - if ((mPointerGesture.lastGestureMode == PointerGesture::PRESS - || mPointerGesture.lastGestureMode == PointerGesture::SWIPE - || mPointerGesture.lastGestureMode == PointerGesture::FREEFORM) - && currentFingerCount < 2) { + if ((mPointerGesture.lastGestureMode == PointerGesture::PRESS || + mPointerGesture.lastGestureMode == PointerGesture::SWIPE || + mPointerGesture.lastGestureMode == PointerGesture::FREEFORM) && + currentFingerCount < 2) { // Enter quiet time when exiting swipe or freeform state. // This is to prevent accidentally entering the hover state and flinging the // pointer when finishing a swipe and there is still one pointer left onscreen. isQuietTime = true; - } else if (mPointerGesture.lastGestureMode == PointerGesture::BUTTON_CLICK_OR_DRAG - && currentFingerCount >= 2 - && !isPointerDown(mCurrentRawState.buttonState)) { + } else if (mPointerGesture.lastGestureMode == PointerGesture::BUTTON_CLICK_OR_DRAG && + currentFingerCount >= 2 && !isPointerDown(mCurrentRawState.buttonState)) { // Enter quiet time when releasing the button and there are still two or more // fingers down. This may indicate that one finger was used to press the button // but it has not gone up yet. @@ -5654,8 +5566,8 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, if (isQuietTime) { // Case 1: Quiet time. (QUIET) #if DEBUG_GESTURES - ALOGD("Gestures: QUIET for next %0.3fms", (mPointerGesture.quietTime - + mConfig.pointerGestureQuietInterval - when) * 0.000001f); + ALOGD("Gestures: QUIET for next %0.3fms", + (mPointerGesture.quietTime + mConfig.pointerGestureQuietInterval - when) * 0.000001f); #endif if (mPointerGesture.lastGestureMode != PointerGesture::QUIET) { *outFinishPreviousGesture = true; @@ -5682,7 +5594,8 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, // being dragged. #if DEBUG_GESTURES ALOGD("Gestures: BUTTON_CLICK_OR_DRAG activeTouchId=%d, " - "currentFingerCount=%d", activeTouchId, currentFingerCount); + "currentFingerCount=%d", + activeTouchId, currentFingerCount); #endif // Reset state when just starting. if (mPointerGesture.lastGestureMode != PointerGesture::BUTTON_CLICK_OR_DRAG) { @@ -5695,7 +5608,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, if (activeTouchId >= 0 && currentFingerCount > 1) { int32_t bestId = -1; float bestSpeed = mConfig.pointerGestureDragMinSwitchSpeed; - for (BitSet32 idBits(mCurrentCookedState.fingerIdBits); !idBits.isEmpty(); ) { + for (BitSet32 idBits(mCurrentCookedState.fingerIdBits); !idBits.isEmpty();) { uint32_t id = idBits.clearFirstMarkedBit(); float vx, vy; if (mPointerGesture.velocityTracker.getVelocity(id, &vx, &vy)) { @@ -5710,7 +5623,8 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, mPointerGesture.activeTouchId = activeTouchId = bestId; #if DEBUG_GESTURES ALOGD("Gestures: BUTTON_CLICK_OR_DRAG switched pointers, " - "bestId=%d, bestSpeed=%0.3f", bestId, bestSpeed); + "bestId=%d, bestSpeed=%0.3f", + bestId, bestSpeed); #endif } } @@ -5758,55 +5672,52 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, // Watch for taps coming out of HOVER or TAP_DRAG mode. // Checking for taps after TAP_DRAG allows us to detect double-taps. bool tapped = false; - if ((mPointerGesture.lastGestureMode == PointerGesture::HOVER - || mPointerGesture.lastGestureMode == PointerGesture::TAP_DRAG) - && lastFingerCount == 1) { + if ((mPointerGesture.lastGestureMode == PointerGesture::HOVER || + mPointerGesture.lastGestureMode == PointerGesture::TAP_DRAG) && + lastFingerCount == 1) { if (when <= mPointerGesture.tapDownTime + mConfig.pointerGestureTapInterval) { float x, y; mPointerController->getPosition(&x, &y); - if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop - && fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) { + if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop && + fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) { #if DEBUG_GESTURES ALOGD("Gestures: TAP"); #endif mPointerGesture.tapUpTime = when; - getContext()->requestTimeoutAtTime(when - + mConfig.pointerGestureTapDragInterval); + getContext()->requestTimeoutAtTime(when + + mConfig.pointerGestureTapDragInterval); mPointerGesture.activeGestureId = 0; mPointerGesture.currentGestureMode = PointerGesture::TAP; mPointerGesture.currentGestureIdBits.clear(); - mPointerGesture.currentGestureIdBits.markBit( - mPointerGesture.activeGestureId); - mPointerGesture.currentGestureIdToIndex[ - mPointerGesture.activeGestureId] = 0; + mPointerGesture.currentGestureIdBits.markBit(mPointerGesture.activeGestureId); + mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0; mPointerGesture.currentGestureProperties[0].clear(); mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId; mPointerGesture.currentGestureProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; mPointerGesture.currentGestureCoords[0].clear(); - mPointerGesture.currentGestureCoords[0].setAxisValue( - AMOTION_EVENT_AXIS_X, mPointerGesture.tapX); - mPointerGesture.currentGestureCoords[0].setAxisValue( - AMOTION_EVENT_AXIS_Y, mPointerGesture.tapY); - mPointerGesture.currentGestureCoords[0].setAxisValue( - AMOTION_EVENT_AXIS_PRESSURE, 1.0f); + mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, + mPointerGesture.tapX); + mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, + mPointerGesture.tapY); + mPointerGesture.currentGestureCoords[0] + .setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f); tapped = true; } else { #if DEBUG_GESTURES - ALOGD("Gestures: Not a TAP, deltaX=%f, deltaY=%f", - x - mPointerGesture.tapX, - y - mPointerGesture.tapY); + ALOGD("Gestures: Not a TAP, deltaX=%f, deltaY=%f", x - mPointerGesture.tapX, + y - mPointerGesture.tapY); #endif } } else { #if DEBUG_GESTURES if (mPointerGesture.tapDownTime != LLONG_MIN) { ALOGD("Gestures: Not a TAP, %0.3fms since down", - (when - mPointerGesture.tapDownTime) * 0.000001f); + (when - mPointerGesture.tapDownTime) * 0.000001f); } else { ALOGD("Gestures: Not a TAP, incompatible mode transitions"); } @@ -5836,20 +5747,19 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, if (when <= mPointerGesture.tapUpTime + mConfig.pointerGestureTapDragInterval) { float x, y; mPointerController->getPosition(&x, &y); - if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop - && fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) { + if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop && + fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) { mPointerGesture.currentGestureMode = PointerGesture::TAP_DRAG; } else { #if DEBUG_GESTURES ALOGD("Gestures: Not a TAP_DRAG, deltaX=%f, deltaY=%f", - x - mPointerGesture.tapX, - y - mPointerGesture.tapY); + x - mPointerGesture.tapX, y - mPointerGesture.tapY); #endif } } else { #if DEBUG_GESTURES ALOGD("Gestures: Not a TAP_DRAG, %0.3fms time since up", - (when - mPointerGesture.tapUpTime) * 0.000001f); + (when - mPointerGesture.tapUpTime) * 0.000001f); #endif } } else if (mPointerGesture.lastGestureMode == PointerGesture::TAP_DRAG) { @@ -5900,13 +5810,12 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0; mPointerGesture.currentGestureProperties[0].clear(); mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId; - mPointerGesture.currentGestureProperties[0].toolType = - AMOTION_EVENT_TOOL_TYPE_FINGER; + mPointerGesture.currentGestureProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; mPointerGesture.currentGestureCoords[0].clear(); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, - down ? 1.0f : 0.0f); + down ? 1.0f : 0.0f); if (lastFingerCount == 0 && currentFingerCount != 0) { mPointerGesture.resetTap(); @@ -5930,20 +5839,20 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, // a decision to transition into SWIPE or FREEFORM mode accordingly. ALOG_ASSERT(activeTouchId >= 0); - bool settled = when >= mPointerGesture.firstTouchTime - + mConfig.pointerGestureMultitouchSettleInterval; - if (mPointerGesture.lastGestureMode != PointerGesture::PRESS - && mPointerGesture.lastGestureMode != PointerGesture::SWIPE - && mPointerGesture.lastGestureMode != PointerGesture::FREEFORM) { + bool settled = when >= + mPointerGesture.firstTouchTime + mConfig.pointerGestureMultitouchSettleInterval; + if (mPointerGesture.lastGestureMode != PointerGesture::PRESS && + mPointerGesture.lastGestureMode != PointerGesture::SWIPE && + mPointerGesture.lastGestureMode != PointerGesture::FREEFORM) { *outFinishPreviousGesture = true; } else if (!settled && currentFingerCount > lastFingerCount) { // Additional pointers have gone down but not yet settled. // Reset the gesture. #if DEBUG_GESTURES ALOGD("Gestures: Resetting gesture since additional pointers went down for MULTITOUCH, " - "settle time remaining %0.3fms", (mPointerGesture.firstTouchTime - + mConfig.pointerGestureMultitouchSettleInterval - when) - * 0.000001f); + "settle time remaining %0.3fms", + (mPointerGesture.firstTouchTime + mConfig.pointerGestureMultitouchSettleInterval - + when) * 0.000001f); #endif *outCancelPreviousGesture = true; } else { @@ -5960,20 +5869,21 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, // Use the centroid and pointer location as the reference points for the gesture. #if DEBUG_GESTURES ALOGD("Gestures: Using centroid as reference for MULTITOUCH, " - "settle time remaining %0.3fms", (mPointerGesture.firstTouchTime - + mConfig.pointerGestureMultitouchSettleInterval - when) - * 0.000001f); + "settle time remaining %0.3fms", + (mPointerGesture.firstTouchTime + mConfig.pointerGestureMultitouchSettleInterval - + when) * 0.000001f); #endif - mCurrentRawState.rawPointerData.getCentroidOfTouchingPointers( - &mPointerGesture.referenceTouchX, - &mPointerGesture.referenceTouchY); + mCurrentRawState.rawPointerData + .getCentroidOfTouchingPointers(&mPointerGesture.referenceTouchX, + &mPointerGesture.referenceTouchY); mPointerController->getPosition(&mPointerGesture.referenceGestureX, - &mPointerGesture.referenceGestureY); + &mPointerGesture.referenceGestureY); } // Clear the reference deltas for fingers not yet included in the reference calculation. - for (BitSet32 idBits(mCurrentCookedState.fingerIdBits.value - & ~mPointerGesture.referenceIdBits.value); !idBits.isEmpty(); ) { + for (BitSet32 idBits(mCurrentCookedState.fingerIdBits.value & + ~mPointerGesture.referenceIdBits.value); + !idBits.isEmpty();) { uint32_t id = idBits.clearFirstMarkedBit(); mPointerGesture.referenceDeltas[id].dx = 0; mPointerGesture.referenceDeltas[id].dy = 0; @@ -5982,9 +5892,9 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, // Add delta for all fingers and calculate a common movement delta. float commonDeltaX = 0, commonDeltaY = 0; - BitSet32 commonIdBits(mLastCookedState.fingerIdBits.value - & mCurrentCookedState.fingerIdBits.value); - for (BitSet32 idBits(commonIdBits); !idBits.isEmpty(); ) { + BitSet32 commonIdBits(mLastCookedState.fingerIdBits.value & + mCurrentCookedState.fingerIdBits.value); + for (BitSet32 idBits(commonIdBits); !idBits.isEmpty();) { bool first = (idBits == commonIdBits); uint32_t id = idBits.clearFirstMarkedBit(); const RawPointerData::Pointer& cpd = mCurrentRawState.rawPointerData.pointerForId(id); @@ -6006,11 +5916,10 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, if (mPointerGesture.currentGestureMode == PointerGesture::PRESS) { float dist[MAX_POINTER_ID + 1]; int32_t distOverThreshold = 0; - for (BitSet32 idBits(mPointerGesture.referenceIdBits); !idBits.isEmpty(); ) { + for (BitSet32 idBits(mPointerGesture.referenceIdBits); !idBits.isEmpty();) { uint32_t id = idBits.clearFirstMarkedBit(); PointerGesture::Delta& delta = mPointerGesture.referenceDeltas[id]; - dist[id] = hypotf(delta.dx * mPointerXZoomScale, - delta.dy * mPointerYZoomScale); + dist[id] = hypotf(delta.dx * mPointerXZoomScale, delta.dy * mPointerYZoomScale); if (dist[id] > mConfig.pointerGestureMultitouchMinDistance) { distOverThreshold += 1; } @@ -6023,7 +5932,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, // There are more than two pointers, switch to FREEFORM. #if DEBUG_GESTURES ALOGD("Gestures: PRESS transitioned to FREEFORM, number of pointers %d > 2", - currentFingerCount); + currentFingerCount); #endif *outCancelPreviousGesture = true; mPointerGesture.currentGestureMode = PointerGesture::FREEFORM; @@ -6042,7 +5951,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, // switch to FREEFORM. #if DEBUG_GESTURES ALOGD("Gestures: PRESS transitioned to FREEFORM, distance %0.3f > %0.3f", - mutualDistance, mPointerGestureMaxSwipeWidth); + mutualDistance, mPointerGestureMaxSwipeWidth); #endif *outCancelPreviousGesture = true; mPointerGesture.currentGestureMode = PointerGesture::FREEFORM; @@ -6051,12 +5960,13 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, // before deciding whether this is a SWIPE or FREEFORM gesture. float dist1 = dist[id1]; float dist2 = dist[id2]; - if (dist1 >= mConfig.pointerGestureMultitouchMinDistance - && dist2 >= mConfig.pointerGestureMultitouchMinDistance) { + if (dist1 >= mConfig.pointerGestureMultitouchMinDistance && + dist2 >= mConfig.pointerGestureMultitouchMinDistance) { // Calculate the dot product of the displacement vectors. // When the vectors are oriented in approximately the same direction, // the angle betweeen them is near zero and the cosine of the angle - // approches 1.0. Recall that dot(v1, v2) = cos(angle) * mag(v1) * mag(v2). + // approches 1.0. Recall that dot(v1, v2) = cos(angle) * mag(v1) * + // mag(v2). PointerGesture::Delta& delta1 = mPointerGesture.referenceDeltas[id1]; PointerGesture::Delta& delta2 = mPointerGesture.referenceDeltas[id2]; float dx1 = delta1.dx * mPointerXZoomScale; @@ -6069,22 +5979,22 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, // Pointers are moving in the same direction. Switch to SWIPE. #if DEBUG_GESTURES ALOGD("Gestures: PRESS transitioned to SWIPE, " - "dist1 %0.3f >= %0.3f, dist2 %0.3f >= %0.3f, " - "cosine %0.3f >= %0.3f", - dist1, mConfig.pointerGestureMultitouchMinDistance, - dist2, mConfig.pointerGestureMultitouchMinDistance, - cosine, mConfig.pointerGestureSwipeTransitionAngleCosine); + "dist1 %0.3f >= %0.3f, dist2 %0.3f >= %0.3f, " + "cosine %0.3f >= %0.3f", + dist1, mConfig.pointerGestureMultitouchMinDistance, dist2, + mConfig.pointerGestureMultitouchMinDistance, cosine, + mConfig.pointerGestureSwipeTransitionAngleCosine); #endif mPointerGesture.currentGestureMode = PointerGesture::SWIPE; } else { // Pointers are moving in different directions. Switch to FREEFORM. #if DEBUG_GESTURES ALOGD("Gestures: PRESS transitioned to FREEFORM, " - "dist1 %0.3f >= %0.3f, dist2 %0.3f >= %0.3f, " - "cosine %0.3f < %0.3f", - dist1, mConfig.pointerGestureMultitouchMinDistance, - dist2, mConfig.pointerGestureMultitouchMinDistance, - cosine, mConfig.pointerGestureSwipeTransitionAngleCosine); + "dist1 %0.3f >= %0.3f, dist2 %0.3f >= %0.3f, " + "cosine %0.3f < %0.3f", + dist1, mConfig.pointerGestureMultitouchMinDistance, dist2, + mConfig.pointerGestureMultitouchMinDistance, cosine, + mConfig.pointerGestureSwipeTransitionAngleCosine); #endif *outCancelPreviousGesture = true; mPointerGesture.currentGestureMode = PointerGesture::FREEFORM; @@ -6099,7 +6009,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, if (currentFingerCount > 2) { #if DEBUG_GESTURES ALOGD("Gestures: SWIPE transitioned to FREEFORM, number of pointers %d > 2", - currentFingerCount); + currentFingerCount); #endif *outCancelPreviousGesture = true; mPointerGesture.currentGestureMode = PointerGesture::FREEFORM; @@ -6108,9 +6018,9 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, // Move the reference points based on the overall group motion of the fingers // except in PRESS mode while waiting for a transition to occur. - if (mPointerGesture.currentGestureMode != PointerGesture::PRESS - && (commonDeltaX || commonDeltaY)) { - for (BitSet32 idBits(mPointerGesture.referenceIdBits); !idBits.isEmpty(); ) { + if (mPointerGesture.currentGestureMode != PointerGesture::PRESS && + (commonDeltaX || commonDeltaY)) { + for (BitSet32 idBits(mPointerGesture.referenceIdBits); !idBits.isEmpty();) { uint32_t id = idBits.clearFirstMarkedBit(); PointerGesture::Delta& delta = mPointerGesture.referenceDeltas[id]; delta.dx = 0; @@ -6131,13 +6041,13 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, } // Report gestures. - if (mPointerGesture.currentGestureMode == PointerGesture::PRESS - || mPointerGesture.currentGestureMode == PointerGesture::SWIPE) { + if (mPointerGesture.currentGestureMode == PointerGesture::PRESS || + mPointerGesture.currentGestureMode == PointerGesture::SWIPE) { // PRESS or SWIPE mode. #if DEBUG_GESTURES ALOGD("Gestures: PRESS or SWIPE activeTouchId=%d," - "activeGestureId=%d, currentTouchPointerCount=%d", - activeTouchId, mPointerGesture.activeGestureId, currentFingerCount); + "activeGestureId=%d, currentTouchPointerCount=%d", + activeTouchId, mPointerGesture.activeGestureId, currentFingerCount); #endif ALOG_ASSERT(mPointerGesture.activeGestureId >= 0); @@ -6146,20 +6056,19 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0; mPointerGesture.currentGestureProperties[0].clear(); mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId; - mPointerGesture.currentGestureProperties[0].toolType = - AMOTION_EVENT_TOOL_TYPE_FINGER; + mPointerGesture.currentGestureProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; mPointerGesture.currentGestureCoords[0].clear(); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, - mPointerGesture.referenceGestureX); + mPointerGesture.referenceGestureX); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, - mPointerGesture.referenceGestureY); + mPointerGesture.referenceGestureY); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f); } else if (mPointerGesture.currentGestureMode == PointerGesture::FREEFORM) { // FREEFORM mode. #if DEBUG_GESTURES ALOGD("Gestures: FREEFORM activeTouchId=%d," - "activeGestureId=%d, currentTouchPointerCount=%d", - activeTouchId, mPointerGesture.activeGestureId, currentFingerCount); + "activeGestureId=%d, currentTouchPointerCount=%d", + activeTouchId, mPointerGesture.activeGestureId, currentFingerCount); #endif ALOG_ASSERT(mPointerGesture.activeGestureId >= 0); @@ -6181,15 +6090,15 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, } else { // Otherwise, assume we mapped all touches from the previous frame. // Reuse all mappings that are still applicable. - mappedTouchIdBits.value = mLastCookedState.fingerIdBits.value - & mCurrentCookedState.fingerIdBits.value; + mappedTouchIdBits.value = mLastCookedState.fingerIdBits.value & + mCurrentCookedState.fingerIdBits.value; usedGestureIdBits = mPointerGesture.lastGestureIdBits; // Check whether we need to choose a new active gesture id because the // current went went up. - for (BitSet32 upTouchIdBits(mLastCookedState.fingerIdBits.value - & ~mCurrentCookedState.fingerIdBits.value); - !upTouchIdBits.isEmpty(); ) { + for (BitSet32 upTouchIdBits(mLastCookedState.fingerIdBits.value & + ~mCurrentCookedState.fingerIdBits.value); + !upTouchIdBits.isEmpty();) { uint32_t upTouchId = upTouchIdBits.clearFirstMarkedBit(); uint32_t upGestureId = mPointerGesture.freeformTouchToGestureIdMap[upTouchId]; if (upGestureId == uint32_t(mPointerGesture.activeGestureId)) { @@ -6201,10 +6110,10 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, #if DEBUG_GESTURES ALOGD("Gestures: FREEFORM follow up " - "mappedTouchIdBits=0x%08x, usedGestureIdBits=0x%08x, " - "activeGestureId=%d", - mappedTouchIdBits.value, usedGestureIdBits.value, - mPointerGesture.activeGestureId); + "mappedTouchIdBits=0x%08x, usedGestureIdBits=0x%08x, " + "activeGestureId=%d", + mappedTouchIdBits.value, usedGestureIdBits.value, + mPointerGesture.activeGestureId); #endif BitSet32 idBits(mCurrentCookedState.fingerIdBits); @@ -6216,15 +6125,15 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, mPointerGesture.freeformTouchToGestureIdMap[touchId] = gestureId; #if DEBUG_GESTURES ALOGD("Gestures: FREEFORM " - "new mapping for touch id %d -> gesture id %d", - touchId, gestureId); + "new mapping for touch id %d -> gesture id %d", + touchId, gestureId); #endif } else { gestureId = mPointerGesture.freeformTouchToGestureIdMap[touchId]; #if DEBUG_GESTURES ALOGD("Gestures: FREEFORM " - "existing mapping for touch id %d -> gesture id %d", - touchId, gestureId); + "existing mapping for touch id %d -> gesture id %d", + touchId, gestureId); #endif } mPointerGesture.currentGestureIdBits.markBit(gestureId); @@ -6232,10 +6141,8 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, const RawPointerData::Pointer& pointer = mCurrentRawState.rawPointerData.pointerForId(touchId); - float deltaX = (pointer.x - mPointerGesture.referenceTouchX) - * mPointerXZoomScale; - float deltaY = (pointer.y - mPointerGesture.referenceTouchY) - * mPointerYZoomScale; + float deltaX = (pointer.x - mPointerGesture.referenceTouchX) * mPointerXZoomScale; + float deltaY = (pointer.y - mPointerGesture.referenceTouchY) * mPointerYZoomScale; rotateDelta(mSurfaceOrientation, &deltaX, &deltaY); mPointerGesture.currentGestureProperties[i].clear(); @@ -6243,12 +6150,14 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, mPointerGesture.currentGestureProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; mPointerGesture.currentGestureCoords[i].clear(); - mPointerGesture.currentGestureCoords[i].setAxisValue( - AMOTION_EVENT_AXIS_X, mPointerGesture.referenceGestureX + deltaX); - mPointerGesture.currentGestureCoords[i].setAxisValue( - AMOTION_EVENT_AXIS_Y, mPointerGesture.referenceGestureY + deltaY); - mPointerGesture.currentGestureCoords[i].setAxisValue( - AMOTION_EVENT_AXIS_PRESSURE, 1.0f); + mPointerGesture.currentGestureCoords[i] + .setAxisValue(AMOTION_EVENT_AXIS_X, + mPointerGesture.referenceGestureX + deltaX); + mPointerGesture.currentGestureCoords[i] + .setAxisValue(AMOTION_EVENT_AXIS_Y, + mPointerGesture.referenceGestureY + deltaY); + mPointerGesture.currentGestureCoords[i].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, + 1.0f); } if (mPointerGesture.activeGestureId < 0) { @@ -6256,7 +6165,8 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, mPointerGesture.currentGestureIdBits.firstMarkedBit(); #if DEBUG_GESTURES ALOGD("Gestures: FREEFORM new " - "activeGestureId=%d", mPointerGesture.activeGestureId); + "activeGestureId=%d", + mPointerGesture.activeGestureId); #endif } } @@ -6266,34 +6176,32 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, #if DEBUG_GESTURES ALOGD("Gestures: finishPreviousGesture=%s, cancelPreviousGesture=%s, " - "currentGestureMode=%d, currentGestureIdBits=0x%08x, " - "lastGestureMode=%d, lastGestureIdBits=0x%08x", - toString(*outFinishPreviousGesture), toString(*outCancelPreviousGesture), - mPointerGesture.currentGestureMode, mPointerGesture.currentGestureIdBits.value, - mPointerGesture.lastGestureMode, mPointerGesture.lastGestureIdBits.value); - for (BitSet32 idBits = mPointerGesture.currentGestureIdBits; !idBits.isEmpty(); ) { + "currentGestureMode=%d, currentGestureIdBits=0x%08x, " + "lastGestureMode=%d, lastGestureIdBits=0x%08x", + toString(*outFinishPreviousGesture), toString(*outCancelPreviousGesture), + mPointerGesture.currentGestureMode, mPointerGesture.currentGestureIdBits.value, + mPointerGesture.lastGestureMode, mPointerGesture.lastGestureIdBits.value); + for (BitSet32 idBits = mPointerGesture.currentGestureIdBits; !idBits.isEmpty();) { uint32_t id = idBits.clearFirstMarkedBit(); uint32_t index = mPointerGesture.currentGestureIdToIndex[id]; const PointerProperties& properties = mPointerGesture.currentGestureProperties[index]; const PointerCoords& coords = mPointerGesture.currentGestureCoords[index]; ALOGD(" currentGesture[%d]: index=%d, toolType=%d, " - "x=%0.3f, y=%0.3f, pressure=%0.3f", - id, index, properties.toolType, - coords.getAxisValue(AMOTION_EVENT_AXIS_X), - coords.getAxisValue(AMOTION_EVENT_AXIS_Y), - coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE)); + "x=%0.3f, y=%0.3f, pressure=%0.3f", + id, index, properties.toolType, coords.getAxisValue(AMOTION_EVENT_AXIS_X), + coords.getAxisValue(AMOTION_EVENT_AXIS_Y), + coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE)); } - for (BitSet32 idBits = mPointerGesture.lastGestureIdBits; !idBits.isEmpty(); ) { + for (BitSet32 idBits = mPointerGesture.lastGestureIdBits; !idBits.isEmpty();) { uint32_t id = idBits.clearFirstMarkedBit(); uint32_t index = mPointerGesture.lastGestureIdToIndex[id]; const PointerProperties& properties = mPointerGesture.lastGestureProperties[index]; const PointerCoords& coords = mPointerGesture.lastGestureCoords[index]; ALOGD(" lastGesture[%d]: index=%d, toolType=%d, " - "x=%0.3f, y=%0.3f, pressure=%0.3f", - id, index, properties.toolType, - coords.getAxisValue(AMOTION_EVENT_AXIS_X), - coords.getAxisValue(AMOTION_EVENT_AXIS_Y), - coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE)); + "x=%0.3f, y=%0.3f, pressure=%0.3f", + id, index, properties.toolType, coords.getAxisValue(AMOTION_EVENT_AXIS_X), + coords.getAxisValue(AMOTION_EVENT_AXIS_Y), + coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE)); } #endif return true; @@ -6345,12 +6253,12 @@ void TouchInputMapper::dispatchPointerMouse(nsecs_t when, uint32_t policyFlags) float deltaX = 0, deltaY = 0; if (mLastCookedState.mouseIdBits.hasBit(id)) { uint32_t lastIndex = mCurrentRawState.rawPointerData.idToIndex[id]; - deltaX = (mCurrentRawState.rawPointerData.pointers[currentIndex].x - - mLastRawState.rawPointerData.pointers[lastIndex].x) - * mPointerXMovementScale; - deltaY = (mCurrentRawState.rawPointerData.pointers[currentIndex].y - - mLastRawState.rawPointerData.pointers[lastIndex].y) - * mPointerYMovementScale; + deltaX = (mCurrentRawState.rawPointerData.pointers[currentIndex].x - + mLastRawState.rawPointerData.pointers[lastIndex].x) * + mPointerXMovementScale; + deltaY = (mCurrentRawState.rawPointerData.pointers[currentIndex].y - + mLastRawState.rawPointerData.pointers[lastIndex].y) * + mPointerYMovementScale; rotateDelta(mSurfaceOrientation, &deltaX, &deltaY); mPointerVelocityControl.move(when, &deltaX, &deltaY); @@ -6370,7 +6278,7 @@ void TouchInputMapper::dispatchPointerMouse(nsecs_t when, uint32_t policyFlags) mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x); mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y); mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, - hovering ? 0.0f : 1.0f); + hovering ? 0.0f : 1.0f); mPointerSimple.currentProperties.id = 0; mPointerSimple.currentProperties.toolType = mCurrentCookedState.cookedPointerData.pointerProperties[currentIndex].toolType; @@ -6390,8 +6298,8 @@ void TouchInputMapper::abortPointerMouse(nsecs_t when, uint32_t policyFlags) { mPointerVelocityControl.reset(); } -void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, - bool down, bool hovering) { +void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, bool down, + bool hovering) { int32_t metaState = getContext()->getGlobalMetaState(); int32_t displayId = mViewport.displayId; @@ -6575,7 +6483,7 @@ void TouchInputMapper::dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32 const int32_t deviceId = getDeviceId(); std::vector<TouchVideoFrame> frames = mDevice->getEventHub()->getVideoFrames(deviceId); std::for_each(frames.begin(), frames.end(), - [this](TouchVideoFrame& frame) { frame.rotate(this->mSurfaceOrientation); }); + [this](TouchVideoFrame& frame) { frame.rotate(this->mSurfaceOrientation); }); NotifyMotionArgs args(mContext->getNextSequenceNum(), when, deviceId, source, displayId, policyFlags, action, actionButton, flags, metaState, buttonState, MotionClassification::NONE, edgeFlags, pointerCount, pointerProperties, @@ -6585,9 +6493,11 @@ void TouchInputMapper::dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32 } bool TouchInputMapper::updateMovedPointers(const PointerProperties* inProperties, - const PointerCoords* inCoords, const uint32_t* inIdToIndex, - PointerProperties* outProperties, PointerCoords* outCoords, const uint32_t* outIdToIndex, - BitSet32 idBits) const { + const PointerCoords* inCoords, + const uint32_t* inIdToIndex, + PointerProperties* outProperties, + PointerCoords* outCoords, const uint32_t* outIdToIndex, + BitSet32 idBits) const { bool changed = false; while (!idBits.isEmpty()) { uint32_t id = idBits.clearFirstMarkedBit(); @@ -6626,26 +6536,23 @@ void TouchInputMapper::cancelTouch(nsecs_t when) { bool TouchInputMapper::isPointInsideSurface(int32_t x, int32_t y) { const float scaledX = x * mXScale; const float scaledY = y * mYScale; - return x >= mRawPointerAxes.x.minValue && x <= mRawPointerAxes.x.maxValue - && scaledX >= mPhysicalLeft && scaledX <= mPhysicalLeft + mPhysicalWidth - && y >= mRawPointerAxes.y.minValue && y <= mRawPointerAxes.y.maxValue - && scaledY >= mPhysicalTop && scaledY <= mPhysicalTop + mPhysicalHeight; + return x >= mRawPointerAxes.x.minValue && x <= mRawPointerAxes.x.maxValue && + scaledX >= mPhysicalLeft && scaledX <= mPhysicalLeft + mPhysicalWidth && + y >= mRawPointerAxes.y.minValue && y <= mRawPointerAxes.y.maxValue && + scaledY >= mPhysicalTop && scaledY <= mPhysicalTop + mPhysicalHeight; } const TouchInputMapper::VirtualKey* TouchInputMapper::findVirtualKeyHit(int32_t x, int32_t y) { - - for (const VirtualKey& virtualKey: mVirtualKeys) { + for (const VirtualKey& virtualKey : mVirtualKeys) { #if DEBUG_VIRTUAL_KEYS ALOGD("VirtualKeys: Hit test (%d, %d): keyCode=%d, scanCode=%d, " - "left=%d, top=%d, right=%d, bottom=%d", - x, y, - virtualKey.keyCode, virtualKey.scanCode, - virtualKey.hitLeft, virtualKey.hitTop, - virtualKey.hitRight, virtualKey.hitBottom); + "left=%d, top=%d, right=%d, bottom=%d", + x, y, virtualKey.keyCode, virtualKey.scanCode, virtualKey.hitLeft, virtualKey.hitTop, + virtualKey.hitRight, virtualKey.hitBottom); #endif if (virtualKey.isHit(x, y)) { - return & virtualKey; + return &virtualKey; } } @@ -6674,9 +6581,8 @@ void TouchInputMapper::assignPointerIds(const RawState* last, RawState* current) return; } - if (currentPointerCount == 1 && lastPointerCount == 1 - && current->rawPointerData.pointers[0].toolType - == last->rawPointerData.pointers[0].toolType) { + if (currentPointerCount == 1 && lastPointerCount == 1 && + current->rawPointerData.pointers[0].toolType == last->rawPointerData.pointers[0].toolType) { // Only one pointer and no change in count so it must have the same id as before. uint32_t id = last->rawPointerData.pointers[0].id; current->rawPointerData.pointers[0].id = id; @@ -6695,9 +6601,9 @@ void TouchInputMapper::assignPointerIds(const RawState* last, RawState* current) uint32_t heapSize = 0; for (uint32_t currentPointerIndex = 0; currentPointerIndex < currentPointerCount; - currentPointerIndex++) { + currentPointerIndex++) { for (uint32_t lastPointerIndex = 0; lastPointerIndex < lastPointerCount; - lastPointerIndex++) { + lastPointerIndex++) { const RawPointerData::Pointer& currentPointer = current->rawPointerData.pointers[currentPointerIndex]; const RawPointerData::Pointer& lastPointer = @@ -6718,16 +6624,16 @@ void TouchInputMapper::assignPointerIds(const RawState* last, RawState* current) } // Heapify - for (uint32_t startIndex = heapSize / 2; startIndex != 0; ) { + for (uint32_t startIndex = heapSize / 2; startIndex != 0;) { startIndex -= 1; - for (uint32_t parentIndex = startIndex; ;) { + for (uint32_t parentIndex = startIndex;;) { uint32_t childIndex = parentIndex * 2 + 1; if (childIndex >= heapSize) { break; } - if (childIndex + 1 < heapSize - && heap[childIndex + 1].distance < heap[childIndex].distance) { + if (childIndex + 1 < heapSize && + heap[childIndex + 1].distance < heap[childIndex].distance) { childIndex += 1; } @@ -6743,9 +6649,8 @@ void TouchInputMapper::assignPointerIds(const RawState* last, RawState* current) #if DEBUG_POINTER_ASSIGNMENT ALOGD("assignPointerIds - initial distance min-heap: size=%d", heapSize); for (size_t i = 0; i < heapSize; i++) { - ALOGD(" heap[%zu]: cur=%" PRIu32 ", last=%" PRIu32 ", distance=%" PRIu64, - i, heap[i].currentPointerIndex, heap[i].lastPointerIndex, - heap[i].distance); + ALOGD(" heap[%zu]: cur=%" PRIu32 ", last=%" PRIu32 ", distance=%" PRIu64, i, + heap[i].currentPointerIndex, heap[i].lastPointerIndex, heap[i].distance); } #endif @@ -6767,14 +6672,14 @@ void TouchInputMapper::assignPointerIds(const RawState* last, RawState* current) // Previous iterations consumed the root element of the heap. // Pop root element off of the heap (sift down). heap[0] = heap[heapSize]; - for (uint32_t parentIndex = 0; ;) { + for (uint32_t parentIndex = 0;;) { uint32_t childIndex = parentIndex * 2 + 1; if (childIndex >= heapSize) { break; } - if (childIndex + 1 < heapSize - && heap[childIndex + 1].distance < heap[childIndex].distance) { + if (childIndex + 1 < heapSize && + heap[childIndex + 1].distance < heap[childIndex].distance) { childIndex += 1; } @@ -6789,9 +6694,8 @@ void TouchInputMapper::assignPointerIds(const RawState* last, RawState* current) #if DEBUG_POINTER_ASSIGNMENT ALOGD("assignPointerIds - reduced distance min-heap: size=%d", heapSize); for (size_t i = 0; i < heapSize; i++) { - ALOGD(" heap[%zu]: cur=%" PRIu32 ", last=%" PRIu32 ", distance=%" PRIu64, - i, heap[i].currentPointerIndex, heap[i].lastPointerIndex, - heap[i].distance); + ALOGD(" heap[%zu]: cur=%" PRIu32 ", last=%" PRIu32 ", distance=%" PRIu64, i, + heap[i].currentPointerIndex, heap[i].lastPointerIndex, heap[i].distance); } #endif } @@ -6811,13 +6715,14 @@ void TouchInputMapper::assignPointerIds(const RawState* last, RawState* current) current->rawPointerData.pointers[currentPointerIndex].id = id; current->rawPointerData.idToIndex[id] = currentPointerIndex; current->rawPointerData.markIdBit(id, - current->rawPointerData.isHovering(currentPointerIndex)); + current->rawPointerData.isHovering( + currentPointerIndex)); usedIdBits.markBit(id); #if DEBUG_POINTER_ASSIGNMENT - ALOGD("assignPointerIds - matched: cur=%" PRIu32 ", last=%" PRIu32 - ", id=%" PRIu32 ", distance=%" PRIu64, - lastPointerIndex, currentPointerIndex, id, heap[0].distance); + ALOGD("assignPointerIds - matched: cur=%" PRIu32 ", last=%" PRIu32 ", id=%" PRIu32 + ", distance=%" PRIu64, + lastPointerIndex, currentPointerIndex, id, heap[0].distance); #endif break; } @@ -6831,7 +6736,7 @@ void TouchInputMapper::assignPointerIds(const RawState* last, RawState* current) current->rawPointerData.pointers[currentPointerIndex].id = id; current->rawPointerData.idToIndex[id] = currentPointerIndex; current->rawPointerData.markIdBit(id, - current->rawPointerData.isHovering(currentPointerIndex)); + current->rawPointerData.isHovering(currentPointerIndex)); #if DEBUG_POINTER_ASSIGNMENT ALOGD("assignPointerIds - assigned: cur=%" PRIu32 ", id=%" PRIu32, currentPointerIndex, id); @@ -6868,7 +6773,7 @@ int32_t TouchInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode } bool TouchInputMapper::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, - const int32_t* keyCodes, uint8_t* outFlags) { + const int32_t* keyCodes, uint8_t* outFlags) { for (const VirtualKey& virtualKey : mVirtualKeys) { for (size_t i = 0; i < numCodes; i++) { if (virtualKey.keyCode == keyCodes[i]) { @@ -6893,12 +6798,9 @@ std::optional<int32_t> TouchInputMapper::getAssociatedDisplayId() { // --- SingleTouchInputMapper --- -SingleTouchInputMapper::SingleTouchInputMapper(InputDevice* device) : - TouchInputMapper(device) { -} +SingleTouchInputMapper::SingleTouchInputMapper(InputDevice* device) : TouchInputMapper(device) {} -SingleTouchInputMapper::~SingleTouchInputMapper() { -} +SingleTouchInputMapper::~SingleTouchInputMapper() {} void SingleTouchInputMapper::reset(nsecs_t when) { mSingleTouchMotionAccumulator.reset(getDevice()); @@ -6917,10 +6819,10 @@ void SingleTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { outState->rawPointerData.pointerCount = 1; outState->rawPointerData.idToIndex[0] = 0; - bool isHovering = mTouchButtonAccumulator.getToolType() != AMOTION_EVENT_TOOL_TYPE_MOUSE - && (mTouchButtonAccumulator.isHovering() - || (mRawPointerAxes.pressure.valid - && mSingleTouchMotionAccumulator.getAbsolutePressure() <= 0)); + bool isHovering = mTouchButtonAccumulator.getToolType() != AMOTION_EVENT_TOOL_TYPE_MOUSE && + (mTouchButtonAccumulator.isHovering() || + (mRawPointerAxes.pressure.valid && + mSingleTouchMotionAccumulator.getAbsolutePressure() <= 0)); outState->rawPointerData.markIdBit(0, isHovering); RawPointerData::Pointer& outPointer = outState->rawPointerData.pointers[0]; @@ -6960,15 +6862,11 @@ bool SingleTouchInputMapper::hasStylus() const { return mTouchButtonAccumulator.hasStylus(); } - // --- MultiTouchInputMapper --- -MultiTouchInputMapper::MultiTouchInputMapper(InputDevice* device) : - TouchInputMapper(device) { -} +MultiTouchInputMapper::MultiTouchInputMapper(InputDevice* device) : TouchInputMapper(device) {} -MultiTouchInputMapper::~MultiTouchInputMapper() { -} +MultiTouchInputMapper::~MultiTouchInputMapper() {} void MultiTouchInputMapper::reset(nsecs_t when) { mMultiTouchMotionAccumulator.reset(getDevice()); @@ -7000,8 +6898,8 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { if (outCount >= MAX_POINTERS) { #if DEBUG_POINTERS ALOGD("MultiTouch device %s emitted more than maximum of %d pointers; " - "ignoring the rest.", - getDeviceName().c_str(), MAX_POINTERS); + "ignoring the rest.", + getDeviceName().c_str(), MAX_POINTERS); #endif break; // too many fingers! } @@ -7027,9 +6925,9 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { } } - bool isHovering = mTouchButtonAccumulator.getToolType() != AMOTION_EVENT_TOOL_TYPE_MOUSE - && (mTouchButtonAccumulator.isHovering() - || (mRawPointerAxes.pressure.valid && inSlot->getPressure() <= 0)); + bool isHovering = mTouchButtonAccumulator.getToolType() != AMOTION_EVENT_TOOL_TYPE_MOUSE && + (mTouchButtonAccumulator.isHovering() || + (mRawPointerAxes.pressure.valid && inSlot->getPressure() <= 0)); outPointer.isHovering = isHovering; // Assign pointer id using tracking id if available. @@ -7037,7 +6935,7 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { int32_t trackingId = inSlot->getTrackingId(); int32_t id = -1; if (trackingId >= 0) { - for (BitSet32 idBits(mPointerIdBits); !idBits.isEmpty(); ) { + for (BitSet32 idBits(mPointerIdBits); !idBits.isEmpty();) { uint32_t n = idBits.clearFirstMarkedBit(); if (mPointerTrackingIdMap[n] == trackingId) { id = n; @@ -7084,35 +6982,29 @@ void MultiTouchInputMapper::configureRawPointerAxes() { getAbsoluteAxisInfo(ABS_MT_TRACKING_ID, &mRawPointerAxes.trackingId); getAbsoluteAxisInfo(ABS_MT_SLOT, &mRawPointerAxes.slot); - if (mRawPointerAxes.trackingId.valid - && mRawPointerAxes.slot.valid - && mRawPointerAxes.slot.minValue == 0 && mRawPointerAxes.slot.maxValue > 0) { + if (mRawPointerAxes.trackingId.valid && mRawPointerAxes.slot.valid && + mRawPointerAxes.slot.minValue == 0 && mRawPointerAxes.slot.maxValue > 0) { size_t slotCount = mRawPointerAxes.slot.maxValue + 1; if (slotCount > MAX_SLOTS) { ALOGW("MultiTouch Device %s reported %zu slots but the framework " - "only supports a maximum of %zu slots at this time.", - getDeviceName().c_str(), slotCount, MAX_SLOTS); + "only supports a maximum of %zu slots at this time.", + getDeviceName().c_str(), slotCount, MAX_SLOTS); slotCount = MAX_SLOTS; } - mMultiTouchMotionAccumulator.configure(getDevice(), - slotCount, true /*usingSlotsProtocol*/); + mMultiTouchMotionAccumulator.configure(getDevice(), slotCount, true /*usingSlotsProtocol*/); } else { - mMultiTouchMotionAccumulator.configure(getDevice(), - MAX_POINTERS, false /*usingSlotsProtocol*/); + mMultiTouchMotionAccumulator.configure(getDevice(), MAX_POINTERS, + false /*usingSlotsProtocol*/); } } bool MultiTouchInputMapper::hasStylus() const { - return mMultiTouchMotionAccumulator.hasStylus() - || mTouchButtonAccumulator.hasStylus(); + return mMultiTouchMotionAccumulator.hasStylus() || mTouchButtonAccumulator.hasStylus(); } // --- ExternalStylusInputMapper -ExternalStylusInputMapper::ExternalStylusInputMapper(InputDevice* device) : - InputMapper(device) { - -} +ExternalStylusInputMapper::ExternalStylusInputMapper(InputDevice* device) : InputMapper(device) {} uint32_t ExternalStylusInputMapper::getSources() { return AINPUT_SOURCE_STYLUS; @@ -7120,8 +7012,8 @@ uint32_t ExternalStylusInputMapper::getSources() { void ExternalStylusInputMapper::populateDeviceInfo(InputDeviceInfo* info) { InputMapper::populateDeviceInfo(info); - info->addMotionRange(AMOTION_EVENT_AXIS_PRESSURE, AINPUT_SOURCE_STYLUS, - 0.0f, 1.0f, 0.0f, 0.0f, 0.0f); + info->addMotionRange(AMOTION_EVENT_AXIS_PRESSURE, AINPUT_SOURCE_STYLUS, 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f); } void ExternalStylusInputMapper::dump(std::string& dump) { @@ -7132,8 +7024,8 @@ void ExternalStylusInputMapper::dump(std::string& dump) { dumpStylusState(dump, mStylusState); } -void ExternalStylusInputMapper::configure(nsecs_t when, - const InputReaderConfiguration* config, uint32_t changes) { +void ExternalStylusInputMapper::configure(nsecs_t when, const InputReaderConfiguration* config, + uint32_t changes) { getAbsoluteAxisInfo(ABS_PRESSURE, &mRawPressureAxis); mTouchButtonAccumulator.configure(getDevice()); } @@ -7178,15 +7070,11 @@ void ExternalStylusInputMapper::sync(nsecs_t when) { mContext->dispatchExternalStylusState(mStylusState); } - // --- JoystickInputMapper --- -JoystickInputMapper::JoystickInputMapper(InputDevice* device) : - InputMapper(device) { -} +JoystickInputMapper::JoystickInputMapper(InputDevice* device) : InputMapper(device) {} -JoystickInputMapper::~JoystickInputMapper() { -} +JoystickInputMapper::~JoystickInputMapper() {} uint32_t JoystickInputMapper::getSources() { return AINPUT_SOURCE_JOYSTICK; @@ -7201,22 +7089,20 @@ void JoystickInputMapper::populateDeviceInfo(InputDeviceInfo* info) { if (axis.axisInfo.mode == AxisInfo::MODE_SPLIT) { addMotionRange(axis.axisInfo.highAxis, axis, info); - } } } -void JoystickInputMapper::addMotionRange(int32_t axisId, const Axis& axis, - InputDeviceInfo* info) { - info->addMotionRange(axisId, AINPUT_SOURCE_JOYSTICK, - axis.min, axis.max, axis.flat, axis.fuzz, axis.resolution); +void JoystickInputMapper::addMotionRange(int32_t axisId, const Axis& axis, InputDeviceInfo* info) { + info->addMotionRange(axisId, AINPUT_SOURCE_JOYSTICK, axis.min, axis.max, axis.flat, axis.fuzz, + axis.resolution); /* In order to ease the transition for developers from using the old axes * to the newer, more semantically correct axes, we'll continue to register * the old axes as duplicates of their corresponding new ones. */ int32_t compatAxis = getCompatAxis(axisId); if (compatAxis >= 0) { - info->addMotionRange(compatAxis, AINPUT_SOURCE_JOYSTICK, - axis.min, axis.max, axis.flat, axis.fuzz, axis.resolution); + info->addMotionRange(compatAxis, AINPUT_SOURCE_JOYSTICK, axis.min, axis.max, axis.flat, + axis.fuzz, axis.resolution); } } @@ -7224,11 +7110,11 @@ void JoystickInputMapper::addMotionRange(int32_t axisId, const Axis& axis, * artificially created for compatibility purposes. * Returns -1 if no compatibility axis is needed. */ int32_t JoystickInputMapper::getCompatAxis(int32_t axis) { - switch(axis) { - case AMOTION_EVENT_AXIS_LTRIGGER: - return AMOTION_EVENT_AXIS_BRAKE; - case AMOTION_EVENT_AXIS_RTRIGGER: - return AMOTION_EVENT_AXIS_GAS; + switch (axis) { + case AMOTION_EVENT_AXIS_LTRIGGER: + return AMOTION_EVENT_AXIS_BRAKE; + case AMOTION_EVENT_AXIS_RTRIGGER: + return AMOTION_EVENT_AXIS_GAS; } return -1; } @@ -7252,33 +7138,33 @@ void JoystickInputMapper::dump(std::string& dump) { dump += StringPrintf(" / %s (split at %d)", label, axis.axisInfo.splitValue); } else { dump += StringPrintf(" / %d (split at %d)", axis.axisInfo.highAxis, - axis.axisInfo.splitValue); + axis.axisInfo.splitValue); } } else if (axis.axisInfo.mode == AxisInfo::MODE_INVERT) { dump += " (invert)"; } dump += StringPrintf(": min=%0.5f, max=%0.5f, flat=%0.5f, fuzz=%0.5f, resolution=%0.5f\n", - axis.min, axis.max, axis.flat, axis.fuzz, axis.resolution); + axis.min, axis.max, axis.flat, axis.fuzz, axis.resolution); dump += StringPrintf(INDENT4 " scale=%0.5f, offset=%0.5f, " - "highScale=%0.5f, highOffset=%0.5f\n", - axis.scale, axis.offset, axis.highScale, axis.highOffset); + "highScale=%0.5f, highOffset=%0.5f\n", + axis.scale, axis.offset, axis.highScale, axis.highOffset); dump += StringPrintf(INDENT4 " rawAxis=%d, rawMin=%d, rawMax=%d, " - "rawFlat=%d, rawFuzz=%d, rawResolution=%d\n", - mAxes.keyAt(i), axis.rawAxisInfo.minValue, axis.rawAxisInfo.maxValue, - axis.rawAxisInfo.flat, axis.rawAxisInfo.fuzz, axis.rawAxisInfo.resolution); + "rawFlat=%d, rawFuzz=%d, rawResolution=%d\n", + mAxes.keyAt(i), axis.rawAxisInfo.minValue, axis.rawAxisInfo.maxValue, + axis.rawAxisInfo.flat, axis.rawAxisInfo.fuzz, + axis.rawAxisInfo.resolution); } } -void JoystickInputMapper::configure(nsecs_t when, - const InputReaderConfiguration* config, uint32_t changes) { +void JoystickInputMapper::configure(nsecs_t when, const InputReaderConfiguration* config, + uint32_t changes) { InputMapper::configure(when, config, changes); if (!changes) { // first time only // Collect all axes. for (int32_t abs = 0; abs <= ABS_MAX; abs++) { - if (!(getAbsAxisUsage(abs, getDevice()->getClasses()) - & INPUT_DEVICE_CLASS_JOYSTICK)) { + if (!(getAbsAxisUsage(abs, getDevice()->getClasses()) & INPUT_DEVICE_CLASS_JOYSTICK)) { continue; // axis must be claimed by a different device } @@ -7295,31 +7181,28 @@ void JoystickInputMapper::configure(nsecs_t when, } // Apply flat override. - int32_t rawFlat = axisInfo.flatOverride < 0 - ? rawAxisInfo.flat : axisInfo.flatOverride; + int32_t rawFlat = + axisInfo.flatOverride < 0 ? rawAxisInfo.flat : axisInfo.flatOverride; // Calculate scaling factors and limits. Axis axis; if (axisInfo.mode == AxisInfo::MODE_SPLIT) { float scale = 1.0f / (axisInfo.splitValue - rawAxisInfo.minValue); float highScale = 1.0f / (rawAxisInfo.maxValue - axisInfo.splitValue); - axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped, - scale, 0.0f, highScale, 0.0f, - 0.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale, - rawAxisInfo.resolution * scale); + axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped, scale, 0.0f, highScale, + 0.0f, 0.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale, + rawAxisInfo.resolution * scale); } else if (isCenteredAxis(axisInfo.axis)) { float scale = 2.0f / (rawAxisInfo.maxValue - rawAxisInfo.minValue); float offset = avg(rawAxisInfo.minValue, rawAxisInfo.maxValue) * -scale; - axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped, - scale, offset, scale, offset, - -1.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale, - rawAxisInfo.resolution * scale); + axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped, scale, offset, scale, + offset, -1.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale, + rawAxisInfo.resolution * scale); } else { float scale = 1.0f / (rawAxisInfo.maxValue - rawAxisInfo.minValue); - axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped, - scale, 0.0f, scale, 0.0f, - 0.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale, - rawAxisInfo.resolution * scale); + axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped, scale, 0.0f, scale, + 0.0f, 0.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale, + rawAxisInfo.resolution * scale); } // To eliminate noise while the joystick is at rest, filter out small variations @@ -7334,7 +7217,7 @@ void JoystickInputMapper::configure(nsecs_t when, // Prefer to keep explicitly mapped axes. if (mAxes.size() > PointerCoords::MAX_AXES) { ALOGI("Joystick '%s' has %zu axes but the framework only supports a maximum of %d.", - getDeviceName().c_str(), mAxes.size(), PointerCoords::MAX_AXES); + getDeviceName().c_str(), mAxes.size(), PointerCoords::MAX_AXES); pruneAxes(true); pruneAxes(false); } @@ -7345,8 +7228,8 @@ void JoystickInputMapper::configure(nsecs_t when, for (size_t i = 0; i < numAxes; i++) { Axis& axis = mAxes.editValueAt(i); if (axis.axisInfo.axis < 0) { - while (nextGenericAxisId <= AMOTION_EVENT_AXIS_GENERIC_16 - && haveAxis(nextGenericAxisId)) { + while (nextGenericAxisId <= AMOTION_EVENT_AXIS_GENERIC_16 && + haveAxis(nextGenericAxisId)) { nextGenericAxisId += 1; } @@ -7355,8 +7238,8 @@ void JoystickInputMapper::configure(nsecs_t when, nextGenericAxisId += 1; } else { ALOGI("Ignoring joystick '%s' axis %d because all of the generic axis ids " - "have already been assigned to other axes.", - getDeviceName().c_str(), mAxes.keyAt(i)); + "have already been assigned to other axes.", + getDeviceName().c_str(), mAxes.keyAt(i)); mAxes.removeItemsAt(i--); numAxes -= 1; } @@ -7369,9 +7252,8 @@ bool JoystickInputMapper::haveAxis(int32_t axisId) { size_t numAxes = mAxes.size(); for (size_t i = 0; i < numAxes; i++) { const Axis& axis = mAxes.valueAt(i); - if (axis.axisInfo.axis == axisId - || (axis.axisInfo.mode == AxisInfo::MODE_SPLIT - && axis.axisInfo.highAxis == axisId)) { + if (axis.axisInfo.axis == axisId || + (axis.axisInfo.mode == AxisInfo::MODE_SPLIT && axis.axisInfo.highAxis == axisId)) { return true; } } @@ -7385,27 +7267,27 @@ void JoystickInputMapper::pruneAxes(bool ignoreExplicitlyMappedAxes) { continue; } ALOGI("Discarding joystick '%s' axis %d because there are too many axes.", - getDeviceName().c_str(), mAxes.keyAt(i)); + getDeviceName().c_str(), mAxes.keyAt(i)); mAxes.removeItemsAt(i); } } bool JoystickInputMapper::isCenteredAxis(int32_t axis) { switch (axis) { - case AMOTION_EVENT_AXIS_X: - case AMOTION_EVENT_AXIS_Y: - case AMOTION_EVENT_AXIS_Z: - case AMOTION_EVENT_AXIS_RX: - case AMOTION_EVENT_AXIS_RY: - case AMOTION_EVENT_AXIS_RZ: - case AMOTION_EVENT_AXIS_HAT_X: - case AMOTION_EVENT_AXIS_HAT_Y: - case AMOTION_EVENT_AXIS_ORIENTATION: - case AMOTION_EVENT_AXIS_RUDDER: - case AMOTION_EVENT_AXIS_WHEEL: - return true; - default: - return false; + case AMOTION_EVENT_AXIS_X: + case AMOTION_EVENT_AXIS_Y: + case AMOTION_EVENT_AXIS_Z: + case AMOTION_EVENT_AXIS_RX: + case AMOTION_EVENT_AXIS_RY: + case AMOTION_EVENT_AXIS_RZ: + case AMOTION_EVENT_AXIS_HAT_X: + case AMOTION_EVENT_AXIS_HAT_Y: + case AMOTION_EVENT_AXIS_ORIENTATION: + case AMOTION_EVENT_AXIS_RUDDER: + case AMOTION_EVENT_AXIS_WHEEL: + return true; + default: + return false; } } @@ -7422,49 +7304,50 @@ void JoystickInputMapper::reset(nsecs_t when) { void JoystickInputMapper::process(const RawEvent* rawEvent) { switch (rawEvent->type) { - case EV_ABS: { - ssize_t index = mAxes.indexOfKey(rawEvent->code); - if (index >= 0) { - Axis& axis = mAxes.editValueAt(index); - float newValue, highNewValue; - switch (axis.axisInfo.mode) { - case AxisInfo::MODE_INVERT: - newValue = (axis.rawAxisInfo.maxValue - rawEvent->value) - * axis.scale + axis.offset; - highNewValue = 0.0f; - break; - case AxisInfo::MODE_SPLIT: - if (rawEvent->value < axis.axisInfo.splitValue) { - newValue = (axis.axisInfo.splitValue - rawEvent->value) - * axis.scale + axis.offset; - highNewValue = 0.0f; - } else if (rawEvent->value > axis.axisInfo.splitValue) { - newValue = 0.0f; - highNewValue = (rawEvent->value - axis.axisInfo.splitValue) - * axis.highScale + axis.highOffset; - } else { - newValue = 0.0f; - highNewValue = 0.0f; + case EV_ABS: { + ssize_t index = mAxes.indexOfKey(rawEvent->code); + if (index >= 0) { + Axis& axis = mAxes.editValueAt(index); + float newValue, highNewValue; + switch (axis.axisInfo.mode) { + case AxisInfo::MODE_INVERT: + newValue = (axis.rawAxisInfo.maxValue - rawEvent->value) * axis.scale + + axis.offset; + highNewValue = 0.0f; + break; + case AxisInfo::MODE_SPLIT: + if (rawEvent->value < axis.axisInfo.splitValue) { + newValue = (axis.axisInfo.splitValue - rawEvent->value) * axis.scale + + axis.offset; + highNewValue = 0.0f; + } else if (rawEvent->value > axis.axisInfo.splitValue) { + newValue = 0.0f; + highNewValue = + (rawEvent->value - axis.axisInfo.splitValue) * axis.highScale + + axis.highOffset; + } else { + newValue = 0.0f; + highNewValue = 0.0f; + } + break; + default: + newValue = rawEvent->value * axis.scale + axis.offset; + highNewValue = 0.0f; + break; } - break; - default: - newValue = rawEvent->value * axis.scale + axis.offset; - highNewValue = 0.0f; - break; + axis.newValue = newValue; + axis.highNewValue = highNewValue; } - axis.newValue = newValue; - axis.highNewValue = highNewValue; + break; } - break; - } - case EV_SYN: - switch (rawEvent->code) { - case SYN_REPORT: - sync(rawEvent->when, false /*force*/); + case EV_SYN: + switch (rawEvent->code) { + case SYN_REPORT: + sync(rawEvent->when, false /*force*/); + break; + } break; - } - break; } } @@ -7490,7 +7373,7 @@ void JoystickInputMapper::sync(nsecs_t when, bool force) { setPointerCoordsAxisValue(&pointerCoords, axis.axisInfo.axis, axis.currentValue); if (axis.axisInfo.mode == AxisInfo::MODE_SPLIT) { setPointerCoordsAxisValue(&pointerCoords, axis.axisInfo.highAxis, - axis.highCurrentValue); + axis.highCurrentValue); } } @@ -7510,8 +7393,8 @@ void JoystickInputMapper::sync(nsecs_t when, bool force) { getListener()->notifyMotion(&args); } -void JoystickInputMapper::setPointerCoordsAxisValue(PointerCoords* pointerCoords, - int32_t axis, float value) { +void JoystickInputMapper::setPointerCoordsAxisValue(PointerCoords* pointerCoords, int32_t axis, + float value) { pointerCoords->setAxisValue(axis, value); /* In order to ease the transition for developers from using the old axes * to the newer, more semantically correct axes, we'll continue to produce @@ -7528,14 +7411,16 @@ bool JoystickInputMapper::filterAxes(bool force) { size_t numAxes = mAxes.size(); for (size_t i = 0; i < numAxes; i++) { Axis& axis = mAxes.editValueAt(i); - if (force || hasValueChangedSignificantly(axis.filter, - axis.newValue, axis.currentValue, axis.min, axis.max)) { + if (force || + hasValueChangedSignificantly(axis.filter, axis.newValue, axis.currentValue, axis.min, + axis.max)) { axis.currentValue = axis.newValue; atLeastOneSignificantChange = true; } if (axis.axisInfo.mode == AxisInfo::MODE_SPLIT) { - if (force || hasValueChangedSignificantly(axis.filter, - axis.highNewValue, axis.highCurrentValue, axis.min, axis.max)) { + if (force || + hasValueChangedSignificantly(axis.filter, axis.highNewValue, axis.highCurrentValue, + axis.min, axis.max)) { axis.highCurrentValue = axis.highNewValue; atLeastOneSignificantChange = true; } @@ -7544,24 +7429,25 @@ bool JoystickInputMapper::filterAxes(bool force) { return atLeastOneSignificantChange; } -bool JoystickInputMapper::hasValueChangedSignificantly( - float filter, float newValue, float currentValue, float min, float max) { +bool JoystickInputMapper::hasValueChangedSignificantly(float filter, float newValue, + float currentValue, float min, float max) { if (newValue != currentValue) { // Filter out small changes in value unless the value is converging on the axis // bounds or center point. This is intended to reduce the amount of information // sent to applications by particularly noisy joysticks (such as PS3). - if (fabs(newValue - currentValue) > filter - || hasMovedNearerToValueWithinFilteredRange(filter, newValue, currentValue, min) - || hasMovedNearerToValueWithinFilteredRange(filter, newValue, currentValue, max) - || hasMovedNearerToValueWithinFilteredRange(filter, newValue, currentValue, 0)) { + if (fabs(newValue - currentValue) > filter || + hasMovedNearerToValueWithinFilteredRange(filter, newValue, currentValue, min) || + hasMovedNearerToValueWithinFilteredRange(filter, newValue, currentValue, max) || + hasMovedNearerToValueWithinFilteredRange(filter, newValue, currentValue, 0)) { return true; } } return false; } -bool JoystickInputMapper::hasMovedNearerToValueWithinFilteredRange( - float filter, float newValue, float currentValue, float thresholdValue) { +bool JoystickInputMapper::hasMovedNearerToValueWithinFilteredRange(float filter, float newValue, + float currentValue, + float thresholdValue) { float newDistance = fabs(newValue - thresholdValue); if (newDistance < filter) { float oldDistance = fabs(currentValue - thresholdValue); diff --git a/services/inputflinger/InputReaderFactory.cpp b/services/inputflinger/reader/InputReaderFactory.cpp index 072499b9cd..7c2311266c 100644 --- a/services/inputflinger/InputReaderFactory.cpp +++ b/services/inputflinger/reader/InputReaderFactory.cpp @@ -19,9 +19,8 @@ namespace android { -sp<InputReaderInterface> createInputReader( - const sp<InputReaderPolicyInterface>& policy, - const sp<InputListenerInterface>& listener) { +sp<InputReaderInterface> createInputReader(const sp<InputReaderPolicyInterface>& policy, + const sp<InputListenerInterface>& listener) { return new InputReader(std::make_unique<EventHub>(), policy, listener); } diff --git a/services/inputflinger/TouchVideoDevice.cpp b/services/inputflinger/reader/TouchVideoDevice.cpp index 19c1313dcd..c075078528 100644 --- a/services/inputflinger/TouchVideoDevice.cpp +++ b/services/inputflinger/reader/TouchVideoDevice.cpp @@ -37,10 +37,13 @@ using android::base::unique_fd; namespace android { TouchVideoDevice::TouchVideoDevice(int fd, std::string&& name, std::string&& devicePath, - uint32_t height, uint32_t width, - const std::array<const int16_t*, NUM_BUFFERS>& readLocations) : - mFd(fd), mName(std::move(name)), mPath(std::move(devicePath)), - mHeight(height), mWidth(width), + uint32_t height, uint32_t width, + const std::array<const int16_t*, NUM_BUFFERS>& readLocations) + : mFd(fd), + mName(std::move(name)), + mPath(std::move(devicePath)), + mHeight(height), + mWidth(width), mReadLocations(readLocations) { mFrames.reserve(MAX_QUEUE_SIZE); }; @@ -60,11 +63,11 @@ std::unique_ptr<TouchVideoDevice> TouchVideoDevice::create(std::string devicePat } if (!(cap.capabilities & V4L2_CAP_TOUCH)) { ALOGE("Capability V4L2_CAP_TOUCH is not present, can't use device for heatmap data. " - "Make sure device specifies V4L2_CAP_TOUCH"); + "Make sure device specifies V4L2_CAP_TOUCH"); return nullptr; } - ALOGI("Opening video device: driver = %s, card = %s, bus_info = %s, version = %i", - cap.driver, cap.card, cap.bus_info, cap.version); + ALOGI("Opening video device: driver = %s, card = %s, bus_info = %s, version = %i", cap.driver, + cap.card, cap.bus_info, cap.version); std::string name = reinterpret_cast<const char*>(cap.card); struct v4l2_input v4l2_input_struct; @@ -77,7 +80,7 @@ std::unique_ptr<TouchVideoDevice> TouchVideoDevice::create(std::string devicePat if (v4l2_input_struct.type != V4L2_INPUT_TYPE_TOUCH) { ALOGE("Video device does not provide touch data. " - "Make sure device specifies V4L2_INPUT_TYPE_TOUCH."); + "Make sure device specifies V4L2_INPUT_TYPE_TOUCH."); return nullptr; } @@ -120,14 +123,14 @@ std::unique_ptr<TouchVideoDevice> TouchVideoDevice::create(std::string devicePat return nullptr; } if (buf.length != height * width * sizeof(int16_t)) { - ALOGE("Unexpected value of buf.length = %i (offset = %" PRIu32 ")", - buf.length, buf.m.offset); + ALOGE("Unexpected value of buf.length = %i (offset = %" PRIu32 ")", buf.length, + buf.m.offset); return nullptr; } - readLocations[i] = static_cast<const int16_t*>(mmap(nullptr /* start anywhere */, - buf.length, PROT_READ /* required */, MAP_SHARED /* recommended */, - fd.get(), buf.m.offset)); + readLocations[i] = static_cast<const int16_t*>( + mmap(nullptr /* start anywhere */, buf.length, PROT_READ /* required */, + MAP_SHARED /* recommended */, fd.get(), buf.m.offset)); if (readLocations[i] == MAP_FAILED) { ALOGE("%s: map failed: %s", __func__, strerror(errno)); return nullptr; @@ -150,8 +153,9 @@ std::unique_ptr<TouchVideoDevice> TouchVideoDevice::create(std::string devicePat } } // Using 'new' to access a non-public constructor. - return std::unique_ptr<TouchVideoDevice>(new TouchVideoDevice( - fd.release(), std::move(name), std::move(devicePath), height, width, readLocations)); + return std::unique_ptr<TouchVideoDevice>(new TouchVideoDevice(fd.release(), std::move(name), + std::move(devicePath), height, + width, readLocations)); } size_t TouchVideoDevice::readAndQueueFrames() { @@ -163,10 +167,10 @@ size_t TouchVideoDevice::readAndQueueFrames() { } // Concatenate the vectors, then clip up to maximum size allowed mFrames.insert(mFrames.end(), std::make_move_iterator(frames.begin()), - std::make_move_iterator(frames.end())); + std::make_move_iterator(frames.end())); if (mFrames.size() > MAX_QUEUE_SIZE) { ALOGE("More than %zu frames have been accumulated. Dropping %zu frames", MAX_QUEUE_SIZE, - mFrames.size() - MAX_QUEUE_SIZE); + mFrames.size() - MAX_QUEUE_SIZE); mFrames.erase(mFrames.begin(), mFrames.end() - MAX_QUEUE_SIZE); } return numFrames; @@ -193,8 +197,8 @@ std::optional<TouchVideoFrame> TouchVideoDevice::readFrame() { if ((buf.flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) != V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC) { // We use CLOCK_MONOTONIC for input events, so if the clocks don't match, // we can't compare timestamps. Just log a warning, since this is a driver issue - ALOGW("The timestamp %ld.%ld was not acquired using CLOCK_MONOTONIC", - buf.timestamp.tv_sec, buf.timestamp.tv_usec); + ALOGW("The timestamp %ld.%ld was not acquired using CLOCK_MONOTONIC", buf.timestamp.tv_sec, + buf.timestamp.tv_usec); } std::vector<int16_t> data(mHeight * mWidth); const int16_t* readFrom = mReadLocations[buf.index]; @@ -233,7 +237,7 @@ TouchVideoDevice::~TouchVideoDevice() { } for (const int16_t* buffer : mReadLocations) { void* bufferAddress = static_cast<void*>(const_cast<int16_t*>(buffer)); - result = munmap(bufferAddress, mHeight * mWidth * sizeof(int16_t)); + result = munmap(bufferAddress, mHeight * mWidth * sizeof(int16_t)); if (result == -1) { ALOGE("%s: Couldn't unmap: [%s]", __func__, strerror(errno)); } @@ -242,9 +246,9 @@ TouchVideoDevice::~TouchVideoDevice() { std::string TouchVideoDevice::dump() const { return StringPrintf("Video device %s (%s) : height=%" PRIu32 ", width=%" PRIu32 - ", fd=%i, hasValidFd=%s", - mName.c_str(), mPath.c_str(), mHeight, mWidth, mFd.get(), - hasValidFd() ? "true" : "false"); + ", fd=%i, hasValidFd=%s", + mName.c_str(), mPath.c_str(), mHeight, mWidth, mFd.get(), + hasValidFd() ? "true" : "false"); } } // namespace android diff --git a/services/inputflinger/EventHub.h b/services/inputflinger/reader/include/EventHub.h index 6c3a4a2aa3..da0f497b90 100644 --- a/services/inputflinger/EventHub.h +++ b/services/inputflinger/reader/include/EventHub.h @@ -22,17 +22,17 @@ #include <input/Input.h> #include <input/InputDevice.h> -#include <input/Keyboard.h> -#include <input/KeyLayoutMap.h> #include <input/KeyCharacterMap.h> +#include <input/KeyLayoutMap.h> +#include <input/Keyboard.h> #include <input/VirtualKeyMap.h> -#include <utils/Mutex.h> -#include <utils/Log.h> -#include <utils/List.h> +#include <utils/BitSet.h> #include <utils/Errors.h> -#include <utils/PropertyMap.h> #include <utils/KeyedVector.h> -#include <utils/BitSet.h> +#include <utils/List.h> +#include <utils/Log.h> +#include <utils/Mutex.h> +#include <utils/PropertyMap.h> #include <linux/input.h> #include <sys/epoll.h> @@ -41,8 +41,8 @@ /* Convenience constants. */ -#define BTN_FIRST 0x100 // first button code -#define BTN_LAST 0x15f // last button code +#define BTN_FIRST 0x100 // first button code +#define BTN_LAST 0x15f // last button code namespace android { @@ -61,10 +61,10 @@ struct RawEvent { struct RawAbsoluteAxisInfo { bool valid; // true if the information is valid, false otherwise - int32_t minValue; // minimum value - int32_t maxValue; // maximum value - int32_t flat; // center flat position, eg. flat == 8 means center is between -8 and 8 - int32_t fuzz; // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise + int32_t minValue; // minimum value + int32_t maxValue; // maximum value + int32_t flat; // center flat position, eg. flat == 8 means center is between -8 and 8 + int32_t fuzz; // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise int32_t resolution; // resolution in units per mm or radians per mm inline void clear() { @@ -82,37 +82,37 @@ struct RawAbsoluteAxisInfo { */ enum { /* The input device is a keyboard or has buttons. */ - INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001, + INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001, /* The input device is an alpha-numeric keyboard (not just a dial pad). */ - INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002, + INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002, /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */ - INPUT_DEVICE_CLASS_TOUCH = 0x00000004, + INPUT_DEVICE_CLASS_TOUCH = 0x00000004, /* The input device is a cursor device such as a trackball or mouse. */ - INPUT_DEVICE_CLASS_CURSOR = 0x00000008, + INPUT_DEVICE_CLASS_CURSOR = 0x00000008, /* The input device is a multi-touch touchscreen. */ - INPUT_DEVICE_CLASS_TOUCH_MT = 0x00000010, + INPUT_DEVICE_CLASS_TOUCH_MT = 0x00000010, /* The input device is a directional pad (implies keyboard, has DPAD keys). */ - INPUT_DEVICE_CLASS_DPAD = 0x00000020, + INPUT_DEVICE_CLASS_DPAD = 0x00000020, /* The input device is a gamepad (implies keyboard, has BUTTON keys). */ - INPUT_DEVICE_CLASS_GAMEPAD = 0x00000040, + INPUT_DEVICE_CLASS_GAMEPAD = 0x00000040, /* The input device has switches. */ - INPUT_DEVICE_CLASS_SWITCH = 0x00000080, + INPUT_DEVICE_CLASS_SWITCH = 0x00000080, /* The input device is a joystick (implies gamepad, has joystick absolute axes). */ - INPUT_DEVICE_CLASS_JOYSTICK = 0x00000100, + INPUT_DEVICE_CLASS_JOYSTICK = 0x00000100, /* The input device has a vibrator (supports FF_RUMBLE). */ - INPUT_DEVICE_CLASS_VIBRATOR = 0x00000200, + INPUT_DEVICE_CLASS_VIBRATOR = 0x00000200, /* The input device has a microphone. */ - INPUT_DEVICE_CLASS_MIC = 0x00000400, + INPUT_DEVICE_CLASS_MIC = 0x00000400, /* The input device is an external stylus (has data we want to fuse with touch data). */ INPUT_DEVICE_CLASS_EXTERNAL_STYLUS = 0x00000800, @@ -121,10 +121,10 @@ enum { INPUT_DEVICE_CLASS_ROTARY_ENCODER = 0x00001000, /* The input device is virtual (not a real device, not part of UI configuration). */ - INPUT_DEVICE_CLASS_VIRTUAL = 0x40000000, + INPUT_DEVICE_CLASS_VIRTUAL = 0x40000000, /* The input device is external (not built-in). */ - INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000, + INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000, }; /* @@ -148,8 +148,8 @@ extern uint32_t getAbsAxisUsage(int32_t axis, uint32_t deviceClasses); */ class EventHubInterface { public: - EventHubInterface() { } - virtual ~EventHubInterface() { } + EventHubInterface() {} + virtual ~EventHubInterface() {} // Synthetic raw event type codes produced when devices are added or removed. enum { @@ -173,18 +173,17 @@ public: virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const = 0; virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, - RawAbsoluteAxisInfo* outAxisInfo) const = 0; + RawAbsoluteAxisInfo* outAxisInfo) const = 0; virtual bool hasRelativeAxis(int32_t deviceId, int axis) const = 0; virtual bool hasInputProperty(int32_t deviceId, int property) const = 0; - virtual status_t mapKey(int32_t deviceId, - int32_t scanCode, int32_t usageCode, int32_t metaState, - int32_t* outKeycode, int32_t *outMetaState, uint32_t* outFlags) const = 0; + virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, + int32_t metaState, int32_t* outKeycode, int32_t* outMetaState, + uint32_t* outFlags) const = 0; - virtual status_t mapAxis(int32_t deviceId, int32_t scanCode, - AxisInfo* outAxisInfo) const = 0; + virtual status_t mapAxis(int32_t deviceId, int32_t scanCode, AxisInfo* outAxisInfo) const = 0; // Sets devices that are excluded from opening. // This can be used to ignore input devices for sensors. @@ -212,13 +211,13 @@ public: virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const = 0; virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const = 0; virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, - int32_t* outValue) const = 0; + int32_t* outValue) const = 0; /* * Examine key input devices for specific framework keycode support */ virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes, - uint8_t* outFlags) const = 0; + uint8_t* outFlags) const = 0; virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const = 0; @@ -226,8 +225,8 @@ public: virtual bool hasLed(int32_t deviceId, int32_t led) const = 0; virtual void setLedState(int32_t deviceId, int32_t led, bool on) = 0; - virtual void getVirtualKeyDefinitions(int32_t deviceId, - std::vector<VirtualKeyDefinition>& outVirtualKeys) const = 0; + virtual void getVirtualKeyDefinitions( + int32_t deviceId, std::vector<VirtualKeyDefinition>& outVirtualKeys) const = 0; virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const = 0; virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) = 0; @@ -258,8 +257,7 @@ public: virtual status_t disableDevice(int32_t deviceId) = 0; }; -class EventHub : public EventHubInterface -{ +class EventHub : public EventHubInterface { public: EventHub(); @@ -272,18 +270,17 @@ public: virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const; virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, - RawAbsoluteAxisInfo* outAxisInfo) const; + RawAbsoluteAxisInfo* outAxisInfo) const; virtual bool hasRelativeAxis(int32_t deviceId, int axis) const; virtual bool hasInputProperty(int32_t deviceId, int property) const; - virtual status_t mapKey(int32_t deviceId, - int32_t scanCode, int32_t usageCode, int32_t metaState, - int32_t* outKeycode, int32_t *outMetaState, uint32_t* outFlags) const; + virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, + int32_t metaState, int32_t* outKeycode, int32_t* outMetaState, + uint32_t* outFlags) const; - virtual status_t mapAxis(int32_t deviceId, int32_t scanCode, - AxisInfo* outAxisInfo) const; + virtual status_t mapAxis(int32_t deviceId, int32_t scanCode, AxisInfo* outAxisInfo) const; virtual void setExcludedDevices(const std::vector<std::string>& devices); @@ -292,8 +289,8 @@ public: virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const; virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const; - virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, - const int32_t* keyCodes, uint8_t* outFlags) const; + virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes, + uint8_t* outFlags) const; virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize); virtual std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId); @@ -303,7 +300,7 @@ public: virtual void setLedState(int32_t deviceId, int32_t led, bool on); virtual void getVirtualKeyDefinitions(int32_t deviceId, - std::vector<VirtualKeyDefinition>& outVirtualKeys) const; + std::vector<VirtualKeyDefinition>& outVirtualKeys) const; virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const; virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map); @@ -355,7 +352,7 @@ private: int32_t controllerNumber; Device(int fd, int32_t id, const std::string& path, - const InputDeviceIdentifier& identifier); + const InputDeviceIdentifier& identifier); ~Device(); void close(); @@ -380,7 +377,7 @@ private: void addDeviceLocked(Device* device); void assignDescriptorLocked(InputDeviceIdentifier& identifier); - void closeDeviceByPathLocked(const char *devicePath); + void closeDeviceByPathLocked(const char* devicePath); void closeVideoDeviceByPathLocked(const std::string& devicePath); void closeDeviceLocked(Device* device); void closeAllDevicesLocked(); @@ -397,7 +394,7 @@ private: status_t unregisterDeviceFromEpollLocked(Device* device); void unregisterVideoDeviceFromEpollLocked(const TouchVideoDevice& videoDevice); - status_t scanDirLocked(const char *dirname); + status_t scanDirLocked(const char* dirname); status_t scanVideoDirLocked(const std::string& dirname); void scanDevicesLocked(); status_t readNotifyLocked(); @@ -453,8 +450,8 @@ private: */ std::vector<std::unique_ptr<TouchVideoDevice>> mUnattachedVideoDevices; - Device *mOpeningDevices; - Device *mClosingDevices; + Device* mOpeningDevices; + Device* mClosingDevices; bool mNeedToSendFinishedDeviceScan; bool mNeedToReopenDevices; diff --git a/services/inputflinger/InputReader.h b/services/inputflinger/reader/include/InputReader.h index 0666ca54bf..1b8177c618 100644 --- a/services/inputflinger/InputReader.h +++ b/services/inputflinger/reader/include/InputReader.h @@ -18,9 +18,9 @@ #define _UI_INPUT_READER_H #include "EventHub.h" -#include "PointerControllerInterface.h" #include "InputListener.h" #include "InputReaderBase.h" +#include "PointerControllerInterface.h" #include <input/DisplayViewport.h> #include <input/Input.h> @@ -33,9 +33,9 @@ #include <utils/Mutex.h> #include <utils/Timers.h> -#include <optional> #include <stddef.h> #include <unistd.h> +#include <optional> #include <vector> namespace android { @@ -43,7 +43,6 @@ namespace android { class InputDevice; class InputMapper; - struct StylusState { /* Time the stylus event was received. */ nsecs_t when; @@ -69,21 +68,20 @@ struct StylusState { } }; - /* Internal interface used by individual input devices to access global input device state * and parameters maintained by the input reader. */ class InputReaderContext { public: - InputReaderContext() { } - virtual ~InputReaderContext() { } + InputReaderContext() {} + virtual ~InputReaderContext() {} virtual void updateGlobalMetaState() = 0; virtual int32_t getGlobalMetaState() = 0; virtual void disableVirtualKeysUntil(nsecs_t time) = 0; - virtual bool shouldDropVirtualKey(nsecs_t now, - InputDevice* device, int32_t keyCode, int32_t scanCode) = 0; + virtual bool shouldDropVirtualKey(nsecs_t now, InputDevice* device, int32_t keyCode, + int32_t scanCode) = 0; virtual void fadePointer() = 0; @@ -100,7 +98,6 @@ public: virtual uint32_t getNextSequenceNum() = 0; }; - /* The input reader reads raw event data from the event hub and processes it into input events * that it sends to the input listener. Some functions of the input reader, such as early * event filtering in low power states, are controlled by a separate policy object. @@ -128,29 +125,28 @@ public: virtual bool isInputDeviceEnabled(int32_t deviceId); - virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, - int32_t scanCode); - virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, - int32_t keyCode); - virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, - int32_t sw); + virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, int32_t scanCode); + virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode); + virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t sw); virtual void toggleCapsLockState(int32_t deviceId); - virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, - size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags); + virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, size_t numCodes, + const int32_t* keyCodes, uint8_t* outFlags); virtual void requestRefreshConfiguration(uint32_t changes); virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize, - ssize_t repeat, int32_t token); + ssize_t repeat, int32_t token); virtual void cancelVibrate(int32_t deviceId, int32_t token); virtual bool canDispatchToDisplay(int32_t deviceId, int32_t displayId); + protected: // These members are protected so they can be instrumented by test cases. virtual InputDevice* createDeviceLocked(int32_t deviceId, int32_t controllerNumber, - const InputDeviceIdentifier& identifier, uint32_t classes); + const InputDeviceIdentifier& identifier, + uint32_t classes); class ContextImpl : public InputReaderContext { InputReader* mReader; @@ -161,8 +157,8 @@ protected: virtual void updateGlobalMetaState(); virtual int32_t getGlobalMetaState(); virtual void disableVirtualKeysUntil(nsecs_t time); - virtual bool shouldDropVirtualKey(nsecs_t now, - InputDevice* device, int32_t keyCode, int32_t scanCode); + virtual bool shouldDropVirtualKey(nsecs_t now, InputDevice* device, int32_t keyCode, + int32_t scanCode); virtual void fadePointer(); virtual void requestTimeoutAtTime(nsecs_t when); virtual int32_t bumpGeneration(); @@ -226,8 +222,8 @@ private: nsecs_t mDisableVirtualKeysTimeout; void disableVirtualKeysUntilLocked(nsecs_t time); - bool shouldDropVirtualKeyLocked(nsecs_t now, - InputDevice* device, int32_t keyCode, int32_t scanCode); + bool shouldDropVirtualKeyLocked(nsecs_t now, InputDevice* device, int32_t keyCode, + int32_t scanCode); nsecs_t mNextTimeout; void requestTimeoutAtTimeLocked(nsecs_t when); @@ -238,17 +234,17 @@ private: // state queries typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code); int32_t getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code, - GetStateFunc getStateFunc); + GetStateFunc getStateFunc); bool markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, size_t numCodes, - const int32_t* keyCodes, uint8_t* outFlags); + const int32_t* keyCodes, uint8_t* outFlags); }; - /* Represents the state of a single input device. */ class InputDevice { public: - InputDevice(InputReaderContext* context, int32_t id, int32_t generation, int32_t - controllerNumber, const InputDeviceIdentifier& identifier, uint32_t classes); + InputDevice(InputReaderContext* context, int32_t id, int32_t generation, + int32_t controllerNumber, const InputDeviceIdentifier& identifier, + uint32_t classes); ~InputDevice(); inline InputReaderContext* getContext() { return mContext; } @@ -288,8 +284,8 @@ public: int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); - bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, - const int32_t* keyCodes, uint8_t* outFlags); + bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, const int32_t* keyCodes, + uint8_t* outFlags); void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, int32_t token); void cancelVibrate(int32_t token); void cancelTouch(nsecs_t when); @@ -306,9 +302,7 @@ public: inline const PropertyMap& getConfiguration() { return mConfiguration; } inline EventHubInterface* getEventHub() { return mContext->getEventHub(); } - bool hasKey(int32_t code) { - return getEventHub()->hasScanCode(mId, code); - } + bool hasKey(int32_t code) { return getEventHub()->hasScanCode(mId, code); } bool hasAbsoluteAxis(int32_t code) { RawAbsoluteAxisInfo info; @@ -352,7 +346,6 @@ private: PropertyMap mConfiguration; }; - /* Keeps track of the state of mouse or touch pad buttons. */ class CursorButtonAccumulator { public: @@ -376,7 +369,6 @@ private: void clearButtons(); }; - /* Keeps track of cursor movements. */ class CursorMotionAccumulator { @@ -397,7 +389,6 @@ private: void clearRelativeAxes(); }; - /* Keeps track of cursor scrolling motions. */ class CursorScrollAccumulator { @@ -429,7 +420,6 @@ private: void clearRelativeAxes(); }; - /* Keeps track of the state of touch, stylus and tool buttons. */ class TouchButtonAccumulator { public: @@ -467,7 +457,6 @@ private: void clearButtons(); }; - /* Raw axis information from the driver. */ struct RawPointerAxes { RawAbsoluteAxisInfo x; @@ -490,7 +479,6 @@ struct RawPointerAxes { void clear(); }; - /* Raw data for a collection of pointers including a pointer id mapping table. */ struct RawPointerData { struct Pointer { @@ -533,16 +521,11 @@ struct RawPointerData { touchingIdBits.clear(); } - inline const Pointer& pointerForId(uint32_t id) const { - return pointers[idToIndex[id]]; - } + inline const Pointer& pointerForId(uint32_t id) const { return pointers[idToIndex[id]]; } - inline bool isHovering(uint32_t pointerIndex) { - return pointers[pointerIndex].isHovering; - } + inline bool isHovering(uint32_t pointerIndex) { return pointers[pointerIndex].isHovering; } }; - /* Cooked data for a collection of pointers including a pointer id mapping table. */ struct CookedPointerData { uint32_t pointerCount; @@ -576,7 +559,6 @@ struct CookedPointerData { } }; - /* Keeps track of the state of single-touch protocol. */ class SingleTouchMotionAccumulator { public: @@ -605,7 +587,6 @@ private: void clearAbsoluteAxes(); }; - /* Keeps track of the state of multi-touch protocol. */ class MultiTouchMotionAccumulator { public: @@ -616,10 +597,12 @@ public: inline int32_t getY() const { return mAbsMTPositionY; } inline int32_t getTouchMajor() const { return mAbsMTTouchMajor; } inline int32_t getTouchMinor() const { - return mHaveAbsMTTouchMinor ? mAbsMTTouchMinor : mAbsMTTouchMajor; } + return mHaveAbsMTTouchMinor ? mAbsMTTouchMinor : mAbsMTTouchMajor; + } inline int32_t getToolMajor() const { return mAbsMTWidthMajor; } inline int32_t getToolMinor() const { - return mHaveAbsMTWidthMinor ? mAbsMTWidthMinor : mAbsMTWidthMajor; } + return mHaveAbsMTWidthMinor ? mAbsMTWidthMinor : mAbsMTWidthMajor; + } inline int32_t getOrientation() const { return mAbsMTOrientation; } inline int32_t getTrackingId() const { return mAbsMTTrackingId; } inline int32_t getPressure() const { return mAbsMTPressure; } @@ -672,7 +655,6 @@ private: void clearSlots(int32_t initialSlot); }; - /* An input mapper transforms raw input events into cooked event data. * A single input device can have multiple associated input mappers in order to interpret * different classes of events. @@ -710,9 +692,8 @@ public: virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, - const int32_t* keyCodes, uint8_t* outFlags); - virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, - int32_t token); + const int32_t* keyCodes, uint8_t* outFlags); + virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, int32_t token); virtual void cancelVibrate(int32_t token); virtual void cancelTouch(nsecs_t when); @@ -731,12 +712,11 @@ protected: status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo); void bumpGeneration(); - static void dumpRawAbsoluteAxisInfo(std::string& dump, - const RawAbsoluteAxisInfo& axis, const char* name); + static void dumpRawAbsoluteAxisInfo(std::string& dump, const RawAbsoluteAxisInfo& axis, + const char* name); static void dumpStylusState(std::string& dump, const StylusState& state); }; - class SwitchInputMapper : public InputMapper { public: explicit SwitchInputMapper(InputDevice* device); @@ -756,7 +736,6 @@ private: void sync(nsecs_t when); }; - class VibratorInputMapper : public InputMapper { public: explicit VibratorInputMapper(InputDevice* device); @@ -766,8 +745,7 @@ public: virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); virtual void process(const RawEvent* rawEvent); - virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, - int32_t token); + virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, int32_t token); virtual void cancelVibrate(int32_t token); virtual void timeoutExpired(nsecs_t when); virtual void dump(std::string& dump); @@ -785,7 +763,6 @@ private: void stopVibrating(); }; - class KeyboardInputMapper : public InputMapper { public: KeyboardInputMapper(InputDevice* device, uint32_t source, int32_t keyboardType); @@ -801,7 +778,7 @@ public: virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, - const int32_t* keyCodes, uint8_t* outFlags); + const int32_t* keyCodes, uint8_t* outFlags); virtual int32_t getMetaState(); virtual void updateMetaState(int32_t keyCode); @@ -857,13 +834,11 @@ private: void resetLedState(); void initializeLedState(LedState& ledState, int32_t led); void updateLedState(bool reset); - void updateLedStateForModifier(LedState& ledState, int32_t led, - int32_t modifier, bool reset); + void updateLedStateForModifier(LedState& ledState, int32_t led, int32_t modifier, bool reset); std::optional<DisplayViewport> findViewport(nsecs_t when, const InputReaderConfiguration* config); }; - class CursorInputMapper : public InputMapper { public: explicit CursorInputMapper(InputDevice* device); @@ -931,7 +906,6 @@ private: void sync(nsecs_t when); }; - class RotaryEncoderInputMapper : public InputMapper { public: explicit RotaryEncoderInputMapper(InputDevice* device); @@ -969,7 +943,7 @@ public: virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, - const int32_t* keyCodes, uint8_t* outFlags); + const int32_t* keyCodes, uint8_t* outFlags); virtual void fadePointer(); virtual void cancelTouch(nsecs_t when); @@ -1002,11 +976,11 @@ protected: uint32_t mSource; enum DeviceMode { - DEVICE_MODE_DISABLED, // input is disabled - DEVICE_MODE_DIRECT, // direct mapping (touchscreen) - DEVICE_MODE_UNSCALED, // unscaled mapping (touchpad) + DEVICE_MODE_DISABLED, // input is disabled + DEVICE_MODE_DIRECT, // direct mapping (touchscreen) + DEVICE_MODE_UNSCALED, // unscaled mapping (touchpad) DEVICE_MODE_NAVIGATION, // unscaled mapping with assist gesture (touch navigation) - DEVICE_MODE_POINTER, // pointer mapping (pointer) + DEVICE_MODE_POINTER, // pointer mapping (pointer) }; DeviceMode mDeviceMode; @@ -1303,9 +1277,7 @@ private: bool haveTilt; InputDeviceInfo::MotionRange tilt; - OrientedRanges() { - clear(); - } + OrientedRanges() { clear(); } void clear() { haveSize = false; @@ -1445,9 +1417,9 @@ private: nsecs_t quietTime; // Reference points for multitouch gestures. - float referenceTouchX; // reference touch X/Y coordinates in surface units + float referenceTouchX; // reference touch X/Y coordinates in surface units float referenceTouchY; - float referenceGestureX; // reference gesture X/Y coordinates in pixels + float referenceGestureX; // reference gesture X/Y coordinates in pixels float referenceGestureY; // Distance that each pointer has traveled which has not yet been @@ -1483,9 +1455,7 @@ private: tapUpTime = LLONG_MIN; } - void resetQuietTime() { - quietTime = LLONG_MIN; - } + void resetQuietTime() { quietTime = LLONG_MIN; } } mPointerGesture; struct PointerSimple { @@ -1529,8 +1499,8 @@ private: bool consumeRawTouches(nsecs_t when, uint32_t policyFlags); void processRawTouches(bool timeout); void cookAndDispatch(nsecs_t when); - void dispatchVirtualKey(nsecs_t when, uint32_t policyFlags, - int32_t keyEventAction, int32_t keyEventFlags); + void dispatchVirtualKey(nsecs_t when, uint32_t policyFlags, int32_t keyEventAction, + int32_t keyEventFlags); void dispatchTouches(nsecs_t when, uint32_t policyFlags); void dispatchHoverExit(nsecs_t when, uint32_t policyFlags); @@ -1546,9 +1516,8 @@ private: void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout); void abortPointerGestures(nsecs_t when, uint32_t policyFlags); - bool preparePointerGestures(nsecs_t when, - bool* outCancelPreviousGesture, bool* outFinishPreviousGesture, - bool isTimeout); + bool preparePointerGestures(nsecs_t when, bool* outCancelPreviousGesture, + bool* outFinishPreviousGesture, bool isTimeout); void dispatchPointerStylus(nsecs_t when, uint32_t policyFlags); void abortPointerStylus(nsecs_t when, uint32_t policyFlags); @@ -1556,8 +1525,7 @@ private: void dispatchPointerMouse(nsecs_t when, uint32_t policyFlags); void abortPointerMouse(nsecs_t when, uint32_t policyFlags); - void dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, - bool down, bool hovering); + void dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, bool down, bool hovering); void abortPointerSimple(nsecs_t when, uint32_t policyFlags); bool assignExternalStylusId(const RawState& state, bool timeout); @@ -1568,19 +1536,18 @@ private: // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the // method will take care of setting the index and transmuting the action to DOWN or UP // it is the first / last pointer to go down / up. - void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source, - int32_t action, int32_t actionButton, - int32_t flags, int32_t metaState, int32_t buttonState, int32_t edgeFlags, - const PointerProperties* properties, const PointerCoords* coords, - const uint32_t* idToIndex, BitSet32 idBits, - int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime); + void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source, int32_t action, + int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState, + int32_t edgeFlags, const PointerProperties* properties, + const PointerCoords* coords, const uint32_t* idToIndex, BitSet32 idBits, + int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime); // Updates pointer coords and properties for pointers with specified ids that have moved. // Returns true if any of them changed. - bool updateMovedPointers(const PointerProperties* inProperties, - const PointerCoords* inCoords, const uint32_t* inIdToIndex, - PointerProperties* outProperties, PointerCoords* outCoords, - const uint32_t* outIdToIndex, BitSet32 idBits) const; + bool updateMovedPointers(const PointerProperties* inProperties, const PointerCoords* inCoords, + const uint32_t* inIdToIndex, PointerProperties* outProperties, + PointerCoords* outCoords, const uint32_t* outIdToIndex, + BitSet32 idBits) const; bool isPointInsideSurface(int32_t x, int32_t y); const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y); @@ -1590,7 +1557,6 @@ private: const char* modeToString(DeviceMode deviceMode); }; - class SingleTouchInputMapper : public TouchInputMapper { public: explicit SingleTouchInputMapper(InputDevice* device); @@ -1608,7 +1574,6 @@ private: SingleTouchMotionAccumulator mSingleTouchMotionAccumulator; }; - class MultiTouchInputMapper : public TouchInputMapper { public: explicit MultiTouchInputMapper(InputDevice* device); @@ -1651,7 +1616,6 @@ private: StylusState mStylusState; }; - class JoystickInputMapper : public InputMapper { public: explicit JoystickInputMapper(InputDevice* device); @@ -1671,8 +1635,8 @@ private: bool explicitlyMapped; // true if the axis was explicitly assigned an axis id - float scale; // scale factor from raw to normalized values - float offset; // offset to add after scaling for normalization + float scale; // scale factor from raw to normalized values + float offset; // offset to add after scaling for normalization float highScale; // scale factor from raw to normalized values of high split float highOffset; // offset to add after scaling for normalization of high split @@ -1682,16 +1646,16 @@ private: float fuzz; // normalized error tolerance float resolution; // normalized resolution in units/mm - float filter; // filter out small variations of this size - float currentValue; // current value - float newValue; // most recent value + float filter; // filter out small variations of this size + float currentValue; // current value + float newValue; // most recent value float highCurrentValue; // current value of high split - float highNewValue; // most recent value of high split + float highNewValue; // most recent value of high split void initialize(const RawAbsoluteAxisInfo& rawAxisInfo, const AxisInfo& axisInfo, - bool explicitlyMapped, float scale, float offset, - float highScale, float highOffset, - float min, float max, float flat, float fuzz, float resolution) { + bool explicitlyMapped, float scale, float offset, float highScale, + float highOffset, float min, float max, float flat, float fuzz, + float resolution) { this->rawAxisInfo = rawAxisInfo; this->axisInfo = axisInfo; this->explicitlyMapped = explicitlyMapped; @@ -1725,17 +1689,16 @@ private: void pruneAxes(bool ignoreExplicitlyMappedAxes); bool filterAxes(bool force); - static bool hasValueChangedSignificantly(float filter, - float newValue, float currentValue, float min, float max); - static bool hasMovedNearerToValueWithinFilteredRange(float filter, - float newValue, float currentValue, float thresholdValue); + static bool hasValueChangedSignificantly(float filter, float newValue, float currentValue, + float min, float max); + static bool hasMovedNearerToValueWithinFilteredRange(float filter, float newValue, + float currentValue, float thresholdValue); static bool isCenteredAxis(int32_t axis); static int32_t getCompatAxis(int32_t axis); static void addMotionRange(int32_t axisId, const Axis& axis, InputDeviceInfo* info); - static void setPointerCoordsAxisValue(PointerCoords* pointerCoords, int32_t axis, - float value); + static void setPointerCoordsAxisValue(PointerCoords* pointerCoords, int32_t axis, float value); }; } // namespace android diff --git a/services/inputflinger/TouchVideoDevice.h b/services/inputflinger/reader/include/TouchVideoDevice.h index 0e7e2ef496..9dfa951ff1 100644 --- a/services/inputflinger/TouchVideoDevice.h +++ b/services/inputflinger/reader/include/TouchVideoDevice.h @@ -17,11 +17,11 @@ #ifndef _INPUTFLINGER_TOUCH_VIDEO_DEVICE_H #define _INPUTFLINGER_TOUCH_VIDEO_DEVICE_H -#include <array> #include <android-base/unique_fd.h> #include <input/TouchVideoFrame.h> -#include <optional> #include <stdint.h> +#include <array> +#include <optional> #include <string> #include <vector> @@ -109,9 +109,9 @@ private: * The constructor is private because opening a v4l2 device requires many checks. * To get a new TouchVideoDevice, use 'create' instead. */ - explicit TouchVideoDevice(int fd, std::string&& name, std::string&& devicePath, - uint32_t height, uint32_t width, - const std::array<const int16_t*, NUM_BUFFERS>& readLocations); + explicit TouchVideoDevice(int fd, std::string&& name, std::string&& devicePath, uint32_t height, + uint32_t width, + const std::array<const int16_t*, NUM_BUFFERS>& readLocations); /** * Read all currently available frames. */ diff --git a/services/inputflinger/tests/Android.bp b/services/inputflinger/tests/Android.bp index 9054316204..c4f8626a98 100644 --- a/services/inputflinger/tests/Android.bp +++ b/services/inputflinger/tests/Android.bp @@ -32,4 +32,7 @@ cc_test { "libinputflinger_base", "libinputservice", ], + header_libs: [ + "libinputreader_headers", + ], } diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 09df2a70c7..55c0497c4d 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "../InputReader.h" +#include "InputReader.h" #include "TestInputListener.h" #include <gtest/gtest.h> |