service.cpp 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) 2021 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #define LOG_TAG "android.hardware.power.stats-service.pixel"
  17. #include <dataproviders/DisplayStateResidencyDataProvider.h>
  18. #include <dataproviders/PowerStatsEnergyConsumer.h>
  19. #include <Gs201CommonDataProviders.h>
  20. #include <PowerStatsAidl.h>
  21. #include <android-base/logging.h>
  22. #include <android-base/properties.h>
  23. #include <android/binder_manager.h>
  24. #include <android/binder_process.h>
  25. #include <log/log.h>
  26. #include <sys/stat.h>
  27. using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider;
  28. using aidl::android::hardware::power::stats::EnergyConsumerType;
  29. using aidl::android::hardware::power::stats::PowerStatsEnergyConsumer;
  30. void addDisplay(std::shared_ptr<PowerStats> p) {
  31. // Add display residency stats
  32. std::vector<std::string> states = {
  33. "Off",
  34. "LP: 1080x2400@30",
  35. "On: 1080x2400@60",
  36. "On: 1080x2400@90",
  37. "HBM: 1080x2400@60",
  38. "HBM: 1080x2400@90"};
  39. p->addStateResidencyDataProvider(std::make_unique<DisplayStateResidencyDataProvider>("Display",
  40. "/sys/class/backlight/panel0-backlight/state",
  41. states));
  42. // Add display energy consumer
  43. p->addEnergyConsumer(PowerStatsEnergyConsumer::createMeterAndEntityConsumer(p,
  44. EnergyConsumerType::DISPLAY, "display", {"VSYS_PWR_DISPLAY"}, "Display",
  45. {{"LP: 1080x2400@30", 1},
  46. {"On: 1080x2400@60", 2},
  47. {"On: 1080x2400@90", 3}}));
  48. }
  49. int main() {
  50. struct stat buffer;
  51. LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting.";
  52. // single thread
  53. ABinderProcess_setThreadPoolMaxThreadCount(0);
  54. std::shared_ptr<PowerStats> p = ndk::SharedRefBase::make<PowerStats>();
  55. addGs201CommonDataProvidersQc(p);
  56. addDisplay(p);
  57. if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-2/i2c-st21nfc/power_stats", &buffer)) {
  58. addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-2/i2c-st21nfc/power_stats");
  59. } else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-3/i2c-st21nfc/power_stats", &buffer)) {
  60. addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-3/i2c-st21nfc/power_stats");
  61. } else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-4/i2c-st21nfc/power_stats", &buffer)) {
  62. addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-4/i2c-st21nfc/power_stats");
  63. } else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-5/i2c-st21nfc/power_stats", &buffer)) {
  64. addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-5/i2c-st21nfc/power_stats");
  65. } else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-6/i2c-st21nfc/power_stats", &buffer)) {
  66. addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-6/i2c-st21nfc/power_stats");
  67. } else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-7/i2c-st21nfc/power_stats", &buffer)) {
  68. addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-7/i2c-st21nfc/power_stats");
  69. } else {
  70. addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-8/i2c-st21nfc/power_stats");
  71. }
  72. const std::string instance = std::string() + PowerStats::descriptor + "/default";
  73. binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str());
  74. LOG_ALWAYS_FATAL_IF(status != STATUS_OK);
  75. ABinderProcess_joinThreadPool();
  76. return EXIT_FAILURE; // should not reach
  77. }