Loading cmds/incidentd/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ cc_binary { "libprotoutil", "libservices", "libutils", "libprotobuf-cpp-lite", ], init_rc: ["incidentd.rc"], Loading cmds/incidentd/src/FdBuffer.cpp +16 −5 Original line number Diff line number Diff line Loading @@ -47,9 +47,13 @@ status_t FdBuffer::read(int fd, int64_t timeout) { while (true) { if (mBuffer.size() >= MAX_BUFFER_COUNT * BUFFER_SIZE) { mTruncated = true; VLOG("Truncating data"); break; } if (mBuffer.writeBuffer() == NULL) return NO_MEMORY; if (mBuffer.writeBuffer() == NULL) { VLOG("No memory"); return NO_MEMORY; } int64_t remainingTime = (mStartTime + timeout) - uptimeMillis(); if (remainingTime <= 0) { Loading @@ -58,7 +62,7 @@ status_t FdBuffer::read(int fd, int64_t timeout) { break; } int count = poll(&pfds, 1, remainingTime); int count = TEMP_FAILURE_RETRY(poll(&pfds, 1, remainingTime)); if (count == 0) { VLOG("timed out due to block calling poll"); mTimedOut = true; Loading Loading @@ -102,7 +106,10 @@ status_t FdBuffer::readFully(int fd) { VLOG("Truncating data"); break; } if (mBuffer.writeBuffer() == NULL) return NO_MEMORY; if (mBuffer.writeBuffer() == NULL) { VLOG("No memory"); return NO_MEMORY; } ssize_t amt = TEMP_FAILURE_RETRY(::read(fd, mBuffer.writeBuffer(), mBuffer.currentToWrite())); Loading Loading @@ -144,10 +151,14 @@ status_t FdBuffer::readProcessedDataInStream(int fd, unique_fd toFd, unique_fd f // This is the buffer used to store processed data while (true) { if (mBuffer.size() >= MAX_BUFFER_COUNT * BUFFER_SIZE) { VLOG("Truncating data"); mTruncated = true; break; } if (mBuffer.writeBuffer() == NULL) return NO_MEMORY; if (mBuffer.writeBuffer() == NULL) { VLOG("No memory"); return NO_MEMORY; } int64_t remainingTime = (mStartTime + timeoutMs) - uptimeMillis(); if (remainingTime <= 0) { Loading @@ -157,7 +168,7 @@ status_t FdBuffer::readProcessedDataInStream(int fd, unique_fd toFd, unique_fd f } // wait for any pfds to be ready to perform IO int count = poll(pfds, 3, remainingTime); int count = TEMP_FAILURE_RETRY(poll(pfds, 3, remainingTime)); if (count == 0) { VLOG("timed out due to block calling poll"); mTimedOut = true; Loading cmds/incidentd/src/IncidentService.cpp +3 −5 Original line number Diff line number Diff line Loading @@ -42,13 +42,11 @@ enum { WHAT_RUN_REPORT = 1, WHAT_SEND_BACKLOG_TO_DROPBOX = 2 }; #define DEFAULT_BYTES_SIZE_LIMIT (20 * 1024 * 1024) // 20MB #define DEFAULT_REFACTORY_PERIOD_MS (24 * 60 * 60 * 1000) // 1 Day // Skip logs (1100 - 1108) because they are already in the bug report // Skip 1200, 1201, 1202, 3018 because they take too long // TODO(120079956): Skip 3008, 3015 because of error // Skip these sections for dumpstate only. Dumpstate allows 10s max for each service to dump. // Skip logs (1100 - 1108) and traces (1200 - 1202) because they are already in the bug report. // Skip 3018 because it takes too long. #define SKIPPED_SECTIONS { 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, /* Logs */ \ 1200, 1201, 1202, /* Native, hal, java traces */ \ 3008, /* "package --proto" */ \ 3015, /* "activity --proto processes" */ \ 3018 /* "meminfo -a --proto" */ } namespace android { Loading cmds/incidentd/src/PrivacyBuffer.cpp +12 −3 Original line number Diff line number Diff line Loading @@ -96,7 +96,12 @@ status_t PrivacyBuffer::stripField(const Privacy* parentPolicy, const PrivacySpe uint64_t token = mProto.start(encode_field_id(policy)); while (mData.rp()->pos() - start != msgSize) { status_t err = stripField(policy, spec, depth + 1); if (err != NO_ERROR) return err; if (err != NO_ERROR) { VLOG("Bad value when stripping id %d, wiretype %d, tag %#x, depth %d, size %d, " "relative pos %zu, ", fieldId, read_wire_type(fieldTag), fieldTag, depth, msgSize, mData.rp()->pos() - start); return err; } } mProto.end(token); return NO_ERROR; Loading @@ -117,9 +122,13 @@ status_t PrivacyBuffer::strip(const PrivacySpec& spec) { } while (mData.hasNext()) { status_t err = stripField(mPolicy, spec, 0); if (err != NO_ERROR) return err; if (err != NO_ERROR) return err; // Error logged in stripField. } if (mData.bytesRead() != mData.size()) { VLOG("Buffer corrupted: expect %zu bytes, read %zu bytes", mData.size(), mData.bytesRead()); return BAD_VALUE; } if (mData.bytesRead() != mData.size()) return BAD_VALUE; mSize = mProto.size(); mData.rp()->rewind(); // rewind the read pointer back to beginning after the strip. return NO_ERROR; Loading cmds/incidentd/src/Reporter.cpp +8 −4 Original line number Diff line number Diff line Loading @@ -129,6 +129,7 @@ Reporter::run_report_status_t Reporter::runReport(size_t* reportByteSize) { bool needMainFd = false; int mainFd = -1; int mainDest = -1; int sectionCount = 0; HeaderSection headers; MetadataSection metadataSection; std::string buildType = android::base::GetProperty("ro.build.type", ""); Loading Loading @@ -180,12 +181,12 @@ Reporter::run_report_status_t Reporter::runReport(size_t* reportByteSize) { for (const Section** section = SECTION_LIST; *section; section++) { const int id = (*section)->id; if ((*section)->userdebugAndEngOnly && !isUserdebugOrEng) { ALOGD("Skipping incident report section %d '%s' because it's limited to userdebug/eng", VLOG("Skipping incident report section %d '%s' because it's limited to userdebug/eng", id, (*section)->name.string()); continue; } if (this->batch.containsSection(id)) { ALOGD("Taking incident report section %d '%s'", id, (*section)->name.string()); VLOG("Taking incident report section %d '%s'", id, (*section)->name.string()); for (ReportRequestSet::iterator it = batch.begin(); it != batch.end(); it++) { if ((*it)->listener != NULL && (*it)->args.containsSection(id)) { (*it)->listener->onReportSectionStatus( Loading @@ -198,11 +199,12 @@ Reporter::run_report_status_t Reporter::runReport(size_t* reportByteSize) { 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)); // Execute() has already recorded this status. Only update if there's new failure. stats->set_success(false); goto DONE; } (*reportByteSize) += stats->report_size_bytes(); Loading @@ -214,11 +216,13 @@ Reporter::run_report_status_t Reporter::runReport(size_t* reportByteSize) { id, IIncidentReportStatusListener::STATUS_FINISHED); } } ALOGD("Finish incident report section %d '%s'", id, (*section)->name.string()); VLOG("Finish incident report section %d '%s'", id, (*section)->name.string()); sectionCount++; } } DONE: ALOGD("Incident reporting took %d sections.", sectionCount); // Reports the metdadata when taking the incident report. if (!isTest) metadataSection.Execute(&batch); Loading Loading
cmds/incidentd/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ cc_binary { "libprotoutil", "libservices", "libutils", "libprotobuf-cpp-lite", ], init_rc: ["incidentd.rc"], Loading
cmds/incidentd/src/FdBuffer.cpp +16 −5 Original line number Diff line number Diff line Loading @@ -47,9 +47,13 @@ status_t FdBuffer::read(int fd, int64_t timeout) { while (true) { if (mBuffer.size() >= MAX_BUFFER_COUNT * BUFFER_SIZE) { mTruncated = true; VLOG("Truncating data"); break; } if (mBuffer.writeBuffer() == NULL) return NO_MEMORY; if (mBuffer.writeBuffer() == NULL) { VLOG("No memory"); return NO_MEMORY; } int64_t remainingTime = (mStartTime + timeout) - uptimeMillis(); if (remainingTime <= 0) { Loading @@ -58,7 +62,7 @@ status_t FdBuffer::read(int fd, int64_t timeout) { break; } int count = poll(&pfds, 1, remainingTime); int count = TEMP_FAILURE_RETRY(poll(&pfds, 1, remainingTime)); if (count == 0) { VLOG("timed out due to block calling poll"); mTimedOut = true; Loading Loading @@ -102,7 +106,10 @@ status_t FdBuffer::readFully(int fd) { VLOG("Truncating data"); break; } if (mBuffer.writeBuffer() == NULL) return NO_MEMORY; if (mBuffer.writeBuffer() == NULL) { VLOG("No memory"); return NO_MEMORY; } ssize_t amt = TEMP_FAILURE_RETRY(::read(fd, mBuffer.writeBuffer(), mBuffer.currentToWrite())); Loading Loading @@ -144,10 +151,14 @@ status_t FdBuffer::readProcessedDataInStream(int fd, unique_fd toFd, unique_fd f // This is the buffer used to store processed data while (true) { if (mBuffer.size() >= MAX_BUFFER_COUNT * BUFFER_SIZE) { VLOG("Truncating data"); mTruncated = true; break; } if (mBuffer.writeBuffer() == NULL) return NO_MEMORY; if (mBuffer.writeBuffer() == NULL) { VLOG("No memory"); return NO_MEMORY; } int64_t remainingTime = (mStartTime + timeoutMs) - uptimeMillis(); if (remainingTime <= 0) { Loading @@ -157,7 +168,7 @@ status_t FdBuffer::readProcessedDataInStream(int fd, unique_fd toFd, unique_fd f } // wait for any pfds to be ready to perform IO int count = poll(pfds, 3, remainingTime); int count = TEMP_FAILURE_RETRY(poll(pfds, 3, remainingTime)); if (count == 0) { VLOG("timed out due to block calling poll"); mTimedOut = true; Loading
cmds/incidentd/src/IncidentService.cpp +3 −5 Original line number Diff line number Diff line Loading @@ -42,13 +42,11 @@ enum { WHAT_RUN_REPORT = 1, WHAT_SEND_BACKLOG_TO_DROPBOX = 2 }; #define DEFAULT_BYTES_SIZE_LIMIT (20 * 1024 * 1024) // 20MB #define DEFAULT_REFACTORY_PERIOD_MS (24 * 60 * 60 * 1000) // 1 Day // Skip logs (1100 - 1108) because they are already in the bug report // Skip 1200, 1201, 1202, 3018 because they take too long // TODO(120079956): Skip 3008, 3015 because of error // Skip these sections for dumpstate only. Dumpstate allows 10s max for each service to dump. // Skip logs (1100 - 1108) and traces (1200 - 1202) because they are already in the bug report. // Skip 3018 because it takes too long. #define SKIPPED_SECTIONS { 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, /* Logs */ \ 1200, 1201, 1202, /* Native, hal, java traces */ \ 3008, /* "package --proto" */ \ 3015, /* "activity --proto processes" */ \ 3018 /* "meminfo -a --proto" */ } namespace android { Loading
cmds/incidentd/src/PrivacyBuffer.cpp +12 −3 Original line number Diff line number Diff line Loading @@ -96,7 +96,12 @@ status_t PrivacyBuffer::stripField(const Privacy* parentPolicy, const PrivacySpe uint64_t token = mProto.start(encode_field_id(policy)); while (mData.rp()->pos() - start != msgSize) { status_t err = stripField(policy, spec, depth + 1); if (err != NO_ERROR) return err; if (err != NO_ERROR) { VLOG("Bad value when stripping id %d, wiretype %d, tag %#x, depth %d, size %d, " "relative pos %zu, ", fieldId, read_wire_type(fieldTag), fieldTag, depth, msgSize, mData.rp()->pos() - start); return err; } } mProto.end(token); return NO_ERROR; Loading @@ -117,9 +122,13 @@ status_t PrivacyBuffer::strip(const PrivacySpec& spec) { } while (mData.hasNext()) { status_t err = stripField(mPolicy, spec, 0); if (err != NO_ERROR) return err; if (err != NO_ERROR) return err; // Error logged in stripField. } if (mData.bytesRead() != mData.size()) { VLOG("Buffer corrupted: expect %zu bytes, read %zu bytes", mData.size(), mData.bytesRead()); return BAD_VALUE; } if (mData.bytesRead() != mData.size()) return BAD_VALUE; mSize = mProto.size(); mData.rp()->rewind(); // rewind the read pointer back to beginning after the strip. return NO_ERROR; Loading
cmds/incidentd/src/Reporter.cpp +8 −4 Original line number Diff line number Diff line Loading @@ -129,6 +129,7 @@ Reporter::run_report_status_t Reporter::runReport(size_t* reportByteSize) { bool needMainFd = false; int mainFd = -1; int mainDest = -1; int sectionCount = 0; HeaderSection headers; MetadataSection metadataSection; std::string buildType = android::base::GetProperty("ro.build.type", ""); Loading Loading @@ -180,12 +181,12 @@ Reporter::run_report_status_t Reporter::runReport(size_t* reportByteSize) { for (const Section** section = SECTION_LIST; *section; section++) { const int id = (*section)->id; if ((*section)->userdebugAndEngOnly && !isUserdebugOrEng) { ALOGD("Skipping incident report section %d '%s' because it's limited to userdebug/eng", VLOG("Skipping incident report section %d '%s' because it's limited to userdebug/eng", id, (*section)->name.string()); continue; } if (this->batch.containsSection(id)) { ALOGD("Taking incident report section %d '%s'", id, (*section)->name.string()); VLOG("Taking incident report section %d '%s'", id, (*section)->name.string()); for (ReportRequestSet::iterator it = batch.begin(); it != batch.end(); it++) { if ((*it)->listener != NULL && (*it)->args.containsSection(id)) { (*it)->listener->onReportSectionStatus( Loading @@ -198,11 +199,12 @@ Reporter::run_report_status_t Reporter::runReport(size_t* reportByteSize) { 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)); // Execute() has already recorded this status. Only update if there's new failure. stats->set_success(false); goto DONE; } (*reportByteSize) += stats->report_size_bytes(); Loading @@ -214,11 +216,13 @@ Reporter::run_report_status_t Reporter::runReport(size_t* reportByteSize) { id, IIncidentReportStatusListener::STATUS_FINISHED); } } ALOGD("Finish incident report section %d '%s'", id, (*section)->name.string()); VLOG("Finish incident report section %d '%s'", id, (*section)->name.string()); sectionCount++; } } DONE: ALOGD("Incident reporting took %d sections.", sectionCount); // Reports the metdadata when taking the incident report. if (!isTest) metadataSection.Execute(&batch); Loading