diff options
author | Ethan Yonker <dees_troy@teamw.in> | 2014-04-09 21:29:02 +0200 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit> | 2014-04-15 15:26:44 +0200 |
commit | 00028b4adbe1475fe799a7cec148b37182ac5e9f (patch) | |
tree | 9b132f947eab70fa9ab685e751f017860f522636 | |
parent | Fix touch on Sprint HTC One m8 (diff) | |
download | android_bootable_recovery-00028b4adbe1475fe799a7cec148b37182ac5e9f.tar android_bootable_recovery-00028b4adbe1475fe799a7cec148b37182ac5e9f.tar.gz android_bootable_recovery-00028b4adbe1475fe799a7cec148b37182ac5e9f.tar.bz2 android_bootable_recovery-00028b4adbe1475fe799a7cec148b37182ac5e9f.tar.lz android_bootable_recovery-00028b4adbe1475fe799a7cec148b37182ac5e9f.tar.xz android_bootable_recovery-00028b4adbe1475fe799a7cec148b37182ac5e9f.tar.zst android_bootable_recovery-00028b4adbe1475fe799a7cec148b37182ac5e9f.zip |
Diffstat (limited to '')
-rw-r--r-- | Android.mk | 1 | ||||
-rw-r--r-- | data.cpp | 23 | ||||
-rw-r--r-- | find_file.cpp | 89 | ||||
-rw-r--r-- | find_file.hpp | 37 |
4 files changed, 146 insertions, 4 deletions
diff --git a/Android.mk b/Android.mk index 98c442791..fbddef7e3 100644 --- a/Android.mk +++ b/Android.mk @@ -22,6 +22,7 @@ LOCAL_SRC_FILES := \ twrpTar.cpp \ twrpDU.cpp \ twrpDigest.cpp \ + find_file.cpp LOCAL_SRC_FILES += \ data.cpp \ @@ -45,6 +45,7 @@ #ifndef TW_NO_SCREEN_TIMEOUT #include "gui/blanktimer.hpp" #endif +#include "find_file.hpp" #ifdef TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID #include "cutils/properties.h" @@ -940,17 +941,31 @@ void DataManager::SetDefaultValues() #ifndef TW_MAX_BRIGHTNESS #define TW_MAX_BRIGHTNESS 255 #endif + string findbright; if (strcmp(EXPAND(TW_BRIGHTNESS_PATH), "/nobrightness") != 0) { - LOGINFO("TW_BRIGHTNESS_PATH := %s\n", EXPAND(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 = ""; + } + } + if (findbright.empty()) { + // Attempt to locate the brightness file + findbright = Find_File::Find("brightness", "/sys/class/backlight"); + } + if (findbright.empty()) { + LOGINFO("Unable to locate brightness file\n"); + mConstValues.insert(make_pair("tw_has_brightnesss_file", "0")); + } else { + 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", EXPAND(TW_BRIGHTNESS_PATH))); + mConstValues.insert(make_pair("tw_brightness_file", findbright)); 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))); mValues.insert(make_pair("tw_brightness_pct", make_pair("100", 1))); - } else { - mConstValues.insert(make_pair("tw_has_brightnesss_file", "0")); } #endif mValues.insert(make_pair(TW_MILITARY_TIME, make_pair("0", 1))); diff --git a/find_file.cpp b/find_file.cpp new file mode 100644 index 000000000..f56f243de --- /dev/null +++ b/find_file.cpp @@ -0,0 +1,89 @@ +/* + Copyright 2014 TeamWin + This file is part of TWRP/TeamWin Recovery Project. + + TWRP is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + TWRP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with TWRP. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <string> +#include <vector> +#include <dirent.h> +#include "find_file.hpp" +#include "twrp-functions.hpp" +#include "twcommon.h" + +using namespace std; + +string Find_File::Find(const string& file_name, const string& start_path) { + return Find_File().Find_Internal(file_name, start_path); +} + +Find_File::Find_File() { +} + +string Find_File::Find_Internal(const string& filename, const string& starting_path) { + DIR *d = opendir(starting_path.c_str()); + string new_path, return_path; + vector<string> dirs; + vector<string> symlinks; + unsigned index; + + // Check to see if we have already searched this directory to prevent infinite loops + if (std::find(searched_dirs.begin(), searched_dirs.end(), starting_path) != searched_dirs.end()) { + return ""; + } + searched_dirs.push_back(starting_path); + + if (d == NULL) { + LOGERR("Find_File: Error opening '%s'\n", starting_path.c_str()); + return ""; + } + + struct dirent *p; + while ((p = readdir(d))) { + if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) + continue; + new_path = starting_path + "/"; + new_path.append(p->d_name); + if (p->d_type == DT_DIR) { + // Add dir to search list for later + dirs.push_back(new_path); + } else if (p->d_type == DT_LNK) { + // Add symlink to search list for later + symlinks.push_back(new_path); + } else if (p->d_type == DT_REG && filename == p->d_name) { + // We found a match! + closedir(d); + return new_path; + } + } + closedir(d); + + // Scan real directories first if no match found in this path + for (index = 0; index < dirs.size(); index++) { + return_path = Find_Internal(filename, dirs.at(index)); + if (!return_path.empty()) return return_path; + } + // Scan symlinks after scanning real directories + for (index = 0; index < symlinks.size(); index++) { + char buf[PATH_MAX]; + // Resolve symlink to a real path + char* ret = realpath(symlinks.at(index).c_str(), buf); + if (ret) { + return_path = Find_Internal(filename, buf); + if (!return_path.empty()) return return_path; + } + } + return ""; +} diff --git a/find_file.hpp b/find_file.hpp new file mode 100644 index 000000000..8833e9ad2 --- /dev/null +++ b/find_file.hpp @@ -0,0 +1,37 @@ +/* + Copyright 2014 TeamWin + This file is part of TWRP/TeamWin Recovery Project. + + TWRP is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + TWRP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with TWRP. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef Find_File_HPP +#define Find_File_HPP + +#include <string> +#include <vector> + +using namespace std; + +class Find_File { + +public: + static string Find(const string& file_name, const string& start_path); +private: + Find_File(); + string Find_Internal(const string& filename, const string& starting_path); + vector<string> searched_dirs; +}; + +#endif |