From f88ea9b62158b43109d96470496702583cdb8cd2 Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Tue, 5 Sep 2017 20:17:16 -0400 Subject: Fix stack use-after-scope in InputReader READ of size 4 at 0x0079b1ac3a20 thread T121 (InputReader) Viewport [1] to add: virtual:android:277f1a09-b88d-4d1e-8716-796f114d080b #0 0x79b8820d53 in android::InputReaderConfiguration::getDisplayViewport(android::ViewportType, android::String8 const*, android::DisplayViewport*) const frameworks/native/services/inputflinger/InputReader.cpp:246:39 #1 0x79b8843fab in android::TouchInputMapper::configureSurface(long, bool*) frameworks/native/services/inputflinger/InputReader.cpp:3472:22 #2 0x79b88411b3 in android::TouchInputMapper::configure(long, android::InputReaderConfiguration const*, unsigned int) frameworks/native/services/inputflinger/InputReader.cpp:3248:9 #3 0x79b8825ff3 in android::InputDevice::configure(long, android::InputReaderConfiguration const*, unsigned int) frameworks/native/services/inputflinger/InputReader.cpp:1126:21 #4 0x79b8822653 in android::InputReader::refreshConfigurationLocked(unsigned int) frameworks/native/services/inputflinger/InputReader.cpp:612:25 #5 0x79b88239fb in android::InputReader::loopOnce() frameworks/native/services/inputflinger/InputReader.cpp:343:13 #6 0x79b882d507 in android::InputReaderThread::threadLoop() frameworks/native/services/inputflinger/InputReader.cpp:1004:14 #7 0x79d79e6113 in android::Thread::_threadLoop(void*) system/core/libutils/Threads.cpp:747:28 #8 0x79da914bbb in android::AndroidRuntime::javaThreadShell(void*) frameworks/base/core/jni/AndroidRuntime.cpp:1199:14 #9 0x79da20f31b in __pthread_start(void*) bionic/libc/bionic/pthread_create.cpp:214:18 #10 0x79da1c6dff in __start_thread bionic/libc/bionic/clone.cpp:47:16 Bug: 65378805 Test: asan build Change-Id: I5a65cb007fe4879ce9635572014a568583a2ef4a --- services/inputflinger/InputReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'services/inputflinger/InputReader.cpp') diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index 935d0f626e..d4266f6df9 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -257,7 +257,7 @@ bool InputReaderConfiguration::getDisplayViewport(ViewportType viewportType, const String8* uniqueDisplayId, DisplayViewport* outViewport) const { const DisplayViewport* viewport = NULL; if (viewportType == ViewportType::VIEWPORT_VIRTUAL && uniqueDisplayId != NULL) { - for (DisplayViewport currentViewport : mVirtualDisplays) { + for (const DisplayViewport& currentViewport : mVirtualDisplays) { if (currentViewport.uniqueId == *uniqueDisplayId) { viewport = ¤tViewport; break; -- cgit v1.2.3-59-g8ed1b From 5d83f60f4df35d64854dd67893f7ab2ab3bbf5bc Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Tue, 12 Sep 2017 12:40:29 -0700 Subject: Enforce print format warnings in input subsystem. Treat compiler warnings as errors. Switch to portable print formatting of such types as uint64_t and size_t. Bug: 64258224 Bug: 63412298 Test: m -j, interact with the phone using touch input, check the logcat output. Change-Id: I70a170b0b7d4ac979d997324741d0aeb2e2c458e --- libs/input/InputTransport.cpp | 6 ++--- services/inputflinger/Android.bp | 3 +++ services/inputflinger/EventHub.cpp | 6 ----- services/inputflinger/InputDispatcher.cpp | 38 +++++++++++++++---------------- services/inputflinger/InputReader.cpp | 19 ++++++++-------- 5 files changed, 34 insertions(+), 38 deletions(-) (limited to 'services/inputflinger/InputReader.cpp') diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp index 9abd04ca04..b8901bd123 100644 --- a/libs/input/InputTransport.cpp +++ b/libs/input/InputTransport.cpp @@ -254,7 +254,7 @@ status_t InputPublisher::publishKeyEvent( #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' publisher ~ publishKeyEvent: seq=%u, deviceId=%d, source=0x%x, " "action=0x%x, flags=0x%x, keyCode=%d, scanCode=%d, metaState=0x%x, repeatCount=%d," - "downTime=%lld, eventTime=%lld", + "downTime=%" PRId64 ", eventTime=%" PRId64, mChannel->getName().string(), seq, deviceId, source, action, flags, keyCode, scanCode, metaState, repeatCount, downTime, eventTime); @@ -305,7 +305,7 @@ status_t InputPublisher::publishMotionEvent( ALOGD("channel '%s' publisher ~ publishMotionEvent: seq=%u, deviceId=%d, source=0x%x, " "action=0x%x, actionButton=0x%08x, flags=0x%x, edgeFlags=0x%x, " "metaState=0x%x, buttonState=0x%x, xOffset=%f, yOffset=%f, " - "xPrecision=%f, yPrecision=%f, downTime=%lld, eventTime=%lld, " + "xPrecision=%f, yPrecision=%f, downTime=%" PRId64 ", eventTime=%" PRId64 ", " "pointerCount=%" PRIu32, mChannel->getName().string(), seq, deviceId, source, action, actionButton, flags, edgeFlags, metaState, buttonState, @@ -401,7 +401,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, bool consumeBatches, nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent, int32_t* displayId) { #if DEBUG_TRANSPORT_ACTIONS - ALOGD("channel '%s' consumer ~ consume: consumeBatches=%s, frameTime=%lld", + ALOGD("channel '%s' consumer ~ consume: consumeBatches=%s, frameTime=%" PRId64, mChannel->getName().string(), consumeBatches ? "true" : "false", frameTime); #endif diff --git a/services/inputflinger/Android.bp b/services/inputflinger/Android.bp index 4fd98e2a7e..238cba362c 100644 --- a/services/inputflinger/Android.bp +++ b/services/inputflinger/Android.bp @@ -37,6 +37,9 @@ cc_library_shared { ], cflags: [ + "-Wall", + "-Wextra", + "-Werror", "-Wno-unused-parameter", // TODO: Move inputflinger to its own process and mark it hidden //-fvisibility=hidden diff --git a/services/inputflinger/EventHub.cpp b/services/inputflinger/EventHub.cpp index 50589b484a..99fe0f5d55 100644 --- a/services/inputflinger/EventHub.cpp +++ b/services/inputflinger/EventHub.cpp @@ -69,12 +69,6 @@ namespace android { static const char *WAKE_LOCK_ID = "KeyEvents"; static const char *DEVICE_PATH = "/dev/input"; -/* return the larger integer */ -static inline int max(int v1, int v2) -{ - return (v1 > v2) ? v1 : v2; -} - static inline const char* toString(bool value) { return value ? "true" : "false"; } diff --git a/services/inputflinger/InputDispatcher.cpp b/services/inputflinger/InputDispatcher.cpp index 69067d225b..031218562f 100644 --- a/services/inputflinger/InputDispatcher.cpp +++ b/services/inputflinger/InputDispatcher.cpp @@ -685,7 +685,7 @@ InputDispatcher::KeyEntry* InputDispatcher::synthesizeKeyRepeatLocked(nsecs_t cu bool InputDispatcher::dispatchConfigurationChangedLocked( nsecs_t currentTime, ConfigurationChangedEntry* entry) { #if DEBUG_OUTBOUND_EVENT_DETAILS - ALOGD("dispatchConfigurationChanged - eventTime=%lld", entry->eventTime); + ALOGD("dispatchConfigurationChanged - eventTime=%" PRId64, entry->eventTime); #endif // Reset key repeating in case a keyboard device was added or removed or something. @@ -701,7 +701,8 @@ bool InputDispatcher::dispatchConfigurationChangedLocked( bool InputDispatcher::dispatchDeviceResetLocked( nsecs_t currentTime, DeviceResetEntry* entry) { #if DEBUG_OUTBOUND_EVENT_DETAILS - ALOGD("dispatchDeviceReset - eventTime=%lld, deviceId=%d", entry->eventTime, entry->deviceId); + ALOGD("dispatchDeviceReset - eventTime=%" PRId64 ", deviceId=%d", entry->eventTime, + entry->deviceId); #endif CancelationOptions options(CancelationOptions::CANCEL_ALL_EVENTS, @@ -811,9 +812,9 @@ bool InputDispatcher::dispatchKeyLocked(nsecs_t currentTime, KeyEntry* entry, void InputDispatcher::logOutboundKeyDetailsLocked(const char* prefix, const KeyEntry* entry) { #if DEBUG_OUTBOUND_EVENT_DETAILS - ALOGD("%seventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, " + ALOGD("%seventTime=%" PRId64 ", deviceId=%d, source=0x%x, policyFlags=0x%x, " "action=0x%x, flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, " - "repeatCount=%d, downTime=%lld", + "repeatCount=%d, downTime=%" PRId64, prefix, entry->eventTime, entry->deviceId, entry->source, entry->policyFlags, entry->action, entry->flags, entry->keyCode, entry->scanCode, entry->metaState, @@ -884,10 +885,10 @@ bool InputDispatcher::dispatchMotionLocked( void InputDispatcher::logOutboundMotionDetailsLocked(const char* prefix, const MotionEntry* entry) { #if DEBUG_OUTBOUND_EVENT_DETAILS - ALOGD("%seventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, " + ALOGD("%seventTime=%" PRId64 ", deviceId=%d, source=0x%x, policyFlags=0x%x, " "action=0x%x, actionButton=0x%x, flags=0x%x, " "metaState=0x%x, buttonState=0x%x," - "edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, downTime=%lld", + "edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, downTime=%" PRId64, prefix, entry->eventTime, entry->deviceId, entry->source, entry->policyFlags, entry->action, entry->actionButton, entry->flags, @@ -1132,8 +1133,6 @@ int32_t InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, INJECTION_PERMISSION_DENIED }; - nsecs_t startTime = now(); - // For security reasons, we defer updating the touch state until we are sure that // event injection will be allowed. int32_t displayId = entry->displayId; @@ -2233,7 +2232,7 @@ void InputDispatcher::synthesizeCancelationEventsForConnectionLocked( if (!cancelationEvents.isEmpty()) { #if DEBUG_OUTBOUND_EVENT_DETAILS - ALOGD("channel '%s' ~ Synthesized %d cancelation events to bring channel back in sync " + ALOGD("channel '%s' ~ Synthesized %zu cancelation events to bring channel back in sync " "with reality: %s, mode=%d.", connection->getInputChannelName(), cancelationEvents.size(), options.reason, options.mode); @@ -2369,7 +2368,7 @@ InputDispatcher::splitMotionEvent(const MotionEntry* originalMotionEntry, BitSet void InputDispatcher::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) { #if DEBUG_INBOUND_EVENT_DETAILS - ALOGD("notifyConfigurationChanged - eventTime=%lld", args->eventTime); + ALOGD("notifyConfigurationChanged - eventTime=%" PRId64, args->eventTime); #endif bool needWake; @@ -2387,8 +2386,9 @@ void InputDispatcher::notifyConfigurationChanged(const NotifyConfigurationChange void InputDispatcher::notifyKey(const NotifyKeyArgs* args) { #if DEBUG_INBOUND_EVENT_DETAILS - ALOGD("notifyKey - eventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, action=0x%x, " - "flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, downTime=%lld", + ALOGD("notifyKey - eventTime=%" PRId64 + ", deviceId=%d, source=0x%x, policyFlags=0x%x, action=0x%x, " + "flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, downTime=%" PRId64, args->eventTime, args->deviceId, args->source, args->policyFlags, args->action, args->flags, args->keyCode, args->scanCode, args->metaState, args->downTime); @@ -2482,9 +2482,9 @@ bool InputDispatcher::shouldSendKeyToInputFilterLocked(const NotifyKeyArgs* args void InputDispatcher::notifyMotion(const NotifyMotionArgs* args) { #if DEBUG_INBOUND_EVENT_DETAILS - ALOGD("notifyMotion - eventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, " + ALOGD("notifyMotion - eventTime=%" PRId64 ", deviceId=%d, source=0x%x, policyFlags=0x%x, " "action=0x%x, actionButton=0x%x, flags=0x%x, metaState=0x%x, buttonState=0x%x," - "edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, downTime=%lld", + "edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, downTime=%" PRId64, args->eventTime, args->deviceId, args->source, args->policyFlags, args->action, args->actionButton, args->flags, args->metaState, args->buttonState, args->edgeFlags, args->xPrecision, args->yPrecision, args->downTime); @@ -2562,9 +2562,9 @@ bool InputDispatcher::shouldSendMotionToInputFilterLocked(const NotifyMotionArgs void InputDispatcher::notifySwitch(const NotifySwitchArgs* args) { #if DEBUG_INBOUND_EVENT_DETAILS - ALOGD("notifySwitch - eventTime=%lld, policyFlags=0x%x, switchValues=0x%08x, switchMask=0x%08x", - args->eventTime, args->policyFlags, - args->switchValues, args->switchMask); + ALOGD("notifySwitch - eventTime=%" PRId64 ", policyFlags=0x%x, switchValues=0x%08x, " + "switchMask=0x%08x", + args->eventTime, args->policyFlags, args->switchValues, args->switchMask); #endif uint32_t policyFlags = args->policyFlags; @@ -2575,7 +2575,7 @@ void InputDispatcher::notifySwitch(const NotifySwitchArgs* args) { void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args) { #if DEBUG_INBOUND_EVENT_DETAILS - ALOGD("notifyDeviceReset - eventTime=%lld, deviceId=%d", + ALOGD("notifyDeviceReset - eventTime=%" PRId64 ", deviceId=%d", args->eventTime, args->deviceId); #endif @@ -3743,7 +3743,7 @@ bool InputDispatcher::afterKeyEventLockedInterruptible(const sp& con msg.appendFormat(", %d->%d", fallbackKeys.keyAt(i), fallbackKeys.valueAt(i)); } - ALOGD("Unhandled key event: %d currently tracked fallback keys%s.", + ALOGD("Unhandled key event: %zu currently tracked fallback keys%s.", fallbackKeys.size(), msg.string()); } #endif diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index d4266f6df9..60f2286625 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -429,7 +429,7 @@ void InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) { batchSize += 1; } #if DEBUG_RAW_EVENTS - ALOGD("BatchSize: %d Count: %d", batchSize, count); + ALOGD("BatchSize: %zu Count: %zu", batchSize, count); #endif processEventsForDeviceLocked(deviceId, rawEvent, batchSize); } else { @@ -1176,7 +1176,7 @@ void InputDevice::process(const RawEvent* rawEvents, size_t count) { size_t numMappers = mMappers.size(); for (const RawEvent* rawEvent = rawEvents; count--; rawEvent++) { #if DEBUG_RAW_EVENTS - ALOGD("Input event: device=%d type=0x%04x code=0x%04x value=0x%08x when=%lld", + 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); #endif @@ -1851,7 +1851,7 @@ 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 %d; ignoring this slot.", + "should be between 0 and %zd; ignoring this slot.", mCurrentSlot, mSlotCount - 1); } #endif @@ -2147,9 +2147,9 @@ void VibratorInputMapper::vibrate(const nsecs_t* pattern, size_t patternSize, ss if (i != 0) { patternStr.append(", "); } - patternStr.appendFormat("%lld", pattern[i]); + patternStr.appendFormat("%" PRId64, pattern[i]); } - ALOGD("vibrate: deviceId=%d, pattern=[%s], repeat=%ld, token=%d", + ALOGD("vibrate: deviceId=%d, pattern=[%s], repeat=%zd, token=%d", getDeviceId(), patternStr.string(), repeat, token); #endif @@ -2198,8 +2198,7 @@ void VibratorInputMapper::nextStep() { nsecs_t duration = mPattern[mIndex]; if (vibratorOn) { #if DEBUG_VIBRATOR - ALOGD("nextStep: sending vibrate deviceId=%d, duration=%lld", - getDeviceId(), duration); + ALOGD("nextStep: sending vibrate deviceId=%d, duration=%" PRId64, getDeviceId(), duration); #endif getEventHub()->vibrate(getDeviceId(), duration); } else { @@ -6631,7 +6630,7 @@ 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[%d]: cur=%d, last=%d, distance=%lld", + ALOGD(" heap[%zu]: cur=%d, last=%d, distance=%" PRId64, i, heap[i].currentPointerIndex, heap[i].lastPointerIndex, heap[i].distance); } @@ -6677,7 +6676,7 @@ 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[%d]: cur=%d, last=%d, distance=%lld", + ALOGD(" heap[%zu]: cur=%d, last=%d, distance=%" PRId64, i, heap[i].currentPointerIndex, heap[i].lastPointerIndex, heap[i].distance); } @@ -6703,7 +6702,7 @@ void TouchInputMapper::assignPointerIds(const RawState* last, RawState* current) usedIdBits.markBit(id); #if DEBUG_POINTER_ASSIGNMENT - ALOGD("assignPointerIds - matched: cur=%d, last=%d, id=%d, distance=%lld", + ALOGD("assignPointerIds - matched: cur=%d, last=%d, id=%d, distance=%" PRId64, lastPointerIndex, currentPointerIndex, id, heap[0].distance); #endif break; -- cgit v1.2.3-59-g8ed1b From 7321529ef7a865c08180ba41017621b7defa2be4 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Fri, 13 Oct 2017 11:02:44 -0700 Subject: Fix logging in InputReader PointerDistanceHeapElement::distance is actually uint64_t, so print it with PRIu64. Bug: 64258224 Test: build with define DEBUG_POINTER_ASSIGNMENT 1 Change-Id: I6c6f475a1a68cfa4ff3869f21bd9d94d8b89ac55 --- services/inputflinger/InputReader.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'services/inputflinger/InputReader.cpp') diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index 60f2286625..6dd12d6bdd 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -6630,7 +6630,7 @@ 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=%d, last=%d, distance=%" PRId64, + ALOGD(" heap[%zu]: cur=%" PRIu32 ", last=%" PRIu32 ", distance=%" PRIu64, i, heap[i].currentPointerIndex, heap[i].lastPointerIndex, heap[i].distance); } @@ -6676,7 +6676,7 @@ 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=%d, last=%d, distance=%" PRId64, + ALOGD(" heap[%zu]: cur=%" PRIu32 ", last=%" PRIu32 ", distance=%" PRIu64, i, heap[i].currentPointerIndex, heap[i].lastPointerIndex, heap[i].distance); } @@ -6702,7 +6702,8 @@ void TouchInputMapper::assignPointerIds(const RawState* last, RawState* current) usedIdBits.markBit(id); #if DEBUG_POINTER_ASSIGNMENT - ALOGD("assignPointerIds - matched: cur=%d, last=%d, id=%d, distance=%" PRId64, + ALOGD("assignPointerIds - matched: cur=%" PRIu32 ", last=%" PRIu32 + ", id=%" PRIu32 ", distance=%" PRIu64, lastPointerIndex, currentPointerIndex, id, heap[0].distance); #endif break; @@ -6720,8 +6721,7 @@ void TouchInputMapper::assignPointerIds(const RawState* last, RawState* current) current->rawPointerData.isHovering(currentPointerIndex)); #if DEBUG_POINTER_ASSIGNMENT - ALOGD("assignPointerIds - assigned: cur=%d, id=%d", - currentPointerIndex, id); + ALOGD("assignPointerIds - assigned: cur=%" PRIu32 ", id=%" PRIu32, currentPointerIndex, id); #endif } } -- cgit v1.2.3-59-g8ed1b From 635cb71a65d361ec107afeafcb49488f6812f7d1 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Wed, 1 Nov 2017 16:32:14 -0700 Subject: Fix broken input tests InputPublisherAndConsumer_test currently segfaults due to null pointer dereference. This is because 0 is passed instead of a valid pointer to an allocated int32_t. Also, enforce strict compiler warnings, include signed comparisons. Bug: 62033391 Test: m -j libinput_tests_InputEvent_test libinput_tests_InputChannel_test libinput_tests_InputPublisherAndConsumer_test libinput_tests_InputTransport_test libinput_tests_VelocityTracker_test && adb push out/target/product/taimen/data/nativetest/libinput_tests/ /data/nativetest/ then run the above tests individually, for example /data/nativetest/libinput_tests # ./InputPublisherAndConsumer_test and others in a similar manner Change-Id: Ia030cdbfa22d2bf7bdf6274a337b059ca3f9a6c3 --- include/input/InputTransport.h | 2 +- libs/input/tests/Android.bp | 2 +- libs/input/tests/InputEvent_test.cpp | 8 ++++---- libs/input/tests/InputPublisherAndConsumer_test.cpp | 7 ++++--- services/inputflinger/InputDispatcher.cpp | 5 ++--- services/inputflinger/InputReader.cpp | 8 ++------ 6 files changed, 14 insertions(+), 18 deletions(-) (limited to 'services/inputflinger/InputReader.cpp') diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h index 944947420e..c4b5dca23d 100644 --- a/include/input/InputTransport.h +++ b/include/input/InputTransport.h @@ -455,7 +455,6 @@ private: int32_t* displayId); void updateTouchState(InputMessage& msg); - bool rewriteMessage(const TouchState& state, InputMessage& msg); void resampleTouchState(nsecs_t frameTime, MotionEvent* event, const InputMessage *next); @@ -464,6 +463,7 @@ private: status_t sendUnchainedFinishedSignal(uint32_t seq, bool handled); + static bool rewriteMessage(const TouchState& state, InputMessage& msg); static void initializeKeyEvent(KeyEvent* event, const InputMessage* msg); static void initializeMotionEvent(MotionEvent* event, const InputMessage* msg); static void addSample(MotionEvent* event, const InputMessage* msg); diff --git a/libs/input/tests/Android.bp b/libs/input/tests/Android.bp index e0bab1156b..aca9521c76 100644 --- a/libs/input/tests/Android.bp +++ b/libs/input/tests/Android.bp @@ -10,8 +10,8 @@ cc_test { ], cflags: [ "-Wall", + "-Wextra", "-Werror", - "-Wno-error=sign-compare", // to fix later "-Wno-unused-variable", ], shared_libs: [ diff --git a/libs/input/tests/InputEvent_test.cpp b/libs/input/tests/InputEvent_test.cpp index 3fb1c6df9b..fd3b7c8ee4 100644 --- a/libs/input/tests/InputEvent_test.cpp +++ b/libs/input/tests/InputEvent_test.cpp @@ -184,7 +184,7 @@ TEST_F(KeyEventTest, Properties) { ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event.getType()); ASSERT_EQ(2, event.getDeviceId()); - ASSERT_EQ(AINPUT_SOURCE_GAMEPAD, event.getSource()); + ASSERT_EQ(static_cast(AINPUT_SOURCE_GAMEPAD), event.getSource()); ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, event.getAction()); ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, event.getFlags()); ASSERT_EQ(AKEYCODE_BUTTON_X, event.getKeyCode()); @@ -196,7 +196,7 @@ TEST_F(KeyEventTest, Properties) { // Set source. event.setSource(AINPUT_SOURCE_JOYSTICK); - ASSERT_EQ(AINPUT_SOURCE_JOYSTICK, event.getSource()); + ASSERT_EQ(static_cast(AINPUT_SOURCE_JOYSTICK), event.getSource()); } @@ -300,7 +300,7 @@ void MotionEventTest::assertEqualsEventWithHistory(const MotionEvent* event) { // Check properties. ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType()); ASSERT_EQ(2, event->getDeviceId()); - ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, event->getSource()); + ASSERT_EQ(static_cast(AINPUT_SOURCE_TOUCHSCREEN), event->getSource()); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, event->getAction()); ASSERT_EQ(AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED, event->getFlags()); ASSERT_EQ(AMOTION_EVENT_EDGE_FLAG_TOP, event->getEdgeFlags()); @@ -432,7 +432,7 @@ TEST_F(MotionEventTest, Properties) { // Set source. event.setSource(AINPUT_SOURCE_JOYSTICK); - ASSERT_EQ(AINPUT_SOURCE_JOYSTICK, event.getSource()); + ASSERT_EQ(static_cast(AINPUT_SOURCE_JOYSTICK), event.getSource()); // Set action. event.setAction(AMOTION_EVENT_ACTION_CANCEL); diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp index a1367387bc..34c52d03d1 100644 --- a/libs/input/tests/InputPublisherAndConsumer_test.cpp +++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp @@ -89,8 +89,9 @@ void InputPublisherAndConsumerTest::PublishAndConsumeKeyEvent() { uint32_t consumeSeq; InputEvent* event; + int32_t displayId; status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event, - 0); + &displayId); ASSERT_EQ(OK, status) << "consumer consume should return OK"; @@ -133,7 +134,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() { const uint32_t seq = 15; const int32_t deviceId = 1; const int32_t source = AINPUT_SOURCE_TOUCHSCREEN; - const int32_t displayId = 0; + int32_t displayId = 0; const int32_t action = AMOTION_EVENT_ACTION_MOVE; const int32_t actionButton = 0; const int32_t flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED; @@ -176,7 +177,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() { uint32_t consumeSeq; InputEvent* event; status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event, - 0); + &displayId); ASSERT_EQ(OK, status) << "consumer consume should return OK"; diff --git a/services/inputflinger/InputDispatcher.cpp b/services/inputflinger/InputDispatcher.cpp index 031218562f..906794aee9 100644 --- a/services/inputflinger/InputDispatcher.cpp +++ b/services/inputflinger/InputDispatcher.cpp @@ -1993,10 +1993,10 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime, const PointerCoords* usingCoords = motionEntry->pointerCoords; // Set the X and Y offset depending on the input source. - float xOffset, yOffset, scaleFactor; + float xOffset, yOffset; if ((motionEntry->source & AINPUT_SOURCE_CLASS_POINTER) && !(dispatchEntry->targetFlags & InputTarget::FLAG_ZERO_COORDS)) { - scaleFactor = dispatchEntry->scaleFactor; + float scaleFactor = dispatchEntry->scaleFactor; xOffset = dispatchEntry->xOffset * scaleFactor; yOffset = dispatchEntry->yOffset * scaleFactor; if (scaleFactor != 1.0f) { @@ -2009,7 +2009,6 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime, } else { xOffset = 0.0f; yOffset = 0.0f; - scaleFactor = 1.0f; // We don't want the dispatch target to know. if (dispatchEntry->targetFlags & InputTarget::FLAG_ZERO_COORDS) { diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index 6dd12d6bdd..4304982687 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -2258,7 +2258,7 @@ void KeyboardInputMapper::dump(String8& dump) { dump.appendFormat(INDENT3 "Orientation: %d\n", mOrientation); dump.appendFormat(INDENT3 "KeyDowns: %zu keys currently down\n", mKeyDowns.size()); dump.appendFormat(INDENT3 "MetaState: 0x%0x\n", mMetaState); - dump.appendFormat(INDENT3 "DownTime: %lld\n", (long long)mDownTime); + dump.appendFormat(INDENT3 "DownTime: %" PRId64 "\n", mDownTime); } @@ -2619,7 +2619,7 @@ void CursorInputMapper::dump(String8& dump) { dump.appendFormat(INDENT3 "Orientation: %d\n", mOrientation); dump.appendFormat(INDENT3 "ButtonState: 0x%08x\n", mButtonState); dump.appendFormat(INDENT3 "Down: %s\n", toString(isPointerDown(mButtonState))); - dump.appendFormat(INDENT3 "DownTime: %lld\n", (long long)mDownTime); + dump.appendFormat(INDENT3 "DownTime: %" PRId64 "\n", mDownTime); } void CursorInputMapper::configure(nsecs_t when, @@ -5508,18 +5508,15 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, // Otherwise choose an arbitrary remaining pointer. // This guarantees we always have an active touch id when there is at least one pointer. // We keep the same active touch id for as long as possible. - bool activeTouchChanged = false; int32_t lastActiveTouchId = mPointerGesture.activeTouchId; int32_t activeTouchId = lastActiveTouchId; if (activeTouchId < 0) { if (!mCurrentCookedState.fingerIdBits.isEmpty()) { - activeTouchChanged = true; activeTouchId = mPointerGesture.activeTouchId = mCurrentCookedState.fingerIdBits.firstMarkedBit(); mPointerGesture.firstTouchTime = when; } } else if (!mCurrentCookedState.fingerIdBits.hasBit(activeTouchId)) { - activeTouchChanged = true; if (!mCurrentCookedState.fingerIdBits.isEmpty()) { activeTouchId = mPointerGesture.activeTouchId = mCurrentCookedState.fingerIdBits.firstMarkedBit(); @@ -5615,7 +5612,6 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, } if (bestId >= 0 && bestId != activeTouchId) { mPointerGesture.activeTouchId = activeTouchId = bestId; - activeTouchChanged = true; #if DEBUG_GESTURES ALOGD("Gestures: BUTTON_CLICK_OR_DRAG switched pointers, " "bestId=%d, bestSpeed=%0.3f", bestId, bestSpeed); -- cgit v1.2.3-59-g8ed1b From 96f12993947f6bf0240ab28e7f44379a0acafbfd Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Thu, 9 Nov 2017 14:45:38 -0800 Subject: Fix sanitizer in InputFlinger Reader/Dispatcher. Refactor for loops that were generating runtime errors on integer sanitized builds. Bug: 30969751 Test: Compiles and boots without runtime errors. Change-Id: I5772333b8060d643c756f229187d02ae5caa7ed7 --- services/inputflinger/InputDispatcher.cpp | 6 ++++-- services/inputflinger/InputReader.cpp | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'services/inputflinger/InputReader.cpp') diff --git a/services/inputflinger/InputDispatcher.cpp b/services/inputflinger/InputDispatcher.cpp index 906794aee9..8ab30e8722 100644 --- a/services/inputflinger/InputDispatcher.cpp +++ b/services/inputflinger/InputDispatcher.cpp @@ -2903,7 +2903,7 @@ void InputDispatcher::setInputWindows(const Vector >& inpu for (size_t d = 0; d < mTouchStatesByDisplay.size(); d++) { TouchState& state = mTouchStatesByDisplay.editValueAt(d); - for (size_t i = 0; i < state.windows.size(); i++) { + for (size_t i = 0; i < state.windows.size(); ) { TouchedWindow& touchedWindow = state.windows.editItemAt(i); if (!hasWindowHandleLocked(touchedWindow.windowHandle)) { #if DEBUG_FOCUS @@ -2918,7 +2918,9 @@ void InputDispatcher::setInputWindows(const Vector >& inpu synthesizeCancelationEventsForInputChannelLocked( touchedInputChannel, options); } - state.windows.removeAt(i--); + state.windows.removeAt(i); + } else { + ++i; } } } diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index 4304982687..591f8d7e61 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -1174,7 +1174,7 @@ void InputDevice::process(const RawEvent* rawEvents, size_t count) { // gamepad button presses are handled by different mappers but they should be dispatched // in the order received. size_t numMappers = mMappers.size(); - for (const RawEvent* rawEvent = rawEvents; count--; rawEvent++) { + 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, @@ -1202,6 +1202,7 @@ void InputDevice::process(const RawEvent* rawEvents, size_t count) { mapper->process(rawEvent); } } + --count; } } -- cgit v1.2.3-59-g8ed1b From f93fcf4c403fa4181536821680d495824a4290c5 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Wed, 22 Nov 2017 16:00:14 -0800 Subject: Prefer std::string over String8 String8 is obsolete, only use std::string in the input libraries now. Bug: 64258224 Test: make Change-Id: I958b6b281d969138f39cc26825c877a24bc4a853 --- include/input/InputTransport.h | 9 +- libs/input/InputTransport.cpp | 62 ++-- libs/input/tests/InputChannel_test.cpp | 16 +- .../input/tests/InputPublisherAndConsumer_test.cpp | 2 +- services/inputflinger/Android.bp | 1 + services/inputflinger/EventHub.cpp | 39 +- services/inputflinger/EventHub.h | 5 +- services/inputflinger/InputApplication.h | 8 +- services/inputflinger/InputDispatcher.cpp | 271 +++++++------- services/inputflinger/InputDispatcher.h | 29 +- services/inputflinger/InputReader.cpp | 401 +++++++++++---------- services/inputflinger/InputReader.h | 49 ++- services/inputflinger/InputWindow.h | 7 +- .../inputflinger/tests/InputDispatcher_test.cpp | 2 +- services/inputflinger/tests/InputReader_test.cpp | 2 +- 15 files changed, 451 insertions(+), 452 deletions(-) (limited to 'services/inputflinger/InputReader.cpp') diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h index c4b5dca23d..6187528cff 100644 --- a/include/input/InputTransport.h +++ b/include/input/InputTransport.h @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -142,16 +141,16 @@ protected: virtual ~InputChannel(); public: - InputChannel(const String8& name, int fd); + InputChannel(const std::string& name, int fd); /* Creates a pair of input channels. * * Returns OK on success. */ - static status_t openInputChannelPair(const String8& name, + static status_t openInputChannelPair(const std::string& name, sp& outServerChannel, sp& outClientChannel); - inline String8 getName() const { return mName; } + inline std::string getName() const { return mName; } inline int getFd() const { return mFd; } /* Sends a message to the other endpoint. @@ -183,7 +182,7 @@ public: sp dup() const; private: - String8 mName; + std::string mName; int mFd; }; diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp index b8901bd123..5fe8d8bc9c 100644 --- a/libs/input/InputTransport.cpp +++ b/libs/input/InputTransport.cpp @@ -99,34 +99,34 @@ size_t InputMessage::size() const { // --- InputChannel --- -InputChannel::InputChannel(const String8& name, int fd) : +InputChannel::InputChannel(const std::string& name, int fd) : mName(name), mFd(fd) { #if DEBUG_CHANNEL_LIFECYCLE ALOGD("Input channel constructed: name='%s', fd=%d", - mName.string(), fd); + mName.c_str(), fd); #endif int result = fcntl(mFd, F_SETFL, O_NONBLOCK); LOG_ALWAYS_FATAL_IF(result != 0, "channel '%s' ~ Could not make socket " - "non-blocking. errno=%d", mName.string(), errno); + "non-blocking. errno=%d", mName.c_str(), errno); } InputChannel::~InputChannel() { #if DEBUG_CHANNEL_LIFECYCLE ALOGD("Input channel destroyed: name='%s', fd=%d", - mName.string(), mFd); + mName.c_str(), mFd); #endif ::close(mFd); } -status_t InputChannel::openInputChannelPair(const String8& name, +status_t InputChannel::openInputChannelPair(const std::string& name, sp& outServerChannel, sp& outClientChannel) { int sockets[2]; if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sockets)) { status_t result = -errno; ALOGE("channel '%s' ~ Could not create socket pair. errno=%d", - name.string(), errno); + name.c_str(), errno); outServerChannel.clear(); outClientChannel.clear(); return result; @@ -138,12 +138,12 @@ status_t InputChannel::openInputChannelPair(const String8& name, setsockopt(sockets[1], SOL_SOCKET, SO_SNDBUF, &bufferSize, sizeof(bufferSize)); setsockopt(sockets[1], SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize)); - String8 serverChannelName = name; - serverChannelName.append(" (server)"); + std::string serverChannelName = name; + serverChannelName += " (server)"; outServerChannel = new InputChannel(serverChannelName, sockets[0]); - String8 clientChannelName = name; - clientChannelName.append(" (client)"); + std::string clientChannelName = name; + clientChannelName += " (client)"; outClientChannel = new InputChannel(clientChannelName, sockets[1]); return OK; } @@ -158,7 +158,7 @@ status_t InputChannel::sendMessage(const InputMessage* msg) { if (nWrite < 0) { int error = errno; #if DEBUG_CHANNEL_MESSAGES - ALOGD("channel '%s' ~ error sending message of type %d, errno=%d", mName.string(), + ALOGD("channel '%s' ~ error sending message of type %d, errno=%d", mName.c_str(), msg->header.type, error); #endif if (error == EAGAIN || error == EWOULDBLOCK) { @@ -173,13 +173,13 @@ status_t InputChannel::sendMessage(const InputMessage* msg) { if (size_t(nWrite) != msgLength) { #if DEBUG_CHANNEL_MESSAGES ALOGD("channel '%s' ~ error sending message type %d, send was incomplete", - mName.string(), msg->header.type); + mName.c_str(), msg->header.type); #endif return DEAD_OBJECT; } #if DEBUG_CHANNEL_MESSAGES - ALOGD("channel '%s' ~ sent message of type %d", mName.string(), msg->header.type); + ALOGD("channel '%s' ~ sent message of type %d", mName.c_str(), msg->header.type); #endif return OK; } @@ -193,7 +193,7 @@ status_t InputChannel::receiveMessage(InputMessage* msg) { if (nRead < 0) { int error = errno; #if DEBUG_CHANNEL_MESSAGES - ALOGD("channel '%s' ~ receive message failed, errno=%d", mName.string(), errno); + ALOGD("channel '%s' ~ receive message failed, errno=%d", mName.c_str(), errno); #endif if (error == EAGAIN || error == EWOULDBLOCK) { return WOULD_BLOCK; @@ -206,20 +206,20 @@ status_t InputChannel::receiveMessage(InputMessage* msg) { if (nRead == 0) { // check for EOF #if DEBUG_CHANNEL_MESSAGES - ALOGD("channel '%s' ~ receive message failed because peer was closed", mName.string()); + ALOGD("channel '%s' ~ receive message failed because peer was closed", mName.c_str()); #endif return DEAD_OBJECT; } if (!msg->isValid(nRead)) { #if DEBUG_CHANNEL_MESSAGES - ALOGD("channel '%s' ~ received invalid message", mName.string()); + ALOGD("channel '%s' ~ received invalid message", mName.c_str()); #endif return BAD_VALUE; } #if DEBUG_CHANNEL_MESSAGES - ALOGD("channel '%s' ~ received message of type %d", mName.string(), msg->header.type); + ALOGD("channel '%s' ~ received message of type %d", mName.c_str(), msg->header.type); #endif return OK; } @@ -255,7 +255,7 @@ status_t InputPublisher::publishKeyEvent( ALOGD("channel '%s' publisher ~ publishKeyEvent: seq=%u, deviceId=%d, source=0x%x, " "action=0x%x, flags=0x%x, keyCode=%d, scanCode=%d, metaState=0x%x, repeatCount=%d," "downTime=%" PRId64 ", eventTime=%" PRId64, - mChannel->getName().string(), seq, + mChannel->getName().c_str(), seq, deviceId, source, action, flags, keyCode, scanCode, metaState, repeatCount, downTime, eventTime); #endif @@ -307,7 +307,7 @@ status_t InputPublisher::publishMotionEvent( "metaState=0x%x, buttonState=0x%x, xOffset=%f, yOffset=%f, " "xPrecision=%f, yPrecision=%f, downTime=%" PRId64 ", eventTime=%" PRId64 ", " "pointerCount=%" PRIu32, - mChannel->getName().string(), seq, + mChannel->getName().c_str(), seq, deviceId, source, action, actionButton, flags, edgeFlags, metaState, buttonState, xOffset, yOffset, xPrecision, yPrecision, downTime, eventTime, pointerCount); #endif @@ -319,7 +319,7 @@ status_t InputPublisher::publishMotionEvent( if (pointerCount > MAX_POINTERS || pointerCount < 1) { ALOGE("channel '%s' publisher ~ Invalid number of pointers provided: %" PRIu32 ".", - mChannel->getName().string(), pointerCount); + mChannel->getName().c_str(), pointerCount); return BAD_VALUE; } @@ -352,7 +352,7 @@ status_t InputPublisher::publishMotionEvent( status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandled) { #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' publisher ~ receiveFinishedSignal", - mChannel->getName().string()); + mChannel->getName().c_str()); #endif InputMessage msg; @@ -364,7 +364,7 @@ status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandle } if (msg.header.type != InputMessage::TYPE_FINISHED) { ALOGE("channel '%s' publisher ~ Received unexpected message of type %d from consumer", - mChannel->getName().string(), msg.header.type); + mChannel->getName().c_str(), msg.header.type); return UNKNOWN_ERROR; } *outSeq = msg.body.finished.seq; @@ -402,7 +402,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, int32_t* displayId) { #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ consume: consumeBatches=%s, frameTime=%" PRId64, - mChannel->getName().string(), consumeBatches ? "true" : "false", frameTime); + mChannel->getName().c_str(), consumeBatches ? "true" : "false", frameTime); #endif *outSeq = 0; @@ -426,7 +426,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, if (*outEvent) { #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ consumed batch event, seq=%u", - mChannel->getName().string(), *outSeq); + mChannel->getName().c_str(), *outSeq); #endif break; } @@ -445,7 +445,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, *outEvent = keyEvent; #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ consumed key event, seq=%u", - mChannel->getName().string(), *outSeq); + mChannel->getName().c_str(), *outSeq); #endif break; } @@ -458,7 +458,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, batch.samples.push(mMsg); #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ appended to batch event", - mChannel->getName().string()); + mChannel->getName().c_str()); #endif break; } else { @@ -474,7 +474,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ consumed batch event and " "deferred current event, seq=%u", - mChannel->getName().string(), *outSeq); + mChannel->getName().c_str(), *outSeq); #endif break; } @@ -488,7 +488,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, batch.samples.push(mMsg); #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ started batch event", - mChannel->getName().string()); + mChannel->getName().c_str()); #endif break; } @@ -503,14 +503,14 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, *displayId = mMsg.body.motion.displayId; #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ consumed motion event, seq=%u", - mChannel->getName().string(), *outSeq); + mChannel->getName().c_str(), *outSeq); #endif break; } default: ALOGE("channel '%s' consumer ~ Received unexpected message of type %d", - mChannel->getName().string(), mMsg.header.type); + mChannel->getName().c_str(), mMsg.header.type); return UNKNOWN_ERROR; } } @@ -828,7 +828,7 @@ bool InputConsumer::shouldResampleTool(int32_t toolType) { status_t InputConsumer::sendFinishedSignal(uint32_t seq, bool handled) { #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ sendFinishedSignal: seq=%u, handled=%s", - mChannel->getName().string(), seq, handled ? "true" : "false"); + mChannel->getName().c_str(), seq, handled ? "true" : "false"); #endif if (!seq) { diff --git a/libs/input/tests/InputChannel_test.cpp b/libs/input/tests/InputChannel_test.cpp index e71ebe2a1d..96c165cac2 100644 --- a/libs/input/tests/InputChannel_test.cpp +++ b/libs/input/tests/InputChannel_test.cpp @@ -41,9 +41,9 @@ TEST_F(InputChannelTest, ConstructorAndDestructor_TakesOwnershipOfFileDescriptor // of a pipe and to check for EPIPE on the other end after the channel is destroyed. Pipe pipe; - sp inputChannel = new InputChannel(String8("channel name"), pipe.sendFd); + sp inputChannel = new InputChannel("channel name", pipe.sendFd); - EXPECT_STREQ("channel name", inputChannel->getName().string()) + EXPECT_STREQ("channel name", inputChannel->getName().c_str()) << "channel should have provided name"; EXPECT_EQ(pipe.sendFd, inputChannel->getFd()) << "channel should have provided fd"; @@ -60,16 +60,16 @@ TEST_F(InputChannelTest, ConstructorAndDestructor_TakesOwnershipOfFileDescriptor TEST_F(InputChannelTest, OpenInputChannelPair_ReturnsAPairOfConnectedChannels) { sp serverChannel, clientChannel; - status_t result = InputChannel::openInputChannelPair(String8("channel name"), + status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); ASSERT_EQ(OK, result) << "should have successfully opened a channel pair"; // Name - EXPECT_STREQ("channel name (server)", serverChannel->getName().string()) + EXPECT_STREQ("channel name (server)", serverChannel->getName().c_str()) << "server channel should have suffixed name"; - EXPECT_STREQ("channel name (client)", clientChannel->getName().string()) + EXPECT_STREQ("channel name (client)", clientChannel->getName().c_str()) << "client channel should have suffixed name"; // Server->Client communication @@ -111,7 +111,7 @@ TEST_F(InputChannelTest, OpenInputChannelPair_ReturnsAPairOfConnectedChannels) { TEST_F(InputChannelTest, ReceiveSignal_WhenNoSignalPresent_ReturnsAnError) { sp serverChannel, clientChannel; - status_t result = InputChannel::openInputChannelPair(String8("channel name"), + status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); ASSERT_EQ(OK, result) @@ -125,7 +125,7 @@ TEST_F(InputChannelTest, ReceiveSignal_WhenNoSignalPresent_ReturnsAnError) { TEST_F(InputChannelTest, ReceiveSignal_WhenPeerClosed_ReturnsAnError) { sp serverChannel, clientChannel; - status_t result = InputChannel::openInputChannelPair(String8("channel name"), + status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); ASSERT_EQ(OK, result) @@ -141,7 +141,7 @@ TEST_F(InputChannelTest, ReceiveSignal_WhenPeerClosed_ReturnsAnError) { TEST_F(InputChannelTest, SendSignal_WhenPeerClosed_ReturnsAnError) { sp serverChannel, clientChannel; - status_t result = InputChannel::openInputChannelPair(String8("channel name"), + status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); ASSERT_EQ(OK, result) diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp index f86f876aa4..c5322414fd 100644 --- a/libs/input/tests/InputPublisherAndConsumer_test.cpp +++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp @@ -36,7 +36,7 @@ protected: PreallocatedInputEventFactory mEventFactory; virtual void SetUp() { - status_t result = InputChannel::openInputChannelPair(String8("channel name"), + status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); mPublisher = new InputPublisher(serverChannel); diff --git a/services/inputflinger/Android.bp b/services/inputflinger/Android.bp index 238cba362c..a9e5a4339c 100644 --- a/services/inputflinger/Android.bp +++ b/services/inputflinger/Android.bp @@ -26,6 +26,7 @@ cc_library_shared { ], shared_libs: [ + "libbase", "libbinder", "libcrypto", "libcutils", diff --git a/services/inputflinger/EventHub.cpp b/services/inputflinger/EventHub.cpp index 99fe0f5d55..4d9a2a0254 100644 --- a/services/inputflinger/EventHub.cpp +++ b/services/inputflinger/EventHub.cpp @@ -39,6 +39,7 @@ #include +#include #include #include #include @@ -64,6 +65,8 @@ #define INDENT2 " " #define INDENT3 " " +using android::base::StringPrintf; + namespace android { static const char *WAKE_LOCK_ID = "KeyEvents"; @@ -1733,43 +1736,43 @@ void EventHub::requestReopenDevices() { mNeedToReopenDevices = true; } -void EventHub::dump(String8& dump) { - dump.append("Event Hub State:\n"); +void EventHub::dump(std::string& dump) { + dump += "Event Hub State:\n"; { // acquire lock AutoMutex _l(mLock); - dump.appendFormat(INDENT "BuiltInKeyboardId: %d\n", mBuiltInKeyboardId); + dump += StringPrintf(INDENT "BuiltInKeyboardId: %d\n", mBuiltInKeyboardId); - dump.append(INDENT "Devices:\n"); + dump += INDENT "Devices:\n"; for (size_t i = 0; i < mDevices.size(); i++) { const Device* device = mDevices.valueAt(i); if (mBuiltInKeyboardId == device->id) { - dump.appendFormat(INDENT2 "%d: %s (aka device 0 - built-in keyboard)\n", + dump += StringPrintf(INDENT2 "%d: %s (aka device 0 - built-in keyboard)\n", device->id, device->identifier.name.string()); } else { - dump.appendFormat(INDENT2 "%d: %s\n", device->id, + dump += StringPrintf(INDENT2 "%d: %s\n", device->id, device->identifier.name.string()); } - dump.appendFormat(INDENT3 "Classes: 0x%08x\n", device->classes); - dump.appendFormat(INDENT3 "Path: %s\n", device->path.string()); - dump.appendFormat(INDENT3 "Enabled: %s\n", toString(device->enabled)); - dump.appendFormat(INDENT3 "Descriptor: %s\n", device->identifier.descriptor.string()); - dump.appendFormat(INDENT3 "Location: %s\n", device->identifier.location.string()); - dump.appendFormat(INDENT3 "ControllerNumber: %d\n", device->controllerNumber); - dump.appendFormat(INDENT3 "UniqueId: %s\n", device->identifier.uniqueId.string()); - dump.appendFormat(INDENT3 "Identifier: bus=0x%04x, vendor=0x%04x, " + dump += StringPrintf(INDENT3 "Classes: 0x%08x\n", device->classes); + dump += StringPrintf(INDENT3 "Path: %s\n", device->path.string()); + dump += StringPrintf(INDENT3 "Enabled: %s\n", toString(device->enabled)); + dump += StringPrintf(INDENT3 "Descriptor: %s\n", device->identifier.descriptor.string()); + dump += StringPrintf(INDENT3 "Location: %s\n", device->identifier.location.string()); + dump += StringPrintf(INDENT3 "ControllerNumber: %d\n", device->controllerNumber); + dump += StringPrintf(INDENT3 "UniqueId: %s\n", device->identifier.uniqueId.string()); + 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); - dump.appendFormat(INDENT3 "KeyLayoutFile: %s\n", + dump += StringPrintf(INDENT3 "KeyLayoutFile: %s\n", device->keyMap.keyLayoutFile.string()); - dump.appendFormat(INDENT3 "KeyCharacterMapFile: %s\n", + dump += StringPrintf(INDENT3 "KeyCharacterMapFile: %s\n", device->keyMap.keyCharacterMapFile.string()); - dump.appendFormat(INDENT3 "ConfigurationFile: %s\n", + dump += StringPrintf(INDENT3 "ConfigurationFile: %s\n", device->configurationFile.string()); - dump.appendFormat(INDENT3 "HaveKeyboardLayoutOverlay: %s\n", + dump += StringPrintf(INDENT3 "HaveKeyboardLayoutOverlay: %s\n", toString(device->overlayKeyMap != NULL)); } } // release lock diff --git a/services/inputflinger/EventHub.h b/services/inputflinger/EventHub.h index 727b73aeb8..66bc29456b 100644 --- a/services/inputflinger/EventHub.h +++ b/services/inputflinger/EventHub.h @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -262,7 +261,7 @@ public: virtual void wake() = 0; /* Dump EventHub state to a string. */ - virtual void dump(String8& dump) = 0; + virtual void dump(std::string& dump) = 0; /* Called by the heatbeat to ensures that the reader has not deadlocked. */ virtual void monitor() = 0; @@ -333,7 +332,7 @@ public: virtual void wake(); - virtual void dump(String8& dump); + virtual void dump(std::string& dump); virtual void monitor(); protected: diff --git a/services/inputflinger/InputApplication.h b/services/inputflinger/InputApplication.h index 1f5504c2d2..724fc2c4f4 100644 --- a/services/inputflinger/InputApplication.h +++ b/services/inputflinger/InputApplication.h @@ -18,10 +18,8 @@ #define _UI_INPUT_APPLICATION_H #include - #include #include -#include namespace android { @@ -29,7 +27,7 @@ namespace android { * Describes the properties of an application that can receive input. */ struct InputApplicationInfo { - String8 name; + std::string name; nsecs_t dispatchingTimeout; }; @@ -46,8 +44,8 @@ public: return mInfo; } - inline String8 getName() const { - return mInfo ? mInfo->name : String8(""); + inline std::string getName() const { + return mInfo ? mInfo->name : ""; } inline nsecs_t getDispatchingTimeout(nsecs_t defaultValue) const { diff --git a/services/inputflinger/InputDispatcher.cpp b/services/inputflinger/InputDispatcher.cpp index 8ab30e8722..4194dea8a9 100644 --- a/services/inputflinger/InputDispatcher.cpp +++ b/services/inputflinger/InputDispatcher.cpp @@ -47,10 +47,12 @@ #include #include +#include #include #include #include +#include #include #include #include @@ -61,6 +63,8 @@ #define INDENT3 " " #define INDENT4 " " +using android::base::StringPrintf; + namespace android { // Default input dispatching timeout if there is no focused application or paused window @@ -176,9 +180,9 @@ static bool isMainDisplay(int32_t displayId) { return displayId == ADISPLAY_ID_DEFAULT || displayId == ADISPLAY_ID_NONE; } -static void dumpRegion(String8& dump, const Region& region) { +static void dumpRegion(std::string& dump, const Region& region) { if (region.isEmpty()) { - dump.append(""); + dump += ""; return; } @@ -189,9 +193,9 @@ static void dumpRegion(String8& dump, const Region& region) { if (first) { first = false; } else { - dump.append("|"); + dump += "|"; } - dump.appendFormat("[%d,%d][%d,%d]", cur->left, cur->top, cur->right, cur->bottom); + dump += StringPrintf("[%d,%d][%d,%d]", cur->left, cur->top, cur->right, cur->bottom); cur++; } } @@ -937,7 +941,7 @@ void InputDispatcher::dispatchEventLocked(nsecs_t currentTime, #if DEBUG_FOCUS ALOGD("Dropping event delivery to target with channel '%s' because it " "is no longer registered with the input dispatcher.", - inputTarget.inputChannel->getName().string()); + inputTarget.inputChannel->getName().c_str()); #endif } } @@ -963,7 +967,7 @@ int32_t InputDispatcher::handleTargetsNotReadyLocked(nsecs_t currentTime, if (mInputTargetWaitCause != INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY) { #if DEBUG_FOCUS ALOGD("Waiting for application to become ready for input: %s. Reason: %s", - getApplicationWindowLabelLocked(applicationHandle, windowHandle).string(), + getApplicationWindowLabelLocked(applicationHandle, windowHandle).c_str(), reason); #endif nsecs_t timeout; @@ -1070,7 +1074,7 @@ void InputDispatcher::resetANRTimeoutsLocked() { int32_t InputDispatcher::findFocusedWindowTargetsLocked(nsecs_t currentTime, const EventEntry* entry, Vector& inputTargets, nsecs_t* nextWakeupTime) { int32_t injectionResult; - String8 reason; + std::string reason; // If there is no currently focused window and no focused application // then drop the event. @@ -1098,9 +1102,9 @@ int32_t InputDispatcher::findFocusedWindowTargetsLocked(nsecs_t currentTime, // Check whether the window is ready for more input. reason = checkWindowReadyForMoreInputLocked(currentTime, mFocusedWindowHandle, entry, "focused"); - if (!reason.isEmpty()) { + if (!reason.empty()) { injectionResult = handleTargetsNotReadyLocked(currentTime, entry, - mFocusedApplicationHandle, mFocusedWindowHandle, nextWakeupTime, reason.string()); + mFocusedApplicationHandle, mFocusedWindowHandle, nextWakeupTime, reason.c_str()); goto Unresponsive; } @@ -1309,8 +1313,8 @@ int32_t InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, && newTouchedWindowHandle != NULL) { #if DEBUG_FOCUS ALOGD("Touch is slipping out of window %s into window %s.", - oldTouchedWindowHandle->getName().string(), - newTouchedWindowHandle->getName().string()); + oldTouchedWindowHandle->getName().c_str(), + newTouchedWindowHandle->getName().c_str()); #endif // Make a slippery exit from the old window. mTempTouchState.addOrUpdateWindow(oldTouchedWindowHandle, @@ -1344,7 +1348,7 @@ int32_t InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, if (mLastHoverWindowHandle != NULL) { #if DEBUG_HOVER ALOGD("Sending hover exit event to window %s.", - mLastHoverWindowHandle->getName().string()); + mLastHoverWindowHandle->getName().c_str()); #endif mTempTouchState.addOrUpdateWindow(mLastHoverWindowHandle, InputTarget::FLAG_DISPATCH_AS_HOVER_EXIT, BitSet32(0)); @@ -1354,7 +1358,7 @@ int32_t InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, if (newHoverWindowHandle != NULL) { #if DEBUG_HOVER ALOGD("Sending hover enter event to window %s.", - newHoverWindowHandle->getName().string()); + newHoverWindowHandle->getName().c_str()); #endif mTempTouchState.addOrUpdateWindow(newHoverWindowHandle, InputTarget::FLAG_DISPATCH_AS_HOVER_ENTER, BitSet32(0)); @@ -1412,11 +1416,11 @@ int32_t InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, const TouchedWindow& touchedWindow = mTempTouchState.windows[i]; if (touchedWindow.targetFlags & InputTarget::FLAG_FOREGROUND) { // Check whether the window is ready for more input. - String8 reason = checkWindowReadyForMoreInputLocked(currentTime, + std::string reason = checkWindowReadyForMoreInputLocked(currentTime, touchedWindow.windowHandle, entry, "touched"); - if (!reason.isEmpty()) { + if (!reason.empty()) { injectionResult = handleTargetsNotReadyLocked(currentTime, entry, - NULL, touchedWindow.windowHandle, nextWakeupTime, reason.string()); + NULL, touchedWindow.windowHandle, nextWakeupTime, reason.c_str()); goto Unresponsive; } } @@ -1604,7 +1608,7 @@ bool InputDispatcher::checkInjectionPermission(const sp& wind ALOGW("Permission denied: injecting event from pid %d uid %d to window %s " "owned by uid %d", injectionState->injectorPid, injectionState->injectorUid, - windowHandle->getName().string(), + windowHandle->getName().c_str(), windowHandle->getInfo()->ownerUid); } else { ALOGW("Permission denied: injecting event from pid %d uid %d", @@ -1656,18 +1660,18 @@ bool InputDispatcher::isWindowObscuredLocked(const sp& window return false; } -String8 InputDispatcher::checkWindowReadyForMoreInputLocked(nsecs_t currentTime, +std::string InputDispatcher::checkWindowReadyForMoreInputLocked(nsecs_t currentTime, const sp& windowHandle, const EventEntry* eventEntry, const char* targetType) { // If the window is paused then keep waiting. if (windowHandle->getInfo()->paused) { - return String8::format("Waiting because the %s window is paused.", targetType); + return StringPrintf("Waiting because the %s window is paused.", targetType); } // If the window's connection is not registered then keep waiting. ssize_t connectionIndex = getConnectionIndexLocked(windowHandle->getInputChannel()); if (connectionIndex < 0) { - return String8::format("Waiting because the %s window's input channel is not " + return StringPrintf("Waiting because the %s window's input channel is not " "registered with the input dispatcher. The window may be in the process " "of being removed.", targetType); } @@ -1675,14 +1679,14 @@ String8 InputDispatcher::checkWindowReadyForMoreInputLocked(nsecs_t currentTime, // If the connection is dead then keep waiting. sp connection = mConnectionsByFd.valueAt(connectionIndex); if (connection->status != Connection::STATUS_NORMAL) { - return String8::format("Waiting because the %s window's input connection is %s." + return StringPrintf("Waiting because the %s window's input connection is %s." "The window may be in the process of being removed.", targetType, connection->getStatusLabel()); } // If the connection is backed up then keep waiting. if (connection->inputPublisherBlocked) { - return String8::format("Waiting because the %s window's input channel is full. " + return StringPrintf("Waiting because the %s window's input channel is full. " "Outbound queue length: %d. Wait queue length: %d.", targetType, connection->outboundQueue.count(), connection->waitQueue.count()); } @@ -1701,7 +1705,7 @@ String8 InputDispatcher::checkWindowReadyForMoreInputLocked(nsecs_t currentTime, // To obtain this behavior, we must serialize key events with respect to all // prior input events. if (!connection->outboundQueue.isEmpty() || !connection->waitQueue.isEmpty()) { - return String8::format("Waiting to send key event because the %s window has not " + return StringPrintf("Waiting to send key event because the %s window has not " "finished processing all of the input events that were previously " "delivered to it. Outbound queue length: %d. Wait queue length: %d.", targetType, connection->outboundQueue.count(), connection->waitQueue.count()); @@ -1725,7 +1729,7 @@ String8 InputDispatcher::checkWindowReadyForMoreInputLocked(nsecs_t currentTime, if (!connection->waitQueue.isEmpty() && currentTime >= connection->waitQueue.head->deliveryTime + STREAM_AHEAD_EVENT_TIMEOUT) { - return String8::format("Waiting to send non-key event because the %s window has not " + return StringPrintf("Waiting to send non-key event because the %s window has not " "finished processing certain input events that were delivered to it over " "%0.1fms ago. Wait queue length: %d. Wait queue head age: %0.1fms.", targetType, STREAM_AHEAD_EVENT_TIMEOUT * 0.000001f, @@ -1733,17 +1737,17 @@ String8 InputDispatcher::checkWindowReadyForMoreInputLocked(nsecs_t currentTime, (currentTime - connection->waitQueue.head->deliveryTime) * 0.000001f); } } - return String8::empty(); + return ""; } -String8 InputDispatcher::getApplicationWindowLabelLocked( +std::string InputDispatcher::getApplicationWindowLabelLocked( const sp& applicationHandle, const sp& windowHandle) { if (applicationHandle != NULL) { if (windowHandle != NULL) { - String8 label(applicationHandle->getName()); - label.append(" - "); - label.append(windowHandle->getName()); + std::string label(applicationHandle->getName()); + label += " - "; + label += windowHandle->getName(); return label; } else { return applicationHandle->getName(); @@ -1751,7 +1755,7 @@ String8 InputDispatcher::getApplicationWindowLabelLocked( } else if (windowHandle != NULL) { return windowHandle->getName(); } else { - return String8(""); + return ""; } } @@ -1760,7 +1764,7 @@ void InputDispatcher::pokeUserActivityLocked(const EventEntry* eventEntry) { const InputWindowInfo* info = mFocusedWindowHandle->getInfo(); if (info->inputFeatures & InputWindowInfo::INPUT_FEATURE_DISABLE_USER_ACTIVITY) { #if DEBUG_DISPATCH_CYCLE - ALOGD("Not poking user activity: disabled by window '%s'.", info->name.string()); + ALOGD("Not poking user activity: disabled by window '%s'.", info->name.c_str()); #endif return; } @@ -2882,7 +2886,7 @@ void InputDispatcher::setInputWindows(const Vector >& inpu if (mFocusedWindowHandle != NULL) { #if DEBUG_FOCUS ALOGD("Focus left window: %s", - mFocusedWindowHandle->getName().string()); + mFocusedWindowHandle->getName().c_str()); #endif sp focusedInputChannel = mFocusedWindowHandle->getInputChannel(); if (focusedInputChannel != NULL) { @@ -2895,7 +2899,7 @@ void InputDispatcher::setInputWindows(const Vector >& inpu if (newFocusedWindowHandle != NULL) { #if DEBUG_FOCUS ALOGD("Focus entered window: %s", - newFocusedWindowHandle->getName().string()); + newFocusedWindowHandle->getName().c_str()); #endif } mFocusedWindowHandle = newFocusedWindowHandle; @@ -2908,7 +2912,7 @@ void InputDispatcher::setInputWindows(const Vector >& inpu if (!hasWindowHandleLocked(touchedWindow.windowHandle)) { #if DEBUG_FOCUS ALOGD("Touched window was removed: %s", - touchedWindow.windowHandle->getName().string()); + touchedWindow.windowHandle->getName().c_str()); #endif sp touchedInputChannel = touchedWindow.windowHandle->getInputChannel(); @@ -2933,7 +2937,7 @@ void InputDispatcher::setInputWindows(const Vector >& inpu const sp& oldWindowHandle = oldWindowHandles.itemAt(i); if (!hasWindowHandleLocked(oldWindowHandle)) { #if DEBUG_FOCUS - ALOGD("Window went away: %s", oldWindowHandle->getName().string()); + ALOGD("Window went away: %s", oldWindowHandle->getName().c_str()); #endif oldWindowHandle->releaseInfo(); } @@ -3035,7 +3039,7 @@ bool InputDispatcher::transferTouchFocus(const sp& fromChannel, const sp& toChannel) { #if DEBUG_FOCUS ALOGD("transferTouchFocus: fromChannel=%s, toChannel=%s", - fromChannel->getName().string(), toChannel->getName().string()); + fromChannel->getName().c_str(), toChannel->getName().c_str()); #endif { // acquire lock AutoMutex _l(mLock); @@ -3132,72 +3136,68 @@ void InputDispatcher::resetAndDropEverythingLocked(const char* reason) { } void InputDispatcher::logDispatchStateLocked() { - String8 dump; + std::string dump; dumpDispatchStateLocked(dump); - char* text = dump.lockBuffer(dump.size()); - char* start = text; - while (*start != '\0') { - char* end = strchr(start, '\n'); - if (*end == '\n') { - *(end++) = '\0'; - } - ALOGD("%s", start); - start = end; + std::istringstream stream(dump); + std::string line; + + while (std::getline(stream, line, '\n')) { + ALOGD("%s", line.c_str()); } } -void InputDispatcher::dumpDispatchStateLocked(String8& dump) { - dump.appendFormat(INDENT "DispatchEnabled: %d\n", mDispatchEnabled); - dump.appendFormat(INDENT "DispatchFrozen: %d\n", mDispatchFrozen); +void InputDispatcher::dumpDispatchStateLocked(std::string& dump) { + dump += StringPrintf(INDENT "DispatchEnabled: %d\n", mDispatchEnabled); + dump += StringPrintf(INDENT "DispatchFrozen: %d\n", mDispatchFrozen); if (mFocusedApplicationHandle != NULL) { - dump.appendFormat(INDENT "FocusedApplication: name='%s', dispatchingTimeout=%0.3fms\n", - mFocusedApplicationHandle->getName().string(), + dump += StringPrintf(INDENT "FocusedApplication: name='%s', dispatchingTimeout=%0.3fms\n", + mFocusedApplicationHandle->getName().c_str(), mFocusedApplicationHandle->getDispatchingTimeout( DEFAULT_INPUT_DISPATCHING_TIMEOUT) / 1000000.0); } else { - dump.append(INDENT "FocusedApplication: \n"); + dump += StringPrintf(INDENT "FocusedApplication: \n"); } - dump.appendFormat(INDENT "FocusedWindow: name='%s'\n", - mFocusedWindowHandle != NULL ? mFocusedWindowHandle->getName().string() : ""); + dump += StringPrintf(INDENT "FocusedWindow: name='%s'\n", + mFocusedWindowHandle != NULL ? mFocusedWindowHandle->getName().c_str() : ""); if (!mTouchStatesByDisplay.isEmpty()) { - dump.appendFormat(INDENT "TouchStatesByDisplay:\n"); + dump += StringPrintf(INDENT "TouchStatesByDisplay:\n"); for (size_t i = 0; i < mTouchStatesByDisplay.size(); i++) { const TouchState& state = mTouchStatesByDisplay.valueAt(i); - dump.appendFormat(INDENT2 "%d: down=%s, split=%s, deviceId=%d, source=0x%08x\n", + dump += StringPrintf(INDENT2 "%d: down=%s, split=%s, deviceId=%d, source=0x%08x\n", state.displayId, toString(state.down), toString(state.split), state.deviceId, state.source); if (!state.windows.isEmpty()) { - dump.append(INDENT3 "Windows:\n"); + dump += INDENT3 "Windows:\n"; for (size_t i = 0; i < state.windows.size(); i++) { const TouchedWindow& touchedWindow = state.windows[i]; - dump.appendFormat(INDENT4 "%zu: name='%s', pointerIds=0x%0x, targetFlags=0x%x\n", - i, touchedWindow.windowHandle->getName().string(), + dump += StringPrintf(INDENT4 "%zu: name='%s', pointerIds=0x%0x, targetFlags=0x%x\n", + i, touchedWindow.windowHandle->getName().c_str(), touchedWindow.pointerIds.value, touchedWindow.targetFlags); } } else { - dump.append(INDENT3 "Windows: \n"); + dump += INDENT3 "Windows: \n"; } } } else { - dump.append(INDENT "TouchStates: \n"); + dump += INDENT "TouchStates: \n"; } if (!mWindowHandles.isEmpty()) { - dump.append(INDENT "Windows:\n"); + dump += INDENT "Windows:\n"; for (size_t i = 0; i < mWindowHandles.size(); i++) { const sp& windowHandle = mWindowHandles.itemAt(i); const InputWindowInfo* windowInfo = windowHandle->getInfo(); - dump.appendFormat(INDENT2 "%zu: name='%s', displayId=%d, " + dump += StringPrintf(INDENT2 "%zu: name='%s', displayId=%d, " "paused=%s, hasFocus=%s, hasWallpaper=%s, " "visible=%s, canReceiveKeys=%s, flags=0x%08x, type=0x%08x, layer=%d, " "frame=[%d,%d][%d,%d], scale=%f, " "touchableRegion=", - i, windowInfo->name.string(), windowInfo->displayId, + i, windowInfo->name.c_str(), windowInfo->displayId, toString(windowInfo->paused), toString(windowInfo->hasFocus), toString(windowInfo->hasWallpaper), @@ -3209,140 +3209,140 @@ void InputDispatcher::dumpDispatchStateLocked(String8& dump) { windowInfo->frameRight, windowInfo->frameBottom, windowInfo->scaleFactor); dumpRegion(dump, windowInfo->touchableRegion); - dump.appendFormat(", inputFeatures=0x%08x", windowInfo->inputFeatures); - dump.appendFormat(", ownerPid=%d, ownerUid=%d, dispatchingTimeout=%0.3fms\n", + dump += StringPrintf(", inputFeatures=0x%08x", windowInfo->inputFeatures); + dump += StringPrintf(", ownerPid=%d, ownerUid=%d, dispatchingTimeout=%0.3fms\n", windowInfo->ownerPid, windowInfo->ownerUid, windowInfo->dispatchingTimeout / 1000000.0); } } else { - dump.append(INDENT "Windows: \n"); + dump += INDENT "Windows: \n"; } if (!mMonitoringChannels.isEmpty()) { - dump.append(INDENT "MonitoringChannels:\n"); + dump += INDENT "MonitoringChannels:\n"; for (size_t i = 0; i < mMonitoringChannels.size(); i++) { const sp& channel = mMonitoringChannels[i]; - dump.appendFormat(INDENT2 "%zu: '%s'\n", i, channel->getName().string()); + dump += StringPrintf(INDENT2 "%zu: '%s'\n", i, channel->getName().c_str()); } } else { - dump.append(INDENT "MonitoringChannels: \n"); + dump += INDENT "MonitoringChannels: \n"; } nsecs_t currentTime = now(); // Dump recently dispatched or dropped events from oldest to newest. if (!mRecentQueue.isEmpty()) { - dump.appendFormat(INDENT "RecentQueue: length=%u\n", mRecentQueue.count()); + dump += StringPrintf(INDENT "RecentQueue: length=%u\n", mRecentQueue.count()); for (EventEntry* entry = mRecentQueue.head; entry; entry = entry->next) { - dump.append(INDENT2); + dump += INDENT2; entry->appendDescription(dump); - dump.appendFormat(", age=%0.1fms\n", + dump += StringPrintf(", age=%0.1fms\n", (currentTime - entry->eventTime) * 0.000001f); } } else { - dump.append(INDENT "RecentQueue: \n"); + dump += INDENT "RecentQueue: \n"; } // Dump event currently being dispatched. if (mPendingEvent) { - dump.append(INDENT "PendingEvent:\n"); - dump.append(INDENT2); + dump += INDENT "PendingEvent:\n"; + dump += INDENT2; mPendingEvent->appendDescription(dump); - dump.appendFormat(", age=%0.1fms\n", + dump += StringPrintf(", age=%0.1fms\n", (currentTime - mPendingEvent->eventTime) * 0.000001f); } else { - dump.append(INDENT "PendingEvent: \n"); + dump += INDENT "PendingEvent: \n"; } // Dump inbound events from oldest to newest. if (!mInboundQueue.isEmpty()) { - dump.appendFormat(INDENT "InboundQueue: length=%u\n", mInboundQueue.count()); + dump += StringPrintf(INDENT "InboundQueue: length=%u\n", mInboundQueue.count()); for (EventEntry* entry = mInboundQueue.head; entry; entry = entry->next) { - dump.append(INDENT2); + dump += INDENT2; entry->appendDescription(dump); - dump.appendFormat(", age=%0.1fms\n", + dump += StringPrintf(", age=%0.1fms\n", (currentTime - entry->eventTime) * 0.000001f); } } else { - dump.append(INDENT "InboundQueue: \n"); + dump += INDENT "InboundQueue: \n"; } if (!mReplacedKeys.isEmpty()) { - dump.append(INDENT "ReplacedKeys:\n"); + dump += INDENT "ReplacedKeys:\n"; for (size_t i = 0; i < mReplacedKeys.size(); i++) { const KeyReplacement& replacement = mReplacedKeys.keyAt(i); int32_t newKeyCode = mReplacedKeys.valueAt(i); - dump.appendFormat(INDENT2 "%zu: originalKeyCode=%d, deviceId=%d, newKeyCode=%d\n", + dump += StringPrintf(INDENT2 "%zu: originalKeyCode=%d, deviceId=%d, newKeyCode=%d\n", i, replacement.keyCode, replacement.deviceId, newKeyCode); } } else { - dump.append(INDENT "ReplacedKeys: \n"); + dump += INDENT "ReplacedKeys: \n"; } if (!mConnectionsByFd.isEmpty()) { - dump.append(INDENT "Connections:\n"); + dump += INDENT "Connections:\n"; for (size_t i = 0; i < mConnectionsByFd.size(); i++) { const sp& connection = mConnectionsByFd.valueAt(i); - dump.appendFormat(INDENT2 "%zu: channelName='%s', windowName='%s', " + dump += StringPrintf(INDENT2 "%zu: channelName='%s', windowName='%s', " "status=%s, monitor=%s, inputPublisherBlocked=%s\n", i, connection->getInputChannelName(), connection->getWindowName(), connection->getStatusLabel(), toString(connection->monitor), toString(connection->inputPublisherBlocked)); if (!connection->outboundQueue.isEmpty()) { - dump.appendFormat(INDENT3 "OutboundQueue: length=%u\n", + dump += StringPrintf(INDENT3 "OutboundQueue: length=%u\n", connection->outboundQueue.count()); for (DispatchEntry* entry = connection->outboundQueue.head; entry; entry = entry->next) { dump.append(INDENT4); entry->eventEntry->appendDescription(dump); - dump.appendFormat(", targetFlags=0x%08x, resolvedAction=%d, age=%0.1fms\n", + dump += StringPrintf(", targetFlags=0x%08x, resolvedAction=%d, age=%0.1fms\n", entry->targetFlags, entry->resolvedAction, (currentTime - entry->eventEntry->eventTime) * 0.000001f); } } else { - dump.append(INDENT3 "OutboundQueue: \n"); + dump += INDENT3 "OutboundQueue: \n"; } if (!connection->waitQueue.isEmpty()) { - dump.appendFormat(INDENT3 "WaitQueue: length=%u\n", + dump += StringPrintf(INDENT3 "WaitQueue: length=%u\n", connection->waitQueue.count()); for (DispatchEntry* entry = connection->waitQueue.head; entry; entry = entry->next) { - dump.append(INDENT4); + dump += INDENT4; entry->eventEntry->appendDescription(dump); - dump.appendFormat(", targetFlags=0x%08x, resolvedAction=%d, " + dump += StringPrintf(", targetFlags=0x%08x, resolvedAction=%d, " "age=%0.1fms, wait=%0.1fms\n", entry->targetFlags, entry->resolvedAction, (currentTime - entry->eventEntry->eventTime) * 0.000001f, (currentTime - entry->deliveryTime) * 0.000001f); } } else { - dump.append(INDENT3 "WaitQueue: \n"); + dump += INDENT3 "WaitQueue: \n"; } } } else { - dump.append(INDENT "Connections: \n"); + dump += INDENT "Connections: \n"; } if (isAppSwitchPendingLocked()) { - dump.appendFormat(INDENT "AppSwitch: pending, due in %0.1fms\n", + dump += StringPrintf(INDENT "AppSwitch: pending, due in %0.1fms\n", (mAppSwitchDueTime - now()) / 1000000.0); } else { - dump.append(INDENT "AppSwitch: not pending\n"); + dump += INDENT "AppSwitch: not pending\n"; } - dump.append(INDENT "Configuration:\n"); - dump.appendFormat(INDENT2 "KeyRepeatDelay: %0.1fms\n", + dump += INDENT "Configuration:\n"; + dump += StringPrintf(INDENT2 "KeyRepeatDelay: %0.1fms\n", mConfig.keyRepeatDelay * 0.000001f); - dump.appendFormat(INDENT2 "KeyRepeatTimeout: %0.1fms\n", + dump += StringPrintf(INDENT2 "KeyRepeatTimeout: %0.1fms\n", mConfig.keyRepeatTimeout * 0.000001f); } status_t InputDispatcher::registerInputChannel(const sp& inputChannel, const sp& inputWindowHandle, bool monitor) { #if DEBUG_REGISTRATION - ALOGD("channel '%s' ~ registerInputChannel - monitor=%s", inputChannel->getName().string(), + ALOGD("channel '%s' ~ registerInputChannel - monitor=%s", inputChannel->getName().c_str(), toString(monitor)); #endif @@ -3351,7 +3351,7 @@ status_t InputDispatcher::registerInputChannel(const sp& inputChan if (getConnectionIndexLocked(inputChannel) >= 0) { ALOGW("Attempted to register already registered input channel '%s'", - inputChannel->getName().string()); + inputChannel->getName().c_str()); return BAD_VALUE; } @@ -3374,7 +3374,7 @@ status_t InputDispatcher::registerInputChannel(const sp& inputChan status_t InputDispatcher::unregisterInputChannel(const sp& inputChannel) { #if DEBUG_REGISTRATION - ALOGD("channel '%s' ~ unregisterInputChannel", inputChannel->getName().string()); + ALOGD("channel '%s' ~ unregisterInputChannel", inputChannel->getName().c_str()); #endif { // acquire lock @@ -3397,7 +3397,7 @@ status_t InputDispatcher::unregisterInputChannelLocked(const sp& i ssize_t connectionIndex = getConnectionIndexLocked(inputChannel); if (connectionIndex < 0) { ALOGW("Attempted to unregister already unregistered input channel '%s'", - inputChannel->getName().string()); + inputChannel->getName().c_str()); return BAD_VALUE; } @@ -3466,7 +3466,7 @@ void InputDispatcher::onANRLocked( float waitDuration = (currentTime - waitStartTime) * 0.000001f; ALOGI("Application is not responding: %s. " "It has been %0.1fms since event, %0.1fms since wait started. Reason: %s", - getApplicationWindowLabelLocked(applicationHandle, windowHandle).string(), + getApplicationWindowLabelLocked(applicationHandle, windowHandle).c_str(), dispatchLatency, waitDuration, reason); // Capture a record of the InputDispatcher state at the time of the ANR. @@ -3476,13 +3476,13 @@ void InputDispatcher::onANRLocked( char timestr[64]; strftime(timestr, sizeof(timestr), "%F %T", &tm); mLastANRState.clear(); - mLastANRState.append(INDENT "ANR:\n"); - mLastANRState.appendFormat(INDENT2 "Time: %s\n", timestr); - mLastANRState.appendFormat(INDENT2 "Window: %s\n", - getApplicationWindowLabelLocked(applicationHandle, windowHandle).string()); - mLastANRState.appendFormat(INDENT2 "DispatchLatency: %0.1fms\n", dispatchLatency); - mLastANRState.appendFormat(INDENT2 "WaitDuration: %0.1fms\n", waitDuration); - mLastANRState.appendFormat(INDENT2 "Reason: %s\n", reason); + mLastANRState += INDENT "ANR:\n"; + mLastANRState += StringPrintf(INDENT2 "Time: %s\n", timestr); + mLastANRState += StringPrintf(INDENT2 "Window: %s\n", + getApplicationWindowLabelLocked(applicationHandle, windowHandle).c_str()); + mLastANRState += StringPrintf(INDENT2 "DispatchLatency: %0.1fms\n", dispatchLatency); + mLastANRState += StringPrintf(INDENT2 "WaitDuration: %0.1fms\n", waitDuration); + mLastANRState += StringPrintf(INDENT2 "Reason: %s\n", reason); dumpDispatchStateLocked(mLastANRState); CommandEntry* commandEntry = postCommandLocked( @@ -3566,11 +3566,11 @@ void InputDispatcher::doDispatchCycleFinishedLockedInterruptible( if (dispatchEntry) { nsecs_t eventDuration = finishTime - dispatchEntry->deliveryTime; if (eventDuration > SLOW_EVENT_PROCESSING_WARNING_TIMEOUT) { - String8 msg; - msg.appendFormat("Window '%s' spent %0.1fms processing the last input event: ", + std::string msg = + StringPrintf("Window '%s' spent %0.1fms processing the last input event: ", connection->getWindowName(), eventDuration * 0.000001f); dispatchEntry->eventEntry->appendDescription(msg); - ALOGI("%s", msg.string()); + ALOGI("%s", msg.c_str()); } bool restartEvent; @@ -3737,15 +3737,15 @@ bool InputDispatcher::afterKeyEventLockedInterruptible(const sp& con #if DEBUG_OUTBOUND_EVENT_DETAILS { - String8 msg; + std::string msg; const KeyedVector& fallbackKeys = connection->inputState.getFallbackKeys(); for (size_t i = 0; i < fallbackKeys.size(); i++) { - msg.appendFormat(", %d->%d", fallbackKeys.keyAt(i), + msg += StringPrintf(", %d->%d", fallbackKeys.keyAt(i), fallbackKeys.valueAt(i)); } ALOGD("Unhandled key event: %zu currently tracked fallback keys%s.", - fallbackKeys.size(), msg.string()); + fallbackKeys.size(), msg.c_str()); } #endif @@ -3824,15 +3824,15 @@ void InputDispatcher::traceWaitQueueLengthLocked(const sp& connectio } } -void InputDispatcher::dump(String8& dump) { +void InputDispatcher::dump(std::string& dump) { AutoMutex _l(mLock); - dump.append("Input Dispatcher State:\n"); + dump += "Input Dispatcher State:\n"; dumpDispatchStateLocked(dump); - if (!mLastANRState.isEmpty()) { - dump.append("\nInput Dispatcher State at time of last ANR:\n"); - dump.append(mLastANRState); + if (!mLastANRState.empty()) { + dump += "\nInput Dispatcher State at time of last ANR:\n"; + dump += mLastANRState; } } @@ -3904,9 +3904,8 @@ InputDispatcher::ConfigurationChangedEntry::ConfigurationChangedEntry(nsecs_t ev InputDispatcher::ConfigurationChangedEntry::~ConfigurationChangedEntry() { } -void InputDispatcher::ConfigurationChangedEntry::appendDescription(String8& msg) const { - msg.append("ConfigurationChangedEvent(), policyFlags=0x%08x", - policyFlags); +void InputDispatcher::ConfigurationChangedEntry::appendDescription(std::string& msg) const { + msg += StringPrintf("ConfigurationChangedEvent(), policyFlags=0x%08x", policyFlags); } @@ -3920,8 +3919,8 @@ InputDispatcher::DeviceResetEntry::DeviceResetEntry(nsecs_t eventTime, int32_t d InputDispatcher::DeviceResetEntry::~DeviceResetEntry() { } -void InputDispatcher::DeviceResetEntry::appendDescription(String8& msg) const { - msg.appendFormat("DeviceResetEvent(deviceId=%d), policyFlags=0x%08x", +void InputDispatcher::DeviceResetEntry::appendDescription(std::string& msg) const { + msg += StringPrintf("DeviceResetEvent(deviceId=%d), policyFlags=0x%08x", deviceId, policyFlags); } @@ -3943,8 +3942,8 @@ InputDispatcher::KeyEntry::KeyEntry(nsecs_t eventTime, InputDispatcher::KeyEntry::~KeyEntry() { } -void InputDispatcher::KeyEntry::appendDescription(String8& msg) const { - msg.appendFormat("KeyEvent(deviceId=%d, source=0x%08x, action=%d, " +void InputDispatcher::KeyEntry::appendDescription(std::string& msg) const { + msg += StringPrintf("KeyEvent(deviceId=%d, source=0x%08x, action=%d, " "flags=0x%08x, keyCode=%d, scanCode=%d, metaState=0x%08x, " "repeatCount=%d), policyFlags=0x%08x", deviceId, source, action, flags, keyCode, scanCode, metaState, @@ -3988,20 +3987,20 @@ InputDispatcher::MotionEntry::MotionEntry(nsecs_t eventTime, int32_t deviceId, InputDispatcher::MotionEntry::~MotionEntry() { } -void InputDispatcher::MotionEntry::appendDescription(String8& msg) const { - msg.appendFormat("MotionEvent(deviceId=%d, source=0x%08x, action=%d, actionButton=0x%08x, " +void InputDispatcher::MotionEntry::appendDescription(std::string& msg) const { + msg += StringPrintf("MotionEvent(deviceId=%d, source=0x%08x, action=%d, actionButton=0x%08x, " "flags=0x%08x, metaState=0x%08x, buttonState=0x%08x, " "edgeFlags=0x%08x, xPrecision=%.1f, yPrecision=%.1f, displayId=%d, pointers=[", deviceId, source, action, actionButton, flags, metaState, buttonState, edgeFlags, xPrecision, yPrecision, displayId); for (uint32_t i = 0; i < pointerCount; i++) { if (i) { - msg.append(", "); + msg += ", "; } - msg.appendFormat("%d: (%.1f, %.1f)", pointerProperties[i].id, + msg += StringPrintf("%d: (%.1f, %.1f)", pointerProperties[i].id, pointerCoords[i].getX(), pointerCoords[i].getY()); } - msg.appendFormat("]), policyFlags=0x%08x", policyFlags); + msg += StringPrintf("]), policyFlags=0x%08x", policyFlags); } @@ -4400,7 +4399,7 @@ InputDispatcher::Connection::~Connection() { const char* InputDispatcher::Connection::getWindowName() const { if (inputWindowHandle != NULL) { - return inputWindowHandle->getName().string(); + return inputWindowHandle->getName().c_str(); } if (monitor) { return "monitor"; diff --git a/services/inputflinger/InputDispatcher.h b/services/inputflinger/InputDispatcher.h index 90c69ce581..92b3a9cfeb 100644 --- a/services/inputflinger/InputDispatcher.h +++ b/services/inputflinger/InputDispatcher.h @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -209,7 +208,7 @@ public: * Returns a new timeout to continue waiting, or 0 to abort dispatch. */ virtual nsecs_t notifyANR(const sp& inputApplicationHandle, const sp& inputWindowHandle, - const String8& reason) = 0; + const std::string& reason) = 0; /* Notifies the system that an input channel is unrecoverably broken. */ virtual void notifyInputChannelBroken(const sp& inputWindowHandle) = 0; @@ -281,7 +280,7 @@ public: /* Dumps the state of the input dispatcher. * * This method may be called on any thread (usually by the input manager). */ - virtual void dump(String8& dump) = 0; + virtual void dump(std::string& dump) = 0; /* Called by the heatbeat to ensures that the dispatcher has not deadlocked. */ virtual void monitor() = 0; @@ -373,7 +372,7 @@ protected: public: explicit InputDispatcher(const sp& policy); - virtual void dump(String8& dump); + virtual void dump(std::string& dump); virtual void monitor(); virtual void dispatchOnce(); @@ -446,7 +445,7 @@ private: void release(); - virtual void appendDescription(String8& msg) const = 0; + virtual void appendDescription(std::string& msg) const = 0; protected: EventEntry(int32_t type, nsecs_t eventTime, uint32_t policyFlags); @@ -456,7 +455,7 @@ private: struct ConfigurationChangedEntry : EventEntry { explicit ConfigurationChangedEntry(nsecs_t eventTime); - virtual void appendDescription(String8& msg) const; + virtual void appendDescription(std::string& msg) const; protected: virtual ~ConfigurationChangedEntry(); @@ -466,7 +465,7 @@ private: int32_t deviceId; DeviceResetEntry(nsecs_t eventTime, int32_t deviceId); - virtual void appendDescription(String8& msg) const; + virtual void appendDescription(std::string& msg) const; protected: virtual ~DeviceResetEntry(); @@ -498,7 +497,7 @@ private: int32_t deviceId, uint32_t source, uint32_t policyFlags, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime); - virtual void appendDescription(String8& msg) const; + virtual void appendDescription(std::string& msg) const; void recycle(); protected: @@ -531,7 +530,7 @@ private: int32_t displayId, uint32_t pointerCount, const PointerProperties* pointerProperties, const PointerCoords* pointerCoords, float xOffset, float yOffset); - virtual void appendDescription(String8& msg) const; + virtual void appendDescription(std::string& msg) const; protected: virtual ~MotionEntry(); @@ -602,7 +601,7 @@ private: KeyEntry* keyEntry; sp inputApplicationHandle; sp inputWindowHandle; - String8 reason; + std::string reason; int32_t userActivityEventType; uint32_t seq; bool handled; @@ -832,7 +831,7 @@ private: explicit Connection(const sp& inputChannel, const sp& inputWindowHandle, bool monitor); - inline const char* getInputChannelName() const { return inputChannel->getName().string(); } + inline const char* getInputChannelName() const { return inputChannel->getName().c_str(); } const char* getWindowName() const; const char* getStatusLabel() const; @@ -994,7 +993,7 @@ private: sp mFocusedApplicationHandle; // Dispatcher state at time of last ANR. - String8 mLastANRState; + std::string mLastANRState; // Dispatch inbound events. bool dispatchConfigurationChangedLocked( @@ -1055,10 +1054,10 @@ private: bool isWindowObscuredAtPointLocked(const sp& windowHandle, int32_t x, int32_t y) const; bool isWindowObscuredLocked(const sp& windowHandle) const; - String8 getApplicationWindowLabelLocked(const sp& applicationHandle, + std::string getApplicationWindowLabelLocked(const sp& applicationHandle, const sp& windowHandle); - String8 checkWindowReadyForMoreInputLocked(nsecs_t currentTime, + std::string checkWindowReadyForMoreInputLocked(nsecs_t currentTime, const sp& windowHandle, const EventEntry* eventEntry, const char* targetType); @@ -1096,7 +1095,7 @@ private: void resetAndDropEverythingLocked(const char* reason); // Dump state. - void dumpDispatchStateLocked(String8& dump); + void dumpDispatchStateLocked(std::string& dump); void logDispatchStateLocked(); // Registration. diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index 591f8d7e61..e398a84391 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -54,6 +54,7 @@ #include +#include #include #include @@ -63,6 +64,8 @@ #define INDENT4 " " #define INDENT5 " " +using android::base::StringPrintf; + namespace android { // --- Constants --- @@ -290,19 +293,19 @@ void InputReaderConfiguration::setVirtualDisplayViewports( mVirtualDisplays = viewports; } -void InputReaderConfiguration::dump(String8& dump) const { - dump.append(INDENT4 "ViewportInternal:\n"); +void InputReaderConfiguration::dump(std::string& dump) const { + dump += INDENT4 "ViewportInternal:\n"; dumpViewport(dump, mInternalDisplay); - dump.append(INDENT4 "ViewportExternal:\n"); + dump += INDENT4 "ViewportExternal:\n"; dumpViewport(dump, mExternalDisplay); - dump.append(INDENT4 "ViewportVirtual:\n"); + dump += INDENT4 "ViewportVirtual:\n"; for (const DisplayViewport& viewport : mVirtualDisplays) { dumpViewport(dump, viewport); } } -void InputReaderConfiguration::dumpViewport(String8& dump, const DisplayViewport& viewport) const { - dump.appendFormat(INDENT5 "Viewport: displayId=%d, orientation=%d, uniqueId='%s', " +void InputReaderConfiguration::dumpViewport(std::string& dump, const DisplayViewport& viewport) const { + dump += StringPrintf(INDENT5 "Viewport: displayId=%d, orientation=%d, uniqueId='%s', " "logicalFrame=[%d, %d, %d, %d], " "physicalFrame=[%d, %d, %d, %d], " "deviceSize=[%d, %d]\n", @@ -873,71 +876,71 @@ bool InputReader::isInputDeviceEnabled(int32_t deviceId) { return false; } -void InputReader::dump(String8& dump) { +void InputReader::dump(std::string& dump) { AutoMutex _l(mLock); mEventHub->dump(dump); - dump.append("\n"); + dump += "\n"; - dump.append("Input Reader State:\n"); + dump += "Input Reader State:\n"; for (size_t i = 0; i < mDevices.size(); i++) { mDevices.valueAt(i)->dump(dump); } - dump.append(INDENT "Configuration:\n"); - dump.append(INDENT2 "ExcludedDeviceNames: ["); + dump += INDENT "Configuration:\n"; + dump += INDENT2 "ExcludedDeviceNames: ["; for (size_t i = 0; i < mConfig.excludedDeviceNames.size(); i++) { if (i != 0) { - dump.append(", "); + dump += ", "; } - dump.append(mConfig.excludedDeviceNames.itemAt(i).string()); + dump += mConfig.excludedDeviceNames.itemAt(i).string(); } - dump.append("]\n"); - dump.appendFormat(INDENT2 "VirtualKeyQuietTime: %0.1fms\n", + dump += "]\n"; + dump += StringPrintf(INDENT2 "VirtualKeyQuietTime: %0.1fms\n", mConfig.virtualKeyQuietTime * 0.000001f); - dump.appendFormat(INDENT2 "PointerVelocityControlParameters: " + 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); - dump.appendFormat(INDENT2 "WheelVelocityControlParameters: " + 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); - dump.appendFormat(INDENT2 "PointerGesture:\n"); - dump.appendFormat(INDENT3 "Enabled: %s\n", + dump += StringPrintf(INDENT2 "PointerGesture:\n"); + dump += StringPrintf(INDENT3 "Enabled: %s\n", toString(mConfig.pointerGesturesEnabled)); - dump.appendFormat(INDENT3 "QuietInterval: %0.1fms\n", + dump += StringPrintf(INDENT3 "QuietInterval: %0.1fms\n", mConfig.pointerGestureQuietInterval * 0.000001f); - dump.appendFormat(INDENT3 "DragMinSwitchSpeed: %0.1fpx/s\n", + dump += StringPrintf(INDENT3 "DragMinSwitchSpeed: %0.1fpx/s\n", mConfig.pointerGestureDragMinSwitchSpeed); - dump.appendFormat(INDENT3 "TapInterval: %0.1fms\n", + dump += StringPrintf(INDENT3 "TapInterval: %0.1fms\n", mConfig.pointerGestureTapInterval * 0.000001f); - dump.appendFormat(INDENT3 "TapDragInterval: %0.1fms\n", + dump += StringPrintf(INDENT3 "TapDragInterval: %0.1fms\n", mConfig.pointerGestureTapDragInterval * 0.000001f); - dump.appendFormat(INDENT3 "TapSlop: %0.1fpx\n", + dump += StringPrintf(INDENT3 "TapSlop: %0.1fpx\n", mConfig.pointerGestureTapSlop); - dump.appendFormat(INDENT3 "MultitouchSettleInterval: %0.1fms\n", + dump += StringPrintf(INDENT3 "MultitouchSettleInterval: %0.1fms\n", mConfig.pointerGestureMultitouchSettleInterval * 0.000001f); - dump.appendFormat(INDENT3 "MultitouchMinDistance: %0.1fpx\n", + dump += StringPrintf(INDENT3 "MultitouchMinDistance: %0.1fpx\n", mConfig.pointerGestureMultitouchMinDistance); - dump.appendFormat(INDENT3 "SwipeTransitionAngleCosine: %0.1f\n", + dump += StringPrintf(INDENT3 "SwipeTransitionAngleCosine: %0.1f\n", mConfig.pointerGestureSwipeTransitionAngleCosine); - dump.appendFormat(INDENT3 "SwipeMaxWidthRatio: %0.1f\n", + dump += StringPrintf(INDENT3 "SwipeMaxWidthRatio: %0.1f\n", mConfig.pointerGestureSwipeMaxWidthRatio); - dump.appendFormat(INDENT3 "MovementSpeedRatio: %0.1f\n", + dump += StringPrintf(INDENT3 "MovementSpeedRatio: %0.1f\n", mConfig.pointerGestureMovementSpeedRatio); - dump.appendFormat(INDENT3 "ZoomSpeedRatio: %0.1f\n", + dump += StringPrintf(INDENT3 "ZoomSpeedRatio: %0.1f\n", mConfig.pointerGestureZoomSpeedRatio); - dump.append(INDENT3 "Viewports:\n"); + dump += INDENT3 "Viewports:\n"; mConfig.dump(dump); } @@ -1069,21 +1072,21 @@ void InputDevice::setEnabled(bool enabled, nsecs_t when) { bumpGeneration(); } -void InputDevice::dump(String8& dump) { +void InputDevice::dump(std::string& dump) { InputDeviceInfo deviceInfo; getDeviceInfo(& deviceInfo); - dump.appendFormat(INDENT "Device %d: %s\n", deviceInfo.getId(), + dump += StringPrintf(INDENT "Device %d: %s\n", deviceInfo.getId(), deviceInfo.getDisplayName().string()); - dump.appendFormat(INDENT2 "Generation: %d\n", mGeneration); - dump.appendFormat(INDENT2 "IsExternal: %s\n", toString(mIsExternal)); - dump.appendFormat(INDENT2 "HasMic: %s\n", toString(mHasMic)); - dump.appendFormat(INDENT2 "Sources: 0x%08x\n", deviceInfo.getSources()); - dump.appendFormat(INDENT2 "KeyboardType: %d\n", deviceInfo.getKeyboardType()); + dump += StringPrintf(INDENT2 "Generation: %d\n", mGeneration); + dump += StringPrintf(INDENT2 "IsExternal: %s\n", toString(mIsExternal)); + dump += StringPrintf(INDENT2 "HasMic: %s\n", toString(mHasMic)); + dump += StringPrintf(INDENT2 "Sources: 0x%08x\n", deviceInfo.getSources()); + dump += StringPrintf(INDENT2 "KeyboardType: %d\n", deviceInfo.getKeyboardType()); const Vector& ranges = deviceInfo.getMotionRanges(); if (!ranges.isEmpty()) { - dump.append(INDENT2 "Motion Ranges:\n"); + dump += INDENT2 "Motion Ranges:\n"; for (size_t i = 0; i < ranges.size(); i++) { const InputDeviceInfo::MotionRange& range = ranges.itemAt(i); const char* label = getAxisLabel(range.axis); @@ -1094,7 +1097,7 @@ void InputDevice::dump(String8& dump) { } else { snprintf(name, sizeof(name), "%d", range.axis); } - dump.appendFormat(INDENT3 "%s: source=0x%08x, " + 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); @@ -1982,7 +1985,7 @@ void InputMapper::populateDeviceInfo(InputDeviceInfo* info) { info->addSource(getSources()); } -void InputMapper::dump(String8& dump) { +void InputMapper::dump(std::string& dump) { } void InputMapper::configure(nsecs_t when, @@ -2044,21 +2047,21 @@ void InputMapper::bumpGeneration() { mDevice->bumpGeneration(); } -void InputMapper::dumpRawAbsoluteAxisInfo(String8& dump, +void InputMapper::dumpRawAbsoluteAxisInfo(std::string& dump, const RawAbsoluteAxisInfo& axis, const char* name) { if (axis.valid) { - dump.appendFormat(INDENT4 "%s: min=%d, max=%d, flat=%d, fuzz=%d, resolution=%d\n", + 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.appendFormat(INDENT4 "%s: unknown range\n", name); + dump += StringPrintf(INDENT4 "%s: unknown range\n", name); } } -void InputMapper::dumpStylusState(String8& dump, const StylusState& state) { - dump.appendFormat(INDENT4 "When: %" PRId64 "\n", state.when); - dump.appendFormat(INDENT4 "Pressure: %f\n", state.pressure); - dump.appendFormat(INDENT4 "Button State: 0x%08x\n", state.buttons); - dump.appendFormat(INDENT4 "Tool Type: %" PRId32 "\n", state.toolType); +void InputMapper::dumpStylusState(std::string& dump, const StylusState& state) { + dump += StringPrintf(INDENT4 "When: %" PRId64 "\n", state.when); + dump += StringPrintf(INDENT4 "Pressure: %f\n", state.pressure); + dump += StringPrintf(INDENT4 "Button State: 0x%08x\n", state.buttons); + dump += StringPrintf(INDENT4 "Tool Type: %" PRId32 "\n", state.toolType); } // --- SwitchInputMapper --- @@ -2112,9 +2115,9 @@ int32_t SwitchInputMapper::getSwitchState(uint32_t sourceMask, int32_t switchCod return getEventHub()->getSwitchState(getDeviceId(), switchCode); } -void SwitchInputMapper::dump(String8& dump) { - dump.append(INDENT2 "Switch Input Mapper:\n"); - dump.appendFormat(INDENT3 "SwitchValues: %x\n", mSwitchValues); +void SwitchInputMapper::dump(std::string& dump) { + dump += INDENT2 "Switch Input Mapper:\n"; + dump += StringPrintf(INDENT3 "SwitchValues: %x\n", mSwitchValues); } // --- VibratorInputMapper --- @@ -2143,15 +2146,15 @@ void VibratorInputMapper::process(const RawEvent* rawEvent) { void VibratorInputMapper::vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, int32_t token) { #if DEBUG_VIBRATOR - String8 patternStr; + std::string patternStr; for (size_t i = 0; i < patternSize; i++) { if (i != 0) { - patternStr.append(", "); + patternStr += ", "; } - patternStr.appendFormat("%" PRId64, pattern[i]); + patternStr += StringPrintf("%" PRId64, pattern[i]); } ALOGD("vibrate: deviceId=%d, pattern=[%s], repeat=%zd, token=%d", - getDeviceId(), patternStr.string(), repeat, token); + getDeviceId(), patternStr.c_str(), repeat, token); #endif mVibrating = true; @@ -2224,9 +2227,9 @@ void VibratorInputMapper::stopVibrating() { getEventHub()->cancelVibrate(getDeviceId()); } -void VibratorInputMapper::dump(String8& dump) { - dump.append(INDENT2 "Vibrator Input Mapper:\n"); - dump.appendFormat(INDENT3 "Vibrating: %s\n", toString(mVibrating)); +void VibratorInputMapper::dump(std::string& dump) { + dump += INDENT2 "Vibrator Input Mapper:\n"; + dump += StringPrintf(INDENT3 "Vibrating: %s\n", toString(mVibrating)); } @@ -2252,14 +2255,14 @@ void KeyboardInputMapper::populateDeviceInfo(InputDeviceInfo* info) { info->setKeyCharacterMap(getEventHub()->getKeyCharacterMap(getDeviceId())); } -void KeyboardInputMapper::dump(String8& dump) { - dump.append(INDENT2 "Keyboard Input Mapper:\n"); +void KeyboardInputMapper::dump(std::string& dump) { + dump += INDENT2 "Keyboard Input Mapper:\n"; dumpParameters(dump); - dump.appendFormat(INDENT3 "KeyboardType: %d\n", mKeyboardType); - dump.appendFormat(INDENT3 "Orientation: %d\n", mOrientation); - dump.appendFormat(INDENT3 "KeyDowns: %zu keys currently down\n", mKeyDowns.size()); - dump.appendFormat(INDENT3 "MetaState: 0x%0x\n", mMetaState); - dump.appendFormat(INDENT3 "DownTime: %" PRId64 "\n", mDownTime); + dump += StringPrintf(INDENT3 "KeyboardType: %d\n", mKeyboardType); + dump += StringPrintf(INDENT3 "Orientation: %d\n", mOrientation); + dump += StringPrintf(INDENT3 "KeyDowns: %zu keys currently down\n", mKeyDowns.size()); + dump += StringPrintf(INDENT3 "MetaState: 0x%0x\n", mMetaState); + dump += StringPrintf(INDENT3 "DownTime: %" PRId64 "\n", mDownTime); } @@ -2319,13 +2322,13 @@ void KeyboardInputMapper::configureParameters() { mParameters.handlesKeyRepeat); } -void KeyboardInputMapper::dumpParameters(String8& dump) { - dump.append(INDENT3 "Parameters:\n"); - dump.appendFormat(INDENT4 "HasAssociatedDisplay: %s\n", +void KeyboardInputMapper::dumpParameters(std::string& dump) { + dump += INDENT3 "Parameters:\n"; + dump += StringPrintf(INDENT4 "HasAssociatedDisplay: %s\n", toString(mParameters.hasAssociatedDisplay)); - dump.appendFormat(INDENT4 "OrientationAware: %s\n", + dump += StringPrintf(INDENT4 "OrientationAware: %s\n", toString(mParameters.orientationAware)); - dump.appendFormat(INDENT4 "HandlesKeyRepeat: %s\n", + dump += StringPrintf(INDENT4 "HandlesKeyRepeat: %s\n", toString(mParameters.handlesKeyRepeat)); } @@ -2604,23 +2607,23 @@ void CursorInputMapper::populateDeviceInfo(InputDeviceInfo* info) { } } -void CursorInputMapper::dump(String8& dump) { - dump.append(INDENT2 "Cursor Input Mapper:\n"); +void CursorInputMapper::dump(std::string& dump) { + dump += INDENT2 "Cursor Input Mapper:\n"; dumpParameters(dump); - dump.appendFormat(INDENT3 "XScale: %0.3f\n", mXScale); - dump.appendFormat(INDENT3 "YScale: %0.3f\n", mYScale); - dump.appendFormat(INDENT3 "XPrecision: %0.3f\n", mXPrecision); - dump.appendFormat(INDENT3 "YPrecision: %0.3f\n", mYPrecision); - dump.appendFormat(INDENT3 "HaveVWheel: %s\n", + dump += StringPrintf(INDENT3 "XScale: %0.3f\n", mXScale); + dump += StringPrintf(INDENT3 "YScale: %0.3f\n", mYScale); + 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())); - dump.appendFormat(INDENT3 "HaveHWheel: %s\n", + dump += StringPrintf(INDENT3 "HaveHWheel: %s\n", toString(mCursorScrollAccumulator.haveRelativeHWheel())); - dump.appendFormat(INDENT3 "VWheelScale: %0.3f\n", mVWheelScale); - dump.appendFormat(INDENT3 "HWheelScale: %0.3f\n", mHWheelScale); - dump.appendFormat(INDENT3 "Orientation: %d\n", mOrientation); - dump.appendFormat(INDENT3 "ButtonState: 0x%08x\n", mButtonState); - dump.appendFormat(INDENT3 "Down: %s\n", toString(isPointerDown(mButtonState))); - dump.appendFormat(INDENT3 "DownTime: %" PRId64 "\n", mDownTime); + dump += StringPrintf(INDENT3 "VWheelScale: %0.3f\n", mVWheelScale); + dump += StringPrintf(INDENT3 "HWheelScale: %0.3f\n", mHWheelScale); + dump += StringPrintf(INDENT3 "Orientation: %d\n", mOrientation); + dump += StringPrintf(INDENT3 "ButtonState: 0x%08x\n", mButtonState); + dump += StringPrintf(INDENT3 "Down: %s\n", toString(isPointerDown(mButtonState))); + dump += StringPrintf(INDENT3 "DownTime: %" PRId64 "\n", mDownTime); } void CursorInputMapper::configure(nsecs_t when, @@ -2728,26 +2731,26 @@ void CursorInputMapper::configureParameters() { } } -void CursorInputMapper::dumpParameters(String8& dump) { - dump.append(INDENT3 "Parameters:\n"); - dump.appendFormat(INDENT4 "HasAssociatedDisplay: %s\n", +void CursorInputMapper::dumpParameters(std::string& dump) { + dump += INDENT3 "Parameters:\n"; + dump += StringPrintf(INDENT4 "HasAssociatedDisplay: %s\n", toString(mParameters.hasAssociatedDisplay)); switch (mParameters.mode) { case Parameters::MODE_POINTER: - dump.append(INDENT4 "Mode: pointer\n"); + dump += INDENT4 "Mode: pointer\n"; break; case Parameters::MODE_POINTER_RELATIVE: - dump.append(INDENT4 "Mode: relative pointer\n"); + dump += INDENT4 "Mode: relative pointer\n"; break; case Parameters::MODE_NAVIGATION: - dump.append(INDENT4 "Mode: navigation\n"); + dump += INDENT4 "Mode: navigation\n"; break; default: ALOG_ASSERT(false); } - dump.appendFormat(INDENT4 "OrientationAware: %s\n", + dump += StringPrintf(INDENT4 "OrientationAware: %s\n", toString(mParameters.orientationAware)); } @@ -3000,9 +3003,9 @@ void RotaryEncoderInputMapper::populateDeviceInfo(InputDeviceInfo* info) { } } -void RotaryEncoderInputMapper::dump(String8& dump) { - dump.append(INDENT2 "Rotary Encoder Input Mapper:\n"); - dump.appendFormat(INDENT3 "HaveWheel: %s\n", +void RotaryEncoderInputMapper::dump(std::string& dump) { + dump += INDENT2 "Rotary Encoder Input Mapper:\n"; + dump += StringPrintf(INDENT3 "HaveWheel: %s\n", toString(mRotaryEncoderScrollAccumulator.haveRelativeVWheel())); } @@ -3151,8 +3154,8 @@ void TouchInputMapper::populateDeviceInfo(InputDeviceInfo* info) { } } -void TouchInputMapper::dump(String8& dump) { - dump.appendFormat(INDENT2 "Touch Input Mapper (mode - %s):\n", modeToString(mDeviceMode)); +void TouchInputMapper::dump(std::string& dump) { + dump += StringPrintf(INDENT2 "Touch Input Mapper (mode - %s):\n", modeToString(mDeviceMode)); dumpParameters(dump); dumpVirtualKeys(dump); dumpRawPointerAxes(dump); @@ -3160,30 +3163,30 @@ void TouchInputMapper::dump(String8& dump) { dumpAffineTransformation(dump); dumpSurface(dump); - dump.appendFormat(INDENT3 "Translation and Scaling Factors:\n"); - dump.appendFormat(INDENT4 "XTranslate: %0.3f\n", mXTranslate); - dump.appendFormat(INDENT4 "YTranslate: %0.3f\n", mYTranslate); - dump.appendFormat(INDENT4 "XScale: %0.3f\n", mXScale); - dump.appendFormat(INDENT4 "YScale: %0.3f\n", mYScale); - dump.appendFormat(INDENT4 "XPrecision: %0.3f\n", mXPrecision); - dump.appendFormat(INDENT4 "YPrecision: %0.3f\n", mYPrecision); - dump.appendFormat(INDENT4 "GeometricScale: %0.3f\n", mGeometricScale); - dump.appendFormat(INDENT4 "PressureScale: %0.3f\n", mPressureScale); - dump.appendFormat(INDENT4 "SizeScale: %0.3f\n", mSizeScale); - dump.appendFormat(INDENT4 "OrientationScale: %0.3f\n", mOrientationScale); - dump.appendFormat(INDENT4 "DistanceScale: %0.3f\n", mDistanceScale); - dump.appendFormat(INDENT4 "HaveTilt: %s\n", toString(mHaveTilt)); - dump.appendFormat(INDENT4 "TiltXCenter: %0.3f\n", mTiltXCenter); - dump.appendFormat(INDENT4 "TiltXScale: %0.3f\n", mTiltXScale); - dump.appendFormat(INDENT4 "TiltYCenter: %0.3f\n", mTiltYCenter); - dump.appendFormat(INDENT4 "TiltYScale: %0.3f\n", mTiltYScale); - - dump.appendFormat(INDENT3 "Last Raw Button State: 0x%08x\n", mLastRawState.buttonState); - dump.appendFormat(INDENT3 "Last Raw Touch: pointerCount=%d\n", + dump += StringPrintf(INDENT3 "Translation and Scaling Factors:\n"); + dump += StringPrintf(INDENT4 "XTranslate: %0.3f\n", mXTranslate); + dump += StringPrintf(INDENT4 "YTranslate: %0.3f\n", mYTranslate); + dump += StringPrintf(INDENT4 "XScale: %0.3f\n", mXScale); + dump += StringPrintf(INDENT4 "YScale: %0.3f\n", mYScale); + dump += StringPrintf(INDENT4 "XPrecision: %0.3f\n", mXPrecision); + dump += StringPrintf(INDENT4 "YPrecision: %0.3f\n", mYPrecision); + dump += StringPrintf(INDENT4 "GeometricScale: %0.3f\n", mGeometricScale); + dump += StringPrintf(INDENT4 "PressureScale: %0.3f\n", mPressureScale); + dump += StringPrintf(INDENT4 "SizeScale: %0.3f\n", mSizeScale); + dump += StringPrintf(INDENT4 "OrientationScale: %0.3f\n", mOrientationScale); + dump += StringPrintf(INDENT4 "DistanceScale: %0.3f\n", mDistanceScale); + dump += StringPrintf(INDENT4 "HaveTilt: %s\n", toString(mHaveTilt)); + dump += StringPrintf(INDENT4 "TiltXCenter: %0.3f\n", mTiltXCenter); + dump += StringPrintf(INDENT4 "TiltXScale: %0.3f\n", mTiltXScale); + dump += StringPrintf(INDENT4 "TiltYCenter: %0.3f\n", mTiltYCenter); + dump += StringPrintf(INDENT4 "TiltYScale: %0.3f\n", mTiltYScale); + + dump += StringPrintf(INDENT3 "Last Raw Button State: 0x%08x\n", mLastRawState.buttonState); + dump += StringPrintf(INDENT3 "Last Raw Touch: pointerCount=%d\n", mLastRawState.rawPointerData.pointerCount); for (uint32_t i = 0; i < mLastRawState.rawPointerData.pointerCount; i++) { const RawPointerData::Pointer& pointer = mLastRawState.rawPointerData.pointers[i]; - dump.appendFormat(INDENT4 "[%d]: id=%d, x=%d, y=%d, pressure=%d, " + 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, @@ -3194,14 +3197,14 @@ void TouchInputMapper::dump(String8& dump) { pointer.toolType, toString(pointer.isHovering)); } - dump.appendFormat(INDENT3 "Last Cooked Button State: 0x%08x\n", mLastCookedState.buttonState); - dump.appendFormat(INDENT3 "Last Cooked Touch: pointerCount=%d\n", + dump += StringPrintf(INDENT3 "Last Cooked Button State: 0x%08x\n", mLastCookedState.buttonState); + dump += StringPrintf(INDENT3 "Last Cooked Touch: pointerCount=%d\n", 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.appendFormat(INDENT4 "[%d]: id=%d, x=%0.3f, y=%0.3f, pressure=%0.3f, " + 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, @@ -3220,26 +3223,26 @@ void TouchInputMapper::dump(String8& dump) { toString(mLastCookedState.cookedPointerData.isHovering(i))); } - dump.append(INDENT3 "Stylus Fusion:\n"); - dump.appendFormat(INDENT4 "ExternalStylusConnected: %s\n", + dump += INDENT3 "Stylus Fusion:\n"; + dump += StringPrintf(INDENT4 "ExternalStylusConnected: %s\n", toString(mExternalStylusConnected)); - dump.appendFormat(INDENT4 "External Stylus ID: %" PRId64 "\n", mExternalStylusId); - dump.appendFormat(INDENT4 "External Stylus Data Timeout: %" PRId64 "\n", + dump += StringPrintf(INDENT4 "External Stylus ID: %" PRId64 "\n", mExternalStylusId); + dump += StringPrintf(INDENT4 "External Stylus Data Timeout: %" PRId64 "\n", mExternalStylusFusionTimeout); - dump.append(INDENT3 "External Stylus State:\n"); + dump += INDENT3 "External Stylus State:\n"; dumpStylusState(dump, mExternalStylusState); if (mDeviceMode == DEVICE_MODE_POINTER) { - dump.appendFormat(INDENT3 "Pointer Gesture Detector:\n"); - dump.appendFormat(INDENT4 "XMovementScale: %0.3f\n", + dump += StringPrintf(INDENT3 "Pointer Gesture Detector:\n"); + dump += StringPrintf(INDENT4 "XMovementScale: %0.3f\n", mPointerXMovementScale); - dump.appendFormat(INDENT4 "YMovementScale: %0.3f\n", + dump += StringPrintf(INDENT4 "YMovementScale: %0.3f\n", mPointerYMovementScale); - dump.appendFormat(INDENT4 "XZoomScale: %0.3f\n", + dump += StringPrintf(INDENT4 "XZoomScale: %0.3f\n", mPointerXZoomScale); - dump.appendFormat(INDENT4 "YZoomScale: %0.3f\n", + dump += StringPrintf(INDENT4 "YZoomScale: %0.3f\n", mPointerYZoomScale); - dump.appendFormat(INDENT4 "MaxSwipeWidth: %f\n", + dump += StringPrintf(INDENT4 "MaxSwipeWidth: %f\n", mPointerGestureMaxSwipeWidth); } } @@ -3400,15 +3403,15 @@ void TouchInputMapper::configureParameters() { mParameters.wake); } -void TouchInputMapper::dumpParameters(String8& dump) { - dump.append(INDENT3 "Parameters:\n"); +void TouchInputMapper::dumpParameters(std::string& dump) { + dump += INDENT3 "Parameters:\n"; switch (mParameters.gestureMode) { case Parameters::GESTURE_MODE_SINGLE_TOUCH: - dump.append(INDENT4 "GestureMode: single-touch\n"); + dump += INDENT4 "GestureMode: single-touch\n"; break; case Parameters::GESTURE_MODE_MULTI_TOUCH: - dump.append(INDENT4 "GestureMode: multi-touch\n"); + dump += INDENT4 "GestureMode: multi-touch\n"; break; default: assert(false); @@ -3416,27 +3419,27 @@ void TouchInputMapper::dumpParameters(String8& dump) { switch (mParameters.deviceType) { case Parameters::DEVICE_TYPE_TOUCH_SCREEN: - dump.append(INDENT4 "DeviceType: touchScreen\n"); + dump += INDENT4 "DeviceType: touchScreen\n"; break; case Parameters::DEVICE_TYPE_TOUCH_PAD: - dump.append(INDENT4 "DeviceType: touchPad\n"); + dump += INDENT4 "DeviceType: touchPad\n"; break; case Parameters::DEVICE_TYPE_TOUCH_NAVIGATION: - dump.append(INDENT4 "DeviceType: touchNavigation\n"); + dump += INDENT4 "DeviceType: touchNavigation\n"; break; case Parameters::DEVICE_TYPE_POINTER: - dump.append(INDENT4 "DeviceType: pointer\n"); + dump += INDENT4 "DeviceType: pointer\n"; break; default: ALOG_ASSERT(false); } - dump.appendFormat( + dump += StringPrintf( INDENT4 "AssociatedDisplay: hasAssociatedDisplay=%s, isExternal=%s, displayId='%s'\n", toString(mParameters.hasAssociatedDisplay), toString(mParameters.associatedDisplayIsExternal), mParameters.uniqueDisplayId.c_str()); - dump.appendFormat(INDENT4 "OrientationAware: %s\n", + dump += StringPrintf(INDENT4 "OrientationAware: %s\n", toString(mParameters.orientationAware)); } @@ -3444,8 +3447,8 @@ void TouchInputMapper::configureRawPointerAxes() { mRawPointerAxes.clear(); } -void TouchInputMapper::dumpRawPointerAxes(String8& dump) { - dump.append(INDENT3 "Raw Touch Axes:\n"); +void TouchInputMapper::dumpRawPointerAxes(std::string& dump) { + dump += INDENT3 "Raw Touch Axes:\n"; dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.x, "X"); dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.y, "Y"); dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.pressure, "Pressure"); @@ -3890,8 +3893,8 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { } } -void TouchInputMapper::dumpSurface(String8& dump) { - dump.appendFormat(INDENT3 "Viewport: displayId=%d, orientation=%d, " +void TouchInputMapper::dumpSurface(std::string& dump) { + dump += StringPrintf(INDENT3 "Viewport: displayId=%d, orientation=%d, " "logicalFrame=[%d, %d, %d, %d], " "physicalFrame=[%d, %d, %d, %d], " "deviceSize=[%d, %d]\n", @@ -3902,11 +3905,11 @@ void TouchInputMapper::dumpSurface(String8& dump) { mViewport.physicalRight, mViewport.physicalBottom, mViewport.deviceWidth, mViewport.deviceHeight); - dump.appendFormat(INDENT3 "SurfaceWidth: %dpx\n", mSurfaceWidth); - dump.appendFormat(INDENT3 "SurfaceHeight: %dpx\n", mSurfaceHeight); - dump.appendFormat(INDENT3 "SurfaceLeft: %d\n", mSurfaceLeft); - dump.appendFormat(INDENT3 "SurfaceTop: %d\n", mSurfaceTop); - dump.appendFormat(INDENT3 "SurfaceOrientation: %d\n", mSurfaceOrientation); + dump += StringPrintf(INDENT3 "SurfaceWidth: %dpx\n", mSurfaceWidth); + dump += StringPrintf(INDENT3 "SurfaceHeight: %dpx\n", mSurfaceHeight); + dump += StringPrintf(INDENT3 "SurfaceLeft: %d\n", mSurfaceLeft); + dump += StringPrintf(INDENT3 "SurfaceTop: %d\n", mSurfaceTop); + dump += StringPrintf(INDENT3 "SurfaceOrientation: %d\n", mSurfaceOrientation); } void TouchInputMapper::configureVirtualKeys() { @@ -3963,13 +3966,13 @@ void TouchInputMapper::configureVirtualKeys() { } } -void TouchInputMapper::dumpVirtualKeys(String8& dump) { +void TouchInputMapper::dumpVirtualKeys(std::string& dump) { if (!mVirtualKeys.isEmpty()) { - dump.append(INDENT3 "Virtual Keys:\n"); + dump += INDENT3 "Virtual Keys:\n"; for (size_t i = 0; i < mVirtualKeys.size(); i++) { const VirtualKey& virtualKey = mVirtualKeys.itemAt(i); - dump.appendFormat(INDENT4 "%zu: scanCode=%d, keyCode=%d, " + 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, @@ -4118,75 +4121,75 @@ void TouchInputMapper::resolveCalibration() { } } -void TouchInputMapper::dumpCalibration(String8& dump) { - dump.append(INDENT3 "Calibration:\n"); +void TouchInputMapper::dumpCalibration(std::string& dump) { + dump += INDENT3 "Calibration:\n"; // Size switch (mCalibration.sizeCalibration) { case Calibration::SIZE_CALIBRATION_NONE: - dump.append(INDENT4 "touch.size.calibration: none\n"); + dump += INDENT4 "touch.size.calibration: none\n"; break; case Calibration::SIZE_CALIBRATION_GEOMETRIC: - dump.append(INDENT4 "touch.size.calibration: geometric\n"); + dump += INDENT4 "touch.size.calibration: geometric\n"; break; case Calibration::SIZE_CALIBRATION_DIAMETER: - dump.append(INDENT4 "touch.size.calibration: diameter\n"); + dump += INDENT4 "touch.size.calibration: diameter\n"; break; case Calibration::SIZE_CALIBRATION_BOX: - dump.append(INDENT4 "touch.size.calibration: box\n"); + dump += INDENT4 "touch.size.calibration: box\n"; break; case Calibration::SIZE_CALIBRATION_AREA: - dump.append(INDENT4 "touch.size.calibration: area\n"); + dump += INDENT4 "touch.size.calibration: area\n"; break; default: ALOG_ASSERT(false); } if (mCalibration.haveSizeScale) { - dump.appendFormat(INDENT4 "touch.size.scale: %0.3f\n", + dump += StringPrintf(INDENT4 "touch.size.scale: %0.3f\n", mCalibration.sizeScale); } if (mCalibration.haveSizeBias) { - dump.appendFormat(INDENT4 "touch.size.bias: %0.3f\n", + dump += StringPrintf(INDENT4 "touch.size.bias: %0.3f\n", mCalibration.sizeBias); } if (mCalibration.haveSizeIsSummed) { - dump.appendFormat(INDENT4 "touch.size.isSummed: %s\n", + dump += StringPrintf(INDENT4 "touch.size.isSummed: %s\n", toString(mCalibration.sizeIsSummed)); } // Pressure switch (mCalibration.pressureCalibration) { case Calibration::PRESSURE_CALIBRATION_NONE: - dump.append(INDENT4 "touch.pressure.calibration: none\n"); + dump += INDENT4 "touch.pressure.calibration: none\n"; break; case Calibration::PRESSURE_CALIBRATION_PHYSICAL: - dump.append(INDENT4 "touch.pressure.calibration: physical\n"); + dump += INDENT4 "touch.pressure.calibration: physical\n"; break; case Calibration::PRESSURE_CALIBRATION_AMPLITUDE: - dump.append(INDENT4 "touch.pressure.calibration: amplitude\n"); + dump += INDENT4 "touch.pressure.calibration: amplitude\n"; break; default: ALOG_ASSERT(false); } if (mCalibration.havePressureScale) { - dump.appendFormat(INDENT4 "touch.pressure.scale: %0.3f\n", + dump += StringPrintf(INDENT4 "touch.pressure.scale: %0.3f\n", mCalibration.pressureScale); } // Orientation switch (mCalibration.orientationCalibration) { case Calibration::ORIENTATION_CALIBRATION_NONE: - dump.append(INDENT4 "touch.orientation.calibration: none\n"); + dump += INDENT4 "touch.orientation.calibration: none\n"; break; case Calibration::ORIENTATION_CALIBRATION_INTERPOLATED: - dump.append(INDENT4 "touch.orientation.calibration: interpolated\n"); + dump += INDENT4 "touch.orientation.calibration: interpolated\n"; break; case Calibration::ORIENTATION_CALIBRATION_VECTOR: - dump.append(INDENT4 "touch.orientation.calibration: vector\n"); + dump += INDENT4 "touch.orientation.calibration: vector\n"; break; default: ALOG_ASSERT(false); @@ -4195,41 +4198,41 @@ void TouchInputMapper::dumpCalibration(String8& dump) { // Distance switch (mCalibration.distanceCalibration) { case Calibration::DISTANCE_CALIBRATION_NONE: - dump.append(INDENT4 "touch.distance.calibration: none\n"); + dump += INDENT4 "touch.distance.calibration: none\n"; break; case Calibration::DISTANCE_CALIBRATION_SCALED: - dump.append(INDENT4 "touch.distance.calibration: scaled\n"); + dump += INDENT4 "touch.distance.calibration: scaled\n"; break; default: ALOG_ASSERT(false); } if (mCalibration.haveDistanceScale) { - dump.appendFormat(INDENT4 "touch.distance.scale: %0.3f\n", + dump += StringPrintf(INDENT4 "touch.distance.scale: %0.3f\n", mCalibration.distanceScale); } switch (mCalibration.coverageCalibration) { case Calibration::COVERAGE_CALIBRATION_NONE: - dump.append(INDENT4 "touch.coverage.calibration: none\n"); + dump += INDENT4 "touch.coverage.calibration: none\n"; break; case Calibration::COVERAGE_CALIBRATION_BOX: - dump.append(INDENT4 "touch.coverage.calibration: box\n"); + dump += INDENT4 "touch.coverage.calibration: box\n"; break; default: ALOG_ASSERT(false); } } -void TouchInputMapper::dumpAffineTransformation(String8& dump) { - dump.append(INDENT3 "Affine Transformation:\n"); +void TouchInputMapper::dumpAffineTransformation(std::string& dump) { + dump += INDENT3 "Affine Transformation:\n"; - dump.appendFormat(INDENT4 "X scale: %0.3f\n", mAffineTransform.x_scale); - dump.appendFormat(INDENT4 "X ymix: %0.3f\n", mAffineTransform.x_ymix); - dump.appendFormat(INDENT4 "X offset: %0.3f\n", mAffineTransform.x_offset); - dump.appendFormat(INDENT4 "Y xmix: %0.3f\n", mAffineTransform.y_xmix); - dump.appendFormat(INDENT4 "Y scale: %0.3f\n", mAffineTransform.y_scale); - dump.appendFormat(INDENT4 "Y offset: %0.3f\n", mAffineTransform.y_offset); + dump += StringPrintf(INDENT4 "X scale: %0.3f\n", mAffineTransform.x_scale); + dump += StringPrintf(INDENT4 "X ymix: %0.3f\n", mAffineTransform.x_ymix); + dump += StringPrintf(INDENT4 "X offset: %0.3f\n", mAffineTransform.x_offset); + dump += StringPrintf(INDENT4 "Y xmix: %0.3f\n", mAffineTransform.y_xmix); + dump += StringPrintf(INDENT4 "Y scale: %0.3f\n", mAffineTransform.y_scale); + dump += StringPrintf(INDENT4 "Y offset: %0.3f\n", mAffineTransform.y_offset); } void TouchInputMapper::updateAffineTransformation() { @@ -7005,11 +7008,11 @@ void ExternalStylusInputMapper::populateDeviceInfo(InputDeviceInfo* info) { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f); } -void ExternalStylusInputMapper::dump(String8& dump) { - dump.append(INDENT2 "External Stylus Input Mapper:\n"); - dump.append(INDENT3 "Raw Stylus Axes:\n"); +void ExternalStylusInputMapper::dump(std::string& dump) { + dump += INDENT2 "External Stylus Input Mapper:\n"; + dump += INDENT3 "Raw Stylus Axes:\n"; dumpRawAbsoluteAxisInfo(dump, mRawPressureAxis, "Pressure"); - dump.append(INDENT3 "Stylus State:\n"); + dump += INDENT3 "Stylus State:\n"; dumpStylusState(dump, mStylusState); } @@ -7114,37 +7117,37 @@ int32_t JoystickInputMapper::getCompatAxis(int32_t axis) { return -1; } -void JoystickInputMapper::dump(String8& dump) { - dump.append(INDENT2 "Joystick Input Mapper:\n"); +void JoystickInputMapper::dump(std::string& dump) { + dump += INDENT2 "Joystick Input Mapper:\n"; - dump.append(INDENT3 "Axes:\n"); + dump += INDENT3 "Axes:\n"; size_t numAxes = mAxes.size(); for (size_t i = 0; i < numAxes; i++) { const Axis& axis = mAxes.valueAt(i); const char* label = getAxisLabel(axis.axisInfo.axis); if (label) { - dump.appendFormat(INDENT4 "%s", label); + dump += StringPrintf(INDENT4 "%s", label); } else { - dump.appendFormat(INDENT4 "%d", axis.axisInfo.axis); + dump += StringPrintf(INDENT4 "%d", axis.axisInfo.axis); } if (axis.axisInfo.mode == AxisInfo::MODE_SPLIT) { label = getAxisLabel(axis.axisInfo.highAxis); if (label) { - dump.appendFormat(" / %s (split at %d)", label, axis.axisInfo.splitValue); + dump += StringPrintf(" / %s (split at %d)", label, axis.axisInfo.splitValue); } else { - dump.appendFormat(" / %d (split at %d)", axis.axisInfo.highAxis, + dump += StringPrintf(" / %d (split at %d)", axis.axisInfo.highAxis, axis.axisInfo.splitValue); } } else if (axis.axisInfo.mode == AxisInfo::MODE_INVERT) { - dump.append(" (invert)"); + dump += " (invert)"; } - dump.appendFormat(": min=%0.5f, max=%0.5f, flat=%0.5f, fuzz=%0.5f, resolution=%0.5f\n", + 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); - dump.appendFormat(INDENT4 " scale=%0.5f, offset=%0.5f, " + dump += StringPrintf(INDENT4 " scale=%0.5f, offset=%0.5f, " "highScale=%0.5f, highOffset=%0.5f\n", axis.scale, axis.offset, axis.highScale, axis.highOffset); - dump.appendFormat(INDENT4 " rawAxis=%d, rawMin=%d, rawMax=%d, " + 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); diff --git a/services/inputflinger/InputReader.h b/services/inputflinger/InputReader.h index a6b9798759..4f48262910 100644 --- a/services/inputflinger/InputReader.h +++ b/services/inputflinger/InputReader.h @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -207,8 +206,8 @@ struct InputReaderConfiguration { void setVirtualDisplayViewports(const Vector& viewports); - void dump(String8& dump) const; - void dumpViewport(String8& dump, const DisplayViewport& viewport) const; + void dump(std::string& dump) const; + void dumpViewport(std::string& dump, const DisplayViewport& viewport) const; private: DisplayViewport mInternalDisplay; @@ -292,7 +291,7 @@ public: /* Dumps the state of the input reader. * * This method may be called on any thread (usually by the input manager). */ - virtual void dump(String8& dump) = 0; + virtual void dump(std::string& dump) = 0; /* Called by the heatbeat to ensures that the reader has not deadlocked. */ virtual void monitor() = 0; @@ -412,7 +411,7 @@ public: const sp& listener); virtual ~InputReader(); - virtual void dump(String8& dump); + virtual void dump(std::string& dump); virtual void monitor(); virtual void loopOnce(); @@ -569,7 +568,7 @@ public: bool isEnabled(); void setEnabled(bool enabled, nsecs_t when); - void dump(String8& dump); + void dump(std::string& dump); void addMapper(InputMapper* mapper); void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); void reset(nsecs_t when); @@ -987,7 +986,7 @@ public: virtual uint32_t getSources() = 0; virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); - virtual void dump(String8& dump); + virtual void dump(std::string& dump); virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); virtual void reset(nsecs_t when); virtual void process(const RawEvent* rawEvent) = 0; @@ -1017,9 +1016,9 @@ protected: status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo); void bumpGeneration(); - static void dumpRawAbsoluteAxisInfo(String8& dump, + static void dumpRawAbsoluteAxisInfo(std::string& dump, const RawAbsoluteAxisInfo& axis, const char* name); - static void dumpStylusState(String8& dump, const StylusState& state); + static void dumpStylusState(std::string& dump, const StylusState& state); }; @@ -1032,7 +1031,7 @@ public: virtual void process(const RawEvent* rawEvent); virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); - virtual void dump(String8& dump); + virtual void dump(std::string& dump); private: uint32_t mSwitchValues; @@ -1056,7 +1055,7 @@ public: int32_t token); virtual void cancelVibrate(int32_t token); virtual void timeoutExpired(nsecs_t when); - virtual void dump(String8& dump); + virtual void dump(std::string& dump); private: bool mVibrating; @@ -1079,7 +1078,7 @@ public: virtual uint32_t getSources(); virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); - virtual void dump(String8& dump); + virtual void dump(std::string& dump); virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); virtual void reset(nsecs_t when); virtual void process(const RawEvent* rawEvent); @@ -1125,7 +1124,7 @@ private: } mParameters; void configureParameters(); - void dumpParameters(String8& dump); + void dumpParameters(std::string& dump); bool isKeyboardOrGamepadKey(int32_t scanCode); bool isMediaKey(int32_t keyCode); @@ -1151,7 +1150,7 @@ public: virtual uint32_t getSources(); virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); - virtual void dump(String8& dump); + virtual void dump(std::string& dump); virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); virtual void reset(nsecs_t when); virtual void process(const RawEvent* rawEvent); @@ -1204,7 +1203,7 @@ private: nsecs_t mDownTime; void configureParameters(); - void dumpParameters(String8& dump); + void dumpParameters(std::string& dump); void sync(nsecs_t when); }; @@ -1217,7 +1216,7 @@ public: virtual uint32_t getSources(); virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); - virtual void dump(String8& dump); + virtual void dump(std::string& dump); virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); virtual void reset(nsecs_t when); virtual void process(const RawEvent* rawEvent); @@ -1239,7 +1238,7 @@ public: virtual uint32_t getSources(); virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); - virtual void dump(String8& dump); + virtual void dump(std::string& dump); virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); virtual void reset(nsecs_t when); virtual void process(const RawEvent* rawEvent); @@ -1482,18 +1481,18 @@ protected: Vector mVirtualKeys; virtual void configureParameters(); - virtual void dumpParameters(String8& dump); + virtual void dumpParameters(std::string& dump); virtual void configureRawPointerAxes(); - virtual void dumpRawPointerAxes(String8& dump); + virtual void dumpRawPointerAxes(std::string& dump); virtual void configureSurface(nsecs_t when, bool* outResetNeeded); - virtual void dumpSurface(String8& dump); + virtual void dumpSurface(std::string& dump); virtual void configureVirtualKeys(); - virtual void dumpVirtualKeys(String8& dump); + virtual void dumpVirtualKeys(std::string& dump); virtual void parseCalibration(); virtual void resolveCalibration(); - virtual void dumpCalibration(String8& dump); + virtual void dumpCalibration(std::string& dump); virtual void updateAffineTransformation(); - virtual void dumpAffineTransformation(String8& dump); + virtual void dumpAffineTransformation(std::string& dump); virtual void resolveExternalStylusPresence(); virtual bool hasStylus() const = 0; virtual bool hasExternalStylus() const; @@ -1904,7 +1903,7 @@ public: virtual uint32_t getSources(); virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); - virtual void dump(String8& dump); + virtual void dump(std::string& dump); virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); virtual void reset(nsecs_t when); virtual void process(const RawEvent* rawEvent); @@ -1926,7 +1925,7 @@ public: virtual uint32_t getSources(); virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); - virtual void dump(String8& dump); + virtual void dump(std::string& dump); virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); virtual void reset(nsecs_t when); virtual void process(const RawEvent* rawEvent); diff --git a/services/inputflinger/InputWindow.h b/services/inputflinger/InputWindow.h index 9eb27983cd..5a48375910 100644 --- a/services/inputflinger/InputWindow.h +++ b/services/inputflinger/InputWindow.h @@ -23,7 +23,6 @@ #include #include #include -#include #include "InputApplication.h" @@ -116,7 +115,7 @@ struct InputWindowInfo { }; sp inputChannel; - String8 name; + std::string name; int32_t layoutParamsFlags; int32_t layoutParamsType; nsecs_t dispatchingTimeout; @@ -173,8 +172,8 @@ public: return mInfo ? mInfo->inputChannel : NULL; } - inline String8 getName() const { - return mInfo ? mInfo->name : String8(""); + inline std::string getName() const { + return mInfo ? mInfo->name : ""; } inline nsecs_t getDispatchingTimeout(nsecs_t defaultValue) const { diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index 7ae36d86f1..aa6df244e2 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -54,7 +54,7 @@ private: virtual nsecs_t notifyANR(const sp&, const sp&, - const String8&) { + const std::string&) { return 0; } diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 76291a5786..0344eadad6 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -798,7 +798,7 @@ private: return false; } - virtual void dump(String8&) { + virtual void dump(std::string&) { } virtual void monitor() { -- cgit v1.2.3-59-g8ed1b From aa449c9c9905049938aba7d44bbcf84c539b58b3 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Wed, 13 Dec 2017 21:21:43 +0000 Subject: Scale the pressure range's max value. Since the pressure scale is configurable via a idc property, it isn't guaranteed to always be [0, 1.0]. Unfortunately, we didn't scale the max value of the MotionRange so we'd incorrectly return a max pressure of 1.0 for all devices, even when they might exceed that range. Test: adb push \ $(gettop)/out/target/product/taimen/data/nativetest/inputflinger_tests/InputReader_test \ /data/nativetest/inputflinger_tests/InputReader_test && adb shell /data/nativetest/inputflinger_tests/InputReader_test Change-Id: I7ef174941c4faa7d7efdaa3d69107740f58afd2a --- services/inputflinger/InputReader.cpp | 4 +++- services/inputflinger/tests/InputReader_test.cpp | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'services/inputflinger/InputReader.cpp') diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index e398a84391..76ea889dc5 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -3705,11 +3705,13 @@ 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.havePressureScale) { mPressureScale = mCalibration.pressureScale; + pressureMax = mPressureScale * mRawPointerAxes.pressure.maxValue; } else if (mRawPointerAxes.pressure.valid && mRawPointerAxes.pressure.maxValue != 0) { mPressureScale = 1.0f / mRawPointerAxes.pressure.maxValue; @@ -3719,7 +3721,7 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { mOrientedRanges.pressure.axis = AMOTION_EVENT_AXIS_PRESSURE; mOrientedRanges.pressure.source = mSource; mOrientedRanges.pressure.min = 0; - mOrientedRanges.pressure.max = 1.0; + mOrientedRanges.pressure.max = pressureMax; mOrientedRanges.pressure.flat = 0; mOrientedRanges.pressure.fuzz = 0; mOrientedRanges.pressure.resolution = 0; diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 0344eadad6..63c92d1dc7 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -2954,8 +2954,8 @@ const int32_t TouchInputMapperTest::RAW_TOUCH_MIN = 0; const int32_t TouchInputMapperTest::RAW_TOUCH_MAX = 31; const int32_t TouchInputMapperTest::RAW_TOOL_MIN = 0; const int32_t TouchInputMapperTest::RAW_TOOL_MAX = 15; -const int32_t TouchInputMapperTest::RAW_PRESSURE_MIN = RAW_TOUCH_MIN; -const int32_t TouchInputMapperTest::RAW_PRESSURE_MAX = RAW_TOUCH_MAX; +const int32_t TouchInputMapperTest::RAW_PRESSURE_MIN = 0; +const int32_t TouchInputMapperTest::RAW_PRESSURE_MAX = 255; const int32_t TouchInputMapperTest::RAW_ORIENTATION_MIN = -7; const int32_t TouchInputMapperTest::RAW_ORIENTATION_MAX = 7; const int32_t TouchInputMapperTest::RAW_DISTANCE_MIN = 0; @@ -5316,6 +5316,12 @@ TEST_F(MultiTouchInputMapperTest, Process_PressureAxis_AmplitudeCalibration) { addConfigurationProperty("touch.pressure.scale", "0.01"); addMapperAndConfigure(mapper); + InputDeviceInfo info; + mapper->populateDeviceInfo(&info); + ASSERT_NO_FATAL_FAILURE(assertMotionRange(info, + AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_TOUCHSCREEN, + 0.0f, RAW_PRESSURE_MAX * 0.01, 0.0f, 0.0f)); + // These calculations are based on the input device calibration documentation. int32_t rawX = 100; int32_t rawY = 200; -- cgit v1.2.3-59-g8ed1b From 16f90693fdce4aec6ec7507628660e4f9564a201 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Wed, 27 Dec 2017 14:29:55 -0800 Subject: Process EV_MSC MSC_TIMESTAMP in InputMapper An evdev driver could report EV_MSC MSC_TIMESTAMP input event to relay the number of microseconds since the last reset. This data could be useful for keeping track of the specific kernel time of a particular input_event. Propagate this data here to the InputDispatcher level, but only for the MultiTouchInputMapper. Bug: 62940136 Test: report MSC_TIMESTAMP in kernel driver on Pixel 2 XL device and observe the data in the inputflinger layer using HeatMapDemo app. Test: m -j inputflinger_tests_InputReader_test inputflinger_tests_InputDispatcher_test && adb push out/target/product/$TARGET_PRODUCT/data/nativetest64/* /data/nativetest64/ then on device: /data/nativetest64/inputflinger_tests # ./InputReader_test Change-Id: Id990ec46a380e7f367020863fd86e4bae6ce47e4 --- services/inputflinger/InputListener.cpp | 9 ++-- services/inputflinger/InputListener.h | 9 +++- services/inputflinger/InputReader.cpp | 63 +++++++++++++++--------- services/inputflinger/InputReader.h | 9 ++++ services/inputflinger/tests/InputReader_test.cpp | 30 +++++++++++ 5 files changed, 94 insertions(+), 26 deletions(-) (limited to 'services/inputflinger/InputReader.cpp') diff --git a/services/inputflinger/InputListener.cpp b/services/inputflinger/InputListener.cpp index 2ee222b2bd..520fea4c95 100644 --- a/services/inputflinger/InputListener.cpp +++ b/services/inputflinger/InputListener.cpp @@ -69,13 +69,15 @@ void NotifyKeyArgs::notify(const sp& listener) const { NotifyMotionArgs::NotifyMotionArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, uint32_t policyFlags, int32_t action, int32_t actionButton, int32_t flags, int32_t metaState, - int32_t buttonState, int32_t edgeFlags, int32_t displayId, uint32_t pointerCount, + int32_t buttonState, int32_t edgeFlags, int32_t displayId, uint32_t deviceTimestamp, + uint32_t pointerCount, const PointerProperties* pointerProperties, const PointerCoords* pointerCoords, float xPrecision, float yPrecision, nsecs_t downTime) : eventTime(eventTime), deviceId(deviceId), source(source), policyFlags(policyFlags), action(action), actionButton(actionButton), flags(flags), metaState(metaState), buttonState(buttonState), - edgeFlags(edgeFlags), displayId(displayId), pointerCount(pointerCount), + edgeFlags(edgeFlags), displayId(displayId), deviceTimestamp(deviceTimestamp), + pointerCount(pointerCount), xPrecision(xPrecision), yPrecision(yPrecision), downTime(downTime) { for (uint32_t i = 0; i < pointerCount; i++) { this->pointerProperties[i].copyFrom(pointerProperties[i]); @@ -88,7 +90,8 @@ NotifyMotionArgs::NotifyMotionArgs(const NotifyMotionArgs& other) : policyFlags(other.policyFlags), action(other.action), actionButton(other.actionButton), flags(other.flags), metaState(other.metaState), buttonState(other.buttonState), - edgeFlags(other.edgeFlags), displayId(other.displayId), pointerCount(other.pointerCount), + edgeFlags(other.edgeFlags), displayId(other.displayId), + deviceTimestamp(other.deviceTimestamp), pointerCount(other.pointerCount), xPrecision(other.xPrecision), yPrecision(other.yPrecision), downTime(other.downTime) { for (uint32_t i = 0; i < pointerCount; i++) { pointerProperties[i].copyFrom(other.pointerProperties[i]); diff --git a/services/inputflinger/InputListener.h b/services/inputflinger/InputListener.h index ea3dd1caac..77afb344c2 100644 --- a/services/inputflinger/InputListener.h +++ b/services/inputflinger/InputListener.h @@ -90,6 +90,13 @@ struct NotifyMotionArgs : public NotifyArgs { int32_t buttonState; int32_t edgeFlags; int32_t displayId; + /** + * A timestamp in the input device's time base, not the platform's. + * The units are microseconds since the last reset. + * This can only be compared to other device timestamps from the same device. + * This value will overflow after a little over an hour. + */ + uint32_t deviceTimestamp; uint32_t pointerCount; PointerProperties pointerProperties[MAX_POINTERS]; PointerCoords pointerCoords[MAX_POINTERS]; @@ -102,7 +109,7 @@ struct NotifyMotionArgs : public NotifyArgs { NotifyMotionArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, uint32_t policyFlags, int32_t action, int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState, - int32_t edgeFlags, int32_t displayId, uint32_t pointerCount, + int32_t edgeFlags, int32_t displayId, uint32_t deviceTimestamp, uint32_t pointerCount, const PointerProperties* pointerProperties, const PointerCoords* pointerCoords, float xPrecision, float yPrecision, nsecs_t downTime); diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index 76ea889dc5..e0cd8a005a 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -1787,7 +1787,7 @@ void SingleTouchMotionAccumulator::process(const RawEvent* rawEvent) { MultiTouchMotionAccumulator::MultiTouchMotionAccumulator() : mCurrentSlot(-1), mSlots(NULL), mSlotCount(0), mUsingSlotsProtocol(false), - mHaveStylus(false) { + mHaveStylus(false), mDeviceTimestamp(0) { } MultiTouchMotionAccumulator::~MultiTouchMotionAccumulator() { @@ -1828,6 +1828,7 @@ void MultiTouchMotionAccumulator::reset(InputDevice* device) { } else { clearSlots(-1); } + mDeviceTimestamp = 0; } void MultiTouchMotionAccumulator::clearSlots(int32_t initialSlot) { @@ -1921,6 +1922,8 @@ void MultiTouchMotionAccumulator::process(const RawEvent* rawEvent) { } else if (rawEvent->type == EV_SYN && rawEvent->code == SYN_MT_REPORT) { // MultiTouch Sync: The driver has returned all data for *one* of the pointers. mCurrentSlot += 1; + } else if (rawEvent->type == EV_MSC && rawEvent->code == MSC_TIMESTAMP) { + mDeviceTimestamp = rawEvent->value; } } @@ -2894,7 +2897,7 @@ void CursorInputMapper::sync(nsecs_t when) { NotifyMotionArgs releaseArgs(when, getDeviceId(), mSource, policyFlags, AMOTION_EVENT_ACTION_BUTTON_RELEASE, actionButton, 0, metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE, - displayId, 1, &pointerProperties, &pointerCoords, + displayId, /* deviceTimestamp */ 0, 1, &pointerProperties, &pointerCoords, mXPrecision, mYPrecision, downTime); getListener()->notifyMotion(&releaseArgs); } @@ -2903,7 +2906,7 @@ void CursorInputMapper::sync(nsecs_t when) { NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags, motionEventAction, 0, 0, metaState, currentButtonState, AMOTION_EVENT_EDGE_FLAG_NONE, - displayId, 1, &pointerProperties, &pointerCoords, + displayId, /* deviceTimestamp */ 0, 1, &pointerProperties, &pointerCoords, mXPrecision, mYPrecision, downTime); getListener()->notifyMotion(&args); @@ -2915,7 +2918,7 @@ void CursorInputMapper::sync(nsecs_t when) { NotifyMotionArgs pressArgs(when, getDeviceId(), mSource, policyFlags, AMOTION_EVENT_ACTION_BUTTON_PRESS, actionButton, 0, metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE, - displayId, 1, &pointerProperties, &pointerCoords, + displayId, /* deviceTimestamp */ 0, 1, &pointerProperties, &pointerCoords, mXPrecision, mYPrecision, downTime); getListener()->notifyMotion(&pressArgs); } @@ -2929,7 +2932,7 @@ void CursorInputMapper::sync(nsecs_t when) { NotifyMotionArgs hoverArgs(when, getDeviceId(), mSource, policyFlags, AMOTION_EVENT_ACTION_HOVER_MOVE, 0, 0, metaState, currentButtonState, AMOTION_EVENT_EDGE_FLAG_NONE, - displayId, 1, &pointerProperties, &pointerCoords, + displayId, /* deviceTimestamp */ 0, 1, &pointerProperties, &pointerCoords, mXPrecision, mYPrecision, downTime); getListener()->notifyMotion(&hoverArgs); } @@ -2942,7 +2945,7 @@ void CursorInputMapper::sync(nsecs_t when) { NotifyMotionArgs scrollArgs(when, getDeviceId(), mSource, policyFlags, AMOTION_EVENT_ACTION_SCROLL, 0, 0, metaState, currentButtonState, AMOTION_EVENT_EDGE_FLAG_NONE, - displayId, 1, &pointerProperties, &pointerCoords, + displayId, /* deviceTimestamp */ 0, 1, &pointerProperties, &pointerCoords, mXPrecision, mYPrecision, downTime); getListener()->notifyMotion(&scrollArgs); } @@ -3072,7 +3075,7 @@ void RotaryEncoderInputMapper::sync(nsecs_t when) { NotifyMotionArgs scrollArgs(when, getDeviceId(), mSource, policyFlags, AMOTION_EVENT_ACTION_SCROLL, 0, 0, metaState, 0, AMOTION_EVENT_EDGE_FLAG_NONE, - displayId, 1, &pointerProperties, &pointerCoords, + displayId, /* deviceTimestamp */ 0, 1, &pointerProperties, &pointerCoords, 0, 0, 0); getListener()->notifyMotion(&scrollArgs); } @@ -4729,6 +4732,7 @@ void TouchInputMapper::abortTouches(nsecs_t when, uint32_t policyFlags) { int32_t buttonState = mCurrentCookedState.buttonState; dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_CANCEL, 0, 0, metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE, + mCurrentCookedState.deviceTimestamp, mCurrentCookedState.cookedPointerData.pointerProperties, mCurrentCookedState.cookedPointerData.pointerCoords, mCurrentCookedState.cookedPointerData.idToIndex, @@ -4751,6 +4755,7 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) { dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_MOVE, 0, 0, metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE, + mCurrentCookedState.deviceTimestamp, mCurrentCookedState.cookedPointerData.pointerProperties, mCurrentCookedState.cookedPointerData.pointerCoords, mCurrentCookedState.cookedPointerData.idToIndex, @@ -4785,6 +4790,7 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) { dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_POINTER_UP, 0, 0, metaState, buttonState, 0, + mCurrentCookedState.deviceTimestamp, mLastCookedState.cookedPointerData.pointerProperties, mLastCookedState.cookedPointerData.pointerCoords, mLastCookedState.cookedPointerData.idToIndex, @@ -4799,6 +4805,7 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) { ALOG_ASSERT(moveIdBits.value == dispatchedIdBits.value); dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_MOVE, 0, 0, metaState, buttonState, 0, + mCurrentCookedState.deviceTimestamp, mCurrentCookedState.cookedPointerData.pointerProperties, mCurrentCookedState.cookedPointerData.pointerCoords, mCurrentCookedState.cookedPointerData.idToIndex, @@ -4817,6 +4824,7 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) { dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_POINTER_DOWN, 0, 0, metaState, buttonState, 0, + mCurrentCookedState.deviceTimestamp, mCurrentCookedState.cookedPointerData.pointerProperties, mCurrentCookedState.cookedPointerData.pointerCoords, mCurrentCookedState.cookedPointerData.idToIndex, @@ -4832,6 +4840,7 @@ void TouchInputMapper::dispatchHoverExit(nsecs_t when, uint32_t policyFlags) { int32_t metaState = getContext()->getGlobalMetaState(); dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_HOVER_EXIT, 0, 0, metaState, mLastCookedState.buttonState, 0, + mLastCookedState.deviceTimestamp, mLastCookedState.cookedPointerData.pointerProperties, mLastCookedState.cookedPointerData.pointerCoords, mLastCookedState.cookedPointerData.idToIndex, @@ -4848,6 +4857,7 @@ void TouchInputMapper::dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFl if (!mSentHoverEnter) { dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_HOVER_ENTER, 0, 0, metaState, mCurrentRawState.buttonState, 0, + mCurrentCookedState.deviceTimestamp, mCurrentCookedState.cookedPointerData.pointerProperties, mCurrentCookedState.cookedPointerData.pointerCoords, mCurrentCookedState.cookedPointerData.idToIndex, @@ -4859,6 +4869,7 @@ void TouchInputMapper::dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFl dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_HOVER_MOVE, 0, 0, metaState, mCurrentRawState.buttonState, 0, + mCurrentCookedState.deviceTimestamp, mCurrentCookedState.cookedPointerData.pointerProperties, mCurrentCookedState.cookedPointerData.pointerCoords, mCurrentCookedState.cookedPointerData.idToIndex, @@ -4878,6 +4889,7 @@ void TouchInputMapper::dispatchButtonRelease(nsecs_t when, uint32_t policyFlags) dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_BUTTON_RELEASE, actionButton, 0, metaState, buttonState, 0, + mCurrentCookedState.deviceTimestamp, mCurrentCookedState.cookedPointerData.pointerProperties, mCurrentCookedState.cookedPointerData.pointerCoords, mCurrentCookedState.cookedPointerData.idToIndex, idBits, -1, @@ -4895,6 +4907,7 @@ void TouchInputMapper::dispatchButtonPress(nsecs_t when, uint32_t policyFlags) { buttonState |= actionButton; dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_BUTTON_PRESS, actionButton, 0, metaState, buttonState, 0, + mCurrentCookedState.deviceTimestamp, mCurrentCookedState.cookedPointerData.pointerProperties, mCurrentCookedState.cookedPointerData.pointerCoords, mCurrentCookedState.cookedPointerData.idToIndex, idBits, -1, @@ -4913,6 +4926,8 @@ void TouchInputMapper::cookPointerData() { uint32_t currentPointerCount = mCurrentRawState.rawPointerData.pointerCount; mCurrentCookedState.cookedPointerData.clear(); + mCurrentCookedState.deviceTimestamp = + mCurrentRawState.deviceTimestamp; mCurrentCookedState.cookedPointerData.pointerCount = currentPointerCount; mCurrentCookedState.cookedPointerData.hoveringIdBits = mCurrentRawState.rawPointerData.hoveringIdBits; @@ -5305,7 +5320,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag if (cancelPreviousGesture) { dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_CANCEL, 0, 0, metaState, buttonState, - AMOTION_EVENT_EDGE_FLAG_NONE, + AMOTION_EVENT_EDGE_FLAG_NONE, /* deviceTimestamp */ 0, mPointerGesture.lastGestureProperties, mPointerGesture.lastGestureCoords, mPointerGesture.lastGestureIdToIndex, dispatchedGestureIdBits, -1, 0, @@ -5326,6 +5341,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_POINTER_UP, 0, 0, metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE, + /* deviceTimestamp */ 0, mPointerGesture.lastGestureProperties, mPointerGesture.lastGestureCoords, mPointerGesture.lastGestureIdToIndex, dispatchedGestureIdBits, id, @@ -5340,7 +5356,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag if (moveNeeded) { dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_MOVE, 0, 0, metaState, buttonState, - AMOTION_EVENT_EDGE_FLAG_NONE, + AMOTION_EVENT_EDGE_FLAG_NONE, /* deviceTimestamp */ 0, mPointerGesture.currentGestureProperties, mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex, dispatchedGestureIdBits, -1, @@ -5361,6 +5377,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_POINTER_DOWN, 0, 0, metaState, buttonState, 0, + /* deviceTimestamp */ 0, mPointerGesture.currentGestureProperties, mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex, dispatchedGestureIdBits, id, @@ -5372,7 +5389,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag if (mPointerGesture.currentGestureMode == PointerGesture::HOVER) { dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_HOVER_MOVE, 0, 0, - metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE, + metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE, /* deviceTimestamp */ 0, mPointerGesture.currentGestureProperties, mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex, mPointerGesture.currentGestureIdBits, -1, @@ -5399,7 +5416,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags, AMOTION_EVENT_ACTION_HOVER_MOVE, 0, 0, metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE, - mViewport.displayId, 1, &pointerProperties, &pointerCoords, + mViewport.displayId, /* deviceTimestamp */ 0, 1, &pointerProperties, &pointerCoords, 0, 0, mPointerGesture.downTime); getListener()->notifyMotion(&args); } @@ -5429,7 +5446,7 @@ void TouchInputMapper::abortPointerGestures(nsecs_t when, uint32_t policyFlags) int32_t buttonState = mCurrentRawState.buttonState; dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_CANCEL, 0, 0, metaState, buttonState, - AMOTION_EVENT_EDGE_FLAG_NONE, + AMOTION_EVENT_EDGE_FLAG_NONE, /* deviceTimestamp */ 0, mPointerGesture.lastGestureProperties, mPointerGesture.lastGestureCoords, mPointerGesture.lastGestureIdToIndex, mPointerGesture.lastGestureIdBits, -1, @@ -6321,7 +6338,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, // Send up. NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags, AMOTION_EVENT_ACTION_UP, 0, 0, metaState, mLastRawState.buttonState, 0, - mViewport.displayId, + mViewport.displayId, /* deviceTimestamp */ 0, 1, &mPointerSimple.lastProperties, &mPointerSimple.lastCoords, mOrientedXPrecision, mOrientedYPrecision, mPointerSimple.downTime); @@ -6334,7 +6351,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, // Send hover exit. NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags, AMOTION_EVENT_ACTION_HOVER_EXIT, 0, 0, metaState, mLastRawState.buttonState, 0, - mViewport.displayId, + mViewport.displayId, /* deviceTimestamp */ 0, 1, &mPointerSimple.lastProperties, &mPointerSimple.lastCoords, mOrientedXPrecision, mOrientedYPrecision, mPointerSimple.downTime); @@ -6349,7 +6366,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, // Send down. NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags, AMOTION_EVENT_ACTION_DOWN, 0, 0, metaState, mCurrentRawState.buttonState, 0, - mViewport.displayId, + mViewport.displayId, /* deviceTimestamp */ 0, 1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords, mOrientedXPrecision, mOrientedYPrecision, mPointerSimple.downTime); @@ -6359,7 +6376,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, // Send move. NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags, AMOTION_EVENT_ACTION_MOVE, 0, 0, metaState, mCurrentRawState.buttonState, 0, - mViewport.displayId, + mViewport.displayId, /* deviceTimestamp */ 0, 1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords, mOrientedXPrecision, mOrientedYPrecision, mPointerSimple.downTime); @@ -6374,7 +6391,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags, AMOTION_EVENT_ACTION_HOVER_ENTER, 0, 0, metaState, mCurrentRawState.buttonState, 0, - mViewport.displayId, + mViewport.displayId, /* deviceTimestamp */ 0, 1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords, mOrientedXPrecision, mOrientedYPrecision, mPointerSimple.downTime); @@ -6385,7 +6402,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags, AMOTION_EVENT_ACTION_HOVER_MOVE, 0, 0, metaState, mCurrentRawState.buttonState, 0, - mViewport.displayId, + mViewport.displayId, /* deviceTimestamp */ 0, 1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords, mOrientedXPrecision, mOrientedYPrecision, mPointerSimple.downTime); @@ -6406,7 +6423,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags, AMOTION_EVENT_ACTION_SCROLL, 0, 0, metaState, mCurrentRawState.buttonState, 0, - mViewport.displayId, + mViewport.displayId, /* deviceTimestamp */ 0, 1, &mPointerSimple.currentProperties, &pointerCoords, mOrientedXPrecision, mOrientedYPrecision, mPointerSimple.downTime); @@ -6431,7 +6448,7 @@ void TouchInputMapper::abortPointerSimple(nsecs_t when, uint32_t policyFlags) { void TouchInputMapper::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, + int32_t metaState, int32_t buttonState, int32_t edgeFlags, uint32_t deviceTimestamp, const PointerProperties* properties, const PointerCoords* coords, const uint32_t* idToIndex, BitSet32 idBits, int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime) { @@ -6469,7 +6486,7 @@ void TouchInputMapper::dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32 NotifyMotionArgs args(when, getDeviceId(), source, policyFlags, action, actionButton, flags, metaState, buttonState, edgeFlags, - mViewport.displayId, pointerCount, pointerProperties, pointerCoords, + mViewport.displayId, deviceTimestamp, pointerCount, pointerProperties, pointerCoords, xPrecision, yPrecision, downTime); getListener()->notifyMotion(&args); } @@ -6949,6 +6966,7 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { outCount += 1; } + outState->deviceTimestamp = mMultiTouchMotionAccumulator.getDeviceTimestamp(); outState->rawPointerData.pointerCount = outCount; mPointerIdBits = newPointerIdBits; @@ -7388,7 +7406,8 @@ void JoystickInputMapper::sync(nsecs_t when, bool force) { NotifyMotionArgs args(when, getDeviceId(), AINPUT_SOURCE_JOYSTICK, policyFlags, AMOTION_EVENT_ACTION_MOVE, 0, 0, metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE, - ADISPLAY_ID_NONE, 1, &pointerProperties, &pointerCoords, 0, 0, 0); + ADISPLAY_ID_NONE, /* deviceTimestamp */ 0, 1, &pointerProperties, &pointerCoords, + 0, 0, 0); getListener()->notifyMotion(&args); } diff --git a/services/inputflinger/InputReader.h b/services/inputflinger/InputReader.h index 4f48262910..cef3212684 100644 --- a/services/inputflinger/InputReader.h +++ b/services/inputflinger/InputReader.h @@ -947,6 +947,7 @@ public: inline size_t getSlotCount() const { return mSlotCount; } inline const Slot* getSlot(size_t index) const { return &mSlots[index]; } + inline uint32_t getDeviceTimestamp() const { return mDeviceTimestamp; } private: int32_t mCurrentSlot; @@ -954,6 +955,7 @@ private: size_t mSlotCount; bool mUsingSlotsProtocol; bool mHaveStylus; + uint32_t mDeviceTimestamp; void clearSlots(int32_t initialSlot); }; @@ -1396,6 +1398,7 @@ protected: struct RawState { nsecs_t when; + uint32_t deviceTimestamp; // Raw pointer sample data. RawPointerData rawPointerData; @@ -1408,6 +1411,7 @@ protected: void copyFrom(const RawState& other) { when = other.when; + deviceTimestamp = other.deviceTimestamp; rawPointerData.copyFrom(other.rawPointerData); buttonState = other.buttonState; rawVScroll = other.rawVScroll; @@ -1416,6 +1420,7 @@ protected: void clear() { when = 0; + deviceTimestamp = 0; rawPointerData.clear(); buttonState = 0; rawVScroll = 0; @@ -1424,6 +1429,7 @@ protected: }; struct CookedState { + uint32_t deviceTimestamp; // Cooked pointer sample data. CookedPointerData cookedPointerData; @@ -1435,6 +1441,7 @@ protected: int32_t buttonState; void copyFrom(const CookedState& other) { + deviceTimestamp = other.deviceTimestamp; cookedPointerData.copyFrom(other.cookedPointerData); fingerIdBits = other.fingerIdBits; stylusIdBits = other.stylusIdBits; @@ -1443,6 +1450,7 @@ protected: } void clear() { + deviceTimestamp = 0; cookedPointerData.clear(); fingerIdBits.clear(); stylusIdBits.clear(); @@ -1837,6 +1845,7 @@ private: 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, + uint32_t deviceTimestamp, const PointerProperties* properties, const PointerCoords* coords, const uint32_t* idToIndex, BitSet32 idBits, int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime); diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 63c92d1dc7..0a961cb42b 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -4384,6 +4384,7 @@ protected: void processSlot(MultiTouchInputMapper* mapper, int32_t slot); void processToolType(MultiTouchInputMapper* mapper, int32_t toolType); void processKey(MultiTouchInputMapper* mapper, int32_t code, int32_t value); + void processTimestamp(MultiTouchInputMapper* mapper, uint32_t value); void processMTSync(MultiTouchInputMapper* mapper); void processSync(MultiTouchInputMapper* mapper); }; @@ -4499,6 +4500,10 @@ void MultiTouchInputMapperTest::processKey( process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, code, value); } +void MultiTouchInputMapperTest::processTimestamp(MultiTouchInputMapper* mapper, uint32_t value) { + process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_MSC, MSC_TIMESTAMP, value); +} + void MultiTouchInputMapperTest::processMTSync(MultiTouchInputMapper* mapper) { process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_MT_REPORT, 0); } @@ -5881,5 +5886,30 @@ TEST_F(MultiTouchInputMapperTest, Process_WhenAbsMTPressureIsPresent_HoversIfIts toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); } +TEST_F(MultiTouchInputMapperTest, Process_HandlesTimestamp) { + MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); + + addConfigurationProperty("touch.deviceType", "touchScreen"); + prepareDisplay(DISPLAY_ORIENTATION_0); + prepareAxes(POSITION); + addMapperAndConfigure(mapper); + NotifyMotionArgs args; + + // By default, deviceTimestamp should be zero + processPosition(mapper, 100, 100); + processMTSync(mapper); + processSync(mapper); + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); + ASSERT_EQ(0U, args.deviceTimestamp); + + // Now the timestamp of 1000 is reported by evdev and should appear in MotionArgs + processPosition(mapper, 0, 0); + processTimestamp(mapper, 1000); + processMTSync(mapper); + processSync(mapper); + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); + ASSERT_EQ(1000U, args.deviceTimestamp); +} + } // namespace android -- cgit v1.2.3-59-g8ed1b