1 #ifndef RESTRICTED_EVENT_METRIC_PRODUCER_H
2 #define RESTRICTED_EVENT_METRIC_PRODUCER_H
3 
4 #include <gtest/gtest_prod.h>
5 
6 #include "EventMetricProducer.h"
7 #include "utils/RestrictedPolicyManager.h"
8 
9 namespace android {
10 namespace os {
11 namespace statsd {
12 
13 class RestrictedEventMetricProducer : public EventMetricProducer {
14 public:
15     RestrictedEventMetricProducer(
16             const ConfigKey& key, const EventMetric& eventMetric, const int conditionIndex,
17             const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard,
18             const uint64_t protoHash, int64_t startTimeNs,
19             const wp<ConfigMetadataProvider> configMetadataProvider,
20             const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap = {},
21             const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
22                     eventDeactivationMap = {},
23             const vector<int>& slicedStateAtoms = {},
24             const unordered_map<int, unordered_map<int, int64_t>>& stateGroupMap = {});
25 
26     void onMetricRemove() override;
27 
28     void enforceRestrictedDataTtl(sqlite3* db, int64_t wallClockNs);
29 
30     void flushRestrictedData() override;
31 
32     bool writeMetricMetadataToProto(metadata::MetricMetadata* metricMetadata) override;
33 
34     void loadMetricMetadataFromProto(const metadata::MetricMetadata& metricMetadata) override;
35 
getRestrictionCategory()36     inline StatsdRestrictionCategory getRestrictionCategory() {
37         std::lock_guard<std::mutex> lock(mMutex);
38         return mRestrictedDataCategory;
39     }
40 
41 private:
42     void onMatchedLogEventInternalLocked(
43             const size_t matcherIndex, const MetricDimensionKey& eventKey,
44             const ConditionKey& conditionKey, bool condition, const LogEvent& event,
45             const std::map<int, HashableDimensionKey>& statePrimaryKeys) override;
46 
47     void onDumpReportLocked(const int64_t dumpTimeNs, const bool include_current_partial_bucket,
48                             const bool erase_data, const DumpLatency dumpLatency,
49                             std::set<string>* str_set,
50                             android::util::ProtoOutputStream* protoOutput) override;
51 
52     void clearPastBucketsLocked(const int64_t dumpTimeNs) override;
53 
54     void dropDataLocked(const int64_t dropTimeNs) override;
55 
56     void deleteMetricTable();
57 
58     bool mIsMetricTableCreated = false;
59 
60     StatsdRestrictionCategory mRestrictedDataCategory;
61 
62     vector<LogEvent> mLogEvents;
63 };
64 
65 }  // namespace statsd
66 }  // namespace os
67 }  // namespace android
68 #endif  // RESTRICTED_EVENT_METRIC_PRODUCER_H
69