Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bb45d3c3 authored by Nandana Dutt's avatar Nandana Dutt Committed by android-build-merger
Browse files

Merge "Wire up new binder method arguments"

am: 61cb76e7

Change-Id: Id2cb6e6c51d13aff9c65345c4f651976d57fe114
parents 72c3e195 61cb76e7
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -98,11 +98,10 @@ binder::Status DumpstateService::setListener(const std::string& name,
    return binder::Status::ok();
}

binder::Status DumpstateService::startBugreport(const android::base::unique_fd& /* bugreportFd */,
                                                const android::base::unique_fd& /* screenshotFd */,
binder::Status DumpstateService::startBugreport(const android::base::unique_fd& bugreport_fd,
                                                const android::base::unique_fd& screenshot_fd,
                                                int bugreport_mode,
                                                const sp<IDumpstateListener>& /* listener */) {
    // TODO(b/111441001): Pass in fds & other arguments to DumpOptions.
                                                const sp<IDumpstateListener>& listener) {
    MYLOGI("startBugreport() with mode: %d\n", bugreport_mode);

    if (bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_FULL &&
@@ -116,9 +115,20 @@ binder::Status DumpstateService::startBugreport(const android::base::unique_fd&
                         StringPrintf("Invalid bugreport mode: %d", bugreport_mode));
    }

    if (bugreport_fd.get() == -1 || screenshot_fd.get() == -1) {
        return exception(binder::Status::EX_ILLEGAL_ARGUMENT, "Invalid file descriptor");
    }

    std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>();
    options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode));
    options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode), bugreport_fd,
                        screenshot_fd);

    std::lock_guard<std::mutex> lock(lock_);
    // TODO(b/111441001): Disallow multiple simultaneous bugreports.
    ds_.SetOptions(std::move(options));
    if (listener != nullptr) {
        ds_.listener_ = listener;
    }

    pthread_t thread;
    status_t err = pthread_create(&thread, nullptr, callAndNotify, &ds_);
+2 −2
Original line number Diff line number Diff line
@@ -42,8 +42,8 @@ class DumpstateService : public BinderService<DumpstateService>, public BnDumpst
                               bool getSectionDetails,
                               sp<IDumpstateToken>* returned_token) override;

    binder::Status startBugreport(const android::base::unique_fd& bugreportFd,
                                  const android::base::unique_fd& screenshotFd, int bugreport_mode,
    binder::Status startBugreport(const android::base::unique_fd& bugreport_fd,
                                  const android::base::unique_fd& screenshot_fd, int bugreport_mode,
                                  const sp<IDumpstateListener>& listener) override;

  private:
+14 −10
Original line number Diff line number Diff line
@@ -1875,7 +1875,8 @@ static void PrepareToWriteToFile() {
    ds.tmp_path_ = ds.GetPath(".tmp");
    ds.log_path_ = ds.GetPath("-dumpstate_log-" + std::to_string(ds.pid_) + ".txt");

    std::string destination = ds.options_->fd != -1 ? StringPrintf("[fd:%d]", ds.options_->fd)
    std::string destination = ds.options_->bugreport_fd.get() != -1
                                  ? StringPrintf("[fd:%d]", ds.options_->bugreport_fd.get())
                                  : ds.bugreport_dir_.c_str();
    MYLOGD(
        "Bugreport dir: %s\n"
@@ -1954,8 +1955,8 @@ static void FinalizeFile() {
            }
            // The zip file lives in an internal directory. Copy it over to output.
            bool copy_succeeded = false;
            if (ds.options_->fd != -1) {
                copy_succeeded = android::os::CopyFileToFd(ds.path_, ds.options_->fd);
            if (ds.options_->bugreport_fd.get() != -1) {
                copy_succeeded = android::os::CopyFileToFd(ds.path_, ds.options_->bugreport_fd.get());
            } else {
                ds.final_path_ = ds.GetPath(ds.bugreport_dir_, ".zip");
                copy_succeeded = android::os::CopyFileToFile(ds.path_, ds.final_path_);
@@ -2158,7 +2159,7 @@ static void LogDumpOptions(const Dumpstate::DumpOptions& options) {
    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("fd: %d\n", options.fd);
    MYLOGI("fd: %d\n", options.bugreport_fd.get());
    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());
@@ -2166,14 +2167,17 @@ static void LogDumpOptions(const Dumpstate::DumpOptions& options) {
    MYLOGI("notification_description: %s\n", options.notification_description.c_str());
}

void Dumpstate::DumpOptions::Initialize(BugreportMode bugreport_mode) {
void Dumpstate::DumpOptions::Initialize(BugreportMode bugreport_mode,
                                        const android::base::unique_fd& bugreport_fd_in,
                                        const android::base::unique_fd& screenshot_fd_in) {
    // 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";
    // Duplicate the fds because the passed in fds don't outlive the binder transaction.
    bugreport_fd.reset(dup(bugreport_fd_in.get()));
    screenshot_fd.reset(dup(screenshot_fd_in.get()));

    extra_options = ModeToString(bugreport_mode);
    SetOptionsFromMode(bugreport_mode, this);
@@ -2224,11 +2228,11 @@ Dumpstate::RunStatus Dumpstate::DumpOptions::Initialize(int argc, char* argv[])
}

bool Dumpstate::DumpOptions::ValidateOptions() const {
    if (fd != -1 && !do_zip_file) {
    if (bugreport_fd.get() != -1 && !do_zip_file) {
        return false;
    }

    bool has_out_file_options = !use_outfile.empty() || fd != -1;
    bool has_out_file_options = !use_outfile.empty() || bugreport_fd.get() != -1;
    if ((do_zip_file || do_add_date || do_progress_updates || do_broadcast) &&
        !has_out_file_options) {
        return false;
+7 −4
Original line number Diff line number Diff line
@@ -342,9 +342,11 @@ class Dumpstate {
        bool wifi_only = false;
        // Whether progress updates should be published.
        bool do_progress_updates = false;
        // File descriptor to output zip file. -1 indicates not set. Takes precedence over
        // use_outfile.
        int fd = -1;
        // File descriptor to output zip file. Takes precedence over use_outfile.
        android::base::unique_fd bugreport_fd;
        // File descriptor to screenshot file.
        // TODO(b/111441001): Use this fd.
        android::base::unique_fd screenshot_fd;
        // Partial path to output file.
        std::string use_outfile;
        // TODO: rename to MODE.
@@ -360,7 +362,8 @@ class Dumpstate {
        RunStatus Initialize(int argc, char* argv[]);

        /* Initializes options from the requested mode. */
        void Initialize(BugreportMode bugreport_mode);
        void Initialize(BugreportMode bugreport_mode, const android::base::unique_fd& bugreport_fd,
                        const android::base::unique_fd& screenshot_fd);

        /* Returns true if the options set so far are consistent. */
        bool ValidateOptions() const;