diff options
| -rw-r--r-- | cmds/dumpstate/dumpstate.cpp | 6 | ||||
| -rw-r--r-- | cmds/lshal/PipeRelay.cpp | 58 | ||||
| -rw-r--r-- | libs/input/tests/Android.bp | 1 | ||||
| -rw-r--r-- | services/inputflinger/tests/Android.bp | 1 |
4 files changed, 59 insertions, 7 deletions
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 240fb74f42..f574b038d2 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -1431,6 +1431,12 @@ static void DumpstateTelephonyOnly() { DUMPSYS_COMPONENTS_OPTIONS); printf("========================================================\n"); + printf("== Checkins\n"); + printf("========================================================\n"); + + RunDumpsys("CHECKIN BATTERYSTATS", {"batterystats", "-c"}); + + printf("========================================================\n"); printf("== dumpstate: done (id %d)\n", ds.id_); printf("========================================================\n"); } diff --git a/cmds/lshal/PipeRelay.cpp b/cmds/lshal/PipeRelay.cpp index 3a17e03050..820679fbe2 100644 --- a/cmds/lshal/PipeRelay.cpp +++ b/cmds/lshal/PipeRelay.cpp @@ -16,33 +16,75 @@ #include "PipeRelay.h" +#include <sys/select.h> +#include <sys/time.h> +#include <sys/types.h> +#include <unistd.h> + +#include <atomic> + +#include <android-base/logging.h> #include <utils/Thread.h> namespace android { namespace lshal { +static constexpr struct timeval READ_TIMEOUT { .tv_sec = 1, .tv_usec = 0 }; + struct PipeRelay::RelayThread : public Thread { explicit RelayThread(int fd, std::ostream &os); bool threadLoop() override; + void setFinished(); private: int mFd; std::ostream &mOutStream; + // If we were to use requestExit() and exitPending() instead, threadLoop() + // may not run at all by the time ~PipeRelay is called (i.e. debug() has + // returned from HAL). By using our own flag, we ensure that select() and + // read() are executed until data are drained. + std::atomic_bool mFinished; + DISALLOW_COPY_AND_ASSIGN(RelayThread); }; //////////////////////////////////////////////////////////////////////////////// PipeRelay::RelayThread::RelayThread(int fd, std::ostream &os) - : mFd(fd), - mOutStream(os) { -} + : mFd(fd), mOutStream(os), mFinished(false) {} bool PipeRelay::RelayThread::threadLoop() { char buffer[1024]; - ssize_t n = read(mFd, buffer, sizeof(buffer)); + + fd_set set; + FD_ZERO(&set); + FD_SET(mFd, &set); + + struct timeval timeout = READ_TIMEOUT; + + int res = TEMP_FAILURE_RETRY(select(mFd + 1, &set, nullptr, nullptr, &timeout)); + if (res < 0) { + PLOG(INFO) << "select() failed"; + return false; + } + + if (res == 0 || !FD_ISSET(mFd, &set)) { + if (mFinished) { + LOG(WARNING) << "debug: timeout reading from pipe, output may be truncated."; + return false; + } + // timeout, but debug() has not returned, so wait for HAL to finish. + return true; + } + + // FD_ISSET(mFd, &set) == true. Data available, start reading + ssize_t n = TEMP_FAILURE_RETRY(read(mFd, buffer, sizeof(buffer))); + + if (n < 0) { + PLOG(ERROR) << "read() failed"; + } if (n <= 0) { return false; @@ -53,6 +95,10 @@ bool PipeRelay::RelayThread::threadLoop() { return true; } +void PipeRelay::RelayThread::setFinished() { + mFinished = true; +} + //////////////////////////////////////////////////////////////////////////////// PipeRelay::PipeRelay(std::ostream &os) @@ -77,12 +123,14 @@ void PipeRelay::CloseFd(int *fd) { PipeRelay::~PipeRelay() { CloseFd(&mFds[1]); - CloseFd(&mFds[0]); if (mThread != nullptr) { + mThread->setFinished(); mThread->join(); mThread.clear(); } + + CloseFd(&mFds[0]); } status_t PipeRelay::initCheck() const { diff --git a/libs/input/tests/Android.bp b/libs/input/tests/Android.bp index aca9521c76..f06119f3f7 100644 --- a/libs/input/tests/Android.bp +++ b/libs/input/tests/Android.bp @@ -1,7 +1,6 @@ // Build the unit tests. cc_test { name: "libinput_tests", - test_per_src: true, srcs: [ "InputChannel_test.cpp", "InputEvent_test.cpp", diff --git a/services/inputflinger/tests/Android.bp b/services/inputflinger/tests/Android.bp index dd19800057..afaf139d37 100644 --- a/services/inputflinger/tests/Android.bp +++ b/services/inputflinger/tests/Android.bp @@ -6,7 +6,6 @@ cc_test { "InputReader_test.cpp", "InputDispatcher_test.cpp", ], - test_per_src: true, cflags: [ "-Wall", "-Werror", |