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