powerstats: Add device specific display states
Bug: 167216667
Test: dumpsys android.hardware.power.stats.IPowerStats/default
Change-Id: I90ea3553ababbc802fdc6f893f698b85655b1ad9
diff --git a/powerstats/raven/service.cpp b/powerstats/raven/service.cpp
index d7c7599..8ccc616 100644
--- a/powerstats/raven/service.cpp
+++ b/powerstats/raven/service.cpp
@@ -16,8 +16,10 @@
#define LOG_TAG "android.hardware.power.stats-service.pixel"
-#include <PowerStatsAidl.h>
+#include <dataproviders/DisplayStateResidencyDataProvider.h>
+#include <dataproviders/PowerStatsEnergyConsumer.h>
#include <Gs101CommonDataProviders.h>
+#include <PowerStatsAidl.h>
#include <android-base/logging.h>
#include <android-base/properties.h>
@@ -25,6 +27,45 @@
#include <android/binder_process.h>
#include <log/log.h>
+using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider;
+using aidl::android::hardware::power::stats::EnergyConsumerType;
+using aidl::android::hardware::power::stats::PowerStatsEnergyConsumer;
+
+void addDisplay(std::shared_ptr<PowerStats> p) {
+ // Add display residency stats
+ std::vector<std::string> states = {
+ "Off",
+ "LP: 1440x3120@10",
+ "LP: 1440x3120@30",
+ "On: 1440x3120@10",
+ "On: 1440x3120@30",
+ "On: 1440x3120@60",
+ "On: 1440x3120@90",
+ "On: 1440x3120@120",
+ "HBM: 1440x3120@60",
+ };
+
+ p->addStateResidencyDataProvider(std::make_unique<DisplayStateResidencyDataProvider>("Display",
+ "/sys/class/backlight/panel0-backlight/state",
+ states));
+
+ // Add display energy consumer
+ /*
+ * TODO(b/167216667): Add correct display power model here. Must read from display rail
+ * and include proper coefficients for display states.
+ */
+ p->addEnergyConsumer(PowerStatsEnergyConsumer::createMeterAndEntityConsumer(p,
+ EnergyConsumerType::DISPLAY, "display", {"PPVAR_VSYS_PWR_DISP"}, "Display",
+ {{"LP: 1440x3120@10", 1},
+ {"LP: 1440x3120@30", 2},
+ {"On: 1440x3120@10", 3},
+ {"On: 1440x3120@30", 4},
+ {"On: 1440x3120@60", 5},
+ {"On: 1440x3120@90", 6},
+ {"On: 1440x3120@120", 7},
+ {"HBM: 1440x3120@60", 8}}));
+}
+
int main() {
LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting.";
@@ -34,6 +75,7 @@
std::shared_ptr<PowerStats> p = ndk::SharedRefBase::make<PowerStats>();
addGs101CommonDataProviders(p);
+ addDisplay(p);
const std::string instance = std::string() + PowerStats::descriptor + "/default";
binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str());