summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2022-10-18 21:52:41 -0700
committer Colin Cross <ccross@android.com> 2022-10-18 21:52:41 -0700
commit5b79930750cdfd7c9aa09f95fdfe3fa9ecc34768 (patch)
treeb9404b0cc41ab67d3b9ecb49b95ce9852a334664
parent22c43f5828ea5b995f699f13246ed323539e9575 (diff)
Make inputflinger_tests compile for musl
inputflinger_tests compile for the host now, so they need to be compatible with musl libc. Use LLONG_MIN and LLONG_MAX instead of the nonstandard LONG_LONG_MIN and LONG_LONG_MAX. Use input_event_sec and input_event_usec to intialize time fields in struct input_event, they are not always stored in a struct timespec. Include linux/ioctl.h to define _IOC_SIZE. Cast tv_sec and tv_usec to long long, as the type can be any integer type. Cast EPOLLIN to compare with epoll_event.events, it is not unsigned in musl. Include transitive dependencies of static libraries that are not needed by the linker when CFI is enabled, but are detected as errors when CFI is not enabled. Bug: 190084016 Test: m USE_HOST_MUSL=true inputflinger_tests Change-Id: I625bb612d5a8816ec5d1ade6d3a887981a549569
-rw-r--r--services/inputflinger/Android.bp1
-rw-r--r--services/inputflinger/dispatcher/AnrTracker.cpp2
-rw-r--r--services/inputflinger/dispatcher/AnrTracker.h2
-rw-r--r--services/inputflinger/dispatcher/InputDispatcher.cpp22
-rw-r--r--services/inputflinger/reader/Android.bp1
-rw-r--r--services/inputflinger/reader/EventHub.cpp17
-rw-r--r--services/inputflinger/reader/TouchVideoDevice.cpp5
-rw-r--r--services/inputflinger/tests/AnrTracker_test.cpp2
-rw-r--r--services/inputflinger/tests/InputDispatcher_test.cpp2
-rw-r--r--services/inputflinger/tests/UinputDevice.cpp2
10 files changed, 30 insertions, 26 deletions
diff --git a/services/inputflinger/Android.bp b/services/inputflinger/Android.bp
index 4dcbba2c43..d1de551799 100644
--- a/services/inputflinger/Android.bp
+++ b/services/inputflinger/Android.bp
@@ -182,6 +182,7 @@ cc_defaults {
host: {
static_libs: [
"libinput",
+ "libui-types",
],
},
},
diff --git a/services/inputflinger/dispatcher/AnrTracker.cpp b/services/inputflinger/dispatcher/AnrTracker.cpp
index c3f611e7db..a18063f299 100644
--- a/services/inputflinger/dispatcher/AnrTracker.cpp
+++ b/services/inputflinger/dispatcher/AnrTracker.cpp
@@ -54,7 +54,7 @@ bool AnrTracker::empty() const {
}
// If empty() is false, return the time at which the next connection should cause an ANR
-// If empty() is true, return LONG_LONG_MAX
+// If empty() is true, return LLONG_MAX
nsecs_t AnrTracker::firstTimeout() const {
if (mAnrTimeouts.empty()) {
return std::numeric_limits<nsecs_t>::max();
diff --git a/services/inputflinger/dispatcher/AnrTracker.h b/services/inputflinger/dispatcher/AnrTracker.h
index 5e5e0c4bae..cff5d00e4b 100644
--- a/services/inputflinger/dispatcher/AnrTracker.h
+++ b/services/inputflinger/dispatcher/AnrTracker.h
@@ -35,7 +35,7 @@ public:
bool empty() const;
// If empty() is false, return the time at which the next connection should cause an ANR
- // If empty() is true, return LONG_LONG_MAX
+ // If empty() is true, return LLONG_MAX
nsecs_t firstTimeout() const;
// Return the token of the next connection that should cause an ANR.
// Do not call this unless empty() is false, you will encounter undefined behaviour.
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 5587a8f5d0..84c18fd74b 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -555,7 +555,7 @@ InputDispatcher::InputDispatcher(const sp<InputDispatcherPolicyInterface>& polic
mLastDropReason(DropReason::NOT_DROPPED),
mIdGenerator(IdGenerator::Source::INPUT_DISPATCHER),
mAppSwitchSawKeyDown(false),
- mAppSwitchDueTime(LONG_LONG_MAX),
+ mAppSwitchDueTime(LLONG_MAX),
mNextUnblockedEvent(nullptr),
mMonitorDispatchingTimeout(DEFAULT_INPUT_DISPATCHING_TIMEOUT),
mDispatchEnabled(false),
@@ -612,7 +612,7 @@ status_t InputDispatcher::stop() {
}
void InputDispatcher::dispatchOnce() {
- nsecs_t nextWakeupTime = LONG_LONG_MAX;
+ nsecs_t nextWakeupTime = LLONG_MAX;
{ // acquire lock
std::scoped_lock _l(mLock);
mDispatcherIsAlive.notify_all();
@@ -626,7 +626,7 @@ void InputDispatcher::dispatchOnce() {
// Run all pending commands if there are any.
// If any commands were run then force the next poll to wake up immediately.
if (runCommandsLockedInterruptable()) {
- nextWakeupTime = LONG_LONG_MIN;
+ nextWakeupTime = LLONG_MIN;
}
// If we are still waiting for ack on some events,
@@ -636,7 +636,7 @@ void InputDispatcher::dispatchOnce() {
// We are about to enter an infinitely long sleep, because we have no commands or
// pending or queued events
- if (nextWakeupTime == LONG_LONG_MAX) {
+ if (nextWakeupTime == LLONG_MAX) {
mDispatcherEnteredIdle.notify_all();
}
} // release lock
@@ -681,14 +681,14 @@ void InputDispatcher::processNoFocusedWindowAnrLocked() {
*/
nsecs_t InputDispatcher::processAnrsLocked() {
const nsecs_t currentTime = now();
- nsecs_t nextAnrCheck = LONG_LONG_MAX;
+ nsecs_t nextAnrCheck = LLONG_MAX;
// Check if we are waiting for a focused window to appear. Raise ANR if waited too long
if (mNoFocusedWindowTimeoutTime.has_value() && mAwaitedFocusedApplication != nullptr) {
if (currentTime >= *mNoFocusedWindowTimeoutTime) {
processNoFocusedWindowAnrLocked();
mAwaitedFocusedApplication.reset();
mNoFocusedWindowTimeoutTime = std::nullopt;
- return LONG_LONG_MIN;
+ return LLONG_MIN;
} else {
// Keep waiting. We will drop the event when mNoFocusedWindowTimeoutTime comes.
nextAnrCheck = *mNoFocusedWindowTimeoutTime;
@@ -711,7 +711,7 @@ nsecs_t InputDispatcher::processAnrsLocked() {
// Stop waking up for this unresponsive connection
mAnrTracker.eraseToken(connection->inputChannel->getConnectionToken());
onAnrLocked(connection);
- return LONG_LONG_MIN;
+ return LLONG_MIN;
}
std::chrono::nanoseconds InputDispatcher::getDispatchingTimeoutLocked(
@@ -918,7 +918,7 @@ void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) {
mLastDropReason = dropReason;
releasePendingEventLocked();
- *nextWakeupTime = LONG_LONG_MIN; // force next poll to wake up immediately
+ *nextWakeupTime = LLONG_MIN; // force next poll to wake up immediately
}
}
@@ -1201,11 +1201,11 @@ bool InputDispatcher::isAppSwitchKeyEvent(const KeyEntry& keyEntry) {
}
bool InputDispatcher::isAppSwitchPendingLocked() {
- return mAppSwitchDueTime != LONG_LONG_MAX;
+ return mAppSwitchDueTime != LLONG_MAX;
}
void InputDispatcher::resetPendingAppSwitchLocked(bool handled) {
- mAppSwitchDueTime = LONG_LONG_MAX;
+ mAppSwitchDueTime = LLONG_MAX;
if (DEBUG_APP_SWITCH) {
if (handled) {
@@ -1498,7 +1498,7 @@ bool InputDispatcher::dispatchKeyLocked(nsecs_t currentTime, std::shared_ptr<Key
// stop the key repeat on current device.
entry->repeatCount = mKeyRepeatState.lastKeyEntry->repeatCount + 1;
resetKeyRepeatLocked();
- mKeyRepeatState.nextRepeatTime = LONG_LONG_MAX; // don't generate repeats ourselves
+ mKeyRepeatState.nextRepeatTime = LLONG_MAX; // don't generate repeats ourselves
} else {
// Not a repeat. Save key down state in case we do see a repeat later.
resetKeyRepeatLocked();
diff --git a/services/inputflinger/reader/Android.bp b/services/inputflinger/reader/Android.bp
index 43259c0c5f..c5e1f0ca94 100644
--- a/services/inputflinger/reader/Android.bp
+++ b/services/inputflinger/reader/Android.bp
@@ -89,6 +89,7 @@ cc_defaults {
host: {
static_libs: [
"libinput",
+ "libbinder",
],
},
},
diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp
index 956746d7d2..b97c46613b 100644
--- a/services/inputflinger/reader/EventHub.cpp
+++ b/services/inputflinger/reader/EventHub.cpp
@@ -19,6 +19,7 @@
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
+#include <linux/ioctl.h>
#include <memory.h>
#include <stdint.h>
#include <stdio.h>
@@ -191,8 +192,8 @@ static nsecs_t processEventTimestamp(const struct input_event& event) {
// calls clock_gettime(CLOCK_MONOTONIC) which is implemented as a
// system call that also queries ktime_get_ts().
- const nsecs_t inputEventTime = seconds_to_nanoseconds(event.time.tv_sec) +
- microseconds_to_nanoseconds(event.time.tv_usec);
+ const nsecs_t inputEventTime = seconds_to_nanoseconds(event.input_event_sec) +
+ microseconds_to_nanoseconds(event.input_event_usec);
return inputEventTime;
}
@@ -632,8 +633,8 @@ void EventHub::Device::setLedStateLocked(int32_t led, bool on) {
int32_t sc;
if (hasValidFd() && mapLed(led, &sc) != NAME_NOT_FOUND) {
struct input_event ev;
- ev.time.tv_sec = 0;
- ev.time.tv_usec = 0;
+ ev.input_event_sec = 0;
+ ev.input_event_usec = 0;
ev.type = EV_LED;
ev.code = sc;
ev.value = on ? 1 : 0;
@@ -1462,8 +1463,8 @@ void EventHub::vibrate(int32_t deviceId, const VibrationElement& element) {
device->ffEffectId = effect.id;
struct input_event ev;
- ev.time.tv_sec = 0;
- ev.time.tv_usec = 0;
+ ev.input_event_sec = 0;
+ ev.input_event_usec = 0;
ev.type = EV_FF;
ev.code = device->ffEffectId;
ev.value = 1;
@@ -1484,8 +1485,8 @@ void EventHub::cancelVibrate(int32_t deviceId) {
device->ffEffectPlaying = false;
struct input_event ev;
- ev.time.tv_sec = 0;
- ev.time.tv_usec = 0;
+ ev.input_event_sec = 0;
+ ev.input_event_usec = 0;
ev.type = EV_FF;
ev.code = device->ffEffectId;
ev.value = 0;
diff --git a/services/inputflinger/reader/TouchVideoDevice.cpp b/services/inputflinger/reader/TouchVideoDevice.cpp
index 2f8138b832..627dcba9cf 100644
--- a/services/inputflinger/reader/TouchVideoDevice.cpp
+++ b/services/inputflinger/reader/TouchVideoDevice.cpp
@@ -198,8 +198,9 @@ std::optional<TouchVideoFrame> TouchVideoDevice::readFrame() {
if ((buf.flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) != V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC) {
// We use CLOCK_MONOTONIC for input events, so if the clocks don't match,
// we can't compare timestamps. Just log a warning, since this is a driver issue
- ALOGW("The timestamp %ld.%ld was not acquired using CLOCK_MONOTONIC", buf.timestamp.tv_sec,
- buf.timestamp.tv_usec);
+ ALOGW("The timestamp %lld.%lld was not acquired using CLOCK_MONOTONIC",
+ static_cast<long long>(buf.timestamp.tv_sec),
+ static_cast<long long>(buf.timestamp.tv_usec));
}
std::vector<int16_t> data(mHeight * mWidth);
const int16_t* readFrom = mReadLocations[buf.index];
diff --git a/services/inputflinger/tests/AnrTracker_test.cpp b/services/inputflinger/tests/AnrTracker_test.cpp
index f8be48af25..25adeea48f 100644
--- a/services/inputflinger/tests/AnrTracker_test.cpp
+++ b/services/inputflinger/tests/AnrTracker_test.cpp
@@ -137,7 +137,7 @@ TEST(AnrTrackerTest, Empty_DoesntCrash) {
ASSERT_TRUE(tracker.empty());
- ASSERT_EQ(LONG_LONG_MAX, tracker.firstTimeout());
+ ASSERT_EQ(LLONG_MAX, tracker.firstTimeout());
// Can't call firstToken() if tracker.empty()
}
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index a1ccfc7d16..aaf50ce5ed 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -7027,7 +7027,7 @@ TEST_F(InputDispatcherSpyWindowTest, ReceivesInputInOrder) {
break; // epoll_wait timed out
}
for (int i = 0; i < nFds; i++) {
- ASSERT_EQ(EPOLLIN, events[i].events);
+ ASSERT_EQ(static_cast<uint32_t>(EPOLLIN), events[i].events);
eventOrder.push_back(static_cast<size_t>(events[i].data.u64));
channels[i]->consumeMotionDown();
}
diff --git a/services/inputflinger/tests/UinputDevice.cpp b/services/inputflinger/tests/UinputDevice.cpp
index 7862b5839c..a23c873656 100644
--- a/services/inputflinger/tests/UinputDevice.cpp
+++ b/services/inputflinger/tests/UinputDevice.cpp
@@ -59,11 +59,11 @@ void UinputDevice::init() {
}
void UinputDevice::injectEvent(uint16_t type, uint16_t code, int32_t value) {
+ // uinput ignores the timestamp
struct input_event event = {};
event.type = type;
event.code = code;
event.value = value;
- event.time = {}; // uinput ignores the timestamp
if (write(mDeviceFd, &event, sizeof(input_event)) < 0) {
std::string msg = base::StringPrintf("Could not write event %" PRIu16 " %" PRIu16