blob: e0737323ff54fab37673a7934dc97aff34025a80 [file] [log] [blame]
Adam Shihd0f53602023-02-18 15:26:21 +08001/*
2 * Copyright 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Adam Shihd0f53602023-02-18 15:26:21 +080016#include <android-base/file.h>
Cheng Chang2c8ec7e2024-10-16 04:39:03 +000017#include <android-base/properties.h>
18#include <dirent.h>
19#include <dump/pixel_dump.h>
20#include <sys/stat.h>
21#include <unistd.h>
Adam Shihd0f53602023-02-18 15:26:21 +080022
23#define GPS_LOG_NUMBER_PROPERTY "persist.vendor.gps.aol.log_num"
24#define GPS_LOG_DIRECTORY "/data/vendor/gps/logs"
Cheng Chang2c8ec7e2024-10-16 04:39:03 +000025#define GPS_RESOURCE_DIRECTORY "/data/vendor/gps/resource"
Adam Shihd0f53602023-02-18 15:26:21 +080026#define GPS_TMP_LOG_DIRECTORY "/data/vendor/gps/logs/.tmp"
27#define GPS_LOG_PREFIX "gl-"
28#define GPS_MCU_LOG_PREFIX "esw-"
Cheng Chang0e67f942023-03-28 05:00:40 +000029#define GPS_MALLOC_LOG_DIRECTORY "/data/vendor/gps"
30#define GPS_MALLOC_LOG_PREFIX "malloc_"
Cheng Chang498c4cb2023-06-26 03:49:09 +000031#define GPS_VENDOR_CHIP_INFO "/data/vendor/gps/chip.info"
Edwin Tung42f1c4d2023-07-12 17:02:08 +080032#define GPS_RAWLOG_PREFIX "rawbin"
33#define GPS_MEMDUMP_LOG_PREFIX "memdump_"
Adam Shihd0f53602023-02-18 15:26:21 +080034
Cheng Chang2c8ec7e2024-10-16 04:39:03 +000035static void copyDirectory(const std::string &source,
36 const std::string &outputDir) {
37 DIR *dir = opendir(source.c_str());
38 if (dir == nullptr) {
39 return;
40 }
41
42 if (mkdir(outputDir.c_str(), 0777) == -1) {
43 closedir(dir);
44 return;
45 }
46
47 struct dirent *entry;
48 while ((entry = readdir(dir)) != nullptr) {
49 std::string entryName = entry->d_name;
50 if (entryName == "." || entryName == "..") {
51 continue;
52 }
53
54 std::string sourcePath = source + "/" + entryName;
55 std::string destPath = outputDir + "/" + entryName;
56
57 struct stat st;
58 if (stat(sourcePath.c_str(), &st) == 0) {
59 if (S_ISDIR(st.st_mode))
60 copyDirectory(sourcePath, destPath);
61 else
62 copyFile(sourcePath.c_str(), destPath.c_str());
63 }
64 }
65 closedir(dir);
66 return;
67}
68
Adam Shihd0f53602023-02-18 15:26:21 +080069int main() {
70 if(!::android::base::GetBoolProperty("vendor.gps.aol.enabled", false)) {
71 printf("vendor.gps.aol.enabled is false. gps logging is not running.\n");
72 return 0;
73 }
74 int maxFileNum = ::android::base::GetIntProperty(GPS_LOG_NUMBER_PROPERTY, 20);
75 std::string outputDir = concatenatePath(BUGREPORT_PACKING_DIR, "gps");
76 if (mkdir(outputDir.c_str(), 0777) == -1) {
77 printf("Unable to create folder: %s\n", outputDir.c_str());
78 return 0;
79 }
80
81 dumpLogs(GPS_TMP_LOG_DIRECTORY, outputDir.c_str(), 1, GPS_LOG_PREFIX);
82 dumpLogs(GPS_LOG_DIRECTORY, outputDir.c_str(), 3, GPS_MCU_LOG_PREFIX);
83 dumpLogs(GPS_LOG_DIRECTORY, outputDir.c_str(), maxFileNum, GPS_LOG_PREFIX);
Cheng Chang0e67f942023-03-28 05:00:40 +000084 dumpLogs(GPS_MALLOC_LOG_DIRECTORY, outputDir.c_str(), 1, GPS_MALLOC_LOG_PREFIX);
Cheng Chang498c4cb2023-06-26 03:49:09 +000085 if (access(GPS_VENDOR_CHIP_INFO, F_OK) == 0) {
86 copyFile(GPS_VENDOR_CHIP_INFO, concatenatePath(outputDir.c_str(), "chip.info").c_str());
87 }
Edwin Tung42f1c4d2023-07-12 17:02:08 +080088 dumpLogs(GPS_LOG_DIRECTORY, outputDir.c_str(), maxFileNum, GPS_RAWLOG_PREFIX);
89 dumpLogs(GPS_LOG_DIRECTORY, outputDir.c_str(), 18, GPS_MEMDUMP_LOG_PREFIX);
Cheng Chang2c8ec7e2024-10-16 04:39:03 +000090 copyDirectory(GPS_RESOURCE_DIRECTORY, concatenatePath(outputDir.c_str(), "resource"));
Adam Shihd0f53602023-02-18 15:26:21 +080091 return 0;
92}
93