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