Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit daabad7c authored by Yifan Hong's avatar Yifan Hong Committed by Gerrit Code Review
Browse files

Merge "healthd: Remove libhealthd dependency from charger"

parents 7933195a 7dcf7b06
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -88,3 +88,4 @@ $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/product_services)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/root/product_services)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/recovery/root/product_services)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/debug_ramdisk/product_services)
$(call add-clean-step, find $(PRODUCT_OUT) -type l -name "charger" -print0 | xargs -0 rm -f)
+81 −5
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ cc_binary {

cc_library_static {
    name: "libhealthd_charger_nops",
    recovery_available: true,

    srcs: [
        "healthd_mode_charger_nops.cpp",
@@ -104,17 +105,19 @@ cc_library_static {
    ],

    static_libs: [
        "android.hardware.health@2.0-impl",
        "libhealthloop",
        "libhealth2impl",
    ],

    shared_libs: [
        "android.hardware.health@2.0",
        "android.hardware.health@2.1",
        "libutils",
    ],
}

sysprop_library {
    name: "charger_sysprop",
    recovery_available: true,
    srcs: ["charger.sysprop"],
    property_owner: "Platform",
    api_packages: ["android.sysprop"],
@@ -141,16 +144,16 @@ cc_library_static {
    export_include_dirs: [".", "include"],

    static_libs: [
        "android.hardware.health@2.0-impl",
        "android.hardware.health@1.0-convert",
        "libcharger_sysprop",
        "libhealthstoragedefault",
        "libhealthd_draw",
        "libhealthloop",
        "libhealth2impl",
        "libminui",
    ],

    shared_libs: [
        "android.hardware.health@2.0",
        "android.hardware.health@2.1",
        "libbase",
        "libcutils",
        "liblog",
@@ -164,3 +167,76 @@ cc_library_static {
        "AnimationParser.cpp",
    ],
}

cc_defaults {
    name: "charger_defaults",

    cflags: [
        "-Wall",
        "-Werror",
    ],

    shared_libs: [
        // common
        "android.hardware.health@2.0",
        "android.hardware.health@2.1",
        "libbase",
        "libcutils",
        "libhidlbase",
        "liblog",
        "libutils",

        // system charger only
        "libpng",
    ],

    static_libs: [
        // common
        "android.hardware.health@1.0-convert",
        "libbatterymonitor",
        "libcharger_sysprop",
        "libhealthd_charger_nops",
        "libhealthloop",
        "libhealth2impl",

        // system charger only
        "libhealthd_draw",
        "libhealthd_charger",
        "libminui",
        "libsuspend",
    ],
}

cc_binary {
    name: "charger",
    defaults: ["charger_defaults"],
    recovery_available: true,
    srcs: [
        "charger.cpp",
        "charger_utils.cpp",
    ],

    target: {
        recovery: {
            // No UI and libsuspend for recovery charger.
            cflags: [
                "-DCHARGER_FORCE_NO_UI=1",
            ],
            exclude_shared_libs: [
                "libpng",
            ],
            exclude_static_libs: [
                "libhealthd_draw",
                "libhealthd_charger",
                "libminui",
                "libsuspend",
            ],
        }
    }
}

cc_test {
    name: "charger_test",
    defaults: ["charger_defaults"],
    srcs: ["charger_test.cpp"],
}
+0 −102
Original line number Diff line number Diff line
@@ -2,112 +2,10 @@

LOCAL_PATH := $(call my-dir)

### charger ###
include $(CLEAR_VARS)
ifeq ($(strip $(BOARD_CHARGER_NO_UI)),true)
LOCAL_CHARGER_NO_UI := true
endif

LOCAL_SRC_FILES := \
    charger.cpp \

LOCAL_MODULE := charger
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include

LOCAL_CFLAGS := -Werror

CHARGER_STATIC_LIBRARIES := \
    android.hardware.health@2.0-impl \
    android.hardware.health@1.0-convert \
    libbinderthreadstate \
    libcharger_sysprop \
    libhidlbase \
    libhealthstoragedefault \
    libminui \
    libvndksupport \
    libhealthd_charger \
    libhealthd_charger_nops \
    libhealthd_draw \
    libbatterymonitor \

CHARGER_SHARED_LIBRARIES := \
    android.hardware.health@2.0 \
    libbase \
    libcutils \
    libjsoncpp \
    libpng \
    libprocessgroup \
    liblog \
    libutils \

CHARGER_SHARED_LIBRARIES += libsuspend

LOCAL_STATIC_LIBRARIES := $(CHARGER_STATIC_LIBRARIES)
LOCAL_SHARED_LIBRARIES := $(CHARGER_SHARED_LIBRARIES)

LOCAL_HAL_STATIC_LIBRARIES := libhealthd

# Symlink /charger to /system/bin/charger
LOCAL_POST_INSTALL_CMD := $(hide) mkdir -p $(TARGET_ROOT_OUT) \
    && ln -sf /system/bin/charger $(TARGET_ROOT_OUT)/charger

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 -DCHARGER_FORCE_NO_UI=1

# 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 \
    libcharger_sysprop \
    libhidlbase \
    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
LOCAL_STATIC_LIBRARIES := $(CHARGER_STATIC_LIBRARIES)
LOCAL_SHARED_LIBRARIES := $(CHARGER_SHARED_LIBRARIES)
LOCAL_SRC_FILES := \
    charger_test.cpp \

include $(BUILD_EXECUTABLE)

CHARGER_STATIC_LIBRARIES :=
CHARGER_SHARED_LIBRARIES :=

### charger_res_images ###
ifneq ($(strip $(LOCAL_CHARGER_NO_UI)),true)
define _add-charger-image
+3 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ struct animation {

    bool run;

    frame* frames;
    frame* frames = nullptr;
    int cur_frame;
    int num_frames;
    int first_frame_repeats;  // Number of times to repeat the first frame in the current cycle
@@ -85,6 +85,8 @@ struct animation {

    int cur_level;  // current battery level being animated (0-100)
    int cur_status;  // current battery status - see BatteryService.h for BATTERY_STATUS_*

    ~animation() { delete frames; }
};

}
+24 −14
Original line number Diff line number Diff line
@@ -21,13 +21,22 @@
#include <condition_variable>
#include <fstream>
#include <iostream>
#include <memory>
#include <mutex>
#include <streambuf>
#include <string>
#include <thread>
#include <vector>

#include <health2/Health.h>
#include <health/utils.h>
#include <health2impl/Health.h>

#include "healthd_mode_charger.h"

using android::hardware::health::InitHealthdConfig;
using android::hardware::health::V2_1::HealthInfo;
using android::hardware::health::V2_1::IHealth;
using android::hardware::health::V2_1::implementation::Health;

#define LOG_THIS(fmt, ...)     \
    ALOGE(fmt, ##__VA_ARGS__); \
@@ -129,22 +138,23 @@ void healthd_board_init(struct healthd_config* config) {
    config->screen_on = NULL;
}

int healthd_board_battery_update(struct android::BatteryProperties*) {
    getUpdateNotifier().set(true /* updated */);

    // return 0 to log periodic polled battery status to kernel log
    return 0;
}

extern int healthd_charger_main(int argc, char** argv);

int main(int argc, char** argv) {
    using android::hardware::health::V2_0::implementation::Health;
class TestHealth : public Health {
  protected:
    using Health::Health;
    void UpdateHealthInfo(HealthInfo*) override { getUpdateNotifier().set(true /* updated */); }
};

int main(int /*argc*/, char** /*argv*/) {
    const char* dumpFile = "/data/local/tmp/dump.txt";

    auto config = std::make_unique<healthd_config>();
    InitHealthdConfig(config.get());
    healthd_board_init(config.get());
    sp<IHealth> passthrough = new TestHealth(std::move(config));

    std::thread bgThread([=] {
        healthd_charger_main(argc, argv);
        android::Charger charger(passthrough);
        charger.StartLoop();
    });

    // wait for healthd_init to finish
@@ -153,7 +163,7 @@ int main(int argc, char** argv) {
        exit(1);
    }

    Health::getImplementation()->debug(createHidlHandle(dumpFile), {} /* options */);
    passthrough->debug(createHidlHandle(dumpFile), {} /* options */);

    std::string content = openToString(dumpFile);
    int status = expectContains(content, {
Loading