From 2c8ec7ea440e908d7239a925a6d732e1a5ab9cef Mon Sep 17 00:00:00 2001 From: Cheng Chang Date: Wed, 16 Oct 2024 04:39:03 +0000 Subject: [PATCH] dump_gps: Support bugreport extract resource info Bug: 369971486 Flag: EXEMPT log information update. Test: Different input value in b/369971486. Test: Read the sysfs value in b/369971486. Test: Collect bugreport and check the attachment in b/369971486. Test: Sepolicy test in b/369971486. Change-Id: Ib8f2565387a9a2c7d715e4791bbcddb86a12fb70 --- gps/dump/dump_gps.cpp | 44 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/gps/dump/dump_gps.cpp b/gps/dump/dump_gps.cpp index 62f69f8..e073732 100644 --- a/gps/dump/dump_gps.cpp +++ b/gps/dump/dump_gps.cpp @@ -13,13 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include -#include #include +#include +#include +#include +#include +#include #define GPS_LOG_NUMBER_PROPERTY "persist.vendor.gps.aol.log_num" #define GPS_LOG_DIRECTORY "/data/vendor/gps/logs" +#define GPS_RESOURCE_DIRECTORY "/data/vendor/gps/resource" #define GPS_TMP_LOG_DIRECTORY "/data/vendor/gps/logs/.tmp" #define GPS_LOG_PREFIX "gl-" #define GPS_MCU_LOG_PREFIX "esw-" @@ -29,6 +32,40 @@ #define GPS_RAWLOG_PREFIX "rawbin" #define GPS_MEMDUMP_LOG_PREFIX "memdump_" +static void copyDirectory(const std::string &source, + const std::string &outputDir) { + DIR *dir = opendir(source.c_str()); + if (dir == nullptr) { + return; + } + + if (mkdir(outputDir.c_str(), 0777) == -1) { + closedir(dir); + return; + } + + struct dirent *entry; + while ((entry = readdir(dir)) != nullptr) { + std::string entryName = entry->d_name; + if (entryName == "." || entryName == "..") { + continue; + } + + std::string sourcePath = source + "/" + entryName; + std::string destPath = outputDir + "/" + entryName; + + struct stat st; + if (stat(sourcePath.c_str(), &st) == 0) { + if (S_ISDIR(st.st_mode)) + copyDirectory(sourcePath, destPath); + else + copyFile(sourcePath.c_str(), destPath.c_str()); + } + } + closedir(dir); + return; +} + int main() { if(!::android::base::GetBoolProperty("vendor.gps.aol.enabled", false)) { printf("vendor.gps.aol.enabled is false. gps logging is not running.\n"); @@ -50,6 +87,7 @@ int main() { } dumpLogs(GPS_LOG_DIRECTORY, outputDir.c_str(), maxFileNum, GPS_RAWLOG_PREFIX); dumpLogs(GPS_LOG_DIRECTORY, outputDir.c_str(), 18, GPS_MEMDUMP_LOG_PREFIX); + copyDirectory(GPS_RESOURCE_DIRECTORY, concatenatePath(outputDir.c_str(), "resource")); return 0; }