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 | |
Yi Jin | 6cacbcb | 2018-03-30 14:04:52 -0700 | [diff] [blame] | 30 | namespace android { |
| 31 | namespace os { |
| 32 | namespace incidentd { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 33 | |
Yi Jin | ad3e6e5 | 2018-04-03 15:10:34 -0700 | [diff] [blame] | 34 | const int64_t REMOTE_CALL_TIMEOUT_MS = 30 * 1000; // 30 seconds |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 35 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 36 | /** |
| 37 | * Base class for sections |
| 38 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 39 | class Section { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 40 | public: |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 41 | const int id; |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 42 | const int64_t timeoutMs; // each section must have a timeout |
Yi Jin | 3f36035 | 2018-04-16 16:13:04 -0700 | [diff] [blame^] | 43 | const bool deviceSpecific; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 44 | String8 name; |
| 45 | |
Yi Jin | 3f36035 | 2018-04-16 16:13:04 -0700 | [diff] [blame^] | 46 | Section(int id, int64_t timeoutMs = REMOTE_CALL_TIMEOUT_MS, bool deviceSpecific = false); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 47 | virtual ~Section(); |
| 48 | |
| 49 | virtual status_t Execute(ReportRequestSet* requests) const = 0; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | /** |
Yi Jin | edfd5bb | 2017-09-06 17:09:11 -0700 | [diff] [blame] | 53 | * Section that generates incident headers. |
| 54 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 55 | class HeaderSection : public Section { |
Yi Jin | edfd5bb | 2017-09-06 17:09:11 -0700 | [diff] [blame] | 56 | public: |
| 57 | HeaderSection(); |
| 58 | virtual ~HeaderSection(); |
| 59 | |
| 60 | virtual status_t Execute(ReportRequestSet* requests) const; |
| 61 | }; |
| 62 | |
| 63 | /** |
Yi Jin | 329130b | 2018-02-09 16:47:47 -0800 | [diff] [blame] | 64 | * Section that generates incident metadata. |
| 65 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 66 | class MetadataSection : public Section { |
Yi Jin | 329130b | 2018-02-09 16:47:47 -0800 | [diff] [blame] | 67 | public: |
| 68 | MetadataSection(); |
| 69 | virtual ~MetadataSection(); |
| 70 | |
| 71 | virtual status_t Execute(ReportRequestSet* requests) const; |
| 72 | }; |
| 73 | |
| 74 | /** |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 75 | * Section that reads in a file. |
| 76 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 77 | class FileSection : public Section { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 78 | public: |
Yi Jin | 3f36035 | 2018-04-16 16:13:04 -0700 | [diff] [blame^] | 79 | FileSection(int id, const char* filename, bool deviceSpecific = false, |
| 80 | int64_t timeoutMs = 5000 /* 5 seconds */); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 81 | virtual ~FileSection(); |
| 82 | |
| 83 | virtual status_t Execute(ReportRequestSet* requests) const; |
| 84 | |
| 85 | private: |
| 86 | const char* mFilename; |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 87 | 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] | 88 | }; |
| 89 | |
| 90 | /** |
Yi Jin | 1a11fa1 | 2018-02-22 16:44:10 -0800 | [diff] [blame] | 91 | * Section that reads in a file and gzips the content. |
| 92 | */ |
| 93 | class GZipSection : public Section { |
| 94 | public: |
| 95 | GZipSection(int id, const char* filename, ...); |
| 96 | virtual ~GZipSection(); |
| 97 | |
| 98 | virtual status_t Execute(ReportRequestSet* requests) const; |
| 99 | |
| 100 | private: |
| 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 Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 106 | * Base class for sections that call a command that might need a timeout. |
| 107 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 108 | class WorkerThreadSection : public Section { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 109 | public: |
Yi Jin | 3f36035 | 2018-04-16 16:13:04 -0700 | [diff] [blame^] | 110 | WorkerThreadSection(int id, int64_t timeoutMs = REMOTE_CALL_TIMEOUT_MS); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 111 | virtual ~WorkerThreadSection(); |
| 112 | |
| 113 | virtual status_t Execute(ReportRequestSet* requests) const; |
| 114 | |
| 115 | virtual status_t BlockingCall(int pipeWriteFd) const = 0; |
| 116 | }; |
| 117 | |
| 118 | /** |
| 119 | * Section that forks and execs a command, and puts stdout as the section. |
| 120 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 121 | class CommandSection : public Section { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 122 | public: |
Yi Jin | 3f36035 | 2018-04-16 16:13:04 -0700 | [diff] [blame^] | 123 | CommandSection(int id, int64_t timeoutMs, const char* command, ...); |
Yi Jin | b44f7d4 | 2017-07-21 12:12:59 -0700 | [diff] [blame] | 124 | |
| 125 | CommandSection(int id, const char* command, ...); |
| 126 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 127 | virtual ~CommandSection(); |
| 128 | |
| 129 | virtual status_t Execute(ReportRequestSet* requests) const; |
| 130 | |
| 131 | private: |
| 132 | const char** mCommand; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | /** |
| 136 | * Section that calls dumpsys on a system service. |
| 137 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 138 | class DumpsysSection : public WorkerThreadSection { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 139 | public: |
| 140 | DumpsysSection(int id, const char* service, ...); |
| 141 | virtual ~DumpsysSection(); |
| 142 | |
| 143 | virtual status_t BlockingCall(int pipeWriteFd) const; |
| 144 | |
| 145 | private: |
| 146 | String16 mService; |
| 147 | Vector<String16> mArgs; |
| 148 | }; |
| 149 | |
Yi Jin | 3c034c9 | 2017-12-22 17:36:47 -0800 | [diff] [blame] | 150 | /** |
| 151 | * Section that reads from logd. |
| 152 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 153 | class LogSection : public WorkerThreadSection { |
Yi Jin | 3c034c9 | 2017-12-22 17:36:47 -0800 | [diff] [blame] | 154 | // global last log retrieved timestamp for each log_id_t. |
| 155 | static map<log_id_t, log_time> gLastLogsRetrieved; |
| 156 | |
| 157 | public: |
| 158 | LogSection(int id, log_id_t logID); |
| 159 | virtual ~LogSection(); |
| 160 | |
| 161 | virtual status_t BlockingCall(int pipeWriteFd) const; |
| 162 | |
| 163 | private: |
| 164 | log_id_t mLogID; |
| 165 | bool mBinary; |
| 166 | }; |
| 167 | |
Kweku Adams | eadd123 | 2018-02-05 16:45:13 -0800 | [diff] [blame] | 168 | /** |
| 169 | * Section that gets data from tombstoned. |
| 170 | */ |
| 171 | class TombstoneSection : public WorkerThreadSection { |
| 172 | public: |
Yi Jin | 3f36035 | 2018-04-16 16:13:04 -0700 | [diff] [blame^] | 173 | TombstoneSection(int id, const char* type, int64_t timeoutMs = 30000 /* 30 seconds */); |
Kweku Adams | eadd123 | 2018-02-05 16:45:13 -0800 | [diff] [blame] | 174 | virtual ~TombstoneSection(); |
| 175 | |
| 176 | virtual status_t BlockingCall(int pipeWriteFd) const; |
| 177 | |
| 178 | private: |
| 179 | std::string mType; |
| 180 | }; |
| 181 | |
Yi Jin | 6cacbcb | 2018-03-30 14:04:52 -0700 | [diff] [blame] | 182 | } // namespace incidentd |
| 183 | } // namespace os |
| 184 | } // namespace android |
| 185 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 186 | #endif // SECTIONS_H |