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