dump_modemlog: move all files to subdirectory

Since radioext has already moved to this folder, it doesn't make sense
for the base folder to be dump_modemlog. This change moves it to its
own subfolder so that we can also add more in the future.

Test: build and flash, trigger bugreport and check modem logs are there
Bug: 302435001
Change-Id: Ia83378074068526023f591d63b1e5ac4700b8103
This commit is contained in:
kierancyphus 2023-11-10 14:40:18 +08:00 committed by Kieran Cyphus
parent 057e9b0f74
commit 3ed60cec02
17 changed files with 42 additions and 51 deletions

View file

@ -0,0 +1,20 @@
#pragma once
#include <string>
namespace pixel_modem::logging {
/**
* @brief Interface for interacting with Android System Properties.
*/
class AndroidPropertyManager {
public:
virtual ~AndroidPropertyManager() = default;
virtual bool GetBoolProperty(const std::string& key, bool default_value);
virtual std::string GetProperty(const std::string& key,
const std::string& default_value);
virtual int GetIntProperty(const std::string& key, int default_value);
virtual void SetProperty(const std::string& key, const std::string& value);
};
} // namespace pixel_modem::logging

View file

@ -0,0 +1,70 @@
#pragma once
#include <ostream>
#include <string_view>
namespace pixel_modem::logging {
/**
* @brief Data object for information about dumpings logs.
*
* @param src_dir is a const char* containing the path to the directory to be
copied.
* @param dest_dir is a const char* containing the path to the directory that
the contents of the source directory should be copied to.
* @param limit is an int of the maximum number of files to copy.
* @param prefix is a const char* containing a prefix that all files to be
copied should have.
*/
struct LogDumpInfo {
const std::string_view src_dir;
const std::string_view dest_dir;
int limit;
const std::string_view prefix;
friend bool operator==(const LogDumpInfo& lhs, const LogDumpInfo& rhs) {
return (lhs.limit == rhs.limit) && (lhs.src_dir == rhs.src_dir) &&
(lhs.dest_dir == rhs.dest_dir) && (lhs.prefix == rhs.prefix);
}
// Do I have to use .data() here?
friend std::ostream& operator<<(std::ostream& os, const LogDumpInfo& obj) {
os << "src_dir: " << obj.src_dir << ", dest_dir: " << obj.dest_dir
<< ", limit: " << obj.limit << ", prefix: " << obj.prefix;
return os;
}
};
/**
* @brief Data object for information about dumpings logs.
*
* @param src_dir is a const char* containing the path to a file to be copied.
* @param dest_dir is a const char* containing the destination path for the file
* to be copied to.
*/
struct FileCopyInfo {
const std::string_view src_dir;
const std::string_view dest_dir;
friend bool operator==(const FileCopyInfo& lhs, const FileCopyInfo& rhs) {
return (lhs.src_dir == rhs.src_dir) && (lhs.dest_dir == rhs.dest_dir);
}
// Do I have to add .data() here?
friend std::ostream& operator<<(std::ostream& os, const FileCopyInfo& obj) {
os << "src_dir: " << obj.src_dir << ", dest_dir: " << obj.dest_dir;
return os;
}
};
/**
* @brief Interface for dumping modem logs and files.
*/
class Dumper {
public:
virtual ~Dumper() = default;
virtual void DumpLogs(const LogDumpInfo& log_dump_info);
virtual void CopyFile(const FileCopyInfo& file_copy_info);
};
} // namespace pixel_modem::logging

View file

@ -0,0 +1,55 @@
#pragma once
#include <string>
#include "dumper.h"
namespace pixel_modem::logging {
// Modem related Android System Properties
// Controls triggering `modem_logging_start` and `modem_logging_stop`.
inline constexpr static std::string_view kModemLoggingEnabledProperty =
"vendor.sys.modem.logging.enable";
// Signals the current modem logging state. This will be set to
// `vendor.sys.modem.logging.enable` when `modem_log_start` or `modem_log_stop`
// terminates.
inline constexpr static std::string_view kModemLoggingStatusProperty =
"vendor.sys.modem.logging.status";
// Int which specifies how many files to include in the bugreport.
inline constexpr static std::string_view kModemLoggingNumberBugreportProperty =
"persist.vendor.sys.modem.logging.br_num";
// Signals the current location that is being logged to. This can be used to
// determine the logging type.
inline constexpr static std::string_view kModemLoggingPathProperty =
"vendor.sys.modem.logging.log_path";
// Bugreport constants
inline constexpr static int kDefaultBugreportNumberFiles = 100;
inline constexpr static std::string_view kModemAlwaysOnLogDirectory =
"/data/vendor/radio/logs/always-on";
inline constexpr static std::string_view kModemLogPrefix = "sbuff_";
inline constexpr static std::string_view kBugreportPackingDirectory =
"/data/vendor/radio/logs/always-on/all_logs";
inline constexpr static LogDumpInfo kLogDumpInfo[] = {
{.src_dir = "/data/vendor/radio/extended_logs",
.dest_dir = kBugreportPackingDirectory,
.limit = 20,
.prefix = "extended_log_"},
{.src_dir = "/data/vendor/radio/sim/",
.dest_dir = kBugreportPackingDirectory,
.limit = 1,
.prefix = "sim_poweron_log_"},
{.src_dir = "data/vendor/radio/logs/history",
.dest_dir = kBugreportPackingDirectory,
.limit = 2,
.prefix = "Logging"}};
constexpr static FileCopyInfo kFileCopyInfo[] = {
{.src_dir = "/mnt/vendor/efs/nv_normal.bin",
.dest_dir = "/data/vendor/radio/logs/always-on/all_logs/nv_normal.bin"},
{.src_dir = "/mnt/vendor/efs/nv_protected.bin",
.dest_dir =
"/data/vendor/radio/logs/always-on/all_logs/nv_protected.bin"}};
} // namespace pixel_modem::logging

View file

@ -0,0 +1,79 @@
#pragma once
#include "android_property_manager.h"
#include "dumper.h"
namespace pixel_modem::logging {
/**
* @brief Responsible for dumping all relevant modem logs.
*/
class ModemLogDumper {
public:
ModemLogDumper(Dumper& dumper,
AndroidPropertyManager& android_property_manager)
: dumper_(dumper), android_property_manager_(android_property_manager){};
/**
* @brief Dumps modem related logs and persistent files to bugreport.
*
* If PILOT and On Demand Logging are both not enabled, this method will
* attempt to stop modem logging, copy over the logs, and then restart so that
* the original logging enabled / disabled state is preserved. Additionally,
* all directories specified in `kLogDumpInfo` and all files in
* `kFileCopyInfo` will be included.
*/
void DumpModemLogs();
private:
/**
* @brief Checks modem logging status property to assert if logging is
* running or not.
*/
bool isModemLoggingRunning();
/**
* @brief Checks if On Demand Logging or PILOT Logging is enabled.
*
* If either of them are enabled, then the `log_path` property will no longer
* point to the always on logging directory.
*/
bool allowedToStopModemLogging();
/**
* @brief Stops modem logging.
*
* This sets the modem logging property which in turn triggers
* modem_logging_control's modem_logging_stop service. Modem logging isn't
* guaranteed to have stopped after this call, so it's necessary to poll the
* status property to ensure it's stopped before proceeding.
*/
void stopModemLogging();
/**
* @brief Polls modem logging status property to ensure modem logging has
* stopped.
*
* Even after the property is confirmed to be false, it will continue to
* sleep for a second to ensure that the modem_logging_stop service has exited
* properly.
*/
void waitForStopModemLogging();
/**
* @brief Starts modem logging.
*
* This sets the modem logging property which in turn triggers
* modem_logging_control's modem_logging_start service. Modem logging isn't
* guaranteed to have started after this call, so it's necessary to poll the
* status property to ensure it's started before proceeding to guarantee
* success.
*/
void startModemLogging();
private:
Dumper& dumper_;
AndroidPropertyManager& android_property_manager_;
};
} // namespace pixel_modem::logging