service.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider;
  27. using aidl::android::hardware::power::stats::EnergyConsumerType;
  28. using aidl::android::hardware::power::stats::PowerStatsEnergyConsumer;
  29. void addDisplay(std::shared_ptr<PowerStats> p) {
  30. // Add display residency stats
  31. std::vector<std::string> states = {
  32. "Off",
  33. "LP: 1080x2400@30",
  34. "On: 1080x2400@60",
  35. "On: 1080x2400@90",
  36. "HBM: 1080x2400@60",
  37. "HBM: 1080x2400@90"};
  38. p->addStateResidencyDataProvider(std::make_unique<DisplayStateResidencyDataProvider>("Display",
  39. "/sys/class/backlight/panel0-backlight/state",
  40. states));
  41. // Add display energy consumer
  42. p->addEnergyConsumer(PowerStatsEnergyConsumer::createMeterAndEntityConsumer(p,
  43. EnergyConsumerType::DISPLAY, "display", {"VSYS_PWR_DISPLAY"}, "Display",
  44. {{"LP: 1080x2400@30", 1},
  45. {"On: 1080x2400@60", 2},
  46. {"On: 1080x2400@90", 3}}));
  47. }
  48. int main() {
  49. LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting.";
  50. // single thread
  51. ABinderProcess_setThreadPoolMaxThreadCount(0);
  52. std::shared_ptr<PowerStats> p = ndk::SharedRefBase::make<PowerStats>();
  53. addGs201CommonDataProviders(p);
  54. addDisplay(p);
  55. addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-4/i2c-st21nfc/power_stats");
  56. const std::string instance = std::string() + PowerStats::descriptor + "/default";
  57. binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str());
  58. LOG_ALWAYS_FATAL_IF(status != STATUS_OK);
  59. ABinderProcess_joinThreadPool();
  60. return EXIT_FAILURE; // should not reach
  61. }