1 #include "modem_log_dumper.h"
2
3 #include <log/log.h>
4
5 #include "bugreport_constants.h"
6 #include "dumper.h"
7 #include "modem_log_constants.h"
8
9 namespace pixel_modem::logging {
10
DumpModemLogs()11 void ModemLogDumper::DumpModemLogs() {
12 bool shouldRestartModemLogging =
13 allowedToStopModemLogging() && isModemLoggingRunning();
14 int maxFileNum = android_property_manager_.GetIntProperty(
15 kModemLoggingNumberBugreportProperty.data(),
16 kDefaultBugreportNumberFiles);
17
18 // Should always trigger `stopModemLogging`. This is because currently copying
19 // modem logs and stopping modem logging are entangled.
20 // TODO: b/289435256 - Always copy logs and return this to checking if logging
21 // is actively running.
22 if (allowedToStopModemLogging()) {
23 // If modem logging is running at time of bugreport, it needs to be stopped
24 // to ensure that the most recent logs are included in the bugreport. If
25 // this command fails, only older log files will be included, as seen in
26 // b/289435256.
27 stopModemLogging();
28 waitForStopModemLogging();
29 } else {
30 ALOGD("modem logging is not running\n");
31 }
32
33 dumper_.DumpLogs({kModemAlwaysOnLogDirectory, kBugreportPackingDirectory,
34 maxFileNum, kModemLogPrefix});
35
36 if (shouldRestartModemLogging) {
37 startModemLogging();
38 }
39
40 for (const LogDumpInfo& log_dump_info : kLogDumpInfo) {
41 dumper_.DumpLogs(log_dump_info);
42 }
43
44 for (const FileCopyInfo& file_copy_info : kFileCopyInfo) {
45 dumper_.CopyFile(file_copy_info);
46 }
47 };
48
isModemLoggingRunning()49 bool ModemLogDumper::isModemLoggingRunning() {
50 return android_property_manager_.GetBoolProperty(
51 kModemLoggingStatusProperty.data(), false);
52 }
53
allowedToStopModemLogging()54 bool ModemLogDumper::allowedToStopModemLogging() {
55 return android_property_manager_.GetProperty(kModemLoggingPathProperty.data(),
56 /*default_value=*/"") ==
57 kModemAlwaysOnLogDirectory;
58 }
59
stopModemLogging()60 void ModemLogDumper::stopModemLogging() {
61 android_property_manager_.SetProperty(kModemLoggingEnabledProperty.data(),
62 "false");
63 ALOGD("Stopping modem logging...\n");
64 }
65
waitForStopModemLogging()66 void ModemLogDumper::waitForStopModemLogging() {
67 // TODO(b/289582966) improve stop logging mechanism to not use sleep
68 for (int i = 0; i < 15; i++) {
69 if (!isModemLoggingRunning()) {
70 ALOGD("modem logging stopped\n");
71 sleep(1);
72 break;
73 }
74 sleep(1);
75 }
76 }
77
startModemLogging()78 void ModemLogDumper::startModemLogging() {
79 ALOGD("Restarting modem logging...\n");
80 android_property_manager_.SetProperty(kModemLoggingEnabledProperty.data(),
81 "true");
82 }
83
84 } // namespace pixel_modem::logging
85