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 | */ |
| 16 | |
| 17 | #ifndef REPORTER_H |
| 18 | #define REPORTER_H |
| 19 | |
| 20 | #include <android/os/IIncidentReportStatusListener.h> |
| 21 | #include <android/os/IncidentReportArgs.h> |
| 22 | |
| 23 | #include <string> |
| 24 | #include <vector> |
| 25 | |
| 26 | #include <time.h> |
| 27 | |
| 28 | using namespace android; |
| 29 | using namespace android::os; |
| 30 | using namespace std; |
| 31 | |
| 32 | // ================================================================================ |
| 33 | struct ReportRequest : public virtual RefBase |
| 34 | { |
| 35 | IncidentReportArgs args; |
| 36 | sp<IIncidentReportStatusListener> listener; |
| 37 | int fd; |
| 38 | status_t err; |
| 39 | |
| 40 | ReportRequest(const IncidentReportArgs& args, |
| 41 | const sp<IIncidentReportStatusListener> &listener, int fd); |
| 42 | virtual ~ReportRequest(); |
| 43 | }; |
| 44 | |
| 45 | // ================================================================================ |
| 46 | class ReportRequestSet |
| 47 | { |
| 48 | public: |
| 49 | ReportRequestSet(); |
| 50 | ~ReportRequestSet(); |
| 51 | |
| 52 | void add(const sp<ReportRequest>& request); |
| 53 | void setMainFd(int fd); |
| 54 | |
| 55 | // Write to all of the fds for the requests. If a write fails, it stops |
| 56 | // writing to that fd and returns NO_ERROR. When we are out of fds to write |
| 57 | // to it returns an error. |
| 58 | status_t write(uint8_t const* buf, size_t size); |
| 59 | |
| 60 | typedef vector<sp<ReportRequest>>::iterator iterator; |
| 61 | |
| 62 | iterator begin() { return mRequests.begin(); } |
| 63 | iterator end() { return mRequests.end(); } |
| 64 | |
Yi Jin | add11e9 | 2017-07-30 16:10:07 -0700 | [diff] [blame] | 65 | bool containsSection(int id); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 66 | private: |
| 67 | vector<sp<ReportRequest>> mRequests; |
Yi Jin | add11e9 | 2017-07-30 16:10:07 -0700 | [diff] [blame] | 68 | IncidentReportArgs mSections; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 69 | int mWritableCount; |
| 70 | int mMainFd; |
| 71 | }; |
| 72 | |
| 73 | // ================================================================================ |
| 74 | class Reporter : public virtual RefBase |
| 75 | { |
| 76 | public: |
| 77 | enum run_report_status_t { |
| 78 | REPORT_FINISHED = 0, |
| 79 | REPORT_NEEDS_DROPBOX = 1 |
| 80 | }; |
| 81 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 82 | ReportRequestSet batch; |
| 83 | |
| 84 | Reporter(); |
Yi Jin | add11e9 | 2017-07-30 16:10:07 -0700 | [diff] [blame] | 85 | Reporter(const char* directory); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 86 | virtual ~Reporter(); |
| 87 | |
| 88 | // Run the report as described in the batch and args parameters. |
| 89 | run_report_status_t runReport(); |
| 90 | |
| 91 | static run_report_status_t upload_backlog(); |
| 92 | |
| 93 | private: |
Yi Jin | add11e9 | 2017-07-30 16:10:07 -0700 | [diff] [blame] | 94 | String8 mIncidentDirectory; |
| 95 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 96 | string mFilename; |
| 97 | off_t mMaxSize; |
| 98 | size_t mMaxCount; |
| 99 | time_t mStartTime; |
| 100 | |
| 101 | status_t create_file(int* fd); |
Yi Jin | add11e9 | 2017-07-30 16:10:07 -0700 | [diff] [blame] | 102 | |
| 103 | bool isTest = true; // default to true for testing |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | |
| 107 | #endif // REPORTER_H |