From 21f580d9efc9f56df1a1421e510660142e26b43c Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 8 Feb 2013 13:49:44 -0800 Subject: [PATCH] - client (Android): suspend processing if battery temperature > 45 C. We can adjust this or make it configurable later. --- client/cs_prefs.cpp | 14 ++++++++++---- client/hostinfo_unix.cpp | 13 ++++++++++++- lib/hostinfo.h | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/client/cs_prefs.cpp b/client/cs_prefs.cpp index 159ed18ccd..46066dfc7a 100644 --- a/client/cs_prefs.cpp +++ b/client/cs_prefs.cpp @@ -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: @@ -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) { diff --git a/client/hostinfo_unix.cpp b/client/hostinfo_unix.cpp index e11dfb41a3..cba4d52463 100644 --- a/client/hostinfo_unix.cpp +++ b/client/hostinfo_unix.cpp @@ -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]; @@ -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 diff --git a/lib/hostinfo.h b/lib/hostinfo.h index f1fdadc6a6..898307f289 100644 --- a/lib/hostinfo.h +++ b/lib/hostinfo.h @@ -70,6 +70,7 @@ public: #ifdef ANDROID int battery_charge_pct; int battery_state; + int battery_temperature_celsius; void get_battery_status(); #endif