Merge "Add whitelisted atom ids to StatsdConfig" into rvc-dev am: e688c64bf7 am: d29b709e53 am: 693185661f

Change-Id: Iab6454b2cdfd6cf9f95ac636690f24616a835a5c
This commit is contained in:
TreeHugger Robot
2020-05-15 21:44:58 +00:00
committed by Automerger Merge Worker
4 changed files with 35 additions and 0 deletions

View File

@@ -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);
@@ -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());

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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