Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 16 | #pragma once |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 17 | |
| 18 | #ifndef REPORTER_H |
| 19 | #define REPORTER_H |
| 20 | |
| 21 | #include <android/os/IIncidentReportStatusListener.h> |
| 22 | #include <android/os/IncidentReportArgs.h> |
| 23 | |
Yi Jin | 329130b | 2018-02-09 16:47:47 -0800 | [diff] [blame] | 24 | #include <map> |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 25 | #include <string> |
| 26 | #include <vector> |
| 27 | |
| 28 | #include <time.h> |
| 29 | |
Yi Jin | 4e84310 | 2018-02-14 15:36:18 -0800 | [diff] [blame] | 30 | #include "Throttler.h" |
| 31 | #include "frameworks/base/libs/incident/proto/android/os/metadata.pb.h" |
| 32 | |
Yi Jin | 6cacbcb | 2018-03-30 14:04:52 -0700 | [diff] [blame] | 33 | namespace android { |
| 34 | namespace os { |
| 35 | namespace incidentd { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 36 | |
| 37 | // ================================================================================ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 38 | struct ReportRequest : public virtual RefBase { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 39 | IncidentReportArgs args; |
| 40 | sp<IIncidentReportStatusListener> listener; |
| 41 | int fd; |
| 42 | status_t err; |
| 43 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 44 | ReportRequest(const IncidentReportArgs& args, const sp<IIncidentReportStatusListener>& listener, |
| 45 | int fd); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 46 | virtual ~ReportRequest(); |
Yi Jin | edfd5bb | 2017-09-06 17:09:11 -0700 | [diff] [blame] | 47 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 48 | bool ok(); // returns true if the request is ok for write. |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | // ================================================================================ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 52 | class ReportRequestSet { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 53 | public: |
| 54 | ReportRequestSet(); |
| 55 | ~ReportRequestSet(); |
| 56 | |
| 57 | void add(const sp<ReportRequest>& request); |
| 58 | void setMainFd(int fd); |
Yi Jin | 3ec5cc7 | 2018-01-26 13:42:43 -0800 | [diff] [blame] | 59 | void setMainDest(int dest); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 60 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 61 | typedef vector<sp<ReportRequest>>::iterator iterator; |
| 62 | |
| 63 | iterator begin() { return mRequests.begin(); } |
| 64 | iterator end() { return mRequests.end(); } |
| 65 | |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 66 | int mainFd() { return mMainFd; } |
Yi Jin | 3ec5cc7 | 2018-01-26 13:42:43 -0800 | [diff] [blame] | 67 | int mainDest() { return mMainDest; } |
Yi Jin | 329130b | 2018-02-09 16:47:47 -0800 | [diff] [blame] | 68 | IncidentMetadata& metadata() { return mMetadata; } |
Yi Jin | 86dce41 | 2018-03-07 11:36:57 -0800 | [diff] [blame] | 69 | map<int, IncidentMetadata::SectionStats>& allSectionStats() { return mSectionStats; } |
Yi Jin | 329130b | 2018-02-09 16:47:47 -0800 | [diff] [blame] | 70 | |
| 71 | bool containsSection(int id); |
| 72 | IncidentMetadata::SectionStats* sectionStats(int id); |
| 73 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 74 | private: |
| 75 | vector<sp<ReportRequest>> mRequests; |
Yi Jin | add11e9 | 2017-07-30 16:10:07 -0700 | [diff] [blame] | 76 | IncidentReportArgs mSections; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 77 | int mMainFd; |
Yi Jin | 3ec5cc7 | 2018-01-26 13:42:43 -0800 | [diff] [blame] | 78 | int mMainDest; |
Yi Jin | 329130b | 2018-02-09 16:47:47 -0800 | [diff] [blame] | 79 | |
| 80 | IncidentMetadata mMetadata; |
Yi Jin | 86dce41 | 2018-03-07 11:36:57 -0800 | [diff] [blame] | 81 | map<int, IncidentMetadata::SectionStats> mSectionStats; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | // ================================================================================ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 85 | class Reporter : public virtual RefBase { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 86 | public: |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 87 | enum run_report_status_t { REPORT_FINISHED = 0, REPORT_NEEDS_DROPBOX = 1 }; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 88 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 89 | ReportRequestSet batch; |
| 90 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 91 | Reporter(); // PROD must use this constructor. |
Chih-Hung Hsieh | 7a88a93 | 2018-12-20 13:45:04 -0800 | [diff] [blame] | 92 | explicit Reporter(const char* directory); // For testing purpose only. |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 93 | virtual ~Reporter(); |
| 94 | |
| 95 | // Run the report as described in the batch and args parameters. |
Yi Jin | 4e84310 | 2018-02-14 15:36:18 -0800 | [diff] [blame] | 96 | run_report_status_t runReport(size_t* reportByteSize); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 97 | |
| 98 | static run_report_status_t upload_backlog(); |
| 99 | |
| 100 | private: |
Yi Jin | add11e9 | 2017-07-30 16:10:07 -0700 | [diff] [blame] | 101 | String8 mIncidentDirectory; |
| 102 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 103 | string mFilename; |
| 104 | off_t mMaxSize; |
| 105 | size_t mMaxCount; |
| 106 | time_t mStartTime; |
| 107 | |
| 108 | status_t create_file(int* fd); |
Yi Jin | add11e9 | 2017-07-30 16:10:07 -0700 | [diff] [blame] | 109 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 110 | bool isTest = true; // default to true for testing |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 111 | }; |
| 112 | |
Yi Jin | 6cacbcb | 2018-03-30 14:04:52 -0700 | [diff] [blame] | 113 | } // namespace incidentd |
| 114 | } // namespace os |
| 115 | } // namespace android |
| 116 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 117 | #endif // REPORTER_H |