1 /*
2 * Copyright (C) 2020 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 #include "PowerStats.h"
18
19 #include "FakeEnergyConsumer.h"
20 #include "FakeEnergyMeter.h"
21 #include "FakeStateResidencyDataProvider.h"
22
23 #include <android-base/logging.h>
24 #include <android/binder_manager.h>
25 #include <android/binder_process.h>
26
27 using aidl::android::hardware::power::stats::EnergyConsumerType;
28 using aidl::android::hardware::power::stats::FakeEnergyConsumer;
29 using aidl::android::hardware::power::stats::FakeEnergyMeter;
30 using aidl::android::hardware::power::stats::FakeStateResidencyDataProvider;
31 using aidl::android::hardware::power::stats::PowerStats;
32 using aidl::android::hardware::power::stats::State;
33
setFakeEnergyMeter(std::shared_ptr<PowerStats> p)34 void setFakeEnergyMeter(std::shared_ptr<PowerStats> p) {
35 p->setEnergyMeter(
36 std::make_unique<FakeEnergyMeter>(std::vector<std::pair<std::string, std::string>>{
37 {"Rail1", "Display"},
38 {"Rail2", "CPU"},
39 {"Rail3", "Modem"},
40 }));
41 }
42
addFakeStateResidencyDataProvider1(std::shared_ptr<PowerStats> p)43 void addFakeStateResidencyDataProvider1(std::shared_ptr<PowerStats> p) {
44 p->addStateResidencyDataProvider(std::make_unique<FakeStateResidencyDataProvider>(
45 "CPU", std::vector<State>{{0, "Idle"}, {1, "Active"}}));
46 }
47
addFakeStateResidencyDataProvider2(std::shared_ptr<PowerStats> p)48 void addFakeStateResidencyDataProvider2(std::shared_ptr<PowerStats> p) {
49 p->addStateResidencyDataProvider(std::make_unique<FakeStateResidencyDataProvider>(
50 "Display", std::vector<State>{{0, "Off"}, {1, "On"}}));
51 }
52
addFakeEnergyConsumer1(std::shared_ptr<PowerStats> p)53 void addFakeEnergyConsumer1(std::shared_ptr<PowerStats> p) {
54 p->addEnergyConsumer(std::make_unique<FakeEnergyConsumer>(EnergyConsumerType::OTHER, "GPU"));
55 }
56
addFakeEnergyConsumer2(std::shared_ptr<PowerStats> p)57 void addFakeEnergyConsumer2(std::shared_ptr<PowerStats> p) {
58 p->addEnergyConsumer(
59 std::make_unique<FakeEnergyConsumer>(EnergyConsumerType::MOBILE_RADIO, "MODEM"));
60 }
61
main()62 int main() {
63 ABinderProcess_setThreadPoolMaxThreadCount(0);
64 std::shared_ptr<PowerStats> p = ndk::SharedRefBase::make<PowerStats>();
65
66 setFakeEnergyMeter(p);
67
68 addFakeStateResidencyDataProvider1(p);
69 addFakeStateResidencyDataProvider2(p);
70
71 addFakeEnergyConsumer1(p);
72 addFakeEnergyConsumer2(p);
73
74 const std::string instance = std::string() + PowerStats::descriptor + "/default";
75 binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str());
76 CHECK_EQ(status, STATUS_OK);
77
78 ABinderProcess_joinThreadPool();
79 return EXIT_FAILURE; // should not reach
80 }
81