Write modem log to the 2nd fd from dumpstate

Bug: 33820081
Test: Verify modem logs from bugreport
Change-Id: I0cd0ce8c1a4b2cc3e8a2eeda65b0aa8e1a983fd1
This commit is contained in:
Jie Song
2017-06-15 16:31:38 -07:00
parent 3266111d28
commit a9cb65d25c
2 changed files with 36 additions and 7 deletions

View File

@@ -19,6 +19,7 @@
#include "DumpstateDevice.h"
#include <android-base/properties.h>
#include <android-base/unique_fd.h>
#include <cutils/properties.h>
#include <libgen.h>
#include <log/log.h>
@@ -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<uint8_t> 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<void> DumpstateDevice::dumpstateBoard(const hidl_handle& handle) {
if (handle == nullptr || handle->numFds < 1) {
@@ -148,7 +168,14 @@ Return<void> 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");

View File

@@ -38,6 +38,8 @@ using ::android::sp;
struct DumpstateDevice : public IDumpstateDevice {
// Methods from ::android::hardware::dumpstate::V1_0::IDumpstateDevice follow.
Return<void> dumpstateBoard(const hidl_handle& h) override;
void dumpModem(int fd, int fdModem);
};
} // namespace implementation