blob: 0ab34ede96421f21360da613b1824f0dcd6773d9 [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
23#include <android/os/BnIncidentManager.h>
24#include <utils/Looper.h>
25
26#include <deque>
27#include <mutex>
28
Yi Jin4e843102018-02-14 15:36:18 -080029#include "Throttler.h"
30
Joe Onorato1754d742016-11-21 17:51:35 -080031using namespace android;
32using namespace android::base;
33using namespace android::binder;
34using namespace android::os;
35using namespace std;
36
37// ================================================================================
Yi Jinb592e3b2018-02-01 15:17:04 -080038class ReportRequestQueue : public virtual RefBase {
Joe Onorato1754d742016-11-21 17:51:35 -080039public:
40 ReportRequestQueue();
41 virtual ~ReportRequestQueue();
42
43 void addRequest(const sp<ReportRequest>& request);
44 sp<ReportRequest> getNextRequest();
45
46private:
47 mutex mLock;
48 deque<sp<ReportRequest> > mQueue;
49};
50
Joe Onorato1754d742016-11-21 17:51:35 -080051// ================================================================================
Yi Jinb592e3b2018-02-01 15:17:04 -080052class ReportHandler : public MessageHandler {
Joe Onorato1754d742016-11-21 17:51:35 -080053public:
Yi Jin4e843102018-02-14 15:36:18 -080054 ReportHandler(const sp<Looper>& handlerLooper, const sp<ReportRequestQueue>& queue,
55 const sp<Throttler>& throttler);
Joe Onorato1754d742016-11-21 17:51:35 -080056 virtual ~ReportHandler();
57
58 virtual void handleMessage(const Message& message);
59
60 /**
61 * Adds a ReportRequest to the queue.
62 */
63 void scheduleRunReport(const sp<ReportRequest>& request);
64
65 /**
66 * Resets mBacklogDelay to the default and schedules sending
67 * the messages to dropbox.
68 */
69 void scheduleSendBacklogToDropbox();
70
71private:
72 mutex mLock;
73 nsecs_t mBacklogDelay;
74 sp<Looper> mHandlerLooper;
75 sp<ReportRequestQueue> mQueue;
Yi Jin4e843102018-02-14 15:36:18 -080076 sp<Throttler> mThrottler;
Joe Onorato1754d742016-11-21 17:51:35 -080077
78 /**
79 * Runs all of the reports that have been queued.
80 */
81 void run_report();
82
83 /**
84 * Schedules a dropbox task mBacklogDelay nanoseconds from now.
85 */
86 void schedule_send_backlog_to_dropbox_locked();
87
88 /**
89 * Sends the backlog to the dropbox service.
90 */
91 void send_backlog_to_dropbox();
92};
93
Joe Onorato1754d742016-11-21 17:51:35 -080094// ================================================================================
95class IncidentService : public BnIncidentManager {
96public:
97 IncidentService(const sp<Looper>& handlerLooper);
98 virtual ~IncidentService();
99
100 virtual Status reportIncident(const IncidentReportArgs& args);
101
102 virtual Status reportIncidentToStream(const IncidentReportArgs& args,
Yi Jinb592e3b2018-02-01 15:17:04 -0800103 const sp<IIncidentReportStatusListener>& listener,
104 const unique_fd& stream);
Joe Onorato1754d742016-11-21 17:51:35 -0800105
106 virtual Status systemRunning();
107
Yi Jinb592e3b2018-02-01 15:17:04 -0800108 // Implement commands for debugging purpose.
109 virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
110 uint32_t flags) override;
111 virtual status_t command(FILE* in, FILE* out, FILE* err, Vector<String8>& args);
112
Joe Onorato1754d742016-11-21 17:51:35 -0800113private:
114 sp<ReportRequestQueue> mQueue;
115 sp<ReportHandler> mHandler;
Yi Jin4e843102018-02-14 15:36:18 -0800116 sp<Throttler> mThrottler;
Yi Jinb592e3b2018-02-01 15:17:04 -0800117
118 /**
119 * Commands print out help.
120 */
121 status_t cmd_help(FILE* out);
122
123 /**
124 * Commands related to privacy filtering.
125 */
126 status_t cmd_privacy(FILE* in, FILE* out, FILE* err, Vector<String8>& args);
Joe Onorato1754d742016-11-21 17:51:35 -0800127};
128
Yi Jinb592e3b2018-02-01 15:17:04 -0800129#endif // INCIDENT_SERVICE_H