Skip to content

Commit 0b651c1

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "TouchInputMapper: Add logs for b/396796958" into main
2 parents ca5ace6 + a35dc99 commit 0b651c1

7 files changed

Lines changed: 76 additions & 14 deletions

File tree

services/inputflinger/reader/InputReader.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <unistd.h>
3333
#include <utils/Errors.h>
3434
#include <utils/Thread.h>
35+
#include <string>
3536

3637
#include "InputDevice.h"
3738
#include "include/gestures.h"
@@ -945,7 +946,10 @@ bool InputReader::setKernelWakeEnabled(int32_t deviceId, bool enabled) {
945946

946947
void InputReader::dump(std::string& dump) {
947948
std::scoped_lock _l(mLock);
949+
dumpLocked(dump);
950+
}
948951

952+
void InputReader::dumpLocked(std::string& dump) {
949953
mEventHub->dump(dump);
950954
dump += "\n";
951955

@@ -1032,6 +1036,12 @@ void InputReader::monitor() {
10321036
InputReader::ContextImpl::ContextImpl(InputReader* reader)
10331037
: mReader(reader), mIdGenerator(IdGenerator::Source::INPUT_READER) {}
10341038

1039+
std::string InputReader::ContextImpl::dump() {
1040+
std::string dump;
1041+
mReader->dumpLocked(dump);
1042+
return dump;
1043+
}
1044+
10351045
void InputReader::ContextImpl::updateGlobalMetaState() {
10361046
// lock is already held by the input loop
10371047
mReader->updateGlobalMetaStateLocked();

services/inputflinger/reader/include/InputReader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <utils/Mutex.h>
2222

2323
#include <memory>
24+
#include <string>
2425
#include <unordered_map>
2526
#include <vector>
2627

@@ -142,6 +143,7 @@ class InputReader : public InputReaderInterface {
142143

143144
public:
144145
explicit ContextImpl(InputReader* reader);
146+
std::string dump() REQUIRES(mReader->mLock) override;
145147
// lock is already held by the input loop
146148
void updateGlobalMetaState() NO_THREAD_SAFETY_ANALYSIS override;
147149
int32_t getGlobalMetaState() NO_THREAD_SAFETY_ANALYSIS override;
@@ -216,6 +218,8 @@ class InputReader : public InputReaderInterface {
216218
// The input device that produced a new gesture most recently.
217219
DeviceId mLastUsedDeviceId GUARDED_BY(mLock){ReservedInputDeviceId::INVALID_INPUT_DEVICE_ID};
218220

221+
void dumpLocked(std::string& dump) REQUIRES(mLock);
222+
219223
// low-level input event decoding and device management
220224
[[nodiscard]] std::list<NotifyArgs> processEventsLocked(const RawEvent* rawEvents, size_t count)
221225
REQUIRES(mLock);

services/inputflinger/reader/include/InputReaderContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <input/KeyboardClassifier.h>
2121
#include "NotifyArgs.h"
2222

23+
#include <string>
2324
#include <vector>
2425

2526
namespace android {
@@ -39,6 +40,8 @@ class InputReaderContext {
3940
InputReaderContext() {}
4041
virtual ~InputReaderContext() {}
4142

43+
virtual std::string dump() = 0;
44+
4245
virtual void updateGlobalMetaState() = 0;
4346
virtual int32_t getGlobalMetaState() = 0;
4447

services/inputflinger/reader/mapper/TouchInputMapper.cpp

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <cinttypes>
2525
#include <cmath>
2626
#include <cstddef>
27+
#include <sstream>
28+
#include <string>
2729
#include <tuple>
2830

2931
#include <math.h>
@@ -138,6 +140,40 @@ void RawPointerData::getCentroidOfTouchingPointers(float* outX, float* outY) con
138140
*outY = y;
139141
}
140142

143+
std::ostream& operator<<(std::ostream& out, const RawPointerData::Pointer& p) {
144+
out << "id=" << p.id << ", x=" << p.x << ", y=" << p.y << ", pressure=" << p.pressure
145+
<< ", touchMajor=" << p.touchMajor << ", touchMinor=" << p.touchMinor
146+
<< ", toolMajor=" << p.toolMajor << ", toolMinor=" << p.toolMinor
147+
<< ", orientation=" << p.orientation << ", tiltX=" << p.tiltX << ", tiltY=" << p.tiltY
148+
<< ", distance=" << p.distance << ", toolType=" << ftl::enum_string(p.toolType)
149+
<< ", isHovering=" << p.isHovering;
150+
return out;
151+
}
152+
153+
std::ostream& operator<<(std::ostream& out, const RawPointerData& data) {
154+
out << data.pointerCount << " pointers:\n";
155+
for (uint32_t i = 0; i < data.pointerCount; i++) {
156+
out << INDENT << "[" << i << "]: " << data.pointers[i] << std::endl;
157+
}
158+
out << "ID bits: hovering = 0x" << std::hex << std::setfill('0') << std::setw(8)
159+
<< data.hoveringIdBits.value << ", touching = 0x" << std::setfill('0') << std::setw(8)
160+
<< data.touchingIdBits.value << ", canceled = 0x" << std::setfill('0') << std::setw(8)
161+
<< data.canceledIdBits.value << std::dec;
162+
return out;
163+
}
164+
165+
// --- TouchInputMapper::RawState ---
166+
167+
std::ostream& operator<<(std::ostream& out, const TouchInputMapper::RawState& state) {
168+
out << "When: " << state.when << std::endl;
169+
out << "Read time: " << state.readTime << std::endl;
170+
out << "Button state: 0x" << std::setfill('0') << std::setw(8) << std::hex << state.buttonState
171+
<< std::dec << std::endl;
172+
out << "Raw pointer data:" << std::endl;
173+
out << addLinePrefix(streamableToString(state.rawPointerData), INDENT);
174+
return out;
175+
}
176+
141177
// --- TouchInputMapper ---
142178

143179
TouchInputMapper::TouchInputMapper(InputDeviceContext& deviceContext,
@@ -232,20 +268,8 @@ void TouchInputMapper::dump(std::string& dump) {
232268
dump += StringPrintf(INDENT4 "TiltYScale: %0.3f\n", mTiltYScale);
233269

234270
dump += StringPrintf(INDENT3 "Last Raw Button State: 0x%08x\n", mLastRawState.buttonState);
235-
dump += StringPrintf(INDENT3 "Last Raw Touch: pointerCount=%d\n",
236-
mLastRawState.rawPointerData.pointerCount);
237-
for (uint32_t i = 0; i < mLastRawState.rawPointerData.pointerCount; i++) {
238-
const RawPointerData::Pointer& pointer = mLastRawState.rawPointerData.pointers[i];
239-
dump += StringPrintf(INDENT4 "[%d]: id=%d, x=%d, y=%d, pressure=%d, "
240-
"touchMajor=%d, touchMinor=%d, toolMajor=%d, toolMinor=%d, "
241-
"orientation=%d, tiltX=%d, tiltY=%d, distance=%d, "
242-
"toolType=%s, isHovering=%s\n",
243-
i, pointer.id, pointer.x, pointer.y, pointer.pressure,
244-
pointer.touchMajor, pointer.touchMinor, pointer.toolMajor,
245-
pointer.toolMinor, pointer.orientation, pointer.tiltX, pointer.tiltY,
246-
pointer.distance, ftl::enum_string(pointer.toolType).c_str(),
247-
toString(pointer.isHovering));
248-
}
271+
dump += INDENT3 "Last Raw Touch:\n";
272+
dump += addLinePrefix(streamableToString(mLastRawState), INDENT4) + "\n";
249273

250274
dump += StringPrintf(INDENT3 "Last Cooked Button State: 0x%08x\n",
251275
mLastCookedState.buttonState);
@@ -1476,6 +1500,22 @@ std::list<NotifyArgs> TouchInputMapper::sync(nsecs_t when, nsecs_t readTime) {
14761500
last.rawPointerData.touchingIdBits.value, next.rawPointerData.touchingIdBits.value,
14771501
last.rawPointerData.hoveringIdBits.value, next.rawPointerData.hoveringIdBits.value,
14781502
next.rawPointerData.canceledIdBits.value);
1503+
if (debugRawEvents() && last.rawPointerData.pointerCount == 0 &&
1504+
next.rawPointerData.pointerCount == 1) {
1505+
// Dump a bunch of info to try to debug b/396796958.
1506+
// TODO(b/396796958): remove this debug dump.
1507+
ALOGD("pointerCount went from 0 to 1. last:\n%s",
1508+
addLinePrefix(streamableToString(last), INDENT).c_str());
1509+
ALOGD("next:\n%s", addLinePrefix(streamableToString(next), INDENT).c_str());
1510+
ALOGD("InputReader dump:");
1511+
// The dump is too long to simply add as a format parameter in one log message, so we have
1512+
// to split it by line and log them individually.
1513+
std::istringstream stream(mDeviceContext.getContext()->dump());
1514+
std::string line;
1515+
while (std::getline(stream, line, '\n')) {
1516+
ALOGD(INDENT "%s", line.c_str());
1517+
}
1518+
}
14791519

14801520
if (!next.rawPointerData.touchingIdBits.isEmpty() &&
14811521
!next.rawPointerData.hoveringIdBits.isEmpty() &&

services/inputflinger/reader/mapper/TouchInputMapper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ class TouchInputMapper : public InputMapper {
348348
inline void clear() { *this = RawState(); }
349349
};
350350

351+
friend std::ostream& operator<<(std::ostream& out, const RawState& state);
352+
351353
struct CookedState {
352354
// Cooked pointer sample data.
353355
CookedPointerData cookedPointerData{};

services/inputflinger/tests/InterfaceMocks.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ namespace android {
5050

5151
class MockInputReaderContext : public InputReaderContext {
5252
public:
53+
std::string dump() override { return "(dump from MockInputReaderContext)"; }
54+
5355
MOCK_METHOD(void, updateGlobalMetaState, (), (override));
5456
MOCK_METHOD(int32_t, getGlobalMetaState, (), (override));
5557

services/inputflinger/tests/fuzzers/MapperHelpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ class FuzzInputReaderContext : public InputReaderContext {
360360
std::shared_ptr<ThreadSafeFuzzedDataProvider> fdp)
361361
: mEventHub(eventHub), mPolicy(sp<FuzzInputReaderPolicy>::make(fdp)), mFdp(fdp) {}
362362
~FuzzInputReaderContext() {}
363+
std::string dump() { return "(dump from FuzzInputReaderContext)"; }
363364
void updateGlobalMetaState() override {}
364365
int32_t getGlobalMetaState() { return mFdp->ConsumeIntegral<int32_t>(); }
365366
void disableVirtualKeysUntil(nsecs_t time) override {}

0 commit comments

Comments
 (0)