power/stats: Index the state residency data providers am: 3bad122962
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1663119
Change-Id: Ie15a72e82306e08208f5c3ffc9d49599a8bb8884
diff --git a/power/stats/aidl/default/PowerStats.cpp b/power/stats/aidl/default/PowerStats.cpp
index 7cf591e..4b771a8 100644
--- a/power/stats/aidl/default/PowerStats.cpp
+++ b/power/stats/aidl/default/PowerStats.cpp
@@ -32,15 +32,19 @@
}
int32_t id = mPowerEntityInfos.size();
+ auto info = p->getInfo();
- for (const auto& [entityName, states] : p->getInfo()) {
+ size_t index = mStateResidencyDataProviders.size();
+ mStateResidencyDataProviders.emplace_back(std::move(p));
+
+ for (const auto& [entityName, states] : info) {
PowerEntity i = {
.id = id++,
.name = entityName,
.states = states,
};
mPowerEntityInfos.emplace_back(i);
- mStateResidencyDataProviders.emplace_back(std::move(p));
+ mStateResidencyDataProviderIndex.emplace_back(index);
}
}
@@ -92,7 +96,8 @@
// Check to see if we already have data for the given id
std::string powerEntityName = mPowerEntityInfos[id].name;
if (stateResidencies.find(powerEntityName) == stateResidencies.end()) {
- mStateResidencyDataProviders[id]->getStateResidencies(&stateResidencies);
+ mStateResidencyDataProviders.at(mStateResidencyDataProviderIndex.at(id))
+ ->getStateResidencies(&stateResidencies);
}
// Append results if we have them
diff --git a/power/stats/aidl/default/PowerStats.h b/power/stats/aidl/default/PowerStats.h
index f4c5e69..91d272d 100644
--- a/power/stats/aidl/default/PowerStats.h
+++ b/power/stats/aidl/default/PowerStats.h
@@ -73,6 +73,8 @@
private:
std::vector<std::unique_ptr<IStateResidencyDataProvider>> mStateResidencyDataProviders;
std::vector<PowerEntity> mPowerEntityInfos;
+ /* Index that maps each power entity id to an entry in mStateResidencyDataProviders */
+ std::vector<size_t> mStateResidencyDataProviderIndex;
std::vector<std::unique_ptr<IEnergyConsumer>> mEnergyConsumers;
std::vector<EnergyConsumer> mEnergyConsumerInfos;