Creating PendingIntentRef
Update #setDataFetchOperation to avoid using intentsender.
Bug: 146074295
Test: Ran GTS Tests
Change-Id: I7df5c6441725aa4e46fac18925664c9455f50fb9
diff --git a/cmds/statsd/src/config/ConfigManager.cpp b/cmds/statsd/src/config/ConfigManager.cpp
index fc949b4..7bfb991 100644
--- a/cmds/statsd/src/config/ConfigManager.cpp
+++ b/cmds/statsd/src/config/ConfigManager.cpp
@@ -46,6 +46,23 @@
using android::base::StringPrintf;
using std::unique_ptr;
+class ConfigReceiverDeathRecipient : public android::IBinder::DeathRecipient {
+ public:
+ ConfigReceiverDeathRecipient(sp<ConfigManager> configManager, const ConfigKey& configKey):
+ mConfigManager(configManager),
+ mConfigKey(configKey) {}
+ ~ConfigReceiverDeathRecipient() override = default;
+ private:
+ sp<ConfigManager> mConfigManager;
+ ConfigKey mConfigKey;
+
+ void binderDied(const android::wp<android::IBinder>& who) override {
+ if (IInterface::asBinder(mConfigManager->GetConfigReceiver(mConfigKey)) == who.promote()) {
+ mConfigManager->RemoveConfigReceiver(mConfigKey);
+ }
+ }
+};
+
ConfigManager::ConfigManager() {
}
@@ -118,9 +135,11 @@
}
}
-void ConfigManager::SetConfigReceiver(const ConfigKey& key, const sp<IBinder>& intentSender) {
+void ConfigManager::SetConfigReceiver(const ConfigKey& key,
+ const sp<IPendingIntentRef>& pir) {
lock_guard<mutex> lock(mMutex);
- mConfigReceivers[key] = intentSender;
+ mConfigReceivers[key] = pir;
+ IInterface::asBinder(pir)->linkToDeath(new ConfigReceiverDeathRecipient(this, key));
}
void ConfigManager::RemoveConfigReceiver(const ConfigKey& key) {
@@ -266,7 +285,7 @@
return ret;
}
-const sp<android::IBinder> ConfigManager::GetConfigReceiver(const ConfigKey& key) const {
+const sp<IPendingIntentRef> ConfigManager::GetConfigReceiver(const ConfigKey& key) const {
lock_guard<mutex> lock(mMutex);
auto it = mConfigReceivers.find(key);