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 INCIDENT_SERVICE_H |
| 19 | #define INCIDENT_SERVICE_H |
| 20 | |
| 21 | #include "Reporter.h" |
| 22 | |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 23 | #include "Broadcaster.h" |
| 24 | #include "Throttler.h" |
| 25 | #include "WorkDirectory.h" |
| 26 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 27 | #include <android/os/BnIncidentManager.h> |
| 28 | #include <utils/Looper.h> |
| 29 | |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 30 | #include <vector> |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 31 | #include <mutex> |
| 32 | |
Yi Jin | 4e84310 | 2018-02-14 15:36:18 -0800 | [diff] [blame] | 33 | |
Yi Jin | 6cacbcb | 2018-03-30 14:04:52 -0700 | [diff] [blame] | 34 | namespace android { |
| 35 | namespace os { |
| 36 | namespace incidentd { |
| 37 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 38 | using namespace android; |
| 39 | using namespace android::base; |
| 40 | using namespace android::binder; |
| 41 | using namespace android::os; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 42 | |
| 43 | // ================================================================================ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 44 | class ReportHandler : public MessageHandler { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 45 | public: |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 46 | ReportHandler(const sp<WorkDirectory>& workDirectory, |
| 47 | const sp<Broadcaster>& broadcaster, const sp<Looper>& handlerLooper, |
| 48 | const sp<Throttler>& throttler); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 49 | virtual ~ReportHandler(); |
| 50 | |
| 51 | virtual void handleMessage(const Message& message); |
| 52 | |
| 53 | /** |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 54 | * Schedule a report for the "main" report, where it will be delivered to |
| 55 | * the uploaders and/or dropbox. |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 56 | */ |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 57 | void schedulePersistedReport(const IncidentReportArgs& args); |
| 58 | |
| 59 | /** |
| 60 | * Adds a ReportRequest to the queue for one that has a listener an and fd |
| 61 | */ |
| 62 | void scheduleStreamingReport(const IncidentReportArgs& args, |
| 63 | const sp<IIncidentReportStatusListener>& listener, |
| 64 | int streamFd); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * Resets mBacklogDelay to the default and schedules sending |
| 68 | * the messages to dropbox. |
| 69 | */ |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 70 | void scheduleSendBacklog(); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 71 | |
| 72 | private: |
| 73 | mutex mLock; |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 74 | |
| 75 | sp<WorkDirectory> mWorkDirectory; |
| 76 | sp<Broadcaster> mBroadcaster; |
| 77 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 78 | sp<Looper> mHandlerLooper; |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 79 | nsecs_t mBacklogDelay; |
Yi Jin | 4e84310 | 2018-02-14 15:36:18 -0800 | [diff] [blame] | 80 | sp<Throttler> mThrottler; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 81 | |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 82 | sp<ReportBatch> mBatch; |
| 83 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 84 | /** |
| 85 | * Runs all of the reports that have been queued. |
| 86 | */ |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 87 | void take_report(); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 88 | |
| 89 | /** |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 90 | * Schedules permission controller approve the reports. |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 91 | */ |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 92 | void schedule_send_approvals_locked(); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 93 | |
| 94 | /** |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 95 | * Sends the approvals to the PermissionController |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 96 | */ |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 97 | void send_approvals(); |
| 98 | |
| 99 | /** |
| 100 | * Schedules the broadcasts that reports are complete mBacklogDelay nanoseconds from now. |
| 101 | * The delay is because typically when an incident report is taken, the system is not |
| 102 | * really in a happy state. So we wait a bit before sending the report to let things |
| 103 | * quiet down if they can. The urgency is in taking the report, not sharing the report. |
| 104 | * However, we don |
| 105 | */ |
| 106 | void schedule_send_broadcasts_locked(); |
| 107 | |
| 108 | /** |
| 109 | * Sends the broadcasts to the dropbox service. |
| 110 | */ |
| 111 | void send_broadcasts(); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 112 | }; |
| 113 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 114 | // ================================================================================ |
| 115 | class IncidentService : public BnIncidentManager { |
| 116 | public: |
Chih-Hung Hsieh | 7a88a93 | 2018-12-20 13:45:04 -0800 | [diff] [blame] | 117 | explicit IncidentService(const sp<Looper>& handlerLooper); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 118 | virtual ~IncidentService(); |
| 119 | |
| 120 | virtual Status reportIncident(const IncidentReportArgs& args); |
| 121 | |
| 122 | virtual Status reportIncidentToStream(const IncidentReportArgs& args, |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 123 | const sp<IIncidentReportStatusListener>& listener, |
Jiyong Park | b8ba234 | 2019-11-25 11:03:38 +0900 | [diff] [blame] | 124 | unique_fd stream); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 125 | |
Jiyong Park | b8ba234 | 2019-11-25 11:03:38 +0900 | [diff] [blame] | 126 | virtual Status reportIncidentToDumpstate(unique_fd stream, |
Mike Ma | 5a57d79 | 2019-08-21 14:52:46 -0700 | [diff] [blame] | 127 | const sp<IIncidentReportStatusListener>& listener); |
| 128 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 129 | virtual Status systemRunning(); |
| 130 | |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 131 | virtual Status getIncidentReportList(const String16& pkg, const String16& cls, |
| 132 | vector<String16>* result); |
| 133 | |
| 134 | virtual Status getIncidentReport(const String16& pkg, const String16& cls, |
| 135 | const String16& id, IncidentManager::IncidentReport* result); |
| 136 | |
| 137 | virtual Status deleteIncidentReports(const String16& pkg, const String16& cls, |
| 138 | const String16& id); |
| 139 | |
| 140 | virtual Status deleteAllIncidentReports(const String16& pkg); |
| 141 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 142 | // Implement commands for debugging purpose. |
| 143 | virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 144 | uint32_t flags) override; |
| 145 | virtual status_t command(FILE* in, FILE* out, FILE* err, Vector<String8>& args); |
| 146 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 147 | private: |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 148 | sp<WorkDirectory> mWorkDirectory; |
| 149 | sp<Broadcaster> mBroadcaster; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 150 | sp<ReportHandler> mHandler; |
Yi Jin | 4e84310 | 2018-02-14 15:36:18 -0800 | [diff] [blame] | 151 | sp<Throttler> mThrottler; |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 152 | |
| 153 | /** |
| 154 | * Commands print out help. |
| 155 | */ |
| 156 | status_t cmd_help(FILE* out); |
| 157 | |
| 158 | /** |
| 159 | * Commands related to privacy filtering. |
| 160 | */ |
| 161 | status_t cmd_privacy(FILE* in, FILE* out, FILE* err, Vector<String8>& args); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 162 | }; |
| 163 | |
Yi Jin | 6cacbcb | 2018-03-30 14:04:52 -0700 | [diff] [blame] | 164 | } // namespace incidentd |
| 165 | } // namespace os |
| 166 | } // namespace android |
| 167 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame] | 168 | #endif // INCIDENT_SERVICE_H |