blob: 0a1e03eb6f4106db2b83204830406450ce5c465c [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 SECTIONS_H
18#define SECTIONS_H
19
Yi Jin99c248f2017-08-25 18:11:58 -070020#include "Reporter.h"
Joe Onorato1754d742016-11-21 17:51:35 -080021
Yi Jinb44f7d42017-07-21 12:12:59 -070022#include <stdarg.h>
Joe Onorato1754d742016-11-21 17:51:35 -080023#include <utils/String8.h>
24#include <utils/String16.h>
25#include <utils/Vector.h>
26
27using namespace android;
28
Yi Jinb44f7d42017-07-21 12:12:59 -070029const int64_t REMOTE_CALL_TIMEOUT_MS = 10 * 1000; // 10 seconds
30
Joe Onorato1754d742016-11-21 17:51:35 -080031/**
32 * Base class for sections
33 */
34class Section
35{
36public:
Yi Jinb44f7d42017-07-21 12:12:59 -070037 const int id;
38 const int64_t timeoutMs; // each section must have a timeout
Joe Onorato1754d742016-11-21 17:51:35 -080039 String8 name;
40
Yi Jinb44f7d42017-07-21 12:12:59 -070041 Section(int id, const int64_t timeoutMs = REMOTE_CALL_TIMEOUT_MS);
Joe Onorato1754d742016-11-21 17:51:35 -080042 virtual ~Section();
43
44 virtual status_t Execute(ReportRequestSet* requests) const = 0;
Joe Onorato1754d742016-11-21 17:51:35 -080045};
46
47/**
Yi Jinedfd5bb2017-09-06 17:09:11 -070048 * Section that generates incident headers.
49 */
50class HeaderSection : public Section
51{
52public:
53 HeaderSection();
54 virtual ~HeaderSection();
55
56 virtual status_t Execute(ReportRequestSet* requests) const;
57};
58
59/**
Joe Onorato1754d742016-11-21 17:51:35 -080060 * Section that reads in a file.
61 */
62class FileSection : public Section
63{
64public:
Yi Jinb44f7d42017-07-21 12:12:59 -070065 FileSection(int id, const char* filename, const int64_t timeoutMs = 5000 /* 5 seconds */);
Joe Onorato1754d742016-11-21 17:51:35 -080066 virtual ~FileSection();
67
68 virtual status_t Execute(ReportRequestSet* requests) const;
69
70private:
71 const char* mFilename;
72};
73
74/**
75 * Base class for sections that call a command that might need a timeout.
76 */
77class WorkerThreadSection : public Section
78{
79public:
80 WorkerThreadSection(int id);
81 virtual ~WorkerThreadSection();
82
83 virtual status_t Execute(ReportRequestSet* requests) const;
84
85 virtual status_t BlockingCall(int pipeWriteFd) const = 0;
86};
87
88/**
89 * Section that forks and execs a command, and puts stdout as the section.
90 */
91class CommandSection : public Section
92{
93public:
Yi Jinb44f7d42017-07-21 12:12:59 -070094 CommandSection(int id, const int64_t timeoutMs, const char* command, ...);
95
96 CommandSection(int id, const char* command, ...);
97
Joe Onorato1754d742016-11-21 17:51:35 -080098 virtual ~CommandSection();
99
100 virtual status_t Execute(ReportRequestSet* requests) const;
101
102private:
103 const char** mCommand;
Yi Jinb44f7d42017-07-21 12:12:59 -0700104
105 void init(const char* command, va_list args);
Joe Onorato1754d742016-11-21 17:51:35 -0800106};
107
108/**
109 * Section that calls dumpsys on a system service.
110 */
111class DumpsysSection : public WorkerThreadSection
112{
113public:
114 DumpsysSection(int id, const char* service, ...);
115 virtual ~DumpsysSection();
116
117 virtual status_t BlockingCall(int pipeWriteFd) const;
118
119private:
120 String16 mService;
121 Vector<String16> mArgs;
122};
123
124#endif // SECTIONS_H
125