| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#pragma once |
| 17 |
|
| 18 |
#include "WorkDirectory.h" |
| 19 |
|
| 20 |
#include <android/os/BnIncidentAuthListener.h> |
| 21 |
#include <android/os/IIncidentCompanion.h> |
| 22 |
#include <frameworks/base/cmds/incidentd/src/report_file.pb.h> |
| 23 |
|
| 24 |
namespace android { |
| 25 |
namespace os { |
| 26 |
namespace incidentd { |
| 27 |
|
| 28 |
using android::binder::Status; |
| 29 |
using android::os::BnIncidentAuthListener; |
| 30 |
using android::os::IIncidentCompanion; |
| 31 |
|
| 32 |
class ReportHandler; |
| 33 |
|
| 34 |
class Broadcaster : public virtual RefBase { |
| 35 |
public: |
| 36 |
enum broadcast_status_t { |
| 37 |
BROADCASTS_FINISHED = 0, |
| 38 |
BROADCASTS_REPEAT = 1, |
| 39 |
BROADCASTS_BACKOFF = 2 |
| 40 |
}; |
| 41 |
|
| 42 |
Broadcaster(const sp<WorkDirectory>& workDirectory); |
| 43 |
|
| 44 |
void setHandler(const sp<ReportHandler>& handler); |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
void reset(); |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
void clearBroadcasts(const string& pkg, const string& cls, const string& id); |
| 57 |
void clearPackageBroadcasts(const string& pkg); |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
broadcast_status_t sendBroadcasts(); |
| 63 |
|
| 64 |
private: |
| 65 |
struct ReportId { |
| 66 |
ReportId(); |
| 67 |
ReportId(const ReportId& that); |
| 68 |
ReportId(const string& i, const string& p, const string& c); |
| 69 |
~ReportId(); |
| 70 |
|
| 71 |
bool operator<(const ReportId& that) const; |
| 72 |
|
| 73 |
string id; |
| 74 |
string pkg; |
| 75 |
string cls; |
| 76 |
}; |
| 77 |
|
| 78 |
class ConsentListener : public BnIncidentAuthListener { |
| 79 |
public: |
| 80 |
ConsentListener(const sp<Broadcaster>& broadcaster, const ReportId& reportId); |
| 81 |
virtual ~ConsentListener(); |
| 82 |
virtual Status onReportApproved(); |
| 83 |
virtual Status onReportDenied(); |
| 84 |
private: |
| 85 |
sp<Broadcaster> mBroadcaster; |
| 86 |
ReportId mId; |
| 87 |
}; |
| 88 |
|
| 89 |
struct ReportStatus { |
| 90 |
ReportStatus(); |
| 91 |
ReportStatus(const ReportStatus& that); |
| 92 |
~ReportStatus(); |
| 93 |
|
| 94 |
bool approval_sent; |
| 95 |
bool ready_sent; |
| 96 |
sp<ConsentListener> listener; |
| 97 |
}; |
| 98 |
|
| 99 |
sp<ReportHandler> mReportHandler; |
| 100 |
sp<WorkDirectory> mWorkDirectory; |
| 101 |
|
| 102 |
|
| 103 |
mutex mLock; |
| 104 |
map<ReportId,ReportStatus> mHistory; |
| 105 |
int64_t mLastSent; |
| 106 |
|
| 107 |
void set_last_sent(int64_t timestamp); |
| 108 |
int64_t get_last_sent(); |
| 109 |
void print_report_statuses() const; |
| 110 |
status_t send_approval_broadcasts(const string& id, const string& pkg, const string& cls); |
| 111 |
void report_approved(const ReportId& reportId); |
| 112 |
void report_denied(const ReportId& reportId); |
| 113 |
status_t send_report_ready_broadcasts(const string& id, const string& pkg, const string& cls); |
| 114 |
status_t send_to_dropbox(const sp<ReportFile>& file, const IncidentReportArgs& args); |
| 115 |
bool was_approval_sent(const string& id, const string& pkg, const string& cls); |
| 116 |
void set_approval_sent(const string& id, const string& pkg, const string& cls, |
| 117 |
const sp<ConsentListener>& listener); |
| 118 |
bool was_ready_sent(const string& id, const string& pkg, const string& cls); |
| 119 |
void set_ready_sent(const string& id, const string& pkg, const string& cls); |
| 120 |
sp<IIncidentCompanion> get_incident_companion(); |
| 121 |
}; |
| 122 |
|
| 123 |
|
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
|