powerstats: Add device specific display states

Bug: 167216667
Test: dumpsys android.hardware.power.stats.IPowerStats/default
Change-Id: I90ea3553ababbc802fdc6f893f698b85655b1ad9
This commit is contained in:
Benjamin Schwartz 2021-04-05 22:26:29 -07:00 committed by TreeHugger Robot
parent 56926638e1
commit e04673cadf
4 changed files with 146 additions and 4 deletions

View file

@ -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 @@ int main() {
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());