summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTatsuyuki Ishi <ishitatsuyuki@gmail.com>2015-12-28 02:08:58 +0100
committerDees Troy <dees_troy@teamw.in>2016-01-22 18:06:00 +0100
commit548a175182238e2612af0892ca5475aba5b02c44 (patch)
treec74cef9d616b97ac610bd2dc3b50dcb6100dc38a
parentminzip: Add support for >2GB zipfile (diff)
downloadandroid_bootable_recovery-548a175182238e2612af0892ca5475aba5b02c44.tar
android_bootable_recovery-548a175182238e2612af0892ca5475aba5b02c44.tar.gz
android_bootable_recovery-548a175182238e2612af0892ca5475aba5b02c44.tar.bz2
android_bootable_recovery-548a175182238e2612af0892ca5475aba5b02c44.tar.lz
android_bootable_recovery-548a175182238e2612af0892ca5475aba5b02c44.tar.xz
android_bootable_recovery-548a175182238e2612af0892ca5475aba5b02c44.tar.zst
android_bootable_recovery-548a175182238e2612af0892ca5475aba5b02c44.zip
-rw-r--r--data.cpp57
-rw-r--r--gui/blanktimer.cpp15
-rw-r--r--twrp-functions.cpp17
-rw-r--r--variables.h4
4 files changed, 50 insertions, 43 deletions
diff --git a/data.cpp b/data.cpp
index c945f2af0..e38f36641 100644
--- a/data.cpp
+++ b/data.cpp
@@ -55,10 +55,6 @@
#define DEVID_MAX 64
#define HWID_MAX 32
-#ifndef TW_MAX_BRIGHTNESS
-#define TW_MAX_BRIGHTNESS 255
-#endif
-
extern "C"
{
#include "twcommon.h"
@@ -829,16 +825,15 @@ void DataManager::SetDefaultValues()
#endif
mValues.insert(make_pair("tw_gui_done", make_pair("0", 0)));
mValues.insert(make_pair("tw_encrypt_backup", make_pair("0", 0)));
-#ifdef TW_BRIGHTNESS_PATH
string findbright;
- if (strcmp(EXPAND(TW_BRIGHTNESS_PATH), "/nobrightness") != 0) {
- findbright = EXPAND(TW_BRIGHTNESS_PATH);
- LOGINFO("TW_BRIGHTNESS_PATH := %s\n", findbright.c_str());
- if (!TWFunc::Path_Exists(findbright)) {
- LOGINFO("Specified brightness file '%s' not found.\n", findbright.c_str());
- findbright = "";
- }
+#ifdef TW_BRIGHTNESS_PATH
+ findbright = EXPAND(TW_BRIGHTNESS_PATH);
+ LOGINFO("TW_BRIGHTNESS_PATH := %s\n", findbright.c_str());
+ if (!TWFunc::Path_Exists(findbright)) {
+ LOGINFO("Specified brightness file '%s' not found.\n", findbright.c_str());
+ findbright = "";
}
+#endif
if (findbright.empty()) {
// Attempt to locate the brightness file
findbright = Find_File::Find("brightness", "/sys/class/backlight");
@@ -851,10 +846,33 @@ void DataManager::SetDefaultValues()
LOGINFO("Found brightness file at '%s'\n", findbright.c_str());
mConstValues.insert(make_pair("tw_has_brightnesss_file", "1"));
mConstValues.insert(make_pair("tw_brightness_file", findbright));
+ string maxBrightness;
+#ifdef TW_MAX_BRIGHTNESS
ostringstream maxVal;
maxVal << TW_MAX_BRIGHTNESS;
- mConstValues.insert(make_pair("tw_brightness_max", maxVal.str()));
- mValues.insert(make_pair("tw_brightness", make_pair(maxVal.str(), 1)));
+ maxBrightness = maxVal.str();
+#else
+ // Attempt to locate the max_brightness file
+ string maxbrightpath = findbright.insert(findbright.rfind('/') + 1, "max_");
+ if (TWFunc::Path_Exists(maxbrightpath)) {
+ ifstream maxVal(maxbrightpath);
+ if(maxVal >> maxBrightness) {
+ LOGINFO("Got max brightness %s from '%s'\n", maxBrightness.c_str(), maxbrightpath.c_str());
+ } else {
+ // Something went wrong, set that to indicate error
+ maxBrightness = "-1";
+ }
+ }
+ if(stoi(maxBrightness) <= 0)
+ {
+ // Fallback into default
+ ostringstream maxVal;
+ maxVal << 255;
+ maxBrightness = maxVal.str();
+ }
+#endif
+ mConstValues.insert(make_pair("tw_brightness_max", maxBrightness));
+ mValues.insert(make_pair("tw_brightness", make_pair(maxBrightness, 1)));
mValues.insert(make_pair("tw_brightness_pct", make_pair("100", 1)));
#ifdef TW_SECONDARY_BRIGHTNESS_PATH
string secondfindbright = EXPAND(TW_SECONDARY_BRIGHTNESS_PATH);
@@ -867,7 +885,7 @@ void DataManager::SetDefaultValues()
#endif
#ifdef TW_DEFAULT_BRIGHTNESS
int defValInt = TW_DEFAULT_BRIGHTNESS;
- int maxValInt = TW_MAX_BRIGHTNESS;
+ int maxValInt = stoi(maxBrightness);
// Deliberately int so the % is always a whole number
int defPctInt = ( ( (double)defValInt / maxValInt ) * 100 );
ostringstream defPct;
@@ -879,12 +897,11 @@ void DataManager::SetDefaultValues()
defVal << TW_DEFAULT_BRIGHTNESS;
mValues.erase("tw_brightness");
mValues.insert(make_pair("tw_brightness", make_pair(defVal.str(), 1)));
- TWFunc::Set_Brightness(defVal.str());
+ TWFunc::Set_Brightness(defVal.str());
#else
- TWFunc::Set_Brightness(maxVal.str());
+ TWFunc::Set_Brightness(maxBrightness);
#endif
}
-#endif
mValues.insert(make_pair(TW_MILITARY_TIME, make_pair("0", 1)));
#ifndef TW_EXCLUDE_ENCRYPTED_BACKUPS
mValues.insert(make_pair("tw_include_encrypted_backup", make_pair("1", 0)));
@@ -1096,9 +1113,7 @@ void DataManager::ReadSettingsFile(void)
PartitionManager.Mount_All_Storage();
update_tz_environment_variables();
#ifdef TW_MAX_BRIGHTNESS
- if (GetStrValue("tw_brightness_path") != "/nobrightness") {
- TWFunc::Set_Brightness(GetStrValue("tw_brightness"));
- }
+ TWFunc::Set_Brightness(GetStrValue("tw_brightness"));
#endif
}
diff --git a/gui/blanktimer.cpp b/gui/blanktimer.cpp
index 95b6c47ff..06208e273 100644
--- a/gui/blanktimer.cpp
+++ b/gui/blanktimer.cpp
@@ -81,16 +81,13 @@ void blanktimer::checkForTimeout() {
string blanktimer::getBrightness(void) {
string result;
- string brightness_path;
- DataManager::GetValue("tw_brightness_file", brightness_path);
- if (brightness_path == "/nobrightness")
- return brightness_path;
- DataManager::GetValue("tw_brightness", result);
- if (result == "") {
- result = "255";
+
+ if (DataManager::GetIntValue("tw_has_brightnesss_file")) {
+ DataManager::GetValue("tw_brightness", result);
+ if (result.empty())
+ result = "255";
}
return result;
-
}
void blanktimer::resetTimerAndUnblank(void) {
@@ -112,7 +109,7 @@ void blanktimer::resetTimerAndUnblank(void) {
gui_forceRender();
// No break here, we want to keep going
case kDim:
- if (orig_brightness != "/nobrightness")
+ if (!orig_brightness.empty())
TWFunc::Set_Brightness(orig_brightness);
state = kOn;
case kOn:
diff --git a/twrp-functions.cpp b/twrp-functions.cpp
index e73a52dbb..63ed0a644 100644
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -981,20 +981,19 @@ bool TWFunc::Create_Dir_Recursive(const std::string& path, mode_t mode, uid_t ui
int TWFunc::Set_Brightness(std::string brightness_value)
{
+ int result = -1;
+ std::string secondary_brightness_file;
- std::string brightness_file = DataManager::GetStrValue("tw_brightness_file");;
-
- if (brightness_file.compare("/nobrightness") != 0) {
- std::string secondary_brightness_file = DataManager::GetStrValue("tw_secondary_brightness_file");
+ if (DataManager::GetIntValue("tw_has_brightnesss_file")) {
LOGINFO("TWFunc::Set_Brightness: Setting brightness control to %s\n", brightness_value.c_str());
- int result = TWFunc::write_file(brightness_file, brightness_value);
- if (secondary_brightness_file != "") {
- LOGINFO("TWFunc::Set_Brightness: Setting SECONDARY brightness control to %s\n", brightness_value.c_str());
+ result = TWFunc::write_file(DataManager::GetStrValue("tw_brightness_file"), brightness_value);
+ DataManager::GetValue("tw_secondary_brightness_file", secondary_brightness_file);
+ if (!secondary_brightness_file.empty()) {
+ LOGINFO("TWFunc::Set_Brightness: Setting secondary brightness control to %s\n", brightness_value.c_str());
TWFunc::write_file(secondary_brightness_file, brightness_value);
}
- return result;
}
- return -1;
+ return result;
}
bool TWFunc::Toggle_MTP(bool enable) {
diff --git a/variables.h b/variables.h
index f7304b474..e66f8c31f 100644
--- a/variables.h
+++ b/variables.h
@@ -172,10 +172,6 @@
#define CUSTOM_LUN_FILE "/sys/class/android_usb/android0/f_mass_storage/lun%d/file"
#endif
-#ifndef TW_BRIGHTNESS_PATH
-#define TW_BRIGHTNESS_PATH /nobrightness
-#endif
-
// For OpenRecoveryScript
#define SCRIPT_FILE_CACHE "/cache/recovery/openrecoveryscript"
#define SCRIPT_FILE_TMP "/tmp/openrecoveryscript"