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