Skip to content

Commit

Permalink
healthd: dock battery
Browse files Browse the repository at this point in the history
Change-Id: I2ad09e5e87d55c47af4d1efc14cc585cc08e2dce
Require: topic:dock_battery
Signed-off-by: Jorge Ruesga <[email protected]>
  • Loading branch information
jruesga authored and Steve Kondik committed Sep 3, 2016
1 parent 18248b1 commit 3a66fa1
Show file tree
Hide file tree
Showing 7 changed files with 395 additions and 87 deletions.
416 changes: 330 additions & 86 deletions healthd/BatteryMonitor.cpp

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions healthd/BatteryPropertiesRegistrar.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2015 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -77,6 +78,10 @@ status_t BatteryPropertiesRegistrar::getProperty(int id, struct BatteryProperty
return healthd_get_property(id, val);
}

status_t BatteryPropertiesRegistrar::getDockProperty(int id, struct BatteryProperty *val) {
return healthd_get_dock_property(id, val);
}

status_t BatteryPropertiesRegistrar::dump(int fd, const Vector<String16>& /*args*/) {
IPCThreadState* self = IPCThreadState::self();
const int pid = self->getCallingPid();
Expand Down
2 changes: 2 additions & 0 deletions healthd/BatteryPropertiesRegistrar.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2015 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,6 +41,7 @@ class BatteryPropertiesRegistrar : public BnBatteryPropertiesRegistrar,
void registerListener(const sp<IBatteryPropertiesListener>& listener);
void unregisterListener(const sp<IBatteryPropertiesListener>& listener);
status_t getProperty(int id, struct BatteryProperty *val);
status_t getDockProperty(int id, struct BatteryProperty *val);
status_t dump(int fd, const Vector<String16>& args);
void binderDied(const wp<IBinder>& who);
};
Expand Down
17 changes: 17 additions & 0 deletions healthd/healthd.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2015 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -64,6 +65,18 @@ static struct healthd_config healthd_config = {
.energyCounter = NULL,
.boot_min_cap = 0,
.screen_on = NULL,
.dockBatterySupported = false,
.dockBatteryStatusPath = String8(String8::kEmptyString),
.dockBatteryHealthPath = String8(String8::kEmptyString),
.dockBatteryPresentPath = String8(String8::kEmptyString),
.dockBatteryCapacityPath = String8(String8::kEmptyString),
.dockBatteryVoltagePath = String8(String8::kEmptyString),
.dockBatteryTemperaturePath = String8(String8::kEmptyString),
.dockBatteryTechnologyPath = String8(String8::kEmptyString),
.dockBatteryCurrentNowPath = String8(String8::kEmptyString),
.dockBatteryCurrentAvgPath = String8(String8::kEmptyString),
.dockBatteryChargeCounterPath = String8(String8::kEmptyString),
.dockEnergyCounter = NULL,
};

static int eventct;
Expand Down Expand Up @@ -182,6 +195,10 @@ status_t healthd_get_property(int id, struct BatteryProperty *val) {
return gBatteryMonitor->getProperty(id, val);
}

status_t healthd_get_dock_property(int id, struct BatteryProperty *val) {
return gBatteryMonitor->getDockProperty(id, val);
}

void healthd_battery_update(void) {
// Fast wake interval when on charger (watch for overheat);
// slow wake interval when on battery (watch for drained battery).
Expand Down
1 change: 1 addition & 0 deletions healthd/healthd_mode_charger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ static void process_key(struct charger *charger, int code, int64_t now)
if (property_get_bool("ro.enable_boot_charger_mode", false)) {
LOGW("[%" PRId64 "] booting from charger mode\n", now);
healthd_board_mode_charger_set_backlight(false);
gr_fb_blank(true);
property_set("sys.boot_from_charger_mode", "1");
} else {
if (charger->batt_anim->capacity >= charger->boot_min_cap) {
Expand Down
7 changes: 6 additions & 1 deletion healthd/include/healthd/BatteryMonitor.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2015 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,20 +35,24 @@ class BatteryMonitor {
ANDROID_POWER_SUPPLY_TYPE_AC,
ANDROID_POWER_SUPPLY_TYPE_USB,
ANDROID_POWER_SUPPLY_TYPE_WIRELESS,
ANDROID_POWER_SUPPLY_TYPE_BATTERY
ANDROID_POWER_SUPPLY_TYPE_BATTERY,
ANDROID_POWER_SUPPLY_TYPE_DOCK_AC,
ANDROID_POWER_SUPPLY_TYPE_DOCK_BATTERY
};

BatteryMonitor();
void init(struct healthd_config *hc);
bool update(void);
int getChargeStatus();
status_t getProperty(int id, struct BatteryProperty *val);
status_t getDockProperty(int id, struct BatteryProperty *val);
void dumpState(int fd);

private:
struct healthd_config *mHealthdConfig;
Vector<String8> mChargerNames;
bool mBatteryDevicePresent;
bool mDockBatteryDevicePresent;
bool mAlwaysPluggedDevice;
int mBatteryFixedCapacity;
int mBatteryFixedTemperature;
Expand Down
34 changes: 34 additions & 0 deletions healthd/include/healthd/healthd.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2015 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,8 +49,25 @@
// batteryTemperaturePath: battery temperature (POWER_SUPPLY_PROP_TEMP)
// batteryTechnologyPath: battery technology (POWER_SUPPLY_PROP_TECHNOLOGY)
// batteryCurrentNowPath: battery current (POWER_SUPPLY_PROP_CURRENT_NOW)
// batteryCurrentAvgPath: battery average (POWER_SUPPLY_PROP_CURRENT_AVG)
// batteryChargeCounterPath: battery accumulated charge
// (POWER_SUPPLY_PROP_CHARGE_COUNTER)
//
// dockBatteryStatusPath: dock charging status (POWER_SUPPLY_PROP_STATUS)
// dockBatteryHealthPath: dock battery health (POWER_SUPPLY_PROP_HEALTH)
// dockBatteryPresentPath: dock battery present (POWER_SUPPLY_PROP_PRESENT)
// dockBatteryCapacityPath: remaining dock capacity (POWER_SUPPLY_PROP_CAPACITY)
// dockBatteryVoltagePath: dock battery voltage (POWER_SUPPLY_PROP_VOLTAGE_NOW)
// dockBatteryTemperaturePath: dock battery temperature (POWER_SUPPLY_PROP_TEMP)
// dockBatteryTechnologyPath: dock battery technology (POWER_SUPPLY_PROP_TECHNOLOGY)
// dockBatteryCurrentNowPath: dock battery current (POWER_SUPPLY_PROP_CURRENT_NOW)
// dockBatteryCurrentAvgPath: dock battery average (POWER_SUPPLY_PROP_CURRENT_AVG)
// dockBatteryChargeCounterPath: dock battery accumulated charge
// (POWER_SUPPLY_PROP_CHARGE_COUNTER)
//
// The dockBatterySupported property indicates whether a dock battery is supported
// by the device, and whether this module should fetch dock battery values.
// Defaults is to false.

struct healthd_config {
int periodic_chores_interval_fast;
Expand All @@ -71,6 +89,20 @@ struct healthd_config {
int (*energyCounter)(int64_t *);
int boot_min_cap;
bool (*screen_on)(android::BatteryProperties *props);

bool dockBatterySupported;
android::String8 dockBatteryStatusPath;
android::String8 dockBatteryHealthPath;
android::String8 dockBatteryPresentPath;
android::String8 dockBatteryCapacityPath;
android::String8 dockBatteryVoltagePath;
android::String8 dockBatteryTemperaturePath;
android::String8 dockBatteryTechnologyPath;
android::String8 dockBatteryCurrentNowPath;
android::String8 dockBatteryCurrentAvgPath;
android::String8 dockBatteryChargeCounterPath;

int (*dockEnergyCounter)(int64_t *);
};

// Global helper functions
Expand All @@ -79,6 +111,8 @@ int healthd_register_event(int fd, void (*handler)(uint32_t));
void healthd_battery_update();
android::status_t healthd_get_property(int id,
struct android::BatteryProperty *val);
android::status_t healthd_get_dock_property(int id,
struct android::BatteryProperty *val);
void healthd_dump_battery_state(int fd);

struct healthd_mode_ops {
Expand Down

0 comments on commit 3a66fa1

Please sign in to comment.