1526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil/* 2526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil * Copyright (C) 2016 The Android Open Source Project 3526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil * 4526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil * Licensed under the Apache License, Version 2.0 (the "License"); 5526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil * you may not use this file except in compliance with the License. 6526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil * You may obtain a copy of the License at 7526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil * 8526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil * http://www.apache.org/licenses/LICENSE-2.0 9526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil * 10526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil * Unless required by applicable law or agreed to in writing, software 11526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil * distributed under the License is distributed on an "AS IS" BASIS, 12526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil * See the License for the specific language governing permissions and 14526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil * limitations under the License. 15526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil */ 16526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 17526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil#define LOG_TAG "charger" 18526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil#define KLOG_LEVEL 6 19526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 20526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil#include <healthd/healthd.h> 21526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 22526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil#include <stdlib.h> 23526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil#include <string.h> 24526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil#include <cutils/klog.h> 25526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 26526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilusing namespace android; 27526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 28526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil// main healthd loop 29526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilextern int healthd_main(void); 30526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 31526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil// Charger mode 32526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 33526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilextern void healthd_mode_charger_init(struct healthd_config *config); 34526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilextern int healthd_mode_charger_preparetowait(void); 35526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilextern void healthd_mode_charger_heartbeat(void); 36526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilextern void healthd_mode_charger_battery_update( 37526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil struct android::BatteryProperties *props); 38526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 39526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil// NOPs for modes that need no special action 40526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 41526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilstatic void healthd_mode_nop_init(struct healthd_config *config); 42526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilstatic int healthd_mode_nop_preparetowait(void); 43526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilstatic void healthd_mode_nop_heartbeat(void); 44526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilstatic void healthd_mode_nop_battery_update( 45526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil struct android::BatteryProperties *props); 46526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 47526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilstatic struct healthd_mode_ops healthd_nops = { 48526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil .init = healthd_mode_nop_init, 49526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil .preparetowait = healthd_mode_nop_preparetowait, 50526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil .heartbeat = healthd_mode_nop_heartbeat, 51526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil .battery_update = healthd_mode_nop_battery_update, 52526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil}; 53526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 54526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil#ifdef CHARGER_NO_UI 55526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilstatic struct healthd_mode_ops charger_ops = healthd_nops; 56526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil#else 57526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilstatic struct healthd_mode_ops charger_ops = { 58526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil .init = healthd_mode_charger_init, 59526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil .preparetowait = healthd_mode_charger_preparetowait, 60526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil .heartbeat = healthd_mode_charger_heartbeat, 61526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil .battery_update = healthd_mode_charger_battery_update, 62526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil}; 63526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil#endif 64526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 65526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilstatic void healthd_mode_nop_init(struct healthd_config* /*config*/) { 66526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil} 67526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 68526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilstatic int healthd_mode_nop_preparetowait(void) { 69526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil return -1; 70526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil} 71526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 72526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilstatic void healthd_mode_nop_heartbeat(void) { 73526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil} 74526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 75526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilstatic void healthd_mode_nop_battery_update( 76526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil struct android::BatteryProperties* /*props*/) { 77526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil} 78526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 79526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patilint main(int argc, char **argv) { 80526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil int ch; 81526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 82526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil healthd_mode_ops = &charger_ops; 83526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 84526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil while ((ch = getopt(argc, argv, "cr")) != -1) { 85526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil switch (ch) { 86526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil case 'c': 87526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil // -c is now a noop 88526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil break; 89526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil case 'r': 90526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil // force nops for recovery 91526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil healthd_mode_ops = &healthd_nops; 92526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil break; 93526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil case '?': 94526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil default: 95526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil KLOG_ERROR(LOG_TAG, "Unrecognized charger option: %c\n", 96526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil optopt); 97526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil exit(1); 98526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil } 99526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil } 100526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil 101526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil return healthd_main(); 102526f8cf339f6c215d2d89924824b674cb99cfcc9Sandeep Patil} 103