Loading cmds/statsd/src/metrics/MetricsManager.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,8 @@ MetricsManager::MetricsManager(const ConfigKey& key, const StatsdConfig& config, mLastReportTimeNs(currentTimeNs), mLastReportWallClockNs(getWallClockNs()), mPullerManager(pullerManager), mWhitelistedAtomIds(config.whitelisted_atom_ids().begin(), config.whitelisted_atom_ids().end()), mShouldPersistHistory(config.persist_locally()) { // Init the ttl end timestamp. refreshTtl(timeBaseNs); Loading Loading @@ -366,11 +368,16 @@ void MetricsManager::onDumpReport(const int64_t dumpTimeStampNs, bool MetricsManager::checkLogCredentials(const LogEvent& event) { // TODO(b/154856835): Remove this check once we get whitelist from the config. if (android::util::AtomsInfo::kWhitelistedAtoms.find(event.GetTagId()) != android::util::AtomsInfo::kWhitelistedAtoms.end()) { return true; } if (mWhitelistedAtomIds.find(event.GetTagId()) != mWhitelistedAtomIds.end()) { return true; } std::lock_guard<std::mutex> lock(mAllowedLogSourcesMutex); if (mAllowedLogSources.find(event.GetUid()) == mAllowedLogSources.end()) { VLOG("log source %d not on the whitelist", event.GetUid()); Loading cmds/statsd/src/metrics/MetricsManager.h +2 −0 Original line number Diff line number Diff line Loading @@ -189,6 +189,8 @@ private: // To guard access to mAllowedLogSources mutable std::mutex mAllowedLogSourcesMutex; const std::set<int32_t> mWhitelistedAtomIds; // We can pull any atom from these uids. std::set<int32_t> mDefaultPullUids; Loading cmds/statsd/src/statsd_config.proto +2 −0 Original line number Diff line number Diff line Loading @@ -489,6 +489,8 @@ message StatsdConfig { repeated PullAtomPackages pull_atom_packages = 23; repeated int32 whitelisted_atom_ids = 24; // Field number 1000 is reserved for later use. reserved 1000; } cmds/statsd/tests/MetricsManager_test.cpp +24 −0 Original line number Diff line number Diff line Loading @@ -591,6 +591,30 @@ TEST(MetricsManagerTest, TestLogSources) { EXPECT_TRUE(isSubset(defaultPullUids, set<int32_t>(atom3Uids.begin(), atom3Uids.end()))); } TEST(MetricsManagerTest, TestCheckLogCredentialsWhitelistedAtom) { sp<UidMap> uidMap; sp<StatsPullerManager> pullerManager = new StatsPullerManager(); sp<AlarmMonitor> anomalyAlarmMonitor; sp<AlarmMonitor> periodicAlarmMonitor; StatsdConfig config = buildGoodConfig(); config.add_whitelisted_atom_ids(3); config.add_whitelisted_atom_ids(4); MetricsManager metricsManager(kConfigKey, config, timeBaseSec, timeBaseSec, uidMap, pullerManager, anomalyAlarmMonitor, periodicAlarmMonitor); LogEvent event(0 /* uid */, 0 /* pid */); CreateNoValuesLogEvent(&event, 10 /* atom id */, 0 /* timestamp */); EXPECT_FALSE(metricsManager.checkLogCredentials(event)); CreateNoValuesLogEvent(&event, 3 /* atom id */, 0 /* timestamp */); EXPECT_TRUE(metricsManager.checkLogCredentials(event)); CreateNoValuesLogEvent(&event, 4 /* atom id */, 0 /* timestamp */); EXPECT_TRUE(metricsManager.checkLogCredentials(event)); } } // namespace statsd } // namespace os } // namespace android Loading Loading
cmds/statsd/src/metrics/MetricsManager.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,8 @@ MetricsManager::MetricsManager(const ConfigKey& key, const StatsdConfig& config, mLastReportTimeNs(currentTimeNs), mLastReportWallClockNs(getWallClockNs()), mPullerManager(pullerManager), mWhitelistedAtomIds(config.whitelisted_atom_ids().begin(), config.whitelisted_atom_ids().end()), mShouldPersistHistory(config.persist_locally()) { // Init the ttl end timestamp. refreshTtl(timeBaseNs); Loading Loading @@ -366,11 +368,16 @@ void MetricsManager::onDumpReport(const int64_t dumpTimeStampNs, bool MetricsManager::checkLogCredentials(const LogEvent& event) { // TODO(b/154856835): Remove this check once we get whitelist from the config. if (android::util::AtomsInfo::kWhitelistedAtoms.find(event.GetTagId()) != android::util::AtomsInfo::kWhitelistedAtoms.end()) { return true; } if (mWhitelistedAtomIds.find(event.GetTagId()) != mWhitelistedAtomIds.end()) { return true; } std::lock_guard<std::mutex> lock(mAllowedLogSourcesMutex); if (mAllowedLogSources.find(event.GetUid()) == mAllowedLogSources.end()) { VLOG("log source %d not on the whitelist", event.GetUid()); Loading
cmds/statsd/src/metrics/MetricsManager.h +2 −0 Original line number Diff line number Diff line Loading @@ -189,6 +189,8 @@ private: // To guard access to mAllowedLogSources mutable std::mutex mAllowedLogSourcesMutex; const std::set<int32_t> mWhitelistedAtomIds; // We can pull any atom from these uids. std::set<int32_t> mDefaultPullUids; Loading
cmds/statsd/src/statsd_config.proto +2 −0 Original line number Diff line number Diff line Loading @@ -489,6 +489,8 @@ message StatsdConfig { repeated PullAtomPackages pull_atom_packages = 23; repeated int32 whitelisted_atom_ids = 24; // Field number 1000 is reserved for later use. reserved 1000; }
cmds/statsd/tests/MetricsManager_test.cpp +24 −0 Original line number Diff line number Diff line Loading @@ -591,6 +591,30 @@ TEST(MetricsManagerTest, TestLogSources) { EXPECT_TRUE(isSubset(defaultPullUids, set<int32_t>(atom3Uids.begin(), atom3Uids.end()))); } TEST(MetricsManagerTest, TestCheckLogCredentialsWhitelistedAtom) { sp<UidMap> uidMap; sp<StatsPullerManager> pullerManager = new StatsPullerManager(); sp<AlarmMonitor> anomalyAlarmMonitor; sp<AlarmMonitor> periodicAlarmMonitor; StatsdConfig config = buildGoodConfig(); config.add_whitelisted_atom_ids(3); config.add_whitelisted_atom_ids(4); MetricsManager metricsManager(kConfigKey, config, timeBaseSec, timeBaseSec, uidMap, pullerManager, anomalyAlarmMonitor, periodicAlarmMonitor); LogEvent event(0 /* uid */, 0 /* pid */); CreateNoValuesLogEvent(&event, 10 /* atom id */, 0 /* timestamp */); EXPECT_FALSE(metricsManager.checkLogCredentials(event)); CreateNoValuesLogEvent(&event, 3 /* atom id */, 0 /* timestamp */); EXPECT_TRUE(metricsManager.checkLogCredentials(event)); CreateNoValuesLogEvent(&event, 4 /* atom id */, 0 /* timestamp */); EXPECT_TRUE(metricsManager.checkLogCredentials(event)); } } // namespace statsd } // namespace os } // namespace android Loading