Add toString and remove default case
For a future CL, we will need to print some bools. To facilitate that,
add a "toString" function.
Also, if we add a focus type, it would be good that the compiler
highlights cases where the new type isn't being handled in a switch
statement. Therefore, remove all default cases in switch statements
where feasible.
Because we are now adding an "unused" function that compiler complains
about, also convert DEBUG_TRANSPORT_ACTIONS into a constexpr bool.
Bug: none
Test: presubmit
Change-Id: Ie8472707f1699d2009232b9f36abae9a36a97f5f
diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp
index a5dd3c0..8d1dd63 100644
--- a/libs/input/InputTransport.cpp
+++ b/libs/input/InputTransport.cpp
@@ -14,7 +14,7 @@
static constexpr bool DEBUG_CHANNEL_LIFECYCLE = false;
// Log debug messages about transport actions
-#define DEBUG_TRANSPORT_ACTIONS 0
+static constexpr bool DEBUG_TRANSPORT_ACTIONS = false;
// Log debug messages about touch event resampling
#define DEBUG_RESAMPLING 0
@@ -88,6 +88,10 @@
return (source & AINPUT_SOURCE_CLASS_POINTER) == AINPUT_SOURCE_CLASS_POINTER;
}
+inline static const char* toString(bool value) {
+ return value ? "true" : "false";
+}
+
// --- InputMessage ---
bool InputMessage::isValid(size_t actualSize) const {
@@ -216,10 +220,6 @@
msg->body.finished.handled = body.finished.handled;
break;
}
- default: {
- LOG_FATAL("Unexpected message type %i", header.type);
- break;
- }
}
}
@@ -432,14 +432,13 @@
mChannel->getName().c_str(), keyCode);
ATRACE_NAME(message.c_str());
}
-#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=%" PRId64 ", eventTime=%" PRId64,
- mChannel->getName().c_str(), seq,
- deviceId, source, action, flags, keyCode, scanCode, metaState, repeatCount,
- downTime, eventTime);
-#endif
+ 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=%" PRId64 ", eventTime=%" PRId64,
+ mChannel->getName().c_str(), seq, deviceId, source, action, flags, keyCode, scanCode,
+ metaState, repeatCount, downTime, eventTime);
+ }
if (!seq) {
ALOGE("Attempted to publish a key event with sequence number 0.");
@@ -476,18 +475,18 @@
mChannel->getName().c_str(), action);
ATRACE_NAME(message.c_str());
}
-#if DEBUG_TRANSPORT_ACTIONS
- ALOGD("channel '%s' publisher ~ publishMotionEvent: seq=%u, deviceId=%d, source=0x%x, "
- "displayId=%" PRId32 ", "
- "action=0x%x, actionButton=0x%08x, flags=0x%x, edgeFlags=0x%x, "
- "metaState=0x%x, buttonState=0x%x, classification=%s, xOffset=%f, yOffset=%f, "
- "xPrecision=%f, yPrecision=%f, downTime=%" PRId64 ", eventTime=%" PRId64 ", "
- "pointerCount=%" PRIu32,
- mChannel->getName().c_str(), seq,
- deviceId, source, displayId, action, actionButton, flags, edgeFlags, metaState,
- buttonState, motionClassificationToString(classification),
- xOffset, yOffset, xPrecision, yPrecision, downTime, eventTime, pointerCount);
-#endif
+ if (DEBUG_TRANSPORT_ACTIONS) {
+ ALOGD("channel '%s' publisher ~ publishMotionEvent: seq=%u, deviceId=%d, source=0x%x, "
+ "displayId=%" PRId32 ", "
+ "action=0x%x, actionButton=0x%08x, flags=0x%x, edgeFlags=0x%x, "
+ "metaState=0x%x, buttonState=0x%x, classification=%s, xOffset=%f, yOffset=%f, "
+ "xPrecision=%f, yPrecision=%f, downTime=%" PRId64 ", eventTime=%" PRId64 ", "
+ "pointerCount=%" PRIu32,
+ mChannel->getName().c_str(), seq, deviceId, source, displayId, action, actionButton,
+ flags, edgeFlags, metaState, buttonState,
+ motionClassificationToString(classification), xOffset, yOffset, xPrecision,
+ yPrecision, downTime, eventTime, pointerCount);
+ }
if (!seq) {
ALOGE("Attempted to publish a motion event with sequence number 0.");
@@ -531,10 +530,9 @@
}
status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandled) {
-#if DEBUG_TRANSPORT_ACTIONS
- ALOGD("channel '%s' publisher ~ receiveFinishedSignal",
- mChannel->getName().c_str());
-#endif
+ if (DEBUG_TRANSPORT_ACTIONS) {
+ ALOGD("channel '%s' publisher ~ receiveFinishedSignal", mChannel->getName().c_str());
+ }
InputMessage msg;
status_t result = mChannel->receiveMessage(&msg);
@@ -569,10 +567,10 @@
status_t InputConsumer::consume(InputEventFactoryInterface* factory,
bool consumeBatches, nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent) {
-#if DEBUG_TRANSPORT_ACTIONS
- ALOGD("channel '%s' consumer ~ consume: consumeBatches=%s, frameTime=%" PRId64,
- mChannel->getName().c_str(), consumeBatches ? "true" : "false", frameTime);
-#endif
+ if (DEBUG_TRANSPORT_ACTIONS) {
+ ALOGD("channel '%s' consumer ~ consume: consumeBatches=%s, frameTime=%" PRId64,
+ mChannel->getName().c_str(), toString(consumeBatches), frameTime);
+ }
*outSeq = 0;
*outEvent = nullptr;
@@ -592,10 +590,10 @@
if (consumeBatches || result != WOULD_BLOCK) {
result = consumeBatch(factory, frameTime, outSeq, outEvent);
if (*outEvent) {
-#if DEBUG_TRANSPORT_ACTIONS
- ALOGD("channel '%s' consumer ~ consumed batch event, seq=%u",
- mChannel->getName().c_str(), *outSeq);
-#endif
+ if (DEBUG_TRANSPORT_ACTIONS) {
+ ALOGD("channel '%s' consumer ~ consumed batch event, seq=%u",
+ mChannel->getName().c_str(), *outSeq);
+ }
break;
}
}
@@ -611,10 +609,10 @@
initializeKeyEvent(keyEvent, &mMsg);
*outSeq = mMsg.body.key.seq;
*outEvent = keyEvent;
-#if DEBUG_TRANSPORT_ACTIONS
- ALOGD("channel '%s' consumer ~ consumed key event, seq=%u",
- mChannel->getName().c_str(), *outSeq);
-#endif
+ if (DEBUG_TRANSPORT_ACTIONS) {
+ ALOGD("channel '%s' consumer ~ consumed key event, seq=%u",
+ mChannel->getName().c_str(), *outSeq);
+ }
break;
}
@@ -624,10 +622,10 @@
Batch& batch = mBatches.editItemAt(batchIndex);
if (canAddSample(batch, &mMsg)) {
batch.samples.push(mMsg);
-#if DEBUG_TRANSPORT_ACTIONS
- ALOGD("channel '%s' consumer ~ appended to batch event",
- mChannel->getName().c_str());
-#endif
+ if (DEBUG_TRANSPORT_ACTIONS) {
+ ALOGD("channel '%s' consumer ~ appended to batch event",
+ mChannel->getName().c_str());
+ }
break;
} else if (isPointerEvent(mMsg.body.motion.source) &&
mMsg.body.motion.action == AMOTION_EVENT_ACTION_CANCEL) {
@@ -649,27 +647,27 @@
if (result) {
return result;
}
-#if DEBUG_TRANSPORT_ACTIONS
- ALOGD("channel '%s' consumer ~ consumed batch event and "
- "deferred current event, seq=%u",
- mChannel->getName().c_str(), *outSeq);
-#endif
+ if (DEBUG_TRANSPORT_ACTIONS) {
+ ALOGD("channel '%s' consumer ~ consumed batch event and "
+ "deferred current event, seq=%u",
+ mChannel->getName().c_str(), *outSeq);
+ }
break;
}
}
- // Start a new batch if needed.
- if (mMsg.body.motion.action == AMOTION_EVENT_ACTION_MOVE
- || mMsg.body.motion.action == AMOTION_EVENT_ACTION_HOVER_MOVE) {
- mBatches.push();
- Batch& batch = mBatches.editTop();
- batch.samples.push(mMsg);
-#if DEBUG_TRANSPORT_ACTIONS
- ALOGD("channel '%s' consumer ~ started batch event",
- mChannel->getName().c_str());
-#endif
- break;
- }
+ // Start a new batch if needed.
+ if (mMsg.body.motion.action == AMOTION_EVENT_ACTION_MOVE ||
+ mMsg.body.motion.action == AMOTION_EVENT_ACTION_HOVER_MOVE) {
+ mBatches.push();
+ Batch& batch = mBatches.editTop();
+ batch.samples.push(mMsg);
+ if (DEBUG_TRANSPORT_ACTIONS) {
+ ALOGD("channel '%s' consumer ~ started batch event",
+ mChannel->getName().c_str());
+ }
+ break;
+ }
MotionEvent* motionEvent = factory->createMotionEvent();
if (! motionEvent) return NO_MEMORY;
@@ -679,17 +677,18 @@
*outSeq = mMsg.body.motion.seq;
*outEvent = motionEvent;
-#if DEBUG_TRANSPORT_ACTIONS
- ALOGD("channel '%s' consumer ~ consumed motion event, seq=%u",
- mChannel->getName().c_str(), *outSeq);
-#endif
+ if (DEBUG_TRANSPORT_ACTIONS) {
+ ALOGD("channel '%s' consumer ~ consumed motion event, seq=%u",
+ mChannel->getName().c_str(), *outSeq);
+ }
break;
}
- default:
- ALOGE("channel '%s' consumer ~ Received unexpected message of type %d",
- mChannel->getName().c_str(), mMsg.header.type);
- return UNKNOWN_ERROR;
+ case InputMessage::Type::FINISHED: {
+ LOG_ALWAYS_FATAL("Consumed a FINISHED message, which should never be seen by "
+ "InputConsumer!");
+ break;
+ }
}
}
return OK;
@@ -1014,10 +1013,10 @@
}
status_t InputConsumer::sendFinishedSignal(uint32_t seq, bool handled) {
-#if DEBUG_TRANSPORT_ACTIONS
- ALOGD("channel '%s' consumer ~ sendFinishedSignal: seq=%u, handled=%s",
- mChannel->getName().c_str(), seq, handled ? "true" : "false");
-#endif
+ if (DEBUG_TRANSPORT_ACTIONS) {
+ ALOGD("channel '%s' consumer ~ sendFinishedSignal: seq=%u, handled=%s",
+ mChannel->getName().c_str(), seq, toString(handled));
+ }
if (!seq) {
ALOGE("Attempted to send a finished signal with sequence number 0.");
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index c219941..aba5a30 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -2295,10 +2295,12 @@
reportTouchEventForStatistics(*motionEntry);
break;
}
-
- default:
- ALOG_ASSERT(false);
+ case EventEntry::Type::CONFIGURATION_CHANGED:
+ case EventEntry::Type::DEVICE_RESET: {
+ LOG_ALWAYS_FATAL("Should never start dispatch cycles for %s events",
+ EventEntry::typeToString(eventEntry->type));
return;
+ }
}
// Check the result.