healthd: Add charger.recovery module.

This CL splits out healthd_mode_charger_nops for building
charger.recovery. It doesn't change the functionality of the charger
module under recovery, i.e. a) it still doesn't do much work other than
reporting the battery status periodically; b) it keeps calling
device-specific healthd functions (healthd_board_init and
healthd_board_battery_update) via the statically linked HAL.

Previously `charger -r` was used to indicate starting charger under
recovery mode. This CL makes it a noop since we've changed the caller in
recovery.

Bug: 73660730
Bug: 114042635
Test: Boot into charger mode on walleye. Check that charger UI works.
Test: Boot into recovery mode on walleye. Check that /system/bin/charger
      keeps working.
Test: Run charger_test on walleye.
Change-Id: Id91acfcc77ec315c2382392dc54e36c3e85de2eb
This commit is contained in:
Tao Bao 2018-09-11 10:46:35 -07:00
parent f2455d8068
commit 5747e228f7
7 changed files with 213 additions and 99 deletions

View file

@ -84,3 +84,29 @@ cc_binary {
"manifest_healthd.xml"
],
}
cc_library_static {
name: "libhealthd_charger_nops",
srcs: [
"healthd_mode_charger_nops.cpp",
],
cflags: [
"-Wall",
"-Werror",
],
header_libs: [
"libhealthd_headers",
],
static_libs: [
"android.hardware.health@2.0-impl",
],
shared_libs: [
"android.hardware.health@2.0",
"libutils",
],
}

View file

@ -97,6 +97,7 @@ CHARGER_STATIC_LIBRARIES := \
libhealthstoragedefault \
libvndksupport \
libhealthd_charger \
libhealthd_charger_nops \
libhealthd_draw \
libbatterymonitor \
@ -107,20 +108,20 @@ CHARGER_SHARED_LIBRARIES := \
libjsoncpp \
libprocessgroup \
liblog \
libpng \
libutils \
LOCAL_STATIC_LIBRARIES := $(CHARGER_STATIC_LIBRARIES)
LOCAL_SHARED_LIBRARIES := $(CHARGER_SHARED_LIBRARIES)
ifneq ($(strip $(LOCAL_CHARGER_NO_UI)),true)
LOCAL_STATIC_LIBRARIES += libminui
CHARGER_STATIC_LIBRARIES += libminui
CHARGER_SHARED_LIBRARIES += libpng
endif
ifeq ($(strip $(BOARD_CHARGER_ENABLE_SUSPEND)),true)
LOCAL_SHARED_LIBRARIES += libsuspend
CHARGER_SHARED_LIBRARIES += libsuspend
endif
LOCAL_STATIC_LIBRARIES := $(CHARGER_STATIC_LIBRARIES)
LOCAL_SHARED_LIBRARIES := $(CHARGER_SHARED_LIBRARIES)
LOCAL_HAL_STATIC_LIBRARIES := libhealthd
# Symlink /charger to /system/bin/charger
@ -129,15 +130,56 @@ LOCAL_POST_INSTALL_CMD := $(hide) mkdir -p $(TARGET_ROOT_OUT) \
include $(BUILD_EXECUTABLE)
### charger.recovery ###
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
charger.cpp \
LOCAL_MODULE := charger.recovery
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/bin
LOCAL_MODULE_STEM := charger
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_CFLAGS := -Wall -Werror
LOCAL_CFLAGS += -DCHARGER_NO_UI
# charger.recovery doesn't link against libhealthd_{charger,draw} or libminui, since it doesn't need
# any UI support.
LOCAL_STATIC_LIBRARIES := \
android.hardware.health@2.0-impl \
android.hardware.health@1.0-convert \
libbinderthreadstate \
libhidltransport \
libhidlbase \
libhwbinder_noltopgo \
libhealthstoragedefault \
libvndksupport \
libhealthd_charger_nops \
libbatterymonitor \
# These shared libs will be installed to recovery image because of the dependency in `recovery`
# module.
LOCAL_SHARED_LIBRARIES := \
android.hardware.health@2.0 \
libbase \
libcutils \
liblog \
libutils \
# The use of LOCAL_HAL_STATIC_LIBRARIES prevents from building this module with Android.bp.
LOCAL_HAL_STATIC_LIBRARIES := libhealthd
include $(BUILD_EXECUTABLE)
### charger_test ###
include $(CLEAR_VARS)
LOCAL_MODULE := charger_test
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_CFLAGS := -Wall -Werror -DCHARGER_TEST -DCHARGER_NO_UI
LOCAL_CFLAGS := -Wall -Werror -DCHARGER_NO_UI
LOCAL_STATIC_LIBRARIES := $(CHARGER_STATIC_LIBRARIES)
LOCAL_SHARED_LIBRARIES := $(CHARGER_SHARED_LIBRARIES)
LOCAL_SRC_FILES := \
charger.cpp \
charger_test.cpp \
include $(BUILD_EXECUTABLE)

View file

@ -14,98 +14,13 @@
* limitations under the License.
*/
#define LOG_TAG "charger"
#define KLOG_LEVEL 6
#include "healthd_mode_charger.h"
#include "healthd_mode_charger_nops.h"
#include <health2/Health.h>
#include <healthd/healthd.h>
#include <stdlib.h>
#include <string.h>
#include <cutils/klog.h>
using namespace android;
// main healthd loop
extern int healthd_main(void);
// 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);
static int healthd_mode_nop_preparetowait(void);
static void healthd_mode_nop_heartbeat(void);
static void healthd_mode_nop_battery_update(
struct android::BatteryProperties *props);
static struct healthd_mode_ops healthd_nops = {
.init = healthd_mode_nop_init,
.preparetowait = healthd_mode_nop_preparetowait,
.heartbeat = healthd_mode_nop_heartbeat,
.battery_update = healthd_mode_nop_battery_update,
};
#ifdef CHARGER_NO_UI
static struct healthd_mode_ops charger_ops = healthd_nops;
#else
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,
};
#endif
static void healthd_mode_nop_init(struct healthd_config* config) {
using android::hardware::health::V2_0::implementation::Health;
Health::initInstance(config);
}
static int healthd_mode_nop_preparetowait(void) {
return -1;
}
static void healthd_mode_nop_heartbeat(void) {
}
static void healthd_mode_nop_battery_update(
struct android::BatteryProperties* /*props*/) {
}
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':
// force nops for recovery
healthd_mode_ops = &healthd_nops;
break;
case '?':
default:
KLOG_ERROR(LOG_TAG, "Unrecognized charger option: %c\n",
optopt);
exit(1);
}
}
return healthd_main();
}
#ifndef CHARGER_TEST
int main(int argc, char** argv) {
#ifdef CHARGER_NO_UI
return healthd_charger_nops(argc, argv);
#else
return healthd_charger_main(argc, argv);
}
#endif
}

View file

@ -54,6 +54,9 @@
using namespace android;
// main healthd loop
extern int healthd_main(void);
char* locale;
#ifndef max
@ -711,3 +714,33 @@ void healthd_mode_charger_init(struct healthd_config* config) {
healthd_config = config;
charger->boot_min_cap = config->boot_min_cap;
}
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();
}

View file

@ -0,0 +1,19 @@
/*
* Copyright (C) 2019 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.
* 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.
*/
#pragma once
int healthd_charger_main(int argc, char** argv);

View file

@ -0,0 +1,60 @@
/*
* Copyright (C) 2019 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.
* 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 "healthd_mode_charger_nops.h"
#include <health2/Health.h>
#include <healthd/healthd.h>
#include <stdlib.h>
#include <string.h>
using namespace android;
// main healthd loop
extern int healthd_main(void);
// NOPs for modes that need no special action
static void healthd_mode_nop_init(struct healthd_config* config);
static int healthd_mode_nop_preparetowait(void);
static void healthd_mode_nop_heartbeat(void);
static void healthd_mode_nop_battery_update(struct android::BatteryProperties* props);
static struct healthd_mode_ops healthd_nops = {
.init = healthd_mode_nop_init,
.preparetowait = healthd_mode_nop_preparetowait,
.heartbeat = healthd_mode_nop_heartbeat,
.battery_update = healthd_mode_nop_battery_update,
};
static void healthd_mode_nop_init(struct healthd_config* config) {
using android::hardware::health::V2_0::implementation::Health;
Health::initInstance(config);
}
static int healthd_mode_nop_preparetowait(void) {
return -1;
}
static void healthd_mode_nop_heartbeat(void) {}
static void healthd_mode_nop_battery_update(struct android::BatteryProperties* /*props*/) {}
int healthd_charger_nops(int /* argc */, char** /* argv */) {
healthd_mode_ops = &healthd_nops;
return healthd_main();
}

View file

@ -0,0 +1,19 @@
/*
* Copyright (C) 2019 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.
* 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.
*/
#pragma once
int healthd_charger_nops(int argc, char** argv);