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

Commit bd542030 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "healthd: clean up unused code"

parents f863aef5 25eb37a8
Loading
Loading
Loading
Loading
+0 −2
Original line number Original line Diff line number Diff line
@@ -27,8 +27,6 @@ cc_library_static {
        "healthd_common.cpp",
        "healthd_common.cpp",
    ],
    ],


    cflags: ["-DHEALTHD_USE_HEALTH_2_0"],

    export_include_dirs: ["include"],
    export_include_dirs: ["include"],


    shared_libs: [
    shared_libs: [
+0 −6
Original line number Original line Diff line number Diff line
@@ -89,12 +89,6 @@ LOCAL_CFLAGS := -Werror
ifeq ($(strip $(LOCAL_CHARGER_NO_UI)),true)
ifeq ($(strip $(LOCAL_CHARGER_NO_UI)),true)
LOCAL_CFLAGS += -DCHARGER_NO_UI
LOCAL_CFLAGS += -DCHARGER_NO_UI
endif
endif
ifneq ($(BOARD_PERIODIC_CHORES_INTERVAL_FAST),)
LOCAL_CFLAGS += -DBOARD_PERIODIC_CHORES_INTERVAL_FAST=$(BOARD_PERIODIC_CHORES_INTERVAL_FAST)
endif
ifneq ($(BOARD_PERIODIC_CHORES_INTERVAL_SLOW),)
LOCAL_CFLAGS += -DBOARD_PERIODIC_CHORES_INTERVAL_SLOW=$(BOARD_PERIODIC_CHORES_INTERVAL_SLOW)
endif


CHARGER_STATIC_LIBRARIES := \
CHARGER_STATIC_LIBRARIES := \
    android.hardware.health@2.0-impl \
    android.hardware.health@2.0-impl \
+14 −7
Original line number Original line Diff line number Diff line
@@ -27,7 +27,7 @@
#include <thread>
#include <thread>
#include <vector>
#include <vector>


#include <healthd/healthd.h>
#include <health2/Health.h>


#define LOG_THIS(fmt, ...)     \
#define LOG_THIS(fmt, ...)     \
    ALOGE(fmt, ##__VA_ARGS__); \
    ALOGE(fmt, ##__VA_ARGS__); \
@@ -97,6 +97,16 @@ int expectContains(const std::string& content, const std::vector<std::string>& f
    return status;
    return status;
}
}


::android::hardware::hidl_handle createHidlHandle(const char* filepath) {
    int fd = creat(filepath, S_IRUSR | S_IWUSR);
    if (fd < 0) return {};
    native_handle_t* nativeHandle = native_handle_create(1, 0);
    nativeHandle->data[0] = fd;
    ::android::hardware::hidl_handle handle;
    handle.setTo(nativeHandle, true /* shouldOwn */);
    return handle;
}

void healthd_board_init(struct healthd_config* config) {
void healthd_board_init(struct healthd_config* config) {
    config->periodic_chores_interval_fast = 60;
    config->periodic_chores_interval_fast = 60;
    config->periodic_chores_interval_slow = 600;
    config->periodic_chores_interval_slow = 600;
@@ -129,6 +139,8 @@ int healthd_board_battery_update(struct android::BatteryProperties*) {
extern int healthd_charger_main(int argc, char** argv);
extern int healthd_charger_main(int argc, char** argv);


int main(int argc, char** argv) {
int main(int argc, char** argv) {
    using android::hardware::health::V2_0::implementation::Health;

    const char* dumpFile = "/data/local/tmp/dump.txt";
    const char* dumpFile = "/data/local/tmp/dump.txt";


    std::thread bgThread([=] {
    std::thread bgThread([=] {
@@ -141,12 +153,7 @@ int main(int argc, char** argv) {
        exit(1);
        exit(1);
    }
    }


    int fd = creat(dumpFile, S_IRUSR | S_IWUSR);
    Health::getImplementation()->debug(createHidlHandle(dumpFile), {} /* options */);
    if (fd < 0) {
        exit(errno);
    }
    healthd_dump_battery_state(fd);
    close(fd);


    std::string content = openToString(dumpFile);
    std::string content = openToString(dumpFile);
    int status = expectContains(content, {
    int status = expectContains(content, {
+5 −124
Original line number Original line Diff line number Diff line
@@ -33,25 +33,14 @@
#include <sys/timerfd.h>
#include <sys/timerfd.h>
#include <utils/Errors.h>
#include <utils/Errors.h>


#ifdef HEALTHD_USE_HEALTH_2_0
#include <health2/Health.h>
#include <health2/Health.h>
#endif


using namespace android;
using namespace android;


#ifndef BOARD_PERIODIC_CHORES_INTERVAL_FAST
// Periodic chores fast interval in seconds
// Periodic chores fast interval in seconds
#define DEFAULT_PERIODIC_CHORES_INTERVAL_FAST (60 * 1)
#define DEFAULT_PERIODIC_CHORES_INTERVAL_FAST (60 * 1)
#else
  #define DEFAULT_PERIODIC_CHORES_INTERVAL_FAST (BOARD_PERIODIC_CHORES_INTERVAL_FAST)
#endif

#ifndef BOARD_PERIODIC_CHORES_INTERVAL_SLOW
// Periodic chores fast interval in seconds
// Periodic chores fast interval in seconds
#define DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW (60 * 10)
#define DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW (60 * 10)
#else
  #define DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW (BOARD_PERIODIC_CHORES_INTERVAL_SLOW)
#endif


static struct healthd_config healthd_config = {
static struct healthd_config healthd_config = {
    .periodic_chores_interval_fast = DEFAULT_PERIODIC_CHORES_INTERVAL_FAST,
    .periodic_chores_interval_fast = DEFAULT_PERIODIC_CHORES_INTERVAL_FAST,
@@ -88,11 +77,7 @@ static int awake_poll_interval = -1;


static int wakealarm_wake_interval = DEFAULT_PERIODIC_CHORES_INTERVAL_FAST;
static int wakealarm_wake_interval = DEFAULT_PERIODIC_CHORES_INTERVAL_FAST;


#ifndef HEALTHD_USE_HEALTH_2_0
static BatteryMonitor* gBatteryMonitor = nullptr;
#else
using ::android::hardware::health::V2_0::implementation::Health;
using ::android::hardware::health::V2_0::implementation::Health;
#endif


struct healthd_mode_ops *healthd_mode_ops = nullptr;
struct healthd_mode_ops *healthd_mode_ops = nullptr;


@@ -135,81 +120,6 @@ static void wakealarm_set_interval(int interval) {
        KLOG_ERROR(LOG_TAG, "wakealarm_set_interval: timerfd_settime failed\n");
        KLOG_ERROR(LOG_TAG, "wakealarm_set_interval: timerfd_settime failed\n");
}
}


#ifdef HEALTHD_USE_HEALTH_2_0
status_t convertStatus(android::hardware::health::V2_0::Result r) {
    using android::hardware::health::V2_0::Result;
    switch(r) {
        case Result::SUCCESS:       return OK;
        case Result::NOT_SUPPORTED: return BAD_VALUE;
        case Result::NOT_FOUND:     return NAME_NOT_FOUND;
        case Result::CALLBACK_DIED: return DEAD_OBJECT;
        case Result::UNKNOWN: // fallthrough
        default:
            return UNKNOWN_ERROR;
    }
}
#endif

status_t healthd_get_property(int id, struct BatteryProperty *val) {
#ifndef HEALTHD_USE_HEALTH_2_0
    return gBatteryMonitor->getProperty(id, val);
#else
    using android::hardware::health::V1_0::BatteryStatus;
    using android::hardware::health::V2_0::Result;
    val->valueInt64 = INT64_MIN;
    status_t err = UNKNOWN_ERROR;
    switch (id) {
        case BATTERY_PROP_CHARGE_COUNTER: {
            Health::getImplementation()->getChargeCounter([&](Result r, int32_t v) {
                err = convertStatus(r);
                val->valueInt64 = v;
            });
            break;
        }
        case BATTERY_PROP_CURRENT_NOW: {
            Health::getImplementation()->getCurrentNow([&](Result r, int32_t v) {
                err = convertStatus(r);
                val->valueInt64 = v;
            });
            break;
        }
        case BATTERY_PROP_CURRENT_AVG: {
            Health::getImplementation()->getCurrentAverage([&](Result r, int32_t v) {
                err = convertStatus(r);
                val->valueInt64 = v;
            });
            break;
        }
        case BATTERY_PROP_CAPACITY: {
            Health::getImplementation()->getCapacity([&](Result r, int32_t v) {
                err = convertStatus(r);
                val->valueInt64 = v;
            });
            break;
        }
        case BATTERY_PROP_ENERGY_COUNTER: {
            Health::getImplementation()->getEnergyCounter([&](Result r, int64_t v) {
                err = convertStatus(r);
                val->valueInt64 = v;
            });
            break;
        }
        case BATTERY_PROP_BATTERY_STATUS: {
            Health::getImplementation()->getChargeStatus([&](Result r, BatteryStatus v) {
                err = convertStatus(r);
                val->valueInt64 = static_cast<int64_t>(v);
            });
            break;
        }
        default: {
            err = BAD_VALUE;
            break;
        }
    }
    return err;
#endif
}

void healthd_battery_update_internal(bool charger_online) {
void healthd_battery_update_internal(bool charger_online) {
    // Fast wake interval when on charger (watch for overheat);
    // Fast wake interval when on charger (watch for overheat);
    // slow wake interval when on battery (watch for drained battery).
    // slow wake interval when on battery (watch for drained battery).
@@ -233,26 +143,8 @@ void healthd_battery_update_internal(bool charger_online) {
                -1 : healthd_config.periodic_chores_interval_fast * 1000;
                -1 : healthd_config.periodic_chores_interval_fast * 1000;
}
}


void healthd_battery_update(void) {
static void healthd_battery_update(void) {
#ifndef HEALTHD_USE_HEALTH_2_0
    healthd_battery_update_internal(gBatteryMonitor->update());
#else
    Health::getImplementation()->update();
    Health::getImplementation()->update();
#endif
}

void healthd_dump_battery_state(int fd) {
#ifndef HEALTHD_USE_HEALTH_2_0
    gBatteryMonitor->dumpState(fd);
#else
    native_handle_t* nativeHandle = native_handle_create(1, 0);
    nativeHandle->data[0] = fd;
    ::android::hardware::hidl_handle handle;
    handle.setTo(nativeHandle, true /* shouldOwn */);
    Health::getImplementation()->debug(handle, {} /* options */);
#endif

    fsync(fd);
}
}


static void periodic_chores() {
static void periodic_chores() {
@@ -368,21 +260,10 @@ static int healthd_init() {
        return -1;
        return -1;
    }
    }


#ifndef HEALTHD_USE_HEALTH_2_0
    healthd_board_init(&healthd_config);
#else
    // healthd_board_* functions are removed in health@2.0
#endif

    healthd_mode_ops->init(&healthd_config);
    healthd_mode_ops->init(&healthd_config);
    wakealarm_init();
    wakealarm_init();
    uevent_init();
    uevent_init();


#ifndef HEALTHD_USE_HEALTH_2_0
    gBatteryMonitor = new BatteryMonitor();
    gBatteryMonitor->init(&healthd_config);
#endif

    return 0;
    return 0;
}
}


+0 −9
Original line number Original line Diff line number Diff line
@@ -81,15 +81,6 @@ enum EventWakeup {
// Global helper functions
// Global helper functions


int healthd_register_event(int fd, void (*handler)(uint32_t), EventWakeup wakeup = EVENT_NO_WAKEUP_FD);
int healthd_register_event(int fd, void (*handler)(uint32_t), EventWakeup wakeup = EVENT_NO_WAKEUP_FD);
void healthd_battery_update();

// deprecated.
// TODO(b/62229583): This function should be removed since it is only used by
// BatteryPropertiesRegistrar.
android::status_t healthd_get_property(int id,
    struct android::BatteryProperty *val);

void healthd_dump_battery_state(int fd);


struct healthd_mode_ops {
struct healthd_mode_ops {
    void (*init)(struct healthd_config *config);
    void (*init)(struct healthd_config *config);