blob: 1d7966df5447da89a15056c21a475d1251c61eeb [file] [log] [blame]
Benjamin Schwartzc798cb32021-03-18 17:55:40 -07001/*
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
Benjamin Schwartze04673c2021-04-05 22:26:29 -070019#include <dataproviders/DisplayStateResidencyDataProvider.h>
20#include <dataproviders/PowerStatsEnergyConsumer.h>
Benjamin Schwartzc798cb32021-03-18 17:55:40 -070021#include <Gs101CommonDataProviders.h>
Benjamin Schwartze04673c2021-04-05 22:26:29 -070022#include <PowerStatsAidl.h>
Benjamin Schwartzc798cb32021-03-18 17:55:40 -070023
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>
chungkaie593aaa2022-04-06 10:11:12 +000029#include <sys/stat.h>
Benjamin Schwartzc798cb32021-03-18 17:55:40 -070030
Benjamin Schwartze04673c2021-04-05 22:26:29 -070031using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider;
32using aidl::android::hardware::power::stats::EnergyConsumerType;
33using aidl::android::hardware::power::stats::PowerStatsEnergyConsumer;
34
35void addDisplay(std::shared_ptr<PowerStats> p) {
36 // Add display residency stats
37 std::vector<std::string> states = {
38 "Off",
39 "LP: 1440x3040@30",
40 "On: 1440x3040@60",
41 "On: 1440x3040@90",
42 "HBM: 1440x3040@60",
43 "HBM: 1440x3040@90"};
44
45 p->addStateResidencyDataProvider(std::make_unique<DisplayStateResidencyDataProvider>("Display",
46 "/sys/class/backlight/panel0-backlight/state",
47 states));
48
49 // Add display energy consumer
50 /*
51 * TODO(b/167216667): Add correct display power model here. Must read from display rail
52 * and include proper coefficients for display states.
53 */
54 p->addEnergyConsumer(PowerStatsEnergyConsumer::createMeterAndEntityConsumer(p,
55 EnergyConsumerType::DISPLAY, "display", {"PPVAR_VSYS_PWR_DISP"}, "Display",
56 {{"LP: 1440x3040@30", 1},
57 {"On: 1440x3040@60", 2},
58 {"On: 1440x3040@90", 3}}));
59}
60
Benjamin Schwartzc798cb32021-03-18 17:55:40 -070061int main() {
chungkaie593aaa2022-04-06 10:11:12 +000062 struct stat buffer;
63
Benjamin Schwartzc798cb32021-03-18 17:55:40 -070064 LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting.";
65
66 // single thread
67 ABinderProcess_setThreadPoolMaxThreadCount(0);
68
69 std::shared_ptr<PowerStats> p = ndk::SharedRefBase::make<PowerStats>();
70
71 addGs101CommonDataProviders(p);
Benjamin Schwartze04673c2021-04-05 22:26:29 -070072 addDisplay(p);
Jacky Liu78c26012024-02-02 12:59:20 +080073 if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-7/7-0008/power_stats", &buffer)) {
74 addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-7/7-0008/power_stats");
chungkaie593aaa2022-04-06 10:11:12 +000075 }
Benjamin Schwartzc798cb32021-03-18 17:55:40 -070076 const std::string instance = std::string() + PowerStats::descriptor + "/default";
77 binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str());
78 LOG_ALWAYS_FATAL_IF(status != STATUS_OK);
79
80 ABinderProcess_joinThreadPool();
81 return EXIT_FAILURE; // should not reach
82}