Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e688c64b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add whitelisted atom ids to StatsdConfig" into rvc-dev

parents 3c1b83c3 f681646d
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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());
+2 −0
Original line number Diff line number Diff line
@@ -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;

+2 −0
Original line number Diff line number Diff line
@@ -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;
}
+24 −0
Original line number Diff line number Diff line
@@ -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