Adds client API for interacting with statsd.
This API will primarily be used by GmsCore to send updated configs.
Also, sending a config will implicitly notify the StatsD that this
client wants to know when it should request data for this config.
We send a broadcast so that all interested subscribers can know if
data needs to be pulled.
Test: Manually tested that sending broadcast works via new adb
command added in StatsService.
Change-Id: I23cdd1df706036e14b32c3d01af30c3d4af819fa
diff --git a/bin/src/config/ConfigManager.cpp b/bin/src/config/ConfigManager.cpp
index d86ab57..2a8a741 100644
--- a/bin/src/config/ConfigManager.cpp
+++ b/bin/src/config/ConfigManager.cpp
@@ -60,6 +60,14 @@
}
}
+void ConfigManager::SetConfigReceiver(const ConfigKey& key, const string& pkg, const string& cls) {
+ mConfigReceivers[key] = pair<string, string>(pkg, cls);
+}
+
+void ConfigManager::RemoveConfigReceiver(const ConfigKey& key) {
+ mConfigReceivers.erase(key);
+}
+
void ConfigManager::RemoveConfig(const ConfigKey& key) {
unordered_map<ConfigKey, StatsdConfig>::iterator it = mConfigs.find(key);
if (it != mConfigs.end()) {
@@ -85,6 +93,7 @@
if (it->first.GetUid() == uid) {
removed.push_back(it->first);
it = mConfigs.erase(it);
+ mConfigReceivers.erase(it->first);
} else {
it++;
}
diff --git a/bin/src/config/ConfigManager.h b/bin/src/config/ConfigManager.h
index 5d73eaf..c21247f 100644
--- a/bin/src/config/ConfigManager.h
+++ b/bin/src/config/ConfigManager.h
@@ -32,6 +32,7 @@
using std::string;
using std::unordered_map;
using std::vector;
+using std::pair;
/**
* Keeps track of which configurations have been set from various sources.
@@ -64,6 +65,16 @@
void UpdateConfig(const ConfigKey& key, const StatsdConfig& data);
/**
+ * Sets the broadcast receiver for a configuration key.
+ */
+ void SetConfigReceiver(const ConfigKey& key, const string& pkg, const string& cls);
+
+ /**
+ * Erase any broadcast receiver associated with this config key.
+ */
+ void RemoveConfigReceiver(const ConfigKey& key);
+
+ /**
* A configuration was removed.
*
* Reports this to listeners.
@@ -87,11 +98,17 @@
void update_saved_configs();
/**
- * The Configs that have been set
+ * The Configs that have been set. Each config should
*/
unordered_map<ConfigKey, StatsdConfig> mConfigs;
/**
+ * Each config key can be subscribed by up to one receiver, specified as the package name and
+ * class name.
+ */
+ unordered_map<ConfigKey, pair<string, string>> mConfigReceivers;
+
+ /**
* The ConfigListeners that will be told about changes.
*/
vector<sp<ConfigListener>> mListeners;