summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2021-10-06 03:53:26 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2021-10-06 03:53:26 +0000
commitf168dbca4477d861856b0329d6f8f628fd789084 (patch)
treeb7bca4838e44905a48b8d9fc1302aa6239a0121f
parentfdbeeffcae37cb1c7bbb774a0f6a13ed741c7a7f (diff)
parentbf765136da983f8928e4c28fad3b9f3914774ebc (diff)
downloadpixel-f168dbca4477d861856b0329d6f8f628fd789084.tar.gz
Merge changes from topic "pollVibeStateWithTimeout" into sc-v2-dev
* changes: vibrator: cs40l26: add timeout for haptic pollVibeState vibrator: common: add timeout to pollStr() Revert "vibrator: cs40l26: remove pollVibeState for Haptic"
-rw-r--r--vibrator/common/HardwareBase.h16
-rw-r--r--vibrator/cs40l26/Hardware.h4
-rw-r--r--vibrator/cs40l26/Vibrator.cpp5
-rw-r--r--vibrator/cs40l26/Vibrator.h2
4 files changed, 21 insertions, 6 deletions
diff --git a/vibrator/common/HardwareBase.h b/vibrator/common/HardwareBase.h
index ce1541b9..214c0565 100644
--- a/vibrator/common/HardwareBase.h
+++ b/vibrator/common/HardwareBase.h
@@ -77,7 +77,7 @@ class HwApiBase {
template <typename T>
bool poll(const T &value, std::istream *stream);
template <typename T>
- bool pollStr(const T &value, std::istream *stream);
+ bool pollStr(const T &value, std::istream *stream, const int32_t timeout = -1);
template <typename T>
void record(const char *func, const T &value, const std::ios *stream);
@@ -171,7 +171,7 @@ bool HwApiBase::poll(const T &value, std::istream *stream) {
}
template <typename T>
-bool HwApiBase::pollStr(const T &value, std::istream *stream) {
+bool HwApiBase::pollStr(const T &value, std::istream *stream, const int32_t timeoutMs) {
ATRACE_NAME("HwApi::pollStr");
auto path = mPathPrefix + mNames[stream];
unique_fd fileFd{::open(path.c_str(), O_RDONLY)};
@@ -181,6 +181,12 @@ bool HwApiBase::pollStr(const T &value, std::istream *stream) {
};
T actual;
bool ret;
+ int epollRet;
+
+ if (timeoutMs < -1) {
+ ALOGE("Invalid polling timeout!");
+ return false;
+ }
if (epoll_ctl(epollFd, EPOLL_CTL_ADD, fileFd, &event)) {
ALOGE("Failed to poll string %s (%d): %s", mNames[stream].c_str(), errno, strerror(errno));
@@ -188,7 +194,11 @@ bool HwApiBase::pollStr(const T &value, std::istream *stream) {
}
while ((ret = getStr(&actual, stream)) && (actual != value)) {
- epoll_wait(epollFd, &event, 1, -1);
+ epollRet = epoll_wait(epollFd, &event, 1, timeoutMs);
+ if (epollRet <= 0) {
+ ALOGE("Polling error or timeout! (%d)", epollRet);
+ return false;
+ }
}
HWAPI_RECORD(value, stream);
diff --git a/vibrator/cs40l26/Hardware.h b/vibrator/cs40l26/Hardware.h
index f9577e00..9be96c8a 100644
--- a/vibrator/cs40l26/Hardware.h
+++ b/vibrator/cs40l26/Hardware.h
@@ -53,7 +53,9 @@ class HwApi : public Vibrator::HwApi, private HwApiBase {
bool setGpioFallScale(uint32_t value) override { return set(value, &mGpioFallScale); }
bool setGpioRiseIndex(uint32_t value) override { return set(value, &mGpioRiseIndex); }
bool setGpioRiseScale(uint32_t value) override { return set(value, &mGpioRiseScale); }
- bool pollVibeState(std::string value) override { return pollStr(value, &mVibeState); }
+ bool pollVibeState(std::string value, int32_t timeoutMs) override {
+ return pollStr(value, &mVibeState, timeoutMs);
+ }
bool setClabEnable(bool value) override { return set(value, &mClabEnable); }
bool getAvailablePwleSegments(uint32_t *value) override {
return getStr(value, &mAvailablePwleSegments);
diff --git a/vibrator/cs40l26/Vibrator.cpp b/vibrator/cs40l26/Vibrator.cpp
index 4d59ee98..17224669 100644
--- a/vibrator/cs40l26/Vibrator.cpp
+++ b/vibrator/cs40l26/Vibrator.cpp
@@ -60,7 +60,7 @@ static constexpr int8_t MAX_PAUSE_TIMING_ERROR_MS = 1; // ALERT Irq Handling
static constexpr uint32_t MAX_TIME_MS = UINT16_MAX;
static constexpr auto ASYNC_COMPLETION_TIMEOUT = std::chrono::milliseconds(100);
-
+static constexpr auto POLLING_TIMEOUT = 20;
static constexpr int32_t COMPOSE_DELAY_MAX_MS = 10000;
/* Preserve 1 section for the first delay before the first effect. */
@@ -1276,6 +1276,9 @@ ndk::ScopedAStatus Vibrator::performEffect(uint32_t effectIndex, uint32_t volLev
}
void Vibrator::waitForComplete(std::shared_ptr<IVibratorCallback> &&callback) {
+ if (!mHwApi->pollVibeState("Vibe state: Haptic\n", POLLING_TIMEOUT)) {
+ ALOGE("Fail to get state \"Haptic\"");
+ }
mHwApi->pollVibeState("Vibe state: Stopped\n");
if (callback) {
diff --git a/vibrator/cs40l26/Vibrator.h b/vibrator/cs40l26/Vibrator.h
index a6fd6741..27459c95 100644
--- a/vibrator/cs40l26/Vibrator.h
+++ b/vibrator/cs40l26/Vibrator.h
@@ -93,7 +93,7 @@ class Vibrator : public BnVibrator {
// Blocks until vibrator reaches desired state
// ("Vibe state: Haptic" means enabled).
// ("Vibe state: Stopped" means disabled).
- virtual bool pollVibeState(std::string value) = 0;
+ virtual bool pollVibeState(std::string value, int32_t timeoutMs = -1) = 0;
// Enables/disables closed-loop active braking.
virtual bool setClabEnable(bool value) = 0;
// Reports the number of available PWLE segments.