diff --git a/dumpstate/Dumpstate.cpp b/dumpstate/Dumpstate.cpp index 5b467a56..550d95ec 100644 --- a/dumpstate/Dumpstate.cpp +++ b/dumpstate/Dumpstate.cpp @@ -29,10 +29,6 @@ #include "DumpstateUtil.h" -#define TCPDUMP_LOG_DIRECTORY "/data/vendor/tcpdump_logger/logs" -#define TCPDUMP_NUMBER_BUGREPORT "persist.vendor.tcpdump.log.br_num" -#define TCPDUMP_PERSIST_PROPERTY "persist.vendor.tcpdump.log.alwayson" - #define HW_REVISION "ro.boot.hardware.revision" using android::os::dumpstate::CommandOptions; @@ -45,97 +41,10 @@ namespace android { namespace hardware { namespace dumpstate { -#define BUFSIZE 65536 -#define TCPDUMP_LOG_PREFIX "tcpdump" - typedef std::chrono::time_point timepoint_t; const char kVerboseLoggingProperty[] = "persist.vendor.verbose_logging_enabled"; -void Dumpstate::dumpLogs(int fd, std::string srcDir, std::string destDir, int maxFileNum, - const char *logPrefix) { - struct dirent **dirent_list = NULL; - int num_entries = scandir(srcDir.c_str(), - &dirent_list, - 0, - (int (*)(const struct dirent **, const struct dirent **)) alphasort); - if (!dirent_list) { - return; - } else if (num_entries <= 0) { - return; - } - - int copiedFiles = 0; - - for (int i = num_entries - 1; i >= 0; i--) { - ALOGD("Found %s\n", dirent_list[i]->d_name); - - if (0 != strncmp(dirent_list[i]->d_name, logPrefix, strlen(logPrefix))) { - continue; - } - - if ((copiedFiles >= maxFileNum) && (maxFileNum != -1)) { - ALOGD("Skipped %s\n", dirent_list[i]->d_name); - continue; - } - - copiedFiles++; - - CommandOptions options = CommandOptions::WithTimeout(120).Build(); - std::string srcLogFile = srcDir + "/" + dirent_list[i]->d_name; - std::string destLogFile = destDir + "/" + dirent_list[i]->d_name; - - std::string copyCmd = "/vendor/bin/cp " + srcLogFile + " " + destLogFile; - - ALOGD("Copying %s to %s\n", srcLogFile.c_str(), destLogFile.c_str()); - RunCommandToFd(fd, "CP LOGS", { "/vendor/bin/sh", "-c", copyCmd.c_str() }, options); - } - - while (num_entries--) { - free(dirent_list[num_entries]); - } - - free(dirent_list); -} - -void copyFile(std::string srcFile, std::string destFile) { - uint8_t buffer[BUFSIZE]; - ssize_t size; - - int fdSrc = open(srcFile.c_str(), O_RDONLY); - if (fdSrc < 0) { - ALOGD("Failed to open source file %s\n", srcFile.c_str()); - return; - } - - int fdDest = open(destFile.c_str(), O_WRONLY | O_CREAT, 0666); - if (fdDest < 0) { - ALOGD("Failed to open destination file %s\n", destFile.c_str()); - close(fdSrc); - return; - } - - ALOGD("Copying %s to %s\n", srcFile.c_str(), destFile.c_str()); - while ((size = TEMP_FAILURE_RETRY(read(fdSrc, buffer, BUFSIZE))) > 0) { - TEMP_FAILURE_RETRY(write(fdDest, buffer, size)); - } - - close(fdDest); - close(fdSrc); -} - -void dumpNetmgrLogs(std::string destDir) { - const std::vector netmgrLogs - { - "/data/vendor/radio/metrics_data", - "/data/vendor/radio/omadm_logs.txt", - "/data/vendor/radio/power_anomaly_data.txt", - }; - for (const auto& logFile : netmgrLogs) { - copyFile(logFile, destDir + "/" + basename(logFile.c_str())); - } -} - timepoint_t startSection(int fd, const std::string §ionName) { ::android::base::WriteStringToFd( "\n" @@ -156,12 +65,6 @@ void endSection(int fd, const std::string §ionName, timepoint_t startTime) { "\n", fd); } -Dumpstate::Dumpstate() - : mLogSections{ - { "radio", [this](int fd, const std::string &destDir) { dumpRadioLogs(fd, destDir); } }, - } { -} - // Dump data requested by an argument to the "dump" interface, or help info // if the specified section is not supported. void Dumpstate::dumpTextSection(int fd, const std::string §ionName) { @@ -206,16 +109,6 @@ void Dumpstate::dumpTextSection(int fd, const std::string §ionName) { "not avalable from the command line.\n", fd); } -void Dumpstate::dumpRadioLogs(int fd, const std::string &destDir) { - std::string tcpdumpLogDir = TCPDUMP_LOG_DIRECTORY; - bool tcpdumpEnabled = ::android::base::GetBoolProperty(TCPDUMP_PERSIST_PROPERTY, false); - - if (tcpdumpEnabled) { - dumpLogs(fd, tcpdumpLogDir, destDir, ::android::base::GetIntProperty(TCPDUMP_NUMBER_BUGREPORT, 5), TCPDUMP_LOG_PREFIX); - } - dumpNetmgrLogs(destDir); -} - void Dumpstate::dumpLogSection(int fd, int fd_bin) { std::string logDir = MODEM_LOG_DIRECTORY; @@ -226,15 +119,6 @@ void Dumpstate::dumpLogSection(int fd, int fd_bin) dumpTextSection(fd, kAllSections); - // Dump all module logs - if (!PropertiesHelper::IsUserBuild()) { - for (const auto §ion : mLogSections) { - auto startTime = startSection(fd, section.first); - section.second(fd, logAllDir); - endSection(fd, section.first, startTime); - } - } - RunCommandToFd(fd, "TAR LOG", {"/vendor/bin/tar", "cvf", logCombined.c_str(), "-C", logAllDir.c_str(), "."}, CommandOptions::WithTimeout(20).Build()); RunCommandToFd(fd, "CHG PERM", {"/vendor/bin/chmod", "a+w", logCombined.c_str()}, CommandOptions::WithTimeout(2).Build()); diff --git a/dumpstate/Dumpstate.h b/dumpstate/Dumpstate.h index 88041200..787b7747 100644 --- a/dumpstate/Dumpstate.h +++ b/dumpstate/Dumpstate.h @@ -27,8 +27,6 @@ namespace dumpstate { class Dumpstate : public BnDumpstateDevice { public: - Dumpstate(); - ::ndk::ScopedAStatus dumpstateBoard(const std::vector<::ndk::ScopedFileDescriptor>& in_fds, IDumpstateDevice::DumpstateMode in_mode, int64_t in_timeoutMillis) override; @@ -42,20 +40,9 @@ class Dumpstate : public BnDumpstateDevice { private: const std::string kAllSections = "all"; - std::vector>> mLogSections; - - void dumpLogs(int fd, std::string srcDir, std::string destDir, int maxFileNum, - const char *logPrefix); - void dumpTextSection(int fd, std::string const& sectionName); void dumpLogSection(int fd, int fdModem); - // Log sections to be dumped individually into dumpstate_board.bin - void dumpRadioLogs(int fd, const std::string &destDir); - - // Hybrid and binary sections that require an additional file descriptor - void dumpRilLogs(int fd, std::string destDir); - //bool getVerboseLoggingEnabledImpl(); //::ndk::ScopedAStatus dumpstateBoardImpl(const int fd, const bool full); };