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
17 #define LOG_TAG "android.hardware.power.stats-service.pixel"
18
19 #include <dataproviders/DisplayStateResidencyDataProvider.h>
20 #include <dataproviders/PowerStatsEnergyConsumer.h>
21 #include <Gs201CommonDataProviders.h>
22 #include <PowerStatsAidl.h>
23
24 #include <android-base/logging.h>
25 #include <android-base/properties.h>
26 #include <android/binder_manager.h>
27 #include <android/binder_process.h>
28 #include <log/log.h>
29
30 using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider;
31 using aidl::android::hardware::power::stats::EnergyConsumerType;
32 using aidl::android::hardware::power::stats::PowerStatsEnergyConsumer;
33
addDisplay(std::shared_ptr<PowerStats> p)34 void addDisplay(std::shared_ptr<PowerStats> p) {
35 // Add display residency stats
36 std::vector<std::string> states = {
37 "Off",
38 "LP: 1080x2340@30",
39 "On: 1080x2340@60",
40 "On: 1080x2340@90",
41 "HBM: 1080x2340@60",
42 "HBM: 1080x2340@90"};
43
44 p->addStateResidencyDataProvider(std::make_unique<DisplayStateResidencyDataProvider>(
45 "Display",
46 "/sys/class/backlight/panel0-backlight/state",
47 states));
48
49 // Add display energy consumer
50 p->addEnergyConsumer(PowerStatsEnergyConsumer::createMeterAndEntityConsumer(
51 p, EnergyConsumerType::DISPLAY, "display", {"PPVAR_VSYS_PWR_DISP"}, "Display",
52 {{"LP: 1080x2340@30", 1},
53 {"On: 1080x2340@60", 2},
54 {"On: 1080x2340@90", 3},
55 {"HBM: 1080x2340@60", 4},
56 {"HBM: 1080x2340@90", 5}}));
57 }
58
main()59 int main() {
60 LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting.";
61
62 // single thread
63 ABinderProcess_setThreadPoolMaxThreadCount(0);
64
65 std::shared_ptr<PowerStats> p = ndk::SharedRefBase::make<PowerStats>();
66
67 addGs201CommonDataProviders(p);
68 addDisplay(p);
69
70 const std::string instance = std::string() + PowerStats::descriptor + "/default";
71 binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str());
72 LOG_ALWAYS_FATAL_IF(status != STATUS_OK);
73
74 ABinderProcess_joinThreadPool();
75 return EXIT_FAILURE; // should not reach
76 }
77