Use bool directly in InputMessage
In order to send the data via socket, we use the InputMessage struct. In
this struct, various fields are stored. This struct's purpose is to
serialize the input event information.
We are storing bools in InputMessage as various integer types. To read
these bools, we compare the integers to 1. It's not very convenient.
To simplify this, let's store bools directly in InputMessage. Bool size
is implementation-dependent, but it's typically 1, so we can just guard
against that with a static_assert.
Bug: 169866723
Test: presubmit
Change-Id: Iae4870fac95e884cc328791c0035df6e31e34a7b
diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp
index 1e47a3c..ee2daec 100644
--- a/libs/input/InputTransport.cpp
+++ b/libs/input/InputTransport.cpp
@@ -577,8 +577,8 @@
msg.header.type = InputMessage::Type::FOCUS;
msg.header.seq = seq;
msg.body.focus.eventId = eventId;
- msg.body.focus.hasFocus = hasFocus ? 1 : 0;
- msg.body.focus.inTouchMode = inTouchMode ? 1 : 0;
+ msg.body.focus.hasFocus = hasFocus;
+ msg.body.focus.inTouchMode = inTouchMode;
return mChannel->sendMessage(&msg);
}
@@ -595,7 +595,7 @@
msg.header.type = InputMessage::Type::CAPTURE;
msg.header.seq = seq;
msg.body.capture.eventId = eventId;
- msg.body.capture.pointerCaptureEnabled = pointerCaptureEnabled ? 1 : 0;
+ msg.body.capture.pointerCaptureEnabled = pointerCaptureEnabled;
return mChannel->sendMessage(&msg);
}
@@ -615,7 +615,7 @@
mChannel->getName().c_str(), NamedEnum::string(msg.header.type).c_str());
return UNKNOWN_ERROR;
}
- callback(msg.header.seq, msg.body.finished.handled == 1, msg.body.finished.consumeTime);
+ callback(msg.header.seq, msg.body.finished.handled, msg.body.finished.consumeTime);
return OK;
}
@@ -1168,7 +1168,7 @@
InputMessage msg;
msg.header.type = InputMessage::Type::FINISHED;
msg.header.seq = seq;
- msg.body.finished.handled = handled ? 1 : 0;
+ msg.body.finished.handled = handled;
msg.body.finished.consumeTime = getConsumeTime(seq);
status_t result = mChannel->sendMessage(&msg);
if (result == OK) {
@@ -1228,12 +1228,12 @@
}
void InputConsumer::initializeFocusEvent(FocusEvent* event, const InputMessage* msg) {
- event->initialize(msg->body.focus.eventId, msg->body.focus.hasFocus == 1,
- msg->body.focus.inTouchMode == 1);
+ event->initialize(msg->body.focus.eventId, msg->body.focus.hasFocus,
+ msg->body.focus.inTouchMode);
}
void InputConsumer::initializeCaptureEvent(CaptureEvent* event, const InputMessage* msg) {
- event->initialize(msg->body.capture.eventId, msg->body.capture.pointerCaptureEnabled == 1);
+ event->initialize(msg->body.capture.eventId, msg->body.capture.pointerCaptureEnabled);
}
void InputConsumer::initializeMotionEvent(MotionEvent* event, const InputMessage* msg) {