blob: b74cc42903062bf0bda25ecf3049081ed502ac44 [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
Joe Onorato1754d742016-11-21 17:51:35 -080055 typedef vector<sp<ReportRequest>>::iterator iterator;
56
57 iterator begin() { return mRequests.begin(); }
58 iterator end() { return mRequests.end(); }
59
Yi Jin99c248f2017-08-25 18:11:58 -070060 int mainFd() { return mMainFd; }
Yi Jinadd11e92017-07-30 16:10:07 -070061 bool containsSection(int id);
Joe Onorato1754d742016-11-21 17:51:35 -080062private:
63 vector<sp<ReportRequest>> mRequests;
Yi Jinadd11e92017-07-30 16:10:07 -070064 IncidentReportArgs mSections;
Joe Onorato1754d742016-11-21 17:51:35 -080065 int mMainFd;
66};
67
68// ================================================================================
69class Reporter : public virtual RefBase
70{
71public:
72 enum run_report_status_t {
73 REPORT_FINISHED = 0,
74 REPORT_NEEDS_DROPBOX = 1
75 };
76
Joe Onorato1754d742016-11-21 17:51:35 -080077 ReportRequestSet batch;
78
79 Reporter();
Yi Jinadd11e92017-07-30 16:10:07 -070080 Reporter(const char* directory);
Joe Onorato1754d742016-11-21 17:51:35 -080081 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
88private:
Yi Jinadd11e92017-07-30 16:10:07 -070089 String8 mIncidentDirectory;
90
Joe Onorato1754d742016-11-21 17:51:35 -080091 string mFilename;
92 off_t mMaxSize;
93 size_t mMaxCount;
94 time_t mStartTime;
95
96 status_t create_file(int* fd);
Yi Jinadd11e92017-07-30 16:10:07 -070097
98 bool isTest = true; // default to true for testing
Joe Onorato1754d742016-11-21 17:51:35 -080099};
100
101
102#endif // REPORTER_H