| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#pragma once |
| 17 |
|
| 18 |
#ifndef INCIDENT_SERVICE_H |
| 19 |
#define INCIDENT_SERVICE_H |
| 20 |
|
| 21 |
#include "Reporter.h" |
| 22 |
|
| 23 |
#include "Broadcaster.h" |
| 24 |
#include "Throttler.h" |
| 25 |
#include "WorkDirectory.h" |
| 26 |
|
| 27 |
#include <android/os/BnIncidentManager.h> |
| 28 |
#include <utils/Looper.h> |
| 29 |
|
| 30 |
#include <vector> |
| 31 |
#include <mutex> |
| 32 |
|
| 33 |
|
| 34 |
namespace android { |
| 35 |
namespace os { |
| 36 |
namespace incidentd { |
| 37 |
|
| 38 |
using namespace android; |
| 39 |
using namespace android::base; |
| 40 |
using namespace android::binder; |
| 41 |
using namespace android::os; |
| 42 |
|
| 43 |
class BringYourOwnSection; |
| 44 |
|
| 45 |
|
| 46 |
class ReportHandler : public MessageHandler { |
| 47 |
public: |
| 48 |
ReportHandler(const sp<WorkDirectory>& workDirectory, |
| 49 |
const sp<Broadcaster>& broadcaster, |
| 50 |
const sp<Looper>& handlerLooper, |
| 51 |
const sp<Throttler>& throttler, |
| 52 |
const vector<BringYourOwnSection*>& registeredSections); |
| 53 |
virtual ~ReportHandler(); |
| 54 |
|
| 55 |
virtual void handleMessage(const Message& message); |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
void schedulePersistedReport(const IncidentReportArgs& args); |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
void scheduleStreamingReport(const IncidentReportArgs& args, |
| 67 |
const sp<IIncidentReportStatusListener>& listener, |
| 68 |
int streamFd); |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
void scheduleSendBacklog(); |
| 75 |
|
| 76 |
private: |
| 77 |
mutex mLock; |
| 78 |
|
| 79 |
sp<WorkDirectory> mWorkDirectory; |
| 80 |
sp<Broadcaster> mBroadcaster; |
| 81 |
|
| 82 |
sp<Looper> mHandlerLooper; |
| 83 |
nsecs_t mBacklogDelay; |
| 84 |
sp<Throttler> mThrottler; |
| 85 |
|
| 86 |
const vector<BringYourOwnSection*>& mRegisteredSections; |
| 87 |
|
| 88 |
sp<ReportBatch> mBatch; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
void take_report(); |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
void schedule_send_approvals_locked(); |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
void send_approvals(); |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
void schedule_send_broadcasts_locked(); |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
void send_broadcasts(); |
| 118 |
}; |
| 119 |
|
| 120 |
|
| 121 |
class IncidentService : public BnIncidentManager { |
| 122 |
public: |
| 123 |
explicit IncidentService(const sp<Looper>& handlerLooper); |
| 124 |
virtual ~IncidentService(); |
| 125 |
|
| 126 |
virtual Status reportIncident(const IncidentReportArgs& args); |
| 127 |
|
| 128 |
virtual Status reportIncidentToStream(const IncidentReportArgs& args, |
| 129 |
const sp<IIncidentReportStatusListener>& listener, |
| 130 |
unique_fd stream); |
| 131 |
|
| 132 |
virtual Status reportIncidentToDumpstate(unique_fd stream, |
| 133 |
const sp<IIncidentReportStatusListener>& listener); |
| 134 |
|
| 135 |
virtual Status registerSection(int id, const String16& name, |
| 136 |
const sp<IIncidentDumpCallback>& callback); |
| 137 |
|
| 138 |
virtual Status unregisterSection(int id); |
| 139 |
|
| 140 |
virtual Status systemRunning(); |
| 141 |
|
| 142 |
virtual Status getIncidentReportList(const String16& pkg, const String16& cls, |
| 143 |
vector<String16>* result); |
| 144 |
|
| 145 |
virtual Status getIncidentReport(const String16& pkg, const String16& cls, |
| 146 |
const String16& id, IncidentManager::IncidentReport* result); |
| 147 |
|
| 148 |
virtual Status deleteIncidentReports(const String16& pkg, const String16& cls, |
| 149 |
const String16& id); |
| 150 |
|
| 151 |
virtual Status deleteAllIncidentReports(const String16& pkg); |
| 152 |
|
| 153 |
|
| 154 |
virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 155 |
uint32_t flags) override; |
| 156 |
virtual status_t command(FILE* in, FILE* out, FILE* err, Vector<String8>& args); |
| 157 |
|
| 158 |
private: |
| 159 |
sp<WorkDirectory> mWorkDirectory; |
| 160 |
sp<Broadcaster> mBroadcaster; |
| 161 |
sp<ReportHandler> mHandler; |
| 162 |
sp<Throttler> mThrottler; |
| 163 |
vector<BringYourOwnSection*> mRegisteredSections; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
status_t cmd_help(FILE* out); |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
status_t cmd_privacy(FILE* in, FILE* out, FILE* err, Vector<String8>& args); |
| 174 |
}; |
| 175 |
|
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
#endif |