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 <ZumaCommonDataProviders.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: 1008x2244@1",
39 "LP: 1008x2244@30",
40 "On: 1008x2244@1",
41 "On: 1008x2244@10",
42 "On: 1008x2244@30",
43 "On: 1008x2244@60",
44 "On: 1008x2244@120",
45 "HBM: 1008x2244@1",
46 "HBM: 1008x2244@10",
47 "HBM: 1008x2244@30",
48 "HBM: 1008x2244@60",
49 "HBM: 1008x2244@120",
50 "LP: 1344x2992@1",
51 "LP: 1344x2992@30",
52 "On: 1344x2992@1",
53 "On: 1344x2992@10",
54 "On: 1344x2992@30",
55 "On: 1344x2992@60",
56 "On: 1344x2992@120",
57 "HBM: 1344x2992@1",
58 "HBM: 1344x2992@10",
59 "HBM: 1344x2992@30",
60 "HBM: 1344x2992@60",
61 "HBM: 1344x2992@120"};
62
63 p->addStateResidencyDataProvider(std::make_unique<DisplayStateResidencyDataProvider>(
64 "Display",
65 "/sys/class/backlight/panel0-backlight/state",
66 states));
67
68 // Add display energy consumer
69 p->addEnergyConsumer(PowerStatsEnergyConsumer::createMeterConsumer(
70 p,
71 EnergyConsumerType::DISPLAY,
72 "DISPLAY",
73 {"VSYS_PWR_DISPLAY"}));
74 }
75
main()76 int main() {
77 LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting.";
78
79 // single thread
80 ABinderProcess_setThreadPoolMaxThreadCount(0);
81
82 std::shared_ptr<PowerStats> p = ndk::SharedRefBase::make<PowerStats>();
83
84 addZumaCommonDataProviders(p);
85 addDisplay(p);
86
87 const std::string instance = std::string() + PowerStats::descriptor + "/default";
88 binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str());
89 LOG_ALWAYS_FATAL_IF(status != STATUS_OK);
90
91 ABinderProcess_joinThreadPool();
92 return EXIT_FAILURE; // should not reach
93 }
94