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 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 55 | typedef vector<sp<ReportRequest>>::iterator iterator; |
| 56 | |
| 57 | iterator begin() { return mRequests.begin(); } |
| 58 | iterator end() { return mRequests.end(); } |
| 59 | |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 60 | int mainFd() { return mMainFd; } |
Yi Jin | add11e9 | 2017-07-30 16:10:07 -0700 | [diff] [blame] | 61 | bool containsSection(int id); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 62 | private: |
| 63 | vector<sp<ReportRequest>> mRequests; |
Yi Jin | add11e9 | 2017-07-30 16:10:07 -0700 | [diff] [blame] | 64 | IncidentReportArgs mSections; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 65 | int mMainFd; |
| 66 | }; |
| 67 | |
| 68 | // ================================================================================ |
| 69 | class Reporter : public virtual RefBase |
| 70 | { |
| 71 | public: |
| 72 | enum run_report_status_t { |
| 73 | REPORT_FINISHED = 0, |
| 74 | REPORT_NEEDS_DROPBOX = 1 |
| 75 | }; |
| 76 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 77 | ReportRequestSet batch; |
| 78 | |
| 79 | Reporter(); |
Yi Jin | add11e9 | 2017-07-30 16:10:07 -0700 | [diff] [blame] | 80 | Reporter(const char* directory); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 81 | virtual ~Reporter(); |
| 82 | |
| 83 | // Run the report as described in the batch and args parameters. |
| 84 | run_report_status_t runReport(); |
| 85 | |
| 86 | static run_report_status_t upload_backlog(); |
| 87 | |
| 88 | private: |
Yi Jin | add11e9 | 2017-07-30 16:10:07 -0700 | [diff] [blame] | 89 | String8 mIncidentDirectory; |
| 90 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 91 | string mFilename; |
| 92 | off_t mMaxSize; |
| 93 | size_t mMaxCount; |
| 94 | time_t mStartTime; |
| 95 | |
| 96 | status_t create_file(int* fd); |
Yi Jin | add11e9 | 2017-07-30 16:10:07 -0700 | [diff] [blame] | 97 | |
| 98 | bool isTest = true; // default to true for testing |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | |
| 102 | #endif // REPORTER_H |