Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | /* |
Dees Troy | 3be70a8 | 2013-10-22 14:25:12 +0000 | [diff] [blame] | 2 | Copyright 2012 bigbiff/Dees_Troy TeamWin |
| 3 | This file is part of TWRP/TeamWin Recovery Project. |
| 4 | |
| 5 | TWRP is free software: you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation, either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | TWRP is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with TWRP. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 18 | |
| 19 | #include <linux/input.h> |
| 20 | #include <pthread.h> |
| 21 | #include <stdarg.h> |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include <fcntl.h> |
| 26 | #include <sys/stat.h> |
| 27 | #include <sys/time.h> |
| 28 | #include <sys/mman.h> |
| 29 | #include <sys/types.h> |
| 30 | #include <sys/ioctl.h> |
| 31 | #include <time.h> |
| 32 | #include <unistd.h> |
| 33 | #include <stdlib.h> |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 34 | #include <ctype.h> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 35 | |
| 36 | #include <string> |
| 37 | #include <utility> |
| 38 | #include <map> |
| 39 | #include <fstream> |
| 40 | #include <sstream> |
| 41 | |
| 42 | #include "variables.h" |
| 43 | #include "data.hpp" |
| 44 | #include "partitions.hpp" |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 45 | #include "twrp-functions.hpp" |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 46 | #ifndef TW_NO_SCREEN_TIMEOUT |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 47 | #include "gui/blanktimer.hpp" |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 48 | #endif |
Ethan Yonker | 00028b4 | 2014-04-09 14:29:02 -0500 | [diff] [blame] | 49 | #include "find_file.hpp" |
Ethan Yonker | 4b94cfd | 2014-12-11 10:00:45 -0600 | [diff] [blame] | 50 | #include "set_metadata.h" |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 51 | #include <cutils/properties.h> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 52 | |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 53 | #define DEVID_MAX 64 |
| 54 | #define HWID_MAX 32 |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 55 | |
Ethan Yonker | a18f108 | 2014-07-07 15:07:58 -0500 | [diff] [blame] | 56 | #ifndef TW_MAX_BRIGHTNESS |
| 57 | #define TW_MAX_BRIGHTNESS 255 |
| 58 | #endif |
| 59 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 60 | extern "C" |
| 61 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 62 | #include "twcommon.h" |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 63 | #include "gui/pages.h" |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 64 | #include "minuitwrp/minui.h" |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 65 | void gui_notifyVarChange(const char *name, const char* value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 66 | } |
| 67 | |
Ethan Yonker | 961d20e | 2015-06-29 14:00:03 -0500 | [diff] [blame] | 68 | #define FILE_VERSION 0x00010010 |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 69 | |
| 70 | using namespace std; |
| 71 | |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 72 | map<string, DataManager::TStrIntPair> DataManager::mValues; |
| 73 | map<string, string> DataManager::mConstValues; |
| 74 | string DataManager::mBackingFile; |
| 75 | int DataManager::mInitialized = 0; |
Jenkins | 1710bf2 | 2014-10-02 20:22:21 -0400 | [diff] [blame] | 76 | |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 77 | extern bool datamedia; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 78 | |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 79 | pthread_mutex_t DataManager::m_valuesLock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER; |
| 80 | |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 81 | // Device ID functions |
| 82 | void DataManager::sanitize_device_id(char* device_id) { |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 83 | const char* whitelist ="-._"; |
| 84 | char str[DEVID_MAX]; |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 85 | char* c = str; |
| 86 | |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 87 | snprintf(str, DEVID_MAX, "%s", device_id); |
| 88 | memset(device_id, 0, strlen(device_id)); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 89 | while (*c) { |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 90 | if (isalnum(*c) || strchr(whitelist, *c)) |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 91 | strncat(device_id, c, 1); |
| 92 | c++; |
| 93 | } |
| 94 | return; |
| 95 | } |
| 96 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 97 | #define CMDLINE_SERIALNO "androidboot.serialno=" |
| 98 | #define CMDLINE_SERIALNO_LEN (strlen(CMDLINE_SERIALNO)) |
| 99 | #define CPUINFO_SERIALNO "Serial" |
| 100 | #define CPUINFO_SERIALNO_LEN (strlen(CPUINFO_SERIALNO)) |
| 101 | #define CPUINFO_HARDWARE "Hardware" |
| 102 | #define CPUINFO_HARDWARE_LEN (strlen(CPUINFO_HARDWARE)) |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 103 | |
| 104 | void DataManager::get_device_id(void) { |
| 105 | FILE *fp; |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 106 | size_t i; |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 107 | char line[2048]; |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 108 | char hardware_id[HWID_MAX] = { 0 }; |
| 109 | char device_id[DEVID_MAX] = { 0 }; |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 110 | char* token; |
| 111 | |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 112 | #ifdef TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 113 | // Use (product_model)_(hardware_id) as device id |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 114 | char model_id[PROPERTY_VALUE_MAX]; |
| 115 | property_get("ro.product.model", model_id, "error"); |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 116 | if (strcmp(model_id, "error") != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 117 | LOGINFO("=> product model: '%s'\n", model_id); |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 118 | // Replace spaces with underscores |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 119 | for (i = 0; i < strlen(model_id); i++) { |
| 120 | if (model_id[i] == ' ') |
| 121 | model_id[i] = '_'; |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 122 | } |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 123 | snprintf(device_id, DEVID_MAX, "%s", model_id); |
| 124 | |
| 125 | if (strlen(device_id) < DEVID_MAX) { |
| 126 | fp = fopen("proc_cpuinfo.txt", "rt"); |
| 127 | if (fp != NULL) { |
| 128 | while (fgets(line, sizeof(line), fp) != NULL) { |
| 129 | if (memcmp(line, CPUINFO_HARDWARE, |
| 130 | CPUINFO_HARDWARE_LEN) == 0) { |
| 131 | // skip past "Hardware", spaces, and colon |
| 132 | token = line + CPUINFO_HARDWARE_LEN; |
| 133 | while (*token && (!isgraph(*token) || *token == ':')) |
| 134 | token++; |
| 135 | |
| 136 | if (*token && *token != '\n' |
| 137 | && strcmp("UNKNOWN\n", token)) { |
| 138 | snprintf(hardware_id, HWID_MAX, "%s", token); |
| 139 | if (hardware_id[strlen(hardware_id)-1] == '\n') |
| 140 | hardware_id[strlen(hardware_id)-1] = 0; |
| 141 | LOGINFO("=> hardware id from cpuinfo: '%s'\n", |
| 142 | hardware_id); |
| 143 | } |
| 144 | break; |
| 145 | } |
| 146 | } |
| 147 | fclose(fp); |
| 148 | } |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 149 | } |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 150 | |
| 151 | if (hardware_id[0] != 0) |
| 152 | snprintf(device_id, DEVID_MAX, "%s_%s", model_id, hardware_id); |
| 153 | |
| 154 | sanitize_device_id(device_id); |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 155 | mConstValues.insert(make_pair("device_id", device_id)); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 156 | LOGINFO("=> using device id: '%s'\n", device_id); |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 157 | return; |
| 158 | } |
| 159 | #endif |
| 160 | |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 161 | #ifndef TW_FORCE_CPUINFO_FOR_DEVICE_ID |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 162 | // Check the cmdline to see if the serial number was supplied |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 163 | fp = fopen("/proc/cmdline", "rt"); |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 164 | if (fp != NULL) { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 165 | fgets(line, sizeof(line), fp); |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 166 | fclose(fp); // cmdline is only one line long |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 167 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 168 | token = strtok(line, " "); |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 169 | while (token) { |
| 170 | if (memcmp(token, CMDLINE_SERIALNO, CMDLINE_SERIALNO_LEN) == 0) { |
| 171 | token += CMDLINE_SERIALNO_LEN; |
| 172 | snprintf(device_id, DEVID_MAX, "%s", token); |
| 173 | sanitize_device_id(device_id); // also removes newlines |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 174 | mConstValues.insert(make_pair("device_id", device_id)); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 175 | return; |
| 176 | } |
| 177 | token = strtok(NULL, " "); |
| 178 | } |
| 179 | } |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 180 | #endif |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 181 | // Check cpuinfo for serial number; if found, use as device_id |
| 182 | // If serial number is not found, fallback to hardware_id for the device_id |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 183 | fp = fopen("/proc/cpuinfo", "rt"); |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 184 | if (fp != NULL) { |
| 185 | while (fgets(line, sizeof(line), fp) != NULL) { |
| 186 | if (memcmp(line, CPUINFO_SERIALNO, CPUINFO_SERIALNO_LEN) == 0) { |
| 187 | // skip past "Serial", spaces, and colon |
| 188 | token = line + CPUINFO_SERIALNO_LEN; |
| 189 | while (*token && (!isgraph(*token) || *token == ':')) |
| 190 | token++; |
| 191 | |
| 192 | if (*token && *token != '\n') { |
| 193 | snprintf(device_id, DEVID_MAX, "%s", token); |
| 194 | sanitize_device_id(device_id); // also removes newlines |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 195 | LOGINFO("=> serial from cpuinfo: '%s'\n", device_id); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 196 | mConstValues.insert(make_pair("device_id", device_id)); |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 197 | fclose(fp); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 198 | return; |
| 199 | } |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 200 | } else if (memcmp(line, CPUINFO_HARDWARE, |
| 201 | CPUINFO_HARDWARE_LEN) == 0) { |
| 202 | // skip past "Hardware", spaces, and colon |
| 203 | token = line + CPUINFO_HARDWARE_LEN; |
| 204 | while (*token && (!isgraph(*token) || *token == ':')) |
| 205 | token++; |
| 206 | |
| 207 | if (*token && *token != '\n') { |
| 208 | snprintf(hardware_id, HWID_MAX, "%s", token); |
| 209 | if (hardware_id[strlen(hardware_id)-1] == '\n') |
| 210 | hardware_id[strlen(hardware_id)-1] = 0; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 211 | LOGINFO("=> hardware id from cpuinfo: '%s'\n", hardware_id); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | } |
| 215 | fclose(fp); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 216 | } |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 217 | |
| 218 | if (hardware_id[0] != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 219 | LOGINFO("\nusing hardware id for device id: '%s'\n", hardware_id); |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 220 | snprintf(device_id, DEVID_MAX, "%s", hardware_id); |
| 221 | sanitize_device_id(device_id); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 222 | mConstValues.insert(make_pair("device_id", device_id)); |
| 223 | return; |
| 224 | } |
| 225 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 226 | strcpy(device_id, "serialno"); |
Matt Mower | e926074 | 2015-02-22 20:20:18 -0600 | [diff] [blame] | 227 | LOGERR("=> device id not found, using '%s'\n", device_id); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 228 | mConstValues.insert(make_pair("device_id", device_id)); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 229 | return; |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 230 | } |
| 231 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 232 | int DataManager::ResetDefaults() |
| 233 | { |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 234 | pthread_mutex_lock(&m_valuesLock); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 235 | mValues.clear(); |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 236 | pthread_mutex_unlock(&m_valuesLock); |
| 237 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 238 | mConstValues.clear(); |
| 239 | SetDefaultValues(); |
| 240 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | int DataManager::LoadValues(const string filename) |
| 244 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 245 | string str, dev_id; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 246 | |
| 247 | if (!mInitialized) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 248 | SetDefaultValues(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 249 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 250 | GetValue("device_id", dev_id); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 251 | // Save off the backing file for set operations |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 252 | mBackingFile = filename; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 253 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 254 | // Read in the file, if possible |
| 255 | FILE* in = fopen(filename.c_str(), "rb"); |
| 256 | if (!in) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 257 | LOGINFO("Settings file '%s' not found.\n", filename.c_str()); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 258 | return 0; |
| 259 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 260 | LOGINFO("Loading settings from '%s'.\n", filename.c_str()); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 261 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 262 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 263 | int file_version; |
| 264 | if (fread(&file_version, 1, sizeof(int), in) != sizeof(int)) goto error; |
| 265 | if (file_version != FILE_VERSION) goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 266 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 267 | while (!feof(in)) |
| 268 | { |
| 269 | string Name; |
| 270 | string Value; |
| 271 | unsigned short length; |
| 272 | char array[512]; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 273 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 274 | if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error; |
| 275 | if (length >= 512) goto error; |
| 276 | if (fread(array, 1, length, in) != length) goto error; |
| 277 | Name = array; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 278 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 279 | if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error; |
| 280 | if (length >= 512) goto error; |
| 281 | if (fread(array, 1, length, in) != length) goto error; |
| 282 | Value = array; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 283 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 284 | map<string, TStrIntPair>::iterator pos; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 285 | |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 286 | pthread_mutex_lock(&m_valuesLock); |
| 287 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 288 | pos = mValues.find(Name); |
| 289 | if (pos != mValues.end()) |
| 290 | { |
| 291 | pos->second.first = Value; |
| 292 | pos->second.second = 1; |
| 293 | } |
| 294 | else |
| 295 | mValues.insert(TNameValuePair(Name, TStrIntPair(Value, 1))); |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 296 | |
| 297 | pthread_mutex_unlock(&m_valuesLock); |
| 298 | |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 299 | #ifndef TW_NO_SCREEN_TIMEOUT |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 300 | if (Name == "tw_screen_timeout_secs") |
| 301 | blankTimer.setTime(atoi(Value.c_str())); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 302 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 303 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 304 | error: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 305 | fclose(in); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 306 | string current = GetCurrentStoragePath(); |
Ethan Yonker | eeed3c5 | 2014-04-16 11:49:02 -0500 | [diff] [blame] | 307 | TWPartition* Part = PartitionManager.Find_Partition_By_Path(current); |
Vojtech Bocek | 93cb1ef | 2014-05-12 15:41:52 +0200 | [diff] [blame] | 308 | if(!Part) |
| 309 | Part = PartitionManager.Get_Default_Storage_Partition(); |
| 310 | if (Part && current != Part->Storage_Path && Part->Mount(false)) { |
Ethan Yonker | eeed3c5 | 2014-04-16 11:49:02 -0500 | [diff] [blame] | 311 | LOGINFO("LoadValues setting storage path to '%s'\n", Part->Storage_Path.c_str()); |
| 312 | SetValue("tw_storage_path", Part->Storage_Path); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 313 | } else { |
| 314 | SetBackupFolder(); |
| 315 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 316 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | int DataManager::Flush() |
| 320 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 321 | return SaveValues(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | int DataManager::SaveValues() |
| 325 | { |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 326 | #ifndef TW_OEM_BUILD |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 327 | if (mBackingFile.empty()) |
| 328 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 329 | |
| 330 | string mount_path = GetSettingsStoragePath(); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 331 | PartitionManager.Mount_By_Path(mount_path.c_str(), 1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 332 | |
| 333 | FILE* out = fopen(mBackingFile.c_str(), "wb"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 334 | if (!out) |
| 335 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 336 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 337 | int file_version = FILE_VERSION; |
| 338 | fwrite(&file_version, 1, sizeof(int), out); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 339 | |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 340 | pthread_mutex_lock(&m_valuesLock); |
| 341 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 342 | map<string, TStrIntPair>::iterator iter; |
| 343 | for (iter = mValues.begin(); iter != mValues.end(); ++iter) |
| 344 | { |
| 345 | // Save only the persisted data |
| 346 | if (iter->second.second != 0) |
| 347 | { |
| 348 | unsigned short length = (unsigned short) iter->first.length() + 1; |
| 349 | fwrite(&length, 1, sizeof(unsigned short), out); |
| 350 | fwrite(iter->first.c_str(), 1, length, out); |
| 351 | length = (unsigned short) iter->second.first.length() + 1; |
| 352 | fwrite(&length, 1, sizeof(unsigned short), out); |
| 353 | fwrite(iter->second.first.c_str(), 1, length, out); |
| 354 | } |
| 355 | } |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 356 | |
| 357 | pthread_mutex_unlock(&m_valuesLock); |
| 358 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 359 | fclose(out); |
Ethan Yonker | 4b94cfd | 2014-12-11 10:00:45 -0600 | [diff] [blame] | 360 | tw_set_default_metadata(mBackingFile.c_str()); |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 361 | #endif // ifdef TW_OEM_BUILD |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 362 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | int DataManager::GetValue(const string varName, string& value) |
| 366 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 367 | string localStr = varName; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 368 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 369 | if (!mInitialized) |
| 370 | SetDefaultValues(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 371 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 372 | // Strip off leading and trailing '%' if provided |
| 373 | if (localStr.length() > 2 && localStr[0] == '%' && localStr[localStr.length()-1] == '%') |
| 374 | { |
| 375 | localStr.erase(0, 1); |
| 376 | localStr.erase(localStr.length() - 1, 1); |
| 377 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 378 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 379 | // Handle magic values |
| 380 | if (GetMagicValue(localStr, value) == 0) |
| 381 | return 0; |
Xuefer | a163f15 | 2015-03-26 22:45:04 +0800 | [diff] [blame] | 382 | |
| 383 | // Handle property |
| 384 | if (localStr.length() > 9 && localStr.substr(0, 9) == "property.") { |
| 385 | char property_value[PROPERTY_VALUE_MAX]; |
| 386 | property_get(localStr.substr(9).c_str(), property_value, ""); |
| 387 | value = property_value; |
| 388 | return 0; |
| 389 | } |
| 390 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 391 | map<string, string>::iterator constPos; |
| 392 | constPos = mConstValues.find(localStr); |
| 393 | if (constPos != mConstValues.end()) |
| 394 | { |
| 395 | value = constPos->second; |
| 396 | return 0; |
| 397 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 398 | |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 399 | pthread_mutex_lock(&m_valuesLock); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 400 | map<string, TStrIntPair>::iterator pos; |
| 401 | pos = mValues.find(localStr); |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 402 | if (pos == mValues.end()){ |
| 403 | pthread_mutex_unlock(&m_valuesLock); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 404 | return -1; |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 405 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 406 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 407 | value = pos->second.first; |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 408 | pthread_mutex_unlock(&m_valuesLock); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 409 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | int DataManager::GetValue(const string varName, int& value) |
| 413 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 414 | string data; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 415 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 416 | if (GetValue(varName,data) != 0) |
| 417 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 418 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 419 | value = atoi(data.c_str()); |
| 420 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 421 | } |
| 422 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 423 | int DataManager::GetValue(const string varName, float& value) |
| 424 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 425 | string data; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 426 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 427 | if (GetValue(varName,data) != 0) |
| 428 | return -1; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 429 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 430 | value = atof(data.c_str()); |
| 431 | return 0; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 432 | } |
| 433 | |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 434 | unsigned long long DataManager::GetValue(const string varName, unsigned long long& value) |
| 435 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 436 | string data; |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 437 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 438 | if (GetValue(varName,data) != 0) |
| 439 | return -1; |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 440 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 441 | value = strtoull(data.c_str(), NULL, 10); |
| 442 | return 0; |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 443 | } |
| 444 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 445 | // This function will return an empty string if the value doesn't exist |
| 446 | string DataManager::GetStrValue(const string varName) |
| 447 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 448 | string retVal; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 449 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 450 | GetValue(varName, retVal); |
| 451 | return retVal; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | // This function will return 0 if the value doesn't exist |
| 455 | int DataManager::GetIntValue(const string varName) |
| 456 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 457 | string retVal; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 458 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 459 | GetValue(varName, retVal); |
| 460 | return atoi(retVal.c_str()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | int DataManager::SetValue(const string varName, string value, int persist /* = 0 */) |
| 464 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 465 | if (!mInitialized) |
| 466 | SetDefaultValues(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 467 | |
Xuefer | a163f15 | 2015-03-26 22:45:04 +0800 | [diff] [blame] | 468 | // Handle property |
| 469 | if (varName.length() > 9 && varName.substr(0, 9) == "property.") { |
| 470 | int ret = property_set(varName.substr(9).c_str(), value.c_str()); |
| 471 | if (ret) |
| 472 | LOGERR("Error setting property '%s' to '%s'\n", varName.substr(9).c_str(), value.c_str()); |
| 473 | return ret; |
| 474 | } |
| 475 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 476 | // Don't allow empty values or numerical starting values |
| 477 | if (varName.empty() || (varName[0] >= '0' && varName[0] <= '9')) |
| 478 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 479 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 480 | map<string, string>::iterator constChk; |
| 481 | constChk = mConstValues.find(varName); |
| 482 | if (constChk != mConstValues.end()) |
| 483 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 484 | |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 485 | pthread_mutex_lock(&m_valuesLock); |
| 486 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 487 | map<string, TStrIntPair>::iterator pos; |
| 488 | pos = mValues.find(varName); |
| 489 | if (pos == mValues.end()) |
| 490 | pos = (mValues.insert(TNameValuePair(varName, TStrIntPair(value, persist)))).first; |
| 491 | else |
| 492 | pos->second.first = value; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 493 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 494 | if (pos->second.second != 0) |
| 495 | SaveValues(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 496 | |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 497 | pthread_mutex_unlock(&m_valuesLock); |
| 498 | |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 499 | #ifndef TW_NO_SCREEN_TIMEOUT |
bigbiff bigbiff | f8e2f37 | 2013-02-27 20:50:43 -0500 | [diff] [blame] | 500 | if (varName == "tw_screen_timeout_secs") { |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 501 | blankTimer.setTime(atoi(value.c_str())); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 502 | } else |
| 503 | #endif |
| 504 | if (varName == "tw_storage_path") { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 505 | SetBackupFolder(); |
bigbiff bigbiff | f8e2f37 | 2013-02-27 20:50:43 -0500 | [diff] [blame] | 506 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 507 | gui_notifyVarChange(varName.c_str(), value.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 508 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | int DataManager::SetValue(const string varName, int value, int persist /* = 0 */) |
| 512 | { |
| 513 | ostringstream valStr; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 514 | valStr << value; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 515 | if (varName == "tw_use_external_storage") { |
| 516 | string str; |
| 517 | |
| 518 | if (GetIntValue(TW_HAS_DUAL_STORAGE) == 1) { |
| 519 | if (value == 0) { |
| 520 | str = GetStrValue(TW_INTERNAL_PATH); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 521 | } else { |
| 522 | str = GetStrValue(TW_EXTERNAL_PATH); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 523 | } |
| 524 | } else if (GetIntValue(TW_HAS_INTERNAL) == 1) |
| 525 | str = GetStrValue(TW_INTERNAL_PATH); |
| 526 | else |
| 527 | str = GetStrValue(TW_EXTERNAL_PATH); |
| 528 | |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 529 | SetValue("tw_storage_path", str); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 530 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 531 | return SetValue(varName, valStr.str(), persist); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | int DataManager::SetValue(const string varName, float value, int persist /* = 0 */) |
| 535 | { |
| 536 | ostringstream valStr; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 537 | valStr << value; |
| 538 | return SetValue(varName, valStr.str(), persist);; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 539 | } |
| 540 | |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 541 | int DataManager::SetValue(const string varName, unsigned long long value, int persist /* = 0 */) |
| 542 | { |
| 543 | ostringstream valStr; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 544 | valStr << value; |
| 545 | return SetValue(varName, valStr.str(), persist); |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 546 | } |
| 547 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 548 | int DataManager::SetProgress(float Fraction) { |
| 549 | return SetValue("ui_progress", (float) (Fraction * 100.0)); |
| 550 | } |
| 551 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 552 | int DataManager::ShowProgress(float Portion, float Seconds) |
| 553 | { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 554 | float Starting_Portion; |
| 555 | GetValue("ui_progress_portion", Starting_Portion); |
| 556 | if (SetValue("ui_progress_portion", (float)(Portion * 100.0) + Starting_Portion) != 0) |
| 557 | return -1; |
| 558 | if (SetValue("ui_progress_frames", Seconds * 30) != 0) |
| 559 | return -1; |
| 560 | return 0; |
| 561 | } |
| 562 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 563 | void DataManager::DumpValues() |
| 564 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 565 | map<string, TStrIntPair>::iterator iter; |
| 566 | gui_print("Data Manager dump - Values with leading X are persisted.\n"); |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 567 | pthread_mutex_lock(&m_valuesLock); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 568 | for (iter = mValues.begin(); iter != mValues.end(); ++iter) |
| 569 | gui_print("%c %s=%s\n", iter->second.second ? 'X' : ' ', iter->first.c_str(), iter->second.first.c_str()); |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 570 | pthread_mutex_unlock(&m_valuesLock); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 571 | } |
| 572 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 573 | void DataManager::update_tz_environment_variables(void) |
| 574 | { |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 575 | setenv("TZ", GetStrValue(TW_TIME_ZONE_VAR).c_str(), 1); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 576 | tzset(); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 577 | } |
| 578 | |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 579 | void DataManager::SetBackupFolder() |
| 580 | { |
| 581 | string str = GetCurrentStoragePath(); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 582 | TWPartition* partition = PartitionManager.Find_Partition_By_Path(str); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 583 | str += "/TWRP/BACKUPS/"; |
| 584 | |
| 585 | string dev_id; |
| 586 | GetValue("device_id", dev_id); |
| 587 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 588 | str += dev_id; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 589 | LOGINFO("Backup folder set to '%s'\n", str.c_str()); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 590 | SetValue(TW_BACKUPS_FOLDER_VAR, str, 0); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 591 | if (partition != NULL) { |
| 592 | SetValue("tw_storage_display_name", partition->Storage_Name); |
| 593 | char free_space[255]; |
| 594 | sprintf(free_space, "%llu", partition->Free / 1024 / 1024); |
| 595 | SetValue("tw_storage_free_size", free_space); |
| 596 | string zip_path, zip_root, storage_path; |
| 597 | GetValue(TW_ZIP_LOCATION_VAR, zip_path); |
| 598 | if (partition->Has_Data_Media) |
| 599 | storage_path = partition->Symlink_Mount_Point; |
| 600 | else |
| 601 | storage_path = partition->Storage_Path; |
| 602 | if (zip_path.size() < storage_path.size()) { |
| 603 | SetValue(TW_ZIP_LOCATION_VAR, storage_path); |
| 604 | } else { |
Dees Troy | c2e9bc7 | 2013-09-10 00:16:24 +0000 | [diff] [blame] | 605 | zip_root = TWFunc::Get_Root_Path(zip_path); |
Dees_Troy | 1872795 | 2013-06-20 15:24:48 -0500 | [diff] [blame] | 606 | if (zip_root != storage_path) { |
| 607 | LOGINFO("DataManager::SetBackupFolder zip path was %s changing to %s, %s\n", zip_path.c_str(), storage_path.c_str(), zip_root.c_str()); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 608 | SetValue(TW_ZIP_LOCATION_VAR, storage_path); |
Dees_Troy | 1872795 | 2013-06-20 15:24:48 -0500 | [diff] [blame] | 609 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 610 | } |
| 611 | } else { |
| 612 | if (PartitionManager.Fstab_Processed() != 0) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 613 | LOGERR("Storage partition '%s' not found\n", str.c_str()); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 614 | } |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 615 | } |
| 616 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 617 | void DataManager::SetDefaultValues() |
| 618 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 619 | string str, path; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 620 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 621 | get_device_id(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 622 | |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 623 | pthread_mutex_lock(&m_valuesLock); |
| 624 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 625 | mInitialized = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 626 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 627 | mConstValues.insert(make_pair("true", "1")); |
| 628 | mConstValues.insert(make_pair("false", "0")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 629 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 630 | mConstValues.insert(make_pair(TW_VERSION_VAR, TW_VERSION_STR)); |
Ethan Yonker | 03db326 | 2014-02-05 08:02:06 -0600 | [diff] [blame] | 631 | mValues.insert(make_pair("tw_button_vibrate", make_pair("80", 1))); |
| 632 | mValues.insert(make_pair("tw_keyboard_vibrate", make_pair("40", 1))); |
| 633 | mValues.insert(make_pair("tw_action_vibrate", make_pair("160", 1))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 634 | |
Vojtech Bocek | 93cb1ef | 2014-05-12 15:41:52 +0200 | [diff] [blame] | 635 | TWPartition *store = PartitionManager.Get_Default_Storage_Partition(); |
| 636 | if(store) |
| 637 | mValues.insert(make_pair("tw_storage_path", make_pair(store->Storage_Path.c_str(), 1))); |
| 638 | else |
| 639 | mValues.insert(make_pair("tw_storage_path", make_pair("/", 1))); |
| 640 | |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 641 | #ifdef TW_FORCE_CPUINFO_FOR_DEVICE_ID |
| 642 | printf("TW_FORCE_CPUINFO_FOR_DEVICE_ID := true\n"); |
| 643 | #endif |
| 644 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 645 | #ifdef BOARD_HAS_NO_REAL_SDCARD |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 646 | printf("BOARD_HAS_NO_REAL_SDCARD := true\n"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 647 | mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "0")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 648 | #else |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 649 | mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 650 | #endif |
| 651 | |
| 652 | #ifdef TW_INCLUDE_DUMLOCK |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 653 | printf("TW_INCLUDE_DUMLOCK := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 654 | mConstValues.insert(make_pair(TW_SHOW_DUMLOCK, "1")); |
| 655 | #else |
| 656 | mConstValues.insert(make_pair(TW_SHOW_DUMLOCK, "0")); |
| 657 | #endif |
| 658 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 659 | str = GetCurrentStoragePath(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 660 | SetValue(TW_ZIP_LOCATION_VAR, str.c_str(), 1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 661 | str += "/TWRP/BACKUPS/"; |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 662 | |
| 663 | string dev_id; |
| 664 | GetValue("device_id", dev_id); |
| 665 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 666 | str += dev_id; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 667 | SetValue(TW_BACKUPS_FOLDER_VAR, str, 0); |
| 668 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 669 | mConstValues.insert(make_pair(TW_REBOOT_SYSTEM, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 670 | #ifdef TW_NO_REBOOT_RECOVERY |
Talustus | 33ebf93 | 2013-02-02 14:11:14 +0100 | [diff] [blame] | 671 | printf("TW_NO_REBOOT_RECOVERY := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 672 | mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, "0")); |
| 673 | #else |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 674 | mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 675 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 676 | mConstValues.insert(make_pair(TW_REBOOT_POWEROFF, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 677 | #ifdef TW_NO_REBOOT_BOOTLOADER |
Talustus | 33ebf93 | 2013-02-02 14:11:14 +0100 | [diff] [blame] | 678 | printf("TW_NO_REBOOT_BOOTLOADER := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 679 | mConstValues.insert(make_pair(TW_REBOOT_BOOTLOADER, "0")); |
| 680 | #else |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 681 | mConstValues.insert(make_pair(TW_REBOOT_BOOTLOADER, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 682 | #endif |
| 683 | #ifdef RECOVERY_SDCARD_ON_DATA |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 684 | printf("RECOVERY_SDCARD_ON_DATA := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 685 | mConstValues.insert(make_pair(TW_HAS_DATA_MEDIA, "1")); |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 686 | mConstValues.insert(make_pair("tw_has_internal", "1")); |
| 687 | datamedia = true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 688 | #else |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 689 | mValues.insert(make_pair(TW_HAS_DATA_MEDIA, make_pair("0", 0))); |
| 690 | mValues.insert(make_pair("tw_has_internal", make_pair("0", 0))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 691 | #endif |
| 692 | #ifdef TW_NO_BATT_PERCENT |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 693 | printf("TW_NO_BATT_PERCENT := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 694 | mConstValues.insert(make_pair(TW_NO_BATTERY_PERCENT, "1")); |
| 695 | #else |
| 696 | mConstValues.insert(make_pair(TW_NO_BATTERY_PERCENT, "0")); |
| 697 | #endif |
Jenkins | 1710bf2 | 2014-10-02 20:22:21 -0400 | [diff] [blame] | 698 | #ifdef TW_NO_CPU_TEMP |
| 699 | printf("TW_NO_CPU_TEMP := true\n"); |
| 700 | mConstValues.insert(make_pair("tw_no_cpu_temp", "1")); |
| 701 | #else |
| 702 | string cpu_temp_file; |
| 703 | #ifdef TW_CUSTOM_CPU_TEMP_PATH |
| 704 | cpu_temp_file = EXPAND(TW_CUSTOM_CPU_TEMP_PATH); |
| 705 | #else |
| 706 | cpu_temp_file = "/sys/class/thermal/thermal_zone0/temp"; |
| 707 | #endif |
| 708 | if (TWFunc::Path_Exists(cpu_temp_file)) { |
| 709 | mConstValues.insert(make_pair("tw_no_cpu_temp", "0")); |
| 710 | } else { |
| 711 | LOGINFO("CPU temperature file '%s' not found, disabling CPU temp.\n", cpu_temp_file.c_str()); |
| 712 | mConstValues.insert(make_pair("tw_no_cpu_temp", "1")); |
| 713 | } |
| 714 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 715 | #ifdef TW_CUSTOM_POWER_BUTTON |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 716 | printf("TW_POWER_BUTTON := %s\n", EXPAND(TW_CUSTOM_POWER_BUTTON)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 717 | mConstValues.insert(make_pair(TW_POWER_BUTTON, EXPAND(TW_CUSTOM_POWER_BUTTON))); |
| 718 | #else |
| 719 | mConstValues.insert(make_pair(TW_POWER_BUTTON, "0")); |
| 720 | #endif |
| 721 | #ifdef TW_ALWAYS_RMRF |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 722 | printf("TW_ALWAYS_RMRF := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 723 | mConstValues.insert(make_pair(TW_RM_RF_VAR, "1")); |
| 724 | #endif |
| 725 | #ifdef TW_NEVER_UNMOUNT_SYSTEM |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 726 | printf("TW_NEVER_UNMOUNT_SYSTEM := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 727 | mConstValues.insert(make_pair(TW_DONT_UNMOUNT_SYSTEM, "1")); |
| 728 | #else |
| 729 | mConstValues.insert(make_pair(TW_DONT_UNMOUNT_SYSTEM, "0")); |
| 730 | #endif |
| 731 | #ifdef TW_NO_USB_STORAGE |
Dees_Troy | 6a042c8 | 2013-01-23 18:50:52 +0000 | [diff] [blame] | 732 | printf("TW_NO_USB_STORAGE := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 733 | mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "0")); |
| 734 | #else |
Dees_Troy | 6a042c8 | 2013-01-23 18:50:52 +0000 | [diff] [blame] | 735 | char lun_file[255]; |
| 736 | string Lun_File_str = CUSTOM_LUN_FILE; |
| 737 | size_t found = Lun_File_str.find("%"); |
| 738 | if (found != string::npos) { |
| 739 | sprintf(lun_file, CUSTOM_LUN_FILE, 0); |
| 740 | Lun_File_str = lun_file; |
| 741 | } |
| 742 | if (!TWFunc::Path_Exists(Lun_File_str)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 743 | LOGINFO("Lun file '%s' does not exist, USB storage mode disabled\n", Lun_File_str.c_str()); |
Dees_Troy | 6a042c8 | 2013-01-23 18:50:52 +0000 | [diff] [blame] | 744 | mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "0")); |
| 745 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 746 | LOGINFO("Lun file '%s'\n", Lun_File_str.c_str()); |
Dees_Troy | 6a042c8 | 2013-01-23 18:50:52 +0000 | [diff] [blame] | 747 | mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "1")); |
| 748 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 749 | #endif |
| 750 | #ifdef TW_INCLUDE_INJECTTWRP |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 751 | printf("TW_INCLUDE_INJECTTWRP := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 752 | mConstValues.insert(make_pair(TW_HAS_INJECTTWRP, "1")); |
| 753 | mValues.insert(make_pair(TW_INJECT_AFTER_ZIP, make_pair("1", 1))); |
| 754 | #else |
| 755 | mConstValues.insert(make_pair(TW_HAS_INJECTTWRP, "0")); |
| 756 | mValues.insert(make_pair(TW_INJECT_AFTER_ZIP, make_pair("0", 1))); |
| 757 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 758 | #ifdef TW_HAS_DOWNLOAD_MODE |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 759 | printf("TW_HAS_DOWNLOAD_MODE := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 760 | mConstValues.insert(make_pair(TW_DOWNLOAD_MODE, "1")); |
| 761 | #endif |
| 762 | #ifdef TW_INCLUDE_CRYPTO |
| 763 | mConstValues.insert(make_pair(TW_HAS_CRYPTO, "1")); |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 764 | printf("TW_INCLUDE_CRYPTO := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 765 | #endif |
| 766 | #ifdef TW_SDEXT_NO_EXT4 |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 767 | printf("TW_SDEXT_NO_EXT4 := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 768 | mConstValues.insert(make_pair(TW_SDEXT_DISABLE_EXT4, "1")); |
| 769 | #else |
| 770 | mConstValues.insert(make_pair(TW_SDEXT_DISABLE_EXT4, "0")); |
| 771 | #endif |
| 772 | |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 773 | #ifdef TW_HAS_NO_BOOT_PARTITION |
Dees_Troy | f100c94 | 2013-06-21 08:15:31 -0500 | [diff] [blame] | 774 | mValues.insert(make_pair("tw_backup_list", make_pair("/system;/data;", 1))); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 775 | #else |
Dees_Troy | f100c94 | 2013-06-21 08:15:31 -0500 | [diff] [blame] | 776 | mValues.insert(make_pair("tw_backup_list", make_pair("/system;/data;/boot;", 1))); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 777 | #endif |
| 778 | mConstValues.insert(make_pair(TW_MIN_SYSTEM_VAR, TW_MIN_SYSTEM_SIZE)); |
Dees Troy | b21cc64 | 2013-09-10 17:36:41 +0000 | [diff] [blame] | 779 | mValues.insert(make_pair(TW_BACKUP_NAME, make_pair("(Auto Generate)", 0))); |
bigbiff bigbiff | 7ce7f0c | 2013-01-25 09:54:04 -0500 | [diff] [blame] | 780 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 781 | mValues.insert(make_pair(TW_REBOOT_AFTER_FLASH_VAR, make_pair("0", 1))); |
| 782 | mValues.insert(make_pair(TW_SIGNED_ZIP_VERIFY_VAR, make_pair("0", 1))); |
| 783 | mValues.insert(make_pair(TW_FORCE_MD5_CHECK_VAR, make_pair("0", 1))); |
| 784 | mValues.insert(make_pair(TW_COLOR_THEME_VAR, make_pair("0", 1))); |
| 785 | mValues.insert(make_pair(TW_USE_COMPRESSION_VAR, make_pair("0", 1))); |
| 786 | mValues.insert(make_pair(TW_SHOW_SPAM_VAR, make_pair("0", 1))); |
Matt Mower | cf94db1 | 2015-04-08 13:09:13 -0500 | [diff] [blame] | 787 | mValues.insert(make_pair(TW_TIME_ZONE_VAR, make_pair("CST6CDT,M3.2.0,M11.1.0", 1))); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 788 | mValues.insert(make_pair(TW_SORT_FILES_BY_DATE_VAR, make_pair("0", 1))); |
| 789 | mValues.insert(make_pair(TW_GUI_SORT_ORDER, make_pair("1", 1))); |
| 790 | mValues.insert(make_pair(TW_RM_RF_VAR, make_pair("0", 1))); |
| 791 | mValues.insert(make_pair(TW_SKIP_MD5_CHECK_VAR, make_pair("0", 1))); |
| 792 | mValues.insert(make_pair(TW_SKIP_MD5_GENERATE_VAR, make_pair("0", 1))); |
| 793 | mValues.insert(make_pair(TW_SDEXT_SIZE, make_pair("512", 1))); |
| 794 | mValues.insert(make_pair(TW_SWAP_SIZE, make_pair("32", 1))); |
| 795 | mValues.insert(make_pair(TW_SDPART_FILE_SYSTEM, make_pair("ext3", 1))); |
Matt Mower | cf94db1 | 2015-04-08 13:09:13 -0500 | [diff] [blame] | 796 | mValues.insert(make_pair(TW_TIME_ZONE_GUISEL, make_pair("CST6;CDT,M3.2.0,M11.1.0", 1))); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 797 | mValues.insert(make_pair(TW_TIME_ZONE_GUIOFFSET, make_pair("0", 1))); |
| 798 | mValues.insert(make_pair(TW_TIME_ZONE_GUIDST, make_pair("1", 1))); |
| 799 | mValues.insert(make_pair(TW_ACTION_BUSY, make_pair("0", 0))); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 800 | mValues.insert(make_pair("tw_wipe_cache", make_pair("0", 0))); |
| 801 | mValues.insert(make_pair("tw_wipe_dalvik", make_pair("0", 0))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 802 | if (GetIntValue(TW_HAS_INTERNAL) == 1 && GetIntValue(TW_HAS_DATA_MEDIA) == 1 && GetIntValue(TW_HAS_EXTERNAL) == 0) |
| 803 | SetValue(TW_HAS_USB_STORAGE, 0, 0); |
| 804 | else |
| 805 | SetValue(TW_HAS_USB_STORAGE, 1, 0); |
| 806 | mValues.insert(make_pair(TW_ZIP_INDEX, make_pair("0", 0))); |
| 807 | mValues.insert(make_pair(TW_ZIP_QUEUE_COUNT, make_pair("0", 0))); |
| 808 | mValues.insert(make_pair(TW_FILENAME, make_pair("/sdcard", 0))); |
| 809 | mValues.insert(make_pair(TW_SIMULATE_ACTIONS, make_pair("0", 1))); |
| 810 | mValues.insert(make_pair(TW_SIMULATE_FAIL, make_pair("0", 1))); |
| 811 | mValues.insert(make_pair(TW_IS_ENCRYPTED, make_pair("0", 0))); |
| 812 | mValues.insert(make_pair(TW_IS_DECRYPTED, make_pair("0", 0))); |
| 813 | mValues.insert(make_pair(TW_CRYPTO_PASSWORD, make_pair("0", 0))); |
| 814 | mValues.insert(make_pair(TW_DATA_BLK_DEVICE, make_pair("0", 0))); |
| 815 | mValues.insert(make_pair("tw_terminal_state", make_pair("0", 0))); |
| 816 | mValues.insert(make_pair("tw_background_thread_running", make_pair("0", 0))); |
| 817 | mValues.insert(make_pair(TW_RESTORE_FILE_DATE, make_pair("0", 0))); |
bigbiff bigbiff | f8e2f37 | 2013-02-27 20:50:43 -0500 | [diff] [blame] | 818 | mValues.insert(make_pair("tw_military_time", make_pair("0", 1))); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 819 | #ifdef TW_NO_SCREEN_TIMEOUT |
| 820 | mValues.insert(make_pair("tw_screen_timeout_secs", make_pair("0", 1))); |
| 821 | mValues.insert(make_pair("tw_no_screen_timeout", make_pair("1", 1))); |
| 822 | #else |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 823 | mValues.insert(make_pair("tw_screen_timeout_secs", make_pair("60", 1))); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 824 | mValues.insert(make_pair("tw_no_screen_timeout", make_pair("0", 1))); |
| 825 | #endif |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 826 | mValues.insert(make_pair("tw_gui_done", make_pair("0", 0))); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 827 | mValues.insert(make_pair("tw_encrypt_backup", make_pair("0", 0))); |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 828 | #ifdef TW_BRIGHTNESS_PATH |
Ethan Yonker | 00028b4 | 2014-04-09 14:29:02 -0500 | [diff] [blame] | 829 | string findbright; |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 830 | if (strcmp(EXPAND(TW_BRIGHTNESS_PATH), "/nobrightness") != 0) { |
Ethan Yonker | 00028b4 | 2014-04-09 14:29:02 -0500 | [diff] [blame] | 831 | findbright = EXPAND(TW_BRIGHTNESS_PATH); |
| 832 | LOGINFO("TW_BRIGHTNESS_PATH := %s\n", findbright.c_str()); |
| 833 | if (!TWFunc::Path_Exists(findbright)) { |
| 834 | LOGINFO("Specified brightness file '%s' not found.\n", findbright.c_str()); |
| 835 | findbright = ""; |
| 836 | } |
| 837 | } |
| 838 | if (findbright.empty()) { |
| 839 | // Attempt to locate the brightness file |
| 840 | findbright = Find_File::Find("brightness", "/sys/class/backlight"); |
Ethan Yonker | 9c102b5 | 2014-04-15 11:06:18 -0500 | [diff] [blame] | 841 | if (findbright.empty()) findbright = Find_File::Find("brightness", "/sys/class/leds/lcd-backlight"); |
Ethan Yonker | 00028b4 | 2014-04-09 14:29:02 -0500 | [diff] [blame] | 842 | } |
| 843 | if (findbright.empty()) { |
| 844 | LOGINFO("Unable to locate brightness file\n"); |
| 845 | mConstValues.insert(make_pair("tw_has_brightnesss_file", "0")); |
| 846 | } else { |
| 847 | LOGINFO("Found brightness file at '%s'\n", findbright.c_str()); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 848 | mConstValues.insert(make_pair("tw_has_brightnesss_file", "1")); |
Ethan Yonker | 00028b4 | 2014-04-09 14:29:02 -0500 | [diff] [blame] | 849 | mConstValues.insert(make_pair("tw_brightness_file", findbright)); |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 850 | ostringstream maxVal; |
| 851 | maxVal << TW_MAX_BRIGHTNESS; |
| 852 | mConstValues.insert(make_pair("tw_brightness_max", maxVal.str())); |
| 853 | mValues.insert(make_pair("tw_brightness", make_pair(maxVal.str(), 1))); |
| 854 | mValues.insert(make_pair("tw_brightness_pct", make_pair("100", 1))); |
xNUTx | e85f02d | 2014-07-18 01:30:58 +0200 | [diff] [blame] | 855 | #ifdef TW_SECONDARY_BRIGHTNESS_PATH |
| 856 | string secondfindbright = EXPAND(TW_SECONDARY_BRIGHTNESS_PATH); |
| 857 | if (secondfindbright != "" && TWFunc::Path_Exists(secondfindbright)) { |
| 858 | LOGINFO("Will use a second brightness file at '%s'\n", secondfindbright.c_str()); |
| 859 | mConstValues.insert(make_pair("tw_secondary_brightness_file", secondfindbright)); |
| 860 | } else { |
| 861 | LOGINFO("Specified secondary brightness file '%s' not found.\n", secondfindbright.c_str()); |
| 862 | } |
| 863 | #endif |
Ethan Yonker | a18f108 | 2014-07-07 15:07:58 -0500 | [diff] [blame] | 864 | string max_bright = maxVal.str(); |
xNUTx | e85f02d | 2014-07-18 01:30:58 +0200 | [diff] [blame] | 865 | TWFunc::Set_Brightness(max_bright); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 866 | } |
| 867 | #endif |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 868 | mValues.insert(make_pair(TW_MILITARY_TIME, make_pair("0", 1))); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 869 | #ifndef TW_EXCLUDE_ENCRYPTED_BACKUPS |
| 870 | mValues.insert(make_pair("tw_include_encrypted_backup", make_pair("1", 0))); |
| 871 | #else |
| 872 | LOGINFO("TW_EXCLUDE_ENCRYPTED_BACKUPS := true\n"); |
| 873 | mValues.insert(make_pair("tw_include_encrypted_backup", make_pair("0", 0))); |
| 874 | #endif |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 875 | #ifdef TW_HAS_MTP |
| 876 | mConstValues.insert(make_pair("tw_has_mtp", "1")); |
| 877 | mValues.insert(make_pair("tw_mtp_enabled", make_pair("1", 1))); |
Ethan Yonker | c8743cf | 2014-09-03 21:16:40 -0500 | [diff] [blame] | 878 | mValues.insert(make_pair("tw_mtp_debug", make_pair("0", 1))); |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 879 | #else |
| 880 | LOGINFO("TW_EXCLUDE_MTP := true\n"); |
| 881 | mConstValues.insert(make_pair("tw_has_mtp", "0")); |
| 882 | mConstValues.insert(make_pair("tw_mtp_enabled", "0")); |
| 883 | #endif |
Ethan Yonker | 961d20e | 2015-06-29 14:00:03 -0500 | [diff] [blame] | 884 | mValues.insert(make_pair("tw_mount_system_ro", make_pair("2", 1))); |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 885 | mValues.insert(make_pair("tw_never_show_system_ro_page", make_pair("0", 1))); |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 886 | |
| 887 | pthread_mutex_unlock(&m_valuesLock); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | // Magic Values |
| 891 | int DataManager::GetMagicValue(const string varName, string& value) |
| 892 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 893 | // Handle special dynamic cases |
| 894 | if (varName == "tw_time") |
| 895 | { |
| 896 | char tmp[32]; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 897 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 898 | struct tm *current; |
| 899 | time_t now; |
| 900 | int tw_military_time; |
| 901 | now = time(0); |
| 902 | current = localtime(&now); |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 903 | GetValue(TW_MILITARY_TIME, tw_military_time); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 904 | if (current->tm_hour >= 12) |
| 905 | { |
| 906 | if (tw_military_time == 1) |
| 907 | sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min); |
| 908 | else |
| 909 | sprintf(tmp, "%d:%02d PM", current->tm_hour == 12 ? 12 : current->tm_hour - 12, current->tm_min); |
bigbiff bigbiff | 4efe9c3 | 2013-02-20 18:58:11 -0500 | [diff] [blame] | 910 | } |
bigbiff bigbiff | 4efe9c3 | 2013-02-20 18:58:11 -0500 | [diff] [blame] | 911 | else |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 912 | { |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 913 | if (tw_military_time == 1) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 914 | sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min); |
| 915 | else |
| 916 | sprintf(tmp, "%d:%02d AM", current->tm_hour == 0 ? 12 : current->tm_hour, current->tm_min); |
| 917 | } |
| 918 | value = tmp; |
| 919 | return 0; |
bigbiff bigbiff | 4efe9c3 | 2013-02-20 18:58:11 -0500 | [diff] [blame] | 920 | } |
Jenkins | 1710bf2 | 2014-10-02 20:22:21 -0400 | [diff] [blame] | 921 | else if (varName == "tw_cpu_temp") |
| 922 | { |
Agontuk | a29361a | 2015-04-22 14:42:59 +0600 | [diff] [blame] | 923 | int tw_no_cpu_temp; |
| 924 | GetValue("tw_no_cpu_temp", tw_no_cpu_temp); |
| 925 | if (tw_no_cpu_temp == 1) return -1; |
| 926 | |
Jenkins | 1710bf2 | 2014-10-02 20:22:21 -0400 | [diff] [blame] | 927 | string cpu_temp_file; |
| 928 | static unsigned long convert_temp = 0; |
| 929 | static time_t cpuSecCheck = 0; |
| 930 | int divisor = 0; |
| 931 | struct timeval curTime; |
| 932 | string results; |
| 933 | |
| 934 | gettimeofday(&curTime, NULL); |
| 935 | if (curTime.tv_sec > cpuSecCheck) |
| 936 | { |
| 937 | #ifdef TW_CUSTOM_CPU_TEMP_PATH |
| 938 | cpu_temp_file = EXPAND(TW_CUSTOM_CPU_TEMP_PATH); |
| 939 | if (TWFunc::read_file(cpu_temp_file, results) != 0) |
| 940 | return -1; |
| 941 | #else |
| 942 | cpu_temp_file = "/sys/class/thermal/thermal_zone0/temp"; |
| 943 | if (TWFunc::read_file(cpu_temp_file, results) != 0) |
| 944 | return -1; |
| 945 | #endif |
| 946 | convert_temp = strtoul(results.c_str(), NULL, 0) / 1000; |
| 947 | if (convert_temp <= 0) |
| 948 | convert_temp = strtoul(results.c_str(), NULL, 0); |
HandyMenny | b603345 | 2014-10-15 21:39:12 +0200 | [diff] [blame] | 949 | if (convert_temp >= 150) |
| 950 | convert_temp = strtoul(results.c_str(), NULL, 0) / 10; |
| 951 | cpuSecCheck = curTime.tv_sec + 5; |
Jenkins | 1710bf2 | 2014-10-02 20:22:21 -0400 | [diff] [blame] | 952 | } |
| 953 | value = TWFunc::to_string(convert_temp); |
| 954 | return 0; |
| 955 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 956 | else if (varName == "tw_battery") |
| 957 | { |
| 958 | char tmp[16]; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 959 | static char charging = ' '; |
| 960 | static int lastVal = -1; |
| 961 | static time_t nextSecCheck = 0; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 962 | struct timeval curTime; |
| 963 | gettimeofday(&curTime, NULL); |
| 964 | if (curTime.tv_sec > nextSecCheck) |
| 965 | { |
| 966 | char cap_s[4]; |
Dees_Troy | f33b490 | 2013-03-01 00:51:39 +0000 | [diff] [blame] | 967 | #ifdef TW_CUSTOM_BATTERY_PATH |
| 968 | string capacity_file = EXPAND(TW_CUSTOM_BATTERY_PATH); |
| 969 | capacity_file += "/capacity"; |
| 970 | FILE * cap = fopen(capacity_file.c_str(),"rt"); |
| 971 | #else |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 972 | FILE * cap = fopen("/sys/class/power_supply/battery/capacity","rt"); |
Dees_Troy | f33b490 | 2013-03-01 00:51:39 +0000 | [diff] [blame] | 973 | #endif |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 974 | if (cap){ |
| 975 | fgets(cap_s, 4, cap); |
| 976 | fclose(cap); |
| 977 | lastVal = atoi(cap_s); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 978 | if (lastVal > 100) lastVal = 101; |
| 979 | if (lastVal < 0) lastVal = 0; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 980 | } |
Dees_Troy | f33b490 | 2013-03-01 00:51:39 +0000 | [diff] [blame] | 981 | #ifdef TW_CUSTOM_BATTERY_PATH |
| 982 | string status_file = EXPAND(TW_CUSTOM_BATTERY_PATH); |
| 983 | status_file += "/status"; |
| 984 | cap = fopen(status_file.c_str(),"rt"); |
| 985 | #else |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 986 | cap = fopen("/sys/class/power_supply/battery/status","rt"); |
Dees_Troy | f33b490 | 2013-03-01 00:51:39 +0000 | [diff] [blame] | 987 | #endif |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 988 | if (cap) { |
| 989 | fgets(cap_s, 2, cap); |
| 990 | fclose(cap); |
| 991 | if (cap_s[0] == 'C') |
| 992 | charging = '+'; |
| 993 | else |
| 994 | charging = ' '; |
| 995 | } |
| 996 | nextSecCheck = curTime.tv_sec + 60; |
| 997 | } |
| 998 | |
| 999 | sprintf(tmp, "%i%%%c", lastVal, charging); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1000 | value = tmp; |
| 1001 | return 0; |
| 1002 | } |
| 1003 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1004 | } |
| 1005 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1006 | void DataManager::Output_Version(void) |
| 1007 | { |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1008 | string Path; |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1009 | char version[255]; |
| 1010 | |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1011 | if (!PartitionManager.Mount_By_Path("/cache", false)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1012 | LOGINFO("Unable to mount '%s' to write version number.\n", Path.c_str()); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1013 | return; |
| 1014 | } |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1015 | if (!TWFunc::Path_Exists("/cache/recovery/.")) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1016 | LOGINFO("Recreating /cache/recovery folder.\n"); |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1017 | if (mkdir("/cache/recovery", S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP) != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1018 | LOGERR("DataManager::Output_Version -- Unable to make /cache/recovery\n"); |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1019 | return; |
| 1020 | } |
| 1021 | } |
| 1022 | Path = "/cache/recovery/.version"; |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1023 | if (TWFunc::Path_Exists(Path)) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1024 | unlink(Path.c_str()); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1025 | } |
| 1026 | FILE *fp = fopen(Path.c_str(), "w"); |
| 1027 | if (fp == NULL) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1028 | LOGERR("Unable to open '%s'.\n", Path.c_str()); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1029 | return; |
| 1030 | } |
| 1031 | strcpy(version, TW_VERSION_STR); |
| 1032 | fwrite(version, sizeof(version[0]), strlen(version) / sizeof(version[0]), fp); |
| 1033 | fclose(fp); |
Dees_Troy | d93bda5 | 2013-07-03 19:55:19 +0000 | [diff] [blame] | 1034 | TWFunc::copy_file("/etc/recovery.fstab", "/cache/recovery/recovery.fstab", 0644); |
| 1035 | PartitionManager.Output_Storage_Fstab(); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1036 | sync(); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1037 | LOGINFO("Version number saved to '%s'\n", Path.c_str()); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1038 | } |
| 1039 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1040 | void DataManager::ReadSettingsFile(void) |
| 1041 | { |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 1042 | #ifndef TW_OEM_BUILD |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1043 | // Load up the values for TWRP - Sleep to let the card be ready |
| 1044 | char mkdir_path[255], settings_file[255]; |
| 1045 | int is_enc, has_dual, use_ext, has_data_media, has_ext; |
| 1046 | |
| 1047 | GetValue(TW_IS_ENCRYPTED, is_enc); |
| 1048 | GetValue(TW_HAS_DATA_MEDIA, has_data_media); |
| 1049 | if (is_enc == 1 && has_data_media == 1) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1050 | LOGINFO("Cannot load settings -- encrypted.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1051 | return; |
| 1052 | } |
| 1053 | |
| 1054 | memset(mkdir_path, 0, sizeof(mkdir_path)); |
| 1055 | memset(settings_file, 0, sizeof(settings_file)); |
Vojtech Bocek | fda239b | 2015-01-07 22:55:13 +0100 | [diff] [blame] | 1056 | sprintf(mkdir_path, "%s/TWRP", GetSettingsStoragePath().c_str()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1057 | sprintf(settings_file, "%s/.twrps", mkdir_path); |
| 1058 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1059 | if (!PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1060 | { |
| 1061 | usleep(500000); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1062 | if (!PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1063 | LOGERR("Unable to mount %s when trying to read settings file.\n", settings_file); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | mkdir(mkdir_path, 0777); |
| 1067 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1068 | LOGINFO("Attempt to load settings from settings file...\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1069 | LoadValues(settings_file); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1070 | Output_Version(); |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 1071 | #endif // ifdef TW_OEM_BUILD |
Ethan Yonker | 7af51ce | 2014-04-04 13:33:30 -0500 | [diff] [blame] | 1072 | PartitionManager.Mount_All_Storage(); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1073 | update_tz_environment_variables(); |
xNUTx | e85f02d | 2014-07-18 01:30:58 +0200 | [diff] [blame] | 1074 | #ifdef TW_MAX_BRIGHTNESS |
| 1075 | if (GetStrValue("tw_brightness_path") != "/nobrightness") { |
| 1076 | TWFunc::Set_Brightness(GetStrValue("tw_brightness")); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 1077 | } |
xNUTx | e85f02d | 2014-07-18 01:30:58 +0200 | [diff] [blame] | 1078 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | string DataManager::GetCurrentStoragePath(void) |
| 1082 | { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1083 | return GetStrValue("tw_storage_path"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1084 | } |
| 1085 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1086 | string DataManager::GetSettingsStoragePath(void) |
| 1087 | { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1088 | return GetStrValue("tw_settings_path"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1089 | } |
| 1090 | |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 1091 | void DataManager::Vibrate(const string varName) |
| 1092 | { |
| 1093 | int vib_value = 0; |
| 1094 | GetValue(varName, vib_value); |
| 1095 | if (vib_value) { |
| 1096 | vibrate(vib_value); |
| 1097 | } |
| 1098 | } |