blob: 43e7fd5b82a0feeeebbf66d7fba7729955bfaa66 [file] [log] [blame]
Sandeep Patil526f8cf2016-11-01 16:41:56 -07001/*
2 * Copyright (C) 2016 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 "charger"
18#define KLOG_LEVEL 6
19
Yifan Hong10c2b402017-11-08 10:57:52 -080020#include <health2/Health.h>
Sandeep Patil526f8cf2016-11-01 16:41:56 -070021#include <healthd/healthd.h>
22
23#include <stdlib.h>
24#include <string.h>
25#include <cutils/klog.h>
26
27using namespace android;
28
29// main healthd loop
30extern int healthd_main(void);
31
32// Charger mode
33
34extern void healthd_mode_charger_init(struct healthd_config *config);
35extern int healthd_mode_charger_preparetowait(void);
36extern void healthd_mode_charger_heartbeat(void);
37extern void healthd_mode_charger_battery_update(
38 struct android::BatteryProperties *props);
39
40// NOPs for modes that need no special action
41
42static void healthd_mode_nop_init(struct healthd_config *config);
43static int healthd_mode_nop_preparetowait(void);
44static void healthd_mode_nop_heartbeat(void);
45static void healthd_mode_nop_battery_update(
46 struct android::BatteryProperties *props);
47
48static struct healthd_mode_ops healthd_nops = {
49 .init = healthd_mode_nop_init,
50 .preparetowait = healthd_mode_nop_preparetowait,
51 .heartbeat = healthd_mode_nop_heartbeat,
52 .battery_update = healthd_mode_nop_battery_update,
53};
54
55#ifdef CHARGER_NO_UI
56static struct healthd_mode_ops charger_ops = healthd_nops;
57#else
58static struct healthd_mode_ops charger_ops = {
59 .init = healthd_mode_charger_init,
60 .preparetowait = healthd_mode_charger_preparetowait,
61 .heartbeat = healthd_mode_charger_heartbeat,
62 .battery_update = healthd_mode_charger_battery_update,
63};
64#endif
65
Yifan Hong10c2b402017-11-08 10:57:52 -080066static void healthd_mode_nop_init(struct healthd_config* config) {
67 using android::hardware::health::V2_0::implementation::Health;
68 Health::initInstance(config);
Sandeep Patil526f8cf2016-11-01 16:41:56 -070069}
70
71static int healthd_mode_nop_preparetowait(void) {
72 return -1;
73}
74
75static void healthd_mode_nop_heartbeat(void) {
76}
77
78static void healthd_mode_nop_battery_update(
79 struct android::BatteryProperties* /*props*/) {
80}
81
Yifan Hongb7cd45f2017-11-13 18:47:03 -080082int healthd_charger_main(int argc, char** argv) {
Sandeep Patil526f8cf2016-11-01 16:41:56 -070083 int ch;
84
85 healthd_mode_ops = &charger_ops;
86
87 while ((ch = getopt(argc, argv, "cr")) != -1) {
88 switch (ch) {
89 case 'c':
90 // -c is now a noop
91 break;
92 case 'r':
93 // force nops for recovery
94 healthd_mode_ops = &healthd_nops;
95 break;
96 case '?':
97 default:
98 KLOG_ERROR(LOG_TAG, "Unrecognized charger option: %c\n",
99 optopt);
100 exit(1);
101 }
102 }
103
104 return healthd_main();
105}
Yifan Hongb7cd45f2017-11-13 18:47:03 -0800106
107#ifndef CHARGER_TEST
108int main(int argc, char** argv) {
109 return healthd_charger_main(argc, argv);
110}
111#endif