kierancyphus c7da8aa098 dump_modemlog: always move modem logs
Dynamic log mask events can occur without leaving the logging status
property as enabled, which means when dumpstate should always try to
stop modem logging so that the new logs can be copied over.

Having the copying of logs and stopping of modem logging combined in
one command is no longer an ideal design, so b/289435256 was created
to find a better solution to this.

Test: build, flash, trigger log mask event, check logs in bugreport.
Bug: 302435001
Change-Id: I56358d3f08ac1f2a6099ede14c5e17b5ebffabbd
2023-12-01 05:30:02 +00:00

85 lines
2.6 KiB
C++

#include "modem_log_dumper.h"
#include <log/log.h>
#include "bugreport_constants.h"
#include "dumper.h"
#include "modem_log_constants.h"
namespace pixel_modem::logging {
void ModemLogDumper::DumpModemLogs() {
bool shouldRestartModemLogging =
allowedToStopModemLogging() && isModemLoggingRunning();
int maxFileNum = android_property_manager_.GetIntProperty(
kModemLoggingNumberBugreportProperty.data(),
kDefaultBugreportNumberFiles);
// Should always trigger `stopModemLogging`. This is because currently copying
// modem logs and stopping modem logging are entangled.
// TODO: b/289435256 - Always copy logs and return this to checking if logging
// is actively running.
if (allowedToStopModemLogging()) {
// If modem logging is running at time of bugreport, it needs to be stopped
// to ensure that the most recent logs are included in the bugreport. If
// this command fails, only older log files will be included, as seen in
// b/289435256.
stopModemLogging();
waitForStopModemLogging();
} else {
ALOGD("modem logging is not running\n");
}
dumper_.DumpLogs({kModemAlwaysOnLogDirectory, kBugreportPackingDirectory,
maxFileNum, kModemLogPrefix});
if (shouldRestartModemLogging) {
startModemLogging();
}
for (const LogDumpInfo& log_dump_info : kLogDumpInfo) {
dumper_.DumpLogs(log_dump_info);
}
for (const FileCopyInfo& file_copy_info : kFileCopyInfo) {
dumper_.CopyFile(file_copy_info);
}
};
bool ModemLogDumper::isModemLoggingRunning() {
return android_property_manager_.GetBoolProperty(
kModemLoggingStatusProperty.data(), false);
}
bool ModemLogDumper::allowedToStopModemLogging() {
return android_property_manager_.GetProperty(kModemLoggingPathProperty.data(),
/*default_value=*/"") ==
kModemAlwaysOnLogDirectory;
}
void ModemLogDumper::stopModemLogging() {
android_property_manager_.SetProperty(kModemLoggingEnabledProperty.data(),
"false");
ALOGD("Stopping modem logging...\n");
}
void ModemLogDumper::waitForStopModemLogging() {
// TODO(b/289582966) improve stop logging mechanism to not use sleep
for (int i = 0; i < 15; i++) {
if (!isModemLoggingRunning()) {
ALOGD("modem logging stopped\n");
sleep(1);
break;
}
sleep(1);
}
}
void ModemLogDumper::startModemLogging() {
ALOGD("Restarting modem logging...\n");
android_property_manager_.SetProperty(kModemLoggingEnabledProperty.data(),
"true");
}
} // namespace pixel_modem::logging