powerstats: Add device specific display states

Bug: 167216667
Test: dumpsys android.hardware.power.stats.IPowerStats/default
Change-Id: I90ea3553ababbc802fdc6f893f698b85655b1ad9
diff --git a/powerstats/oriole/service.cpp b/powerstats/oriole/service.cpp
index d7c7599..6da7102 100644
--- a/powerstats/oriole/service.cpp
+++ b/powerstats/oriole/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,37 @@
 #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: 1080x2400@30",
+        "On: 1080x2400@60",
+        "On: 1080x2400@90",
+        "HBM: 1080x2400@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: 1080x2400@30", 1},
+             {"On: 1080x2400@60", 2},
+             {"On: 1080x2400@90", 3},
+             {"HBM: 1080x2400@60", 4}}));
+}
+
 int main() {
     LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting.";
 
@@ -34,6 +67,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());
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());
diff --git a/powerstats/slider/service.cpp b/powerstats/slider/service.cpp
index d7c7599..5fe5332 100644
--- a/powerstats/slider/service.cpp
+++ b/powerstats/slider/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,36 @@
 #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: 1440x3040@30",
+        "On: 1440x3040@60",
+        "On: 1440x3040@90",
+        "HBM: 1440x3040@60",
+        "HBM: 1440x3040@90"};
+
+    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: 1440x3040@30", 1},
+             {"On: 1440x3040@60", 2},
+             {"On: 1440x3040@90", 3}}));
+}
+
 int main() {
     LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting.";
 
@@ -34,6 +66,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());
diff --git a/powerstats/whitefin/service.cpp b/powerstats/whitefin/service.cpp
index d7c7599..2a102fa 100644
--- a/powerstats/whitefin/service.cpp
+++ b/powerstats/whitefin/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,36 @@
 #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: 1080x2340@30",
+        "On: 1080x2340@60",
+        "On: 1080x2340@90",
+        "HBM: 1080x2340@60",
+        "HBM: 1080x2340@90"};
+
+    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: 1440x3040@30", 1},
+             {"On: 1440x3040@60", 2},
+             {"On: 1440x3040@90", 3}}));
+}
+
 int main() {
     LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting.";
 
@@ -34,6 +66,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());