blob: b2c7f233e11b68d4cd8cfb026b77b56d03eb7db1 [file] [log] [blame]
Joe Onorato1754d742016-11-21 17:51:35 -08001/*
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 Jinb592e3b2018-02-01 15:17:04 -080016#pragma once
Joe Onorato1754d742016-11-21 17:51:35 -080017
18#ifndef INCIDENT_SERVICE_H
19#define INCIDENT_SERVICE_H
20
21#include "Reporter.h"
22
Joe Onorato99598ee2019-02-11 15:55:13 +000023#include "Broadcaster.h"
24#include "Throttler.h"
25#include "WorkDirectory.h"
26
Joe Onorato1754d742016-11-21 17:51:35 -080027#include <android/os/BnIncidentManager.h>
28#include <utils/Looper.h>
29
Joe Onorato99598ee2019-02-11 15:55:13 +000030#include <vector>
Joe Onorato1754d742016-11-21 17:51:35 -080031#include <mutex>
32
Yi Jin4e843102018-02-14 15:36:18 -080033
Yi Jin6cacbcb2018-03-30 14:04:52 -070034namespace android {
35namespace os {
36namespace incidentd {
37
Joe Onorato1754d742016-11-21 17:51:35 -080038using namespace android;
39using namespace android::base;
40using namespace android::binder;
41using namespace android::os;
Joe Onorato1754d742016-11-21 17:51:35 -080042
43// ================================================================================
Yi Jinb592e3b2018-02-01 15:17:04 -080044class ReportHandler : public MessageHandler {
Joe Onorato1754d742016-11-21 17:51:35 -080045public:
Joe Onorato99598ee2019-02-11 15:55:13 +000046 ReportHandler(const sp<WorkDirectory>& workDirectory,
47 const sp<Broadcaster>& broadcaster, const sp<Looper>& handlerLooper,
48 const sp<Throttler>& throttler);
Joe Onorato1754d742016-11-21 17:51:35 -080049 virtual ~ReportHandler();
50
51 virtual void handleMessage(const Message& message);
52
53 /**
Joe Onorato99598ee2019-02-11 15:55:13 +000054 * Schedule a report for the "main" report, where it will be delivered to
55 * the uploaders and/or dropbox.
Joe Onorato1754d742016-11-21 17:51:35 -080056 */
Joe Onorato99598ee2019-02-11 15:55:13 +000057 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 Onorato1754d742016-11-21 17:51:35 -080065
66 /**
67 * Resets mBacklogDelay to the default and schedules sending
68 * the messages to dropbox.
69 */
Joe Onorato99598ee2019-02-11 15:55:13 +000070 void scheduleSendBacklog();
Joe Onorato1754d742016-11-21 17:51:35 -080071
72private:
73 mutex mLock;
Joe Onorato99598ee2019-02-11 15:55:13 +000074
75 sp<WorkDirectory> mWorkDirectory;
76 sp<Broadcaster> mBroadcaster;
77
Joe Onorato1754d742016-11-21 17:51:35 -080078 sp<Looper> mHandlerLooper;
Joe Onorato99598ee2019-02-11 15:55:13 +000079 nsecs_t mBacklogDelay;
Yi Jin4e843102018-02-14 15:36:18 -080080 sp<Throttler> mThrottler;
Joe Onorato1754d742016-11-21 17:51:35 -080081
Joe Onorato99598ee2019-02-11 15:55:13 +000082 sp<ReportBatch> mBatch;
83
Joe Onorato1754d742016-11-21 17:51:35 -080084 /**
85 * Runs all of the reports that have been queued.
86 */
Joe Onorato99598ee2019-02-11 15:55:13 +000087 void take_report();
Joe Onorato1754d742016-11-21 17:51:35 -080088
89 /**
Joe Onorato99598ee2019-02-11 15:55:13 +000090 * Schedules permission controller approve the reports.
Joe Onorato1754d742016-11-21 17:51:35 -080091 */
Joe Onorato99598ee2019-02-11 15:55:13 +000092 void schedule_send_approvals_locked();
Joe Onorato1754d742016-11-21 17:51:35 -080093
94 /**
Joe Onorato99598ee2019-02-11 15:55:13 +000095 * Sends the approvals to the PermissionController
Joe Onorato1754d742016-11-21 17:51:35 -080096 */
Joe Onorato99598ee2019-02-11 15:55:13 +000097 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 Onorato1754d742016-11-21 17:51:35 -0800112};
113
Joe Onorato1754d742016-11-21 17:51:35 -0800114// ================================================================================
115class IncidentService : public BnIncidentManager {
116public:
Chih-Hung Hsieh7a88a932018-12-20 13:45:04 -0800117 explicit IncidentService(const sp<Looper>& handlerLooper);
Joe Onorato1754d742016-11-21 17:51:35 -0800118 virtual ~IncidentService();
119
120 virtual Status reportIncident(const IncidentReportArgs& args);
121
122 virtual Status reportIncidentToStream(const IncidentReportArgs& args,
Yi Jinb592e3b2018-02-01 15:17:04 -0800123 const sp<IIncidentReportStatusListener>& listener,
Jiyong Parkb8ba2342019-11-25 11:03:38 +0900124 unique_fd stream);
Joe Onorato1754d742016-11-21 17:51:35 -0800125
Jiyong Parkb8ba2342019-11-25 11:03:38 +0900126 virtual Status reportIncidentToDumpstate(unique_fd stream,
Mike Ma5a57d792019-08-21 14:52:46 -0700127 const sp<IIncidentReportStatusListener>& listener);
128
Joe Onorato1754d742016-11-21 17:51:35 -0800129 virtual Status systemRunning();
130
Joe Onorato99598ee2019-02-11 15:55:13 +0000131 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 Jinb592e3b2018-02-01 15:17:04 -0800142 // 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 Onorato1754d742016-11-21 17:51:35 -0800147private:
Joe Onorato99598ee2019-02-11 15:55:13 +0000148 sp<WorkDirectory> mWorkDirectory;
149 sp<Broadcaster> mBroadcaster;
Joe Onorato1754d742016-11-21 17:51:35 -0800150 sp<ReportHandler> mHandler;
Yi Jin4e843102018-02-14 15:36:18 -0800151 sp<Throttler> mThrottler;
Yi Jinb592e3b2018-02-01 15:17:04 -0800152
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 Onorato1754d742016-11-21 17:51:35 -0800162};
163
Yi Jin6cacbcb2018-03-30 14:04:52 -0700164} // namespace incidentd
165} // namespace os
166} // namespace android
167
Yi Jinb592e3b2018-02-01 15:17:04 -0800168#endif // INCIDENT_SERVICE_H