blob: 5a8fe1a8b8de346cfd70d183aa6197156f5e2df8 [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
20#include <healthd/healthd.h>
21
22#include <stdlib.h>
23#include <string.h>
24#include <cutils/klog.h>
25
26using namespace android;
27
28// main healthd loop
29extern int healthd_main(void);
30
31// Charger mode
32
33extern void healthd_mode_charger_init(struct healthd_config *config);
34extern int healthd_mode_charger_preparetowait(void);
35extern void healthd_mode_charger_heartbeat(void);
36extern void healthd_mode_charger_battery_update(
37 struct android::BatteryProperties *props);
38
39// NOPs for modes that need no special action
40
41static void healthd_mode_nop_init(struct healthd_config *config);
42static int healthd_mode_nop_preparetowait(void);
43static void healthd_mode_nop_heartbeat(void);
44static void healthd_mode_nop_battery_update(
45 struct android::BatteryProperties *props);
46
47static struct healthd_mode_ops healthd_nops = {
48 .init = healthd_mode_nop_init,
49 .preparetowait = healthd_mode_nop_preparetowait,
50 .heartbeat = healthd_mode_nop_heartbeat,
51 .battery_update = healthd_mode_nop_battery_update,
52};
53
54#ifdef CHARGER_NO_UI
55static struct healthd_mode_ops charger_ops = healthd_nops;
56#else
57static struct healthd_mode_ops charger_ops = {
58 .init = healthd_mode_charger_init,
59 .preparetowait = healthd_mode_charger_preparetowait,
60 .heartbeat = healthd_mode_charger_heartbeat,
61 .battery_update = healthd_mode_charger_battery_update,
62};
63#endif
64
65static void healthd_mode_nop_init(struct healthd_config* /*config*/) {
66}
67
68static int healthd_mode_nop_preparetowait(void) {
69 return -1;
70}
71
72static void healthd_mode_nop_heartbeat(void) {
73}
74
75static void healthd_mode_nop_battery_update(
76 struct android::BatteryProperties* /*props*/) {
77}
78
79int main(int argc, char **argv) {
80 int ch;
81
82 healthd_mode_ops = &charger_ops;
83
84 while ((ch = getopt(argc, argv, "cr")) != -1) {
85 switch (ch) {
86 case 'c':
87 // -c is now a noop
88 break;
89 case 'r':
90 // force nops for recovery
91 healthd_mode_ops = &healthd_nops;
92 break;
93 case '?':
94 default:
95 KLOG_ERROR(LOG_TAG, "Unrecognized charger option: %c\n",
96 optopt);
97 exit(1);
98 }
99 }
100
101 return healthd_main();
102}