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

Commit 7c6e121c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

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

Change-Id: I90b9809c17a14af0f4d729937a7569b7a2701384
parents c8d5b6ce e688c64b
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -71,6 +71,8 @@ MetricsManager::MetricsManager(const ConfigKey& key, const StatsdConfig& config,
      mLastReportTimeNs(currentTimeNs),
      mLastReportTimeNs(currentTimeNs),
      mLastReportWallClockNs(getWallClockNs()),
      mLastReportWallClockNs(getWallClockNs()),
      mPullerManager(pullerManager),
      mPullerManager(pullerManager),
      mWhitelistedAtomIds(config.whitelisted_atom_ids().begin(),
                          config.whitelisted_atom_ids().end()),
      mShouldPersistHistory(config.persist_locally()) {
      mShouldPersistHistory(config.persist_locally()) {
    // Init the ttl end timestamp.
    // Init the ttl end timestamp.
    refreshTtl(timeBaseNs);
    refreshTtl(timeBaseNs);
@@ -366,11 +368,16 @@ void MetricsManager::onDumpReport(const int64_t dumpTimeStampNs,




bool MetricsManager::checkLogCredentials(const LogEvent& event) {
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()) !=
    if (android::util::AtomsInfo::kWhitelistedAtoms.find(event.GetTagId()) !=
      android::util::AtomsInfo::kWhitelistedAtoms.end())
      android::util::AtomsInfo::kWhitelistedAtoms.end())
    {
    {
        return true;
        return true;
    }
    }

    if (mWhitelistedAtomIds.find(event.GetTagId()) != mWhitelistedAtomIds.end()) {
        return true;
    }
    std::lock_guard<std::mutex> lock(mAllowedLogSourcesMutex);
    std::lock_guard<std::mutex> lock(mAllowedLogSourcesMutex);
    if (mAllowedLogSources.find(event.GetUid()) == mAllowedLogSources.end()) {
    if (mAllowedLogSources.find(event.GetUid()) == mAllowedLogSources.end()) {
        VLOG("log source %d not on the whitelist", event.GetUid());
        VLOG("log source %d not on the whitelist", event.GetUid());
+2 −0
Original line number Original line Diff line number Diff line
@@ -189,6 +189,8 @@ private:
    // To guard access to mAllowedLogSources
    // To guard access to mAllowedLogSources
    mutable std::mutex mAllowedLogSourcesMutex;
    mutable std::mutex mAllowedLogSourcesMutex;


    const std::set<int32_t> mWhitelistedAtomIds;

    // We can pull any atom from these uids.
    // We can pull any atom from these uids.
    std::set<int32_t> mDefaultPullUids;
    std::set<int32_t> mDefaultPullUids;


+2 −0
Original line number Original line Diff line number Diff line
@@ -489,6 +489,8 @@ message StatsdConfig {


  repeated PullAtomPackages pull_atom_packages = 23;
  repeated PullAtomPackages pull_atom_packages = 23;


  repeated int32 whitelisted_atom_ids = 24;

  // Field number 1000 is reserved for later use.
  // Field number 1000 is reserved for later use.
  reserved 1000;
  reserved 1000;
}
}
+24 −0
Original line number Original line Diff line number Diff line
@@ -591,6 +591,30 @@ TEST(MetricsManagerTest, TestLogSources) {
    EXPECT_TRUE(isSubset(defaultPullUids, set<int32_t>(atom3Uids.begin(), atom3Uids.end())));
    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 statsd
}  // namespace os
}  // namespace os
}  // namespace android
}  // namespace android