2011-08-30 17:46:09 +00:00
|
|
|
/*
|
2017-07-13 22:10:35 +00:00
|
|
|
* Copyright (C) 2011-2017 The Android Open Source Project
|
2011-08-30 17:46:09 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2014-05-16 00:49:06 +00:00
|
|
|
#include <inttypes.h>
|
2011-08-30 17:46:09 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2013-09-09 19:09:08 +00:00
|
|
|
#include <sys/epoll.h>
|
2011-08-30 17:46:09 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2017-01-19 06:54:54 +00:00
|
|
|
#include <functional>
|
|
|
|
|
2016-08-11 22:29:50 +00:00
|
|
|
#include <android-base/file.h>
|
2017-06-27 16:19:09 +00:00
|
|
|
#include <android-base/macros.h>
|
2016-08-11 22:29:50 +00:00
|
|
|
|
2012-09-12 01:52:40 +00:00
|
|
|
#include <linux/netlink.h>
|
2017-07-13 22:10:35 +00:00
|
|
|
#include <sys/socket.h>
|
2012-09-12 01:52:40 +00:00
|
|
|
|
2011-08-30 17:46:09 +00:00
|
|
|
#include <cutils/klog.h>
|
2011-09-30 00:20:07 +00:00
|
|
|
#include <cutils/misc.h>
|
2014-06-16 22:06:21 +00:00
|
|
|
#include <cutils/properties.h>
|
2017-07-13 22:10:35 +00:00
|
|
|
#include <cutils/uevent.h>
|
2017-01-31 23:51:50 +00:00
|
|
|
#include <sys/reboot.h>
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2012-12-07 01:06:36 +00:00
|
|
|
#ifdef CHARGER_ENABLE_SUSPEND
|
2012-11-16 01:03:03 +00:00
|
|
|
#include <suspend/autosuspend.h>
|
2012-12-07 01:06:36 +00:00
|
|
|
#endif
|
2012-11-16 01:03:03 +00:00
|
|
|
|
2016-08-11 22:29:50 +00:00
|
|
|
#include "AnimationParser.h"
|
2017-07-13 22:10:35 +00:00
|
|
|
#include "healthd_draw.h"
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2017-11-08 18:57:52 +00:00
|
|
|
#include <health2/Health.h>
|
2016-02-17 20:21:34 +00:00
|
|
|
#include <healthd/healthd.h>
|
2013-09-09 19:09:08 +00:00
|
|
|
|
2016-08-11 22:29:50 +00:00
|
|
|
using namespace android;
|
|
|
|
|
2018-09-11 17:46:35 +00:00
|
|
|
// main healthd loop
|
|
|
|
extern int healthd_main(void);
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
char* locale;
|
2014-02-13 20:25:21 +00:00
|
|
|
|
2011-08-30 17:46:09 +00:00
|
|
|
#ifndef max
|
2017-07-13 22:10:35 +00:00
|
|
|
#define max(a, b) ((a) > (b) ? (a) : (b))
|
2011-08-30 17:46:09 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef min
|
2017-07-13 22:10:35 +00:00
|
|
|
#define min(a, b) ((a) < (b) ? (a) : (b))
|
2011-08-30 17:46:09 +00:00
|
|
|
#endif
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
2011-09-22 22:49:04 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
#define MSEC_PER_SEC (1000LL)
|
|
|
|
#define NSEC_PER_MSEC (1000000LL)
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
#define BATTERY_UNKNOWN_TIME (2 * MSEC_PER_SEC)
|
|
|
|
#define POWER_ON_KEY_TIME (2 * MSEC_PER_SEC)
|
2011-08-30 17:46:09 +00:00
|
|
|
#define UNPLUGGED_SHUTDOWN_TIME (10 * MSEC_PER_SEC)
|
2018-07-17 09:49:34 +00:00
|
|
|
#define UNPLUGGED_DISPLAY_TIME (3 * MSEC_PER_SEC)
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
#define LAST_KMSG_MAX_SZ (32 * 1024)
|
2011-09-30 00:20:07 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
#define LOGE(x...) KLOG_ERROR("charger", x);
|
|
|
|
#define LOGW(x...) KLOG_WARNING("charger", x);
|
|
|
|
#define LOGV(x...) KLOG_DEBUG("charger", x);
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2019-01-28 20:55:54 +00:00
|
|
|
// Resources in /product/etc/res overrides resources in /res.
|
|
|
|
// If the device is using the Generic System Image (GSI), resources may exist in
|
|
|
|
// both paths.
|
|
|
|
static constexpr const char* product_animation_desc_path =
|
|
|
|
"/product/etc/res/values/charger/animation.txt";
|
|
|
|
static constexpr const char* product_animation_root = "/product/etc/res/images/";
|
|
|
|
static constexpr const char* animation_desc_path = "/res/values/charger/animation.txt";
|
2016-08-11 22:29:50 +00:00
|
|
|
|
2011-08-30 17:46:09 +00:00
|
|
|
struct key_state {
|
|
|
|
bool pending;
|
|
|
|
bool down;
|
|
|
|
int64_t timestamp;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct charger {
|
2013-09-09 19:09:08 +00:00
|
|
|
bool have_battery_state;
|
|
|
|
bool charger_connected;
|
2018-07-17 09:49:34 +00:00
|
|
|
bool screen_blanked;
|
2011-08-30 17:46:09 +00:00
|
|
|
int64_t next_screen_transition;
|
|
|
|
int64_t next_key_check;
|
|
|
|
int64_t next_pwr_check;
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
key_state keys[KEY_MAX + 1];
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
animation* batt_anim;
|
2015-04-15 17:25:55 +00:00
|
|
|
GRSurface* surf_unknown;
|
2014-10-22 01:24:11 +00:00
|
|
|
int boot_min_cap;
|
2011-08-30 17:46:09 +00:00
|
|
|
};
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static const animation BASE_ANIMATION = {
|
|
|
|
.text_clock =
|
|
|
|
{
|
|
|
|
.pos_x = 0,
|
|
|
|
.pos_y = 0,
|
|
|
|
|
|
|
|
.color_r = 255,
|
|
|
|
.color_g = 255,
|
|
|
|
.color_b = 255,
|
|
|
|
.color_a = 255,
|
|
|
|
|
|
|
|
.font = nullptr,
|
|
|
|
},
|
|
|
|
.text_percent =
|
|
|
|
{
|
|
|
|
.pos_x = 0,
|
|
|
|
.pos_y = 0,
|
|
|
|
|
|
|
|
.color_r = 255,
|
|
|
|
.color_g = 255,
|
|
|
|
.color_b = 255,
|
|
|
|
.color_a = 255,
|
|
|
|
},
|
2016-08-11 22:29:50 +00:00
|
|
|
|
|
|
|
.run = false,
|
|
|
|
|
|
|
|
.frames = nullptr,
|
|
|
|
.cur_frame = 0,
|
|
|
|
.num_frames = 0,
|
|
|
|
.first_frame_repeats = 2,
|
|
|
|
|
|
|
|
.cur_cycle = 0,
|
|
|
|
.num_cycles = 3,
|
|
|
|
|
|
|
|
.cur_level = 0,
|
|
|
|
.cur_status = BATTERY_STATUS_UNKNOWN,
|
|
|
|
};
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static animation::frame default_animation_frames[] = {
|
2011-09-22 22:49:04 +00:00
|
|
|
{
|
|
|
|
.disp_time = 750,
|
2016-08-11 22:29:50 +00:00
|
|
|
.min_level = 0,
|
|
|
|
.max_level = 19,
|
2013-09-09 19:09:08 +00:00
|
|
|
.surface = NULL,
|
2011-09-22 22:49:04 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.disp_time = 750,
|
2016-08-11 22:29:50 +00:00
|
|
|
.min_level = 0,
|
|
|
|
.max_level = 39,
|
2013-09-09 19:09:08 +00:00
|
|
|
.surface = NULL,
|
2011-09-22 22:49:04 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.disp_time = 750,
|
2016-08-11 22:29:50 +00:00
|
|
|
.min_level = 0,
|
|
|
|
.max_level = 59,
|
2013-09-09 19:09:08 +00:00
|
|
|
.surface = NULL,
|
2011-09-22 22:49:04 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.disp_time = 750,
|
2016-08-11 22:29:50 +00:00
|
|
|
.min_level = 0,
|
|
|
|
.max_level = 79,
|
2013-09-09 19:09:08 +00:00
|
|
|
.surface = NULL,
|
2011-09-22 22:49:04 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.disp_time = 750,
|
2016-08-11 22:29:50 +00:00
|
|
|
.min_level = 80,
|
|
|
|
.max_level = 95,
|
2013-09-09 19:09:08 +00:00
|
|
|
.surface = NULL,
|
2011-09-22 22:49:04 +00:00
|
|
|
},
|
2011-09-26 21:14:19 +00:00
|
|
|
{
|
|
|
|
.disp_time = 750,
|
2016-08-11 22:29:50 +00:00
|
|
|
.min_level = 0,
|
|
|
|
.max_level = 100,
|
2013-09-09 19:09:08 +00:00
|
|
|
.surface = NULL,
|
2011-09-26 21:14:19 +00:00
|
|
|
},
|
2011-09-22 22:49:04 +00:00
|
|
|
};
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static animation battery_animation = BASE_ANIMATION;
|
2011-09-22 22:49:04 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static charger charger_state;
|
|
|
|
static healthd_config* healthd_config;
|
|
|
|
static android::BatteryProperties* batt_prop;
|
|
|
|
static std::unique_ptr<HealthdDraw> healthd_draw;
|
2011-08-30 17:46:09 +00:00
|
|
|
|
|
|
|
/* current time in milliseconds */
|
2017-07-13 22:10:35 +00:00
|
|
|
static int64_t curr_time_ms() {
|
|
|
|
timespec tm;
|
2011-08-30 17:46:09 +00:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &tm);
|
|
|
|
return tm.tv_sec * MSEC_PER_SEC + (tm.tv_nsec / NSEC_PER_MSEC);
|
|
|
|
}
|
|
|
|
|
2011-09-30 00:20:07 +00:00
|
|
|
#define MAX_KLOG_WRITE_BUF_SZ 256
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static void dump_last_kmsg(void) {
|
|
|
|
char* buf;
|
|
|
|
char* ptr;
|
2011-09-30 00:20:07 +00:00
|
|
|
unsigned sz = 0;
|
|
|
|
int len;
|
|
|
|
|
2014-09-23 21:54:24 +00:00
|
|
|
LOGW("\n");
|
|
|
|
LOGW("*************** LAST KMSG ***************\n");
|
|
|
|
LOGW("\n");
|
2017-06-27 16:19:09 +00:00
|
|
|
const char* kmsg[] = {
|
|
|
|
// clang-format off
|
|
|
|
"/sys/fs/pstore/console-ramoops-0",
|
|
|
|
"/sys/fs/pstore/console-ramoops",
|
|
|
|
"/proc/last_kmsg",
|
|
|
|
// clang-format on
|
|
|
|
};
|
|
|
|
for (size_t i = 0; i < arraysize(kmsg); ++i) {
|
|
|
|
buf = (char*)load_file(kmsg[i], &sz);
|
|
|
|
if (buf && sz) break;
|
|
|
|
}
|
2013-11-23 01:52:59 +00:00
|
|
|
|
2011-09-30 00:20:07 +00:00
|
|
|
if (!buf || !sz) {
|
2017-06-27 16:19:09 +00:00
|
|
|
LOGW("last_kmsg not found. Cold reset?\n");
|
|
|
|
goto out;
|
2011-09-30 00:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
len = min(sz, LAST_KMSG_MAX_SZ);
|
|
|
|
ptr = buf + (sz - len);
|
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
int cnt = min(len, MAX_KLOG_WRITE_BUF_SZ);
|
|
|
|
char yoink;
|
2017-07-13 22:10:35 +00:00
|
|
|
char* nl;
|
2011-09-30 00:20:07 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
nl = (char*)memrchr(ptr, '\n', cnt - 1);
|
|
|
|
if (nl) cnt = nl - ptr + 1;
|
2011-09-30 00:20:07 +00:00
|
|
|
|
|
|
|
yoink = ptr[cnt];
|
|
|
|
ptr[cnt] = '\0';
|
2014-09-23 21:54:24 +00:00
|
|
|
klog_write(6, "<4>%s", ptr);
|
2011-09-30 00:20:07 +00:00
|
|
|
ptr[cnt] = yoink;
|
|
|
|
|
|
|
|
len -= cnt;
|
|
|
|
ptr += cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
out:
|
2014-09-23 21:54:24 +00:00
|
|
|
LOGW("\n");
|
|
|
|
LOGW("************* END LAST KMSG *************\n");
|
|
|
|
LOGW("\n");
|
2011-09-30 00:20:07 +00:00
|
|
|
}
|
|
|
|
|
2012-11-16 01:03:03 +00:00
|
|
|
#ifdef CHARGER_ENABLE_SUSPEND
|
2017-07-13 22:10:35 +00:00
|
|
|
static int request_suspend(bool enable) {
|
2012-11-16 01:03:03 +00:00
|
|
|
if (enable)
|
|
|
|
return autosuspend_enable();
|
|
|
|
else
|
|
|
|
return autosuspend_disable();
|
|
|
|
}
|
|
|
|
#else
|
2017-07-13 22:10:35 +00:00
|
|
|
static int request_suspend(bool /*enable*/) {
|
2012-11-16 01:03:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static void kick_animation(animation* anim) {
|
2011-09-22 22:49:04 +00:00
|
|
|
anim->run = true;
|
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static void reset_animation(animation* anim) {
|
2011-09-22 22:49:04 +00:00
|
|
|
anim->cur_cycle = 0;
|
|
|
|
anim->cur_frame = 0;
|
|
|
|
anim->run = false;
|
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static void update_screen_state(charger* charger, int64_t now) {
|
|
|
|
animation* batt_anim = charger->batt_anim;
|
2011-09-22 22:49:04 +00:00
|
|
|
int disp_time;
|
|
|
|
|
2016-08-11 22:29:50 +00:00
|
|
|
if (!batt_anim->run || now < charger->next_screen_transition) return;
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
if (healthd_draw == nullptr) {
|
2014-09-26 02:44:42 +00:00
|
|
|
if (healthd_config && healthd_config->screen_on) {
|
|
|
|
if (!healthd_config->screen_on(batt_prop)) {
|
|
|
|
LOGV("[%" PRId64 "] leave screen off\n", now);
|
|
|
|
batt_anim->run = false;
|
|
|
|
charger->next_screen_transition = -1;
|
2017-07-13 22:10:35 +00:00
|
|
|
if (charger->charger_connected) request_suspend(true);
|
2014-09-26 02:44:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-06-30 20:15:05 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
healthd_draw.reset(new HealthdDraw(batt_anim));
|
2014-06-30 20:15:05 +00:00
|
|
|
|
|
|
|
#ifndef CHARGER_DISABLE_INIT_BLANK
|
2017-07-13 22:10:35 +00:00
|
|
|
healthd_draw->blank_screen(true);
|
2018-07-17 09:49:34 +00:00
|
|
|
charger->screen_blanked = true;
|
2014-06-30 20:15:05 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-22 22:49:04 +00:00
|
|
|
/* animation is over, blank screen and leave */
|
2016-08-11 22:29:50 +00:00
|
|
|
if (batt_anim->num_cycles > 0 && batt_anim->cur_cycle == batt_anim->num_cycles) {
|
2011-09-22 22:49:04 +00:00
|
|
|
reset_animation(batt_anim);
|
2011-08-30 17:46:09 +00:00
|
|
|
charger->next_screen_transition = -1;
|
2017-07-13 22:10:35 +00:00
|
|
|
healthd_draw->blank_screen(true);
|
2018-07-17 09:49:34 +00:00
|
|
|
charger->screen_blanked = true;
|
2014-05-16 00:49:06 +00:00
|
|
|
LOGV("[%" PRId64 "] animation done\n", now);
|
2017-07-13 22:10:35 +00:00
|
|
|
if (charger->charger_connected) request_suspend(true);
|
2011-09-22 22:49:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
disp_time = batt_anim->frames[batt_anim->cur_frame].disp_time;
|
|
|
|
|
2018-07-17 09:49:34 +00:00
|
|
|
if (charger->screen_blanked) {
|
|
|
|
healthd_draw->blank_screen(false);
|
|
|
|
charger->screen_blanked = false;
|
|
|
|
}
|
2018-05-23 22:48:46 +00:00
|
|
|
|
2011-09-22 22:49:04 +00:00
|
|
|
/* animation starting, set up the animation */
|
|
|
|
if (batt_anim->cur_frame == 0) {
|
2014-05-16 00:49:06 +00:00
|
|
|
LOGV("[%" PRId64 "] animation starting\n", now);
|
2016-08-11 22:29:50 +00:00
|
|
|
if (batt_prop) {
|
|
|
|
batt_anim->cur_level = batt_prop->batteryLevel;
|
|
|
|
batt_anim->cur_status = batt_prop->batteryStatus;
|
|
|
|
if (batt_prop->batteryLevel >= 0 && batt_anim->num_frames != 0) {
|
|
|
|
/* find first frame given current battery level */
|
|
|
|
for (int i = 0; i < batt_anim->num_frames; i++) {
|
|
|
|
if (batt_anim->cur_level >= batt_anim->frames[i].min_level &&
|
|
|
|
batt_anim->cur_level <= batt_anim->frames[i].max_level) {
|
|
|
|
batt_anim->cur_frame = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-09-22 22:49:04 +00:00
|
|
|
|
2018-07-17 09:49:34 +00:00
|
|
|
if (charger->charger_connected) {
|
|
|
|
// repeat the first frame first_frame_repeats times
|
|
|
|
disp_time = batt_anim->frames[batt_anim->cur_frame].disp_time *
|
|
|
|
batt_anim->first_frame_repeats;
|
|
|
|
} else {
|
|
|
|
disp_time = UNPLUGGED_DISPLAY_TIME / batt_anim->num_cycles;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGV("cur_frame=%d disp_time=%d\n", batt_anim->cur_frame, disp_time);
|
2011-09-22 22:49:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw the new frame (@ cur_frame) */
|
2017-07-13 22:10:35 +00:00
|
|
|
healthd_draw->redraw_screen(charger->batt_anim, charger->surf_unknown);
|
2011-09-22 22:49:04 +00:00
|
|
|
|
|
|
|
/* if we don't have anim frames, we only have one image, so just bump
|
|
|
|
* the cycle counter and exit
|
|
|
|
*/
|
2016-08-11 22:29:50 +00:00
|
|
|
if (batt_anim->num_frames == 0 || batt_anim->cur_level < 0) {
|
|
|
|
LOGW("[%" PRId64 "] animation missing or unknown battery status\n", now);
|
2011-09-22 22:49:04 +00:00
|
|
|
charger->next_screen_transition = now + BATTERY_UNKNOWN_TIME;
|
|
|
|
batt_anim->cur_cycle++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* schedule next screen transition */
|
2018-07-17 09:49:34 +00:00
|
|
|
charger->next_screen_transition = curr_time_ms() + disp_time;
|
2011-09-22 22:49:04 +00:00
|
|
|
|
2014-06-23 18:13:15 +00:00
|
|
|
/* advance frame cntr to the next valid frame only if we are charging
|
2011-09-22 22:49:04 +00:00
|
|
|
* if necessary, advance cycle cntr, and reset frame cntr
|
|
|
|
*/
|
2014-06-23 18:13:15 +00:00
|
|
|
if (charger->charger_connected) {
|
2011-10-31 23:53:41 +00:00
|
|
|
batt_anim->cur_frame++;
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2014-06-23 18:13:15 +00:00
|
|
|
while (batt_anim->cur_frame < batt_anim->num_frames &&
|
2016-08-11 22:29:50 +00:00
|
|
|
(batt_anim->cur_level < batt_anim->frames[batt_anim->cur_frame].min_level ||
|
|
|
|
batt_anim->cur_level > batt_anim->frames[batt_anim->cur_frame].max_level)) {
|
2014-06-23 18:13:15 +00:00
|
|
|
batt_anim->cur_frame++;
|
2016-08-11 22:29:50 +00:00
|
|
|
}
|
2014-06-23 18:13:15 +00:00
|
|
|
if (batt_anim->cur_frame >= batt_anim->num_frames) {
|
|
|
|
batt_anim->cur_cycle++;
|
|
|
|
batt_anim->cur_frame = 0;
|
|
|
|
|
|
|
|
/* don't reset the cycle counter, since we use that as a signal
|
|
|
|
* in a test above to check if animation is over
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Stop animating if we're not charging.
|
|
|
|
* If we stop it immediately instead of going through this loop, then
|
|
|
|
* the animation would stop somewhere in the middle.
|
|
|
|
*/
|
|
|
|
batt_anim->cur_frame = 0;
|
|
|
|
batt_anim->cur_cycle++;
|
2011-09-22 22:49:04 +00:00
|
|
|
}
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static int set_key_callback(charger* charger, int code, int value) {
|
2011-10-12 23:16:05 +00:00
|
|
|
int64_t now = curr_time_ms();
|
|
|
|
int down = !!value;
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
if (code > KEY_MAX) return -1;
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2011-10-12 23:18:23 +00:00
|
|
|
/* ignore events that don't modify our state */
|
2017-07-13 22:10:35 +00:00
|
|
|
if (charger->keys[code].down == down) return 0;
|
2011-10-12 23:18:23 +00:00
|
|
|
|
2011-08-30 17:46:09 +00:00
|
|
|
/* only record the down even timestamp, as the amount
|
|
|
|
* of time the key spent not being pressed is not useful */
|
2017-07-13 22:10:35 +00:00
|
|
|
if (down) charger->keys[code].timestamp = now;
|
2011-10-12 23:16:05 +00:00
|
|
|
charger->keys[code].down = down;
|
|
|
|
charger->keys[code].pending = true;
|
2011-08-30 17:46:09 +00:00
|
|
|
if (down) {
|
2014-05-16 00:49:06 +00:00
|
|
|
LOGV("[%" PRId64 "] key[%d] down\n", now, code);
|
2011-08-30 17:46:09 +00:00
|
|
|
} else {
|
2011-10-12 23:16:05 +00:00
|
|
|
int64_t duration = now - charger->keys[code].timestamp;
|
2011-08-30 17:46:09 +00:00
|
|
|
int64_t secs = duration / 1000;
|
|
|
|
int64_t msecs = duration - secs * 1000;
|
2017-07-13 22:10:35 +00:00
|
|
|
LOGV("[%" PRId64 "] key[%d] up (was down for %" PRId64 ".%" PRId64 "sec)\n", now, code,
|
|
|
|
secs, msecs);
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
2011-10-12 23:16:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static void update_input_state(charger* charger, input_event* ev) {
|
|
|
|
if (ev->type != EV_KEY) return;
|
2017-01-19 06:54:54 +00:00
|
|
|
set_key_callback(charger, ev->code, ev->value);
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static void set_next_key_check(charger* charger, key_state* key, int64_t timeout) {
|
2011-08-30 17:46:09 +00:00
|
|
|
int64_t then = key->timestamp + timeout;
|
|
|
|
|
|
|
|
if (charger->next_key_check == -1 || then < charger->next_key_check)
|
|
|
|
charger->next_key_check = then;
|
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static void process_key(charger* charger, int code, int64_t now) {
|
|
|
|
key_state* key = &charger->keys[code];
|
2011-08-30 17:46:09 +00:00
|
|
|
|
|
|
|
if (code == KEY_POWER) {
|
|
|
|
if (key->down) {
|
|
|
|
int64_t reboot_timeout = key->timestamp + POWER_ON_KEY_TIME;
|
|
|
|
if (now >= reboot_timeout) {
|
2014-06-16 22:06:21 +00:00
|
|
|
/* We do not currently support booting from charger mode on
|
|
|
|
all devices. Check the property and continue booting or reboot
|
|
|
|
accordingly. */
|
|
|
|
if (property_get_bool("ro.enable_boot_charger_mode", false)) {
|
2014-09-23 21:54:24 +00:00
|
|
|
LOGW("[%" PRId64 "] booting from charger mode\n", now);
|
2014-06-16 22:06:21 +00:00
|
|
|
property_set("sys.boot_from_charger_mode", "1");
|
|
|
|
} else {
|
2016-08-11 22:29:50 +00:00
|
|
|
if (charger->batt_anim->cur_level >= charger->boot_min_cap) {
|
2014-10-22 01:24:11 +00:00
|
|
|
LOGW("[%" PRId64 "] rebooting\n", now);
|
2017-01-31 23:51:50 +00:00
|
|
|
reboot(RB_AUTOBOOT);
|
2014-10-22 01:24:11 +00:00
|
|
|
} else {
|
2017-07-13 22:10:35 +00:00
|
|
|
LOGV("[%" PRId64
|
|
|
|
"] ignore power-button press, battery level "
|
|
|
|
"less than minimum\n",
|
|
|
|
now);
|
2014-10-22 01:24:11 +00:00
|
|
|
}
|
2014-06-16 22:06:21 +00:00
|
|
|
}
|
2011-08-30 17:46:09 +00:00
|
|
|
} else {
|
|
|
|
/* if the key is pressed but timeout hasn't expired,
|
|
|
|
* make sure we wake up at the right-ish time to check
|
|
|
|
*/
|
|
|
|
set_next_key_check(charger, key, POWER_ON_KEY_TIME);
|
2014-10-22 21:16:35 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
/* Turn on the display and kick animation on power-key press
|
|
|
|
* rather than on key release
|
|
|
|
*/
|
2014-10-22 21:16:35 +00:00
|
|
|
kick_animation(charger->batt_anim);
|
|
|
|
request_suspend(false);
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* if the power key got released, force screen state cycle */
|
2012-11-16 01:03:03 +00:00
|
|
|
if (key->pending) {
|
2011-09-22 22:49:04 +00:00
|
|
|
kick_animation(charger->batt_anim);
|
2018-07-17 09:49:34 +00:00
|
|
|
request_suspend(false);
|
2012-11-16 01:03:03 +00:00
|
|
|
}
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
key->pending = false;
|
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static void handle_input_state(charger* charger, int64_t now) {
|
2011-08-30 17:46:09 +00:00
|
|
|
process_key(charger, KEY_POWER, now);
|
|
|
|
|
|
|
|
if (charger->next_key_check != -1 && now > charger->next_key_check)
|
|
|
|
charger->next_key_check = -1;
|
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static void handle_power_supply_state(charger* charger, int64_t now) {
|
|
|
|
if (!charger->have_battery_state) return;
|
2013-09-09 19:09:08 +00:00
|
|
|
|
|
|
|
if (!charger->charger_connected) {
|
2012-11-16 01:03:03 +00:00
|
|
|
request_suspend(false);
|
2011-08-30 17:46:09 +00:00
|
|
|
if (charger->next_pwr_check == -1) {
|
2018-07-17 09:49:34 +00:00
|
|
|
/* Last cycle would have stopped at the extreme top of battery-icon
|
|
|
|
* Need to show the correct level corresponding to capacity.
|
|
|
|
*
|
|
|
|
* Reset next_screen_transition to update screen immediately.
|
|
|
|
* Reset & kick animation to show complete animation cycles
|
|
|
|
* when charger disconnected.
|
|
|
|
*/
|
|
|
|
charger->next_screen_transition = now - 1;
|
|
|
|
reset_animation(charger->batt_anim);
|
|
|
|
kick_animation(charger->batt_anim);
|
2011-08-30 17:46:09 +00:00
|
|
|
charger->next_pwr_check = now + UNPLUGGED_SHUTDOWN_TIME;
|
2014-09-23 21:54:24 +00:00
|
|
|
LOGW("[%" PRId64 "] device unplugged: shutting down in %" PRId64 " (@ %" PRId64 ")\n",
|
2014-05-16 00:49:06 +00:00
|
|
|
now, (int64_t)UNPLUGGED_SHUTDOWN_TIME, charger->next_pwr_check);
|
2011-08-30 17:46:09 +00:00
|
|
|
} else if (now >= charger->next_pwr_check) {
|
2014-09-23 21:54:24 +00:00
|
|
|
LOGW("[%" PRId64 "] shutting down\n", now);
|
2017-01-31 23:51:50 +00:00
|
|
|
reboot(RB_POWER_OFF);
|
2011-08-30 17:46:09 +00:00
|
|
|
} else {
|
|
|
|
/* otherwise we already have a shutdown timer scheduled */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* online supply present, reset shutdown timer if set */
|
|
|
|
if (charger->next_pwr_check != -1) {
|
2018-07-17 09:49:34 +00:00
|
|
|
/* Reset next_screen_transition to update screen immediately.
|
|
|
|
* Reset & kick animation to show complete animation cycles
|
|
|
|
* when charger connected again.
|
|
|
|
*/
|
|
|
|
request_suspend(false);
|
|
|
|
charger->next_screen_transition = now - 1;
|
|
|
|
reset_animation(charger->batt_anim);
|
2011-09-22 22:49:04 +00:00
|
|
|
kick_animation(charger->batt_anim);
|
2018-07-17 09:49:34 +00:00
|
|
|
LOGW("[%" PRId64 "] device plugged in: shutdown cancelled\n", now);
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
charger->next_pwr_check = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
void healthd_mode_charger_heartbeat() {
|
|
|
|
charger* charger = &charger_state;
|
2013-09-09 19:09:08 +00:00
|
|
|
int64_t now = curr_time_ms();
|
|
|
|
|
|
|
|
handle_input_state(charger, now);
|
|
|
|
handle_power_supply_state(charger, now);
|
|
|
|
|
|
|
|
/* do screen update last in case any of the above want to start
|
|
|
|
* screen transitions (animations, etc)
|
|
|
|
*/
|
|
|
|
update_screen_state(charger, now);
|
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
void healthd_mode_charger_battery_update(android::BatteryProperties* props) {
|
|
|
|
charger* charger = &charger_state;
|
2013-09-09 19:09:08 +00:00
|
|
|
|
|
|
|
charger->charger_connected =
|
2017-07-13 22:10:35 +00:00
|
|
|
props->chargerAcOnline || props->chargerUsbOnline || props->chargerWirelessOnline;
|
2013-09-09 19:09:08 +00:00
|
|
|
|
|
|
|
if (!charger->have_battery_state) {
|
|
|
|
charger->have_battery_state = true;
|
|
|
|
charger->next_screen_transition = curr_time_ms() - 1;
|
2018-07-17 09:49:34 +00:00
|
|
|
request_suspend(false);
|
2013-09-09 19:09:08 +00:00
|
|
|
reset_animation(charger->batt_anim);
|
|
|
|
kick_animation(charger->batt_anim);
|
|
|
|
}
|
2014-09-26 02:44:42 +00:00
|
|
|
batt_prop = props;
|
2013-09-09 19:09:08 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
int healthd_mode_charger_preparetowait(void) {
|
|
|
|
charger* charger = &charger_state;
|
2013-09-09 19:09:08 +00:00
|
|
|
int64_t now = curr_time_ms();
|
2011-08-30 17:46:09 +00:00
|
|
|
int64_t next_event = INT64_MAX;
|
|
|
|
int64_t timeout;
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
LOGV("[%" PRId64 "] next screen: %" PRId64 " next key: %" PRId64 " next pwr: %" PRId64 "\n",
|
|
|
|
now, charger->next_screen_transition, charger->next_key_check, charger->next_pwr_check);
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
if (charger->next_screen_transition != -1) next_event = charger->next_screen_transition;
|
2011-08-30 17:46:09 +00:00
|
|
|
if (charger->next_key_check != -1 && charger->next_key_check < next_event)
|
|
|
|
next_event = charger->next_key_check;
|
|
|
|
if (charger->next_pwr_check != -1 && charger->next_pwr_check < next_event)
|
|
|
|
next_event = charger->next_pwr_check;
|
|
|
|
|
|
|
|
if (next_event != -1 && next_event != INT64_MAX)
|
|
|
|
timeout = max(0, next_event - now);
|
|
|
|
else
|
|
|
|
timeout = -1;
|
2013-09-09 19:09:08 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
return (int)timeout;
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static int input_callback(charger* charger, int fd, unsigned int epevents) {
|
|
|
|
input_event ev;
|
2011-08-30 17:46:09 +00:00
|
|
|
int ret;
|
|
|
|
|
2013-09-09 19:09:08 +00:00
|
|
|
ret = ev_get_input(fd, epevents, &ev);
|
2017-07-13 22:10:35 +00:00
|
|
|
if (ret) return -1;
|
2011-10-12 23:16:05 +00:00
|
|
|
update_input_state(charger, &ev);
|
2011-08-30 17:46:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static void charger_event_handler(uint32_t /*epevents*/) {
|
2011-08-30 17:46:09 +00:00
|
|
|
int ret;
|
|
|
|
|
2013-09-09 19:09:08 +00:00
|
|
|
ret = ev_wait(-1);
|
2017-07-13 22:10:35 +00:00
|
|
|
if (!ret) ev_dispatch();
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
animation* init_animation() {
|
2016-08-11 22:29:50 +00:00
|
|
|
bool parse_success;
|
|
|
|
|
|
|
|
std::string content;
|
2019-01-28 20:55:54 +00:00
|
|
|
if (base::ReadFileToString(product_animation_desc_path, &content)) {
|
|
|
|
parse_success = parse_animation_desc(content, &battery_animation);
|
|
|
|
battery_animation.set_resource_root(product_animation_root);
|
|
|
|
} else if (base::ReadFileToString(animation_desc_path, &content)) {
|
2016-08-11 22:29:50 +00:00
|
|
|
parse_success = parse_animation_desc(content, &battery_animation);
|
|
|
|
} else {
|
|
|
|
LOGW("Could not open animation description at %s\n", animation_desc_path);
|
|
|
|
parse_success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parse_success) {
|
|
|
|
LOGW("Could not parse animation description. Using default animation.\n");
|
|
|
|
battery_animation = BASE_ANIMATION;
|
|
|
|
battery_animation.animation_file.assign("charger/battery_scale");
|
|
|
|
battery_animation.frames = default_animation_frames;
|
|
|
|
battery_animation.num_frames = ARRAY_SIZE(default_animation_frames);
|
|
|
|
}
|
|
|
|
if (battery_animation.fail_file.empty()) {
|
|
|
|
battery_animation.fail_file.assign("charger/battery_fail");
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGV("Animation Description:\n");
|
2017-07-13 22:10:35 +00:00
|
|
|
LOGV(" animation: %d %d '%s' (%d)\n", battery_animation.num_cycles,
|
|
|
|
battery_animation.first_frame_repeats, battery_animation.animation_file.c_str(),
|
|
|
|
battery_animation.num_frames);
|
2016-08-11 22:29:50 +00:00
|
|
|
LOGV(" fail_file: '%s'\n", battery_animation.fail_file.c_str());
|
2017-07-13 22:10:35 +00:00
|
|
|
LOGV(" clock: %d %d %d %d %d %d '%s'\n", battery_animation.text_clock.pos_x,
|
|
|
|
battery_animation.text_clock.pos_y, battery_animation.text_clock.color_r,
|
|
|
|
battery_animation.text_clock.color_g, battery_animation.text_clock.color_b,
|
|
|
|
battery_animation.text_clock.color_a, battery_animation.text_clock.font_file.c_str());
|
|
|
|
LOGV(" percent: %d %d %d %d %d %d '%s'\n", battery_animation.text_percent.pos_x,
|
|
|
|
battery_animation.text_percent.pos_y, battery_animation.text_percent.color_r,
|
|
|
|
battery_animation.text_percent.color_g, battery_animation.text_percent.color_b,
|
|
|
|
battery_animation.text_percent.color_a, battery_animation.text_percent.font_file.c_str());
|
2016-08-11 22:29:50 +00:00
|
|
|
for (int i = 0; i < battery_animation.num_frames; i++) {
|
|
|
|
LOGV(" frame %.2d: %d %d %d\n", i, battery_animation.frames[i].disp_time,
|
2017-07-13 22:10:35 +00:00
|
|
|
battery_animation.frames[i].min_level, battery_animation.frames[i].max_level);
|
2016-08-11 22:29:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &battery_animation;
|
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
void healthd_mode_charger_init(struct healthd_config* config) {
|
2017-11-08 18:57:52 +00:00
|
|
|
using android::hardware::health::V2_0::implementation::Health;
|
|
|
|
|
2011-08-30 17:46:09 +00:00
|
|
|
int ret;
|
2017-07-13 22:10:35 +00:00
|
|
|
charger* charger = &charger_state;
|
2011-09-22 22:49:04 +00:00
|
|
|
int i;
|
2013-09-09 19:09:08 +00:00
|
|
|
int epollfd;
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2011-09-30 00:20:07 +00:00
|
|
|
dump_last_kmsg();
|
|
|
|
|
2014-09-23 21:54:24 +00:00
|
|
|
LOGW("--------------- STARTING CHARGER MODE ---------------\n");
|
2011-09-30 00:20:07 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
ret = ev_init(std::bind(&input_callback, charger, std::placeholders::_1, std::placeholders::_2));
|
2013-09-09 19:09:08 +00:00
|
|
|
if (!ret) {
|
|
|
|
epollfd = ev_get_epollfd();
|
2016-10-18 23:35:15 +00:00
|
|
|
healthd_register_event(epollfd, charger_event_handler, EVENT_WAKEUP_FD);
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
animation* anim = init_animation();
|
2016-08-11 22:29:50 +00:00
|
|
|
charger->batt_anim = anim;
|
|
|
|
|
|
|
|
ret = res_create_display_surface(anim->fail_file.c_str(), &charger->surf_unknown);
|
2011-08-30 17:46:09 +00:00
|
|
|
if (ret < 0) {
|
2018-05-23 22:48:46 +00:00
|
|
|
LOGE("Cannot load custom battery_fail image. Reverting to built in: %d\n", ret);
|
2016-08-11 22:29:50 +00:00
|
|
|
ret = res_create_display_surface("charger/battery_fail", &charger->surf_unknown);
|
|
|
|
if (ret < 0) {
|
|
|
|
LOGE("Cannot load built in battery_fail image\n");
|
|
|
|
charger->surf_unknown = NULL;
|
|
|
|
}
|
2011-09-22 22:49:04 +00:00
|
|
|
}
|
|
|
|
|
2015-04-15 17:25:55 +00:00
|
|
|
GRSurface** scale_frames;
|
2014-03-11 15:42:09 +00:00
|
|
|
int scale_count;
|
2015-12-16 18:57:10 +00:00
|
|
|
int scale_fps; // Not in use (charger/battery_scale doesn't have FPS text
|
|
|
|
// chunk). We are using hard-coded frame.disp_time instead.
|
2017-07-13 22:10:35 +00:00
|
|
|
ret = res_create_multi_display_surface(anim->animation_file.c_str(), &scale_count, &scale_fps,
|
|
|
|
&scale_frames);
|
2014-03-11 15:42:09 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
LOGE("Cannot load battery_scale image\n");
|
2016-08-11 22:29:50 +00:00
|
|
|
anim->num_frames = 0;
|
|
|
|
anim->num_cycles = 1;
|
|
|
|
} else if (scale_count != anim->num_frames) {
|
2017-07-13 22:10:35 +00:00
|
|
|
LOGE("battery_scale image has unexpected frame count (%d, expected %d)\n", scale_count,
|
|
|
|
anim->num_frames);
|
2016-08-11 22:29:50 +00:00
|
|
|
anim->num_frames = 0;
|
|
|
|
anim->num_cycles = 1;
|
2014-03-11 15:42:09 +00:00
|
|
|
} else {
|
2016-08-11 22:29:50 +00:00
|
|
|
for (i = 0; i < anim->num_frames; i++) {
|
|
|
|
anim->frames[i].surface = scale_frames[i];
|
2011-09-22 22:49:04 +00:00
|
|
|
}
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
2017-07-13 22:10:35 +00:00
|
|
|
ev_sync_key_state(
|
|
|
|
std::bind(&set_key_callback, charger, std::placeholders::_1, std::placeholders::_2));
|
2011-10-12 23:16:05 +00:00
|
|
|
|
2013-09-09 19:09:08 +00:00
|
|
|
charger->next_screen_transition = -1;
|
2011-08-30 17:46:09 +00:00
|
|
|
charger->next_key_check = -1;
|
|
|
|
charger->next_pwr_check = -1;
|
2017-11-08 18:57:52 +00:00
|
|
|
|
|
|
|
// Initialize Health implementation (which initializes the internal BatteryMonitor).
|
|
|
|
Health::initInstance(config);
|
|
|
|
|
2014-09-26 02:44:42 +00:00
|
|
|
healthd_config = config;
|
2014-10-22 01:24:11 +00:00
|
|
|
charger->boot_min_cap = config->boot_min_cap;
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
2018-09-11 17:46:35 +00:00
|
|
|
|
|
|
|
static struct healthd_mode_ops charger_ops = {
|
|
|
|
.init = healthd_mode_charger_init,
|
|
|
|
.preparetowait = healthd_mode_charger_preparetowait,
|
|
|
|
.heartbeat = healthd_mode_charger_heartbeat,
|
|
|
|
.battery_update = healthd_mode_charger_battery_update,
|
|
|
|
};
|
|
|
|
|
|
|
|
int healthd_charger_main(int argc, char** argv) {
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
healthd_mode_ops = &charger_ops;
|
|
|
|
|
|
|
|
while ((ch = getopt(argc, argv, "cr")) != -1) {
|
|
|
|
switch (ch) {
|
|
|
|
case 'c':
|
|
|
|
// -c is now a noop
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
// -r is now a noop
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
LOGE("Unrecognized charger option: %c\n", optopt);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return healthd_main();
|
|
|
|
}
|