blob: 76c6ba0a8f3b69b537c92f07512363b80163d198 [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 Hong830cdb12021-01-11 20:47:23 -080042 // make a default health service
43 auto config = std::make_unique<healthd_config>();
44 ::android::hardware::health::InitHealthdConfig(config.get());
45 auto binder = ndk::SharedRefBase::make<Health>(gInstanceName, std::move(config));
Yifan Honga8f55ca2021-10-20 23:05:45 -070046
47 if (argc >= 2 && argv[1] == gChargerArg) {
48 android::base::InitLogging(argv, &android::base::KernelLogger);
49
50#if !CHARGER_FORCE_NO_UI
51 // If charger shouldn't have UI for your device, simply drop the line below
52 // for your service implementation. This corresponds to
53 // ro.charger.no_ui=true
54 return ChargerModeMain(binder, std::make_shared<ChargerCallback>(binder));
55#endif
56
57 LOG(INFO) << "Starting charger mode without UI.";
58 } else {
59 LOG(INFO) << "Starting health HAL.";
60 }
61
Yifan Hong830cdb12021-01-11 20:47:23 -080062 auto hal_health_loop = std::make_shared<HalHealthLoop>(binder, binder);
63 return hal_health_loop->StartLoop();
64}