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