blob: 03b2ecb791c0e892a0e6979ab84f5ea39ec858d5 [file] [log] [blame]
Yifan Hong830cdb12021-01-11 20:47:23 -08001/*
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
Yifan Honga8f55ca2021-10-20 23:05:45 -070022#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
Yifan Hong830cdb12021-01-11 20:47:23 -080030using aidl::android::hardware::health::HalHealthLoop;
31using aidl::android::hardware::health::Health;
32
Yifan Honga8f55ca2021-10-20 23:05:45 -070033#if !CHARGER_FORCE_NO_UI
34using aidl::android::hardware::health::charger::ChargerCallback;
35using aidl::android::hardware::health::charger::ChargerModeMain;
36#endif
Yifan Hong830cdb12021-01-11 20:47:23 -080037
Yifan Honga8f55ca2021-10-20 23:05:45 -070038static constexpr const char* gInstanceName = "default";
39static constexpr std::string_view gChargerArg{"--charger"};
40
41int main(int argc, char** argv) {
Yifan Hong87ece162021-11-15 18:50:44 -080042#ifdef __ANDROID_RECOVERY__
43 android::base::InitLogging(argv, android::base::KernelLogger);
44#endif
45
Yifan Hong830cdb12021-01-11 20:47:23 -080046 // 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));
Yifan Honga8f55ca2021-10-20 23:05:45 -070050
51 if (argc >= 2 && argv[1] == gChargerArg) {
Yifan Honga8f55ca2021-10-20 23:05:45 -070052#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
Yifan Hong830cdb12021-01-11 20:47:23 -080064 auto hal_health_loop = std::make_shared<HalHealthLoop>(binder, binder);
65 return hal_health_loop->StartLoop();
66}