1 /*
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  */
16 #include <dump/pixel_dump.h>
17 #include <android-base/properties.h>
18 #include <android-base/file.h>
19 
20 #define RIL_LOG_DIRECTORY "/data/vendor/radio"
21 #define RIL_LOG_DIRECTORY_PROPERTY "persist.vendor.ril.log.base_dir"
22 #define RIL_LOG_NUMBER_PROPERTY "persist.vendor.ril.log.num_file"
23 #define RIL_LOG_PREFIX "rild.log."
24 
25 #define TCPDUMP_LOG_DIRECTORY "/data/vendor/tcpdump_logger/logs"
26 #define TCPDUMP_NUMBER_BUGREPORT "persist.vendor.tcpdump.log.br_num"
27 #define TCPDUMP_PERSIST_PROPERTY "persist.vendor.tcpdump.log.alwayson"
28 #define TCPDUMP_LOG_PREFIX "tcpdump"
29 
main()30 int main() {
31     // netmgr
32     bool tcpdumpEnabled = ::android::base::GetBoolProperty(TCPDUMP_PERSIST_PROPERTY, false);
33 
34     if (tcpdumpEnabled) {
35         dumpLogs(TCPDUMP_LOG_DIRECTORY, BUGREPORT_PACKING_DIR, ::android::base::GetIntProperty(TCPDUMP_NUMBER_BUGREPORT, 5), TCPDUMP_LOG_PREFIX);
36     }
37     copyFile("/data/vendor/radio/adum_log", "/data/vendor/radio/logs/always-on/all_logs/adum_log");
38     copyFile("/data/vendor/radio/adum_log_old", "/data/vendor/radio/logs/always-on/all_logs/adum_log_old");
39     copyFile("/data/vendor/radio/metrics_data", "/data/vendor/radio/logs/always-on/all_logs/metrics_data");
40     copyFile("/data/vendor/radio/omadm_logs.txt", "/data/vendor/radio/logs/always-on/all_logs/omadm_logs.txt");
41     copyFile("/data/vendor/radio/power_anomaly_data.txt", "/data/vendor/radio/logs/always-on/all_logs/power_anomaly_data.txt");
42 
43     // RIL dump
44     std::string rilLogDir = ::android::base::GetProperty(RIL_LOG_DIRECTORY_PROPERTY, RIL_LOG_DIRECTORY);
45 
46     int maxFileNum = ::android::base::GetIntProperty(RIL_LOG_NUMBER_PROPERTY, 50);
47 
48     const std::string currentLogDir = concatenatePath(rilLogDir.c_str(), "/cur");
49     const std::string previousLogDir = concatenatePath(rilLogDir.c_str(), "/prev");
50     const std::string currentDestDir = concatenatePath(BUGREPORT_PACKING_DIR, "cur");
51     const std::string previousDestDir = concatenatePath(BUGREPORT_PACKING_DIR, "prev");
52     if (mkdir(currentDestDir.c_str(), 0777) == -1) {
53         printf("Unable to create folder: %s\n", currentDestDir.c_str());
54         return 0;
55     }
56     if (mkdir(previousDestDir.c_str(), 0777) == -1) {
57         printf("Unable to create folder: %s\n", previousDestDir.c_str());
58         return 0;
59     }
60 
61     dumpLogs(currentLogDir.c_str(), currentDestDir.c_str(), maxFileNum, RIL_LOG_PREFIX);
62     dumpLogs(previousLogDir.c_str(), previousDestDir.c_str(), maxFileNum, RIL_LOG_PREFIX);
63     return 0;
64 }
65