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; |
Dees_Troy | 1872795 | 2013-06-20 15:24:48 -0500 | [diff] [blame] | 547 | zip_root.resize(storage_path.size()); |
| 548 | if (zip_root != storage_path) { |
| 549 | 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] | 550 | SetValue(TW_ZIP_LOCATION_VAR, storage_path); |
Dees_Troy | 1872795 | 2013-06-20 15:24:48 -0500 | [diff] [blame] | 551 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 552 | } |
| 553 | } else { |
| 554 | if (PartitionManager.Fstab_Processed() != 0) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 555 | LOGERR("Storage partition '%s' not found\n", str.c_str()); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 556 | } |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 557 | } |
| 558 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 559 | void DataManager::SetDefaultValues() |
| 560 | { |
| 561 | string str, path; |
| 562 | |
| 563 | get_device_id(); |
| 564 | |
| 565 | mInitialized = 1; |
| 566 | |
| 567 | mConstValues.insert(make_pair("true", "1")); |
| 568 | mConstValues.insert(make_pair("false", "0")); |
| 569 | |
| 570 | mConstValues.insert(make_pair(TW_VERSION_VAR, TW_VERSION_STR)); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 571 | mValues.insert(make_pair("tw_storage_path", make_pair("/", 1))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 572 | |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 573 | #ifdef TW_FORCE_CPUINFO_FOR_DEVICE_ID |
| 574 | printf("TW_FORCE_CPUINFO_FOR_DEVICE_ID := true\n"); |
| 575 | #endif |
| 576 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 577 | #ifdef BOARD_HAS_NO_REAL_SDCARD |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 578 | printf("BOARD_HAS_NO_REAL_SDCARD := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 579 | mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "0")); |
| 580 | #else |
| 581 | mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "1")); |
| 582 | #endif |
| 583 | |
| 584 | #ifdef TW_INCLUDE_DUMLOCK |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 585 | printf("TW_INCLUDE_DUMLOCK := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 586 | mConstValues.insert(make_pair(TW_SHOW_DUMLOCK, "1")); |
| 587 | #else |
| 588 | mConstValues.insert(make_pair(TW_SHOW_DUMLOCK, "0")); |
| 589 | #endif |
| 590 | |
| 591 | #ifdef TW_INTERNAL_STORAGE_PATH |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 592 | LOGINFO("Internal path defined: '%s'\n", EXPAND(TW_INTERNAL_STORAGE_PATH)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 593 | mValues.insert(make_pair(TW_USE_EXTERNAL_STORAGE, make_pair("0", 1))); |
| 594 | mConstValues.insert(make_pair(TW_HAS_INTERNAL, "1")); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 595 | 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] | 596 | mConstValues.insert(make_pair(TW_INTERNAL_LABEL, EXPAND(TW_INTERNAL_STORAGE_MOUNT_POINT))); |
| 597 | path.clear(); |
| 598 | path = "/"; |
| 599 | path += EXPAND(TW_INTERNAL_STORAGE_MOUNT_POINT); |
| 600 | mConstValues.insert(make_pair(TW_INTERNAL_MOUNT, path)); |
| 601 | #ifdef TW_EXTERNAL_STORAGE_PATH |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 602 | LOGINFO("External path defined: '%s'\n", EXPAND(TW_EXTERNAL_STORAGE_PATH)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 603 | // Device has dual storage |
| 604 | mConstValues.insert(make_pair(TW_HAS_DUAL_STORAGE, "1")); |
| 605 | mConstValues.insert(make_pair(TW_HAS_EXTERNAL, "1")); |
| 606 | mConstValues.insert(make_pair(TW_EXTERNAL_PATH, EXPAND(TW_EXTERNAL_STORAGE_PATH))); |
| 607 | mConstValues.insert(make_pair(TW_EXTERNAL_LABEL, EXPAND(TW_EXTERNAL_STORAGE_MOUNT_POINT))); |
| 608 | mValues.insert(make_pair(TW_ZIP_EXTERNAL_VAR, make_pair(EXPAND(TW_EXTERNAL_STORAGE_PATH), 1))); |
| 609 | path.clear(); |
| 610 | path = "/"; |
| 611 | path += EXPAND(TW_EXTERNAL_STORAGE_MOUNT_POINT); |
| 612 | mConstValues.insert(make_pair(TW_EXTERNAL_MOUNT, path)); |
| 613 | if (strcmp(EXPAND(TW_EXTERNAL_STORAGE_PATH), "/sdcard") == 0) { |
| 614 | mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/emmc", 1))); |
| 615 | } else { |
| 616 | mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/sdcard", 1))); |
| 617 | } |
| 618 | #else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 619 | LOGINFO("Just has internal storage.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 620 | // Just has internal storage |
| 621 | mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/sdcard", 1))); |
| 622 | mConstValues.insert(make_pair(TW_HAS_DUAL_STORAGE, "0")); |
| 623 | mConstValues.insert(make_pair(TW_HAS_EXTERNAL, "0")); |
| 624 | mConstValues.insert(make_pair(TW_EXTERNAL_PATH, "0")); |
| 625 | mConstValues.insert(make_pair(TW_EXTERNAL_MOUNT, "0")); |
| 626 | mConstValues.insert(make_pair(TW_EXTERNAL_LABEL, "0")); |
| 627 | #endif |
| 628 | #else |
| 629 | #ifdef RECOVERY_SDCARD_ON_DATA |
| 630 | #ifdef TW_EXTERNAL_STORAGE_PATH |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 631 | 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] | 632 | // Device has /data/media + external storage |
| 633 | mConstValues.insert(make_pair(TW_HAS_DUAL_STORAGE, "1")); |
| 634 | #else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 635 | LOGINFO("Single storage only -- data/media.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 636 | // Device just has external storage |
| 637 | mConstValues.insert(make_pair(TW_HAS_DUAL_STORAGE, "0")); |
| 638 | mConstValues.insert(make_pair(TW_HAS_EXTERNAL, "0")); |
| 639 | #endif |
| 640 | #else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 641 | LOGINFO("Single storage only.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 642 | // Device just has external storage |
| 643 | mConstValues.insert(make_pair(TW_HAS_DUAL_STORAGE, "0")); |
| 644 | #endif |
| 645 | #ifdef RECOVERY_SDCARD_ON_DATA |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 646 | LOGINFO("Device has /data/media defined.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 647 | // Device has /data/media |
| 648 | mConstValues.insert(make_pair(TW_USE_EXTERNAL_STORAGE, "0")); |
| 649 | mConstValues.insert(make_pair(TW_HAS_INTERNAL, "1")); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 650 | mValues.insert(make_pair(TW_INTERNAL_PATH, make_pair("/data/media", 0))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 651 | mConstValues.insert(make_pair(TW_INTERNAL_MOUNT, "/data")); |
| 652 | mConstValues.insert(make_pair(TW_INTERNAL_LABEL, "data")); |
| 653 | #ifdef TW_EXTERNAL_STORAGE_PATH |
| 654 | if (strcmp(EXPAND(TW_EXTERNAL_STORAGE_PATH), "/sdcard") == 0) { |
| 655 | mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/emmc", 1))); |
| 656 | } else { |
| 657 | mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/sdcard", 1))); |
| 658 | } |
| 659 | #else |
| 660 | mValues.insert(make_pair(TW_ZIP_INTERNAL_VAR, make_pair("/sdcard", 1))); |
| 661 | #endif |
| 662 | #else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 663 | LOGINFO("No internal storage defined.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 664 | // Device has no internal storage |
| 665 | mConstValues.insert(make_pair(TW_USE_EXTERNAL_STORAGE, "1")); |
| 666 | mConstValues.insert(make_pair(TW_HAS_INTERNAL, "0")); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 667 | mValues.insert(make_pair(TW_INTERNAL_PATH, make_pair("0", 0))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 668 | mConstValues.insert(make_pair(TW_INTERNAL_MOUNT, "0")); |
| 669 | mConstValues.insert(make_pair(TW_INTERNAL_LABEL, "0")); |
| 670 | #endif |
| 671 | #ifdef TW_EXTERNAL_STORAGE_PATH |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 672 | LOGINFO("Only external path defined: '%s'\n", EXPAND(TW_EXTERNAL_STORAGE_PATH)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 673 | // External has custom definition |
| 674 | mConstValues.insert(make_pair(TW_HAS_EXTERNAL, "1")); |
| 675 | mConstValues.insert(make_pair(TW_EXTERNAL_PATH, EXPAND(TW_EXTERNAL_STORAGE_PATH))); |
| 676 | mConstValues.insert(make_pair(TW_EXTERNAL_LABEL, EXPAND(TW_EXTERNAL_STORAGE_MOUNT_POINT))); |
| 677 | mValues.insert(make_pair(TW_ZIP_EXTERNAL_VAR, make_pair(EXPAND(TW_EXTERNAL_STORAGE_PATH), 1))); |
| 678 | path.clear(); |
| 679 | path = "/"; |
| 680 | path += EXPAND(TW_EXTERNAL_STORAGE_MOUNT_POINT); |
| 681 | mConstValues.insert(make_pair(TW_EXTERNAL_MOUNT, path)); |
| 682 | #else |
| 683 | #ifndef RECOVERY_SDCARD_ON_DATA |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 684 | LOGINFO("No storage defined, defaulting to /sdcard.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 685 | // Standard external definition |
| 686 | mConstValues.insert(make_pair(TW_HAS_EXTERNAL, "1")); |
| 687 | mConstValues.insert(make_pair(TW_EXTERNAL_PATH, "/sdcard")); |
| 688 | mConstValues.insert(make_pair(TW_EXTERNAL_MOUNT, "/sdcard")); |
| 689 | mConstValues.insert(make_pair(TW_EXTERNAL_LABEL, "sdcard")); |
| 690 | mValues.insert(make_pair(TW_ZIP_EXTERNAL_VAR, make_pair("/sdcard", 1))); |
| 691 | #endif |
| 692 | #endif |
| 693 | #endif |
| 694 | |
| 695 | #ifdef TW_DEFAULT_EXTERNAL_STORAGE |
| 696 | SetValue(TW_USE_EXTERNAL_STORAGE, 1); |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 697 | printf("TW_DEFAULT_EXTERNAL_STORAGE := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 698 | #endif |
| 699 | |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 700 | #ifdef RECOVERY_SDCARD_ON_DATA |
| 701 | if (PartitionManager.Mount_By_Path("/data", false) && TWFunc::Path_Exists("/data/media/0")) |
| 702 | SetValue(TW_INTERNAL_PATH, "/data/media/0"); |
| 703 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 704 | str = GetCurrentStoragePath(); |
| 705 | #ifdef RECOVERY_SDCARD_ON_DATA |
| 706 | #ifndef TW_EXTERNAL_STORAGE_PATH |
| 707 | SetValue(TW_ZIP_LOCATION_VAR, "/sdcard", 1); |
| 708 | #else |
| 709 | if (strcmp(EXPAND(TW_EXTERNAL_STORAGE_PATH), "/sdcard") == 0) { |
| 710 | SetValue(TW_ZIP_LOCATION_VAR, "/emmc", 1); |
| 711 | } else { |
| 712 | SetValue(TW_ZIP_LOCATION_VAR, "/sdcard", 1); |
| 713 | } |
| 714 | #endif |
| 715 | #else |
| 716 | SetValue(TW_ZIP_LOCATION_VAR, str.c_str(), 1); |
| 717 | #endif |
| 718 | str += "/TWRP/BACKUPS/"; |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 719 | |
| 720 | string dev_id; |
| 721 | GetValue("device_id", dev_id); |
| 722 | |
| 723 | str += dev_id; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 724 | SetValue(TW_BACKUPS_FOLDER_VAR, str, 0); |
| 725 | |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 726 | #ifdef SP1_DISPLAY_NAME |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 727 | printf("SP1_DISPLAY_NAME := %s\n", EXPAND(SP1_DISPLAY_NAME)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 728 | 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] | 729 | #else |
| 730 | #ifdef SP1_NAME |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 731 | printf("SP1_NAME := %s\n", EXPAND(SP1_NAME)); |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 732 | if (strlen(EXPAND(SP1_NAME))) mConstValues.insert(make_pair(TW_SP1_PARTITION_NAME_VAR, EXPAND(SP1_NAME))); |
| 733 | #endif |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 734 | #endif |
| 735 | #ifdef SP2_DISPLAY_NAME |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 736 | printf("SP2_DISPLAY_NAME := %s\n", EXPAND(SP2_DISPLAY_NAME)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 737 | 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] | 738 | #else |
| 739 | #ifdef SP2_NAME |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 740 | printf("SP2_NAME := %s\n", EXPAND(SP2_NAME)); |
bigbiff bigbiff | 20ef6e3 | 2012-11-23 20:22:11 -0500 | [diff] [blame] | 741 | 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] | 742 | #endif |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 743 | #endif |
| 744 | #ifdef SP3_DISPLAY_NAME |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 745 | printf("SP3_DISPLAY_NAME := %s\n", EXPAND(SP3_DISPLAY_NAME)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 746 | 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] | 747 | #else |
| 748 | #ifdef SP3_NAME |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 749 | printf("SP3_NAME := %s\n", EXPAND(SP3_NAME)); |
bigbiff bigbiff | 20ef6e3 | 2012-11-23 20:22:11 -0500 | [diff] [blame] | 750 | 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] | 751 | #endif |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 752 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 753 | |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 754 | mConstValues.insert(make_pair(TW_REBOOT_SYSTEM, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 755 | #ifdef TW_NO_REBOOT_RECOVERY |
Talustus | 33ebf93 | 2013-02-02 14:11:14 +0100 | [diff] [blame] | 756 | printf("TW_NO_REBOOT_RECOVERY := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 757 | mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, "0")); |
| 758 | #else |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 759 | mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 760 | #endif |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 761 | mConstValues.insert(make_pair(TW_REBOOT_POWEROFF, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 762 | #ifdef TW_NO_REBOOT_BOOTLOADER |
Talustus | 33ebf93 | 2013-02-02 14:11:14 +0100 | [diff] [blame] | 763 | printf("TW_NO_REBOOT_BOOTLOADER := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 764 | mConstValues.insert(make_pair(TW_REBOOT_BOOTLOADER, "0")); |
| 765 | #else |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 766 | mConstValues.insert(make_pair(TW_REBOOT_BOOTLOADER, "1")); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 767 | #endif |
| 768 | #ifdef RECOVERY_SDCARD_ON_DATA |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 769 | printf("RECOVERY_SDCARD_ON_DATA := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 770 | mConstValues.insert(make_pair(TW_HAS_DATA_MEDIA, "1")); |
| 771 | #else |
| 772 | mConstValues.insert(make_pair(TW_HAS_DATA_MEDIA, "0")); |
| 773 | #endif |
| 774 | #ifdef TW_NO_BATT_PERCENT |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 775 | printf("TW_NO_BATT_PERCENT := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 776 | mConstValues.insert(make_pair(TW_NO_BATTERY_PERCENT, "1")); |
| 777 | #else |
| 778 | mConstValues.insert(make_pair(TW_NO_BATTERY_PERCENT, "0")); |
| 779 | #endif |
| 780 | #ifdef TW_CUSTOM_POWER_BUTTON |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 781 | printf("TW_POWER_BUTTON := %s\n", EXPAND(TW_CUSTOM_POWER_BUTTON)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 782 | mConstValues.insert(make_pair(TW_POWER_BUTTON, EXPAND(TW_CUSTOM_POWER_BUTTON))); |
| 783 | #else |
| 784 | mConstValues.insert(make_pair(TW_POWER_BUTTON, "0")); |
| 785 | #endif |
| 786 | #ifdef TW_ALWAYS_RMRF |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 787 | printf("TW_ALWAYS_RMRF := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 788 | mConstValues.insert(make_pair(TW_RM_RF_VAR, "1")); |
| 789 | #endif |
| 790 | #ifdef TW_NEVER_UNMOUNT_SYSTEM |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 791 | printf("TW_NEVER_UNMOUNT_SYSTEM := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 792 | mConstValues.insert(make_pair(TW_DONT_UNMOUNT_SYSTEM, "1")); |
| 793 | #else |
| 794 | mConstValues.insert(make_pair(TW_DONT_UNMOUNT_SYSTEM, "0")); |
| 795 | #endif |
| 796 | #ifdef TW_NO_USB_STORAGE |
Dees_Troy | 6a042c8 | 2013-01-23 18:50:52 +0000 | [diff] [blame] | 797 | printf("TW_NO_USB_STORAGE := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 798 | mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "0")); |
| 799 | #else |
Dees_Troy | 6a042c8 | 2013-01-23 18:50:52 +0000 | [diff] [blame] | 800 | char lun_file[255]; |
| 801 | string Lun_File_str = CUSTOM_LUN_FILE; |
| 802 | size_t found = Lun_File_str.find("%"); |
| 803 | if (found != string::npos) { |
| 804 | sprintf(lun_file, CUSTOM_LUN_FILE, 0); |
| 805 | Lun_File_str = lun_file; |
| 806 | } |
| 807 | if (!TWFunc::Path_Exists(Lun_File_str)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 808 | 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] | 809 | mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "0")); |
| 810 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 811 | LOGINFO("Lun file '%s'\n", Lun_File_str.c_str()); |
Dees_Troy | 6a042c8 | 2013-01-23 18:50:52 +0000 | [diff] [blame] | 812 | mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "1")); |
| 813 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 814 | #endif |
| 815 | #ifdef TW_INCLUDE_INJECTTWRP |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 816 | printf("TW_INCLUDE_INJECTTWRP := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 817 | mConstValues.insert(make_pair(TW_HAS_INJECTTWRP, "1")); |
| 818 | mValues.insert(make_pair(TW_INJECT_AFTER_ZIP, make_pair("1", 1))); |
| 819 | #else |
| 820 | mConstValues.insert(make_pair(TW_HAS_INJECTTWRP, "0")); |
| 821 | mValues.insert(make_pair(TW_INJECT_AFTER_ZIP, make_pair("0", 1))); |
| 822 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 823 | #ifdef TW_HAS_DOWNLOAD_MODE |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 824 | printf("TW_HAS_DOWNLOAD_MODE := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 825 | mConstValues.insert(make_pair(TW_DOWNLOAD_MODE, "1")); |
| 826 | #endif |
| 827 | #ifdef TW_INCLUDE_CRYPTO |
| 828 | mConstValues.insert(make_pair(TW_HAS_CRYPTO, "1")); |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 829 | printf("TW_INCLUDE_CRYPTO := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 830 | #endif |
| 831 | #ifdef TW_SDEXT_NO_EXT4 |
Dees_Troy | f449981 | 2013-01-23 19:07:38 +0000 | [diff] [blame] | 832 | printf("TW_SDEXT_NO_EXT4 := true\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 833 | mConstValues.insert(make_pair(TW_SDEXT_DISABLE_EXT4, "1")); |
| 834 | #else |
| 835 | mConstValues.insert(make_pair(TW_SDEXT_DISABLE_EXT4, "0")); |
| 836 | #endif |
| 837 | |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 838 | #ifdef TW_HAS_NO_BOOT_PARTITION |
Dees_Troy | f100c94 | 2013-06-21 08:15:31 -0500 | [diff] [blame] | 839 | mValues.insert(make_pair("tw_backup_list", make_pair("/system;/data;", 1))); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 840 | #else |
Dees_Troy | f100c94 | 2013-06-21 08:15:31 -0500 | [diff] [blame] | 841 | 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] | 842 | #endif |
| 843 | mConstValues.insert(make_pair(TW_MIN_SYSTEM_VAR, TW_MIN_SYSTEM_SIZE)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 844 | mValues.insert(make_pair(TW_BACKUP_NAME, make_pair("(Current Date)", 0))); |
| 845 | mValues.insert(make_pair(TW_BACKUP_SYSTEM_VAR, make_pair("1", 1))); |
| 846 | mValues.insert(make_pair(TW_BACKUP_DATA_VAR, make_pair("1", 1))); |
| 847 | mValues.insert(make_pair(TW_BACKUP_BOOT_VAR, make_pair("1", 1))); |
| 848 | mValues.insert(make_pair(TW_BACKUP_RECOVERY_VAR, make_pair("0", 1))); |
| 849 | mValues.insert(make_pair(TW_BACKUP_CACHE_VAR, make_pair("0", 1))); |
| 850 | mValues.insert(make_pair(TW_BACKUP_SP1_VAR, make_pair("0", 1))); |
| 851 | mValues.insert(make_pair(TW_BACKUP_SP2_VAR, make_pair("0", 1))); |
| 852 | mValues.insert(make_pair(TW_BACKUP_SP3_VAR, make_pair("0", 1))); |
| 853 | mValues.insert(make_pair(TW_BACKUP_ANDSEC_VAR, make_pair("0", 1))); |
| 854 | mValues.insert(make_pair(TW_BACKUP_SDEXT_VAR, make_pair("0", 1))); |
| 855 | mValues.insert(make_pair(TW_BACKUP_SYSTEM_SIZE, make_pair("0", 0))); |
| 856 | mValues.insert(make_pair(TW_BACKUP_DATA_SIZE, make_pair("0", 0))); |
| 857 | mValues.insert(make_pair(TW_BACKUP_BOOT_SIZE, make_pair("0", 0))); |
| 858 | mValues.insert(make_pair(TW_BACKUP_RECOVERY_SIZE, make_pair("0", 0))); |
| 859 | mValues.insert(make_pair(TW_BACKUP_CACHE_SIZE, make_pair("0", 0))); |
| 860 | mValues.insert(make_pair(TW_BACKUP_ANDSEC_SIZE, make_pair("0", 0))); |
| 861 | mValues.insert(make_pair(TW_BACKUP_SDEXT_SIZE, make_pair("0", 0))); |
| 862 | mValues.insert(make_pair(TW_BACKUP_SP1_SIZE, make_pair("0", 0))); |
| 863 | mValues.insert(make_pair(TW_BACKUP_SP2_SIZE, make_pair("0", 0))); |
| 864 | mValues.insert(make_pair(TW_BACKUP_SP3_SIZE, make_pair("0", 0))); |
| 865 | mValues.insert(make_pair(TW_STORAGE_FREE_SIZE, make_pair("0", 0))); |
bigbiff bigbiff | 7ce7f0c | 2013-01-25 09:54:04 -0500 | [diff] [blame] | 866 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 867 | mValues.insert(make_pair(TW_REBOOT_AFTER_FLASH_VAR, make_pair("0", 1))); |
| 868 | mValues.insert(make_pair(TW_SIGNED_ZIP_VERIFY_VAR, make_pair("0", 1))); |
| 869 | mValues.insert(make_pair(TW_FORCE_MD5_CHECK_VAR, make_pair("0", 1))); |
| 870 | mValues.insert(make_pair(TW_COLOR_THEME_VAR, make_pair("0", 1))); |
| 871 | mValues.insert(make_pair(TW_USE_COMPRESSION_VAR, make_pair("0", 1))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 872 | mValues.insert(make_pair(TW_SHOW_SPAM_VAR, make_pair("0", 1))); |
| 873 | mValues.insert(make_pair(TW_TIME_ZONE_VAR, make_pair("CST6CDT", 1))); |
| 874 | mValues.insert(make_pair(TW_SORT_FILES_BY_DATE_VAR, make_pair("0", 1))); |
| 875 | mValues.insert(make_pair(TW_GUI_SORT_ORDER, make_pair("1", 1))); |
| 876 | mValues.insert(make_pair(TW_RM_RF_VAR, make_pair("0", 1))); |
| 877 | mValues.insert(make_pair(TW_SKIP_MD5_CHECK_VAR, make_pair("0", 1))); |
| 878 | mValues.insert(make_pair(TW_SKIP_MD5_GENERATE_VAR, make_pair("0", 1))); |
| 879 | mValues.insert(make_pair(TW_SDEXT_SIZE, make_pair("512", 1))); |
| 880 | mValues.insert(make_pair(TW_SWAP_SIZE, make_pair("32", 1))); |
| 881 | mValues.insert(make_pair(TW_SDPART_FILE_SYSTEM, make_pair("ext3", 1))); |
| 882 | mValues.insert(make_pair(TW_TIME_ZONE_GUISEL, make_pair("CST6;CDT", 1))); |
| 883 | mValues.insert(make_pair(TW_TIME_ZONE_GUIOFFSET, make_pair("0", 1))); |
| 884 | mValues.insert(make_pair(TW_TIME_ZONE_GUIDST, make_pair("1", 1))); |
| 885 | mValues.insert(make_pair(TW_ACTION_BUSY, make_pair("0", 0))); |
| 886 | mValues.insert(make_pair(TW_BACKUP_AVG_IMG_RATE, make_pair("15000000", 1))); |
| 887 | mValues.insert(make_pair(TW_BACKUP_AVG_FILE_RATE, make_pair("3000000", 1))); |
| 888 | mValues.insert(make_pair(TW_BACKUP_AVG_FILE_COMP_RATE, make_pair("2000000", 1))); |
| 889 | mValues.insert(make_pair(TW_RESTORE_AVG_IMG_RATE, make_pair("15000000", 1))); |
| 890 | mValues.insert(make_pair(TW_RESTORE_AVG_FILE_RATE, make_pair("3000000", 1))); |
| 891 | 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] | 892 | mValues.insert(make_pair("tw_wipe_cache", make_pair("0", 0))); |
| 893 | mValues.insert(make_pair("tw_wipe_dalvik", make_pair("0", 0))); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 894 | if (GetIntValue(TW_HAS_INTERNAL) == 1 && GetIntValue(TW_HAS_DATA_MEDIA) == 1 && GetIntValue(TW_HAS_EXTERNAL) == 0) |
| 895 | SetValue(TW_HAS_USB_STORAGE, 0, 0); |
| 896 | else |
| 897 | SetValue(TW_HAS_USB_STORAGE, 1, 0); |
| 898 | mValues.insert(make_pair(TW_ZIP_INDEX, make_pair("0", 0))); |
| 899 | mValues.insert(make_pair(TW_ZIP_QUEUE_COUNT, make_pair("0", 0))); |
| 900 | mValues.insert(make_pair(TW_FILENAME, make_pair("/sdcard", 0))); |
| 901 | mValues.insert(make_pair(TW_SIMULATE_ACTIONS, make_pair("0", 1))); |
| 902 | mValues.insert(make_pair(TW_SIMULATE_FAIL, make_pair("0", 1))); |
| 903 | mValues.insert(make_pair(TW_IS_ENCRYPTED, make_pair("0", 0))); |
| 904 | mValues.insert(make_pair(TW_IS_DECRYPTED, make_pair("0", 0))); |
| 905 | mValues.insert(make_pair(TW_CRYPTO_PASSWORD, make_pair("0", 0))); |
| 906 | mValues.insert(make_pair(TW_DATA_BLK_DEVICE, make_pair("0", 0))); |
| 907 | mValues.insert(make_pair("tw_terminal_state", make_pair("0", 0))); |
| 908 | mValues.insert(make_pair("tw_background_thread_running", make_pair("0", 0))); |
| 909 | mValues.insert(make_pair(TW_RESTORE_FILE_DATE, make_pair("0", 0))); |
bigbiff bigbiff | f8e2f37 | 2013-02-27 20:50:43 -0500 | [diff] [blame] | 910 | mValues.insert(make_pair("tw_military_time", make_pair("0", 1))); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 911 | mValues.insert(make_pair("tw_screen_timeout_secs", make_pair("60", 1))); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 912 | mValues.insert(make_pair("tw_gui_done", make_pair("0", 0))); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 913 | mValues.insert(make_pair("tw_encrypt_backup", make_pair("0", 0))); |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 914 | #ifdef TW_BRIGHTNESS_PATH |
| 915 | #ifndef TW_MAX_BRIGHTNESS |
| 916 | #define TW_MAX_BRIGHTNESS 255 |
| 917 | #endif |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 918 | if (strcmp(EXPAND(TW_BRIGHTNESS_PATH), "/nobrightness") != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 919 | LOGINFO("TW_BRIGHTNESS_PATH := %s\n", EXPAND(TW_BRIGHTNESS_PATH)); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 920 | mConstValues.insert(make_pair("tw_has_brightnesss_file", "1")); |
| 921 | mConstValues.insert(make_pair("tw_brightness_file", EXPAND(TW_BRIGHTNESS_PATH))); |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 922 | ostringstream maxVal; |
| 923 | maxVal << TW_MAX_BRIGHTNESS; |
| 924 | mConstValues.insert(make_pair("tw_brightness_max", maxVal.str())); |
| 925 | mValues.insert(make_pair("tw_brightness", make_pair(maxVal.str(), 1))); |
| 926 | mValues.insert(make_pair("tw_brightness_pct", make_pair("100", 1))); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 927 | } else { |
| 928 | mConstValues.insert(make_pair("tw_has_brightnesss_file", "0")); |
| 929 | } |
| 930 | #endif |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 931 | mValues.insert(make_pair(TW_MILITARY_TIME, make_pair("0", 1))); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 932 | #ifndef TW_EXCLUDE_ENCRYPTED_BACKUPS |
| 933 | mValues.insert(make_pair("tw_include_encrypted_backup", make_pair("1", 0))); |
| 934 | #else |
| 935 | LOGINFO("TW_EXCLUDE_ENCRYPTED_BACKUPS := true\n"); |
| 936 | mValues.insert(make_pair("tw_include_encrypted_backup", make_pair("0", 0))); |
| 937 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | // Magic Values |
| 941 | int DataManager::GetMagicValue(const string varName, string& value) |
| 942 | { |
| 943 | // Handle special dynamic cases |
| 944 | if (varName == "tw_time") |
| 945 | { |
| 946 | char tmp[32]; |
| 947 | |
| 948 | struct tm *current; |
| 949 | time_t now; |
bigbiff bigbiff | 4efe9c3 | 2013-02-20 18:58:11 -0500 | [diff] [blame] | 950 | int tw_military_time; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 951 | now = time(0); |
| 952 | current = localtime(&now); |
bigbiff bigbiff | 4efe9c3 | 2013-02-20 18:58:11 -0500 | [diff] [blame] | 953 | GetValue(TW_MILITARY_TIME, tw_military_time); |
| 954 | if (current->tm_hour >= 12) { |
| 955 | if (tw_military_time == 1) |
| 956 | sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min); |
| 957 | else |
| 958 | sprintf(tmp, "%d:%02d PM", current->tm_hour == 12 ? 12 : current->tm_hour - 12, current->tm_min); |
| 959 | } |
| 960 | else { |
| 961 | if (tw_military_time == 1) |
| 962 | sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min); |
| 963 | else |
| 964 | sprintf(tmp, "%d:%02d AM", current->tm_hour == 0 ? 12 : current->tm_hour, current->tm_min); |
| 965 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 966 | value = tmp; |
| 967 | return 0; |
| 968 | } |
| 969 | if (varName == "tw_battery") |
| 970 | { |
| 971 | char tmp[16]; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 972 | static char charging = ' '; |
| 973 | static int lastVal = -1; |
| 974 | static time_t nextSecCheck = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 975 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 976 | struct timeval curTime; |
| 977 | gettimeofday(&curTime, NULL); |
| 978 | if (curTime.tv_sec > nextSecCheck) |
| 979 | { |
| 980 | char cap_s[4]; |
Dees_Troy | f33b490 | 2013-03-01 00:51:39 +0000 | [diff] [blame] | 981 | #ifdef TW_CUSTOM_BATTERY_PATH |
| 982 | string capacity_file = EXPAND(TW_CUSTOM_BATTERY_PATH); |
| 983 | capacity_file += "/capacity"; |
| 984 | FILE * cap = fopen(capacity_file.c_str(),"rt"); |
| 985 | #else |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 986 | FILE * cap = fopen("/sys/class/power_supply/battery/capacity","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, 4, cap); |
| 990 | fclose(cap); |
| 991 | lastVal = atoi(cap_s); |
| 992 | if (lastVal > 100) lastVal = 101; |
| 993 | if (lastVal < 0) lastVal = 0; |
| 994 | } |
Dees_Troy | f33b490 | 2013-03-01 00:51:39 +0000 | [diff] [blame] | 995 | #ifdef TW_CUSTOM_BATTERY_PATH |
| 996 | string status_file = EXPAND(TW_CUSTOM_BATTERY_PATH); |
| 997 | status_file += "/status"; |
| 998 | cap = fopen(status_file.c_str(),"rt"); |
| 999 | #else |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1000 | cap = fopen("/sys/class/power_supply/battery/status","rt"); |
Dees_Troy | f33b490 | 2013-03-01 00:51:39 +0000 | [diff] [blame] | 1001 | #endif |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1002 | if (cap) { |
| 1003 | fgets(cap_s, 2, cap); |
| 1004 | fclose(cap); |
| 1005 | if (cap_s[0] == 'C') |
| 1006 | charging = '+'; |
| 1007 | else |
| 1008 | charging = ' '; |
| 1009 | } |
| 1010 | nextSecCheck = curTime.tv_sec + 60; |
| 1011 | } |
| 1012 | |
| 1013 | sprintf(tmp, "%i%%%c", lastVal, charging); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1014 | value = tmp; |
| 1015 | return 0; |
| 1016 | } |
| 1017 | return -1; |
| 1018 | } |
| 1019 | |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1020 | void DataManager::Output_Version(void) { |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1021 | string Path; |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1022 | char version[255]; |
| 1023 | |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1024 | if (!PartitionManager.Mount_By_Path("/cache", false)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1025 | 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] | 1026 | return; |
| 1027 | } |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1028 | if (!TWFunc::Path_Exists("/cache/recovery/.")) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1029 | LOGINFO("Recreating /cache/recovery folder.\n"); |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1030 | 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] | 1031 | LOGERR("DataManager::Output_Version -- Unable to make /cache/recovery\n"); |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1032 | return; |
| 1033 | } |
| 1034 | } |
| 1035 | Path = "/cache/recovery/.version"; |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1036 | if (TWFunc::Path_Exists(Path)) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1037 | unlink(Path.c_str()); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1038 | } |
| 1039 | FILE *fp = fopen(Path.c_str(), "w"); |
| 1040 | if (fp == NULL) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1041 | LOGERR("Unable to open '%s'.\n", Path.c_str()); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1042 | return; |
| 1043 | } |
| 1044 | strcpy(version, TW_VERSION_STR); |
| 1045 | fwrite(version, sizeof(version[0]), strlen(version) / sizeof(version[0]), fp); |
| 1046 | fclose(fp); |
| 1047 | sync(); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1048 | LOGINFO("Version number saved to '%s'\n", Path.c_str()); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1049 | } |
| 1050 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1051 | void DataManager::ReadSettingsFile(void) |
| 1052 | { |
| 1053 | // Load up the values for TWRP - Sleep to let the card be ready |
| 1054 | char mkdir_path[255], settings_file[255]; |
| 1055 | int is_enc, has_dual, use_ext, has_data_media, has_ext; |
| 1056 | |
| 1057 | GetValue(TW_IS_ENCRYPTED, is_enc); |
| 1058 | GetValue(TW_HAS_DATA_MEDIA, has_data_media); |
| 1059 | if (is_enc == 1 && has_data_media == 1) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1060 | LOGINFO("Cannot load settings -- encrypted.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1061 | return; |
| 1062 | } |
| 1063 | |
| 1064 | memset(mkdir_path, 0, sizeof(mkdir_path)); |
| 1065 | memset(settings_file, 0, sizeof(settings_file)); |
| 1066 | sprintf(mkdir_path, "%s/TWRP", DataManager_GetSettingsStoragePath()); |
| 1067 | sprintf(settings_file, "%s/.twrps", mkdir_path); |
| 1068 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1069 | if (!PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1070 | { |
| 1071 | usleep(500000); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1072 | if (!PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1073 | 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] | 1074 | } |
| 1075 | |
| 1076 | mkdir(mkdir_path, 0777); |
| 1077 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1078 | LOGINFO("Attempt to load settings from settings file...\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1079 | LoadValues(settings_file); |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1080 | Output_Version(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1081 | GetValue(TW_HAS_DUAL_STORAGE, has_dual); |
| 1082 | GetValue(TW_USE_EXTERNAL_STORAGE, use_ext); |
| 1083 | GetValue(TW_HAS_EXTERNAL, has_ext); |
| 1084 | if (has_dual != 0 && use_ext == 1) { |
Dees_Troy | 01a9b7a | 2012-10-01 09:01:03 -0400 | [diff] [blame] | 1085 | // Attempt to switch to using external storage |
Dees_Troy | e2920fa | 2012-09-19 16:18:00 -0400 | [diff] [blame] | 1086 | if (!PartitionManager.Mount_Current_Storage(false)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1087 | LOGERR("Failed to mount external storage, using internal storage.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1088 | // Remount failed, default back to internal storage |
| 1089 | SetValue(TW_USE_EXTERNAL_STORAGE, 0); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1090 | PartitionManager.Mount_Current_Storage(true); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1091 | } |
| 1092 | } else { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1093 | PartitionManager.Mount_Current_Storage(true); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1094 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1095 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1096 | if (has_ext) { |
| 1097 | string ext_path; |
| 1098 | |
| 1099 | GetValue(TW_EXTERNAL_PATH, ext_path); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1100 | PartitionManager.Mount_By_Path(ext_path, 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1101 | } |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1102 | update_tz_environment_variables(); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 1103 | #ifdef TW_MAX_BRIGHTNESS |
| 1104 | if (strcmp(EXPAND(TW_BRIGHTNESS_PATH), "/nobrightness") != 0) { |
| 1105 | string brightness_path = EXPAND(TW_BRIGHTNESS_PATH); |
| 1106 | string brightness_value = GetStrValue("tw_brightness"); |
Dees_Troy | 2f9117a | 2013-02-17 19:52:09 -0600 | [diff] [blame] | 1107 | TWFunc::write_file(brightness_path, brightness_value); |
| 1108 | } |
| 1109 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | string DataManager::GetCurrentStoragePath(void) |
| 1113 | { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1114 | return GetStrValue("tw_storage_path"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | string& DataManager::CGetCurrentStoragePath() |
| 1118 | { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1119 | return GetValueRef("tw_storage_path"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | string DataManager::GetSettingsStoragePath(void) |
| 1123 | { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1124 | return GetStrValue("tw_settings_path"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | string& DataManager::CGetSettingsStoragePath() |
| 1128 | { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1129 | return GetValueRef("tw_settings_path"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | extern "C" int DataManager_ResetDefaults() |
| 1133 | { |
| 1134 | return DataManager::ResetDefaults(); |
| 1135 | } |
| 1136 | |
| 1137 | extern "C" void DataManager_LoadDefaults() |
| 1138 | { |
| 1139 | return DataManager::SetDefaultValues(); |
| 1140 | } |
| 1141 | |
| 1142 | extern "C" int DataManager_LoadValues(const char* filename) |
| 1143 | { |
| 1144 | return DataManager::LoadValues(filename); |
| 1145 | } |
| 1146 | |
| 1147 | extern "C" int DataManager_Flush() |
| 1148 | { |
| 1149 | return DataManager::Flush(); |
| 1150 | } |
| 1151 | |
| 1152 | extern "C" int DataManager_GetValue(const char* varName, char* value) |
| 1153 | { |
| 1154 | int ret; |
| 1155 | string str; |
| 1156 | |
| 1157 | ret = DataManager::GetValue(varName, str); |
| 1158 | if (ret == 0) |
| 1159 | strcpy(value, str.c_str()); |
| 1160 | return ret; |
| 1161 | } |
| 1162 | |
| 1163 | extern "C" const char* DataManager_GetStrValue(const char* varName) |
| 1164 | { |
| 1165 | string& str = DataManager::GetValueRef(varName); |
| 1166 | return str.c_str(); |
| 1167 | } |
| 1168 | |
| 1169 | extern "C" const char* DataManager_GetCurrentStoragePath(void) |
| 1170 | { |
| 1171 | string& str = DataManager::CGetCurrentStoragePath(); |
| 1172 | return str.c_str(); |
| 1173 | } |
| 1174 | |
| 1175 | extern "C" const char* DataManager_GetSettingsStoragePath(void) |
| 1176 | { |
| 1177 | string& str = DataManager::CGetSettingsStoragePath(); |
| 1178 | return str.c_str(); |
| 1179 | } |
| 1180 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1181 | extern "C" int DataManager_GetIntValue(const char* varName) |
| 1182 | { |
| 1183 | return DataManager::GetIntValue(varName); |
| 1184 | } |
| 1185 | |
| 1186 | extern "C" int DataManager_SetStrValue(const char* varName, char* value) |
| 1187 | { |
| 1188 | return DataManager::SetValue(varName, value, 0); |
| 1189 | } |
| 1190 | |
| 1191 | extern "C" int DataManager_SetIntValue(const char* varName, int value) |
| 1192 | { |
| 1193 | return DataManager::SetValue(varName, value, 0); |
| 1194 | } |
| 1195 | |
| 1196 | extern "C" int DataManager_SetFloatValue(const char* varName, float value) |
| 1197 | { |
| 1198 | return DataManager::SetValue(varName, value, 0); |
| 1199 | } |
| 1200 | |
| 1201 | extern "C" int DataManager_ToggleIntValue(const char* varName) |
| 1202 | { |
| 1203 | if (DataManager::GetIntValue(varName)) |
| 1204 | return DataManager::SetValue(varName, 0); |
| 1205 | else |
| 1206 | return DataManager::SetValue(varName, 1); |
| 1207 | } |
| 1208 | |
| 1209 | extern "C" void DataManager_DumpValues() |
| 1210 | { |
| 1211 | return DataManager::DumpValues(); |
| 1212 | } |
| 1213 | |
| 1214 | extern "C" void DataManager_ReadSettingsFile() |
| 1215 | { |
| 1216 | return DataManager::ReadSettingsFile(); |
| 1217 | } |