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

Commit c6ad682a authored by Nandana Dutt's avatar Nandana Dutt Committed by Gerrit Code Review
Browse files

Merge "Implement startBugreport binder function"

parents 6d4c9406 197661dc
Loading
Loading
Loading
Loading
+44 −3
Original line number Diff line number Diff line
@@ -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 {};
}

@@ -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();
}

+1 −2
Original line number Diff line number Diff line
@@ -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_;
+21 −4
Original line number Diff line number Diff line
@@ -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);
}
+9 −5
Original line number Diff line number Diff line
@@ -2138,13 +2138,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);
        LogDumpOptions(*options_);
        return RunStatus::INVALID_INPUT;
    }
    options_ = std::move(options);
    /* set as high priority, and protect from OOM killer */
    setpriority(PRIO_PROCESS, 0, -20);

@@ -2366,7 +2369,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) {
+12 −9
Original line number Diff line number Diff line
@@ -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>
@@ -188,15 +189,14 @@ class Dumpstate {
  public:
    enum RunStatus { OK, HELP, INVALID_INPUT, ERROR };

    // TODO(117177665): should enumerate constants in the AIDL file.
    // The mode under which the bugreport should be run. Each mode encapsulates a few options.
    enum BugreportMode {
        BUGREPORT_FULL,
        BUGREPORT_INTERACTIVE,
        BUGREPORT_REMOTE,
        BUGREPORT_WEAR,
        BUGREPORT_TELEPHONY,
        BUGREPORT_WIFI
        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;
@@ -308,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