Merge "Set up config update code path"

This commit is contained in:
TreeHugger Robot
2020-08-01 00:00:30 +00:00
committed by Android (Google) Code Review
6 changed files with 36 additions and 14 deletions

View File

@@ -526,19 +526,34 @@ void StatsLogProcessor::OnConfigUpdated(const int64_t timestampNs, const ConfigK
OnConfigUpdatedLocked(timestampNs, key, config);
}
void StatsLogProcessor::OnConfigUpdatedLocked(
const int64_t timestampNs, const ConfigKey& key, const StatsdConfig& config) {
void StatsLogProcessor::OnConfigUpdatedLocked(const int64_t timestampNs, const ConfigKey& key,
const StatsdConfig& config, bool modularUpdate) {
VLOG("Updated configuration for key %s", key.ToString().c_str());
sp<MetricsManager> newMetricsManager =
new MetricsManager(key, config, mTimeBaseNs, timestampNs, mUidMap, mPullerManager,
mAnomalyAlarmMonitor, mPeriodicAlarmMonitor);
if (newMetricsManager->isConfigValid()) {
newMetricsManager->init();
mUidMap->OnConfigUpdated(key);
newMetricsManager->refreshTtl(timestampNs);
mMetricsManagers[key] = newMetricsManager;
VLOG("StatsdConfig valid");
// Create new config if this is not a modular update or if this is a new config.
const auto& it = mMetricsManagers.find(key);
bool configValid = false;
if (!modularUpdate || it == mMetricsManagers.end()) {
sp<MetricsManager> newMetricsManager =
new MetricsManager(key, config, mTimeBaseNs, timestampNs, mUidMap, mPullerManager,
mAnomalyAlarmMonitor, mPeriodicAlarmMonitor);
configValid = newMetricsManager->isConfigValid();
if (configValid) {
newMetricsManager->init();
mUidMap->OnConfigUpdated(key);
newMetricsManager->refreshTtl(timestampNs);
mMetricsManagers[key] = newMetricsManager;
VLOG("StatsdConfig valid");
}
} else {
// Preserve the existing MetricsManager, update necessary components and metadata in place.
configValid = it->second->updateConfig(timestampNs, config);
if (configValid) {
// TODO(b/162323476): refresh TTL, ensure init() is handled properly.
mUidMap->OnConfigUpdated(key);
}
}
if (!configValid) {
// If there is any error in the config, don't use it.
// Remove any existing config with the same key.
ALOGE("StatsdConfig NOT valid");

View File

@@ -187,8 +187,8 @@ private:
void resetIfConfigTtlExpiredLocked(const int64_t timestampNs);
void OnConfigUpdatedLocked(
const int64_t currentTimestampNs, const ConfigKey& key, const StatsdConfig& config);
void OnConfigUpdatedLocked(const int64_t currentTimestampNs, const ConfigKey& key,
const StatsdConfig& config, bool modularUpdate = false);
void GetActiveConfigsLocked(const int uid, vector<int64_t>& outActiveConfigs);

View File

@@ -195,6 +195,10 @@ MetricsManager::~MetricsManager() {
VLOG("~MetricsManager()");
}
bool MetricsManager::updateConfig(const int64_t currentTimeNs, const StatsdConfig& config) {
return mConfigValid;
}
void MetricsManager::initLogSourceWhiteList() {
std::lock_guard<std::mutex> lock(mAllowedLogSourcesMutex);
mAllowedLogSources.clear();

View File

@@ -46,6 +46,8 @@ public:
virtual ~MetricsManager();
bool updateConfig(const int64_t currentTimeNs, const StatsdConfig& config);
// Return whether the configuration is valid.
bool isConfigValid() const;

View File

@@ -17,6 +17,8 @@
#ifndef STATSD_PACKAGE_INFO_LISTENER_H
#define STATSD_PACKAGE_INFO_LISTENER_H
#include <utils/RefBase.h>
#include <string>
namespace android {

View File

@@ -17,7 +17,6 @@
#pragma once
#include "config/ConfigKey.h"
#include "config/ConfigListener.h"
#include "packages/PackageInfoListener.h"
#include "stats_util.h"