1 #pragma once
2 
3 #include "android_property_manager.h"
4 #include "dumper.h"
5 
6 namespace pixel_modem::logging {
7 
8 /**
9  * @brief Responsible for dumping all relevant modem logs.
10  */
11 class ModemLogDumper {
12  public:
ModemLogDumper(Dumper & dumper,AndroidPropertyManager & android_property_manager)13   ModemLogDumper(Dumper& dumper,
14                  AndroidPropertyManager& android_property_manager)
15       : dumper_(dumper), android_property_manager_(android_property_manager){};
16 
17   /**
18    * @brief Dumps modem related logs and persistent files to bugreport.
19    *
20    * If PILOT and On Demand Logging are both not enabled, this method will
21    * attempt to stop modem logging, copy over the logs, and then restart so that
22    * the original logging enabled / disabled state is preserved. Additionally,
23    * all directories specified in `kLogDumpInfo` and all files in
24    * `kFileCopyInfo` will be included.
25    */
26   void DumpModemLogs();
27 
28  private:
29   /**
30    * @brief Checks modem logging status property to assert if logging is
31    * running or not.
32    */
33   bool isModemLoggingRunning();
34 
35   /**
36    * @brief Checks if On Demand Logging or PILOT Logging is enabled.
37    *
38    * If either of them are enabled, then the `log_path` property will no longer
39    * point to the always on logging directory.
40    */
41   bool allowedToStopModemLogging();
42 
43   /**
44    * @brief Stops modem logging.
45    *
46    * This sets the modem logging property which in turn triggers
47    * modem_logging_control's modem_logging_stop service. Modem logging isn't
48    * guaranteed to have stopped after this call, so it's necessary to poll the
49    * status property to ensure it's stopped before proceeding.
50    */
51   void stopModemLogging();
52 
53   /**
54    * @brief Polls modem logging status property to ensure modem logging has
55    * stopped.
56    *
57    * Even after the property is confirmed to be false, it will continue to
58    * sleep for a second to ensure that the modem_logging_stop service has exited
59    * properly.
60    */
61   void waitForStopModemLogging();
62 
63   /**
64    * @brief Starts modem logging.
65    *
66    * This sets the modem logging property which in turn triggers
67    * modem_logging_control's modem_logging_start service. Modem logging isn't
68    * guaranteed to have started after this call, so it's necessary to poll the
69    * status property to ensure it's started before proceeding to guarantee
70    * success.
71    */
72   void startModemLogging();
73 
74  private:
75   Dumper& dumper_;
76   AndroidPropertyManager& android_property_manager_;
77 };
78 
79 }  // namespace pixel_modem::logging
80