Loading cmds/dumpstate/DumpstateService.cpp +49 −35 Original line number Original line Diff line number Diff line Loading @@ -59,7 +59,7 @@ class DumpstateToken : public BnDumpstateToken {}; } // namespace } // namespace DumpstateService::DumpstateService() : ds_(Dumpstate::GetInstance()) { DumpstateService::DumpstateService() : ds_(nullptr) { } } char const* DumpstateService::getServiceName() { char const* DumpstateService::getServiceName() { Loading @@ -78,6 +78,8 @@ status_t DumpstateService::Start() { return android::OK; return android::OK; } } // Note: this method is part of the old flow and is not expected to be used in combination // with startBugreport. binder::Status DumpstateService::setListener(const std::string& name, binder::Status DumpstateService::setListener(const std::string& name, const sp<IDumpstateListener>& listener, const sp<IDumpstateListener>& listener, bool getSectionDetails, bool getSectionDetails, Loading @@ -92,20 +94,22 @@ binder::Status DumpstateService::setListener(const std::string& name, return binder::Status::ok(); return binder::Status::ok(); } } std::lock_guard<std::mutex> lock(lock_); std::lock_guard<std::mutex> lock(lock_); if (ds_.listener_ != nullptr) { if (ds_ == nullptr) { MYLOGE("setListener(%s): already set (%s)\n", name.c_str(), ds_.listener_name_.c_str()); ds_ = &(Dumpstate::GetInstance()); } if (ds_->listener_ != nullptr) { MYLOGE("setListener(%s): already set (%s)\n", name.c_str(), ds_->listener_name_.c_str()); return binder::Status::ok(); return binder::Status::ok(); } } ds_.listener_name_ = name; ds_->listener_name_ = name; ds_.listener_ = listener; ds_->listener_ = listener; ds_.report_section_ = getSectionDetails; ds_->report_section_ = getSectionDetails; *returned_token = new DumpstateToken(); *returned_token = new DumpstateToken(); return binder::Status::ok(); return binder::Status::ok(); } } // TODO(b/111441001): Hook up to consent service & copy final br only if user approves. binder::Status DumpstateService::startBugreport(int32_t calling_uid, binder::Status DumpstateService::startBugreport(int32_t calling_uid, const std::string& calling_package, const std::string& calling_package, const android::base::unique_fd& bugreport_fd, const android::base::unique_fd& bugreport_fd, Loading Loading @@ -133,15 +137,21 @@ binder::Status DumpstateService::startBugreport(int32_t calling_uid, options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode), bugreport_fd, options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode), bugreport_fd, screenshot_fd); screenshot_fd); // This is the bugreporting API flow, so ensure there is only one bugreport in progress at a // time. std::lock_guard<std::mutex> lock(lock_); std::lock_guard<std::mutex> lock(lock_); // TODO(b/111441001): Disallow multiple simultaneous bugreports. if (ds_ != nullptr) { ds_.SetOptions(std::move(options)); return exception(binder::Status::EX_SERVICE_SPECIFIC, "There is already a bugreport in progress"); } ds_ = &(Dumpstate::GetInstance()); ds_->SetOptions(std::move(options)); if (listener != nullptr) { if (listener != nullptr) { ds_.listener_ = listener; ds_->listener_ = listener; } } DumpstateInfo ds_info; DumpstateInfo ds_info; ds_info.ds = &ds_; ds_info.ds = ds_; ds_info.calling_uid = calling_uid; ds_info.calling_uid = calling_uid; ds_info.calling_package = calling_package; ds_info.calling_package = calling_package; Loading @@ -162,32 +172,36 @@ binder::Status DumpstateService::cancelBugreport() { } } status_t DumpstateService::dump(int fd, const Vector<String16>&) { status_t DumpstateService::dump(int fd, const Vector<String16>&) { std::string destination = ds_.options_->bugreport_fd.get() != -1 if (ds_ == nullptr) { ? StringPrintf("[fd:%d]", ds_.options_->bugreport_fd.get()) dprintf(fd, "Bugreport not in progress yet"); : ds_.bugreport_internal_dir_.c_str(); return NO_ERROR; dprintf(fd, "id: %d\n", ds_.id_); } dprintf(fd, "pid: %d\n", ds_.pid_); std::string destination = ds_->options_->bugreport_fd.get() != -1 dprintf(fd, "update_progress: %s\n", ds_.options_->do_progress_updates ? "true" : "false"); ? StringPrintf("[fd:%d]", ds_->options_->bugreport_fd.get()) dprintf(fd, "update_progress_threshold: %d\n", ds_.update_progress_threshold_); : ds_->bugreport_internal_dir_.c_str(); dprintf(fd, "last_updated_progress: %d\n", ds_.last_updated_progress_); dprintf(fd, "id: %d\n", ds_->id_); dprintf(fd, "pid: %d\n", ds_->pid_); dprintf(fd, "update_progress: %s\n", ds_->options_->do_progress_updates ? "true" : "false"); dprintf(fd, "update_progress_threshold: %d\n", ds_->update_progress_threshold_); dprintf(fd, "last_updated_progress: %d\n", ds_->last_updated_progress_); dprintf(fd, "progress:\n"); dprintf(fd, "progress:\n"); ds_.progress_->Dump(fd, " "); ds_->progress_->Dump(fd, " "); dprintf(fd, "args: %s\n", ds_.options_->args.c_str()); dprintf(fd, "args: %s\n", ds_->options_->args.c_str()); dprintf(fd, "extra_options: %s\n", ds_.options_->extra_options.c_str()); dprintf(fd, "extra_options: %s\n", ds_->options_->extra_options.c_str()); dprintf(fd, "version: %s\n", ds_.version_.c_str()); dprintf(fd, "version: %s\n", ds_->version_.c_str()); dprintf(fd, "bugreport_dir: %s\n", destination.c_str()); dprintf(fd, "bugreport_dir: %s\n", destination.c_str()); dprintf(fd, "screenshot_path: %s\n", ds_.screenshot_path_.c_str()); dprintf(fd, "screenshot_path: %s\n", ds_->screenshot_path_.c_str()); dprintf(fd, "log_path: %s\n", ds_.log_path_.c_str()); dprintf(fd, "log_path: %s\n", ds_->log_path_.c_str()); dprintf(fd, "tmp_path: %s\n", ds_.tmp_path_.c_str()); dprintf(fd, "tmp_path: %s\n", ds_->tmp_path_.c_str()); dprintf(fd, "path: %s\n", ds_.path_.c_str()); dprintf(fd, "path: %s\n", ds_->path_.c_str()); dprintf(fd, "extra_options: %s\n", ds_.options_->extra_options.c_str()); dprintf(fd, "extra_options: %s\n", ds_->options_->extra_options.c_str()); dprintf(fd, "base_name: %s\n", ds_.base_name_.c_str()); dprintf(fd, "base_name: %s\n", ds_->base_name_.c_str()); dprintf(fd, "name: %s\n", ds_.name_.c_str()); dprintf(fd, "name: %s\n", ds_->name_.c_str()); dprintf(fd, "now: %ld\n", ds_.now_); dprintf(fd, "now: %ld\n", ds_->now_); dprintf(fd, "is_zipping: %s\n", ds_.IsZipping() ? "true" : "false"); dprintf(fd, "is_zipping: %s\n", ds_->IsZipping() ? "true" : "false"); dprintf(fd, "listener: %s\n", ds_.listener_name_.c_str()); dprintf(fd, "listener: %s\n", ds_->listener_name_.c_str()); dprintf(fd, "notification title: %s\n", ds_.options_->notification_title.c_str()); dprintf(fd, "notification title: %s\n", ds_->options_->notification_title.c_str()); dprintf(fd, "notification description: %s\n", ds_.options_->notification_description.c_str()); dprintf(fd, "notification description: %s\n", ds_->options_->notification_description.c_str()); return NO_ERROR; return NO_ERROR; } } Loading cmds/dumpstate/DumpstateService.h +5 −1 Original line number Original line Diff line number Diff line Loading @@ -51,7 +51,11 @@ class DumpstateService : public BinderService<DumpstateService>, public BnDumpst binder::Status cancelBugreport(); binder::Status cancelBugreport(); private: private: Dumpstate& ds_; // Dumpstate object which contains all the bugreporting logic. // Note that dumpstate is a oneshot service, so this object is meant to be used at most for // one bugreport. // This service does not own this object. Dumpstate* ds_; std::mutex lock_; std::mutex lock_; }; }; Loading Loading
cmds/dumpstate/DumpstateService.cpp +49 −35 Original line number Original line Diff line number Diff line Loading @@ -59,7 +59,7 @@ class DumpstateToken : public BnDumpstateToken {}; } // namespace } // namespace DumpstateService::DumpstateService() : ds_(Dumpstate::GetInstance()) { DumpstateService::DumpstateService() : ds_(nullptr) { } } char const* DumpstateService::getServiceName() { char const* DumpstateService::getServiceName() { Loading @@ -78,6 +78,8 @@ status_t DumpstateService::Start() { return android::OK; return android::OK; } } // Note: this method is part of the old flow and is not expected to be used in combination // with startBugreport. binder::Status DumpstateService::setListener(const std::string& name, binder::Status DumpstateService::setListener(const std::string& name, const sp<IDumpstateListener>& listener, const sp<IDumpstateListener>& listener, bool getSectionDetails, bool getSectionDetails, Loading @@ -92,20 +94,22 @@ binder::Status DumpstateService::setListener(const std::string& name, return binder::Status::ok(); return binder::Status::ok(); } } std::lock_guard<std::mutex> lock(lock_); std::lock_guard<std::mutex> lock(lock_); if (ds_.listener_ != nullptr) { if (ds_ == nullptr) { MYLOGE("setListener(%s): already set (%s)\n", name.c_str(), ds_.listener_name_.c_str()); ds_ = &(Dumpstate::GetInstance()); } if (ds_->listener_ != nullptr) { MYLOGE("setListener(%s): already set (%s)\n", name.c_str(), ds_->listener_name_.c_str()); return binder::Status::ok(); return binder::Status::ok(); } } ds_.listener_name_ = name; ds_->listener_name_ = name; ds_.listener_ = listener; ds_->listener_ = listener; ds_.report_section_ = getSectionDetails; ds_->report_section_ = getSectionDetails; *returned_token = new DumpstateToken(); *returned_token = new DumpstateToken(); return binder::Status::ok(); return binder::Status::ok(); } } // TODO(b/111441001): Hook up to consent service & copy final br only if user approves. binder::Status DumpstateService::startBugreport(int32_t calling_uid, binder::Status DumpstateService::startBugreport(int32_t calling_uid, const std::string& calling_package, const std::string& calling_package, const android::base::unique_fd& bugreport_fd, const android::base::unique_fd& bugreport_fd, Loading Loading @@ -133,15 +137,21 @@ binder::Status DumpstateService::startBugreport(int32_t calling_uid, options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode), bugreport_fd, options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode), bugreport_fd, screenshot_fd); screenshot_fd); // This is the bugreporting API flow, so ensure there is only one bugreport in progress at a // time. std::lock_guard<std::mutex> lock(lock_); std::lock_guard<std::mutex> lock(lock_); // TODO(b/111441001): Disallow multiple simultaneous bugreports. if (ds_ != nullptr) { ds_.SetOptions(std::move(options)); return exception(binder::Status::EX_SERVICE_SPECIFIC, "There is already a bugreport in progress"); } ds_ = &(Dumpstate::GetInstance()); ds_->SetOptions(std::move(options)); if (listener != nullptr) { if (listener != nullptr) { ds_.listener_ = listener; ds_->listener_ = listener; } } DumpstateInfo ds_info; DumpstateInfo ds_info; ds_info.ds = &ds_; ds_info.ds = ds_; ds_info.calling_uid = calling_uid; ds_info.calling_uid = calling_uid; ds_info.calling_package = calling_package; ds_info.calling_package = calling_package; Loading @@ -162,32 +172,36 @@ binder::Status DumpstateService::cancelBugreport() { } } status_t DumpstateService::dump(int fd, const Vector<String16>&) { status_t DumpstateService::dump(int fd, const Vector<String16>&) { std::string destination = ds_.options_->bugreport_fd.get() != -1 if (ds_ == nullptr) { ? StringPrintf("[fd:%d]", ds_.options_->bugreport_fd.get()) dprintf(fd, "Bugreport not in progress yet"); : ds_.bugreport_internal_dir_.c_str(); return NO_ERROR; dprintf(fd, "id: %d\n", ds_.id_); } dprintf(fd, "pid: %d\n", ds_.pid_); std::string destination = ds_->options_->bugreport_fd.get() != -1 dprintf(fd, "update_progress: %s\n", ds_.options_->do_progress_updates ? "true" : "false"); ? StringPrintf("[fd:%d]", ds_->options_->bugreport_fd.get()) dprintf(fd, "update_progress_threshold: %d\n", ds_.update_progress_threshold_); : ds_->bugreport_internal_dir_.c_str(); dprintf(fd, "last_updated_progress: %d\n", ds_.last_updated_progress_); dprintf(fd, "id: %d\n", ds_->id_); dprintf(fd, "pid: %d\n", ds_->pid_); dprintf(fd, "update_progress: %s\n", ds_->options_->do_progress_updates ? "true" : "false"); dprintf(fd, "update_progress_threshold: %d\n", ds_->update_progress_threshold_); dprintf(fd, "last_updated_progress: %d\n", ds_->last_updated_progress_); dprintf(fd, "progress:\n"); dprintf(fd, "progress:\n"); ds_.progress_->Dump(fd, " "); ds_->progress_->Dump(fd, " "); dprintf(fd, "args: %s\n", ds_.options_->args.c_str()); dprintf(fd, "args: %s\n", ds_->options_->args.c_str()); dprintf(fd, "extra_options: %s\n", ds_.options_->extra_options.c_str()); dprintf(fd, "extra_options: %s\n", ds_->options_->extra_options.c_str()); dprintf(fd, "version: %s\n", ds_.version_.c_str()); dprintf(fd, "version: %s\n", ds_->version_.c_str()); dprintf(fd, "bugreport_dir: %s\n", destination.c_str()); dprintf(fd, "bugreport_dir: %s\n", destination.c_str()); dprintf(fd, "screenshot_path: %s\n", ds_.screenshot_path_.c_str()); dprintf(fd, "screenshot_path: %s\n", ds_->screenshot_path_.c_str()); dprintf(fd, "log_path: %s\n", ds_.log_path_.c_str()); dprintf(fd, "log_path: %s\n", ds_->log_path_.c_str()); dprintf(fd, "tmp_path: %s\n", ds_.tmp_path_.c_str()); dprintf(fd, "tmp_path: %s\n", ds_->tmp_path_.c_str()); dprintf(fd, "path: %s\n", ds_.path_.c_str()); dprintf(fd, "path: %s\n", ds_->path_.c_str()); dprintf(fd, "extra_options: %s\n", ds_.options_->extra_options.c_str()); dprintf(fd, "extra_options: %s\n", ds_->options_->extra_options.c_str()); dprintf(fd, "base_name: %s\n", ds_.base_name_.c_str()); dprintf(fd, "base_name: %s\n", ds_->base_name_.c_str()); dprintf(fd, "name: %s\n", ds_.name_.c_str()); dprintf(fd, "name: %s\n", ds_->name_.c_str()); dprintf(fd, "now: %ld\n", ds_.now_); dprintf(fd, "now: %ld\n", ds_->now_); dprintf(fd, "is_zipping: %s\n", ds_.IsZipping() ? "true" : "false"); dprintf(fd, "is_zipping: %s\n", ds_->IsZipping() ? "true" : "false"); dprintf(fd, "listener: %s\n", ds_.listener_name_.c_str()); dprintf(fd, "listener: %s\n", ds_->listener_name_.c_str()); dprintf(fd, "notification title: %s\n", ds_.options_->notification_title.c_str()); dprintf(fd, "notification title: %s\n", ds_->options_->notification_title.c_str()); dprintf(fd, "notification description: %s\n", ds_.options_->notification_description.c_str()); dprintf(fd, "notification description: %s\n", ds_->options_->notification_description.c_str()); return NO_ERROR; return NO_ERROR; } } Loading
cmds/dumpstate/DumpstateService.h +5 −1 Original line number Original line Diff line number Diff line Loading @@ -51,7 +51,11 @@ class DumpstateService : public BinderService<DumpstateService>, public BnDumpst binder::Status cancelBugreport(); binder::Status cancelBugreport(); private: private: Dumpstate& ds_; // Dumpstate object which contains all the bugreporting logic. // Note that dumpstate is a oneshot service, so this object is meant to be used at most for // one bugreport. // This service does not own this object. Dumpstate* ds_; std::mutex lock_; std::mutex lock_; }; }; Loading