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

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

Merge "Check for user consent denial when dumping traces." am: cd3d535d am: 666ba5d5

am: e6853a20

Change-Id: Ifc2858586a420f2aabe0c0ce0a1215737690dd51
parents d8c938b0 e6853a20
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -1501,14 +1501,12 @@ static Dumpstate::RunStatus DumpstateDefault() {
    // Try to dump anrd trace if the daemon is running.
    dump_anrd_trace();

    // Invoking the following dumpsys calls before dump_traces() to try and
    // Invoking the following dumpsys calls before DumpTraces() to try and
    // keep the system stats as close to its initial state as possible.
    RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(RunDumpsysCritical);

    /* collect stack traces from Dalvik and native processes (needs root) */
    // TODO(128270426): Refactor to take output argument and wrap in
    // RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK.
    dump_traces_path = ds.DumpTraces();
    RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(ds.DumpTraces, &dump_traces_path);

    /* Run some operations that require root. */
    ds.tombstone_data_ = GetDumpFds(TOMBSTONE_DIR, TOMBSTONE_FILE_PREFIX, !ds.IsZipping());
@@ -1638,7 +1636,7 @@ static void DumpstateWifiOnly() {
    printf("========================================================\n");
}

const char* Dumpstate::DumpTraces() {
Dumpstate::RunStatus Dumpstate::DumpTraces(const char** path) {
    DurationReporter duration_reporter("DUMP TRACES");

    const std::string temp_file_pattern = "/data/anr/dumptrace_XXXXXX";
@@ -1654,7 +1652,7 @@ const char* Dumpstate::DumpTraces() {
    android::base::unique_fd fd(mkostemp(file_name_buf.get(), O_APPEND | O_CLOEXEC));
    if (fd < 0) {
        MYLOGE("mkostemp on pattern %s: %s\n", file_name_buf.get(), strerror(errno));
        return nullptr;
        return RunStatus::OK;
    }

    // Nobody should have access to this temporary file except dumpstate, but we
@@ -1664,13 +1662,13 @@ const char* Dumpstate::DumpTraces() {
    const int chmod_ret = fchmod(fd, 0666);
    if (chmod_ret < 0) {
        MYLOGE("fchmod on %s failed: %s\n", file_name_buf.get(), strerror(errno));
        return nullptr;
        return RunStatus::OK;
    }

    std::unique_ptr<DIR, decltype(&closedir)> proc(opendir("/proc"), closedir);
    if (proc.get() == nullptr) {
        MYLOGE("opendir /proc failed: %s\n", strerror(errno));
        return nullptr;
        return RunStatus::OK;
    }

    // Number of times process dumping has timed out. If we encounter too many
@@ -1682,6 +1680,7 @@ const char* Dumpstate::DumpTraces() {

    struct dirent* d;
    while ((d = readdir(proc.get()))) {
        RETURN_IF_USER_DENIED_CONSENT();
        int pid = atoi(d->d_name);
        if (pid <= 0) {
            continue;
@@ -1743,7 +1742,8 @@ const char* Dumpstate::DumpTraces() {
        MYLOGE("Warning: no Dalvik processes found to dump stacks\n");
    }

    return file_name_buf.release();
    *path = file_name_buf.release();
    return RunStatus::OK;
}

void Dumpstate::DumpstateBoard() {
+5 −2
Original line number Diff line number Diff line
@@ -291,8 +291,11 @@ class Dumpstate {
    // TODO: temporary method until Dumpstate object is properly set
    void SetProgress(std::unique_ptr<Progress> progress);

    // Dumps Dalvik and native stack traces, return the trace file location (nullptr if none).
    const char* DumpTraces();
    // Dumps Dalvik and native stack traces, sets the trace file location to path
    // if it succeeded.
    // Note that it returns early if user consent is denied with status USER_CONSENT_DENIED.
    // Returns OK in all other cases.
    RunStatus DumpTraces(const char** path);

    void DumpstateBoard();