diff --git a/powerstats/service.cpp b/powerstats/service.cpp index badc40c..f23c6b6 100644 --- a/powerstats/service.cpp +++ b/powerstats/service.cpp @@ -17,6 +17,7 @@ #define LOG_TAG "android.hardware.power.stats-service.pixel" #include +#include #include #include #include @@ -31,6 +32,7 @@ using aidl::android::hardware::power::stats::DevfreqStateResidencyDataProvider; using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider; using aidl::android::hardware::power::stats::EnergyConsumerType; +using aidl::android::hardware::power::stats::GenericStateResidencyDataProvider; using aidl::android::hardware::power::stats::PowerStatsEnergyConsumer; void addDisplay(std::shared_ptr p) { @@ -85,6 +87,39 @@ void addGPUGs202(std::shared_ptr p) { stateCoeffs)); } +void addUwb(std::shared_ptr p) { + // A constant to represent the number of nanoseconds in one millisecond. + const int NS_TO_MS = 1000000; + + // ACPM stats are reported in nanoseconds. The transform function + // converts nanoseconds to milliseconds. + std::function uwbNsToMs = [](uint64_t a) { return a / NS_TO_MS; }; + const GenericStateResidencyDataProvider::StateResidencyConfig stateConfig = { + .entryCountSupported = true, + .entryCountPrefix = "count:", + .totalTimeSupported = true, + .totalTimePrefix = "dur ns:", + .totalTimeTransform = uwbNsToMs, + .lastEntrySupported = false, + }; + + const std::vector> stateHeaders = { + std::make_pair("Off", "Off state:"), + std::make_pair("Deep sleep", "Deep sleep state:"), + std::make_pair("Run", "Run state:"), + std::make_pair("Idle", "Idle state:"), + std::make_pair("Tx", "Tx state:"), + std::make_pair("Rx", "Rx state:"), + }; + + std::vector cfgs; + cfgs.emplace_back(generateGenericStateResidencyConfigs(stateConfig, stateHeaders), + "UWB", ""); + + p->addStateResidencyDataProvider(std::make_unique( + "/sys/devices/platform/10db0000.spi/spi_master/spi16/spi16.0/uwb/power_stats", cfgs)); +} + int main() { LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting."; @@ -102,6 +137,7 @@ int main() { addWifi(p); addTPU(p); addUfs(p); + addUwb(p); addPowerDomains(p); addDevfreq(p); addGPUGs202(p);