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

Commit 329130b7 authored by Yi Jin's avatar Yi Jin
Browse files

Put metadata or stats into each dropbox incident report.

Bug: 65451198
Test: atest incidentd_test
Change-Id: Ib406b177ad7f1b4bda7fef2e606fc66a9836e060
parent 85a6db68
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ LOCAL_SHARED_LIBRARIES := \
        libcutils \
        libincident \
        liblog \
        libprotobuf-cpp-lite \
        libprotoutil \
        libselinux \
        libservices \
+1 −6
Original line number Diff line number Diff line
@@ -73,11 +73,6 @@ PrivacySpec PrivacySpec::new_spec(int dest)
        case android::os::DEST_LOCAL:
            return PrivacySpec(dest);
        default:
            return PrivacySpec();
    }
}

PrivacySpec PrivacySpec::get_default_dropbox_spec()
{
            return PrivacySpec(android::os::DEST_AUTOMATIC);
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -75,7 +75,6 @@ public:

    // Constructs spec using static methods below.
    static PrivacySpec new_spec(int dest);
    static PrivacySpec get_default_dropbox_spec();
private:
    PrivacySpec(uint8_t dest) : dest(dest) {}
};
+40 −4
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include "Reporter.h"

#include "Privacy.h"
#include "report_directory.h"
#include "section_list.h"

@@ -65,7 +66,9 @@ ReportRequestSet::ReportRequestSet()
    :mRequests(),
     mSections(),
     mMainFd(-1),
     mMainDest(-1)
     mMainDest(-1),
     mMetadata(),
     mSectionStats()
{
}

@@ -79,18 +82,32 @@ ReportRequestSet::add(const sp<ReportRequest>& request)
{
    mRequests.push_back(request);
    mSections.merge(request->args);
    mMetadata.set_request_size(mMetadata.request_size() + 1);
}

void
ReportRequestSet::setMainFd(int fd)
{
    mMainFd = fd;
    mMetadata.set_use_dropbox(fd > 0);
}

void
ReportRequestSet::setMainDest(int dest)
{
    mMainDest = dest;
    PrivacySpec spec = PrivacySpec::new_spec(dest);
    switch (spec.dest) {
        case android::os::DEST_AUTOMATIC:
            mMetadata.set_dest(IncidentMetadata_Destination_AUTOMATIC);
            break;
        case android::os::DEST_EXPLICIT:
            mMetadata.set_dest(IncidentMetadata_Destination_EXPLICIT);
            break;
        case android::os::DEST_LOCAL:
            mMetadata.set_dest(IncidentMetadata_Destination_LOCAL);
            break;
    }
}

bool
@@ -98,6 +115,16 @@ ReportRequestSet::containsSection(int id) {
    return mSections.containsSection(id);
}

IncidentMetadata::SectionStats*
ReportRequestSet::sectionStats(int id) {
    if (mSectionStats.find(id) == mSectionStats.end()) {
        auto stats = mMetadata.add_sections();
        stats->set_id(id);
        mSectionStats[id] = stats;
    }
    return mSectionStats[id];
}

// ================================================================================
Reporter::Reporter() : Reporter(INCIDENT_DIRECTORY) { isTest = false; };

@@ -128,12 +155,12 @@ Reporter::~Reporter()
Reporter::run_report_status_t
Reporter::runReport()
{

    status_t err = NO_ERROR;
    bool needMainFd = false;
    int mainFd = -1;
    int mainDest = -1;
    HeaderSection headers;
    MetadataSection metadataSection;

    // See if we need the main file
    for (ReportRequestSet::iterator it=batch.begin(); it!=batch.end(); it++) {
@@ -182,7 +209,7 @@ Reporter::runReport()
        const int id = (*section)->id;
        if (this->batch.containsSection(id)) {
            ALOGD("Taking incident report section %d '%s'", id, (*section)->name.string());
            // Notify listener of starting
            // Notify listener of starting.
            for (ReportRequestSet::iterator it=batch.begin(); it!=batch.end(); it++) {
                if ((*it)->listener != NULL && (*it)->args.containsSection(id)) {
                    (*it)->listener->onReportSectionStatus(id,
@@ -191,14 +218,20 @@ Reporter::runReport()
            }

            // Execute - go get the data and write it into the file descriptors.
            auto stats = batch.sectionStats(id);
            int64_t startTime = uptimeMillis();
            err = (*section)->Execute(&batch);
            int64_t endTime = uptimeMillis();

            stats->set_success(err == NO_ERROR);
            stats->set_exec_duration_ms(endTime - startTime);
            if (err != NO_ERROR) {
                ALOGW("Incident section %s (%d) failed: %s. Stopping report.",
                        (*section)->name.string(), id, strerror(-err));
                goto DONE;
            }

            // Notify listener of starting
            // Notify listener of ending.
            for (ReportRequestSet::iterator it=batch.begin(); it!=batch.end(); it++) {
                if ((*it)->listener != NULL && (*it)->args.containsSection(id)) {
                    (*it)->listener->onReportSectionStatus(id,
@@ -210,6 +243,9 @@ Reporter::runReport()
    }

DONE:
    // Reports the metdadata when taking the incident report.
    if (!isTest) metadataSection.Execute(&batch);

    // Close the file.
    if (mainFd >= 0) {
        close(mainFd);
+13 −3
Original line number Diff line number Diff line
@@ -17,9 +17,12 @@
#ifndef REPORTER_H
#define REPORTER_H

#include "frameworks/base/libs/incident/proto/android/os/metadata.pb.h"

#include <android/os/IIncidentReportStatusListener.h>
#include <android/os/IncidentReportArgs.h>

#include <map>
#include <string>
#include <vector>

@@ -61,13 +64,20 @@ public:
    iterator end() { return mRequests.end(); }

    int mainFd() { return mMainFd; }
    bool containsSection(int id);
    int mainDest() { return mMainDest; }
    IncidentMetadata& metadata() { return mMetadata; }

    bool containsSection(int id);
    IncidentMetadata::SectionStats* sectionStats(int id);

private:
    vector<sp<ReportRequest>> mRequests;
    IncidentReportArgs mSections;
    int mMainFd;
    int mMainDest;

    IncidentMetadata mMetadata;
    map<int, IncidentMetadata::SectionStats*> mSectionStats;
};

// ================================================================================
@@ -81,8 +91,8 @@ public:

    ReportRequestSet batch;

    Reporter();
    Reporter(const char* directory);
    Reporter(); // PROD must use this constructor.
    Reporter(const char* directory); // For testing purpose only.
    virtual ~Reporter();

    // Run the report as described in the batch and args parameters.
Loading