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 #include <android-base/logging.h>
18 #include <android/binder_interface_utils.h>
19 #include <health-impl/Health.h>
20 #include <health/utils.h>
21 
22 #ifndef CHARGER_FORCE_NO_UI
23 #define CHARGER_FORCE_NO_UI 0
24 #endif
25 
26 #if !CHARGER_FORCE_NO_UI
27 #include <health-impl/ChargerUtils.h>
28 #endif
29 
30 using aidl::android::hardware::health::HalHealthLoop;
31 using aidl::android::hardware::health::Health;
32 
33 #if !CHARGER_FORCE_NO_UI
34 using aidl::android::hardware::health::charger::ChargerCallback;
35 using aidl::android::hardware::health::charger::ChargerModeMain;
36 #endif
37 
38 static constexpr const char* gInstanceName = "default";
39 static constexpr std::string_view gChargerArg{"--charger"};
40 
main(int argc,char ** argv)41 int main(int argc, char** argv) {
42 #ifdef __ANDROID_RECOVERY__
43     android::base::InitLogging(argv, android::base::KernelLogger);
44 #endif
45 
46     // make a default health service
47     auto config = std::make_unique<healthd_config>();
48     ::android::hardware::health::InitHealthdConfig(config.get());
49     auto binder = ndk::SharedRefBase::make<Health>(gInstanceName, std::move(config));
50 
51     if (argc >= 2 && argv[1] == gChargerArg) {
52 #if !CHARGER_FORCE_NO_UI
53         // If charger shouldn't have UI for your device, simply drop the line below
54         // for your service implementation. This corresponds to
55         // ro.charger.no_ui=true
56         return ChargerModeMain(binder, std::make_shared<ChargerCallback>(binder));
57 #endif
58 
59         LOG(INFO) << "Starting charger mode without UI.";
60     } else {
61         LOG(INFO) << "Starting health HAL.";
62     }
63 
64     auto hal_health_loop = std::make_shared<HalHealthLoop>(binder, binder);
65     return hal_health_loop->StartLoop();
66 }
67