Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 1 | /* |
| 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 Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 16 | #pragma once |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 17 | |
| 18 | #ifndef SECTIONS_H |
| 19 | #define SECTIONS_H |
| 20 | |
Yi Jin | 99c248f | 2017-08-25 18:11:58 -0700 | [diff] [blame] | 21 | #include "Reporter.h" |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 22 | |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 23 | #include <stdarg.h> |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 24 | #include <map> |
Yi Jin | 3c034c9 | 2017-12-22 17:36:47 -0800 | [diff] [blame] | 25 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 26 | #include <utils/String16.h> |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 27 | #include <utils/String8.h> |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 28 | #include <utils/Vector.h> |
| 29 | |
| 30 | using namespace android; |
| 31 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 32 | const int64_t REMOTE_CALL_TIMEOUT_MS = 10 * 1000; // 10 seconds |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 33 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 34 | /** |
| 35 | * Base class for sections |
| 36 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 37 | class Section { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 38 | public: |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 39 | const int id; |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 40 | const int64_t timeoutMs; // each section must have a timeout |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 41 | String8 name; |
| 42 | |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 43 | Section(int id, const int64_t timeoutMs = REMOTE_CALL_TIMEOUT_MS); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 44 | virtual ~Section(); |
| 45 | |
| 46 | virtual status_t Execute(ReportRequestSet* requests) const = 0; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | /** |
Yi Jin | edfd5bb | 2017-09-06 17:09:11 -0700 | [diff] [blame] | 50 | * Section that generates incident headers. |
| 51 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 52 | class HeaderSection : public Section { |
Yi Jin | edfd5bb | 2017-09-06 17:09:11 -0700 | [diff] [blame] | 53 | public: |
| 54 | HeaderSection(); |
| 55 | virtual ~HeaderSection(); |
| 56 | |
| 57 | virtual status_t Execute(ReportRequestSet* requests) const; |
| 58 | }; |
| 59 | |
| 60 | /** |
Yi Jin | 329130b | 2018-02-09 16:47:47 -0800 | [diff] [blame] | 61 | * Section that generates incident metadata. |
| 62 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 63 | class MetadataSection : public Section { |
Yi Jin | 329130b | 2018-02-09 16:47:47 -0800 | [diff] [blame] | 64 | public: |
| 65 | MetadataSection(); |
| 66 | virtual ~MetadataSection(); |
| 67 | |
| 68 | virtual status_t Execute(ReportRequestSet* requests) const; |
| 69 | }; |
| 70 | |
| 71 | /** |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 72 | * Section that reads in a file. |
| 73 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 74 | class FileSection : public Section { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 75 | public: |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 76 | FileSection(int id, const char* filename, const int64_t timeoutMs = 5000 /* 5 seconds */); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 77 | virtual ~FileSection(); |
| 78 | |
| 79 | virtual status_t Execute(ReportRequestSet* requests) const; |
| 80 | |
| 81 | private: |
| 82 | const char* mFilename; |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 83 | bool mIsSysfs; // sysfs files are pollable but return POLLERR by default, handle it separately |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | /** |
| 87 | * Base class for sections that call a command that might need a timeout. |
| 88 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 89 | class WorkerThreadSection : public Section { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 90 | public: |
| 91 | WorkerThreadSection(int id); |
| 92 | virtual ~WorkerThreadSection(); |
| 93 | |
| 94 | virtual status_t Execute(ReportRequestSet* requests) const; |
| 95 | |
| 96 | virtual status_t BlockingCall(int pipeWriteFd) const = 0; |
| 97 | }; |
| 98 | |
| 99 | /** |
| 100 | * Section that forks and execs a command, and puts stdout as the section. |
| 101 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 102 | class CommandSection : public Section { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 103 | public: |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 104 | CommandSection(int id, const int64_t timeoutMs, const char* command, ...); |
| 105 | |
| 106 | CommandSection(int id, const char* command, ...); |
| 107 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 108 | virtual ~CommandSection(); |
| 109 | |
| 110 | virtual status_t Execute(ReportRequestSet* requests) const; |
| 111 | |
| 112 | private: |
| 113 | const char** mCommand; |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 114 | |
| 115 | void init(const char* command, va_list args); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | /** |
| 119 | * Section that calls dumpsys on a system service. |
| 120 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 121 | class DumpsysSection : public WorkerThreadSection { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 122 | public: |
| 123 | DumpsysSection(int id, const char* service, ...); |
| 124 | virtual ~DumpsysSection(); |
| 125 | |
| 126 | virtual status_t BlockingCall(int pipeWriteFd) const; |
| 127 | |
| 128 | private: |
| 129 | String16 mService; |
| 130 | Vector<String16> mArgs; |
| 131 | }; |
| 132 | |
Yi Jin | 3c034c9 | 2017-12-22 17:36:47 -0800 | [diff] [blame] | 133 | /** |
| 134 | * Section that reads from logd. |
| 135 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 136 | class LogSection : public WorkerThreadSection { |
Yi Jin | 3c034c9 | 2017-12-22 17:36:47 -0800 | [diff] [blame] | 137 | // global last log retrieved timestamp for each log_id_t. |
| 138 | static map<log_id_t, log_time> gLastLogsRetrieved; |
| 139 | |
| 140 | public: |
| 141 | LogSection(int id, log_id_t logID); |
| 142 | virtual ~LogSection(); |
| 143 | |
| 144 | virtual status_t BlockingCall(int pipeWriteFd) const; |
| 145 | |
| 146 | private: |
| 147 | log_id_t mLogID; |
| 148 | bool mBinary; |
| 149 | }; |
| 150 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 151 | #endif // SECTIONS_H |