blob: 86d956ff75d8df06140b6464f02128be46979dd3 [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 */
Yi Jinb592e3b2018-02-01 15:17:04 -080016#pragma once
Joe Onorato1754d742016-11-21 17:51:35 -080017
18#ifndef SECTIONS_H
19#define SECTIONS_H
20
Yi Jin99c248f2017-08-25 18:11:58 -070021#include "Reporter.h"
Joe Onorato1754d742016-11-21 17:51:35 -080022
Yi Jinb44f7d42017-07-21 12:12:59 -070023#include <stdarg.h>
Yi Jinb592e3b2018-02-01 15:17:04 -080024#include <map>
Yi Jin3c034c92017-12-22 17:36:47 -080025
Joe Onorato1754d742016-11-21 17:51:35 -080026#include <utils/String16.h>
Yi Jinb592e3b2018-02-01 15:17:04 -080027#include <utils/String8.h>
Joe Onorato1754d742016-11-21 17:51:35 -080028#include <utils/Vector.h>
29
Yi Jin6cacbcb2018-03-30 14:04:52 -070030namespace android {
31namespace os {
32namespace incidentd {
Joe Onorato1754d742016-11-21 17:51:35 -080033
Yi Jinad3e6e52018-04-03 15:10:34 -070034const int64_t REMOTE_CALL_TIMEOUT_MS = 30 * 1000; // 30 seconds
Yi Jinb44f7d42017-07-21 12:12:59 -070035
Joe Onorato1754d742016-11-21 17:51:35 -080036/**
37 * Base class for sections
38 */
Yi Jinb592e3b2018-02-01 15:17:04 -080039class Section {
Joe Onorato1754d742016-11-21 17:51:35 -080040public:
Yi Jinb44f7d42017-07-21 12:12:59 -070041 const int id;
Yi Jinb592e3b2018-02-01 15:17:04 -080042 const int64_t timeoutMs; // each section must have a timeout
Kweku Adams3d160912018-05-07 11:26:27 -070043 const bool userdebugAndEngOnly;
Joe Onorato1754d742016-11-21 17:51:35 -080044 String8 name;
45
Kweku Adamse04ef772018-06-13 12:24:38 -070046 Section(int id, int64_t timeoutMs = REMOTE_CALL_TIMEOUT_MS, bool userdebugAndEngOnly = false);
Joe Onorato1754d742016-11-21 17:51:35 -080047 virtual ~Section();
48
49 virtual status_t Execute(ReportRequestSet* requests) const = 0;
Joe Onorato1754d742016-11-21 17:51:35 -080050};
51
52/**
Yi Jinedfd5bb2017-09-06 17:09:11 -070053 * Section that generates incident headers.
54 */
Yi Jinb592e3b2018-02-01 15:17:04 -080055class HeaderSection : public Section {
Yi Jinedfd5bb2017-09-06 17:09:11 -070056public:
57 HeaderSection();
58 virtual ~HeaderSection();
59
60 virtual status_t Execute(ReportRequestSet* requests) const;
61};
62
63/**
Yi Jin329130b2018-02-09 16:47:47 -080064 * Section that generates incident metadata.
65 */
Yi Jinb592e3b2018-02-01 15:17:04 -080066class MetadataSection : public Section {
Yi Jin329130b2018-02-09 16:47:47 -080067public:
68 MetadataSection();
69 virtual ~MetadataSection();
70
71 virtual status_t Execute(ReportRequestSet* requests) const;
72};
73
74/**
Joe Onorato1754d742016-11-21 17:51:35 -080075 * Section that reads in a file.
76 */
Yi Jinb592e3b2018-02-01 15:17:04 -080077class FileSection : public Section {
Joe Onorato1754d742016-11-21 17:51:35 -080078public:
Kweku Adamse04ef772018-06-13 12:24:38 -070079 FileSection(int id, const char* filename,
Yi Jin3f360352018-04-16 16:13:04 -070080 int64_t timeoutMs = 5000 /* 5 seconds */);
Joe Onorato1754d742016-11-21 17:51:35 -080081 virtual ~FileSection();
82
83 virtual status_t Execute(ReportRequestSet* requests) const;
84
85private:
86 const char* mFilename;
Yi Jinb592e3b2018-02-01 15:17:04 -080087 bool mIsSysfs; // sysfs files are pollable but return POLLERR by default, handle it separately
Joe Onorato1754d742016-11-21 17:51:35 -080088};
89
90/**
Yi Jin1a11fa12018-02-22 16:44:10 -080091 * Section that reads in a file and gzips the content.
92 */
93class GZipSection : public Section {
94public:
95 GZipSection(int id, const char* filename, ...);
96 virtual ~GZipSection();
97
98 virtual status_t Execute(ReportRequestSet* requests) const;
99
100private:
101 // It looks up the content from multiple files and stops when the first one is available.
102 const char** mFilenames;
103};
104
105/**
Joe Onorato1754d742016-11-21 17:51:35 -0800106 * Base class for sections that call a command that might need a timeout.
107 */
Yi Jinb592e3b2018-02-01 15:17:04 -0800108class WorkerThreadSection : public Section {
Joe Onorato1754d742016-11-21 17:51:35 -0800109public:
Kweku Adams3d160912018-05-07 11:26:27 -0700110 WorkerThreadSection(int id, int64_t timeoutMs = REMOTE_CALL_TIMEOUT_MS,
111 bool userdebugAndEngOnly = false);
Joe Onorato1754d742016-11-21 17:51:35 -0800112 virtual ~WorkerThreadSection();
113
114 virtual status_t Execute(ReportRequestSet* requests) const;
115
116 virtual status_t BlockingCall(int pipeWriteFd) const = 0;
117};
118
119/**
120 * Section that forks and execs a command, and puts stdout as the section.
121 */
Yi Jinb592e3b2018-02-01 15:17:04 -0800122class CommandSection : public Section {
Joe Onorato1754d742016-11-21 17:51:35 -0800123public:
Yi Jin3f360352018-04-16 16:13:04 -0700124 CommandSection(int id, int64_t timeoutMs, const char* command, ...);
Yi Jinb44f7d42017-07-21 12:12:59 -0700125
126 CommandSection(int id, const char* command, ...);
127
Joe Onorato1754d742016-11-21 17:51:35 -0800128 virtual ~CommandSection();
129
130 virtual status_t Execute(ReportRequestSet* requests) const;
131
132private:
133 const char** mCommand;
Joe Onorato1754d742016-11-21 17:51:35 -0800134};
135
136/**
137 * Section that calls dumpsys on a system service.
138 */
Yi Jinb592e3b2018-02-01 15:17:04 -0800139class DumpsysSection : public WorkerThreadSection {
Joe Onorato1754d742016-11-21 17:51:35 -0800140public:
Kweku Adams3d160912018-05-07 11:26:27 -0700141 DumpsysSection(int id, bool userdebugAndEngOnly, const char* service, ...);
Joe Onorato1754d742016-11-21 17:51:35 -0800142 virtual ~DumpsysSection();
143
144 virtual status_t BlockingCall(int pipeWriteFd) const;
145
146private:
147 String16 mService;
148 Vector<String16> mArgs;
149};
150
Yi Jin3c034c92017-12-22 17:36:47 -0800151/**
152 * Section that reads from logd.
153 */
Yi Jinb592e3b2018-02-01 15:17:04 -0800154class LogSection : public WorkerThreadSection {
Yi Jin3c034c92017-12-22 17:36:47 -0800155 // global last log retrieved timestamp for each log_id_t.
156 static map<log_id_t, log_time> gLastLogsRetrieved;
157
158public:
159 LogSection(int id, log_id_t logID);
160 virtual ~LogSection();
161
162 virtual status_t BlockingCall(int pipeWriteFd) const;
163
164private:
165 log_id_t mLogID;
166 bool mBinary;
167};
168
Kweku Adamseadd1232018-02-05 16:45:13 -0800169/**
170 * Section that gets data from tombstoned.
171 */
172class TombstoneSection : public WorkerThreadSection {
173public:
Kweku Adams0f716792018-09-13 15:48:27 -0700174 TombstoneSection(int id, const char* type, int64_t timeoutMs = 120000 /* 2 minutes */);
Kweku Adamseadd1232018-02-05 16:45:13 -0800175 virtual ~TombstoneSection();
176
177 virtual status_t BlockingCall(int pipeWriteFd) const;
178
179private:
180 std::string mType;
181};
182
Yi Jin6cacbcb2018-03-30 14:04:52 -0700183} // namespace incidentd
184} // namespace os
185} // namespace android
186
Yi Jinb592e3b2018-02-01 15:17:04 -0800187#endif // SECTIONS_H