From a9cb65d25cfa802a5084c9f926fd6699ff068a11 Mon Sep 17 00:00:00 2001 From: Jie Song Date: Thu, 15 Jun 2017 16:31:38 -0700 Subject: [PATCH] Write modem log to the 2nd fd from dumpstate Bug: 33820081 Test: Verify modem logs from bugreport Change-Id: I0cd0ce8c1a4b2cc3e8a2eeda65b0aa8e1a983fd1 --- dumpstate/DumpstateDevice.cpp | 41 +++++++++++++++++++++++++++++------ dumpstate/DumpstateDevice.h | 2 ++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/dumpstate/DumpstateDevice.cpp b/dumpstate/DumpstateDevice.cpp index 4cfecac9..5340108f 100755 --- a/dumpstate/DumpstateDevice.cpp +++ b/dumpstate/DumpstateDevice.cpp @@ -19,6 +19,7 @@ #include "DumpstateDevice.h" #include +#include #include #include #include @@ -45,9 +46,7 @@ namespace dumpstate { namespace V1_0 { namespace implementation { -namespace { - -static void getModemLogs(int fd) +void DumpstateDevice::dumpModem(int fd, int fdModem) { std::string modemLogDir = android::base::GetProperty(MODEM_LOG_LOC_PROPERTY, ""); if (modemLogDir.empty()) { @@ -113,8 +112,32 @@ static void getModemLogs(int fd) std::string modemLogPermCmd= "/vendor/bin/chmod a+rw " + modemLogCombined; RunCommandToFd(fd, "CHG PERM", { "/vendor/bin/sh", "-c", modemLogPermCmd.c_str()}, options); + std::vector buffer(65536); + android::base::unique_fd fdLog(TEMP_FAILURE_RETRY(open(modemLogCombined.c_str(), O_RDONLY | O_CLOEXEC | O_NONBLOCK))); + + if (fdLog >= 0) { + while (1) { + ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fdLog, buffer.data(), buffer.size())); + + if (bytes_read == 0) { + break; + } else if (bytes_read < 0) { + ALOGD("read(%s): %s\n", modemLogCombined.c_str(), strerror(errno)); + break; + } + + ssize_t result = TEMP_FAILURE_RETRY(write(fdModem, buffer.data(), bytes_read)); + + if (result != bytes_read) { + ALOGD("Failed to write %ld bytes, actually written: %ld", bytes_read, result); + break; + } + } + } + std::string modemLogClearCmd= "/vendor/bin/rm -r " + modemLogAllDir; RunCommandToFd(fd, "RM MODEM DIR", { "/vendor/bin/sh", "-c", modemLogClearCmd.c_str()}, options); + RunCommandToFd(fd, "RM LOG", { "/vendor/bin/rm", modemLogCombined.c_str()}, options); } } } @@ -132,9 +155,6 @@ static void DumpTouch(int fd) { } } -} // unnamed namespace - - // Methods from ::android::hardware::dumpstate::V1_0::IDumpstateDevice follow. Return DumpstateDevice::dumpstateBoard(const hidl_handle& handle) { if (handle == nullptr || handle->numFds < 1) { @@ -148,7 +168,14 @@ Return DumpstateDevice::dumpstateBoard(const hidl_handle& handle) { return Void(); } - getModemLogs(fd); + if (handle->numFds < 2) { + ALOGE("no FD for modem\n"); + } + else { + int fdModem = handle->data[1]; + dumpModem(fd, fdModem); + } + DumpFileToFd(fd, "SoC serial number", "/sys/devices/soc0/serial_number"); DumpFileToFd(fd, "CPU present", "/sys/devices/system/cpu/present"); DumpFileToFd(fd, "CPU online", "/sys/devices/system/cpu/online"); diff --git a/dumpstate/DumpstateDevice.h b/dumpstate/DumpstateDevice.h index 9237b3b1..650c0cd0 100644 --- a/dumpstate/DumpstateDevice.h +++ b/dumpstate/DumpstateDevice.h @@ -38,6 +38,8 @@ using ::android::sp; struct DumpstateDevice : public IDumpstateDevice { // Methods from ::android::hardware::dumpstate::V1_0::IDumpstateDevice follow. Return dumpstateBoard(const hidl_handle& h) override; + + void dumpModem(int fd, int fdModem); }; } // namespace implementation