blob: 509611c34d4b501bbf793365cc0887305ada2c30 [file] [log] [blame]
Joe Onorato1754d742016-11-21 17:51:35 -08001/*
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
28using namespace android;
29using namespace android::os;
30using namespace std;
31
32// ================================================================================
33struct 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// ================================================================================
46class ReportRequestSet
47{
48public:
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 Jinadd11e92017-07-30 16:10:07 -070065 bool containsSection(int id);
Joe Onorato1754d742016-11-21 17:51:35 -080066private:
67 vector<sp<ReportRequest>> mRequests;
Yi Jinadd11e92017-07-30 16:10:07 -070068 IncidentReportArgs mSections;
Joe Onorato1754d742016-11-21 17:51:35 -080069 int mWritableCount;
70 int mMainFd;
71};
72
73// ================================================================================
74class Reporter : public virtual RefBase
75{
76public:
77 enum run_report_status_t {
78 REPORT_FINISHED = 0,
79 REPORT_NEEDS_DROPBOX = 1
80 };
81
Joe Onorato1754d742016-11-21 17:51:35 -080082 ReportRequestSet batch;
83
84 Reporter();
Yi Jinadd11e92017-07-30 16:10:07 -070085 Reporter(const char* directory);
Joe Onorato1754d742016-11-21 17:51:35 -080086 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
93private:
Yi Jinadd11e92017-07-30 16:10:07 -070094 String8 mIncidentDirectory;
95
Joe Onorato1754d742016-11-21 17:51:35 -080096 string mFilename;
97 off_t mMaxSize;
98 size_t mMaxCount;
99 time_t mStartTime;
100
101 status_t create_file(int* fd);
Yi Jinadd11e92017-07-30 16:10:07 -0700102
103 bool isTest = true; // default to true for testing
Joe Onorato1754d742016-11-21 17:51:35 -0800104};
105
106
107#endif // REPORTER_H