summaryrefslogtreecommitdiff
path: root/cmds/incidentd/src/Reporter.h
blob: f30ecf0dd648fd46fb2a7e8ce9d6371e18f16f50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef REPORTER_H
#define REPORTER_H

#include <android/os/IIncidentReportStatusListener.h>
#include <android/os/IncidentReportArgs.h>

#include <string>
#include <vector>

#include <time.h>

using namespace android;
using namespace android::os;
using namespace std;

// ================================================================================
struct ReportRequest : public virtual RefBase
{
    IncidentReportArgs args;
    sp<IIncidentReportStatusListener> listener;
    int fd;
    status_t err;

    ReportRequest(const IncidentReportArgs& args,
            const sp<IIncidentReportStatusListener> &listener, int fd);
    virtual ~ReportRequest();

    bool ok(); // returns true if the request is ok for write.
};

// ================================================================================
class ReportRequestSet
{
public:
    ReportRequestSet();
    ~ReportRequestSet();

    void add(const sp<ReportRequest>& request);
    void setMainFd(int fd);
    void setMainDest(int dest);

    typedef vector<sp<ReportRequest>>::iterator iterator;

    iterator begin() { return mRequests.begin(); }
    iterator end() { return mRequests.end(); }

    int mainFd() { return mMainFd; }
    bool containsSection(int id);
    int mainDest() { return mMainDest; }
private:
    vector<sp<ReportRequest>> mRequests;
    IncidentReportArgs mSections;
    int mMainFd;
    int mMainDest;
};

// ================================================================================
class Reporter : public virtual RefBase
{
public:
    enum run_report_status_t {
        REPORT_FINISHED = 0,
        REPORT_NEEDS_DROPBOX = 1
    };

    ReportRequestSet batch;

    Reporter();
    Reporter(const char* directory);
    virtual ~Reporter();

    // Run the report as described in the batch and args parameters.
    run_report_status_t runReport();

    static run_report_status_t upload_backlog();

private:
    String8 mIncidentDirectory;

    string mFilename;
    off_t mMaxSize;
    size_t mMaxCount;
    time_t mStartTime;

    status_t create_file(int* fd);

    bool isTest = true; // default to true for testing
};


#endif // REPORTER_H