Skip to content

Commit

Permalink
- client (Android): suspend processing if battery temperature > 45 C.
Browse files Browse the repository at this point in the history
    We can adjust this or make it configurable later.
  • Loading branch information
davidpanderson authored and Oliver Bock committed Mar 5, 2013
1 parent 58395ed commit 21f580d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
14 changes: 10 additions & 4 deletions client/cs_prefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ int CLIENT_STATE::check_suspend_processing() {
}

#ifdef ANDROID
// check for hot battery
//
host_info.get_battery_status();
if (host_info.battery_state == BATTERY_STATE_OVERHEATED) {
return SUSPEND_REASON_BATTERY_OVERHEATED;
}
if (host_info.battery_temperature_celsius > 45) {
return SUSPEND_REASON_BATTERY_OVERHEATED;
}

// on some devices, running jobs can drain the battery even
// while it's recharging.
// So use the following hysteresis policy:
Expand All @@ -276,10 +286,6 @@ int CLIENT_STATE::check_suspend_processing() {
// Repeat.
//
static bool hyst_state = true;
host_info.get_battery_status();
if (host_info.battery_state == BATTERY_STATE_OVERHEATED) {
return SUSPEND_REASON_BATTERY_OVERHEATED;
}
int cp = host_info.battery_charge_pct;
if (cp >= 0) {
if (cp < 90) {
Expand Down
13 changes: 12 additions & 1 deletion client/hostinfo_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ bool HOST_INFO::host_is_running_on_batteries() {
}

#ifdef ANDROID
// Get battery state and charge percentage
// Get battery state, charge percentage, and temperature
//
void HOST_INFO::get_battery_status() {
char msg[1024];
Expand Down Expand Up @@ -495,6 +495,17 @@ void HOST_INFO::get_battery_status() {
LOGD("battery is charging");
battery_state = BATTERY_STATE_CHARGING;
}

battery_temperature_celsius = 0;
f = fopen("/sys/class/power_supply/battery/batt_temp", "r");
if (!f) {
f = fopen("/sys/class/power_supply/battery/temp", "r");
}
if (f) {
fscanf(f, "%d", &battery_temperature_celsius);
battery_temperature_celsius /= 10;
fclose(f);
}
}
#endif

Expand Down
1 change: 1 addition & 0 deletions lib/hostinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class HOST_INFO {
#ifdef ANDROID
int battery_charge_pct;
int battery_state;
int battery_temperature_celsius;
void get_battery_status();
#endif

Expand Down

0 comments on commit 21f580d

Please sign in to comment.