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 --- services/inputflinger/InputReader.h | 49 ++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'services/inputflinger/InputReader.h') 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); -- 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.h') 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