Loading cmds/dumpstate/DumpstateService.cpp +44 −3 Original line number Diff line number Diff line Loading @@ -24,10 +24,31 @@ #include "DumpstateInternal.h" using android::base::StringPrintf; namespace android { namespace os { namespace { static binder::Status exception(uint32_t code, const std::string& msg) { MYLOGE("%s (%d) ", msg.c_str(), code); return binder::Status::fromExceptionCode(code, String8(msg.c_str())); } static binder::Status error(uint32_t code, const std::string& msg) { MYLOGE("%s (%d) ", msg.c_str(), code); return binder::Status::fromServiceSpecificError(code, String8(msg.c_str())); } static void* callAndNotify(void* data) { Dumpstate& ds = *static_cast<Dumpstate*>(data); // TODO(111441001): Return status on listener. ds.Run(); MYLOGE("Finished Run()\n"); return nullptr; } class DumpstateToken : public BnDumpstateToken {}; } Loading Loading @@ -77,10 +98,30 @@ binder::Status DumpstateService::setListener(const std::string& name, return binder::Status::ok(); } binder::Status DumpstateService::startBugreport(int, const sp<IDumpstateListener>&, const DumpstateOptions&, int32_t* returned_id) { // TODO: fork to handle the bugreport request and return the process id or a request id here. binder::Status DumpstateService::startBugreport(int, int bugreport_mode, int32_t* returned_id) { // TODO(111441001): return a request id here. *returned_id = -1; MYLOGI("startBugreport() with mode: %d\n", bugreport_mode); if (bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_FULL && bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE && bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_REMOTE && bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_WEAR && bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_TELEPHONY && bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_WIFI) { return exception(binder::Status::EX_ILLEGAL_ARGUMENT, StringPrintf("Invalid bugreport mode: %d", bugreport_mode)); } std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>(); options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode)); ds_.SetOptions(std::move(options)); pthread_t thread; status_t err = pthread_create(&thread, nullptr, callAndNotify, &ds_); if (err != 0) { return error(err, "Could not create a background thread."); } return binder::Status::ok(); } Loading cmds/dumpstate/DumpstateService.h +1 −2 Original line number Diff line number Diff line Loading @@ -41,8 +41,7 @@ class DumpstateService : public BinderService<DumpstateService>, public BnDumpst bool getSectionDetails, sp<IDumpstateToken>* returned_token) override; binder::Status startBugreport(int fd, const sp<IDumpstateListener>& listener, const DumpstateOptions& options, int32_t* returned_id) override; binder::Status startBugreport(int fd, int bugreport_mode, int32_t* returned_id) override; private: Dumpstate& ds_; Loading cmds/dumpstate/binder/android/os/IDumpstate.aidl +21 −4 Original line number Diff line number Diff line Loading @@ -39,10 +39,27 @@ interface IDumpstate { IDumpstateToken setListener(@utf8InCpp String name, IDumpstateListener listener, boolean getSectionDetails); // These modes encapsulate a set of run time options for generating bugreports. // A zipped bugreport; default mode. const int BUGREPORT_MODE_FULL = 0; // Interactive bugreport, i.e. triggered by the user. const int BUGREPORT_MODE_INTERACTIVE = 1; // Remote bugreport triggered by DevicePolicyManager, for e.g. const int BUGREPORT_MODE_REMOTE = 2; // Bugreport triggered on a wear device. const int BUGREPORT_MODE_WEAR = 3; // Bugreport limited to only telephony info. const int BUGREPORT_MODE_TELEPHONY = 4; // Bugreport limited to only wifi info. const int BUGREPORT_MODE_WIFI = 5; /* * Starts a bugreport in a child process. * * Returns an identifier of the bugreport process running in the background. * Starts a bugreport in the background. */ int startBugreport(int fd, IDumpstateListener listener, in DumpstateOptions options); int startBugreport(int fd, int bugreportMode); } cmds/dumpstate/dumpstate.cpp +115 −17 Original line number Diff line number Diff line Loading @@ -1940,37 +1940,95 @@ static void SendBugreportFinishedBroadcast() { } } // TODO: Move away from system properties when we have options passed via binder calls. /* Sets runtime options from the system properties and then clears those properties. */ static void SetOptionsFromProperties(Dumpstate::DumpOptions* options) { options->extra_options = android::base::GetProperty(PROPERTY_EXTRA_OPTIONS, ""); if (!options->extra_options.empty()) { // Framework uses a system property to override some command-line args. // Currently, it contains the type of the requested bugreport. if (options->extra_options == "bugreportplus") { static inline const char* ModeToString(Dumpstate::BugreportMode mode) { switch (mode) { case Dumpstate::BugreportMode::BUGREPORT_FULL: return "BUGREPORT_FULL"; case Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE: return "BUGREPORT_INTERACTIVE"; case Dumpstate::BugreportMode::BUGREPORT_REMOTE: return "BUGREPORT_REMOTE"; case Dumpstate::BugreportMode::BUGREPORT_WEAR: return "BUGREPORT_WEAR"; case Dumpstate::BugreportMode::BUGREPORT_TELEPHONY: return "BUGREPORT_TELEPHONY"; case Dumpstate::BugreportMode::BUGREPORT_WIFI: return "BUGREPORT_WIFI"; } } static void SetOptionsFromMode(Dumpstate::BugreportMode mode, Dumpstate::DumpOptions* options) { switch (mode) { case Dumpstate::BugreportMode::BUGREPORT_FULL: options->do_broadcast = true; options->do_fb = true; break; case Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE: // Currently, the dumpstate binder is only used by Shell to update progress. options->do_start_service = true; options->do_progress_updates = true; options->do_fb = false; } else if (options->extra_options == "bugreportremote") { options->do_broadcast = true; break; case Dumpstate::BugreportMode::BUGREPORT_REMOTE: options->do_vibrate = false; options->is_remote_mode = true; options->do_fb = false; } else if (options->extra_options == "bugreportwear") { options->do_broadcast = true; break; case Dumpstate::BugreportMode::BUGREPORT_WEAR: options->do_start_service = true; options->do_progress_updates = true; options->do_zip_file = true; } else if (options->extra_options == "bugreporttelephony") { options->do_fb = true; options->do_broadcast = true; break; case Dumpstate::BugreportMode::BUGREPORT_TELEPHONY: options->telephony_only = true; } else if (options->extra_options == "bugreportwifi") { options->do_fb = true; options->do_broadcast = true; break; case Dumpstate::BugreportMode::BUGREPORT_WIFI: options->wifi_only = true; options->do_zip_file = true; options->do_fb = true; options->do_broadcast = true; break; } } static Dumpstate::BugreportMode getBugreportModeFromProperty() { // If the system property is not set, it's assumed to be a full bugreport. Dumpstate::BugreportMode mode = Dumpstate::BugreportMode::BUGREPORT_FULL; std::string extra_options = android::base::GetProperty(PROPERTY_EXTRA_OPTIONS, ""); if (!extra_options.empty()) { // Framework uses a system property to override some command-line args. // Currently, it contains the type of the requested bugreport. if (extra_options == "bugreportplus") { mode = Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE; } else if (extra_options == "bugreportremote") { mode = Dumpstate::BugreportMode::BUGREPORT_REMOTE; } else if (extra_options == "bugreportwear") { mode = Dumpstate::BugreportMode::BUGREPORT_WEAR; } else if (extra_options == "bugreporttelephony") { mode = Dumpstate::BugreportMode::BUGREPORT_TELEPHONY; } else if (extra_options == "bugreportwifi") { mode = Dumpstate::BugreportMode::BUGREPORT_WIFI; } else { MYLOGE("Unknown extra option: %s\n", options->extra_options.c_str()); MYLOGE("Unknown extra option: %s\n", extra_options.c_str()); } // Reset the property android::base::SetProperty(PROPERTY_EXTRA_OPTIONS, ""); } return mode; } // TODO: Move away from system properties when we have options passed via binder calls. /* Sets runtime options from the system properties and then clears those properties. */ static void SetOptionsFromProperties(Dumpstate::DumpOptions* options) { Dumpstate::BugreportMode mode = getBugreportModeFromProperty(); SetOptionsFromMode(mode, options); options->notification_title = android::base::GetProperty(PROPERTY_EXTRA_TITLE, ""); if (!options->notification_title.empty()) { Loading @@ -1988,6 +2046,40 @@ static void SetOptionsFromProperties(Dumpstate::DumpOptions* options) { } } static void LogDumpOptions(const Dumpstate::DumpOptions& options) { MYLOGI("do_zip_file: %d\n", options.do_zip_file); MYLOGI("do_add_date: %d\n", options.do_add_date); MYLOGI("do_vibrate: %d\n", options.do_vibrate); MYLOGI("use_socket: %d\n", options.use_socket); MYLOGI("use_control_socket: %d\n", options.use_control_socket); MYLOGI("do_fb: %d\n", options.do_fb); MYLOGI("do_broadcast: %d\n", options.do_broadcast); MYLOGI("is_remote_mode: %d\n", options.is_remote_mode); MYLOGI("show_header_only: %d\n", options.show_header_only); MYLOGI("do_start_service: %d\n", options.do_start_service); MYLOGI("telephony_only: %d\n", options.telephony_only); MYLOGI("wifi_only: %d\n", options.wifi_only); MYLOGI("do_progress_updates: %d\n", options.do_progress_updates); MYLOGI("use_outfile: %s\n", options.use_outfile.c_str()); MYLOGI("extra_options: %s\n", options.extra_options.c_str()); MYLOGI("args: %s\n", options.args.c_str()); MYLOGI("notification_title: %s\n", options.notification_title.c_str()); MYLOGI("notification_description: %s\n", options.notification_description.c_str()); } void Dumpstate::DumpOptions::Initialize(BugreportMode bugreport_mode) { // In the new API world, date is always added; output is always a zip file. // TODO(111441001): remove these options once they are obsolete. do_add_date = true; do_zip_file = true; // STOPSHIP b/111441001: Remove hardcoded output file path; accept fd. use_outfile = "/data/user_de/0/com.android.shell/files/bugreports/bugreport"; extra_options = ModeToString(bugreport_mode); SetOptionsFromMode(bugreport_mode, this); } Dumpstate::RunStatus Dumpstate::DumpOptions::Initialize(int argc, char* argv[]) { RunStatus status = RunStatus::OK; int c; Loading Loading @@ -2052,11 +2144,16 @@ bool Dumpstate::DumpOptions::ValidateOptions() const { return true; } Dumpstate::RunStatus Dumpstate::RunWithOptions(std::unique_ptr<DumpOptions> options) { if (!options->ValidateOptions()) { void Dumpstate::SetOptions(std::unique_ptr<DumpOptions> options) { options_ = std::move(options); } Dumpstate::RunStatus Dumpstate::Run() { if (!options_->ValidateOptions()) { MYLOGE("Invalid options specified\n"); LogDumpOptions(*options_); return RunStatus::INVALID_INPUT; } options_ = std::move(options); /* set as high priority, and protect from OOM killer */ setpriority(PRIO_PROCESS, 0, -20); Loading Loading @@ -2278,7 +2375,8 @@ int run_main(int argc, char* argv[]) { std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>(); Dumpstate::RunStatus status = options->Initialize(argc, argv); if (status == Dumpstate::RunStatus::OK) { status = ds.RunWithOptions(std::move(options)); ds.SetOptions(std::move(options)); status = ds.Run(); } switch (status) { Loading cmds/dumpstate/dumpstate.h +23 −2 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include <android-base/macros.h> #include <android-base/unique_fd.h> #include <android/os/IDumpstate.h> #include <android/os/IDumpstateListener.h> #include <utils/StrongPointer.h> #include <ziparchive/zip_writer.h> Loading @@ -42,6 +43,9 @@ // TODO: and then remove explicitly android::os::dumpstate:: prefixes namespace android { namespace os { struct DumpstateOptions; namespace dumpstate { class DumpstateTest; Loading Loading @@ -185,6 +189,16 @@ class Dumpstate { public: enum RunStatus { OK, HELP, INVALID_INPUT, ERROR }; // The mode under which the bugreport should be run. Each mode encapsulates a few options. enum BugreportMode { BUGREPORT_FULL = android::os::IDumpstate::BUGREPORT_MODE_FULL, BUGREPORT_INTERACTIVE = android::os::IDumpstate::BUGREPORT_MODE_INTERACTIVE, BUGREPORT_REMOTE = android::os::IDumpstate::BUGREPORT_MODE_REMOTE, BUGREPORT_WEAR = android::os::IDumpstate::BUGREPORT_MODE_WEAR, BUGREPORT_TELEPHONY = android::os::IDumpstate::BUGREPORT_MODE_TELEPHONY, BUGREPORT_WIFI = android::os::IDumpstate::BUGREPORT_MODE_WIFI }; static android::os::dumpstate::CommandOptions DEFAULT_DUMPSYS; static Dumpstate& GetInstance(); Loading Loading @@ -294,8 +308,11 @@ class Dumpstate { struct DumpOptions; /* Main entry point for running a complete bugreport. Takes ownership of options. */ RunStatus RunWithOptions(std::unique_ptr<DumpOptions> options); /* Main entry point for running a complete bugreport. */ RunStatus Run(); /* Sets runtime options. */ void SetOptions(std::unique_ptr<DumpOptions> options); // TODO: add other options from DumpState. /* Loading @@ -317,6 +334,7 @@ class Dumpstate { // Whether progress updates should be published. bool do_progress_updates = false; std::string use_outfile; // TODO: rename to MODE. // Extra options passed as system property. std::string extra_options; // Command-line arguments as string Loading @@ -328,6 +346,9 @@ class Dumpstate { /* Initializes options from commandline arguments and system properties. */ RunStatus Initialize(int argc, char* argv[]); /* Initializes options from the requested mode. */ void Initialize(BugreportMode bugreport_mode); /* Returns true if the options set so far are consistent. */ bool ValidateOptions() const; }; Loading Loading
cmds/dumpstate/DumpstateService.cpp +44 −3 Original line number Diff line number Diff line Loading @@ -24,10 +24,31 @@ #include "DumpstateInternal.h" using android::base::StringPrintf; namespace android { namespace os { namespace { static binder::Status exception(uint32_t code, const std::string& msg) { MYLOGE("%s (%d) ", msg.c_str(), code); return binder::Status::fromExceptionCode(code, String8(msg.c_str())); } static binder::Status error(uint32_t code, const std::string& msg) { MYLOGE("%s (%d) ", msg.c_str(), code); return binder::Status::fromServiceSpecificError(code, String8(msg.c_str())); } static void* callAndNotify(void* data) { Dumpstate& ds = *static_cast<Dumpstate*>(data); // TODO(111441001): Return status on listener. ds.Run(); MYLOGE("Finished Run()\n"); return nullptr; } class DumpstateToken : public BnDumpstateToken {}; } Loading Loading @@ -77,10 +98,30 @@ binder::Status DumpstateService::setListener(const std::string& name, return binder::Status::ok(); } binder::Status DumpstateService::startBugreport(int, const sp<IDumpstateListener>&, const DumpstateOptions&, int32_t* returned_id) { // TODO: fork to handle the bugreport request and return the process id or a request id here. binder::Status DumpstateService::startBugreport(int, int bugreport_mode, int32_t* returned_id) { // TODO(111441001): return a request id here. *returned_id = -1; MYLOGI("startBugreport() with mode: %d\n", bugreport_mode); if (bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_FULL && bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE && bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_REMOTE && bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_WEAR && bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_TELEPHONY && bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_WIFI) { return exception(binder::Status::EX_ILLEGAL_ARGUMENT, StringPrintf("Invalid bugreport mode: %d", bugreport_mode)); } std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>(); options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode)); ds_.SetOptions(std::move(options)); pthread_t thread; status_t err = pthread_create(&thread, nullptr, callAndNotify, &ds_); if (err != 0) { return error(err, "Could not create a background thread."); } return binder::Status::ok(); } Loading
cmds/dumpstate/DumpstateService.h +1 −2 Original line number Diff line number Diff line Loading @@ -41,8 +41,7 @@ class DumpstateService : public BinderService<DumpstateService>, public BnDumpst bool getSectionDetails, sp<IDumpstateToken>* returned_token) override; binder::Status startBugreport(int fd, const sp<IDumpstateListener>& listener, const DumpstateOptions& options, int32_t* returned_id) override; binder::Status startBugreport(int fd, int bugreport_mode, int32_t* returned_id) override; private: Dumpstate& ds_; Loading
cmds/dumpstate/binder/android/os/IDumpstate.aidl +21 −4 Original line number Diff line number Diff line Loading @@ -39,10 +39,27 @@ interface IDumpstate { IDumpstateToken setListener(@utf8InCpp String name, IDumpstateListener listener, boolean getSectionDetails); // These modes encapsulate a set of run time options for generating bugreports. // A zipped bugreport; default mode. const int BUGREPORT_MODE_FULL = 0; // Interactive bugreport, i.e. triggered by the user. const int BUGREPORT_MODE_INTERACTIVE = 1; // Remote bugreport triggered by DevicePolicyManager, for e.g. const int BUGREPORT_MODE_REMOTE = 2; // Bugreport triggered on a wear device. const int BUGREPORT_MODE_WEAR = 3; // Bugreport limited to only telephony info. const int BUGREPORT_MODE_TELEPHONY = 4; // Bugreport limited to only wifi info. const int BUGREPORT_MODE_WIFI = 5; /* * Starts a bugreport in a child process. * * Returns an identifier of the bugreport process running in the background. * Starts a bugreport in the background. */ int startBugreport(int fd, IDumpstateListener listener, in DumpstateOptions options); int startBugreport(int fd, int bugreportMode); }
cmds/dumpstate/dumpstate.cpp +115 −17 Original line number Diff line number Diff line Loading @@ -1940,37 +1940,95 @@ static void SendBugreportFinishedBroadcast() { } } // TODO: Move away from system properties when we have options passed via binder calls. /* Sets runtime options from the system properties and then clears those properties. */ static void SetOptionsFromProperties(Dumpstate::DumpOptions* options) { options->extra_options = android::base::GetProperty(PROPERTY_EXTRA_OPTIONS, ""); if (!options->extra_options.empty()) { // Framework uses a system property to override some command-line args. // Currently, it contains the type of the requested bugreport. if (options->extra_options == "bugreportplus") { static inline const char* ModeToString(Dumpstate::BugreportMode mode) { switch (mode) { case Dumpstate::BugreportMode::BUGREPORT_FULL: return "BUGREPORT_FULL"; case Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE: return "BUGREPORT_INTERACTIVE"; case Dumpstate::BugreportMode::BUGREPORT_REMOTE: return "BUGREPORT_REMOTE"; case Dumpstate::BugreportMode::BUGREPORT_WEAR: return "BUGREPORT_WEAR"; case Dumpstate::BugreportMode::BUGREPORT_TELEPHONY: return "BUGREPORT_TELEPHONY"; case Dumpstate::BugreportMode::BUGREPORT_WIFI: return "BUGREPORT_WIFI"; } } static void SetOptionsFromMode(Dumpstate::BugreportMode mode, Dumpstate::DumpOptions* options) { switch (mode) { case Dumpstate::BugreportMode::BUGREPORT_FULL: options->do_broadcast = true; options->do_fb = true; break; case Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE: // Currently, the dumpstate binder is only used by Shell to update progress. options->do_start_service = true; options->do_progress_updates = true; options->do_fb = false; } else if (options->extra_options == "bugreportremote") { options->do_broadcast = true; break; case Dumpstate::BugreportMode::BUGREPORT_REMOTE: options->do_vibrate = false; options->is_remote_mode = true; options->do_fb = false; } else if (options->extra_options == "bugreportwear") { options->do_broadcast = true; break; case Dumpstate::BugreportMode::BUGREPORT_WEAR: options->do_start_service = true; options->do_progress_updates = true; options->do_zip_file = true; } else if (options->extra_options == "bugreporttelephony") { options->do_fb = true; options->do_broadcast = true; break; case Dumpstate::BugreportMode::BUGREPORT_TELEPHONY: options->telephony_only = true; } else if (options->extra_options == "bugreportwifi") { options->do_fb = true; options->do_broadcast = true; break; case Dumpstate::BugreportMode::BUGREPORT_WIFI: options->wifi_only = true; options->do_zip_file = true; options->do_fb = true; options->do_broadcast = true; break; } } static Dumpstate::BugreportMode getBugreportModeFromProperty() { // If the system property is not set, it's assumed to be a full bugreport. Dumpstate::BugreportMode mode = Dumpstate::BugreportMode::BUGREPORT_FULL; std::string extra_options = android::base::GetProperty(PROPERTY_EXTRA_OPTIONS, ""); if (!extra_options.empty()) { // Framework uses a system property to override some command-line args. // Currently, it contains the type of the requested bugreport. if (extra_options == "bugreportplus") { mode = Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE; } else if (extra_options == "bugreportremote") { mode = Dumpstate::BugreportMode::BUGREPORT_REMOTE; } else if (extra_options == "bugreportwear") { mode = Dumpstate::BugreportMode::BUGREPORT_WEAR; } else if (extra_options == "bugreporttelephony") { mode = Dumpstate::BugreportMode::BUGREPORT_TELEPHONY; } else if (extra_options == "bugreportwifi") { mode = Dumpstate::BugreportMode::BUGREPORT_WIFI; } else { MYLOGE("Unknown extra option: %s\n", options->extra_options.c_str()); MYLOGE("Unknown extra option: %s\n", extra_options.c_str()); } // Reset the property android::base::SetProperty(PROPERTY_EXTRA_OPTIONS, ""); } return mode; } // TODO: Move away from system properties when we have options passed via binder calls. /* Sets runtime options from the system properties and then clears those properties. */ static void SetOptionsFromProperties(Dumpstate::DumpOptions* options) { Dumpstate::BugreportMode mode = getBugreportModeFromProperty(); SetOptionsFromMode(mode, options); options->notification_title = android::base::GetProperty(PROPERTY_EXTRA_TITLE, ""); if (!options->notification_title.empty()) { Loading @@ -1988,6 +2046,40 @@ static void SetOptionsFromProperties(Dumpstate::DumpOptions* options) { } } static void LogDumpOptions(const Dumpstate::DumpOptions& options) { MYLOGI("do_zip_file: %d\n", options.do_zip_file); MYLOGI("do_add_date: %d\n", options.do_add_date); MYLOGI("do_vibrate: %d\n", options.do_vibrate); MYLOGI("use_socket: %d\n", options.use_socket); MYLOGI("use_control_socket: %d\n", options.use_control_socket); MYLOGI("do_fb: %d\n", options.do_fb); MYLOGI("do_broadcast: %d\n", options.do_broadcast); MYLOGI("is_remote_mode: %d\n", options.is_remote_mode); MYLOGI("show_header_only: %d\n", options.show_header_only); MYLOGI("do_start_service: %d\n", options.do_start_service); MYLOGI("telephony_only: %d\n", options.telephony_only); MYLOGI("wifi_only: %d\n", options.wifi_only); MYLOGI("do_progress_updates: %d\n", options.do_progress_updates); MYLOGI("use_outfile: %s\n", options.use_outfile.c_str()); MYLOGI("extra_options: %s\n", options.extra_options.c_str()); MYLOGI("args: %s\n", options.args.c_str()); MYLOGI("notification_title: %s\n", options.notification_title.c_str()); MYLOGI("notification_description: %s\n", options.notification_description.c_str()); } void Dumpstate::DumpOptions::Initialize(BugreportMode bugreport_mode) { // In the new API world, date is always added; output is always a zip file. // TODO(111441001): remove these options once they are obsolete. do_add_date = true; do_zip_file = true; // STOPSHIP b/111441001: Remove hardcoded output file path; accept fd. use_outfile = "/data/user_de/0/com.android.shell/files/bugreports/bugreport"; extra_options = ModeToString(bugreport_mode); SetOptionsFromMode(bugreport_mode, this); } Dumpstate::RunStatus Dumpstate::DumpOptions::Initialize(int argc, char* argv[]) { RunStatus status = RunStatus::OK; int c; Loading Loading @@ -2052,11 +2144,16 @@ bool Dumpstate::DumpOptions::ValidateOptions() const { return true; } Dumpstate::RunStatus Dumpstate::RunWithOptions(std::unique_ptr<DumpOptions> options) { if (!options->ValidateOptions()) { void Dumpstate::SetOptions(std::unique_ptr<DumpOptions> options) { options_ = std::move(options); } Dumpstate::RunStatus Dumpstate::Run() { if (!options_->ValidateOptions()) { MYLOGE("Invalid options specified\n"); LogDumpOptions(*options_); return RunStatus::INVALID_INPUT; } options_ = std::move(options); /* set as high priority, and protect from OOM killer */ setpriority(PRIO_PROCESS, 0, -20); Loading Loading @@ -2278,7 +2375,8 @@ int run_main(int argc, char* argv[]) { std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>(); Dumpstate::RunStatus status = options->Initialize(argc, argv); if (status == Dumpstate::RunStatus::OK) { status = ds.RunWithOptions(std::move(options)); ds.SetOptions(std::move(options)); status = ds.Run(); } switch (status) { Loading
cmds/dumpstate/dumpstate.h +23 −2 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include <android-base/macros.h> #include <android-base/unique_fd.h> #include <android/os/IDumpstate.h> #include <android/os/IDumpstateListener.h> #include <utils/StrongPointer.h> #include <ziparchive/zip_writer.h> Loading @@ -42,6 +43,9 @@ // TODO: and then remove explicitly android::os::dumpstate:: prefixes namespace android { namespace os { struct DumpstateOptions; namespace dumpstate { class DumpstateTest; Loading Loading @@ -185,6 +189,16 @@ class Dumpstate { public: enum RunStatus { OK, HELP, INVALID_INPUT, ERROR }; // The mode under which the bugreport should be run. Each mode encapsulates a few options. enum BugreportMode { BUGREPORT_FULL = android::os::IDumpstate::BUGREPORT_MODE_FULL, BUGREPORT_INTERACTIVE = android::os::IDumpstate::BUGREPORT_MODE_INTERACTIVE, BUGREPORT_REMOTE = android::os::IDumpstate::BUGREPORT_MODE_REMOTE, BUGREPORT_WEAR = android::os::IDumpstate::BUGREPORT_MODE_WEAR, BUGREPORT_TELEPHONY = android::os::IDumpstate::BUGREPORT_MODE_TELEPHONY, BUGREPORT_WIFI = android::os::IDumpstate::BUGREPORT_MODE_WIFI }; static android::os::dumpstate::CommandOptions DEFAULT_DUMPSYS; static Dumpstate& GetInstance(); Loading Loading @@ -294,8 +308,11 @@ class Dumpstate { struct DumpOptions; /* Main entry point for running a complete bugreport. Takes ownership of options. */ RunStatus RunWithOptions(std::unique_ptr<DumpOptions> options); /* Main entry point for running a complete bugreport. */ RunStatus Run(); /* Sets runtime options. */ void SetOptions(std::unique_ptr<DumpOptions> options); // TODO: add other options from DumpState. /* Loading @@ -317,6 +334,7 @@ class Dumpstate { // Whether progress updates should be published. bool do_progress_updates = false; std::string use_outfile; // TODO: rename to MODE. // Extra options passed as system property. std::string extra_options; // Command-line arguments as string Loading @@ -328,6 +346,9 @@ class Dumpstate { /* Initializes options from commandline arguments and system properties. */ RunStatus Initialize(int argc, char* argv[]); /* Initializes options from the requested mode. */ void Initialize(BugreportMode bugreport_mode); /* Returns true if the options set so far are consistent. */ bool ValidateOptions() const; }; Loading