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