Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/input.h> |
| 18 | #include <pthread.h> |
| 19 | #include <stdarg.h> |
| 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/time.h> |
| 26 | #include <sys/mman.h> |
| 27 | #include <sys/types.h> |
| 28 | #include <sys/ioctl.h> |
| 29 | #include <time.h> |
| 30 | #include <unistd.h> |
| 31 | #include <stdlib.h> |
| 32 | |
| 33 | #include <string> |
| 34 | #include <utility> |
| 35 | #include <map> |
| 36 | #include <fstream> |
| 37 | #include <sstream> |
| 38 | |
| 39 | #include "variables.h" |
| 40 | #include "data.hpp" |
| 41 | #include "partitions.hpp" |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 42 | #include "twrp-functions.hpp" |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 43 | #include "gui/blanktimer.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 44 | |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 45 | #ifdef TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID |
| 46 | #include "cutils/properties.h" |
| 47 | #endif |
| 48 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 49 | extern "C" |
| 50 | { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 51 | #include "twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 52 | #include "data.h" |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 53 | #include "gui/pages.h" |
| 54 | |
| 55 | void gui_notifyVarChange(const char *name, const char* value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | #define FILE_VERSION 0x00010001 |
| 59 | |
| 60 | using namespace std; |
| 61 | |
| 62 | map<string, DataManager::TStrIntPair> DataManager::mValues; |
| 63 | map<string, string> DataManager::mConstValues; |
| 64 | string DataManager::mBackingFile; |
| 65 | int DataManager::mInitialized = 0; |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 66 | extern blanktimer blankTimer; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 67 | |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 68 | // Device ID functions |
| 69 | void DataManager::sanitize_device_id(char* device_id) { |
| 70 | const char* whitelist ="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-._"; |
| 71 | char str[50]; |
| 72 | char* c = str; |
| 73 | |
| 74 | strcpy(str, device_id); |
| 75 | memset(device_id, 0, sizeof(device_id)); |
| 76 | while (*c) { |
| 77 | if (strchr(whitelist, *c)) |
| 78 | strncat(device_id, c, 1); |
| 79 | c++; |
| 80 | } |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | #define CMDLINE_SERIALNO "androidboot.serialno=" |
| 85 | #define CMDLINE_SERIALNO_LEN (strlen(CMDLINE_SERIALNO)) |
| 86 | #define CPUINFO_SERIALNO "Serial" |
| 87 | #define CPUINFO_SERIALNO_LEN (strlen(CPUINFO_SERIALNO)) |
| 88 | #define CPUINFO_HARDWARE "Hardware" |
| 89 | #define CPUINFO_HARDWARE_LEN (strlen(CPUINFO_HARDWARE)) |
| 90 | |
| 91 | void DataManager::get_device_id(void) { |
| 92 | FILE *fp; |
| 93 | char line[2048]; |
| 94 | char hardware_id[32], device_id[64]; |
| 95 | char* token; |
| 96 | |
| 97 | // Assign a blank device_id to start with |
| 98 | device_id[0] = 0; |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 99 | |
| 100 | #ifdef TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID |
| 101 | // Now we'll use product_model_hardwareid as device id |
| 102 | char model_id[PROPERTY_VALUE_MAX]; |
| 103 | property_get("ro.product.model", model_id, "error"); |
| 104 | if (strcmp(model_id,"error") != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 105 | LOGINFO("=> product model: '%s'\n", model_id); |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 106 | // Replace spaces with underscores |
| 107 | for(int i = 0; i < strlen(model_id); i++) { |
| 108 | if(model_id[i] == ' ') |
| 109 | model_id[i] = '_'; |
| 110 | } |
| 111 | strcpy(device_id, model_id); |
| 112 | if (hardware_id[0] != 0) { |
| 113 | strcat(device_id, "_"); |
| 114 | strcat(device_id, hardware_id); |
| 115 | } |
| 116 | sanitize_device_id((char *)device_id); |
| 117 | mConstValues.insert(make_pair("device_id", device_id)); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 118 | LOGINFO("=> using device id: '%s'\n", device_id); |
Anatoly Smaznov | 10c11f6 | 2013-02-12 13:33:40 +0700 | [diff] [blame] | 119 | return; |
| 120 | } |
| 121 | #endif |
| 122 | |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 123 | #ifndef TW_FORCE_CPUINFO_FOR_DEVICE_ID |
| 124 | // First, try the cmdline to see if the serial number was supplied |
| 125 | fp = fopen("/proc/cmdline", "rt"); |
| 126 | if (fp != NULL) |
| 127 | { |
| 128 | // First step, read the line. For cmdline, it's one long line |
| 129 | fgets(line, sizeof(line), fp); |
| 130 | fclose(fp); |
| 131 | |
| 132 | // Now, let's tokenize the string |
| 133 | token = strtok(line, " "); |
| 134 | |
| 135 | // Let's walk through the line, looking for the CMDLINE_SERIALNO token |
| 136 | while (token) |
| 137 | { |
| 138 | // We don't need to verify the length of token, because if it's too short, it will mismatch CMDLINE_SERIALNO at the NULL |
| 139 | if (memcmp(token, CMDLINE_SERIALNO, CMDLINE_SERIALNO_LEN) == 0) |
| 140 | { |
| 141 | // We found the serial number! |
| 142 | strcpy(device_id, token + CMDLINE_SERIALNO_LEN); |
| 143 | sanitize_device_id((char *)device_id); |
| 144 | mConstValues.insert(make_pair("device_id", device_id)); |
| 145 | return; |
| 146 | } |
| 147 | token = strtok(NULL, " "); |
| 148 | } |
| 149 | } |
| 150 | #endif |
| 151 | // Now we'll try cpuinfo for a serial number |
| 152 | fp = fopen("/proc/cpuinfo", "rt"); |
| 153 | if (fp != NULL) |
| 154 | { |
| 155 | while (fgets(line, sizeof(line), fp) != NULL) { // First step, read the line. |
| 156 | if (memcmp(line, CPUINFO_SERIALNO, CPUINFO_SERIALNO_LEN) == 0) // check the beginning of the line for "Serial" |
| 157 | { |
| 158 | // We found the serial number! |
| 159 | token = line + CPUINFO_SERIALNO_LEN; // skip past "Serial" |
| 160 | while ((*token > 0 && *token <= 32 ) || *token == ':') token++; // skip over all spaces and the colon |
| 161 | if (*token != 0) { |
| 162 | token[30] = 0; |
| 163 | if (token[strlen(token)-1] == 10) { // checking for endline chars and dropping them from the end of the string if needed |
| 164 | memset(device_id, 0, sizeof(device_id)); |
| 165 | strncpy(device_id, token, strlen(token) - 1); |
| 166 | } else { |
| 167 | strcpy(device_id, token); |
| 168 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 169 | LOGINFO("=> serial from cpuinfo: '%s'\n", device_id); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 170 | fclose(fp); |
| 171 | sanitize_device_id((char *)device_id); |
| 172 | mConstValues.insert(make_pair("device_id", device_id)); |
| 173 | return; |
| 174 | } |
| 175 | } else if (memcmp(line, CPUINFO_HARDWARE, CPUINFO_HARDWARE_LEN) == 0) {// We're also going to look for the hardware line in cpuinfo and save it for later in case we don't find the device ID |
| 176 | // We found the hardware ID |
| 177 | token = line + CPUINFO_HARDWARE_LEN; // skip past "Hardware" |
| 178 | while ((*token > 0 && *token <= 32 ) || *token == ':') token++; // skip over all spaces and the colon |
| 179 | if (*token != 0) { |
| 180 | token[30] = 0; |
| 181 | if (token[strlen(token)-1] == 10) { // checking for endline chars and dropping them from the end of the string if needed |
| 182 | memset(hardware_id, 0, sizeof(hardware_id)); |
| 183 | strncpy(hardware_id, token, strlen(token) - 1); |
| 184 | } else { |
| 185 | strcpy(hardware_id, token); |
| 186 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 187 | LOGINFO("=> hardware id from cpuinfo: '%s'\n", hardware_id); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | } |
| 191 | fclose(fp); |
| 192 | } |
| 193 | |
| 194 | if (hardware_id[0] != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 195 | LOGINFO("\nusing hardware id for device id: '%s'\n", hardware_id); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 196 | strcpy(device_id, hardware_id); |
| 197 | sanitize_device_id((char *)device_id); |
| 198 | mConstValues.insert(make_pair("device_id", device_id)); |
| 199 | return; |
| 200 | } |
| 201 | |
| 202 | strcpy(device_id, "serialno"); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 203 | LOGERR("=> device id not found, using '%s'.", device_id); |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 204 | mConstValues.insert(make_pair("device_id", device_id)); |
| 205 | return; |
| 206 | } |
| 207 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 208 | int DataManager::ResetDefaults() |
| 209 | { |
| 210 | mValues.clear(); |
| 211 | mConstValues.clear(); |
| 212 | SetDefaultValues(); |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | int DataManager::LoadValues(const string filename) |
| 217 | { |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 218 | string str, dev_id; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 219 | |
| 220 | if (!mInitialized) |
| 221 | SetDefaultValues(); |
| 222 | |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 223 | GetValue("device_id", dev_id); |
| 224 | // Save off the backing file for set operations |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 225 | mBackingFile = filename; |
| 226 | |
| 227 | // Read in the file, if possible |
| 228 | FILE* in = fopen(filename.c_str(), "rb"); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 229 | if (!in) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 230 | LOGINFO("Settings file '%s' not found.\n", filename.c_str()); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 231 | return 0; |
| 232 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 233 | LOGINFO("Loading settings from '%s'.\n", filename.c_str()); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 234 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 235 | |
| 236 | int file_version; |
| 237 | if (fread(&file_version, 1, sizeof(int), in) != sizeof(int)) goto error; |
| 238 | if (file_version != FILE_VERSION) goto error; |
| 239 | |
| 240 | while (!feof(in)) |
| 241 | { |
| 242 | string Name; |
| 243 | string Value; |
| 244 | unsigned short length; |
| 245 | char array[512]; |
| 246 | |
| 247 | if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error; |
| 248 | if (length >= 512) goto error; |
| 249 | if (fread(array, 1, length, in) != length) goto error; |
| 250 | Name = array; |
| 251 | |
| 252 | if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error; |
| 253 | if (length >= 512) goto error; |
| 254 | if (fread(array, 1, length, in) != length) goto error; |
| 255 | Value = array; |
| 256 | |
| 257 | map<string, TStrIntPair>::iterator pos; |
| 258 | |
| 259 | pos = mValues.find(Name); |
| 260 | if (pos != mValues.end()) |
| 261 | { |
| 262 | pos->second.first = Value; |
| 263 | pos->second.second = 1; |
| 264 | } |
| 265 | else |
| 266 | mValues.insert(TNameValuePair(Name, TStrIntPair(Value, 1))); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 267 | if (Name == "tw_screen_timeout_secs") |
| 268 | blankTimer.setTime(atoi(Value.c_str())); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 269 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 270 | error: |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 271 | fclose(in); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 272 | string current = GetCurrentStoragePath(); |
| 273 | string settings = GetSettingsStoragePath(); |
| 274 | if (current != settings && !PartitionManager.Mount_By_Path(current, false)) { |
| 275 | SetValue("tw_storage_path", settings); |
| 276 | } else { |
| 277 | SetBackupFolder(); |
| 278 | } |
| 279 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | int DataManager::Flush() |
| 283 | { |
| 284 | return SaveValues(); |
| 285 | } |
| 286 | |
| 287 | int DataManager::SaveValues() |
| 288 | { |
| 289 | if (mBackingFile.empty()) return -1; |
| 290 | |
| 291 | string mount_path = GetSettingsStoragePath(); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 292 | PartitionManager.Mount_By_Path(mount_path.c_str(), 1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 293 | |
| 294 | FILE* out = fopen(mBackingFile.c_str(), "wb"); |
| 295 | if (!out) return -1; |
| 296 | |
| 297 | int file_version = FILE_VERSION; |
| 298 | fwrite(&file_version, 1, sizeof(int), out); |
| 299 | |
| 300 | map<string, TStrIntPair>::iterator iter; |
| 301 | for (iter = mValues.begin(); iter != mValues.end(); ++iter) |
| 302 | { |
| 303 | // Save only the persisted data |
| 304 | if (iter->second.second != 0) |
| 305 | { |
| 306 | unsigned short length = (unsigned short) iter->first.length() + 1; |
| 307 | fwrite(&length, 1, sizeof(unsigned short), out); |
| 308 | fwrite(iter->first.c_str(), 1, length, out); |
| 309 | length = (unsigned short) iter->second.first.length() + 1; |
| 310 | fwrite(&length, 1, sizeof(unsigned short), out); |
| 311 | fwrite(iter->second.first.c_str(), 1, length, out); |
| 312 | } |
| 313 | } |
| 314 | fclose(out); |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | int DataManager::GetValue(const string varName, string& value) |
| 319 | { |
| 320 | string localStr = varName; |
| 321 | |
| 322 | if (!mInitialized) |
| 323 | SetDefaultValues(); |
| 324 | |
| 325 | // Strip off leading and trailing '%' if provided |
| 326 | if (localStr.length() > 2 && localStr[0] == '%' && localStr[localStr.length()-1] == '%') |
| 327 | { |
| 328 | localStr.erase(0, 1); |
| 329 | localStr.erase(localStr.length() - 1, 1); |
| 330 | } |
| 331 | |
| 332 | // Handle magic values |
| 333 | if (GetMagicValue(localStr, value) == 0) return 0; |
| 334 | |
| 335 | map<string, string>::iterator constPos; |
| 336 | constPos = mConstValues.find(localStr); |
| 337 | if (constPos != mConstValues.end()) |
| 338 | { |
| 339 | value = constPos->second; |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | map<string, TStrIntPair>::iterator pos; |
| 344 | pos = mValues.find(localStr); |
| 345 | if (pos == mValues.end()) |
| 346 | return -1; |
| 347 | |
| 348 | value = pos->second.first; |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | int DataManager::GetValue(const string varName, int& value) |
| 353 | { |
| 354 | string data; |
| 355 | |
| 356 | if (GetValue(varName,data) != 0) |
| 357 | return -1; |
| 358 | |
| 359 | value = atoi(data.c_str()); |
| 360 | return 0; |
| 361 | } |
| 362 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 363 | int DataManager::GetValue(const string varName, float& value) |
| 364 | { |
| 365 | string data; |
| 366 | |
| 367 | if (GetValue(varName,data) != 0) |
| 368 | return -1; |
| 369 | |
| 370 | value = atof(data.c_str()); |
| 371 | return 0; |
| 372 | } |
| 373 | |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 374 | unsigned long long DataManager::GetValue(const string varName, unsigned long long& value) |
| 375 | { |
| 376 | string data; |
| 377 | |
| 378 | if (GetValue(varName,data) != 0) |
| 379 | return -1; |
| 380 | |
| 381 | value = strtoull(data.c_str(), NULL, 10); |
| 382 | return 0; |
| 383 | } |
| 384 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 385 | // This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str |
| 386 | string& DataManager::GetValueRef(const string varName) |
| 387 | { |
| 388 | if (!mInitialized) |
| 389 | SetDefaultValues(); |
| 390 | |
| 391 | map<string, string>::iterator constPos; |
| 392 | constPos = mConstValues.find(varName); |
| 393 | if (constPos != mConstValues.end()) |
| 394 | return constPos->second; |
| 395 | |
| 396 | map<string, TStrIntPair>::iterator pos; |
| 397 | pos = mValues.find(varName); |
| 398 | if (pos == mValues.end()) |
| 399 | pos = (mValues.insert(TNameValuePair(varName, TStrIntPair("", 0)))).first; |
| 400 | |
| 401 | return pos->second.first; |
| 402 | } |
| 403 | |
| 404 | // This function will return an empty string if the value doesn't exist |
| 405 | string DataManager::GetStrValue(const string varName) |
| 406 | { |
| 407 | string retVal; |
| 408 | |
| 409 | GetValue(varName, retVal); |
| 410 | return retVal; |
| 411 | } |
| 412 | |
| 413 | // This function will return 0 if the value doesn't exist |
| 414 | int DataManager::GetIntValue(const string varName) |
| 415 | { |
| 416 | string retVal; |
| 417 | |
| 418 | GetValue(varName, retVal); |
| 419 | return atoi(retVal.c_str()); |
| 420 | } |
| 421 | |
| 422 | int DataManager::SetValue(const string varName, string value, int persist /* = 0 */) |
| 423 | { |
| 424 | if (!mInitialized) |
| 425 | SetDefaultValues(); |
| 426 | |
| 427 | // Don't allow empty values or numerical starting values |
| 428 | if (varName.empty() || (varName[0] >= '0' && varName[0] <= '9')) |
| 429 | return -1; |
| 430 | |
| 431 | map<string, string>::iterator constChk; |
| 432 | constChk = mConstValues.find(varName); |
| 433 | if (constChk != mConstValues.end()) |
| 434 | return -1; |
| 435 | |
| 436 | map<string, TStrIntPair>::iterator pos; |
| 437 | pos = mValues.find(varName); |
| 438 | if (pos == mValues.end()) |
| 439 | pos = (mValues.insert(TNameValuePair(varName, TStrIntPair(value, persist)))).first; |
| 440 | else |
| 441 | pos->second.first = value; |
| 442 | |
| 443 | if (pos->second.second != 0) |
| 444 | SaveValues(); |
bigbiff bigbiff | f8e2f37 | 2013-02-27 20:50:43 -0500 | [diff] [blame] | 445 | if (varName == "tw_screen_timeout_secs") { |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 446 | blankTimer.setTime(atoi(value.c_str())); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 447 | } else if (varName == "tw_storage_path") { |
| 448 | SetBackupFolder(); |
bigbiff bigbiff | f8e2f37 | 2013-02-27 20:50:43 -0500 | [diff] [blame] | 449 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 450 | gui_notifyVarChange(varName.c_str(), value.c_str()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | int DataManager::SetValue(const string varName, int value, int persist /* = 0 */) |
| 455 | { |
| 456 | ostringstream valStr; |
| 457 | valStr << value; |
| 458 | if (varName == "tw_use_external_storage") { |
| 459 | string str; |
| 460 | |
| 461 | if (GetIntValue(TW_HAS_DUAL_STORAGE) == 1) { |
| 462 | if (value == 0) { |
| 463 | str = GetStrValue(TW_INTERNAL_PATH); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 464 | } else { |
| 465 | str = GetStrValue(TW_EXTERNAL_PATH); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 466 | } |
| 467 | } else if (GetIntValue(TW_HAS_INTERNAL) == 1) |
| 468 | str = GetStrValue(TW_INTERNAL_PATH); |
| 469 | else |
| 470 | str = GetStrValue(TW_EXTERNAL_PATH); |
| 471 | |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 472 | SetValue("tw_storage_path", str); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 473 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 474 | return SetValue(varName, valStr.str(), persist); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | int DataManager::SetValue(const string varName, float value, int persist /* = 0 */) |
| 478 | { |
| 479 | ostringstream valStr; |
| 480 | valStr << value; |
| 481 | return SetValue(varName, valStr.str(), persist);; |
| 482 | } |
| 483 | |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 484 | int DataManager::SetValue(const string varName, unsigned long long value, int persist /* = 0 */) |
| 485 | { |
| 486 | ostringstream valStr; |
| 487 | valStr << value; |
| 488 | return SetValue(varName, valStr.str(), persist);; |
| 489 | } |
| 490 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 491 | int DataManager::SetProgress(float Fraction) { |
| 492 | return SetValue("ui_progress", (float) (Fraction * 100.0)); |
| 493 | } |
| 494 | |
| 495 | int DataManager::ShowProgress(float Portion, float Seconds) { |
| 496 | float Starting_Portion; |
| 497 | GetValue("ui_progress_portion", Starting_Portion); |
| 498 | if (SetValue("ui_progress_portion", (float)(Portion * 100.0) + Starting_Portion) != 0) |
| 499 | return -1; |
| 500 | if (SetValue("ui_progress_frames", Seconds * 30) != 0) |
| 501 | return -1; |
| 502 | return 0; |
| 503 | } |
| 504 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 505 | void DataManager::DumpValues() |
| 506 | { |
| 507 | map<string, TStrIntPair>::iterator iter; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 508 | gui_print("Data Manager dump - Values with leading X are persisted.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 509 | for (iter = mValues.begin(); iter != mValues.end(); ++iter) |
| 510 | { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 511 | gui_print("%c %s=%s\n", iter->second.second ? 'X' : ' ', iter->first.c_str(), iter->second.first.c_str()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 515 | void DataManager::update_tz_environment_variables(void) { |
| 516 | setenv("TZ", DataManager_GetStrValue(TW_TIME_ZONE_VAR), 1); |
| 517 | tzset(); |
| 518 | } |
| 519 | |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 520 | void DataManager::SetBackupFolder() |
| 521 | { |
| 522 | string str = GetCurrentStoragePath(); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 523 | TWPartition* partition = PartitionManager.Find_Partition_By_Path(str); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 524 | str += "/TWRP/BACKUPS/"; |
| 525 | |
| 526 | string dev_id; |
| 527 | GetValue("device_id", dev_id); |
| 528 | |
| 529 | str += dev_id; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 530 | LOGINFO("Backup folder set to '%s'\n", str.c_str()); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 531 | SetValue(TW_BACKUPS_FOLDER_VAR, str, 0); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 532 | if (partition != NULL) { |
| 533 | SetValue("tw_storage_display_name", partition->Storage_Name); |
| 534 | char free_space[255]; |
| 535 | sprintf(free_space, "%llu", partition->Free / 1024 / 1024); |
| 536 | SetValue("tw_storage_free_size", free_space); |
| 537 | string zip_path, zip_root, storage_path; |
| 538 | GetValue(TW_ZIP_LOCATION_VAR, zip_path); |
| 539 | if (partition->Has_Data_Media) |
| 540 | storage_path = partition->Symlink_Mount_Point; |
| 541 | else |
| 542 | storage_path = partition->Storage_Path; |
| 543 | if (zip_path.size() < storage_path.size()) { |
| 544 | SetValue(TW_ZIP_LOCATION_VAR, storage_path); |
| 545 | } else { |
| 546 | zip_root= zip_path; |
| 547 | zip_root.resize(storage_path.size() + 1); |
| 548 | if (zip_root != storage_path) |
| 549 | SetValue(TW_ZIP_LOCATION_VAR, storage_path); |
| 550 | } |
| 551 | } else { |
| 552 | if (PartitionManager.Fstab_Processed() != 0) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 553 | LOGERR("Storage partition '%s' not found\n", str.c_str()); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 554 | } |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 555 | } |
| 556 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 557 | void DataManager::SetDefaultValues() |
| 558 | { |
| 559 | string str, path; |
| 560 | |
| 561 | get_device_id(); |
| 562 | |
| 563 | mInitialized = 1; |
| 564 | |
| 565 | mConstValues.insert(make_pair("true", "1")); |
| 566 | mConstValues.insert(make_pair("false", "0")); |
| 567 | |
| 568 | mConstValues.insert(make_pair(TW_VERSION_VAR, TW_VERSION_STR)); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 569 | mValues.insert(make_pair("tw_storage_path", make_pair("/", 1))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 570 | |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 571 | #ifdef TW_FORCE_CPUINFO_FOR_DEVICE_ID |
| 572 | printf("TW_FORCE_CPUINFO_FOR_DEVICE_ID := true\n"); |
| 573 | #endif |
| 574 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 575 | #ifdef BOARD_HAS_NO_REAL_SDCARD |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 576 | printf("BOARD_HAS_NO_REAL_SDCARD := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 577 | mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "0")); |
| 578 | #else |
| 579 | mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "1")); |
| 580 | #endif |
| 581 | |
| 582 | #ifdef TW_INCLUDE_DUMLOCK |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 583 | printf("TW_INCLUDE_DUMLOCK := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 584 | mConstValues.insert(make_pair(TW_SHOW_DUMLOCK, "1")); |
| 585 | #else |
| 586 | mConstValues.insert(make_pair(TW_SHOW_DUMLOCK, "0")); |
| 587 | #endif |
| 588 | |
| 589 | #ifdef TW_INTERNAL_STORAGE_PATH |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 590 | LOGINFO("Internal path defined: '%s'\n", EXPAND(TW_INTERNAL_STORAGE_PATH)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 591 | mValues.insert(make_pair(TW_USE_EXTERNAL_STORAGE, make_pair("0", 1))); |
| 592 | mConstValues.insert(make_pair(TW_HAS_INTERNAL, "1")); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 593 | mValues.insert(make_pair(TW_INTERNAL_PATH, make_pair(EXPAND(TW_INTERNAL_STORAGE_PATH), 0))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 594 | mConstValues.insert(make_pair(TW_INTERNAL_LABEL, EXPAND(TW_INTERNAL_STORAGE_MOUNT_POINT))); |
| 595 | path.clear(); |
| 596 | path = "/"; |
| 597 | path += EXPAND(TW_INTERNAL_STORAGE_MOUNT_POINT); |
| 598 | mConstValues.insert(make_pair(TW_INTERNAL_MOUNT, path)); |
| 599 | #ifdef TW_EXTERNAL_STORAGE_PATH |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 600 | LOGINFO("External path defined: '%s'\n", EXPAND(TW_EXTERNAL_STORAGE_PATH)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 601 | // Device has dual storage |
| 602 | mConstValues.insert(make_pair(TW_HAS_DUAL_STORAGE, "1")); |
| 603 | mConstValues.insert(make_pair(TW_HAS_EXTERNAL, "1")); |
| 604 | mConstValues.insert(make_pair(TW_EXTERNAL_PATH, EXPAND(TW_EXTERNAL_STORAGE_PATH))); |
| 605 | mConstValues.insert(make_pair(TW_EXTERNAL_LABEL, EXPAND(TW_EXTERNAL_STORAGE_MOUNT_POINT))); |
| 606 | mValues.insert(make_pair(TW_ZIP_EXTERNAL_VAR, make_pair(EXPAND(TW_EXTERNAL_STORAGE_PATH), 1))); |
| 607 | path.clear(); |
| 608 | path = "/"; |
| 609 | path += EXPAND(TW_EXTERNAL_STORAGE_MOUNT_POINT); |
| 610 | mConstValues.insert(make_pair(TW_EXTERNAL_MOUNT, path)); |
| 611 | if (strcmp(EXPAND(TW_EXTERNAL_STORAGE_PATH), "/sdcard") == 0) { |
| 612 | mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/emmc", 1))); |
| 613 | } else { |
| 614 | mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/sdcard", 1))); |
| 615 | } |
| 616 | #else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 617 | LOGINFO("Just has internal storage.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 618 | // Just has internal storage |
| 619 | mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/sdcard", 1))); |
| 620 | mConstValues.insert(make_pair(TW_HAS_DUAL_STORAGE, "0")); |
| 621 | mConstValues.insert(make_pair(TW_HAS_EXTERNAL, "0")); |
| 622 | mConstValues.insert(make_pair(TW_EXTERNAL_PATH, "0")); |
| 623 | mConstValues.insert(make_pair(TW_EXTERNAL_MOUNT, "0")); |
| 624 | mConstValues.insert(make_pair(TW_EXTERNAL_LABEL, "0")); |
| 625 | #endif |
| 626 | #else |
| 627 | #ifdef RECOVERY_SDCARD_ON_DATA |
| 628 | #ifdef TW_EXTERNAL_STORAGE_PATH |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 629 | LOGINFO("Has /data/media + external storage in '%s'\n", EXPAND(TW_EXTERNAL_STORAGE_PATH)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 630 | // Device has /data/media + external storage |
| 631 | mConstValues.insert(make_pair(TW_HAS_DUAL_STORAGE, "1")); |
| 632 | #else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 633 | LOGINFO("Single storage only -- data/media.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 634 | // Device just has external storage |
| 635 | mConstValues.insert(make_pair(TW_HAS_DUAL_STORAGE, "0")); |
| 636 | mConstValues.insert(make_pair(TW_HAS_EXTERNAL, "0")); |
| 637 | #endif |
| 638 | #else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 639 | LOGINFO("Single storage only.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 640 | // Device just has external storage |
| 641 | mConstValues.insert(make_pair(TW_HAS_DUAL_STORAGE, "0")); |
| 642 | #endif |
| 643 | #ifdef RECOVERY_SDCARD_ON_DATA |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 644 | LOGINFO("Device has /data/media defined.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 645 | // Device has /data/media |
| 646 | mConstValues.insert(make_pair(TW_USE_EXTERNAL_STORAGE, "0")); |
| 647 | mConstValues.insert(make_pair(TW_HAS_INTERNAL, "1")); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 648 | mValues.insert(make_pair(TW_INTERNAL_PATH, make_pair("/data/media", 0))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 649 | mConstValues.insert(make_pair(TW_INTERNAL_MOUNT, "/data")); |
| 650 | mConstValues.insert(make_pair(TW_INTERNAL_LABEL, "data")); |
| 651 | #ifdef TW_EXTERNAL_STORAGE_PATH |
| 652 | if (strcmp(EXPAND(TW_EXTERNAL_STORAGE_PATH), "/sdcard") == 0) { |
| 653 | mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/emmc", 1))); |
| 654 | } else { |
| 655 | mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/sdcard", 1))); |
| 656 | } |
| 657 | #else |
| 658 | mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/sdcard", 1))); |
| 659 | #endif |
| 660 | #else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 661 | LOGINFO("No internal storage defined.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 662 | // Device has no internal storage |
| 663 | mConstValues.insert(make_pair(TW_USE_EXTERNAL_STORAGE, "1")); |
| 664 | mConstValues.insert(make_pair(TW_HAS_INTERNAL, "0")); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 665 | mValues.insert(make_pair(TW_INTERNAL_PATH, make_pair("0", 0))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 666 | mConstValues.insert(make_pair(TW_INTERNAL_MOUNT, "0")); |
| 667 | mConstValues.insert(make_pair(TW_INTERNAL_LABEL, "0")); |
| 668 | #endif |
| 669 | #ifdef TW_EXTERNAL_STORAGE_PATH |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 670 | LOGINFO("Only external path defined: '%s'\n", EXPAND(TW_EXTERNAL_STORAGE_PATH)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 671 | // External has custom definition |
| 672 | mConstValues.insert(make_pair(TW_HAS_EXTERNAL, "1")); |
| 673 | mConstValues.insert(make_pair(TW_EXTERNAL_PATH, EXPAND(TW_EXTERNAL_STORAGE_PATH))); |
| 674 | mConstValues.insert(make_pair(TW_EXTERNAL_LABEL, EXPAND(TW_EXTERNAL_STORAGE_MOUNT_POINT))); |
| 675 | mValues.insert(make_pair(TW_ZIP_EXTERNAL_VAR, make_pair(EXPAND(TW_EXTERNAL_STORAGE_PATH), 1))); |
| 676 | path.clear(); |
| 677 | path = "/"; |
| 678 | path += EXPAND(TW_EXTERNAL_STORAGE_MOUNT_POINT); |
| 679 | mConstValues.insert(make_pair(TW_EXTERNAL_MOUNT, path)); |
| 680 | #else |
| 681 | #ifndef RECOVERY_SDCARD_ON_DATA |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 682 | LOGINFO("No storage defined, defaulting to /sdcard.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 683 | // Standard external definition |
| 684 | mConstValues.insert(make_pair(TW_HAS_EXTERNAL, "1")); |
| 685 | mConstValues.insert(make_pair(TW_EXTERNAL_PATH, "/sdcard")); |
| 686 | mConstValues.insert(make_pair(TW_EXTERNAL_MOUNT, "/sdcard")); |
| 687 | mConstValues.insert(make_pair(TW_EXTERNAL_LABEL, "sdcard")); |
| 688 | mValues.insert(make_pair(TW_ZIP_EXTERNAL_VAR, make_pair("/sdcard", 1))); |
| 689 | #endif |
| 690 | #endif |
| 691 | #endif |
| 692 | |
| 693 | #ifdef TW_DEFAULT_EXTERNAL_STORAGE |
| 694 | SetValue(TW_USE_EXTERNAL_STORAGE, 1); |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 695 | printf("TW_DEFAULT_EXTERNAL_STORAGE := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 696 | #endif |
| 697 | |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 698 | #ifdef RECOVERY_SDCARD_ON_DATA |
| 699 | if (PartitionManager.Mount_By_Path("/data", false) && TWFunc::Path_Exists("/data/media/0")) |
| 700 | SetValue(TW_INTERNAL_PATH, "/data/media/0"); |
| 701 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 702 | str = GetCurrentStoragePath(); |
| 703 | #ifdef RECOVERY_SDCARD_ON_DATA |
| 704 | #ifndef TW_EXTERNAL_STORAGE_PATH |
| 705 | SetValue(TW_ZIP_LOCATION_VAR, "/sdcard", 1); |
| 706 | #else |
| 707 | if (strcmp(EXPAND(TW_EXTERNAL_STORAGE_PATH), "/sdcard") == 0) { |
| 708 | SetValue(TW_ZIP_LOCATION_VAR, "/emmc", 1); |
| 709 | } else { |
| 710 | SetValue(TW_ZIP_LOCATION_VAR, "/sdcard", 1); |
| 711 | } |
| 712 | #endif |
| 713 | #else |
| 714 | SetValue(TW_ZIP_LOCATION_VAR, str.c_str(), 1); |
| 715 | #endif |
| 716 | str += "/TWRP/BACKUPS/"; |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 717 | |
| 718 | string dev_id; |
| 719 | GetValue("device_id", dev_id); |
| 720 | |
| 721 | str += dev_id; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 722 | SetValue(TW_BACKUPS_FOLDER_VAR, str, 0); |
| 723 | |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 724 | #ifdef SP1_DISPLAY_NAME |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 725 | printf("SP1_DISPLAY_NAME := %s\n", EXPAND(SP1_DISPLAY_NAME)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 726 | if (strlen(EXPAND(SP1_DISPLAY_NAME))) mConstValues.insert(make_pair(TW_SP1_PARTITION_NAME_VAR, EXPAND(SP1_DISPLAY_NAME))); |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 727 | #else |
| 728 | #ifdef SP1_NAME |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 729 | printf("SP1_NAME := %s\n", EXPAND(SP1_NAME)); |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 730 | if (strlen(EXPAND(SP1_NAME))) mConstValues.insert(make_pair(TW_SP1_PARTITION_NAME_VAR, EXPAND(SP1_NAME))); |
| 731 | #endif |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 732 | #endif |
| 733 | #ifdef SP2_DISPLAY_NAME |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 734 | printf("SP2_DISPLAY_NAME := %s\n", EXPAND(SP2_DISPLAY_NAME)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 735 | if (strlen(EXPAND(SP2_DISPLAY_NAME))) mConstValues.insert(make_pair(TW_SP2_PARTITION_NAME_VAR, EXPAND(SP2_DISPLAY_NAME))); |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 736 | #else |
| 737 | #ifdef SP2_NAME |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 738 | printf("SP2_NAME := %s\n", EXPAND(SP2_NAME)); |
bigbiff bigbiff | 20ef6e3 | 2012-11-23 20:22:11 -0500 | [diff] [blame] | 739 | if (strlen(EXPAND(SP2_NAME))) mConstValues.insert(make_pair(TW_SP2_PARTITION_NAME_VAR, EXPAND(SP2_NAME))); |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 740 | #endif |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 741 | #endif |
| 742 | #ifdef SP3_DISPLAY_NAME |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 743 | printf("SP3_DISPLAY_NAME := %s\n", EXPAND(SP3_DISPLAY_NAME)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 744 | if (strlen(EXPAND(SP3_DISPLAY_NAME))) mConstValues.insert(make_pair(TW_SP3_PARTITION_NAME_VAR, EXPAND(SP3_DISPLAY_NAME))); |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 745 | #else |
| 746 | #ifdef SP3_NAME |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 747 | printf("SP3_NAME := %s\n", EXPAND(SP3_NAME)); |
bigbiff bigbiff | 20ef6e3 | 2012-11-23 20:22:11 -0500 | [diff] [blame] | 748 | if (strlen(EXPAND(SP3_NAME))) mConstValues.insert(make_pair(TW_SP3_PARTITION_NAME_VAR, EXPAND(SP3_NAME))); |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 749 | #endif |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 750 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 751 | |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 752 | mConstValues.insert(make_pair(TW_REBOOT_SYSTEM, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 753 | #ifdef TW_NO_REBOOT_RECOVERY |
Talustus | 33ebf93 | 2013-02-02 14:11:14 +0100 | [diff] [blame] | 754 | printf("TW_NO_REBOOT_RECOVERY := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 755 | mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, "0")); |
| 756 | #else |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 757 | mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 758 | #endif |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 759 | mConstValues.insert(make_pair(TW_REBOOT_POWEROFF, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 760 | #ifdef TW_NO_REBOOT_BOOTLOADER |
Talustus | 33ebf93 | 2013-02-02 14:11:14 +0100 | [diff] [blame] | 761 | printf("TW_NO_REBOOT_BOOTLOADER := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 762 | mConstValues.insert(make_pair(TW_REBOOT_BOOTLOADER, "0")); |
| 763 | #else |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 764 | mConstValues.insert(make_pair(TW_REBOOT_BOOTLOADER, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 765 | #endif |
| 766 | #ifdef RECOVERY_SDCARD_ON_DATA |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 767 | printf("RECOVERY_SDCARD_ON_DATA := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 768 | mConstValues.insert(make_pair(TW_HAS_DATA_MEDIA, "1")); |
| 769 | #else |
| 770 | mConstValues.insert(make_pair(TW_HAS_DATA_MEDIA, "0")); |
| 771 | #endif |
| 772 | #ifdef TW_NO_BATT_PERCENT |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 773 | printf("TW_NO_BATT_PERCENT := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 774 | mConstValues.insert(make_pair(TW_NO_BATTERY_PERCENT, "1")); |
| 775 | #else |
| 776 | mConstValues.insert(make_pair(TW_NO_BATTERY_PERCENT, "0")); |
| 777 | #endif |
| 778 | #ifdef TW_CUSTOM_POWER_BUTTON |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 779 | printf("TW_POWER_BUTTON := %s\n", EXPAND(TW_CUSTOM_POWER_BUTTON)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 780 | mConstValues.insert(make_pair(TW_POWER_BUTTON, EXPAND(TW_CUSTOM_POWER_BUTTON))); |
| 781 | #else |
| 782 | mConstValues.insert(make_pair(TW_POWER_BUTTON, "0")); |
| 783 | #endif |
| 784 | #ifdef TW_ALWAYS_RMRF |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 785 | printf("TW_ALWAYS_RMRF := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 786 | mConstValues.insert(make_pair(TW_RM_RF_VAR, "1")); |
| 787 | #endif |
| 788 | #ifdef TW_NEVER_UNMOUNT_SYSTEM |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 789 | printf("TW_NEVER_UNMOUNT_SYSTEM := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 790 | mConstValues.insert(make_pair(TW_DONT_UNMOUNT_SYSTEM, "1")); |
| 791 | #else |
| 792 | mConstValues.insert(make_pair(TW_DONT_UNMOUNT_SYSTEM, "0")); |
| 793 | #endif |
| 794 | #ifdef TW_NO_USB_STORAGE |
Dees_Troy | 6a042c8 | 2013-01-23 18:50:52 +0000 | [diff] [blame] | 795 | printf("TW_NO_USB_STORAGE := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 796 | mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "0")); |
| 797 | #else |
Dees_Troy | 6a042c8 | 2013-01-23 18:50:52 +0000 | [diff] [blame] | 798 | char lun_file[255]; |
| 799 | string Lun_File_str = CUSTOM_LUN_FILE; |
| 800 | size_t found = Lun_File_str.find("%"); |
| 801 | if (found != string::npos) { |
| 802 | sprintf(lun_file, CUSTOM_LUN_FILE, 0); |
| 803 | Lun_File_str = lun_file; |
| 804 | } |
| 805 | if (!TWFunc::Path_Exists(Lun_File_str)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 806 | 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] | 807 | mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "0")); |
| 808 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 809 | LOGINFO("Lun file '%s'\n", Lun_File_str.c_str()); |
Dees_Troy | 6a042c8 | 2013-01-23 18:50:52 +0000 | [diff] [blame] | 810 | mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "1")); |
| 811 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 812 | #endif |
| 813 | #ifdef TW_INCLUDE_INJECTTWRP |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 814 | printf("TW_INCLUDE_INJECTTWRP := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 815 | mConstValues.insert(make_pair(TW_HAS_INJECTTWRP, "1")); |
| 816 | mValues.insert(make_pair(TW_INJECT_AFTER_ZIP, make_pair("1", 1))); |
| 817 | #else |
| 818 | mConstValues.insert(make_pair(TW_HAS_INJECTTWRP, "0")); |
| 819 | mValues.insert(make_pair(TW_INJECT_AFTER_ZIP, make_pair("0", 1))); |
| 820 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 821 | #ifdef TW_HAS_DOWNLOAD_MODE |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 822 | printf("TW_HAS_DOWNLOAD_MODE := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 823 | mConstValues.insert(make_pair(TW_DOWNLOAD_MODE, "1")); |
| 824 | #endif |
| 825 | #ifdef TW_INCLUDE_CRYPTO |
| 826 | mConstValues.insert(make_pair(TW_HAS_CRYPTO, "1")); |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 827 | printf("TW_INCLUDE_CRYPTO := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 828 | #endif |
| 829 | #ifdef TW_SDEXT_NO_EXT4 |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 830 | printf("TW_SDEXT_NO_EXT4 := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 831 | mConstValues.insert(make_pair(TW_SDEXT_DISABLE_EXT4, "1")); |
| 832 | #else |
| 833 | mConstValues.insert(make_pair(TW_SDEXT_DISABLE_EXT4, "0")); |
| 834 | #endif |
| 835 | |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 836 | #ifdef TW_HAS_NO_BOOT_PARTITION |
| 837 | mValues.insert(make_pair("tw_backup_list", make_pair("/system;/data;", 0))); |
| 838 | #else |
| 839 | mValues.insert(make_pair("tw_backup_list", make_pair("/system;/data;/boot;", 0))); |
| 840 | #endif |
| 841 | mConstValues.insert(make_pair(TW_MIN_SYSTEM_VAR, TW_MIN_SYSTEM_SIZE)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 842 | mValues.insert(make_pair(TW_BACKUP_NAME, make_pair("(Current Date)", 0))); |
| 843 | mValues.insert(make_pair(TW_BACKUP_SYSTEM_VAR, make_pair("1", 1))); |
| 844 | mValues.insert(make_pair(TW_BACKUP_DATA_VAR, make_pair("1", 1))); |
| 845 | mValues.insert(make_pair(TW_BACKUP_BOOT_VAR, make_pair("1", 1))); |
| 846 | mValues.insert(make_pair(TW_BACKUP_RECOVERY_VAR, make_pair("0", 1))); |
| 847 | mValues.insert(make_pair(TW_BACKUP_CACHE_VAR, make_pair("0", 1))); |
| 848 | mValues.insert(make_pair(TW_BACKUP_SP1_VAR, make_pair("0", 1))); |
| 849 | mValues.insert(make_pair(TW_BACKUP_SP2_VAR, make_pair("0", 1))); |
| 850 | mValues.insert(make_pair(TW_BACKUP_SP3_VAR, make_pair("0", 1))); |
| 851 | mValues.insert(make_pair(TW_BACKUP_ANDSEC_VAR, make_pair("0", 1))); |
| 852 | mValues.insert(make_pair(TW_BACKUP_SDEXT_VAR, make_pair("0", 1))); |
| 853 | mValues.insert(make_pair(TW_BACKUP_SYSTEM_SIZE, make_pair("0", 0))); |
| 854 | mValues.insert(make_pair(TW_BACKUP_DATA_SIZE, make_pair("0", 0))); |
| 855 | mValues.insert(make_pair(TW_BACKUP_BOOT_SIZE, make_pair("0", 0))); |
| 856 | mValues.insert(make_pair(TW_BACKUP_RECOVERY_SIZE, make_pair("0", 0))); |
| 857 | mValues.insert(make_pair(TW_BACKUP_CACHE_SIZE, make_pair("0", 0))); |
| 858 | mValues.insert(make_pair(TW_BACKUP_ANDSEC_SIZE, make_pair("0", 0))); |
| 859 | mValues.insert(make_pair(TW_BACKUP_SDEXT_SIZE, make_pair("0", 0))); |
| 860 | mValues.insert(make_pair(TW_BACKUP_SP1_SIZE, make_pair("0", 0))); |
| 861 | mValues.insert(make_pair(TW_BACKUP_SP2_SIZE, make_pair("0", 0))); |
| 862 | mValues.insert(make_pair(TW_BACKUP_SP3_SIZE, make_pair("0", 0))); |
| 863 | mValues.insert(make_pair(TW_STORAGE_FREE_SIZE, make_pair("0", 0))); |
bigbiff bigbiff | 7ce7f0c | 2013-01-25 09:54:04 -0500 | [diff] [blame] | 864 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 865 | mValues.insert(make_pair(TW_REBOOT_AFTER_FLASH_VAR, make_pair("0", 1))); |
| 866 | mValues.insert(make_pair(TW_SIGNED_ZIP_VERIFY_VAR, make_pair("0", 1))); |
| 867 | mValues.insert(make_pair(TW_FORCE_MD5_CHECK_VAR, make_pair("0", 1))); |
| 868 | mValues.insert(make_pair(TW_COLOR_THEME_VAR, make_pair("0", 1))); |
| 869 | mValues.insert(make_pair(TW_USE_COMPRESSION_VAR, make_pair("0", 1))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 870 | mValues.insert(make_pair(TW_SHOW_SPAM_VAR, make_pair("0", 1))); |
| 871 | mValues.insert(make_pair(TW_TIME_ZONE_VAR, make_pair("CST6CDT", 1))); |
| 872 | mValues.insert(make_pair(TW_SORT_FILES_BY_DATE_VAR, make_pair("0", 1))); |
| 873 | mValues.insert(make_pair(TW_GUI_SORT_ORDER, make_pair("1", 1))); |
| 874 | mValues.insert(make_pair(TW_RM_RF_VAR, make_pair("0", 1))); |
| 875 | mValues.insert(make_pair(TW_SKIP_MD5_CHECK_VAR, make_pair("0", 1))); |
| 876 | mValues.insert(make_pair(TW_SKIP_MD5_GENERATE_VAR, make_pair("0", 1))); |
| 877 | mValues.insert(make_pair(TW_SDEXT_SIZE, make_pair("512", 1))); |
| 878 | mValues.insert(make_pair(TW_SWAP_SIZE, make_pair("32", 1))); |
| 879 | mValues.insert(make_pair(TW_SDPART_FILE_SYSTEM, make_pair("ext3", 1))); |
| 880 | mValues.insert(make_pair(TW_TIME_ZONE_GUISEL, make_pair("CST6;CDT", 1))); |
| 881 | mValues.insert(make_pair(TW_TIME_ZONE_GUIOFFSET, make_pair("0", 1))); |
| 882 | mValues.insert(make_pair(TW_TIME_ZONE_GUIDST, make_pair("1", 1))); |
| 883 | mValues.insert(make_pair(TW_ACTION_BUSY, make_pair("0", 0))); |
| 884 | mValues.insert(make_pair(TW_BACKUP_AVG_IMG_RATE, make_pair("15000000", 1))); |
| 885 | mValues.insert(make_pair(TW_BACKUP_AVG_FILE_RATE, make_pair("3000000", 1))); |
| 886 | mValues.insert(make_pair(TW_BACKUP_AVG_FILE_COMP_RATE, make_pair("2000000", 1))); |
| 887 | mValues.insert(make_pair(TW_RESTORE_AVG_IMG_RATE, make_pair("15000000", 1))); |
| 888 | mValues.insert(make_pair(TW_RESTORE_AVG_FILE_RATE, make_pair("3000000", 1))); |
| 889 | mValues.insert(make_pair(TW_RESTORE_AVG_FILE_COMP_RATE, make_pair("2000000", 1))); |
bigbiff bigbiff | 7ce7f0c | 2013-01-25 09:54:04 -0500 | [diff] [blame] | 890 | mValues.insert(make_pair("tw_wipe_cache", make_pair("0", 0))); |
| 891 | mValues.insert(make_pair("tw_wipe_dalvik", make_pair("0", 0))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 892 | if (GetIntValue(TW_HAS_INTERNAL) == 1 && GetIntValue(TW_HAS_DATA_MEDIA) == 1 && GetIntValue(TW_HAS_EXTERNAL) == 0) |
| 893 | SetValue(TW_HAS_USB_STORAGE, 0, 0); |
| 894 | else |
| 895 | SetValue(TW_HAS_USB_STORAGE, 1, 0); |
| 896 | mValues.insert(make_pair(TW_ZIP_INDEX, make_pair("0", 0))); |
| 897 | mValues.insert(make_pair(TW_ZIP_QUEUE_COUNT, make_pair("0", 0))); |
| 898 | mValues.insert(make_pair(TW_FILENAME, make_pair("/sdcard", 0))); |
| 899 | mValues.insert(make_pair(TW_SIMULATE_ACTIONS, make_pair("0", 1))); |
| 900 | mValues.insert(make_pair(TW_SIMULATE_FAIL, make_pair("0", 1))); |
| 901 | mValues.insert(make_pair(TW_IS_ENCRYPTED, make_pair("0", 0))); |
| 902 | mValues.insert(make_pair(TW_IS_DECRYPTED, make_pair("0", 0))); |
| 903 | mValues.insert(make_pair(TW_CRYPTO_PASSWORD, make_pair("0", 0))); |
| 904 | mValues.insert(make_pair(TW_DATA_BLK_DEVICE, make_pair("0", 0))); |
| 905 | mValues.insert(make_pair("tw_terminal_state", make_pair("0", 0))); |
| 906 | mValues.insert(make_pair("tw_background_thread_running", make_pair("0", 0))); |
| 907 | mValues.insert(make_pair(TW_RESTORE_FILE_DATE, make_pair("0", 0))); |
bigbiff bigbiff | f8e2f37 | 2013-02-27 20:50:43 -0500 | [diff] [blame] | 908 | mValues.insert(make_pair("tw_military_time", make_pair("0", 1))); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 909 | mValues.insert(make_pair("tw_screen_timeout_secs", make_pair("60", 1))); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 910 | mValues.insert(make_pair("tw_gui_done", make_pair("0", 0))); |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 911 | #ifdef TW_BRIGHTNESS_PATH |
| 912 | #ifndef TW_MAX_BRIGHTNESS |
| 913 | #define TW_MAX_BRIGHTNESS 255 |
| 914 | #endif |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 915 | if (strcmp(EXPAND(TW_BRIGHTNESS_PATH), "/nobrightness") != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 916 | LOGINFO("TW_BRIGHTNESS_PATH := %s\n", EXPAND(TW_BRIGHTNESS_PATH)); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 917 | mConstValues.insert(make_pair("tw_has_brightnesss_file", "1")); |
| 918 | mConstValues.insert(make_pair("tw_brightness_file", EXPAND(TW_BRIGHTNESS_PATH))); |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 919 | ostringstream maxVal; |
| 920 | maxVal << TW_MAX_BRIGHTNESS; |
| 921 | mConstValues.insert(make_pair("tw_brightness_max", maxVal.str())); |
| 922 | mValues.insert(make_pair("tw_brightness", make_pair(maxVal.str(), 1))); |
| 923 | mValues.insert(make_pair("tw_brightness_pct", make_pair("100", 1))); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 924 | } else { |
| 925 | mConstValues.insert(make_pair("tw_has_brightnesss_file", "0")); |
| 926 | } |
| 927 | #endif |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 928 | mValues.insert(make_pair(TW_MILITARY_TIME, make_pair("0", 1))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | // Magic Values |
| 932 | int DataManager::GetMagicValue(const string varName, string& value) |
| 933 | { |
| 934 | // Handle special dynamic cases |
| 935 | if (varName == "tw_time") |
| 936 | { |
| 937 | char tmp[32]; |
| 938 | |
| 939 | struct tm *current; |
| 940 | time_t now; |
bigbiff bigbiff | 4efe9c3 | 2013-02-20 18:58:11 -0500 | [diff] [blame] | 941 | int tw_military_time; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 942 | now = time(0); |
| 943 | current = localtime(&now); |
bigbiff bigbiff | 4efe9c3 | 2013-02-20 18:58:11 -0500 | [diff] [blame] | 944 | GetValue(TW_MILITARY_TIME, tw_military_time); |
| 945 | if (current->tm_hour >= 12) { |
| 946 | if (tw_military_time == 1) |
| 947 | sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min); |
| 948 | else |
| 949 | sprintf(tmp, "%d:%02d PM", current->tm_hour == 12 ? 12 : current->tm_hour - 12, current->tm_min); |
| 950 | } |
| 951 | else { |
| 952 | if (tw_military_time == 1) |
| 953 | sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min); |
| 954 | else |
| 955 | sprintf(tmp, "%d:%02d AM", current->tm_hour == 0 ? 12 : current->tm_hour, current->tm_min); |
| 956 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 957 | value = tmp; |
| 958 | return 0; |
| 959 | } |
| 960 | if (varName == "tw_battery") |
| 961 | { |
| 962 | char tmp[16]; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 963 | static char charging = ' '; |
| 964 | static int lastVal = -1; |
| 965 | static time_t nextSecCheck = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 966 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 967 | struct timeval curTime; |
| 968 | gettimeofday(&curTime, NULL); |
| 969 | if (curTime.tv_sec > nextSecCheck) |
| 970 | { |
| 971 | char cap_s[4]; |
Dees_Troy | f33b490 | 2013-03-01 00:51:39 +0000 | [diff] [blame] | 972 | #ifdef TW_CUSTOM_BATTERY_PATH |
| 973 | string capacity_file = EXPAND(TW_CUSTOM_BATTERY_PATH); |
| 974 | capacity_file += "/capacity"; |
| 975 | FILE * cap = fopen(capacity_file.c_str(),"rt"); |
| 976 | #else |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 977 | FILE * cap = fopen("/sys/class/power_supply/battery/capacity","rt"); |
Dees_Troy | f33b490 | 2013-03-01 00:51:39 +0000 | [diff] [blame] | 978 | #endif |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 979 | if (cap){ |
| 980 | fgets(cap_s, 4, cap); |
| 981 | fclose(cap); |
| 982 | lastVal = atoi(cap_s); |
| 983 | if (lastVal > 100) lastVal = 101; |
| 984 | if (lastVal < 0) lastVal = 0; |
| 985 | } |
Dees_Troy | f33b490 | 2013-03-01 00:51:39 +0000 | [diff] [blame] | 986 | #ifdef TW_CUSTOM_BATTERY_PATH |
| 987 | string status_file = EXPAND(TW_CUSTOM_BATTERY_PATH); |
| 988 | status_file += "/status"; |
| 989 | cap = fopen(status_file.c_str(),"rt"); |
| 990 | #else |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 991 | cap = fopen("/sys/class/power_supply/battery/status","rt"); |
Dees_Troy | f33b490 | 2013-03-01 00:51:39 +0000 | [diff] [blame] | 992 | #endif |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 993 | if (cap) { |
| 994 | fgets(cap_s, 2, cap); |
| 995 | fclose(cap); |
| 996 | if (cap_s[0] == 'C') |
| 997 | charging = '+'; |
| 998 | else |
| 999 | charging = ' '; |
| 1000 | } |
| 1001 | nextSecCheck = curTime.tv_sec + 60; |
| 1002 | } |
| 1003 | |
| 1004 | sprintf(tmp, "%i%%%c", lastVal, charging); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1005 | value = tmp; |
| 1006 | return 0; |
| 1007 | } |
| 1008 | return -1; |
| 1009 | } |
| 1010 | |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1011 | void DataManager::Output_Version(void) { |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1012 | string Path; |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1013 | char version[255]; |
| 1014 | |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1015 | if (!PartitionManager.Mount_By_Path("/cache", false)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1016 | 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] | 1017 | return; |
| 1018 | } |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1019 | if (!TWFunc::Path_Exists("/cache/recovery/.")) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1020 | LOGINFO("Recreating /cache/recovery folder.\n"); |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1021 | 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] | 1022 | LOGERR("DataManager::Output_Version -- Unable to make /cache/recovery\n"); |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1023 | return; |
| 1024 | } |
| 1025 | } |
| 1026 | Path = "/cache/recovery/.version"; |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1027 | if (TWFunc::Path_Exists(Path)) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1028 | unlink(Path.c_str()); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1029 | } |
| 1030 | FILE *fp = fopen(Path.c_str(), "w"); |
| 1031 | if (fp == NULL) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1032 | LOGERR("Unable to open '%s'.\n", Path.c_str()); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1033 | return; |
| 1034 | } |
| 1035 | strcpy(version, TW_VERSION_STR); |
| 1036 | fwrite(version, sizeof(version[0]), strlen(version) / sizeof(version[0]), fp); |
| 1037 | fclose(fp); |
| 1038 | sync(); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1039 | LOGINFO("Version number saved to '%s'\n", Path.c_str()); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1042 | void DataManager::ReadSettingsFile(void) |
| 1043 | { |
| 1044 | // Load up the values for TWRP - Sleep to let the card be ready |
| 1045 | char mkdir_path[255], settings_file[255]; |
| 1046 | int is_enc, has_dual, use_ext, has_data_media, has_ext; |
| 1047 | |
| 1048 | GetValue(TW_IS_ENCRYPTED, is_enc); |
| 1049 | GetValue(TW_HAS_DATA_MEDIA, has_data_media); |
| 1050 | if (is_enc == 1 && has_data_media == 1) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1051 | LOGINFO("Cannot load settings -- encrypted.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1052 | return; |
| 1053 | } |
| 1054 | |
| 1055 | memset(mkdir_path, 0, sizeof(mkdir_path)); |
| 1056 | memset(settings_file, 0, sizeof(settings_file)); |
| 1057 | sprintf(mkdir_path, "%s/TWRP", DataManager_GetSettingsStoragePath()); |
| 1058 | sprintf(settings_file, "%s/.twrps", mkdir_path); |
| 1059 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1060 | if (!PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1061 | { |
| 1062 | usleep(500000); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1063 | if (!PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1064 | 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] | 1065 | } |
| 1066 | |
| 1067 | mkdir(mkdir_path, 0777); |
| 1068 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1069 | LOGINFO("Attempt to load settings from settings file...\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1070 | LoadValues(settings_file); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1071 | Output_Version(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1072 | GetValue(TW_HAS_DUAL_STORAGE, has_dual); |
| 1073 | GetValue(TW_USE_EXTERNAL_STORAGE, use_ext); |
| 1074 | GetValue(TW_HAS_EXTERNAL, has_ext); |
| 1075 | if (has_dual != 0 && use_ext == 1) { |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1076 | // Attempt to switch to using external storage |
Dees_Troy | e2920fa | 2012-09-19 16:18:00 -0400 | [diff] [blame] | 1077 | if (!PartitionManager.Mount_Current_Storage(false)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1078 | LOGERR("Failed to mount external storage, using internal storage.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1079 | // Remount failed, default back to internal storage |
| 1080 | SetValue(TW_USE_EXTERNAL_STORAGE, 0); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1081 | PartitionManager.Mount_Current_Storage(true); |
Dees_Troy | e2920fa | 2012-09-19 16:18:00 -0400 | [diff] [blame] | 1082 | string int_zip_path; |
| 1083 | GetValue(TW_ZIP_INTERNAL_VAR, int_zip_path); |
| 1084 | SetValue(TW_USE_EXTERNAL_STORAGE, 0); |
| 1085 | SetValue(TW_ZIP_LOCATION_VAR, int_zip_path); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1086 | } |
| 1087 | } else { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1088 | PartitionManager.Mount_Current_Storage(true); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1089 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1090 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1091 | if (has_ext) { |
| 1092 | string ext_path; |
| 1093 | |
| 1094 | GetValue(TW_EXTERNAL_PATH, ext_path); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1095 | PartitionManager.Mount_By_Path(ext_path, 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1096 | } |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1097 | update_tz_environment_variables(); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 1098 | #ifdef TW_MAX_BRIGHTNESS |
| 1099 | if (strcmp(EXPAND(TW_BRIGHTNESS_PATH), "/nobrightness") != 0) { |
| 1100 | string brightness_path = EXPAND(TW_BRIGHTNESS_PATH); |
| 1101 | string brightness_value = GetStrValue("tw_brightness"); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 1102 | TWFunc::write_file(brightness_path, brightness_value); |
| 1103 | } |
| 1104 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | string DataManager::GetCurrentStoragePath(void) |
| 1108 | { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1109 | return GetStrValue("tw_storage_path"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | string& DataManager::CGetCurrentStoragePath() |
| 1113 | { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1114 | return GetValueRef("tw_storage_path"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | string DataManager::GetSettingsStoragePath(void) |
| 1118 | { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1119 | return GetStrValue("tw_settings_path"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | string& DataManager::CGetSettingsStoragePath() |
| 1123 | { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1124 | return GetValueRef("tw_settings_path"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | extern "C" int DataManager_ResetDefaults() |
| 1128 | { |
| 1129 | return DataManager::ResetDefaults(); |
| 1130 | } |
| 1131 | |
| 1132 | extern "C" void DataManager_LoadDefaults() |
| 1133 | { |
| 1134 | return DataManager::SetDefaultValues(); |
| 1135 | } |
| 1136 | |
| 1137 | extern "C" int DataManager_LoadValues(const char* filename) |
| 1138 | { |
| 1139 | return DataManager::LoadValues(filename); |
| 1140 | } |
| 1141 | |
| 1142 | extern "C" int DataManager_Flush() |
| 1143 | { |
| 1144 | return DataManager::Flush(); |
| 1145 | } |
| 1146 | |
| 1147 | extern "C" int DataManager_GetValue(const char* varName, char* value) |
| 1148 | { |
| 1149 | int ret; |
| 1150 | string str; |
| 1151 | |
| 1152 | ret = DataManager::GetValue(varName, str); |
| 1153 | if (ret == 0) |
| 1154 | strcpy(value, str.c_str()); |
| 1155 | return ret; |
| 1156 | } |
| 1157 | |
| 1158 | extern "C" const char* DataManager_GetStrValue(const char* varName) |
| 1159 | { |
| 1160 | string& str = DataManager::GetValueRef(varName); |
| 1161 | return str.c_str(); |
| 1162 | } |
| 1163 | |
| 1164 | extern "C" const char* DataManager_GetCurrentStoragePath(void) |
| 1165 | { |
| 1166 | string& str = DataManager::CGetCurrentStoragePath(); |
| 1167 | return str.c_str(); |
| 1168 | } |
| 1169 | |
| 1170 | extern "C" const char* DataManager_GetSettingsStoragePath(void) |
| 1171 | { |
| 1172 | string& str = DataManager::CGetSettingsStoragePath(); |
| 1173 | return str.c_str(); |
| 1174 | } |
| 1175 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1176 | extern "C" int DataManager_GetIntValue(const char* varName) |
| 1177 | { |
| 1178 | return DataManager::GetIntValue(varName); |
| 1179 | } |
| 1180 | |
| 1181 | extern "C" int DataManager_SetStrValue(const char* varName, char* value) |
| 1182 | { |
| 1183 | return DataManager::SetValue(varName, value, 0); |
| 1184 | } |
| 1185 | |
| 1186 | extern "C" int DataManager_SetIntValue(const char* varName, int value) |
| 1187 | { |
| 1188 | return DataManager::SetValue(varName, value, 0); |
| 1189 | } |
| 1190 | |
| 1191 | extern "C" int DataManager_SetFloatValue(const char* varName, float value) |
| 1192 | { |
| 1193 | return DataManager::SetValue(varName, value, 0); |
| 1194 | } |
| 1195 | |
| 1196 | extern "C" int DataManager_ToggleIntValue(const char* varName) |
| 1197 | { |
| 1198 | if (DataManager::GetIntValue(varName)) |
| 1199 | return DataManager::SetValue(varName, 0); |
| 1200 | else |
| 1201 | return DataManager::SetValue(varName, 1); |
| 1202 | } |
| 1203 | |
| 1204 | extern "C" void DataManager_DumpValues() |
| 1205 | { |
| 1206 | return DataManager::DumpValues(); |
| 1207 | } |
| 1208 | |
| 1209 | extern "C" void DataManager_ReadSettingsFile() |
| 1210 | { |
| 1211 | return DataManager::ReadSettingsFile(); |
| 1212 | } |