healthd: move charger executable to healthd charger mode
* Add healthd charger mode ops * Check for executable invocation as "charger", set charger mode if so * Incorporate charger executable as healthd charger mode Change-Id: I4a44e7a4c3a65ae9be94491f7f498aa48d4f8a84
|
@ -1,61 +0,0 @@
|
|||
# Copyright 2011 The Android Open Source Project
|
||||
|
||||
ifneq ($(BUILD_TINY_ANDROID),true)
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
charger.c
|
||||
|
||||
ifeq ($(strip $(BOARD_CHARGER_DISABLE_INIT_BLANK)),true)
|
||||
LOCAL_CFLAGS := -DCHARGER_DISABLE_INIT_BLANK
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(BOARD_CHARGER_ENABLE_SUSPEND)),true)
|
||||
LOCAL_CFLAGS += -DCHARGER_ENABLE_SUSPEND
|
||||
endif
|
||||
|
||||
LOCAL_MODULE := charger
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_FORCE_STATIC_EXECUTABLE := true
|
||||
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
|
||||
LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)
|
||||
|
||||
LOCAL_C_INCLUDES := bootable/recovery
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := libminui libpixelflinger_static libpng
|
||||
ifeq ($(strip $(BOARD_CHARGER_ENABLE_SUSPEND)),true)
|
||||
LOCAL_STATIC_LIBRARIES += libsuspend
|
||||
endif
|
||||
LOCAL_STATIC_LIBRARIES += libz libstdc++ libcutils liblog libm libc
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
define _add-charger-image
|
||||
include $$(CLEAR_VARS)
|
||||
LOCAL_MODULE := system_core_charger_$(notdir $(1))
|
||||
LOCAL_MODULE_STEM := $(notdir $(1))
|
||||
_img_modules += $$(LOCAL_MODULE)
|
||||
LOCAL_SRC_FILES := $1
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_MODULE_CLASS := ETC
|
||||
LOCAL_MODULE_PATH := $$(TARGET_ROOT_OUT)/res/images/charger
|
||||
include $$(BUILD_PREBUILT)
|
||||
endef
|
||||
|
||||
_img_modules :=
|
||||
_images :=
|
||||
$(foreach _img, $(call find-subdir-subdir-files, "images", "*.png"), \
|
||||
$(eval $(call _add-charger-image,$(_img))))
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := charger_res_images
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_REQUIRED_MODULES := $(_img_modules)
|
||||
include $(BUILD_PHONY_PACKAGE)
|
||||
|
||||
_add-charger-image :=
|
||||
_img_modules :=
|
||||
|
||||
endif
|
|
@ -14,6 +14,7 @@ include $(CLEAR_VARS)
|
|||
LOCAL_SRC_FILES := \
|
||||
healthd.cpp \
|
||||
healthd_mode_android.cpp \
|
||||
healthd_mode_charger.cpp \
|
||||
BatteryMonitor.cpp \
|
||||
BatteryPropertiesRegistrar.cpp
|
||||
|
||||
|
@ -23,9 +24,69 @@ LOCAL_FORCE_STATIC_EXECUTABLE := true
|
|||
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT_SBIN)
|
||||
LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_SBIN_UNSTRIPPED)
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := libbatteryservice libbinder libz libutils libstdc++ libcutils liblog libm libc
|
||||
LOCAL_CFLAGS := -D__STDC_LIMIT_MACROS
|
||||
|
||||
ifeq ($(strip $(BOARD_CHARGER_DISABLE_INIT_BLANK)),true)
|
||||
LOCAL_CFLAGS += -DCHARGER_DISABLE_INIT_BLANK
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(BOARD_CHARGER_ENABLE_SUSPEND)),true)
|
||||
LOCAL_CFLAGS += -DCHARGER_ENABLE_SUSPEND
|
||||
endif
|
||||
|
||||
LOCAL_C_INCLUDES := bootable/recovery
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := libbatteryservice libbinder libminui libpixelflinger_static libpng libz libutils libstdc++ libcutils liblog libm libc
|
||||
|
||||
ifeq ($(strip $(BOARD_CHARGER_ENABLE_SUSPEND)),true)
|
||||
LOCAL_STATIC_LIBRARIES += libsuspend
|
||||
endif
|
||||
|
||||
LOCAL_HAL_STATIC_LIBRARIES := libhealthd
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
# Symlink /charger to /sbin/healthd
|
||||
SYMLINKS := \
|
||||
$(TARGET_ROOT_OUT)/charger
|
||||
|
||||
$(SYMLINKS): HEALTHD_BINARY := $(LOCAL_MODULE)
|
||||
$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
|
||||
@echo "Symlink: $@ -> /sbin/$(HEALTHD_BINARY)"
|
||||
@rm -rf $@
|
||||
$(hide) ln -sf /sbin/$(HEALTHD_BINARY) $@
|
||||
|
||||
ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
|
||||
|
||||
# We need this so that the installed files could be picked up based on the
|
||||
# local module name
|
||||
ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
|
||||
$(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
|
||||
|
||||
define _add-charger-image
|
||||
include $$(CLEAR_VARS)
|
||||
LOCAL_MODULE := system_core_charger_$(notdir $(1))
|
||||
LOCAL_MODULE_STEM := $(notdir $(1))
|
||||
_img_modules += $$(LOCAL_MODULE)
|
||||
LOCAL_SRC_FILES := $1
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_MODULE_CLASS := ETC
|
||||
LOCAL_MODULE_PATH := $$(TARGET_ROOT_OUT)/res/images/charger
|
||||
include $$(BUILD_PREBUILT)
|
||||
endef
|
||||
|
||||
_img_modules :=
|
||||
_images :=
|
||||
$(foreach _img, $(call find-subdir-subdir-files, "images", "*.png"), \
|
||||
$(eval $(call _add-charger-image,$(_img))))
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := charger_res_images
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_REQUIRED_MODULES := $(_img_modules)
|
||||
include $(BUILD_PHONY_PACKAGE)
|
||||
|
||||
_add-charger-image :=
|
||||
_img_modules :=
|
||||
|
||||
endif
|
||||
|
|
|
@ -21,8 +21,10 @@
|
|||
#include "BatteryMonitor.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <batteryservice/BatteryService.h>
|
||||
#include <cutils/klog.h>
|
||||
|
@ -79,6 +81,14 @@ extern int healthd_mode_android_preparetowait(void);
|
|||
extern void healthd_mode_android_battery_update(
|
||||
struct android::BatteryProperties *props);
|
||||
|
||||
// Charger mode
|
||||
|
||||
extern void healthd_mode_charger_init(struct healthd_config *config);
|
||||
extern int healthd_mode_charger_preparetowait(void);
|
||||
extern void healthd_mode_charger_heartbeat(void);
|
||||
extern void healthd_mode_charger_battery_update(
|
||||
struct android::BatteryProperties *props);
|
||||
|
||||
// NOPs for modes that need no special action
|
||||
|
||||
static void healthd_mode_nop_init(struct healthd_config *config);
|
||||
|
@ -94,6 +104,13 @@ static struct healthd_mode_ops android_ops = {
|
|||
.battery_update = healthd_mode_android_battery_update,
|
||||
};
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
static struct healthd_mode_ops recovery_ops = {
|
||||
.init = healthd_mode_nop_init,
|
||||
.preparetowait = healthd_mode_nop_preparetowait,
|
||||
|
@ -307,15 +324,22 @@ int main(int argc, char **argv) {
|
|||
klog_set_level(KLOG_LEVEL);
|
||||
healthd_mode_ops = &android_ops;
|
||||
|
||||
while ((ch = getopt(argc, argv, "r")) != -1) {
|
||||
switch (ch) {
|
||||
case 'r':
|
||||
healthd_mode_ops = &recovery_ops;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
KLOG_ERROR(LOG_TAG, "Unrecognized healthd option: %c\n", ch);
|
||||
exit(1);
|
||||
if (!strcmp(basename(argv[0]), "charger")) {
|
||||
healthd_mode_ops = &charger_ops;
|
||||
} else {
|
||||
while ((ch = getopt(argc, argv, "cr")) != -1) {
|
||||
switch (ch) {
|
||||
case 'c':
|
||||
healthd_mode_ops = &charger_ops;
|
||||
break;
|
||||
case 'r':
|
||||
healthd_mode_ops = &recovery_ops;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
KLOG_ERROR(LOG_TAG, "Unrecognized healthd option: %c\n", ch);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -82,6 +82,14 @@ struct healthd_mode_ops {
|
|||
|
||||
extern struct healthd_mode_ops *healthd_mode_ops;
|
||||
|
||||
// Charger mode
|
||||
|
||||
void healthd_mode_charger_init(struct healthd_config *config);
|
||||
int healthd_mode_charger_preparetowait(void);
|
||||
void healthd_mode_charger_heartbeat(void);
|
||||
void healthd_mode_charger_battery_update(
|
||||
struct android::BatteryProperties *props);
|
||||
|
||||
// The following are implemented in libhealthd_board to handle board-specific
|
||||
// behavior.
|
||||
//
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
* Copyright (C) 2011-2013 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -14,9 +14,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//#define DEBUG_UEVENTS
|
||||
#define CHARGER_KLOG_LEVEL 6
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -25,7 +22,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
|
@ -35,11 +32,10 @@
|
|||
#include <sys/socket.h>
|
||||
#include <linux/netlink.h>
|
||||
|
||||
#include <batteryservice/BatteryService.h>
|
||||
#include <cutils/android_reboot.h>
|
||||
#include <cutils/klog.h>
|
||||
#include <cutils/list.h>
|
||||
#include <cutils/misc.h>
|
||||
#include <cutils/uevent.h>
|
||||
|
||||
#ifdef CHARGER_ENABLE_SUSPEND
|
||||
#include <suspend/autosuspend.h>
|
||||
|
@ -47,6 +43,8 @@
|
|||
|
||||
#include "minui/minui.h"
|
||||
|
||||
#include "healthd.h"
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
|
@ -79,15 +77,6 @@ struct key_state {
|
|||
int64_t timestamp;
|
||||
};
|
||||
|
||||
struct power_supply {
|
||||
struct listnode list;
|
||||
char name[256];
|
||||
char type[32];
|
||||
bool online;
|
||||
bool valid;
|
||||
char cap_path[PATH_MAX];
|
||||
};
|
||||
|
||||
struct frame {
|
||||
const char *name;
|
||||
int disp_time;
|
||||
|
@ -112,30 +101,17 @@ struct animation {
|
|||
};
|
||||
|
||||
struct charger {
|
||||
bool have_battery_state;
|
||||
bool charger_connected;
|
||||
int capacity;
|
||||
int64_t next_screen_transition;
|
||||
int64_t next_key_check;
|
||||
int64_t next_pwr_check;
|
||||
|
||||
struct key_state keys[KEY_MAX + 1];
|
||||
int uevent_fd;
|
||||
|
||||
struct listnode supplies;
|
||||
int num_supplies;
|
||||
int num_supplies_online;
|
||||
|
||||
struct animation *batt_anim;
|
||||
gr_surface surf_unknown;
|
||||
|
||||
struct power_supply *battery;
|
||||
};
|
||||
|
||||
struct uevent {
|
||||
const char *action;
|
||||
const char *path;
|
||||
const char *subsystem;
|
||||
const char *ps_name;
|
||||
const char *ps_type;
|
||||
const char *ps_online;
|
||||
};
|
||||
|
||||
static struct frame batt_anim_frames[] = {
|
||||
|
@ -143,44 +119,57 @@ static struct frame batt_anim_frames[] = {
|
|||
.name = "charger/battery_0",
|
||||
.disp_time = 750,
|
||||
.min_capacity = 0,
|
||||
.level_only = false,
|
||||
.surface = NULL,
|
||||
},
|
||||
{
|
||||
.name = "charger/battery_1",
|
||||
.disp_time = 750,
|
||||
.min_capacity = 20,
|
||||
.level_only = false,
|
||||
.surface = NULL,
|
||||
},
|
||||
{
|
||||
.name = "charger/battery_2",
|
||||
.disp_time = 750,
|
||||
.min_capacity = 40,
|
||||
.level_only = false,
|
||||
.surface = NULL,
|
||||
},
|
||||
{
|
||||
.name = "charger/battery_3",
|
||||
.disp_time = 750,
|
||||
.min_capacity = 60,
|
||||
.level_only = false,
|
||||
.surface = NULL,
|
||||
},
|
||||
{
|
||||
.name = "charger/battery_4",
|
||||
.disp_time = 750,
|
||||
.min_capacity = 80,
|
||||
.level_only = true,
|
||||
.surface = NULL,
|
||||
},
|
||||
{
|
||||
.name = "charger/battery_5",
|
||||
.disp_time = 750,
|
||||
.min_capacity = BATTERY_FULL_THRESH,
|
||||
.level_only = false,
|
||||
.surface = NULL,
|
||||
},
|
||||
};
|
||||
|
||||
static struct animation battery_animation = {
|
||||
.run = false,
|
||||
.frames = batt_anim_frames,
|
||||
.cur_frame = 0,
|
||||
.num_frames = ARRAY_SIZE(batt_anim_frames),
|
||||
.cur_cycle = 0,
|
||||
.num_cycles = 3,
|
||||
.capacity = 0,
|
||||
};
|
||||
|
||||
static struct charger charger_state = {
|
||||
.batt_anim = &battery_animation,
|
||||
};
|
||||
static struct charger charger_state;
|
||||
|
||||
static int char_width;
|
||||
static int char_height;
|
||||
|
@ -211,7 +200,7 @@ static void dump_last_kmsg(void)
|
|||
LOGI("\n");
|
||||
LOGI("*************** LAST KMSG ***************\n");
|
||||
LOGI("\n");
|
||||
buf = load_file(LAST_KMSG_PATH, &sz);
|
||||
buf = (char *)load_file(LAST_KMSG_PATH, &sz);
|
||||
if (!buf || !sz) {
|
||||
LOGI("last_kmsg not found. Cold reset?\n");
|
||||
goto out;
|
||||
|
@ -225,7 +214,7 @@ static void dump_last_kmsg(void)
|
|||
char yoink;
|
||||
char *nl;
|
||||
|
||||
nl = memrchr(ptr, '\n', cnt - 1);
|
||||
nl = (char *)memrchr(ptr, '\n', cnt - 1);
|
||||
if (nl)
|
||||
cnt = nl - ptr + 1;
|
||||
|
||||
|
@ -246,114 +235,9 @@ out:
|
|||
LOGI("\n");
|
||||
}
|
||||
|
||||
static int read_file(const char *path, char *buf, size_t sz)
|
||||
static int get_battery_capacity()
|
||||
{
|
||||
int fd;
|
||||
size_t cnt;
|
||||
|
||||
fd = open(path, O_RDONLY, 0);
|
||||
if (fd < 0)
|
||||
goto err;
|
||||
|
||||
cnt = read(fd, buf, sz - 1);
|
||||
if (cnt <= 0)
|
||||
goto err;
|
||||
buf[cnt] = '\0';
|
||||
if (buf[cnt - 1] == '\n') {
|
||||
cnt--;
|
||||
buf[cnt] = '\0';
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return cnt;
|
||||
|
||||
err:
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int read_file_int(const char *path, int *val)
|
||||
{
|
||||
char buf[32];
|
||||
int ret;
|
||||
int tmp;
|
||||
char *end;
|
||||
|
||||
ret = read_file(path, buf, sizeof(buf));
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
tmp = strtol(buf, &end, 0);
|
||||
if (end == buf ||
|
||||
((end < buf+sizeof(buf)) && (*end != '\n' && *end != '\0')))
|
||||
goto err;
|
||||
|
||||
*val = tmp;
|
||||
return 0;
|
||||
|
||||
err:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int get_battery_capacity(struct charger *charger)
|
||||
{
|
||||
int ret;
|
||||
int batt_cap = -1;
|
||||
|
||||
if (!charger->battery)
|
||||
return -1;
|
||||
|
||||
ret = read_file_int(charger->battery->cap_path, &batt_cap);
|
||||
if (ret < 0 || batt_cap > 100) {
|
||||
batt_cap = -1;
|
||||
}
|
||||
|
||||
return batt_cap;
|
||||
}
|
||||
|
||||
static struct power_supply *find_supply(struct charger *charger,
|
||||
const char *name)
|
||||
{
|
||||
struct listnode *node;
|
||||
struct power_supply *supply;
|
||||
|
||||
list_for_each(node, &charger->supplies) {
|
||||
supply = node_to_item(node, struct power_supply, list);
|
||||
if (!strncmp(name, supply->name, sizeof(supply->name)))
|
||||
return supply;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct power_supply *add_supply(struct charger *charger,
|
||||
const char *name, const char *type,
|
||||
const char *path, bool online)
|
||||
{
|
||||
struct power_supply *supply;
|
||||
|
||||
supply = calloc(1, sizeof(struct power_supply));
|
||||
if (!supply)
|
||||
return NULL;
|
||||
|
||||
strlcpy(supply->name, name, sizeof(supply->name));
|
||||
strlcpy(supply->type, type, sizeof(supply->type));
|
||||
snprintf(supply->cap_path, sizeof(supply->cap_path),
|
||||
"/sys/%s/capacity", path);
|
||||
supply->online = online;
|
||||
list_add_tail(&charger->supplies, &supply->list);
|
||||
charger->num_supplies++;
|
||||
LOGV("... added %s %s %d\n", supply->name, supply->type, online);
|
||||
return supply;
|
||||
}
|
||||
|
||||
static void remove_supply(struct charger *charger, struct power_supply *supply)
|
||||
{
|
||||
if (!supply)
|
||||
return;
|
||||
list_remove(&supply->list);
|
||||
charger->num_supplies--;
|
||||
free(supply);
|
||||
return charger_state.capacity;
|
||||
}
|
||||
|
||||
#ifdef CHARGER_ENABLE_SUSPEND
|
||||
|
@ -371,237 +255,6 @@ static int request_suspend(bool enable)
|
|||
}
|
||||
#endif
|
||||
|
||||
static void parse_uevent(const char *msg, struct uevent *uevent)
|
||||
{
|
||||
uevent->action = "";
|
||||
uevent->path = "";
|
||||
uevent->subsystem = "";
|
||||
uevent->ps_name = "";
|
||||
uevent->ps_online = "";
|
||||
uevent->ps_type = "";
|
||||
|
||||
/* currently ignoring SEQNUM */
|
||||
while (*msg) {
|
||||
#ifdef DEBUG_UEVENTS
|
||||
LOGV("uevent str: %s\n", msg);
|
||||
#endif
|
||||
if (!strncmp(msg, "ACTION=", 7)) {
|
||||
msg += 7;
|
||||
uevent->action = msg;
|
||||
} else if (!strncmp(msg, "DEVPATH=", 8)) {
|
||||
msg += 8;
|
||||
uevent->path = msg;
|
||||
} else if (!strncmp(msg, "SUBSYSTEM=", 10)) {
|
||||
msg += 10;
|
||||
uevent->subsystem = msg;
|
||||
} else if (!strncmp(msg, "POWER_SUPPLY_NAME=", 18)) {
|
||||
msg += 18;
|
||||
uevent->ps_name = msg;
|
||||
} else if (!strncmp(msg, "POWER_SUPPLY_ONLINE=", 20)) {
|
||||
msg += 20;
|
||||
uevent->ps_online = msg;
|
||||
} else if (!strncmp(msg, "POWER_SUPPLY_TYPE=", 18)) {
|
||||
msg += 18;
|
||||
uevent->ps_type = msg;
|
||||
}
|
||||
|
||||
/* advance to after the next \0 */
|
||||
while (*msg++)
|
||||
;
|
||||
}
|
||||
|
||||
LOGV("event { '%s', '%s', '%s', '%s', '%s', '%s' }\n",
|
||||
uevent->action, uevent->path, uevent->subsystem,
|
||||
uevent->ps_name, uevent->ps_type, uevent->ps_online);
|
||||
}
|
||||
|
||||
static void process_ps_uevent(struct charger *charger, struct uevent *uevent)
|
||||
{
|
||||
int online;
|
||||
char ps_type[32];
|
||||
struct power_supply *supply = NULL;
|
||||
int i;
|
||||
bool was_online = false;
|
||||
bool battery = false;
|
||||
|
||||
if (uevent->ps_type[0] == '\0') {
|
||||
char *path;
|
||||
int ret;
|
||||
|
||||
if (uevent->path[0] == '\0')
|
||||
return;
|
||||
ret = asprintf(&path, "/sys/%s/type", uevent->path);
|
||||
if (ret <= 0)
|
||||
return;
|
||||
ret = read_file(path, ps_type, sizeof(ps_type));
|
||||
free(path);
|
||||
if (ret < 0)
|
||||
return;
|
||||
} else {
|
||||
strlcpy(ps_type, uevent->ps_type, sizeof(ps_type));
|
||||
}
|
||||
|
||||
if (!strncmp(ps_type, "Battery", 7))
|
||||
battery = true;
|
||||
|
||||
online = atoi(uevent->ps_online);
|
||||
supply = find_supply(charger, uevent->ps_name);
|
||||
if (supply) {
|
||||
was_online = supply->online;
|
||||
supply->online = online;
|
||||
}
|
||||
|
||||
if (!strcmp(uevent->action, "add")) {
|
||||
if (!supply) {
|
||||
supply = add_supply(charger, uevent->ps_name, ps_type, uevent->path,
|
||||
online);
|
||||
if (!supply) {
|
||||
LOGE("cannot add supply '%s' (%s %d)\n", uevent->ps_name,
|
||||
uevent->ps_type, online);
|
||||
return;
|
||||
}
|
||||
/* only pick up the first battery for now */
|
||||
if (battery && !charger->battery)
|
||||
charger->battery = supply;
|
||||
} else {
|
||||
LOGE("supply '%s' already exists..\n", uevent->ps_name);
|
||||
}
|
||||
} else if (!strcmp(uevent->action, "remove")) {
|
||||
if (supply) {
|
||||
if (charger->battery == supply)
|
||||
charger->battery = NULL;
|
||||
remove_supply(charger, supply);
|
||||
supply = NULL;
|
||||
}
|
||||
} else if (!strcmp(uevent->action, "change")) {
|
||||
if (!supply) {
|
||||
LOGE("power supply '%s' not found ('%s' %d)\n",
|
||||
uevent->ps_name, ps_type, online);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
/* allow battery to be managed in the supply list but make it not
|
||||
* contribute to online power supplies. */
|
||||
if (!battery) {
|
||||
if (was_online && !online)
|
||||
charger->num_supplies_online--;
|
||||
else if (supply && !was_online && online)
|
||||
charger->num_supplies_online++;
|
||||
}
|
||||
|
||||
LOGI("power supply %s (%s) %s (action=%s num_online=%d num_supplies=%d)\n",
|
||||
uevent->ps_name, ps_type, battery ? "" : online ? "online" : "offline",
|
||||
uevent->action, charger->num_supplies_online, charger->num_supplies);
|
||||
}
|
||||
|
||||
static void process_uevent(struct charger *charger, struct uevent *uevent)
|
||||
{
|
||||
if (!strcmp(uevent->subsystem, "power_supply"))
|
||||
process_ps_uevent(charger, uevent);
|
||||
}
|
||||
|
||||
#define UEVENT_MSG_LEN 1024
|
||||
static int handle_uevent_fd(struct charger *charger, int fd)
|
||||
{
|
||||
char msg[UEVENT_MSG_LEN+2];
|
||||
int n;
|
||||
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
|
||||
while (true) {
|
||||
struct uevent uevent;
|
||||
|
||||
n = uevent_kernel_multicast_recv(fd, msg, UEVENT_MSG_LEN);
|
||||
if (n <= 0)
|
||||
break;
|
||||
if (n >= UEVENT_MSG_LEN) /* overflow -- discard */
|
||||
continue;
|
||||
|
||||
msg[n] = '\0';
|
||||
msg[n+1] = '\0';
|
||||
|
||||
parse_uevent(msg, &uevent);
|
||||
process_uevent(charger, &uevent);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uevent_callback(int fd, short revents, void *data)
|
||||
{
|
||||
struct charger *charger = data;
|
||||
|
||||
if (!(revents & POLLIN))
|
||||
return -1;
|
||||
return handle_uevent_fd(charger, fd);
|
||||
}
|
||||
|
||||
/* force the kernel to regenerate the change events for the existing
|
||||
* devices, if valid */
|
||||
static void do_coldboot(struct charger *charger, DIR *d, const char *event,
|
||||
bool follow_links, int max_depth)
|
||||
{
|
||||
struct dirent *de;
|
||||
int dfd, fd;
|
||||
|
||||
dfd = dirfd(d);
|
||||
|
||||
fd = openat(dfd, "uevent", O_WRONLY);
|
||||
if (fd >= 0) {
|
||||
write(fd, event, strlen(event));
|
||||
close(fd);
|
||||
handle_uevent_fd(charger, charger->uevent_fd);
|
||||
}
|
||||
|
||||
while ((de = readdir(d)) && max_depth > 0) {
|
||||
DIR *d2;
|
||||
|
||||
LOGV("looking at '%s'\n", de->d_name);
|
||||
|
||||
if ((de->d_type != DT_DIR && !(de->d_type == DT_LNK && follow_links)) ||
|
||||
de->d_name[0] == '.') {
|
||||
LOGV("skipping '%s' type %d (depth=%d follow=%d)\n",
|
||||
de->d_name, de->d_type, max_depth, follow_links);
|
||||
continue;
|
||||
}
|
||||
LOGV("can descend into '%s'\n", de->d_name);
|
||||
|
||||
fd = openat(dfd, de->d_name, O_RDONLY | O_DIRECTORY);
|
||||
if (fd < 0) {
|
||||
LOGE("cannot openat %d '%s' (%d: %s)\n", dfd, de->d_name,
|
||||
errno, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
|
||||
d2 = fdopendir(fd);
|
||||
if (d2 == 0)
|
||||
close(fd);
|
||||
else {
|
||||
LOGV("opened '%s'\n", de->d_name);
|
||||
do_coldboot(charger, d2, event, follow_links, max_depth - 1);
|
||||
closedir(d2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void coldboot(struct charger *charger, const char *path,
|
||||
const char *event)
|
||||
{
|
||||
char str[256];
|
||||
|
||||
LOGV("doing coldboot '%s' in '%s'\n", event, path);
|
||||
DIR *d = opendir(path);
|
||||
if (d) {
|
||||
snprintf(str, sizeof(str), "%s\n", event);
|
||||
do_coldboot(charger, d, str, true, 1);
|
||||
closedir(d);
|
||||
}
|
||||
}
|
||||
|
||||
static int draw_text(const char *str, int x, int y)
|
||||
{
|
||||
int str_len_px = gr_measure(str);
|
||||
|
@ -704,7 +357,7 @@ static void update_screen_state(struct charger *charger, int64_t now)
|
|||
charger->next_screen_transition = -1;
|
||||
gr_fb_blank(true);
|
||||
LOGV("[%lld] animation done\n", now);
|
||||
if (charger->num_supplies_online > 0)
|
||||
if (!charger->charger_connected)
|
||||
request_suspend(true);
|
||||
return;
|
||||
}
|
||||
|
@ -717,7 +370,7 @@ static void update_screen_state(struct charger *charger, int64_t now)
|
|||
int ret;
|
||||
|
||||
LOGV("[%lld] animation starting\n", now);
|
||||
batt_cap = get_battery_capacity(charger);
|
||||
batt_cap = get_battery_capacity();
|
||||
if (batt_cap >= 0 && batt_anim->num_frames != 0) {
|
||||
int i;
|
||||
|
||||
|
@ -778,7 +431,7 @@ static void update_screen_state(struct charger *charger, int64_t now)
|
|||
|
||||
static int set_key_callback(int code, int value, void *data)
|
||||
{
|
||||
struct charger *charger = data;
|
||||
struct charger *charger = (struct charger *)data;
|
||||
int64_t now = curr_time_ms();
|
||||
int down = !!value;
|
||||
|
||||
|
@ -865,7 +518,10 @@ static void handle_input_state(struct charger *charger, int64_t now)
|
|||
|
||||
static void handle_power_supply_state(struct charger *charger, int64_t now)
|
||||
{
|
||||
if (charger->num_supplies_online == 0) {
|
||||
if (!charger->have_battery_state)
|
||||
return;
|
||||
|
||||
if (!charger->charger_connected) {
|
||||
request_suspend(false);
|
||||
if (charger->next_pwr_check == -1) {
|
||||
charger->next_pwr_check = now + UNPLUGGED_SHUTDOWN_TIME;
|
||||
|
@ -887,8 +543,43 @@ static void handle_power_supply_state(struct charger *charger, int64_t now)
|
|||
}
|
||||
}
|
||||
|
||||
static void wait_next_event(struct charger *charger, int64_t now)
|
||||
void healthd_mode_charger_heartbeat()
|
||||
{
|
||||
struct charger *charger = &charger_state;
|
||||
int64_t now = curr_time_ms();
|
||||
int ret;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void healthd_mode_charger_battery_update(
|
||||
struct android::BatteryProperties *props)
|
||||
{
|
||||
struct charger *charger = &charger_state;
|
||||
|
||||
charger->charger_connected =
|
||||
props->chargerAcOnline || props->chargerUsbOnline ||
|
||||
props->chargerWirelessOnline;
|
||||
charger->capacity = props->batteryLevel;
|
||||
|
||||
if (!charger->have_battery_state) {
|
||||
charger->have_battery_state = true;
|
||||
charger->next_screen_transition = curr_time_ms() - 1;
|
||||
reset_animation(charger->batt_anim);
|
||||
kick_animation(charger->batt_anim);
|
||||
}
|
||||
}
|
||||
|
||||
int healthd_mode_charger_preparetowait(void)
|
||||
{
|
||||
struct charger *charger = &charger_state;
|
||||
int64_t now = curr_time_ms();
|
||||
int64_t next_event = INT64_MAX;
|
||||
int64_t timeout;
|
||||
struct input_event ev;
|
||||
|
@ -909,57 +600,38 @@ static void wait_next_event(struct charger *charger, int64_t now)
|
|||
timeout = max(0, next_event - now);
|
||||
else
|
||||
timeout = -1;
|
||||
LOGV("[%lld] blocking (%lld)\n", now, timeout);
|
||||
ret = ev_wait((int)timeout);
|
||||
if (!ret)
|
||||
ev_dispatch();
|
||||
|
||||
return (int)timeout;
|
||||
}
|
||||
|
||||
static int input_callback(int fd, short revents, void *data)
|
||||
static int input_callback(int fd, unsigned int epevents, void *data)
|
||||
{
|
||||
struct charger *charger = data;
|
||||
struct charger *charger = (struct charger *)data;
|
||||
struct input_event ev;
|
||||
int ret;
|
||||
|
||||
ret = ev_get_input(fd, revents, &ev);
|
||||
ret = ev_get_input(fd, epevents, &ev);
|
||||
if (ret)
|
||||
return -1;
|
||||
update_input_state(charger, &ev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void event_loop(struct charger *charger)
|
||||
static void charger_event_handler(uint32_t epevents)
|
||||
{
|
||||
int ret;
|
||||
|
||||
while (true) {
|
||||
int64_t now = curr_time_ms();
|
||||
|
||||
LOGV("[%lld] event_loop()\n", now);
|
||||
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);
|
||||
|
||||
wait_next_event(charger, now);
|
||||
}
|
||||
ret = ev_wait(-1);
|
||||
if (!ret)
|
||||
ev_dispatch();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
void healthd_mode_charger_init(struct healthd_config *config)
|
||||
{
|
||||
int ret;
|
||||
struct charger *charger = &charger_state;
|
||||
int64_t now = curr_time_ms() - 1;
|
||||
int fd;
|
||||
int i;
|
||||
|
||||
list_init(&charger->supplies);
|
||||
|
||||
klog_init();
|
||||
klog_set_level(CHARGER_KLOG_LEVEL);
|
||||
int epollfd;
|
||||
|
||||
dump_last_kmsg();
|
||||
|
||||
|
@ -968,15 +640,11 @@ int main(int argc, char **argv)
|
|||
gr_init();
|
||||
gr_font_size(&char_width, &char_height);
|
||||
|
||||
ev_init(input_callback, charger);
|
||||
|
||||
fd = uevent_open_socket(64*1024, true);
|
||||
if (fd >= 0) {
|
||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
||||
ev_add_fd(fd, uevent_callback, charger);
|
||||
ret = ev_init(input_callback, charger);
|
||||
if (!ret) {
|
||||
epollfd = ev_get_epollfd();
|
||||
healthd_register_event(epollfd, charger_event_handler);
|
||||
}
|
||||
charger->uevent_fd = fd;
|
||||
coldboot(charger, "/sys/class/power_supply", "add");
|
||||
|
||||
ret = res_create_surface("charger/battery_fail", &charger->surf_unknown);
|
||||
if (ret < 0) {
|
||||
|
@ -984,6 +652,8 @@ int main(int argc, char **argv)
|
|||
charger->surf_unknown = NULL;
|
||||
}
|
||||
|
||||
charger->batt_anim = &battery_animation;
|
||||
|
||||
for (i = 0; i < charger->batt_anim->num_frames; i++) {
|
||||
struct frame *frame = &charger->batt_anim->frames[i];
|
||||
|
||||
|
@ -1003,13 +673,7 @@ int main(int argc, char **argv)
|
|||
gr_fb_blank(true);
|
||||
#endif
|
||||
|
||||
charger->next_screen_transition = now - 1;
|
||||
charger->next_screen_transition = -1;
|
||||
charger->next_key_check = -1;
|
||||
charger->next_pwr_check = -1;
|
||||
reset_animation(charger->batt_anim);
|
||||
kick_animation(charger->batt_anim);
|
||||
|
||||
event_loop(charger);
|
||||
|
||||
return 0;
|
||||
}
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
@ -255,7 +255,6 @@ static const struct fs_path_config android_files[] = {
|
|||
{ 00750, AID_ROOT, AID_SHELL, 0, "sbin/*" },
|
||||
{ 00755, AID_ROOT, AID_ROOT, 0, "bin/*" },
|
||||
{ 00750, AID_ROOT, AID_SHELL, 0, "init*" },
|
||||
{ 00750, AID_ROOT, AID_SHELL, 0, "charger*" },
|
||||
{ 00750, AID_ROOT, AID_SHELL, 0, "sbin/fs_mgr" },
|
||||
{ 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" },
|
||||
{ 00644, AID_ROOT, AID_ROOT, 0, 0 },
|
||||
|
|