Merge "create function dumpLog" into udc-dev am: 80fed77790
Original change: https://googleplex-android-review.googlesource.com/c/device/google/gs-common/+/21492984 Change-Id: Icf5bc88d8c0261085b11b2568b5c7ed39f80bf68 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
030e978994
7 changed files with 147 additions and 0 deletions
20
gps/dump/Android.bp
Normal file
20
gps/dump/Android.bp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package {
|
||||||
|
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_binary {
|
||||||
|
name: "dump_gps",
|
||||||
|
srcs: ["dump_gps.cpp"],
|
||||||
|
cflags: [
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-Werror",
|
||||||
|
],
|
||||||
|
shared_libs: [
|
||||||
|
"libbase",
|
||||||
|
"libdump",
|
||||||
|
"liblog",
|
||||||
|
],
|
||||||
|
vendor: true,
|
||||||
|
relative_install_path: "dump",
|
||||||
|
}
|
43
gps/dump/dump_gps.cpp
Normal file
43
gps/dump/dump_gps.cpp
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
#include <dump/pixel_dump.h>
|
||||||
|
#include <android-base/properties.h>
|
||||||
|
#include <android-base/file.h>
|
||||||
|
|
||||||
|
#define GPS_LOG_NUMBER_PROPERTY "persist.vendor.gps.aol.log_num"
|
||||||
|
#define GPS_LOG_DIRECTORY "/data/vendor/gps/logs"
|
||||||
|
#define GPS_TMP_LOG_DIRECTORY "/data/vendor/gps/logs/.tmp"
|
||||||
|
#define GPS_LOG_PREFIX "gl-"
|
||||||
|
#define GPS_MCU_LOG_PREFIX "esw-"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
if(!::android::base::GetBoolProperty("vendor.gps.aol.enabled", false)) {
|
||||||
|
printf("vendor.gps.aol.enabled is false. gps logging is not running.\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int maxFileNum = ::android::base::GetIntProperty(GPS_LOG_NUMBER_PROPERTY, 20);
|
||||||
|
std::string outputDir = concatenatePath(BUGREPORT_PACKING_DIR, "gps");
|
||||||
|
if (mkdir(outputDir.c_str(), 0777) == -1) {
|
||||||
|
printf("Unable to create folder: %s\n", outputDir.c_str());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
dumpLogs(GPS_TMP_LOG_DIRECTORY, outputDir.c_str(), 1, GPS_LOG_PREFIX);
|
||||||
|
dumpLogs(GPS_LOG_DIRECTORY, outputDir.c_str(), 3, GPS_MCU_LOG_PREFIX);
|
||||||
|
dumpLogs(GPS_LOG_DIRECTORY, outputDir.c_str(), maxFileNum, GPS_LOG_PREFIX);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
4
gps/dump/log.mk
Normal file
4
gps/dump/log.mk
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
BOARD_VENDOR_SEPOLICY_DIRS += device/google/gs-common/gps/dump/sepolicy/
|
||||||
|
|
||||||
|
PRODUCT_PACKAGES_DEBUG += dump_gps
|
||||||
|
|
10
gps/dump/sepolicy/dump_gps.te
Normal file
10
gps/dump/sepolicy/dump_gps.te
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
pixel_bugreport(dump_gps)
|
||||||
|
|
||||||
|
userdebug_or_eng(`
|
||||||
|
allow dump_gps radio_vendor_data_file:dir create_dir_perms;
|
||||||
|
allow dump_gps radio_vendor_data_file:file create_file_perms;
|
||||||
|
allow dump_gps vendor_gps_file:dir r_dir_perms;
|
||||||
|
allow dump_gps vendor_gps_file:file r_file_perms;
|
||||||
|
|
||||||
|
get_prop(dump_gps, vendor_gps_prop)
|
||||||
|
')
|
2
gps/dump/sepolicy/file_contexts
Normal file
2
gps/dump/sepolicy/file_contexts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/vendor/bin/dump/dump_gps u:object_r:dump_gps_exec:s0
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
#ifndef DEVICE_GOOGLE_GS_COMMON_INSMOD_INCLUDE_DUMP_PIXEL_DUMP_H_
|
#ifndef DEVICE_GOOGLE_GS_COMMON_INSMOD_INCLUDE_DUMP_PIXEL_DUMP_H_
|
||||||
#define DEVICE_GOOGLE_GS_COMMON_INSMOD_INCLUDE_DUMP_PIXEL_DUMP_H_
|
#define DEVICE_GOOGLE_GS_COMMON_INSMOD_INCLUDE_DUMP_PIXEL_DUMP_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#define BUGREPORT_PACKING_DIR "/data/vendor/radio/logs/always-on/all_logs"
|
||||||
|
#define MODEM_LOG_DIRECTORY "/data/vendor/radio/logs/always-on"
|
||||||
|
|
||||||
void dumpFileContent(const char* title, const char* file_path);
|
void dumpFileContent(const char* title, const char* file_path);
|
||||||
void runCommand(const char* title, const char* cmd);
|
void runCommand(const char* title, const char* cmd);
|
||||||
|
std::string concatenatePath(const char* folder, const char* file);
|
||||||
|
void dumpLogs(const char* SrcDir, const char* DestDir, int limit, const char* prefix);
|
||||||
|
|
||||||
#endif // DEVICE_GOOGLE_GS_COMMON_INSMOD_INCLUDE_DUMP_PIXEL_DUMP_H_
|
#endif // DEVICE_GOOGLE_GS_COMMON_INSMOD_INCLUDE_DUMP_PIXEL_DUMP_H_
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <dump/pixel_dump.h>
|
||||||
|
|
||||||
// Format title and content output.
|
// Format title and content output.
|
||||||
void dumpFileContent(const char* title, const char* file_path) {
|
void dumpFileContent(const char* title, const char* file_path) {
|
||||||
|
@ -35,3 +37,62 @@ void runCommand(const char* title, const char* cmd) {
|
||||||
system(cmd);
|
system(cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string concatenatePath(const char* folder, const char* file){
|
||||||
|
std::string path = folder;
|
||||||
|
if(folder[strlen(folder)-1] == '/'){
|
||||||
|
path = path + file;
|
||||||
|
} else {
|
||||||
|
path = path + "/" + file;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("folder:%s, result:%s\n", folder, path.c_str());
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy stored log from individual folder to our dumpstate folder for
|
||||||
|
// compressing.
|
||||||
|
void dumpLogs(const char* SrcDir, const char* DestDir, int limit, const char* prefix) {
|
||||||
|
|
||||||
|
struct dirent **dirent_list = NULL;
|
||||||
|
int num_entries = scandir(SrcDir, &dirent_list, 0, (int (*)(const struct dirent **, const struct dirent **)) alphasort);
|
||||||
|
if (!dirent_list) {
|
||||||
|
printf("Unable to scan dir: %s.\n", SrcDir);
|
||||||
|
return;
|
||||||
|
} else if (num_entries <= 0) {
|
||||||
|
printf("No file is found.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (access(DestDir, R_OK)) {
|
||||||
|
printf("Unable to find folder: %s\n", DestDir);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int copiedFiles = 0;
|
||||||
|
|
||||||
|
for (int i = num_entries - 1; i >= 0; i--) {
|
||||||
|
|
||||||
|
if (0 != strncmp(dirent_list[i]->d_name, prefix, strlen(prefix))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((copiedFiles >= limit) && (limit != -1)) {
|
||||||
|
printf("Skipped %s\n", dirent_list[i]->d_name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
copiedFiles++;
|
||||||
|
|
||||||
|
std::ifstream src(concatenatePath(SrcDir, dirent_list[i]->d_name).c_str(), std::ios::binary);
|
||||||
|
std::ofstream dst(concatenatePath(DestDir, dirent_list[i]->d_name).c_str(), std::ios::binary);
|
||||||
|
dst << src.rdbuf();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (num_entries--) {
|
||||||
|
free(dirent_list[num_entries]);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(dirent_list);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue