display cpu temperature in twrp
use TW_NO_CPU_TEMP := true to disable display
use TW_CPU_CUSTOM_PATH := path to set custom path
Change-Id: Id260ecbb4ec36a78442387329944f67003d0f6a0
diff --git a/Android.mk b/Android.mk
index 03e1a69..5ec184e 100644
--- a/Android.mk
+++ b/Android.mk
@@ -199,6 +199,9 @@
ifeq ($(TW_NO_BATT_PERCENT), true)
LOCAL_CFLAGS += -DTW_NO_BATT_PERCENT
endif
+ifeq ($(TW_NO_CPU_TEMP), true)
+ LOCAL_CFLAGS += -DTW_NO_CPU_TEMP
+endif
ifneq ($(TW_CUSTOM_POWER_BUTTON),)
LOCAL_CFLAGS += -DTW_CUSTOM_POWER_BUTTON=$(TW_CUSTOM_POWER_BUTTON)
endif
@@ -288,6 +291,12 @@
ifneq ($(TW_CUSTOM_BATTERY_PATH),)
LOCAL_CFLAGS += -DTW_CUSTOM_BATTERY_PATH=$(TW_CUSTOM_BATTERY_PATH)
endif
+ifneq ($(TW_CUSTOM_CPU_TEMP_PATH),)
+ LOCAL_CFLAGS += -DTW_CUSTOM_CPU_TEMP_PATH=$(TW_CUSTOM_CPU_TEMP_PATH)
+endif
+ifneq ($(TW_NO_CPU_TEMP),)
+ LOCAL_CFLAGS += -DTW_NO_CPU_TEMP=$(TW_NO_CPU_TEMP)
+endif
ifneq ($(TW_EXCLUDE_ENCRYPTED_BACKUPS), true)
LOCAL_SHARED_LIBRARIES += libopenaes
else
diff --git a/data.cpp b/data.cpp
index be85158..0e46b3b 100644
--- a/data.cpp
+++ b/data.cpp
@@ -72,6 +72,7 @@
map<string, string> DataManager::mConstValues;
string DataManager::mBackingFile;
int DataManager::mInitialized = 0;
+
#ifndef TW_NO_SCREEN_TIMEOUT
extern blanktimer blankTimer;
#endif
@@ -353,7 +354,6 @@
// Handle magic values
if (GetMagicValue(localStr, value) == 0)
return 0;
-
map<string, string>::iterator constPos;
constPos = mConstValues.find(localStr);
if (constPos != mConstValues.end())
@@ -660,6 +660,23 @@
#else
mConstValues.insert(make_pair(TW_NO_BATTERY_PERCENT, "0"));
#endif
+#ifdef TW_NO_CPU_TEMP
+ printf("TW_NO_CPU_TEMP := true\n");
+ mConstValues.insert(make_pair("tw_no_cpu_temp", "1"));
+#else
+ string cpu_temp_file;
+#ifdef TW_CUSTOM_CPU_TEMP_PATH
+ cpu_temp_file = EXPAND(TW_CUSTOM_CPU_TEMP_PATH);
+#else
+ cpu_temp_file = "/sys/class/thermal/thermal_zone0/temp";
+#endif
+ if (TWFunc::Path_Exists(cpu_temp_file)) {
+ mConstValues.insert(make_pair("tw_no_cpu_temp", "0"));
+ } else {
+ LOGINFO("CPU temperature file '%s' not found, disabling CPU temp.\n", cpu_temp_file.c_str());
+ mConstValues.insert(make_pair("tw_no_cpu_temp", "1"));
+ }
+#endif
#ifdef TW_CUSTOM_POWER_BUTTON
printf("TW_POWER_BUTTON := %s\n", EXPAND(TW_CUSTOM_POWER_BUTTON));
mConstValues.insert(make_pair(TW_POWER_BUTTON, EXPAND(TW_CUSTOM_POWER_BUTTON)));
@@ -862,13 +879,41 @@
value = tmp;
return 0;
}
+ else if (varName == "tw_cpu_temp")
+ {
+ string cpu_temp_file;
+ static unsigned long convert_temp = 0;
+ static time_t cpuSecCheck = 0;
+ int divisor = 0;
+ struct timeval curTime;
+ string results;
+
+ gettimeofday(&curTime, NULL);
+ if (curTime.tv_sec > cpuSecCheck)
+ {
+#ifdef TW_CUSTOM_CPU_TEMP_PATH
+ cpu_temp_file = EXPAND(TW_CUSTOM_CPU_TEMP_PATH);
+ if (TWFunc::read_file(cpu_temp_file, results) != 0)
+ return -1;
+#else
+ cpu_temp_file = "/sys/class/thermal/thermal_zone0/temp";
+ if (TWFunc::read_file(cpu_temp_file, results) != 0)
+ return -1;
+#endif
+ convert_temp = strtoul(results.c_str(), NULL, 0) / 1000;
+ if (convert_temp <= 0)
+ convert_temp = strtoul(results.c_str(), NULL, 0);
+ cpuSecCheck = curTime.tv_sec + 5;
+ }
+ value = TWFunc::to_string(convert_temp);
+ return 0;
+ }
else if (varName == "tw_battery")
{
char tmp[16];
static char charging = ' ';
static int lastVal = -1;
static time_t nextSecCheck = 0;
-
struct timeval curTime;
gettimeofday(&curTime, NULL);
if (curTime.tv_sec > nextSecCheck)
diff --git a/gui/devices/1024x600/res/ui.xml b/gui/devices/1024x600/res/ui.xml
index 4d6f317..7b7ad8c 100644
--- a/gui/devices/1024x600/res/ui.xml
+++ b/gui/devices/1024x600/res/ui.xml
@@ -231,13 +231,13 @@
<object type="text" color="%text_color%">
<font resource="font" />
- <placement x="250" y="5" />
+ <placement x="200" y="5" />
<text>Team Win Recovery Project v%tw_version%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
- <placement x="250" y="30" />
+ <placement x="200" y="30" />
<conditions>
<condition var1="tw_no_battery_percent" var2="0" />
<condition var1="tw_battery" op=">" var2="0" />
@@ -248,14 +248,23 @@
<object type="text" color="%text_color%">
<font resource="font" />
- <placement x="450" y="30" />
+ <placement x="400" y="30" />
<text>%tw_time%</text>
</object>
<object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="700" y="30" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
+
+ <object type="text" color="%text_color%">
<condition var1="tw_simulate_actions" var2="1" />
<font resource="font" />
- <placement x="550" y="30" />
+ <placement x="475" y="30" />
<text>SIMULATING ACTIONS</text>
</object>
diff --git a/gui/devices/1024x768/res/ui.xml b/gui/devices/1024x768/res/ui.xml
index 29f1690..b5ce1b4 100644
--- a/gui/devices/1024x768/res/ui.xml
+++ b/gui/devices/1024x768/res/ui.xml
@@ -231,13 +231,13 @@
<object type="text" color="%text_color%">
<font resource="font" />
- <placement x="250" y="5" />
+ <placement x="200" y="5" />
<text>Team Win Recovery Project v%tw_version%</text>
</object>
<object type="text" color="%text_color%">
<font resource="font" />
- <placement x="250" y="30" />
+ <placement x="200" y="30" />
<conditions>
<condition var1="tw_no_battery_percent" var2="0" />
<condition var1="tw_battery" op=">" var2="0" />
@@ -248,14 +248,23 @@
<object type="text" color="%text_color%">
<font resource="font" />
- <placement x="450" y="30" />
+ <placement x="400" y="30" />
<text>%tw_time%</text>
</object>
<object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="700" y="30" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
+
+ <object type="text" color="%text_color%">
<condition var1="tw_simulate_actions" var2="1" />
<font resource="font" />
- <placement x="550" y="30" />
+ <placement x="475" y="30" />
<text>SIMULATING ACTIONS</text>
</object>
diff --git a/gui/devices/1080x1920/res/ui.xml b/gui/devices/1080x1920/res/ui.xml
index 95c48a5..1367015 100644
--- a/gui/devices/1080x1920/res/ui.xml
+++ b/gui/devices/1080x1920/res/ui.xml
@@ -246,6 +246,15 @@
<text>Battery: %tw_battery%</text>
</object>
+ <object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="760" y="114" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
+
<object type="button">
<highlight color="%highlight_color%" />
<placement x="%home_button_x%" y="%home_button_y%" />
diff --git a/gui/devices/1200x1920/res/ui.xml b/gui/devices/1200x1920/res/ui.xml
index 428880d..77af05b 100644
--- a/gui/devices/1200x1920/res/ui.xml
+++ b/gui/devices/1200x1920/res/ui.xml
@@ -249,6 +249,15 @@
<text>Battery: %tw_battery%</text>
</object>
+ <object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="730" y="114" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
+
<object type="button">
<highlight color="%highlight_color%" />
<placement x="%home_button_x%" y="%home_button_y%" />
diff --git a/gui/devices/1280x800/res/ui.xml b/gui/devices/1280x800/res/ui.xml
index 6f6c2bd..716dadc 100644
--- a/gui/devices/1280x800/res/ui.xml
+++ b/gui/devices/1280x800/res/ui.xml
@@ -253,6 +253,15 @@
</object>
<object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="850" y="30" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
+
+ <object type="text" color="%text_color%">
<condition var1="tw_simulate_actions" var2="1" />
<font resource="font" />
<placement x="550" y="30" />
diff --git a/gui/devices/1440x2560/res/ui.xml b/gui/devices/1440x2560/res/ui.xml
index fe55dfd..79f12cf 100644
--- a/gui/devices/1440x2560/res/ui.xml
+++ b/gui/devices/1440x2560/res/ui.xml
@@ -9,9 +9,9 @@
<preview>preview.jpg</preview>
</details>
- <include>
- <xmlfile name="portrait.xml" />
- </include>
+ <include>
+ <xmlfile name="portrait.xml" />
+ </include>
<resources>
<resource name="font" type="font" filename="RobotoCondensed-Regular.ttf" size="50" fallback="Roboto-Condensed-50" />
@@ -246,6 +246,15 @@
<text>Battery: %tw_battery%</text>
</object>
+ <object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="839" y="132" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
+
<object type="button">
<highlight color="%highlight_color%" />
<placement x="%home_button_x%" y="%home_button_y%" />
diff --git a/gui/devices/1600x2560/res/ui.xml b/gui/devices/1600x2560/res/ui.xml
index 8561b2d..09c7408 100644
--- a/gui/devices/1600x2560/res/ui.xml
+++ b/gui/devices/1600x2560/res/ui.xml
@@ -249,6 +249,15 @@
<text>Battery: %tw_battery%</text>
</object>
+ <object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="739" y="132" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
+
<object type="button">
<highlight color="%highlight_color%" />
<placement x="%home_button_x%" y="%home_button_y%" />
diff --git a/gui/devices/1920x1200/res/ui.xml b/gui/devices/1920x1200/res/ui.xml
index 3e8c9f1..e36d0ae 100644
--- a/gui/devices/1920x1200/res/ui.xml
+++ b/gui/devices/1920x1200/res/ui.xml
@@ -253,9 +253,18 @@
</object>
<object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="1150" y="40" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
+
+ <object type="text" color="%text_color%">
<condition var1="tw_simulate_actions" var2="1" />
<font resource="font" />
- <placement x="850" y="40" />
+ <placement x="750" y="40" />
<text>SIMULATING ACTIONS</text>
</object>
diff --git a/gui/devices/240x240/res/ui.xml b/gui/devices/240x240/res/ui.xml
index 294e595..d157f85 100644
--- a/gui/devices/240x240/res/ui.xml
+++ b/gui/devices/240x240/res/ui.xml
@@ -211,7 +211,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
- <placement x="3" y="3" />
+ <placement x="1" y="3" />
<text>TWRP v%tw_version%</text>
</object>
@@ -224,7 +224,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
- <placement x="100" y="3" />
+ <placement x="89" y="3" />
<text>%tw_time%</text>
</object>
@@ -238,6 +238,15 @@
</conditions>
<text>%tw_battery%</text>
</object>
+
+ <object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="145" y="3" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>%tw_cpu_temp% C</text>
+ </object>
</template>
<template name="header">
diff --git a/gui/devices/2560x1600/res/ui.xml b/gui/devices/2560x1600/res/ui.xml
index cb0c12e..12a2d55 100644
--- a/gui/devices/2560x1600/res/ui.xml
+++ b/gui/devices/2560x1600/res/ui.xml
@@ -253,6 +253,15 @@
</object>
<object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="1650" y="55" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
+
+ <object type="text" color="%text_color%">
<condition var1="tw_simulate_actions" var2="1" />
<font resource="font" />
<placement x="1100" y="55" />
diff --git a/gui/devices/280x280/res/ui.xml b/gui/devices/280x280/res/ui.xml
index 99532ed..971e637 100644
--- a/gui/devices/280x280/res/ui.xml
+++ b/gui/devices/280x280/res/ui.xml
@@ -224,7 +224,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
- <placement x="165" y="3" />
+ <placement x="95" y="3" />
<text>%tw_time%</text>
</object>
@@ -238,6 +238,15 @@
</conditions>
<text>%tw_battery%</text>
</object>
+
+ <object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="160" y="3" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
</template>
<template name="header">
diff --git a/gui/devices/320x320/res/ui.xml b/gui/devices/320x320/res/ui.xml
index f668529..4678e85 100644
--- a/gui/devices/320x320/res/ui.xml
+++ b/gui/devices/320x320/res/ui.xml
@@ -224,7 +224,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
- <placement x="200" y="3" />
+ <placement x="110" y="3" />
<text>%tw_time%</text>
</object>
@@ -238,6 +238,15 @@
</conditions>
<text>%tw_battery%</text>
</object>
+
+ <object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="190" y="3" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
</template>
<template name="header">
diff --git a/gui/devices/320x480/res/ui.xml b/gui/devices/320x480/res/ui.xml
index cccd5b3..dd4cdbc 100644
--- a/gui/devices/320x480/res/ui.xml
+++ b/gui/devices/320x480/res/ui.xml
@@ -232,7 +232,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
- <placement x="165" y="39" />
+ <placement x="135" y="39" />
<conditions>
<condition var1="tw_no_battery_percent" var2="0" />
<condition var1="tw_battery" op=">" var2="0" />
@@ -241,6 +241,15 @@
<text>Battery: %tw_battery%</text>
</object>
+ <object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="265" y="39" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>%tw_cpu_temp% C</text>
+ </object>
+
<object type="button">
<placement x="%home_button_x%" y="%home_button_y%" />
<font resource="font" color="%button_text_color%" />
diff --git a/gui/devices/480x800/res/ui.xml b/gui/devices/480x800/res/ui.xml
index 940ad43..0e0f65d 100644
--- a/gui/devices/480x800/res/ui.xml
+++ b/gui/devices/480x800/res/ui.xml
@@ -232,7 +232,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
- <placement x="250" y="70" />
+ <placement x="190" y="70" />
<conditions>
<condition var1="tw_no_battery_percent" var2="0" />
<condition var1="tw_battery" op=">" var2="0" />
@@ -241,6 +241,15 @@
<text>Battery: %tw_battery%</text>
</object>
+ <object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="350" y="70" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
+
<object type="button">
<placement x="%home_button_x%" y="%home_button_y%" />
<font resource="font" color="%button_text_color%" />
diff --git a/gui/devices/480x854/res/ui.xml b/gui/devices/480x854/res/ui.xml
index dce1d88..26d8b28 100644
--- a/gui/devices/480x854/res/ui.xml
+++ b/gui/devices/480x854/res/ui.xml
@@ -231,7 +231,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
- <placement x="250" y="70" />
+ <placement x="190" y="70" />
<conditions>
<condition var1="tw_no_battery_percent" var2="0" />
<condition var1="tw_battery" op=">" var2="0" />
@@ -240,6 +240,15 @@
<text>Battery: %tw_battery%</text>
</object>
+ <object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="350" y="70" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
+
<object type="button">
<placement x="%home_button_x%" y="%home_button_y%" />
<font resource="font" color="%button_text_color%" />
diff --git a/gui/devices/540x960/res/ui.xml b/gui/devices/540x960/res/ui.xml
index 37c3e26..dc647ce 100644
--- a/gui/devices/540x960/res/ui.xml
+++ b/gui/devices/540x960/res/ui.xml
@@ -232,7 +232,7 @@
<object type="text" color="%text_color%">
<font resource="font" />
- <placement x="250" y="70" />
+ <placement x="200" y="70" />
<conditions>
<condition var1="tw_no_battery_percent" var2="0" />
<condition var1="tw_battery" op=">" var2="0" />
@@ -241,6 +241,15 @@
<text>Battery: %tw_battery%</text>
</object>
+ <object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="400" y="70" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
+
<object type="button">
<placement x="%home_button_x%" y="%home_button_y%" />
<font resource="font" color="%button_text_color%" />
diff --git a/gui/devices/720x1280/res/ui.xml b/gui/devices/720x1280/res/ui.xml
index a7ff192..2f1fbc7 100644
--- a/gui/devices/720x1280/res/ui.xml
+++ b/gui/devices/720x1280/res/ui.xml
@@ -246,6 +246,15 @@
<text>Battery: %tw_battery%</text>
</object>
+ <object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="500" y="76" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
+
<object type="button">
<highlight color="%highlight_color%" />
<placement x="%home_button_x%" y="%home_button_y%" />
diff --git a/gui/devices/800x1280/res/ui.xml b/gui/devices/800x1280/res/ui.xml
index e0036bf..03b6144 100644
--- a/gui/devices/800x1280/res/ui.xml
+++ b/gui/devices/800x1280/res/ui.xml
@@ -243,6 +243,15 @@
<text>Battery: %tw_battery%</text>
</object>
+ <object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="420" y="76" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
+
<object type="button">
<placement x="%home_button_x%" y="%home_button_y%" />
<font resource="font" color="%button_text_color%" />
diff --git a/gui/devices/800x480/res/ui.xml b/gui/devices/800x480/res/ui.xml
index 9acb7a1..ed1c842 100644
--- a/gui/devices/800x480/res/ui.xml
+++ b/gui/devices/800x480/res/ui.xml
@@ -248,11 +248,20 @@
<object type="text" color="%text_color%">
<font resource="font" />
- <placement x="450" y="37" />
+ <placement x="425" y="37" />
<text>%tw_time%</text>
</object>
<object type="text" color="%text_color%">
+ <font resource="font" />
+ <placement x="500" y="37" />
+ <conditions>
+ <condition var1="tw_no_cpu_temp" var2="0" />
+ </conditions>
+ <text>CPU: %tw_cpu_temp% C</text>
+ </object>
+
+ <object type="text" color="%text_color%">
<condition var1="tw_simulate_actions" var2="1" />
<font resource="font" />
<placement x="250" y="20" />
diff --git a/twrp-functions.cpp b/twrp-functions.cpp
index cd8700f..89714dd 100644
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -1289,4 +1289,10 @@
usleep(500000);
}
+std::string TWFunc::to_string(unsigned long value) {
+ std::ostringstream os;
+ os << value;
+ return os.str();
+}
+
#endif // ndef BUILD_TWRPTAR_MAIN
diff --git a/twrp-functions.hpp b/twrp-functions.hpp
index de14d94..1cc531c 100644
--- a/twrp-functions.hpp
+++ b/twrp-functions.hpp
@@ -86,6 +86,7 @@
static bool Create_Dir_Recursive(const std::string& path, mode_t mode = 0755, uid_t uid = -1, gid_t gid = -1); // Create directory and it's parents, if they don't exist. mode, uid and gid are set to all _newly_ created folders. If whole path exists, do nothing.
static int Set_Brightness(std::string brightness_value); // Well, you can read, it does what it says, passing return int from TWFunc::Write_File ;)
static bool Toggle_MTP(bool enable); // Disables MTP if enable is false and re-enables MTP if enable is true and it was enabled the last time it was toggled off
+ static std::string to_string(unsigned long value); //convert ul to string
static void SetPerformanceMode(bool mode); // support recovery.perf.mode