blob: be851584ef342bd4a3cae5a6476bcd3cbbe476d5 [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001/*
Dees Troy3be70a82013-10-22 14:25:12 +00002 Copyright 2012 bigbiff/Dees_Troy TeamWin
3 This file is part of TWRP/TeamWin Recovery Project.
4
5 TWRP is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TWRP is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
17*/
Dees_Troy51a0e822012-09-05 15:24:24 -040018
19#include <linux/input.h>
20#include <pthread.h>
21#include <stdarg.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <fcntl.h>
26#include <sys/stat.h>
27#include <sys/time.h>
28#include <sys/mman.h>
29#include <sys/types.h>
30#include <sys/ioctl.h>
31#include <time.h>
32#include <unistd.h>
33#include <stdlib.h>
34
35#include <string>
36#include <utility>
37#include <map>
38#include <fstream>
39#include <sstream>
40
41#include "variables.h"
42#include "data.hpp"
43#include "partitions.hpp"
Dees_Troy01a9b7a2012-10-01 09:01:03 -040044#include "twrp-functions.hpp"
Ricardo Gomezc9ecd442013-07-05 16:13:52 -070045#ifndef TW_NO_SCREEN_TIMEOUT
Dees_Troy2f9117a2013-02-17 19:52:09 -060046#include "gui/blanktimer.hpp"
Ricardo Gomezc9ecd442013-07-05 16:13:52 -070047#endif
Ethan Yonker00028b42014-04-09 14:29:02 -050048#include "find_file.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040049
Anatoly Smaznov10c11f62013-02-12 13:33:40 +070050#ifdef TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020051 #include "cutils/properties.h"
Anatoly Smaznov10c11f62013-02-12 13:33:40 +070052#endif
53
Ethan Yonkera18f1082014-07-07 15:07:58 -050054#ifndef TW_MAX_BRIGHTNESS
55#define TW_MAX_BRIGHTNESS 255
56#endif
57
Dees_Troy51a0e822012-09-05 15:24:24 -040058extern "C"
59{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020060 #include "twcommon.h"
61 #include "data.h"
Dees_Troy7d15c252012-09-05 20:47:21 -040062 #include "gui/pages.h"
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +000063 #include "minuitwrp/minui.h"
Dees_Troy7d15c252012-09-05 20:47:21 -040064 void gui_notifyVarChange(const char *name, const char* value);
Dees_Troy51a0e822012-09-05 15:24:24 -040065}
66
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020067#define FILE_VERSION 0x00010001
Dees_Troy51a0e822012-09-05 15:24:24 -040068
69using namespace std;
70
Ricardo Gomezc9ecd442013-07-05 16:13:52 -070071map<string, DataManager::TStrIntPair> DataManager::mValues;
72map<string, string> DataManager::mConstValues;
73string DataManager::mBackingFile;
74int DataManager::mInitialized = 0;
75#ifndef TW_NO_SCREEN_TIMEOUT
Dees_Troy2f9117a2013-02-17 19:52:09 -060076extern blanktimer blankTimer;
Ricardo Gomezc9ecd442013-07-05 16:13:52 -070077#endif
Ethan Yonker6277c792014-09-15 14:54:30 -050078extern bool datamedia;
Dees_Troy51a0e822012-09-05 15:24:24 -040079
Dees_Troyfdf5fcc2012-09-11 10:27:01 -040080// Device ID functions
81void DataManager::sanitize_device_id(char* device_id) {
82 const char* whitelist ="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-._";
83 char str[50];
84 char* c = str;
85
86 strcpy(str, device_id);
87 memset(device_id, 0, sizeof(device_id));
88 while (*c) {
89 if (strchr(whitelist, *c))
90 strncat(device_id, c, 1);
91 c++;
92 }
93 return;
94}
95
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020096#define CMDLINE_SERIALNO "androidboot.serialno="
97#define CMDLINE_SERIALNO_LEN (strlen(CMDLINE_SERIALNO))
98#define CPUINFO_SERIALNO "Serial"
99#define CPUINFO_SERIALNO_LEN (strlen(CPUINFO_SERIALNO))
100#define CPUINFO_HARDWARE "Hardware"
101#define CPUINFO_HARDWARE_LEN (strlen(CPUINFO_HARDWARE))
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400102
103void DataManager::get_device_id(void) {
104 FILE *fp;
105 char line[2048];
106 char hardware_id[32], device_id[64];
107 char* token;
108
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200109 // Assign a blank device_id to start with
110 device_id[0] = 0;
Anatoly Smaznov10c11f62013-02-12 13:33:40 +0700111
112#ifdef TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID
113 // Now we'll use product_model_hardwareid as device id
114 char model_id[PROPERTY_VALUE_MAX];
115 property_get("ro.product.model", model_id, "error");
116 if (strcmp(model_id,"error") != 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000117 LOGINFO("=> product model: '%s'\n", model_id);
Anatoly Smaznov10c11f62013-02-12 13:33:40 +0700118 // Replace spaces with underscores
119 for(int i = 0; i < strlen(model_id); i++) {
120 if(model_id[i] == ' ')
121 model_id[i] = '_';
122 }
123 strcpy(device_id, model_id);
124 if (hardware_id[0] != 0) {
125 strcat(device_id, "_");
126 strcat(device_id, hardware_id);
127 }
128 sanitize_device_id((char *)device_id);
129 mConstValues.insert(make_pair("device_id", device_id));
Dees_Troy2673cec2013-04-02 20:22:16 +0000130 LOGINFO("=> using device id: '%s'\n", device_id);
Anatoly Smaznov10c11f62013-02-12 13:33:40 +0700131 return;
132 }
133#endif
134
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400135#ifndef TW_FORCE_CPUINFO_FOR_DEVICE_ID
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200136 // First, try the cmdline to see if the serial number was supplied
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400137 fp = fopen("/proc/cmdline", "rt");
138 if (fp != NULL)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200139 {
140 // First step, read the line. For cmdline, it's one long line
141 fgets(line, sizeof(line), fp);
142 fclose(fp);
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400143
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200144 // Now, let's tokenize the string
145 token = strtok(line, " ");
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400146
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200147 // Let's walk through the line, looking for the CMDLINE_SERIALNO token
148 while (token)
149 {
150 // We don't need to verify the length of token, because if it's too short, it will mismatch CMDLINE_SERIALNO at the NULL
151 if (memcmp(token, CMDLINE_SERIALNO, CMDLINE_SERIALNO_LEN) == 0)
152 {
153 // We found the serial number!
154 strcpy(device_id, token + CMDLINE_SERIALNO_LEN);
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400155 sanitize_device_id((char *)device_id);
156 mConstValues.insert(make_pair("device_id", device_id));
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200157 return;
158 }
159 token = strtok(NULL, " ");
160 }
161 }
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400162#endif
163 // Now we'll try cpuinfo for a serial number
164 fp = fopen("/proc/cpuinfo", "rt");
165 if (fp != NULL)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200166 {
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400167 while (fgets(line, sizeof(line), fp) != NULL) { // First step, read the line.
168 if (memcmp(line, CPUINFO_SERIALNO, CPUINFO_SERIALNO_LEN) == 0) // check the beginning of the line for "Serial"
169 {
170 // We found the serial number!
171 token = line + CPUINFO_SERIALNO_LEN; // skip past "Serial"
172 while ((*token > 0 && *token <= 32 ) || *token == ':') token++; // skip over all spaces and the colon
173 if (*token != 0) {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200174 token[30] = 0;
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400175 if (token[strlen(token)-1] == 10) { // checking for endline chars and dropping them from the end of the string if needed
176 memset(device_id, 0, sizeof(device_id));
177 strncpy(device_id, token, strlen(token) - 1);
178 } else {
179 strcpy(device_id, token);
180 }
Dees_Troy2673cec2013-04-02 20:22:16 +0000181 LOGINFO("=> serial from cpuinfo: '%s'\n", device_id);
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400182 fclose(fp);
183 sanitize_device_id((char *)device_id);
184 mConstValues.insert(make_pair("device_id", device_id));
185 return;
186 }
187 } 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
188 // We found the hardware ID
189 token = line + CPUINFO_HARDWARE_LEN; // skip past "Hardware"
190 while ((*token > 0 && *token <= 32 ) || *token == ':') token++; // skip over all spaces and the colon
191 if (*token != 0) {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200192 token[30] = 0;
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400193 if (token[strlen(token)-1] == 10) { // checking for endline chars and dropping them from the end of the string if needed
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200194 memset(hardware_id, 0, sizeof(hardware_id));
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400195 strncpy(hardware_id, token, strlen(token) - 1);
196 } else {
197 strcpy(hardware_id, token);
198 }
Dees_Troy2673cec2013-04-02 20:22:16 +0000199 LOGINFO("=> hardware id from cpuinfo: '%s'\n", hardware_id);
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400200 }
201 }
202 }
203 fclose(fp);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200204 }
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400205
206 if (hardware_id[0] != 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000207 LOGINFO("\nusing hardware id for device id: '%s'\n", hardware_id);
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400208 strcpy(device_id, hardware_id);
209 sanitize_device_id((char *)device_id);
210 mConstValues.insert(make_pair("device_id", device_id));
211 return;
212 }
213
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200214 strcpy(device_id, "serialno");
Dees_Troy2673cec2013-04-02 20:22:16 +0000215 LOGERR("=> device id not found, using '%s'.", device_id);
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400216 mConstValues.insert(make_pair("device_id", device_id));
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200217 return;
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400218}
219
Dees_Troy51a0e822012-09-05 15:24:24 -0400220int DataManager::ResetDefaults()
221{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200222 mValues.clear();
223 mConstValues.clear();
224 SetDefaultValues();
225 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400226}
227
228int DataManager::LoadValues(const string filename)
229{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200230 string str, dev_id;
Dees_Troy51a0e822012-09-05 15:24:24 -0400231
232 if (!mInitialized)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200233 SetDefaultValues();
Dees_Troy51a0e822012-09-05 15:24:24 -0400234
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200235 GetValue("device_id", dev_id);
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400236 // Save off the backing file for set operations
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200237 mBackingFile = filename;
Dees_Troy51a0e822012-09-05 15:24:24 -0400238
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200239 // Read in the file, if possible
240 FILE* in = fopen(filename.c_str(), "rb");
241 if (!in) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000242 LOGINFO("Settings file '%s' not found.\n", filename.c_str());
Dees_Troya13d74f2013-03-24 08:54:55 -0500243 return 0;
244 } else {
Dees_Troy2673cec2013-04-02 20:22:16 +0000245 LOGINFO("Loading settings from '%s'.\n", filename.c_str());
Dees_Troya13d74f2013-03-24 08:54:55 -0500246 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400247
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200248 int file_version;
249 if (fread(&file_version, 1, sizeof(int), in) != sizeof(int)) goto error;
250 if (file_version != FILE_VERSION) goto error;
Dees_Troy51a0e822012-09-05 15:24:24 -0400251
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200252 while (!feof(in))
253 {
254 string Name;
255 string Value;
256 unsigned short length;
257 char array[512];
Dees_Troy51a0e822012-09-05 15:24:24 -0400258
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200259 if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error;
260 if (length >= 512) goto error;
261 if (fread(array, 1, length, in) != length) goto error;
262 Name = array;
Dees_Troy51a0e822012-09-05 15:24:24 -0400263
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200264 if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error;
265 if (length >= 512) goto error;
266 if (fread(array, 1, length, in) != length) goto error;
267 Value = array;
Dees_Troy51a0e822012-09-05 15:24:24 -0400268
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200269 map<string, TStrIntPair>::iterator pos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400270
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200271 pos = mValues.find(Name);
272 if (pos != mValues.end())
273 {
274 pos->second.first = Value;
275 pos->second.second = 1;
276 }
277 else
278 mValues.insert(TNameValuePair(Name, TStrIntPair(Value, 1)));
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700279#ifndef TW_NO_SCREEN_TIMEOUT
Dees_Troya13d74f2013-03-24 08:54:55 -0500280 if (Name == "tw_screen_timeout_secs")
281 blankTimer.setTime(atoi(Value.c_str()));
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700282#endif
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200283 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400284error:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200285 fclose(in);
Dees_Troya13d74f2013-03-24 08:54:55 -0500286 string current = GetCurrentStoragePath();
Ethan Yonkereeed3c52014-04-16 11:49:02 -0500287 TWPartition* Part = PartitionManager.Find_Partition_By_Path(current);
Vojtech Bocek93cb1ef2014-05-12 15:41:52 +0200288 if(!Part)
289 Part = PartitionManager.Get_Default_Storage_Partition();
290 if (Part && current != Part->Storage_Path && Part->Mount(false)) {
Ethan Yonkereeed3c52014-04-16 11:49:02 -0500291 LOGINFO("LoadValues setting storage path to '%s'\n", Part->Storage_Path.c_str());
292 SetValue("tw_storage_path", Part->Storage_Path);
Dees_Troya13d74f2013-03-24 08:54:55 -0500293 } else {
294 SetBackupFolder();
295 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200296 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400297}
298
299int DataManager::Flush()
300{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200301 return SaveValues();
Dees_Troy51a0e822012-09-05 15:24:24 -0400302}
303
304int DataManager::SaveValues()
305{
Ethan Yonker83e82572014-04-04 10:59:28 -0500306#ifndef TW_OEM_BUILD
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200307 if (mBackingFile.empty())
308 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400309
310 string mount_path = GetSettingsStoragePath();
Dees_Troy5bf43922012-09-07 16:07:55 -0400311 PartitionManager.Mount_By_Path(mount_path.c_str(), 1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400312
313 FILE* out = fopen(mBackingFile.c_str(), "wb");
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200314 if (!out)
315 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400316
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200317 int file_version = FILE_VERSION;
318 fwrite(&file_version, 1, sizeof(int), out);
Dees_Troy51a0e822012-09-05 15:24:24 -0400319
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200320 map<string, TStrIntPair>::iterator iter;
321 for (iter = mValues.begin(); iter != mValues.end(); ++iter)
322 {
323 // Save only the persisted data
324 if (iter->second.second != 0)
325 {
326 unsigned short length = (unsigned short) iter->first.length() + 1;
327 fwrite(&length, 1, sizeof(unsigned short), out);
328 fwrite(iter->first.c_str(), 1, length, out);
329 length = (unsigned short) iter->second.first.length() + 1;
330 fwrite(&length, 1, sizeof(unsigned short), out);
331 fwrite(iter->second.first.c_str(), 1, length, out);
332 }
333 }
334 fclose(out);
Ethan Yonker83e82572014-04-04 10:59:28 -0500335#endif // ifdef TW_OEM_BUILD
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200336 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400337}
338
339int DataManager::GetValue(const string varName, string& value)
340{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200341 string localStr = varName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400342
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200343 if (!mInitialized)
344 SetDefaultValues();
Dees_Troy51a0e822012-09-05 15:24:24 -0400345
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200346 // Strip off leading and trailing '%' if provided
347 if (localStr.length() > 2 && localStr[0] == '%' && localStr[localStr.length()-1] == '%')
348 {
349 localStr.erase(0, 1);
350 localStr.erase(localStr.length() - 1, 1);
351 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400352
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200353 // Handle magic values
354 if (GetMagicValue(localStr, value) == 0)
355 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400356
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200357 map<string, string>::iterator constPos;
358 constPos = mConstValues.find(localStr);
359 if (constPos != mConstValues.end())
360 {
361 value = constPos->second;
362 return 0;
363 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400364
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200365 map<string, TStrIntPair>::iterator pos;
366 pos = mValues.find(localStr);
367 if (pos == mValues.end())
368 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400369
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200370 value = pos->second.first;
371 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400372}
373
374int DataManager::GetValue(const string varName, int& value)
375{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200376 string data;
Dees_Troy51a0e822012-09-05 15:24:24 -0400377
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200378 if (GetValue(varName,data) != 0)
379 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400380
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200381 value = atoi(data.c_str());
382 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400383}
384
Dees_Troy2673cec2013-04-02 20:22:16 +0000385int DataManager::GetValue(const string varName, float& value)
386{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200387 string data;
Dees_Troy2673cec2013-04-02 20:22:16 +0000388
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200389 if (GetValue(varName,data) != 0)
390 return -1;
Dees_Troy2673cec2013-04-02 20:22:16 +0000391
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200392 value = atof(data.c_str());
393 return 0;
Dees_Troy2673cec2013-04-02 20:22:16 +0000394}
395
bigbiff bigbiff2c57d782013-02-19 10:09:21 -0500396unsigned long long DataManager::GetValue(const string varName, unsigned long long& value)
397{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200398 string data;
bigbiff bigbiff2c57d782013-02-19 10:09:21 -0500399
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200400 if (GetValue(varName,data) != 0)
401 return -1;
bigbiff bigbiff2c57d782013-02-19 10:09:21 -0500402
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200403 value = strtoull(data.c_str(), NULL, 10);
404 return 0;
bigbiff bigbiff2c57d782013-02-19 10:09:21 -0500405}
406
Dees_Troy51a0e822012-09-05 15:24:24 -0400407// This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str
408string& DataManager::GetValueRef(const string varName)
409{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200410 if (!mInitialized)
411 SetDefaultValues();
Dees_Troy51a0e822012-09-05 15:24:24 -0400412
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200413 map<string, string>::iterator constPos;
414 constPos = mConstValues.find(varName);
415 if (constPos != mConstValues.end())
416 return constPos->second;
Dees_Troy51a0e822012-09-05 15:24:24 -0400417
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200418 map<string, TStrIntPair>::iterator pos;
419 pos = mValues.find(varName);
420 if (pos == mValues.end())
421 pos = (mValues.insert(TNameValuePair(varName, TStrIntPair("", 0)))).first;
Dees_Troy51a0e822012-09-05 15:24:24 -0400422
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200423 return pos->second.first;
Dees_Troy51a0e822012-09-05 15:24:24 -0400424}
425
426// This function will return an empty string if the value doesn't exist
427string DataManager::GetStrValue(const string varName)
428{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200429 string retVal;
Dees_Troy51a0e822012-09-05 15:24:24 -0400430
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200431 GetValue(varName, retVal);
432 return retVal;
Dees_Troy51a0e822012-09-05 15:24:24 -0400433}
434
435// This function will return 0 if the value doesn't exist
436int DataManager::GetIntValue(const string varName)
437{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200438 string retVal;
Dees_Troy51a0e822012-09-05 15:24:24 -0400439
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200440 GetValue(varName, retVal);
441 return atoi(retVal.c_str());
Dees_Troy51a0e822012-09-05 15:24:24 -0400442}
443
444int DataManager::SetValue(const string varName, string value, int persist /* = 0 */)
445{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200446 if (!mInitialized)
447 SetDefaultValues();
Dees_Troy51a0e822012-09-05 15:24:24 -0400448
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200449 // Don't allow empty values or numerical starting values
450 if (varName.empty() || (varName[0] >= '0' && varName[0] <= '9'))
451 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400452
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200453 map<string, string>::iterator constChk;
454 constChk = mConstValues.find(varName);
455 if (constChk != mConstValues.end())
456 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400457
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200458 map<string, TStrIntPair>::iterator pos;
459 pos = mValues.find(varName);
460 if (pos == mValues.end())
461 pos = (mValues.insert(TNameValuePair(varName, TStrIntPair(value, persist)))).first;
462 else
463 pos->second.first = value;
Dees_Troy51a0e822012-09-05 15:24:24 -0400464
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200465 if (pos->second.second != 0)
466 SaveValues();
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700467
468#ifndef TW_NO_SCREEN_TIMEOUT
bigbiff bigbifff8e2f372013-02-27 20:50:43 -0500469 if (varName == "tw_screen_timeout_secs") {
Dees_Troy2f9117a2013-02-17 19:52:09 -0600470 blankTimer.setTime(atoi(value.c_str()));
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700471 } else
472#endif
473 if (varName == "tw_storage_path") {
Dees_Troya13d74f2013-03-24 08:54:55 -0500474 SetBackupFolder();
bigbiff bigbifff8e2f372013-02-27 20:50:43 -0500475 }
Dees_Troya13d74f2013-03-24 08:54:55 -0500476 gui_notifyVarChange(varName.c_str(), value.c_str());
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200477 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400478}
479
480int DataManager::SetValue(const string varName, int value, int persist /* = 0 */)
481{
482 ostringstream valStr;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200483 valStr << value;
Dees_Troy51a0e822012-09-05 15:24:24 -0400484 if (varName == "tw_use_external_storage") {
485 string str;
486
487 if (GetIntValue(TW_HAS_DUAL_STORAGE) == 1) {
488 if (value == 0) {
489 str = GetStrValue(TW_INTERNAL_PATH);
Dees_Troy51a0e822012-09-05 15:24:24 -0400490 } else {
491 str = GetStrValue(TW_EXTERNAL_PATH);
Dees_Troy51a0e822012-09-05 15:24:24 -0400492 }
493 } else if (GetIntValue(TW_HAS_INTERNAL) == 1)
494 str = GetStrValue(TW_INTERNAL_PATH);
495 else
496 str = GetStrValue(TW_EXTERNAL_PATH);
497
Dees_Troya13d74f2013-03-24 08:54:55 -0500498 SetValue("tw_storage_path", str);
Dees_Troy51a0e822012-09-05 15:24:24 -0400499 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200500 return SetValue(varName, valStr.str(), persist);
Dees_Troy51a0e822012-09-05 15:24:24 -0400501}
502
503int DataManager::SetValue(const string varName, float value, int persist /* = 0 */)
504{
505 ostringstream valStr;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200506 valStr << value;
507 return SetValue(varName, valStr.str(), persist);;
Dees_Troy51a0e822012-09-05 15:24:24 -0400508}
509
bigbiff bigbiff2c57d782013-02-19 10:09:21 -0500510int DataManager::SetValue(const string varName, unsigned long long value, int persist /* = 0 */)
511{
512 ostringstream valStr;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200513 valStr << value;
514 return SetValue(varName, valStr.str(), persist);
bigbiff bigbiff2c57d782013-02-19 10:09:21 -0500515}
516
Dees_Troy2673cec2013-04-02 20:22:16 +0000517int DataManager::SetProgress(float Fraction) {
518 return SetValue("ui_progress", (float) (Fraction * 100.0));
519}
520
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200521int DataManager::ShowProgress(float Portion, float Seconds)
522{
Dees_Troy2673cec2013-04-02 20:22:16 +0000523 float Starting_Portion;
524 GetValue("ui_progress_portion", Starting_Portion);
525 if (SetValue("ui_progress_portion", (float)(Portion * 100.0) + Starting_Portion) != 0)
526 return -1;
527 if (SetValue("ui_progress_frames", Seconds * 30) != 0)
528 return -1;
529 return 0;
530}
531
Dees_Troy51a0e822012-09-05 15:24:24 -0400532void DataManager::DumpValues()
533{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200534 map<string, TStrIntPair>::iterator iter;
535 gui_print("Data Manager dump - Values with leading X are persisted.\n");
536 for (iter = mValues.begin(); iter != mValues.end(); ++iter)
537 gui_print("%c %s=%s\n", iter->second.second ? 'X' : ' ', iter->first.c_str(), iter->second.first.c_str());
Dees_Troy51a0e822012-09-05 15:24:24 -0400538}
539
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200540void DataManager::update_tz_environment_variables(void)
541{
Dees_Troy8170a922012-09-18 15:40:25 -0400542 setenv("TZ", DataManager_GetStrValue(TW_TIME_ZONE_VAR), 1);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200543 tzset();
Dees_Troy8170a922012-09-18 15:40:25 -0400544}
545
Dees_Troy16b74352012-11-14 22:27:31 +0000546void DataManager::SetBackupFolder()
547{
548 string str = GetCurrentStoragePath();
Dees_Troya13d74f2013-03-24 08:54:55 -0500549 TWPartition* partition = PartitionManager.Find_Partition_By_Path(str);
Dees_Troy16b74352012-11-14 22:27:31 +0000550 str += "/TWRP/BACKUPS/";
551
552 string dev_id;
553 GetValue("device_id", dev_id);
554
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200555 str += dev_id;
Dees_Troy2673cec2013-04-02 20:22:16 +0000556 LOGINFO("Backup folder set to '%s'\n", str.c_str());
Dees_Troy16b74352012-11-14 22:27:31 +0000557 SetValue(TW_BACKUPS_FOLDER_VAR, str, 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500558 if (partition != NULL) {
559 SetValue("tw_storage_display_name", partition->Storage_Name);
560 char free_space[255];
561 sprintf(free_space, "%llu", partition->Free / 1024 / 1024);
562 SetValue("tw_storage_free_size", free_space);
563 string zip_path, zip_root, storage_path;
564 GetValue(TW_ZIP_LOCATION_VAR, zip_path);
565 if (partition->Has_Data_Media)
566 storage_path = partition->Symlink_Mount_Point;
567 else
568 storage_path = partition->Storage_Path;
569 if (zip_path.size() < storage_path.size()) {
570 SetValue(TW_ZIP_LOCATION_VAR, storage_path);
571 } else {
Dees Troyc2e9bc72013-09-10 00:16:24 +0000572 zip_root = TWFunc::Get_Root_Path(zip_path);
Dees_Troy18727952013-06-20 15:24:48 -0500573 if (zip_root != storage_path) {
574 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_Troya13d74f2013-03-24 08:54:55 -0500575 SetValue(TW_ZIP_LOCATION_VAR, storage_path);
Dees_Troy18727952013-06-20 15:24:48 -0500576 }
Dees_Troya13d74f2013-03-24 08:54:55 -0500577 }
578 } else {
579 if (PartitionManager.Fstab_Processed() != 0)
Dees_Troy2673cec2013-04-02 20:22:16 +0000580 LOGERR("Storage partition '%s' not found\n", str.c_str());
Dees_Troya13d74f2013-03-24 08:54:55 -0500581 }
Dees_Troy16b74352012-11-14 22:27:31 +0000582}
583
Dees_Troy51a0e822012-09-05 15:24:24 -0400584void DataManager::SetDefaultValues()
585{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200586 string str, path;
Dees_Troy51a0e822012-09-05 15:24:24 -0400587
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200588 get_device_id();
Dees_Troy51a0e822012-09-05 15:24:24 -0400589
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200590 mInitialized = 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400591
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200592 mConstValues.insert(make_pair("true", "1"));
593 mConstValues.insert(make_pair("false", "0"));
Dees_Troy51a0e822012-09-05 15:24:24 -0400594
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200595 mConstValues.insert(make_pair(TW_VERSION_VAR, TW_VERSION_STR));
Ethan Yonker03db3262014-02-05 08:02:06 -0600596 mValues.insert(make_pair("tw_button_vibrate", make_pair("80", 1)));
597 mValues.insert(make_pair("tw_keyboard_vibrate", make_pair("40", 1)));
598 mValues.insert(make_pair("tw_action_vibrate", make_pair("160", 1)));
Dees_Troy51a0e822012-09-05 15:24:24 -0400599
Vojtech Bocek93cb1ef2014-05-12 15:41:52 +0200600 TWPartition *store = PartitionManager.Get_Default_Storage_Partition();
601 if(store)
602 mValues.insert(make_pair("tw_storage_path", make_pair(store->Storage_Path.c_str(), 1)));
603 else
604 mValues.insert(make_pair("tw_storage_path", make_pair("/", 1)));
605
Dees_Troyf4499812013-01-23 19:07:38 +0000606#ifdef TW_FORCE_CPUINFO_FOR_DEVICE_ID
607 printf("TW_FORCE_CPUINFO_FOR_DEVICE_ID := true\n");
608#endif
609
Dees_Troy51a0e822012-09-05 15:24:24 -0400610#ifdef BOARD_HAS_NO_REAL_SDCARD
Dees_Troyf4499812013-01-23 19:07:38 +0000611 printf("BOARD_HAS_NO_REAL_SDCARD := true\n");
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200612 mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "0"));
Dees_Troy51a0e822012-09-05 15:24:24 -0400613#else
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200614 mConstValues.insert(make_pair(TW_ALLOW_PARTITION_SDCARD, "1"));
Dees_Troy51a0e822012-09-05 15:24:24 -0400615#endif
616
617#ifdef TW_INCLUDE_DUMLOCK
Dees_Troyf4499812013-01-23 19:07:38 +0000618 printf("TW_INCLUDE_DUMLOCK := true\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400619 mConstValues.insert(make_pair(TW_SHOW_DUMLOCK, "1"));
620#else
621 mConstValues.insert(make_pair(TW_SHOW_DUMLOCK, "0"));
622#endif
623
Dees_Troy51a0e822012-09-05 15:24:24 -0400624 str = GetCurrentStoragePath();
Dees_Troy51a0e822012-09-05 15:24:24 -0400625 SetValue(TW_ZIP_LOCATION_VAR, str.c_str(), 1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400626 str += "/TWRP/BACKUPS/";
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400627
628 string dev_id;
629 GetValue("device_id", dev_id);
630
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200631 str += dev_id;
Dees_Troy51a0e822012-09-05 15:24:24 -0400632 SetValue(TW_BACKUPS_FOLDER_VAR, str, 0);
633
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200634 mConstValues.insert(make_pair(TW_REBOOT_SYSTEM, "1"));
Dees_Troy51a0e822012-09-05 15:24:24 -0400635#ifdef TW_NO_REBOOT_RECOVERY
Talustus33ebf932013-02-02 14:11:14 +0100636 printf("TW_NO_REBOOT_RECOVERY := true\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400637 mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, "0"));
638#else
Dees_Troya58bead2012-09-27 09:49:29 -0400639 mConstValues.insert(make_pair(TW_REBOOT_RECOVERY, "1"));
Dees_Troy51a0e822012-09-05 15:24:24 -0400640#endif
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200641 mConstValues.insert(make_pair(TW_REBOOT_POWEROFF, "1"));
Dees_Troy51a0e822012-09-05 15:24:24 -0400642#ifdef TW_NO_REBOOT_BOOTLOADER
Talustus33ebf932013-02-02 14:11:14 +0100643 printf("TW_NO_REBOOT_BOOTLOADER := true\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400644 mConstValues.insert(make_pair(TW_REBOOT_BOOTLOADER, "0"));
645#else
Dees_Troya58bead2012-09-27 09:49:29 -0400646 mConstValues.insert(make_pair(TW_REBOOT_BOOTLOADER, "1"));
Dees_Troy51a0e822012-09-05 15:24:24 -0400647#endif
648#ifdef RECOVERY_SDCARD_ON_DATA
Dees_Troyf4499812013-01-23 19:07:38 +0000649 printf("RECOVERY_SDCARD_ON_DATA := true\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400650 mConstValues.insert(make_pair(TW_HAS_DATA_MEDIA, "1"));
Ethan Yonker6277c792014-09-15 14:54:30 -0500651 mConstValues.insert(make_pair("tw_has_internal", "1"));
652 datamedia = true;
Dees_Troy51a0e822012-09-05 15:24:24 -0400653#else
Ethan Yonker6277c792014-09-15 14:54:30 -0500654 mValues.insert(make_pair(TW_HAS_DATA_MEDIA, make_pair("0", 0)));
655 mValues.insert(make_pair("tw_has_internal", make_pair("0", 0)));
Dees_Troy51a0e822012-09-05 15:24:24 -0400656#endif
657#ifdef TW_NO_BATT_PERCENT
Dees_Troyf4499812013-01-23 19:07:38 +0000658 printf("TW_NO_BATT_PERCENT := true\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400659 mConstValues.insert(make_pair(TW_NO_BATTERY_PERCENT, "1"));
660#else
661 mConstValues.insert(make_pair(TW_NO_BATTERY_PERCENT, "0"));
662#endif
663#ifdef TW_CUSTOM_POWER_BUTTON
Dees_Troyf4499812013-01-23 19:07:38 +0000664 printf("TW_POWER_BUTTON := %s\n", EXPAND(TW_CUSTOM_POWER_BUTTON));
Dees_Troy51a0e822012-09-05 15:24:24 -0400665 mConstValues.insert(make_pair(TW_POWER_BUTTON, EXPAND(TW_CUSTOM_POWER_BUTTON)));
666#else
667 mConstValues.insert(make_pair(TW_POWER_BUTTON, "0"));
668#endif
669#ifdef TW_ALWAYS_RMRF
Dees_Troyf4499812013-01-23 19:07:38 +0000670 printf("TW_ALWAYS_RMRF := true\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400671 mConstValues.insert(make_pair(TW_RM_RF_VAR, "1"));
672#endif
673#ifdef TW_NEVER_UNMOUNT_SYSTEM
Dees_Troyf4499812013-01-23 19:07:38 +0000674 printf("TW_NEVER_UNMOUNT_SYSTEM := true\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400675 mConstValues.insert(make_pair(TW_DONT_UNMOUNT_SYSTEM, "1"));
676#else
677 mConstValues.insert(make_pair(TW_DONT_UNMOUNT_SYSTEM, "0"));
678#endif
679#ifdef TW_NO_USB_STORAGE
Dees_Troy6a042c82013-01-23 18:50:52 +0000680 printf("TW_NO_USB_STORAGE := true\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400681 mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "0"));
682#else
Dees_Troy6a042c82013-01-23 18:50:52 +0000683 char lun_file[255];
684 string Lun_File_str = CUSTOM_LUN_FILE;
685 size_t found = Lun_File_str.find("%");
686 if (found != string::npos) {
687 sprintf(lun_file, CUSTOM_LUN_FILE, 0);
688 Lun_File_str = lun_file;
689 }
690 if (!TWFunc::Path_Exists(Lun_File_str)) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000691 LOGINFO("Lun file '%s' does not exist, USB storage mode disabled\n", Lun_File_str.c_str());
Dees_Troy6a042c82013-01-23 18:50:52 +0000692 mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "0"));
693 } else {
Dees_Troy2673cec2013-04-02 20:22:16 +0000694 LOGINFO("Lun file '%s'\n", Lun_File_str.c_str());
Dees_Troy6a042c82013-01-23 18:50:52 +0000695 mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "1"));
696 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400697#endif
698#ifdef TW_INCLUDE_INJECTTWRP
Dees_Troyf4499812013-01-23 19:07:38 +0000699 printf("TW_INCLUDE_INJECTTWRP := true\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400700 mConstValues.insert(make_pair(TW_HAS_INJECTTWRP, "1"));
701 mValues.insert(make_pair(TW_INJECT_AFTER_ZIP, make_pair("1", 1)));
702#else
703 mConstValues.insert(make_pair(TW_HAS_INJECTTWRP, "0"));
704 mValues.insert(make_pair(TW_INJECT_AFTER_ZIP, make_pair("0", 1)));
705#endif
Dees_Troy51a0e822012-09-05 15:24:24 -0400706#ifdef TW_HAS_DOWNLOAD_MODE
Dees_Troyf4499812013-01-23 19:07:38 +0000707 printf("TW_HAS_DOWNLOAD_MODE := true\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400708 mConstValues.insert(make_pair(TW_DOWNLOAD_MODE, "1"));
709#endif
710#ifdef TW_INCLUDE_CRYPTO
711 mConstValues.insert(make_pair(TW_HAS_CRYPTO, "1"));
Dees_Troyf4499812013-01-23 19:07:38 +0000712 printf("TW_INCLUDE_CRYPTO := true\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400713#endif
714#ifdef TW_SDEXT_NO_EXT4
Dees_Troyf4499812013-01-23 19:07:38 +0000715 printf("TW_SDEXT_NO_EXT4 := true\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400716 mConstValues.insert(make_pair(TW_SDEXT_DISABLE_EXT4, "1"));
717#else
718 mConstValues.insert(make_pair(TW_SDEXT_DISABLE_EXT4, "0"));
719#endif
720
Dees_Troya13d74f2013-03-24 08:54:55 -0500721#ifdef TW_HAS_NO_BOOT_PARTITION
Dees_Troyf100c942013-06-21 08:15:31 -0500722 mValues.insert(make_pair("tw_backup_list", make_pair("/system;/data;", 1)));
Dees_Troya13d74f2013-03-24 08:54:55 -0500723#else
Dees_Troyf100c942013-06-21 08:15:31 -0500724 mValues.insert(make_pair("tw_backup_list", make_pair("/system;/data;/boot;", 1)));
Dees_Troya13d74f2013-03-24 08:54:55 -0500725#endif
726 mConstValues.insert(make_pair(TW_MIN_SYSTEM_VAR, TW_MIN_SYSTEM_SIZE));
Dees Troyb21cc642013-09-10 17:36:41 +0000727 mValues.insert(make_pair(TW_BACKUP_NAME, make_pair("(Auto Generate)", 0)));
bigbiff bigbiff7ce7f0c2013-01-25 09:54:04 -0500728
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200729 mValues.insert(make_pair(TW_REBOOT_AFTER_FLASH_VAR, make_pair("0", 1)));
730 mValues.insert(make_pair(TW_SIGNED_ZIP_VERIFY_VAR, make_pair("0", 1)));
731 mValues.insert(make_pair(TW_FORCE_MD5_CHECK_VAR, make_pair("0", 1)));
732 mValues.insert(make_pair(TW_COLOR_THEME_VAR, make_pair("0", 1)));
733 mValues.insert(make_pair(TW_USE_COMPRESSION_VAR, make_pair("0", 1)));
734 mValues.insert(make_pair(TW_SHOW_SPAM_VAR, make_pair("0", 1)));
735 mValues.insert(make_pair(TW_TIME_ZONE_VAR, make_pair("CST6CDT", 1)));
736 mValues.insert(make_pair(TW_SORT_FILES_BY_DATE_VAR, make_pair("0", 1)));
737 mValues.insert(make_pair(TW_GUI_SORT_ORDER, make_pair("1", 1)));
738 mValues.insert(make_pair(TW_RM_RF_VAR, make_pair("0", 1)));
739 mValues.insert(make_pair(TW_SKIP_MD5_CHECK_VAR, make_pair("0", 1)));
740 mValues.insert(make_pair(TW_SKIP_MD5_GENERATE_VAR, make_pair("0", 1)));
741 mValues.insert(make_pair(TW_SDEXT_SIZE, make_pair("512", 1)));
742 mValues.insert(make_pair(TW_SWAP_SIZE, make_pair("32", 1)));
743 mValues.insert(make_pair(TW_SDPART_FILE_SYSTEM, make_pair("ext3", 1)));
744 mValues.insert(make_pair(TW_TIME_ZONE_GUISEL, make_pair("CST6;CDT", 1)));
745 mValues.insert(make_pair(TW_TIME_ZONE_GUIOFFSET, make_pair("0", 1)));
746 mValues.insert(make_pair(TW_TIME_ZONE_GUIDST, make_pair("1", 1)));
747 mValues.insert(make_pair(TW_ACTION_BUSY, make_pair("0", 0)));
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200748 mValues.insert(make_pair("tw_wipe_cache", make_pair("0", 0)));
749 mValues.insert(make_pair("tw_wipe_dalvik", make_pair("0", 0)));
Dees_Troy51a0e822012-09-05 15:24:24 -0400750 if (GetIntValue(TW_HAS_INTERNAL) == 1 && GetIntValue(TW_HAS_DATA_MEDIA) == 1 && GetIntValue(TW_HAS_EXTERNAL) == 0)
751 SetValue(TW_HAS_USB_STORAGE, 0, 0);
752 else
753 SetValue(TW_HAS_USB_STORAGE, 1, 0);
754 mValues.insert(make_pair(TW_ZIP_INDEX, make_pair("0", 0)));
755 mValues.insert(make_pair(TW_ZIP_QUEUE_COUNT, make_pair("0", 0)));
756 mValues.insert(make_pair(TW_FILENAME, make_pair("/sdcard", 0)));
757 mValues.insert(make_pair(TW_SIMULATE_ACTIONS, make_pair("0", 1)));
758 mValues.insert(make_pair(TW_SIMULATE_FAIL, make_pair("0", 1)));
759 mValues.insert(make_pair(TW_IS_ENCRYPTED, make_pair("0", 0)));
760 mValues.insert(make_pair(TW_IS_DECRYPTED, make_pair("0", 0)));
761 mValues.insert(make_pair(TW_CRYPTO_PASSWORD, make_pair("0", 0)));
762 mValues.insert(make_pair(TW_DATA_BLK_DEVICE, make_pair("0", 0)));
763 mValues.insert(make_pair("tw_terminal_state", make_pair("0", 0)));
764 mValues.insert(make_pair("tw_background_thread_running", make_pair("0", 0)));
765 mValues.insert(make_pair(TW_RESTORE_FILE_DATE, make_pair("0", 0)));
bigbiff bigbifff8e2f372013-02-27 20:50:43 -0500766 mValues.insert(make_pair("tw_military_time", make_pair("0", 1)));
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700767#ifdef TW_NO_SCREEN_TIMEOUT
768 mValues.insert(make_pair("tw_screen_timeout_secs", make_pair("0", 1)));
769 mValues.insert(make_pair("tw_no_screen_timeout", make_pair("1", 1)));
770#else
Dees_Troy2f9117a2013-02-17 19:52:09 -0600771 mValues.insert(make_pair("tw_screen_timeout_secs", make_pair("60", 1)));
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700772 mValues.insert(make_pair("tw_no_screen_timeout", make_pair("0", 1)));
773#endif
Dees_Troy6ef66352013-02-21 08:26:57 -0600774 mValues.insert(make_pair("tw_gui_done", make_pair("0", 0)));
Dees_Troy83bd4832013-05-04 12:39:56 +0000775 mValues.insert(make_pair("tw_encrypt_backup", make_pair("0", 0)));
Vojtech Bocek85932342013-04-01 22:11:33 +0200776#ifdef TW_BRIGHTNESS_PATH
Ethan Yonker00028b42014-04-09 14:29:02 -0500777 string findbright;
Dees_Troy2f9117a2013-02-17 19:52:09 -0600778 if (strcmp(EXPAND(TW_BRIGHTNESS_PATH), "/nobrightness") != 0) {
Ethan Yonker00028b42014-04-09 14:29:02 -0500779 findbright = EXPAND(TW_BRIGHTNESS_PATH);
780 LOGINFO("TW_BRIGHTNESS_PATH := %s\n", findbright.c_str());
781 if (!TWFunc::Path_Exists(findbright)) {
782 LOGINFO("Specified brightness file '%s' not found.\n", findbright.c_str());
783 findbright = "";
784 }
785 }
786 if (findbright.empty()) {
787 // Attempt to locate the brightness file
788 findbright = Find_File::Find("brightness", "/sys/class/backlight");
Ethan Yonker9c102b52014-04-15 11:06:18 -0500789 if (findbright.empty()) findbright = Find_File::Find("brightness", "/sys/class/leds/lcd-backlight");
Ethan Yonker00028b42014-04-09 14:29:02 -0500790 }
791 if (findbright.empty()) {
792 LOGINFO("Unable to locate brightness file\n");
793 mConstValues.insert(make_pair("tw_has_brightnesss_file", "0"));
794 } else {
795 LOGINFO("Found brightness file at '%s'\n", findbright.c_str());
Dees_Troy2f9117a2013-02-17 19:52:09 -0600796 mConstValues.insert(make_pair("tw_has_brightnesss_file", "1"));
Ethan Yonker00028b42014-04-09 14:29:02 -0500797 mConstValues.insert(make_pair("tw_brightness_file", findbright));
Vojtech Bocek85932342013-04-01 22:11:33 +0200798 ostringstream maxVal;
799 maxVal << TW_MAX_BRIGHTNESS;
800 mConstValues.insert(make_pair("tw_brightness_max", maxVal.str()));
801 mValues.insert(make_pair("tw_brightness", make_pair(maxVal.str(), 1)));
802 mValues.insert(make_pair("tw_brightness_pct", make_pair("100", 1)));
xNUTxe85f02d2014-07-18 01:30:58 +0200803#ifdef TW_SECONDARY_BRIGHTNESS_PATH
804 string secondfindbright = EXPAND(TW_SECONDARY_BRIGHTNESS_PATH);
805 if (secondfindbright != "" && TWFunc::Path_Exists(secondfindbright)) {
806 LOGINFO("Will use a second brightness file at '%s'\n", secondfindbright.c_str());
807 mConstValues.insert(make_pair("tw_secondary_brightness_file", secondfindbright));
808 } else {
809 LOGINFO("Specified secondary brightness file '%s' not found.\n", secondfindbright.c_str());
810 }
811#endif
Ethan Yonkera18f1082014-07-07 15:07:58 -0500812 string max_bright = maxVal.str();
xNUTxe85f02d2014-07-18 01:30:58 +0200813 TWFunc::Set_Brightness(max_bright);
Dees_Troy2f9117a2013-02-17 19:52:09 -0600814 }
815#endif
Dees_Troya13d74f2013-03-24 08:54:55 -0500816 mValues.insert(make_pair(TW_MILITARY_TIME, make_pair("0", 1)));
Dees_Troy83bd4832013-05-04 12:39:56 +0000817#ifndef TW_EXCLUDE_ENCRYPTED_BACKUPS
818 mValues.insert(make_pair("tw_include_encrypted_backup", make_pair("1", 0)));
819#else
820 LOGINFO("TW_EXCLUDE_ENCRYPTED_BACKUPS := true\n");
821 mValues.insert(make_pair("tw_include_encrypted_backup", make_pair("0", 0)));
822#endif
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400823#ifdef TW_HAS_MTP
824 mConstValues.insert(make_pair("tw_has_mtp", "1"));
825 mValues.insert(make_pair("tw_mtp_enabled", make_pair("1", 1)));
Ethan Yonkerc8743cf2014-09-03 21:16:40 -0500826 mValues.insert(make_pair("tw_mtp_debug", make_pair("0", 1)));
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400827#else
828 LOGINFO("TW_EXCLUDE_MTP := true\n");
829 mConstValues.insert(make_pair("tw_has_mtp", "0"));
830 mConstValues.insert(make_pair("tw_mtp_enabled", "0"));
831#endif
Dees_Troy51a0e822012-09-05 15:24:24 -0400832}
833
834// Magic Values
835int DataManager::GetMagicValue(const string varName, string& value)
836{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200837 // Handle special dynamic cases
838 if (varName == "tw_time")
839 {
840 char tmp[32];
Dees_Troy51a0e822012-09-05 15:24:24 -0400841
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200842 struct tm *current;
843 time_t now;
844 int tw_military_time;
845 now = time(0);
846 current = localtime(&now);
Matt Mowerfb1c4ff2014-04-16 13:43:36 -0500847 GetValue(TW_MILITARY_TIME, tw_military_time);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200848 if (current->tm_hour >= 12)
849 {
850 if (tw_military_time == 1)
851 sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min);
852 else
853 sprintf(tmp, "%d:%02d PM", current->tm_hour == 12 ? 12 : current->tm_hour - 12, current->tm_min);
bigbiff bigbiff4efe9c32013-02-20 18:58:11 -0500854 }
bigbiff bigbiff4efe9c32013-02-20 18:58:11 -0500855 else
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200856 {
Matt Mowerfb1c4ff2014-04-16 13:43:36 -0500857 if (tw_military_time == 1)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200858 sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min);
859 else
860 sprintf(tmp, "%d:%02d AM", current->tm_hour == 0 ? 12 : current->tm_hour, current->tm_min);
861 }
862 value = tmp;
863 return 0;
bigbiff bigbiff4efe9c32013-02-20 18:58:11 -0500864 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200865 else if (varName == "tw_battery")
866 {
867 char tmp[16];
Dees_Troy38bd7602012-09-14 13:33:53 -0400868 static char charging = ' ';
869 static int lastVal = -1;
870 static time_t nextSecCheck = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400871
Dees_Troy38bd7602012-09-14 13:33:53 -0400872 struct timeval curTime;
873 gettimeofday(&curTime, NULL);
874 if (curTime.tv_sec > nextSecCheck)
875 {
876 char cap_s[4];
Dees_Troyf33b4902013-03-01 00:51:39 +0000877#ifdef TW_CUSTOM_BATTERY_PATH
878 string capacity_file = EXPAND(TW_CUSTOM_BATTERY_PATH);
879 capacity_file += "/capacity";
880 FILE * cap = fopen(capacity_file.c_str(),"rt");
881#else
Dees_Troy38bd7602012-09-14 13:33:53 -0400882 FILE * cap = fopen("/sys/class/power_supply/battery/capacity","rt");
Dees_Troyf33b4902013-03-01 00:51:39 +0000883#endif
Dees_Troy38bd7602012-09-14 13:33:53 -0400884 if (cap){
885 fgets(cap_s, 4, cap);
886 fclose(cap);
887 lastVal = atoi(cap_s);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200888 if (lastVal > 100) lastVal = 101;
889 if (lastVal < 0) lastVal = 0;
Dees_Troy38bd7602012-09-14 13:33:53 -0400890 }
Dees_Troyf33b4902013-03-01 00:51:39 +0000891#ifdef TW_CUSTOM_BATTERY_PATH
892 string status_file = EXPAND(TW_CUSTOM_BATTERY_PATH);
893 status_file += "/status";
894 cap = fopen(status_file.c_str(),"rt");
895#else
Dees_Troy38bd7602012-09-14 13:33:53 -0400896 cap = fopen("/sys/class/power_supply/battery/status","rt");
Dees_Troyf33b4902013-03-01 00:51:39 +0000897#endif
Dees_Troy38bd7602012-09-14 13:33:53 -0400898 if (cap) {
899 fgets(cap_s, 2, cap);
900 fclose(cap);
901 if (cap_s[0] == 'C')
902 charging = '+';
903 else
904 charging = ' ';
905 }
906 nextSecCheck = curTime.tv_sec + 60;
907 }
908
909 sprintf(tmp, "%i%%%c", lastVal, charging);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200910 value = tmp;
911 return 0;
912 }
913 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400914}
915
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200916void DataManager::Output_Version(void)
917{
Dees_Troy1c1ac442013-01-17 21:42:14 +0000918 string Path;
Dees_Troy01a9b7a2012-10-01 09:01:03 -0400919 char version[255];
920
Dees_Troy1c1ac442013-01-17 21:42:14 +0000921 if (!PartitionManager.Mount_By_Path("/cache", false)) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000922 LOGINFO("Unable to mount '%s' to write version number.\n", Path.c_str());
Dees_Troy01a9b7a2012-10-01 09:01:03 -0400923 return;
924 }
Dees_Troy1c1ac442013-01-17 21:42:14 +0000925 if (!TWFunc::Path_Exists("/cache/recovery/.")) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000926 LOGINFO("Recreating /cache/recovery folder.\n");
Dees_Troy1c1ac442013-01-17 21:42:14 +0000927 if (mkdir("/cache/recovery", S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP) != 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000928 LOGERR("DataManager::Output_Version -- Unable to make /cache/recovery\n");
Dees_Troy1c1ac442013-01-17 21:42:14 +0000929 return;
930 }
931 }
932 Path = "/cache/recovery/.version";
Dees_Troy01a9b7a2012-10-01 09:01:03 -0400933 if (TWFunc::Path_Exists(Path)) {
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500934 unlink(Path.c_str());
Dees_Troy01a9b7a2012-10-01 09:01:03 -0400935 }
936 FILE *fp = fopen(Path.c_str(), "w");
937 if (fp == NULL) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000938 LOGERR("Unable to open '%s'.\n", Path.c_str());
Dees_Troy01a9b7a2012-10-01 09:01:03 -0400939 return;
940 }
941 strcpy(version, TW_VERSION_STR);
942 fwrite(version, sizeof(version[0]), strlen(version) / sizeof(version[0]), fp);
943 fclose(fp);
Dees_Troyd93bda52013-07-03 19:55:19 +0000944 TWFunc::copy_file("/etc/recovery.fstab", "/cache/recovery/recovery.fstab", 0644);
945 PartitionManager.Output_Storage_Fstab();
Dees_Troy01a9b7a2012-10-01 09:01:03 -0400946 sync();
Dees_Troy2673cec2013-04-02 20:22:16 +0000947 LOGINFO("Version number saved to '%s'\n", Path.c_str());
Dees_Troy01a9b7a2012-10-01 09:01:03 -0400948}
949
Dees_Troy51a0e822012-09-05 15:24:24 -0400950void DataManager::ReadSettingsFile(void)
951{
Ethan Yonker83e82572014-04-04 10:59:28 -0500952#ifndef TW_OEM_BUILD
Dees_Troy51a0e822012-09-05 15:24:24 -0400953 // Load up the values for TWRP - Sleep to let the card be ready
954 char mkdir_path[255], settings_file[255];
955 int is_enc, has_dual, use_ext, has_data_media, has_ext;
956
957 GetValue(TW_IS_ENCRYPTED, is_enc);
958 GetValue(TW_HAS_DATA_MEDIA, has_data_media);
959 if (is_enc == 1 && has_data_media == 1) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000960 LOGINFO("Cannot load settings -- encrypted.\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400961 return;
962 }
963
964 memset(mkdir_path, 0, sizeof(mkdir_path));
965 memset(settings_file, 0, sizeof(settings_file));
966 sprintf(mkdir_path, "%s/TWRP", DataManager_GetSettingsStoragePath());
967 sprintf(settings_file, "%s/.twrps", mkdir_path);
968
Dees_Troy5bf43922012-09-07 16:07:55 -0400969 if (!PartitionManager.Mount_Settings_Storage(false))
Dees_Troy51a0e822012-09-05 15:24:24 -0400970 {
971 usleep(500000);
Dees_Troy5bf43922012-09-07 16:07:55 -0400972 if (!PartitionManager.Mount_Settings_Storage(false))
Dees_Troy2673cec2013-04-02 20:22:16 +0000973 LOGERR("Unable to mount %s when trying to read settings file.\n", settings_file);
Dees_Troy51a0e822012-09-05 15:24:24 -0400974 }
975
976 mkdir(mkdir_path, 0777);
977
Dees_Troy2673cec2013-04-02 20:22:16 +0000978 LOGINFO("Attempt to load settings from settings file...\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400979 LoadValues(settings_file);
Dees_Troy01a9b7a2012-10-01 09:01:03 -0400980 Output_Version();
Ethan Yonker83e82572014-04-04 10:59:28 -0500981#endif // ifdef TW_OEM_BUILD
Ethan Yonker7af51ce2014-04-04 13:33:30 -0500982 PartitionManager.Mount_All_Storage();
Dees_Troy8170a922012-09-18 15:40:25 -0400983 update_tz_environment_variables();
xNUTxe85f02d2014-07-18 01:30:58 +0200984#ifdef TW_MAX_BRIGHTNESS
985 if (GetStrValue("tw_brightness_path") != "/nobrightness") {
986 TWFunc::Set_Brightness(GetStrValue("tw_brightness"));
Dees_Troy2f9117a2013-02-17 19:52:09 -0600987 }
xNUTxe85f02d2014-07-18 01:30:58 +0200988#endif
Dees_Troy51a0e822012-09-05 15:24:24 -0400989}
990
991string DataManager::GetCurrentStoragePath(void)
992{
Dees_Troya13d74f2013-03-24 08:54:55 -0500993 return GetStrValue("tw_storage_path");
Dees_Troy51a0e822012-09-05 15:24:24 -0400994}
995
996string& DataManager::CGetCurrentStoragePath()
997{
Dees_Troya13d74f2013-03-24 08:54:55 -0500998 return GetValueRef("tw_storage_path");
Dees_Troy51a0e822012-09-05 15:24:24 -0400999}
1000
1001string DataManager::GetSettingsStoragePath(void)
1002{
Dees_Troya13d74f2013-03-24 08:54:55 -05001003 return GetStrValue("tw_settings_path");
Dees_Troy51a0e822012-09-05 15:24:24 -04001004}
1005
1006string& DataManager::CGetSettingsStoragePath()
1007{
Dees_Troya13d74f2013-03-24 08:54:55 -05001008 return GetValueRef("tw_settings_path");
Dees_Troy51a0e822012-09-05 15:24:24 -04001009}
1010
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001011extern "C" int DataManager_ResetDefaults(void)
Dees_Troy51a0e822012-09-05 15:24:24 -04001012{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001013 return DataManager::ResetDefaults();
Dees_Troy51a0e822012-09-05 15:24:24 -04001014}
1015
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001016extern "C" void DataManager_LoadDefaults(void)
Dees_Troy51a0e822012-09-05 15:24:24 -04001017{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001018 return DataManager::SetDefaultValues();
Dees_Troy51a0e822012-09-05 15:24:24 -04001019}
1020
1021extern "C" int DataManager_LoadValues(const char* filename)
1022{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001023 return DataManager::LoadValues(filename);
Dees_Troy51a0e822012-09-05 15:24:24 -04001024}
1025
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001026extern "C" int DataManager_Flush(void)
Dees_Troy51a0e822012-09-05 15:24:24 -04001027{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001028 return DataManager::Flush();
Dees_Troy51a0e822012-09-05 15:24:24 -04001029}
1030
1031extern "C" int DataManager_GetValue(const char* varName, char* value)
1032{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001033 int ret;
1034 string str;
Dees_Troy51a0e822012-09-05 15:24:24 -04001035
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001036 ret = DataManager::GetValue(varName, str);
1037 if (ret == 0)
1038 strcpy(value, str.c_str());
1039 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -04001040}
1041
1042extern "C" const char* DataManager_GetStrValue(const char* varName)
1043{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001044 string& str = DataManager::GetValueRef(varName);
1045 return str.c_str();
Dees_Troy51a0e822012-09-05 15:24:24 -04001046}
1047
1048extern "C" const char* DataManager_GetCurrentStoragePath(void)
1049{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001050 string& str = DataManager::CGetCurrentStoragePath();
1051 return str.c_str();
Dees_Troy51a0e822012-09-05 15:24:24 -04001052}
1053
1054extern "C" const char* DataManager_GetSettingsStoragePath(void)
1055{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001056 string& str = DataManager::CGetSettingsStoragePath();
1057 return str.c_str();
Dees_Troy51a0e822012-09-05 15:24:24 -04001058}
1059
Dees_Troy51a0e822012-09-05 15:24:24 -04001060extern "C" int DataManager_GetIntValue(const char* varName)
1061{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001062 return DataManager::GetIntValue(varName);
Dees_Troy51a0e822012-09-05 15:24:24 -04001063}
1064
1065extern "C" int DataManager_SetStrValue(const char* varName, char* value)
1066{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001067 return DataManager::SetValue(varName, value, 0);
Dees_Troy51a0e822012-09-05 15:24:24 -04001068}
1069
1070extern "C" int DataManager_SetIntValue(const char* varName, int value)
1071{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001072 return DataManager::SetValue(varName, value, 0);
Dees_Troy51a0e822012-09-05 15:24:24 -04001073}
1074
1075extern "C" int DataManager_SetFloatValue(const char* varName, float value)
1076{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001077 return DataManager::SetValue(varName, value, 0);
Dees_Troy51a0e822012-09-05 15:24:24 -04001078}
1079
1080extern "C" int DataManager_ToggleIntValue(const char* varName)
1081{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001082 if (DataManager::GetIntValue(varName))
1083 return DataManager::SetValue(varName, 0);
1084 else
1085 return DataManager::SetValue(varName, 1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001086}
1087
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001088extern "C" void DataManager_DumpValues(void)
Dees_Troy51a0e822012-09-05 15:24:24 -04001089{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001090 return DataManager::DumpValues();
Dees_Troy51a0e822012-09-05 15:24:24 -04001091}
1092
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001093extern "C" void DataManager_ReadSettingsFile(void)
Dees_Troy51a0e822012-09-05 15:24:24 -04001094{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001095 return DataManager::ReadSettingsFile();
Dees_Troy51a0e822012-09-05 15:24:24 -04001096}
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +00001097void DataManager::Vibrate(const string varName)
1098{
1099 int vib_value = 0;
1100 GetValue(varName, vib_value);
1101 if (vib_value) {
1102 vibrate(vib_value);
1103 }
1104}