blob: 1ea7b84319007b4747ba221af86e9f791bb6ccc8 [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001/*
Ethan Yonkerfe916112016-03-14 14:54:37 -05002 Copyright 2012 to 2016 bigbiff/Dees_Troy TeamWin
Dees Troy3be70a82013-10-22 14:25:12 +00003 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
Dees_Troy51a0e822012-09-05 15:24:24 -040019#include <pthread.h>
Dees_Troy51a0e822012-09-05 15:24:24 -040020#include <time.h>
Dees_Troy51a0e822012-09-05 15:24:24 -040021#include <string>
Dees_Troy51a0e822012-09-05 15:24:24 -040022#include <sstream>
Ethan Yonkerfe916112016-03-14 14:54:37 -050023#include <cctype>
24#include <cutils/properties.h>
Dees_Troy51a0e822012-09-05 15:24:24 -040025
26#include "variables.h"
27#include "data.hpp"
28#include "partitions.hpp"
Dees_Troy01a9b7a2012-10-01 09:01:03 -040029#include "twrp-functions.hpp"
Ricardo Gomezc9ecd442013-07-05 16:13:52 -070030#ifndef TW_NO_SCREEN_TIMEOUT
Dees_Troy2f9117a2013-02-17 19:52:09 -060031#include "gui/blanktimer.hpp"
Ricardo Gomezc9ecd442013-07-05 16:13:52 -070032#endif
Ethan Yonker00028b42014-04-09 14:29:02 -050033#include "find_file.hpp"
Ethan Yonker4b94cfd2014-12-11 10:00:45 -060034#include "set_metadata.h"
Ethan Yonker74db1572015-10-28 12:44:49 -050035#include "gui/gui.hpp"
Ethan Yonkerfe916112016-03-14 14:54:37 -050036#include "infomanager.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040037
Matt Mowere9260742015-02-22 20:20:18 -060038#define DEVID_MAX 64
39#define HWID_MAX 32
Anatoly Smaznov10c11f62013-02-12 13:33:40 +070040
Dees_Troy51a0e822012-09-05 15:24:24 -040041extern "C"
42{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020043 #include "twcommon.h"
Dees_Troy7d15c252012-09-05 20:47:21 -040044 #include "gui/pages.h"
Dees_Troy7d15c252012-09-05 20:47:21 -040045 void gui_notifyVarChange(const char *name, const char* value);
Dees_Troy51a0e822012-09-05 15:24:24 -040046}
Ethan Yonkerfbb43532015-12-28 21:54:50 +010047#include "minuitwrp/minui.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040048
Ethan Yonkerfe916112016-03-14 14:54:37 -050049#define FILE_VERSION 0x00010010 // Do not set to 0
Dees_Troy51a0e822012-09-05 15:24:24 -040050
51using namespace std;
52
Ricardo Gomezc9ecd442013-07-05 16:13:52 -070053string DataManager::mBackingFile;
54int DataManager::mInitialized = 0;
Ethan Yonkerfe916112016-03-14 14:54:37 -050055InfoManager DataManager::mPersist; // Data that that is not constant and will be saved to the settings file
56InfoManager DataManager::mData; // Data that is not constant and will not be saved to settings file
57InfoManager DataManager::mConst; // Data that is constant and will not be saved to settings file
Jenkins1710bf22014-10-02 20:22:21 -040058
Ethan Yonker6277c792014-09-15 14:54:30 -050059extern bool datamedia;
Dees_Troy51a0e822012-09-05 15:24:24 -040060
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050061#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
Vojtech Bocekfda239b2015-01-07 22:55:13 +010062pthread_mutex_t DataManager::m_valuesLock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050063#else
64pthread_mutex_t DataManager::m_valuesLock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
65#endif
Vojtech Bocekfda239b2015-01-07 22:55:13 +010066
Dees_Troyfdf5fcc2012-09-11 10:27:01 -040067// Device ID functions
68void DataManager::sanitize_device_id(char* device_id) {
Matt Mowere9260742015-02-22 20:20:18 -060069 const char* whitelist ="-._";
70 char str[DEVID_MAX];
Dees_Troyfdf5fcc2012-09-11 10:27:01 -040071 char* c = str;
72
Matt Mowere9260742015-02-22 20:20:18 -060073 snprintf(str, DEVID_MAX, "%s", device_id);
74 memset(device_id, 0, strlen(device_id));
Dees_Troyfdf5fcc2012-09-11 10:27:01 -040075 while (*c) {
Matt Mowere9260742015-02-22 20:20:18 -060076 if (isalnum(*c) || strchr(whitelist, *c))
Dees_Troyfdf5fcc2012-09-11 10:27:01 -040077 strncat(device_id, c, 1);
78 c++;
79 }
80 return;
81}
82
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020083#define CMDLINE_SERIALNO "androidboot.serialno="
84#define CMDLINE_SERIALNO_LEN (strlen(CMDLINE_SERIALNO))
85#define CPUINFO_SERIALNO "Serial"
86#define CPUINFO_SERIALNO_LEN (strlen(CPUINFO_SERIALNO))
87#define CPUINFO_HARDWARE "Hardware"
88#define CPUINFO_HARDWARE_LEN (strlen(CPUINFO_HARDWARE))
Dees_Troyfdf5fcc2012-09-11 10:27:01 -040089
90void DataManager::get_device_id(void) {
91 FILE *fp;
Matt Mowere9260742015-02-22 20:20:18 -060092 size_t i;
Dees_Troyfdf5fcc2012-09-11 10:27:01 -040093 char line[2048];
Matt Mowere9260742015-02-22 20:20:18 -060094 char hardware_id[HWID_MAX] = { 0 };
95 char device_id[DEVID_MAX] = { 0 };
Dees_Troyfdf5fcc2012-09-11 10:27:01 -040096 char* token;
97
Anatoly Smaznov10c11f62013-02-12 13:33:40 +070098#ifdef TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID
Matt Mowere9260742015-02-22 20:20:18 -060099 // Use (product_model)_(hardware_id) as device id
Anatoly Smaznov10c11f62013-02-12 13:33:40 +0700100 char model_id[PROPERTY_VALUE_MAX];
101 property_get("ro.product.model", model_id, "error");
Matt Mowere9260742015-02-22 20:20:18 -0600102 if (strcmp(model_id, "error") != 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000103 LOGINFO("=> product model: '%s'\n", model_id);
Anatoly Smaznov10c11f62013-02-12 13:33:40 +0700104 // Replace spaces with underscores
Matt Mowere9260742015-02-22 20:20:18 -0600105 for (i = 0; i < strlen(model_id); i++) {
106 if (model_id[i] == ' ')
107 model_id[i] = '_';
Anatoly Smaznov10c11f62013-02-12 13:33:40 +0700108 }
Matt Mowere9260742015-02-22 20:20:18 -0600109 snprintf(device_id, DEVID_MAX, "%s", model_id);
110
111 if (strlen(device_id) < DEVID_MAX) {
112 fp = fopen("proc_cpuinfo.txt", "rt");
113 if (fp != NULL) {
114 while (fgets(line, sizeof(line), fp) != NULL) {
115 if (memcmp(line, CPUINFO_HARDWARE,
116 CPUINFO_HARDWARE_LEN) == 0) {
117 // skip past "Hardware", spaces, and colon
118 token = line + CPUINFO_HARDWARE_LEN;
119 while (*token && (!isgraph(*token) || *token == ':'))
120 token++;
121
122 if (*token && *token != '\n'
123 && strcmp("UNKNOWN\n", token)) {
124 snprintf(hardware_id, HWID_MAX, "%s", token);
125 if (hardware_id[strlen(hardware_id)-1] == '\n')
126 hardware_id[strlen(hardware_id)-1] = 0;
127 LOGINFO("=> hardware id from cpuinfo: '%s'\n",
128 hardware_id);
129 }
130 break;
131 }
132 }
133 fclose(fp);
134 }
Anatoly Smaznov10c11f62013-02-12 13:33:40 +0700135 }
Matt Mowere9260742015-02-22 20:20:18 -0600136
137 if (hardware_id[0] != 0)
138 snprintf(device_id, DEVID_MAX, "%s_%s", model_id, hardware_id);
139
140 sanitize_device_id(device_id);
Ethan Yonkerfe916112016-03-14 14:54:37 -0500141 mConst.SetValue("device_id", device_id);
Dees_Troy2673cec2013-04-02 20:22:16 +0000142 LOGINFO("=> using device id: '%s'\n", device_id);
Anatoly Smaznov10c11f62013-02-12 13:33:40 +0700143 return;
144 }
145#endif
146
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400147#ifndef TW_FORCE_CPUINFO_FOR_DEVICE_ID
Matt Mowere9260742015-02-22 20:20:18 -0600148 // Check the cmdline to see if the serial number was supplied
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400149 fp = fopen("/proc/cmdline", "rt");
Matt Mowere9260742015-02-22 20:20:18 -0600150 if (fp != NULL) {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200151 fgets(line, sizeof(line), fp);
Matt Mowere9260742015-02-22 20:20:18 -0600152 fclose(fp); // cmdline is only one line long
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400153
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200154 token = strtok(line, " ");
Matt Mowere9260742015-02-22 20:20:18 -0600155 while (token) {
156 if (memcmp(token, CMDLINE_SERIALNO, CMDLINE_SERIALNO_LEN) == 0) {
157 token += CMDLINE_SERIALNO_LEN;
158 snprintf(device_id, DEVID_MAX, "%s", token);
159 sanitize_device_id(device_id); // also removes newlines
Ethan Yonkerfe916112016-03-14 14:54:37 -0500160 mConst.SetValue("device_id", device_id);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200161 return;
162 }
163 token = strtok(NULL, " ");
164 }
165 }
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400166#endif
Matt Mowere9260742015-02-22 20:20:18 -0600167 // Check cpuinfo for serial number; if found, use as device_id
168 // If serial number is not found, fallback to hardware_id for the device_id
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400169 fp = fopen("/proc/cpuinfo", "rt");
Matt Mowere9260742015-02-22 20:20:18 -0600170 if (fp != NULL) {
171 while (fgets(line, sizeof(line), fp) != NULL) {
172 if (memcmp(line, CPUINFO_SERIALNO, CPUINFO_SERIALNO_LEN) == 0) {
173 // skip past "Serial", spaces, and colon
174 token = line + CPUINFO_SERIALNO_LEN;
175 while (*token && (!isgraph(*token) || *token == ':'))
176 token++;
177
178 if (*token && *token != '\n') {
179 snprintf(device_id, DEVID_MAX, "%s", token);
180 sanitize_device_id(device_id); // also removes newlines
Dees_Troy2673cec2013-04-02 20:22:16 +0000181 LOGINFO("=> serial from cpuinfo: '%s'\n", device_id);
Ethan Yonkerfe916112016-03-14 14:54:37 -0500182 mConst.SetValue("device_id", device_id);
Matt Mowere9260742015-02-22 20:20:18 -0600183 fclose(fp);
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400184 return;
185 }
Matt Mowere9260742015-02-22 20:20:18 -0600186 } else if (memcmp(line, CPUINFO_HARDWARE,
187 CPUINFO_HARDWARE_LEN) == 0) {
188 // skip past "Hardware", spaces, and colon
189 token = line + CPUINFO_HARDWARE_LEN;
190 while (*token && (!isgraph(*token) || *token == ':'))
191 token++;
192
193 if (*token && *token != '\n') {
194 snprintf(hardware_id, HWID_MAX, "%s", token);
195 if (hardware_id[strlen(hardware_id)-1] == '\n')
196 hardware_id[strlen(hardware_id)-1] = 0;
Dees_Troy2673cec2013-04-02 20:22:16 +0000197 LOGINFO("=> hardware id from cpuinfo: '%s'\n", hardware_id);
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400198 }
199 }
200 }
201 fclose(fp);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200202 }
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400203
204 if (hardware_id[0] != 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000205 LOGINFO("\nusing hardware id for device id: '%s'\n", hardware_id);
Matt Mowere9260742015-02-22 20:20:18 -0600206 snprintf(device_id, DEVID_MAX, "%s", hardware_id);
207 sanitize_device_id(device_id);
Ethan Yonkerfe916112016-03-14 14:54:37 -0500208 mConst.SetValue("device_id", device_id);
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400209 return;
210 }
211
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200212 strcpy(device_id, "serialno");
Ethan Yonker74db1572015-10-28 12:44:49 -0500213 LOGINFO("=> device id not found, using '%s'\n", device_id);
Ethan Yonkerfe916112016-03-14 14:54:37 -0500214 mConst.SetValue("device_id", device_id);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200215 return;
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400216}
217
Dees_Troy51a0e822012-09-05 15:24:24 -0400218int DataManager::ResetDefaults()
219{
Vojtech Bocekfda239b2015-01-07 22:55:13 +0100220 pthread_mutex_lock(&m_valuesLock);
Ethan Yonkerfe916112016-03-14 14:54:37 -0500221 mPersist.Clear();
222 mData.Clear();
223 mConst.Clear();
Vojtech Bocekfda239b2015-01-07 22:55:13 +0100224 pthread_mutex_unlock(&m_valuesLock);
225
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200226 SetDefaultValues();
227 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400228}
229
Ethan Yonkerfe916112016-03-14 14:54:37 -0500230int DataManager::LoadValues(const string& filename)
Dees_Troy51a0e822012-09-05 15:24:24 -0400231{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200232 string str, dev_id;
Dees_Troy51a0e822012-09-05 15:24:24 -0400233
234 if (!mInitialized)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200235 SetDefaultValues();
Dees_Troy51a0e822012-09-05 15:24:24 -0400236
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200237 GetValue("device_id", dev_id);
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400238 // Save off the backing file for set operations
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200239 mBackingFile = filename;
Ethan Yonkerfe916112016-03-14 14:54:37 -0500240 mPersist.SetFile(filename);
241 mPersist.SetFileVersion(FILE_VERSION);
Dees_Troy51a0e822012-09-05 15:24:24 -0400242
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200243 // Read in the file, if possible
Ethan Yonkerfe916112016-03-14 14:54:37 -0500244 pthread_mutex_lock(&m_valuesLock);
245 mPersist.LoadValues();
Vojtech Bocekfda239b2015-01-07 22:55:13 +0100246
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700247#ifndef TW_NO_SCREEN_TIMEOUT
Ethan Yonkerfe916112016-03-14 14:54:37 -0500248 blankTimer.setTime(mPersist.GetIntValue("tw_screen_timeout_secs"));
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700249#endif
Ethan Yonkerfe916112016-03-14 14:54:37 -0500250
251 pthread_mutex_unlock(&m_valuesLock);
Dees_Troya13d74f2013-03-24 08:54:55 -0500252 string current = GetCurrentStoragePath();
Ethan Yonkereeed3c52014-04-16 11:49:02 -0500253 TWPartition* Part = PartitionManager.Find_Partition_By_Path(current);
Vojtech Bocek93cb1ef2014-05-12 15:41:52 +0200254 if(!Part)
255 Part = PartitionManager.Get_Default_Storage_Partition();
256 if (Part && current != Part->Storage_Path && Part->Mount(false)) {
Ethan Yonkereeed3c52014-04-16 11:49:02 -0500257 LOGINFO("LoadValues setting storage path to '%s'\n", Part->Storage_Path.c_str());
258 SetValue("tw_storage_path", Part->Storage_Path);
Dees_Troya13d74f2013-03-24 08:54:55 -0500259 } else {
260 SetBackupFolder();
261 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200262 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400263}
264
265int DataManager::Flush()
266{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200267 return SaveValues();
Dees_Troy51a0e822012-09-05 15:24:24 -0400268}
269
270int DataManager::SaveValues()
271{
Ethan Yonker83e82572014-04-04 10:59:28 -0500272#ifndef TW_OEM_BUILD
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200273 if (mBackingFile.empty())
274 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400275
276 string mount_path = GetSettingsStoragePath();
Dees_Troy5bf43922012-09-07 16:07:55 -0400277 PartitionManager.Mount_By_Path(mount_path.c_str(), 1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400278
Ethan Yonkerfe916112016-03-14 14:54:37 -0500279 mPersist.SetFile(mBackingFile);
280 mPersist.SetFileVersion(FILE_VERSION);
Vojtech Bocekfda239b2015-01-07 22:55:13 +0100281 pthread_mutex_lock(&m_valuesLock);
Ethan Yonkerfe916112016-03-14 14:54:37 -0500282 mPersist.SaveValues();
Vojtech Bocekfda239b2015-01-07 22:55:13 +0100283 pthread_mutex_unlock(&m_valuesLock);
284
Ethan Yonker4b94cfd2014-12-11 10:00:45 -0600285 tw_set_default_metadata(mBackingFile.c_str());
Ethan Yonkerfe916112016-03-14 14:54:37 -0500286 LOGINFO("Saved settings file values\n");
Ethan Yonker83e82572014-04-04 10:59:28 -0500287#endif // ifdef TW_OEM_BUILD
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200288 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400289}
290
Ethan Yonkerfe916112016-03-14 14:54:37 -0500291int DataManager::GetValue(const string& varName, string& value)
Dees_Troy51a0e822012-09-05 15:24:24 -0400292{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200293 string localStr = varName;
Ethan Yonkerfe916112016-03-14 14:54:37 -0500294 int ret = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400295
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200296 if (!mInitialized)
297 SetDefaultValues();
Dees_Troy51a0e822012-09-05 15:24:24 -0400298
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200299 // Strip off leading and trailing '%' if provided
300 if (localStr.length() > 2 && localStr[0] == '%' && localStr[localStr.length()-1] == '%')
301 {
302 localStr.erase(0, 1);
303 localStr.erase(localStr.length() - 1, 1);
304 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400305
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200306 // Handle magic values
307 if (GetMagicValue(localStr, value) == 0)
308 return 0;
Xuefera163f152015-03-26 22:45:04 +0800309
310 // Handle property
311 if (localStr.length() > 9 && localStr.substr(0, 9) == "property.") {
312 char property_value[PROPERTY_VALUE_MAX];
313 property_get(localStr.substr(9).c_str(), property_value, "");
314 value = property_value;
315 return 0;
316 }
317
Vojtech Bocekfda239b2015-01-07 22:55:13 +0100318 pthread_mutex_lock(&m_valuesLock);
Ethan Yonkerfe916112016-03-14 14:54:37 -0500319 ret = mConst.GetValue(localStr, value);
320 if (ret == 0)
321 goto exit;
Dees_Troy51a0e822012-09-05 15:24:24 -0400322
Ethan Yonkerfe916112016-03-14 14:54:37 -0500323 ret = mPersist.GetValue(localStr, value);
324 if (ret == 0)
325 goto exit;
326
327 ret = mData.GetValue(localStr, value);
328exit:
Vojtech Bocekfda239b2015-01-07 22:55:13 +0100329 pthread_mutex_unlock(&m_valuesLock);
Ethan Yonkerfe916112016-03-14 14:54:37 -0500330 return ret;
Dees_Troy51a0e822012-09-05 15:24:24 -0400331}
332
Ethan Yonkerfe916112016-03-14 14:54:37 -0500333int DataManager::GetValue(const string& varName, int& value)
Dees_Troy51a0e822012-09-05 15:24:24 -0400334{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200335 string data;
Dees_Troy51a0e822012-09-05 15:24:24 -0400336
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200337 if (GetValue(varName,data) != 0)
338 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400339
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200340 value = atoi(data.c_str());
341 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400342}
343
Ethan Yonkerfe916112016-03-14 14:54:37 -0500344int DataManager::GetValue(const string& varName, float& value)
Dees_Troy2673cec2013-04-02 20:22:16 +0000345{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200346 string data;
Dees_Troy2673cec2013-04-02 20:22:16 +0000347
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200348 if (GetValue(varName,data) != 0)
349 return -1;
Dees_Troy2673cec2013-04-02 20:22:16 +0000350
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200351 value = atof(data.c_str());
352 return 0;
Dees_Troy2673cec2013-04-02 20:22:16 +0000353}
354
Ethan Yonkerfe916112016-03-14 14:54:37 -0500355unsigned long long DataManager::GetValue(const string& varName, unsigned long long& value)
bigbiff bigbiff2c57d782013-02-19 10:09:21 -0500356{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200357 string data;
bigbiff bigbiff2c57d782013-02-19 10:09:21 -0500358
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200359 if (GetValue(varName,data) != 0)
360 return -1;
bigbiff bigbiff2c57d782013-02-19 10:09:21 -0500361
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200362 value = strtoull(data.c_str(), NULL, 10);
363 return 0;
bigbiff bigbiff2c57d782013-02-19 10:09:21 -0500364}
365
Dees_Troy51a0e822012-09-05 15:24:24 -0400366// This function will return an empty string if the value doesn't exist
Ethan Yonkerfe916112016-03-14 14:54:37 -0500367string DataManager::GetStrValue(const string& varName)
Dees_Troy51a0e822012-09-05 15:24:24 -0400368{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200369 string retVal;
Dees_Troy51a0e822012-09-05 15:24:24 -0400370
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200371 GetValue(varName, retVal);
372 return retVal;
Dees_Troy51a0e822012-09-05 15:24:24 -0400373}
374
375// This function will return 0 if the value doesn't exist
Ethan Yonkerfe916112016-03-14 14:54:37 -0500376int DataManager::GetIntValue(const string& varName)
Dees_Troy51a0e822012-09-05 15:24:24 -0400377{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200378 string retVal;
Dees_Troy51a0e822012-09-05 15:24:24 -0400379
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200380 GetValue(varName, retVal);
381 return atoi(retVal.c_str());
Dees_Troy51a0e822012-09-05 15:24:24 -0400382}
383
Ethan Yonkerfe916112016-03-14 14:54:37 -0500384int DataManager::SetValue(const string& varName, const string& value, const int persist /* = 0 */)
Dees_Troy51a0e822012-09-05 15:24:24 -0400385{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200386 if (!mInitialized)
387 SetDefaultValues();
Dees_Troy51a0e822012-09-05 15:24:24 -0400388
Xuefera163f152015-03-26 22:45:04 +0800389 // Handle property
390 if (varName.length() > 9 && varName.substr(0, 9) == "property.") {
391 int ret = property_set(varName.substr(9).c_str(), value.c_str());
392 if (ret)
393 LOGERR("Error setting property '%s' to '%s'\n", varName.substr(9).c_str(), value.c_str());
394 return ret;
395 }
396
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200397 // Don't allow empty values or numerical starting values
398 if (varName.empty() || (varName[0] >= '0' && varName[0] <= '9'))
399 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400400
Ethan Yonkerfe916112016-03-14 14:54:37 -0500401 string test;
Vojtech Bocekfda239b2015-01-07 22:55:13 +0100402 pthread_mutex_lock(&m_valuesLock);
Ethan Yonkerfe916112016-03-14 14:54:37 -0500403 int constChk = mConst.GetValue(varName, test);
404 if (constChk == 0) {
405 pthread_mutex_unlock(&m_valuesLock);
406 return -1;
407 }
Vojtech Bocekfda239b2015-01-07 22:55:13 +0100408
Ethan Yonkerfe916112016-03-14 14:54:37 -0500409 if (persist) {
410 mPersist.SetValue(varName, value);
411 } else {
412 int persistChk = mPersist.GetValue(varName, test);
413 if (persistChk == 0) {
414 mPersist.SetValue(varName, value);
415 } else {
416 mData.SetValue(varName, value);
417 }
418 }
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700419
Vojtech Bocekfda239b2015-01-07 22:55:13 +0100420 pthread_mutex_unlock(&m_valuesLock);
421
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700422#ifndef TW_NO_SCREEN_TIMEOUT
bigbiff bigbifff8e2f372013-02-27 20:50:43 -0500423 if (varName == "tw_screen_timeout_secs") {
Dees_Troy2f9117a2013-02-17 19:52:09 -0600424 blankTimer.setTime(atoi(value.c_str()));
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700425 } else
426#endif
427 if (varName == "tw_storage_path") {
Dees_Troya13d74f2013-03-24 08:54:55 -0500428 SetBackupFolder();
bigbiff bigbifff8e2f372013-02-27 20:50:43 -0500429 }
Dees_Troya13d74f2013-03-24 08:54:55 -0500430 gui_notifyVarChange(varName.c_str(), value.c_str());
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200431 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400432}
433
Ethan Yonkerfe916112016-03-14 14:54:37 -0500434int DataManager::SetValue(const string& varName, const int value, const int persist /* = 0 */)
Dees_Troy51a0e822012-09-05 15:24:24 -0400435{
436 ostringstream valStr;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200437 valStr << value;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200438 return SetValue(varName, valStr.str(), persist);
Dees_Troy51a0e822012-09-05 15:24:24 -0400439}
440
Ethan Yonkerfe916112016-03-14 14:54:37 -0500441int DataManager::SetValue(const string& varName, const float value, const int persist /* = 0 */)
Dees_Troy51a0e822012-09-05 15:24:24 -0400442{
443 ostringstream valStr;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200444 valStr << value;
445 return SetValue(varName, valStr.str(), persist);;
Dees_Troy51a0e822012-09-05 15:24:24 -0400446}
447
Ethan Yonkerfe916112016-03-14 14:54:37 -0500448int DataManager::SetValue(const string& varName, const unsigned long long& value, const int persist /* = 0 */)
bigbiff bigbiff2c57d782013-02-19 10:09:21 -0500449{
450 ostringstream valStr;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200451 valStr << value;
452 return SetValue(varName, valStr.str(), persist);
bigbiff bigbiff2c57d782013-02-19 10:09:21 -0500453}
454
Ethan Yonkerfe916112016-03-14 14:54:37 -0500455int DataManager::SetProgress(const float Fraction) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000456 return SetValue("ui_progress", (float) (Fraction * 100.0));
457}
458
Ethan Yonkerfe916112016-03-14 14:54:37 -0500459int DataManager::ShowProgress(const float Portion, const float Seconds)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200460{
Dees_Troy2673cec2013-04-02 20:22:16 +0000461 float Starting_Portion;
462 GetValue("ui_progress_portion", Starting_Portion);
463 if (SetValue("ui_progress_portion", (float)(Portion * 100.0) + Starting_Portion) != 0)
464 return -1;
465 if (SetValue("ui_progress_frames", Seconds * 30) != 0)
466 return -1;
467 return 0;
468}
469
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200470void DataManager::update_tz_environment_variables(void)
471{
Vojtech Bocekfda239b2015-01-07 22:55:13 +0100472 setenv("TZ", GetStrValue(TW_TIME_ZONE_VAR).c_str(), 1);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200473 tzset();
Dees_Troy8170a922012-09-18 15:40:25 -0400474}
475
Dees_Troy16b74352012-11-14 22:27:31 +0000476void DataManager::SetBackupFolder()
477{
478 string str = GetCurrentStoragePath();
Dees_Troya13d74f2013-03-24 08:54:55 -0500479 TWPartition* partition = PartitionManager.Find_Partition_By_Path(str);
Dees_Troy16b74352012-11-14 22:27:31 +0000480 str += "/TWRP/BACKUPS/";
481
482 string dev_id;
483 GetValue("device_id", dev_id);
484
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200485 str += dev_id;
Dees_Troy2673cec2013-04-02 20:22:16 +0000486 LOGINFO("Backup folder set to '%s'\n", str.c_str());
Dees_Troy16b74352012-11-14 22:27:31 +0000487 SetValue(TW_BACKUPS_FOLDER_VAR, str, 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500488 if (partition != NULL) {
489 SetValue("tw_storage_display_name", partition->Storage_Name);
490 char free_space[255];
491 sprintf(free_space, "%llu", partition->Free / 1024 / 1024);
492 SetValue("tw_storage_free_size", free_space);
493 string zip_path, zip_root, storage_path;
494 GetValue(TW_ZIP_LOCATION_VAR, zip_path);
Ethan Yonkereadfd2e2016-02-18 22:04:18 -0600495 if (partition->Has_Data_Media && !partition->Symlink_Mount_Point.empty())
Dees_Troya13d74f2013-03-24 08:54:55 -0500496 storage_path = partition->Symlink_Mount_Point;
497 else
498 storage_path = partition->Storage_Path;
499 if (zip_path.size() < storage_path.size()) {
500 SetValue(TW_ZIP_LOCATION_VAR, storage_path);
501 } else {
Dees Troyc2e9bc72013-09-10 00:16:24 +0000502 zip_root = TWFunc::Get_Root_Path(zip_path);
Dees_Troy18727952013-06-20 15:24:48 -0500503 if (zip_root != storage_path) {
504 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 -0500505 SetValue(TW_ZIP_LOCATION_VAR, storage_path);
Dees_Troy18727952013-06-20 15:24:48 -0500506 }
Dees_Troya13d74f2013-03-24 08:54:55 -0500507 }
508 } else {
Ethan Yonker74db1572015-10-28 12:44:49 -0500509 if (PartitionManager.Fstab_Processed() != 0) {
510 LOGINFO("Storage partition '%s' not found\n", str.c_str());
511 gui_err("unable_locate_storage=Unable to locate storage device.");
512 }
Dees_Troya13d74f2013-03-24 08:54:55 -0500513 }
Dees_Troy16b74352012-11-14 22:27:31 +0000514}
515
Dees_Troy51a0e822012-09-05 15:24:24 -0400516void DataManager::SetDefaultValues()
517{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200518 string str, path;
Dees_Troy51a0e822012-09-05 15:24:24 -0400519
Ethan Yonkerfe916112016-03-14 14:54:37 -0500520 mConst.SetConst();
521
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200522 get_device_id();
Dees_Troy51a0e822012-09-05 15:24:24 -0400523
Vojtech Bocekfda239b2015-01-07 22:55:13 +0100524 pthread_mutex_lock(&m_valuesLock);
525
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200526 mInitialized = 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400527
Ethan Yonkerfe916112016-03-14 14:54:37 -0500528 mConst.SetValue("true", "1");
529 mConst.SetValue("false", "0");
Dees_Troy51a0e822012-09-05 15:24:24 -0400530
Ethan Yonkerfe916112016-03-14 14:54:37 -0500531 mConst.SetValue(TW_VERSION_VAR, TW_VERSION_STR);
532 mPersist.SetValue("tw_button_vibrate", "80");
533 mPersist.SetValue("tw_keyboard_vibrate", "40");
534 mPersist.SetValue("tw_action_vibrate", "160");
Dees_Troy51a0e822012-09-05 15:24:24 -0400535
Vojtech Bocek93cb1ef2014-05-12 15:41:52 +0200536 TWPartition *store = PartitionManager.Get_Default_Storage_Partition();
537 if(store)
Ethan Yonkerfe916112016-03-14 14:54:37 -0500538 mPersist.SetValue("tw_storage_path", store->Storage_Path);
Vojtech Bocek93cb1ef2014-05-12 15:41:52 +0200539 else
Ethan Yonkerfe916112016-03-14 14:54:37 -0500540 mPersist.SetValue("tw_storage_path", "/");
Vojtech Bocek93cb1ef2014-05-12 15:41:52 +0200541
Dees_Troyf4499812013-01-23 19:07:38 +0000542#ifdef TW_FORCE_CPUINFO_FOR_DEVICE_ID
543 printf("TW_FORCE_CPUINFO_FOR_DEVICE_ID := true\n");
544#endif
545
Dees_Troy51a0e822012-09-05 15:24:24 -0400546#ifdef BOARD_HAS_NO_REAL_SDCARD
Dees_Troyf4499812013-01-23 19:07:38 +0000547 printf("BOARD_HAS_NO_REAL_SDCARD := true\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500548 mConst.SetValue(TW_ALLOW_PARTITION_SDCARD, "0");
Dees_Troy51a0e822012-09-05 15:24:24 -0400549#else
Ethan Yonkerfe916112016-03-14 14:54:37 -0500550 mConst.SetValue(TW_ALLOW_PARTITION_SDCARD, "1");
Dees_Troy51a0e822012-09-05 15:24:24 -0400551#endif
552
553#ifdef TW_INCLUDE_DUMLOCK
Dees_Troyf4499812013-01-23 19:07:38 +0000554 printf("TW_INCLUDE_DUMLOCK := true\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500555 mConst.SetValue(TW_SHOW_DUMLOCK, "1");
Dees_Troy51a0e822012-09-05 15:24:24 -0400556#else
Ethan Yonkerfe916112016-03-14 14:54:37 -0500557 mConst.SetValue(TW_SHOW_DUMLOCK, "0");
Dees_Troy51a0e822012-09-05 15:24:24 -0400558#endif
559
Dees_Troy51a0e822012-09-05 15:24:24 -0400560 str = GetCurrentStoragePath();
Ethan Yonkerfe916112016-03-14 14:54:37 -0500561 mPersist.SetValue(TW_ZIP_LOCATION_VAR, str);
Dees_Troy51a0e822012-09-05 15:24:24 -0400562 str += "/TWRP/BACKUPS/";
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400563
564 string dev_id;
Ethan Yonkerfe916112016-03-14 14:54:37 -0500565 mConst.GetValue("device_id", dev_id);
Dees_Troyfdf5fcc2012-09-11 10:27:01 -0400566
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200567 str += dev_id;
Ethan Yonkerfe916112016-03-14 14:54:37 -0500568 mData.SetValue(TW_BACKUPS_FOLDER_VAR, str);
Dees_Troy51a0e822012-09-05 15:24:24 -0400569
Ethan Yonkerfe916112016-03-14 14:54:37 -0500570 mConst.SetValue(TW_REBOOT_SYSTEM, "1");
Dees_Troy51a0e822012-09-05 15:24:24 -0400571#ifdef TW_NO_REBOOT_RECOVERY
Talustus33ebf932013-02-02 14:11:14 +0100572 printf("TW_NO_REBOOT_RECOVERY := true\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500573 mConst.SetValue(TW_REBOOT_RECOVERY, "0");
Dees_Troy51a0e822012-09-05 15:24:24 -0400574#else
Ethan Yonkerfe916112016-03-14 14:54:37 -0500575 mConst.SetValue(TW_REBOOT_RECOVERY, "1");
Dees_Troy51a0e822012-09-05 15:24:24 -0400576#endif
Ethan Yonkerfe916112016-03-14 14:54:37 -0500577 mConst.SetValue(TW_REBOOT_POWEROFF, "1");
Dees_Troy51a0e822012-09-05 15:24:24 -0400578#ifdef TW_NO_REBOOT_BOOTLOADER
Talustus33ebf932013-02-02 14:11:14 +0100579 printf("TW_NO_REBOOT_BOOTLOADER := true\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500580 mConst.SetValue(TW_REBOOT_BOOTLOADER, "0");
Dees_Troy51a0e822012-09-05 15:24:24 -0400581#else
Ethan Yonkerfe916112016-03-14 14:54:37 -0500582 mConst.SetValue(TW_REBOOT_BOOTLOADER, "1");
Dees_Troy51a0e822012-09-05 15:24:24 -0400583#endif
584#ifdef RECOVERY_SDCARD_ON_DATA
Dees_Troyf4499812013-01-23 19:07:38 +0000585 printf("RECOVERY_SDCARD_ON_DATA := true\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500586 mConst.SetValue(TW_HAS_DATA_MEDIA, "1");
Ethan Yonker6277c792014-09-15 14:54:30 -0500587 datamedia = true;
Dees_Troy51a0e822012-09-05 15:24:24 -0400588#else
Ethan Yonkerfe916112016-03-14 14:54:37 -0500589 mData.SetValue(TW_HAS_DATA_MEDIA, "0");
Dees_Troy51a0e822012-09-05 15:24:24 -0400590#endif
591#ifdef TW_NO_BATT_PERCENT
Dees_Troyf4499812013-01-23 19:07:38 +0000592 printf("TW_NO_BATT_PERCENT := true\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500593 mConst.SetValue(TW_NO_BATTERY_PERCENT, "1");
Dees_Troy51a0e822012-09-05 15:24:24 -0400594#else
Ethan Yonkerfe916112016-03-14 14:54:37 -0500595 mConst.SetValue(TW_NO_BATTERY_PERCENT, "0");
Dees_Troy51a0e822012-09-05 15:24:24 -0400596#endif
Jenkins1710bf22014-10-02 20:22:21 -0400597#ifdef TW_NO_CPU_TEMP
598 printf("TW_NO_CPU_TEMP := true\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500599 mConst.SetValue("tw_no_cpu_temp", "1");
Jenkins1710bf22014-10-02 20:22:21 -0400600#else
601 string cpu_temp_file;
602#ifdef TW_CUSTOM_CPU_TEMP_PATH
603 cpu_temp_file = EXPAND(TW_CUSTOM_CPU_TEMP_PATH);
604#else
605 cpu_temp_file = "/sys/class/thermal/thermal_zone0/temp";
606#endif
607 if (TWFunc::Path_Exists(cpu_temp_file)) {
Ethan Yonkerfe916112016-03-14 14:54:37 -0500608 mConst.SetValue("tw_no_cpu_temp", "0");
Jenkins1710bf22014-10-02 20:22:21 -0400609 } else {
610 LOGINFO("CPU temperature file '%s' not found, disabling CPU temp.\n", cpu_temp_file.c_str());
Ethan Yonkerfe916112016-03-14 14:54:37 -0500611 mConst.SetValue("tw_no_cpu_temp", "1");
Jenkins1710bf22014-10-02 20:22:21 -0400612 }
613#endif
Dees_Troy51a0e822012-09-05 15:24:24 -0400614#ifdef TW_CUSTOM_POWER_BUTTON
Dees_Troyf4499812013-01-23 19:07:38 +0000615 printf("TW_POWER_BUTTON := %s\n", EXPAND(TW_CUSTOM_POWER_BUTTON));
Ethan Yonkerfe916112016-03-14 14:54:37 -0500616 mConst.SetValue(TW_POWER_BUTTON, EXPAND(TW_CUSTOM_POWER_BUTTON));
Dees_Troy51a0e822012-09-05 15:24:24 -0400617#else
Ethan Yonkerfe916112016-03-14 14:54:37 -0500618 mConst.SetValue(TW_POWER_BUTTON, "0");
Dees_Troy51a0e822012-09-05 15:24:24 -0400619#endif
620#ifdef TW_ALWAYS_RMRF
Dees_Troyf4499812013-01-23 19:07:38 +0000621 printf("TW_ALWAYS_RMRF := true\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500622 mConst.SetValue(TW_RM_RF_VAR, "1");
Dees_Troy51a0e822012-09-05 15:24:24 -0400623#endif
624#ifdef TW_NEVER_UNMOUNT_SYSTEM
Dees_Troyf4499812013-01-23 19:07:38 +0000625 printf("TW_NEVER_UNMOUNT_SYSTEM := true\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500626 mConst.SetValue(TW_DONT_UNMOUNT_SYSTEM, "1");
Dees_Troy51a0e822012-09-05 15:24:24 -0400627#else
Ethan Yonkerfe916112016-03-14 14:54:37 -0500628 mConst.SetValue(TW_DONT_UNMOUNT_SYSTEM, "0");
Dees_Troy51a0e822012-09-05 15:24:24 -0400629#endif
630#ifdef TW_NO_USB_STORAGE
Dees_Troy6a042c82013-01-23 18:50:52 +0000631 printf("TW_NO_USB_STORAGE := true\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500632 mConst.SetValue(TW_HAS_USB_STORAGE, "0");
Dees_Troy51a0e822012-09-05 15:24:24 -0400633#else
Dees_Troy6a042c82013-01-23 18:50:52 +0000634 char lun_file[255];
635 string Lun_File_str = CUSTOM_LUN_FILE;
636 size_t found = Lun_File_str.find("%");
637 if (found != string::npos) {
638 sprintf(lun_file, CUSTOM_LUN_FILE, 0);
639 Lun_File_str = lun_file;
640 }
641 if (!TWFunc::Path_Exists(Lun_File_str)) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000642 LOGINFO("Lun file '%s' does not exist, USB storage mode disabled\n", Lun_File_str.c_str());
Ethan Yonkerfe916112016-03-14 14:54:37 -0500643 mConst.SetValue(TW_HAS_USB_STORAGE, "0");
Dees_Troy6a042c82013-01-23 18:50:52 +0000644 } else {
Dees_Troy2673cec2013-04-02 20:22:16 +0000645 LOGINFO("Lun file '%s'\n", Lun_File_str.c_str());
Ethan Yonkerfe916112016-03-14 14:54:37 -0500646 mData.SetValue(TW_HAS_USB_STORAGE, "1");
Dees_Troy6a042c82013-01-23 18:50:52 +0000647 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400648#endif
649#ifdef TW_INCLUDE_INJECTTWRP
Dees_Troyf4499812013-01-23 19:07:38 +0000650 printf("TW_INCLUDE_INJECTTWRP := true\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500651 mConst.SetValue(TW_HAS_INJECTTWRP, "1");
652 mPersist(TW_INJECT_AFTER_ZIP, "1");
Dees_Troy51a0e822012-09-05 15:24:24 -0400653#else
Ethan Yonkerfe916112016-03-14 14:54:37 -0500654 mConst.SetValue(TW_HAS_INJECTTWRP, "0");
Dees_Troy51a0e822012-09-05 15:24:24 -0400655#endif
Dees_Troy51a0e822012-09-05 15:24:24 -0400656#ifdef TW_HAS_DOWNLOAD_MODE
Dees_Troyf4499812013-01-23 19:07:38 +0000657 printf("TW_HAS_DOWNLOAD_MODE := true\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500658 mConst.SetValue(TW_DOWNLOAD_MODE, "1");
Dees_Troy51a0e822012-09-05 15:24:24 -0400659#endif
660#ifdef TW_INCLUDE_CRYPTO
Ethan Yonkerfe916112016-03-14 14:54:37 -0500661 mConst.SetValue(TW_HAS_CRYPTO, "1");
Dees_Troyf4499812013-01-23 19:07:38 +0000662 printf("TW_INCLUDE_CRYPTO := true\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400663#endif
664#ifdef TW_SDEXT_NO_EXT4
Dees_Troyf4499812013-01-23 19:07:38 +0000665 printf("TW_SDEXT_NO_EXT4 := true\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500666 mConst.SetValue(TW_SDEXT_DISABLE_EXT4, "1");
Dees_Troy51a0e822012-09-05 15:24:24 -0400667#else
Ethan Yonkerfe916112016-03-14 14:54:37 -0500668 mConst.SetValue(TW_SDEXT_DISABLE_EXT4, "0");
Dees_Troy51a0e822012-09-05 15:24:24 -0400669#endif
670
Dees_Troya13d74f2013-03-24 08:54:55 -0500671#ifdef TW_HAS_NO_BOOT_PARTITION
Ethan Yonkerfe916112016-03-14 14:54:37 -0500672 mPersist.SetValue("tw_backup_list", "/system;/data;");
Dees_Troya13d74f2013-03-24 08:54:55 -0500673#else
Ethan Yonkerfe916112016-03-14 14:54:37 -0500674 mPersist.SetValue("tw_backup_list", "/system;/data;/boot;");
Dees_Troya13d74f2013-03-24 08:54:55 -0500675#endif
Ethan Yonkerfe916112016-03-14 14:54:37 -0500676 mConst.SetValue(TW_MIN_SYSTEM_VAR, TW_MIN_SYSTEM_SIZE);
677 mData.SetValue(TW_BACKUP_NAME, "(Auto Generate)");
bigbiff bigbiff7ce7f0c2013-01-25 09:54:04 -0500678
Ethan Yonkerfe916112016-03-14 14:54:37 -0500679 mPersist.SetValue(TW_REBOOT_AFTER_FLASH_VAR, "0");
680 mPersist.SetValue(TW_SIGNED_ZIP_VERIFY_VAR, "0");
681 mPersist.SetValue(TW_FORCE_MD5_CHECK_VAR, "0");
682 mPersist.SetValue(TW_USE_COMPRESSION_VAR, "0");
683 mPersist.SetValue(TW_TIME_ZONE_VAR, "CST6CDT,M3.2.0,M11.1.0");
684 mPersist.SetValue(TW_GUI_SORT_ORDER, "1");
685 mPersist.SetValue(TW_RM_RF_VAR, "0");
686 mPersist.SetValue(TW_SKIP_MD5_CHECK_VAR, "0");
687 mPersist.SetValue(TW_SKIP_MD5_GENERATE_VAR, "0");
688 mPersist.SetValue(TW_SDEXT_SIZE, "0");
689 mPersist.SetValue(TW_SWAP_SIZE, "0");
690 mPersist.SetValue(TW_SDPART_FILE_SYSTEM, "ext3");
691 mPersist.SetValue(TW_TIME_ZONE_GUISEL, "CST6;CDT,M3.2.0,M11.1.0");
692 mPersist.SetValue(TW_TIME_ZONE_GUIOFFSET, "0");
693 mPersist.SetValue(TW_TIME_ZONE_GUIDST, "1");
694 mData.SetValue(TW_ACTION_BUSY, "0");
695 mData.SetValue("tw_wipe_cache", "0");
696 mData.SetValue("tw_wipe_dalvik", "0");
697 mData.SetValue(TW_ZIP_INDEX, "0");
698 mData.SetValue(TW_ZIP_QUEUE_COUNT, "0");
699 mData.SetValue(TW_FILENAME, "/sdcard");
700 mData.SetValue(TW_SIMULATE_ACTIONS, "0");
701 mData.SetValue(TW_SIMULATE_FAIL, "0");
702 mData.SetValue(TW_IS_ENCRYPTED, "0");
703 mData.SetValue(TW_IS_DECRYPTED, "0");
704 mData.SetValue(TW_CRYPTO_PASSWORD, "0");
705 mData.SetValue("tw_terminal_state", "0");
706 mData.SetValue("tw_background_thread_running", "0");
707 mData.SetValue(TW_RESTORE_FILE_DATE, "0");
708 mPersist.SetValue("tw_military_time", "0");
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700709#ifdef TW_NO_SCREEN_TIMEOUT
Ethan Yonkerfe916112016-03-14 14:54:37 -0500710 mConst.SetValue("tw_screen_timeout_secs", "0");
711 mConst.SetValue("tw_no_screen_timeout", "1");
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700712#else
Ethan Yonkerfe916112016-03-14 14:54:37 -0500713 mPersist.SetValue("tw_screen_timeout_secs", "60");
714 mPersist.SetValue("tw_no_screen_timeout", "0");
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700715#endif
Ethan Yonkerfe916112016-03-14 14:54:37 -0500716 mData.SetValue("tw_gui_done", "0");
717 mData.SetValue("tw_encrypt_backup", "0");
718
719 // Brightness handling
Ethan Yonker00028b42014-04-09 14:29:02 -0500720 string findbright;
Tatsuyuki Ishi548a1752015-12-28 10:08:58 +0900721#ifdef TW_BRIGHTNESS_PATH
722 findbright = EXPAND(TW_BRIGHTNESS_PATH);
723 LOGINFO("TW_BRIGHTNESS_PATH := %s\n", findbright.c_str());
724 if (!TWFunc::Path_Exists(findbright)) {
725 LOGINFO("Specified brightness file '%s' not found.\n", findbright.c_str());
726 findbright = "";
Ethan Yonker00028b42014-04-09 14:29:02 -0500727 }
Tatsuyuki Ishi548a1752015-12-28 10:08:58 +0900728#endif
Ethan Yonker00028b42014-04-09 14:29:02 -0500729 if (findbright.empty()) {
730 // Attempt to locate the brightness file
731 findbright = Find_File::Find("brightness", "/sys/class/backlight");
Ethan Yonker9c102b52014-04-15 11:06:18 -0500732 if (findbright.empty()) findbright = Find_File::Find("brightness", "/sys/class/leds/lcd-backlight");
Ethan Yonker00028b42014-04-09 14:29:02 -0500733 }
734 if (findbright.empty()) {
735 LOGINFO("Unable to locate brightness file\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500736 mConst.SetValue("tw_has_brightnesss_file", "0");
Ethan Yonker00028b42014-04-09 14:29:02 -0500737 } else {
738 LOGINFO("Found brightness file at '%s'\n", findbright.c_str());
Ethan Yonkerfe916112016-03-14 14:54:37 -0500739 mConst.SetValue("tw_has_brightnesss_file", "1");
740 mConst.SetValue("tw_brightness_file", findbright);
Tatsuyuki Ishi548a1752015-12-28 10:08:58 +0900741 string maxBrightness;
742#ifdef TW_MAX_BRIGHTNESS
Vojtech Bocek85932342013-04-01 22:11:33 +0200743 ostringstream maxVal;
744 maxVal << TW_MAX_BRIGHTNESS;
Tatsuyuki Ishi548a1752015-12-28 10:08:58 +0900745 maxBrightness = maxVal.str();
746#else
747 // Attempt to locate the max_brightness file
748 string maxbrightpath = findbright.insert(findbright.rfind('/') + 1, "max_");
749 if (TWFunc::Path_Exists(maxbrightpath)) {
Ethan Yonker72a85202016-01-22 11:45:06 -0600750 ifstream maxVal(maxbrightpath.c_str());
Tatsuyuki Ishi548a1752015-12-28 10:08:58 +0900751 if(maxVal >> maxBrightness) {
752 LOGINFO("Got max brightness %s from '%s'\n", maxBrightness.c_str(), maxbrightpath.c_str());
753 } else {
754 // Something went wrong, set that to indicate error
755 maxBrightness = "-1";
756 }
757 }
Ethan Yonker72a85202016-01-22 11:45:06 -0600758 if (atoi(maxBrightness.c_str()) <= 0)
Tatsuyuki Ishi548a1752015-12-28 10:08:58 +0900759 {
760 // Fallback into default
761 ostringstream maxVal;
762 maxVal << 255;
763 maxBrightness = maxVal.str();
764 }
765#endif
Ethan Yonkerfe916112016-03-14 14:54:37 -0500766 mConst.SetValue("tw_brightness_max", maxBrightness);
767 mPersist.SetValue("tw_brightness", maxBrightness);
768 mPersist.SetValue("tw_brightness_pct", "100");
xNUTxe85f02d2014-07-18 01:30:58 +0200769#ifdef TW_SECONDARY_BRIGHTNESS_PATH
770 string secondfindbright = EXPAND(TW_SECONDARY_BRIGHTNESS_PATH);
771 if (secondfindbright != "" && TWFunc::Path_Exists(secondfindbright)) {
772 LOGINFO("Will use a second brightness file at '%s'\n", secondfindbright.c_str());
Ethan Yonkerfe916112016-03-14 14:54:37 -0500773 mConst.SetValue("tw_secondary_brightness_file", secondfindbright);
xNUTxe85f02d2014-07-18 01:30:58 +0200774 } else {
775 LOGINFO("Specified secondary brightness file '%s' not found.\n", secondfindbright.c_str());
776 }
777#endif
Greg Wallace36ade452015-11-08 13:54:25 -0500778#ifdef TW_DEFAULT_BRIGHTNESS
779 int defValInt = TW_DEFAULT_BRIGHTNESS;
Ethan Yonker72a85202016-01-22 11:45:06 -0600780 int maxValInt = atoi(maxBrightness.c_str());
Greg Wallace36ade452015-11-08 13:54:25 -0500781 // Deliberately int so the % is always a whole number
782 int defPctInt = ( ( (double)defValInt / maxValInt ) * 100 );
783 ostringstream defPct;
784 defPct << defPctInt;
Ethan Yonkerfe916112016-03-14 14:54:37 -0500785 mPersist.SetValue("tw_brightness_pct", defPct.str());
Greg Wallace36ade452015-11-08 13:54:25 -0500786
787 ostringstream defVal;
788 defVal << TW_DEFAULT_BRIGHTNESS;
Ethan Yonkerfe916112016-03-14 14:54:37 -0500789 mPersist.SetValue("tw_brightness", defVal.str());
Tatsuyuki Ishi548a1752015-12-28 10:08:58 +0900790 TWFunc::Set_Brightness(defVal.str());
Greg Wallace36ade452015-11-08 13:54:25 -0500791#else
Tatsuyuki Ishi548a1752015-12-28 10:08:58 +0900792 TWFunc::Set_Brightness(maxBrightness);
Greg Wallace36ade452015-11-08 13:54:25 -0500793#endif
Dees_Troy2f9117a2013-02-17 19:52:09 -0600794 }
Ethan Yonkerfe916112016-03-14 14:54:37 -0500795
Dees_Troy83bd4832013-05-04 12:39:56 +0000796#ifndef TW_EXCLUDE_ENCRYPTED_BACKUPS
Ethan Yonkerfe916112016-03-14 14:54:37 -0500797 mConst.SetValue("tw_include_encrypted_backup", "1");
Dees_Troy83bd4832013-05-04 12:39:56 +0000798#else
799 LOGINFO("TW_EXCLUDE_ENCRYPTED_BACKUPS := true\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500800 mConst.SetValue("tw_include_encrypted_backup", "0");
Dees_Troy83bd4832013-05-04 12:39:56 +0000801#endif
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400802#ifdef TW_HAS_MTP
Ethan Yonkerfe916112016-03-14 14:54:37 -0500803 mConst.SetValue("tw_has_mtp", "1");
804 mPersist.SetValue("tw_mtp_enabled", "1");
805 mPersist.SetValue("tw_mtp_debug", "0");
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400806#else
807 LOGINFO("TW_EXCLUDE_MTP := true\n");
Ethan Yonkerfe916112016-03-14 14:54:37 -0500808 mConst.SetValue("tw_has_mtp", "0");
809 mConst.SetValue("tw_mtp_enabled", "0");
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -0400810#endif
Ethan Yonkerfe916112016-03-14 14:54:37 -0500811 mPersist.SetValue("tw_mount_system_ro", "2");
812 mPersist.SetValue("tw_never_show_system_ro_page", "0");
813 mPersist.SetValue("tw_language", EXPAND(TW_DEFAULT_LANGUAGE));
Ethan Yonker74db1572015-10-28 12:44:49 -0500814 LOGINFO("LANG: %s\n", EXPAND(TW_DEFAULT_LANGUAGE));
Vojtech Bocekfda239b2015-01-07 22:55:13 +0100815
Ethan Yonkerfe916112016-03-14 14:54:37 -0500816 mData.SetValue("tw_has_adopted_storage", "0");
Ethan Yonker66a19492015-12-10 10:19:45 -0600817
Vojtech Bocekfda239b2015-01-07 22:55:13 +0100818 pthread_mutex_unlock(&m_valuesLock);
Dees_Troy51a0e822012-09-05 15:24:24 -0400819}
820
821// Magic Values
Ethan Yonkerfe916112016-03-14 14:54:37 -0500822int DataManager::GetMagicValue(const string& varName, string& value)
Dees_Troy51a0e822012-09-05 15:24:24 -0400823{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200824 // Handle special dynamic cases
825 if (varName == "tw_time")
826 {
827 char tmp[32];
Dees_Troy51a0e822012-09-05 15:24:24 -0400828
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200829 struct tm *current;
830 time_t now;
831 int tw_military_time;
832 now = time(0);
833 current = localtime(&now);
Matt Mowerfb1c4ff2014-04-16 13:43:36 -0500834 GetValue(TW_MILITARY_TIME, tw_military_time);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200835 if (current->tm_hour >= 12)
836 {
837 if (tw_military_time == 1)
838 sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min);
839 else
840 sprintf(tmp, "%d:%02d PM", current->tm_hour == 12 ? 12 : current->tm_hour - 12, current->tm_min);
bigbiff bigbiff4efe9c32013-02-20 18:58:11 -0500841 }
bigbiff bigbiff4efe9c32013-02-20 18:58:11 -0500842 else
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200843 {
Matt Mowerfb1c4ff2014-04-16 13:43:36 -0500844 if (tw_military_time == 1)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200845 sprintf(tmp, "%d:%02d", current->tm_hour, current->tm_min);
846 else
847 sprintf(tmp, "%d:%02d AM", current->tm_hour == 0 ? 12 : current->tm_hour, current->tm_min);
848 }
849 value = tmp;
850 return 0;
bigbiff bigbiff4efe9c32013-02-20 18:58:11 -0500851 }
Jenkins1710bf22014-10-02 20:22:21 -0400852 else if (varName == "tw_cpu_temp")
853 {
Agontuka29361a2015-04-22 14:42:59 +0600854 int tw_no_cpu_temp;
855 GetValue("tw_no_cpu_temp", tw_no_cpu_temp);
856 if (tw_no_cpu_temp == 1) return -1;
857
Jenkins1710bf22014-10-02 20:22:21 -0400858 string cpu_temp_file;
859 static unsigned long convert_temp = 0;
860 static time_t cpuSecCheck = 0;
861 int divisor = 0;
862 struct timeval curTime;
863 string results;
864
865 gettimeofday(&curTime, NULL);
866 if (curTime.tv_sec > cpuSecCheck)
867 {
868#ifdef TW_CUSTOM_CPU_TEMP_PATH
869 cpu_temp_file = EXPAND(TW_CUSTOM_CPU_TEMP_PATH);
870 if (TWFunc::read_file(cpu_temp_file, results) != 0)
871 return -1;
872#else
873 cpu_temp_file = "/sys/class/thermal/thermal_zone0/temp";
874 if (TWFunc::read_file(cpu_temp_file, results) != 0)
875 return -1;
876#endif
877 convert_temp = strtoul(results.c_str(), NULL, 0) / 1000;
878 if (convert_temp <= 0)
879 convert_temp = strtoul(results.c_str(), NULL, 0);
HandyMennyb6033452014-10-15 21:39:12 +0200880 if (convert_temp >= 150)
881 convert_temp = strtoul(results.c_str(), NULL, 0) / 10;
882 cpuSecCheck = curTime.tv_sec + 5;
Jenkins1710bf22014-10-02 20:22:21 -0400883 }
884 value = TWFunc::to_string(convert_temp);
885 return 0;
886 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200887 else if (varName == "tw_battery")
888 {
889 char tmp[16];
Dees_Troy38bd7602012-09-14 13:33:53 -0400890 static char charging = ' ';
891 static int lastVal = -1;
892 static time_t nextSecCheck = 0;
Dees_Troy38bd7602012-09-14 13:33:53 -0400893 struct timeval curTime;
894 gettimeofday(&curTime, NULL);
895 if (curTime.tv_sec > nextSecCheck)
896 {
897 char cap_s[4];
Dees_Troyf33b4902013-03-01 00:51:39 +0000898#ifdef TW_CUSTOM_BATTERY_PATH
899 string capacity_file = EXPAND(TW_CUSTOM_BATTERY_PATH);
900 capacity_file += "/capacity";
901 FILE * cap = fopen(capacity_file.c_str(),"rt");
902#else
Dees_Troy38bd7602012-09-14 13:33:53 -0400903 FILE * cap = fopen("/sys/class/power_supply/battery/capacity","rt");
Dees_Troyf33b4902013-03-01 00:51:39 +0000904#endif
Dees_Troy38bd7602012-09-14 13:33:53 -0400905 if (cap){
906 fgets(cap_s, 4, cap);
907 fclose(cap);
908 lastVal = atoi(cap_s);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200909 if (lastVal > 100) lastVal = 101;
910 if (lastVal < 0) lastVal = 0;
Dees_Troy38bd7602012-09-14 13:33:53 -0400911 }
Dees_Troyf33b4902013-03-01 00:51:39 +0000912#ifdef TW_CUSTOM_BATTERY_PATH
913 string status_file = EXPAND(TW_CUSTOM_BATTERY_PATH);
914 status_file += "/status";
915 cap = fopen(status_file.c_str(),"rt");
916#else
Dees_Troy38bd7602012-09-14 13:33:53 -0400917 cap = fopen("/sys/class/power_supply/battery/status","rt");
Dees_Troyf33b4902013-03-01 00:51:39 +0000918#endif
Dees_Troy38bd7602012-09-14 13:33:53 -0400919 if (cap) {
920 fgets(cap_s, 2, cap);
921 fclose(cap);
922 if (cap_s[0] == 'C')
923 charging = '+';
924 else
925 charging = ' ';
926 }
927 nextSecCheck = curTime.tv_sec + 60;
928 }
929
930 sprintf(tmp, "%i%%%c", lastVal, charging);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200931 value = tmp;
932 return 0;
933 }
934 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400935}
936
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200937void DataManager::Output_Version(void)
938{
Ethan Yonker89583ef2015-08-26 09:01:59 -0500939#ifndef TW_OEM_BUILD
Dees_Troy1c1ac442013-01-17 21:42:14 +0000940 string Path;
Dees_Troy01a9b7a2012-10-01 09:01:03 -0400941 char version[255];
942
Dees_Troy1c1ac442013-01-17 21:42:14 +0000943 if (!PartitionManager.Mount_By_Path("/cache", false)) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000944 LOGINFO("Unable to mount '%s' to write version number.\n", Path.c_str());
Dees_Troy01a9b7a2012-10-01 09:01:03 -0400945 return;
946 }
Dees_Troy1c1ac442013-01-17 21:42:14 +0000947 if (!TWFunc::Path_Exists("/cache/recovery/.")) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000948 LOGINFO("Recreating /cache/recovery folder.\n");
Dees_Troy1c1ac442013-01-17 21:42:14 +0000949 if (mkdir("/cache/recovery", S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP) != 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000950 LOGERR("DataManager::Output_Version -- Unable to make /cache/recovery\n");
Dees_Troy1c1ac442013-01-17 21:42:14 +0000951 return;
952 }
953 }
954 Path = "/cache/recovery/.version";
Dees_Troy01a9b7a2012-10-01 09:01:03 -0400955 if (TWFunc::Path_Exists(Path)) {
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500956 unlink(Path.c_str());
Dees_Troy01a9b7a2012-10-01 09:01:03 -0400957 }
958 FILE *fp = fopen(Path.c_str(), "w");
959 if (fp == NULL) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500960 gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(Path)(strerror(errno)));
Dees_Troy01a9b7a2012-10-01 09:01:03 -0400961 return;
962 }
963 strcpy(version, TW_VERSION_STR);
964 fwrite(version, sizeof(version[0]), strlen(version) / sizeof(version[0]), fp);
965 fclose(fp);
Dees_Troyd93bda52013-07-03 19:55:19 +0000966 TWFunc::copy_file("/etc/recovery.fstab", "/cache/recovery/recovery.fstab", 0644);
967 PartitionManager.Output_Storage_Fstab();
Dees_Troy01a9b7a2012-10-01 09:01:03 -0400968 sync();
Dees_Troy2673cec2013-04-02 20:22:16 +0000969 LOGINFO("Version number saved to '%s'\n", Path.c_str());
Ethan Yonker89583ef2015-08-26 09:01:59 -0500970#endif
Dees_Troy01a9b7a2012-10-01 09:01:03 -0400971}
972
Dees_Troy51a0e822012-09-05 15:24:24 -0400973void DataManager::ReadSettingsFile(void)
974{
Ethan Yonker83e82572014-04-04 10:59:28 -0500975#ifndef TW_OEM_BUILD
Dees_Troy51a0e822012-09-05 15:24:24 -0400976 // Load up the values for TWRP - Sleep to let the card be ready
977 char mkdir_path[255], settings_file[255];
978 int is_enc, has_dual, use_ext, has_data_media, has_ext;
979
980 GetValue(TW_IS_ENCRYPTED, is_enc);
981 GetValue(TW_HAS_DATA_MEDIA, has_data_media);
982 if (is_enc == 1 && has_data_media == 1) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000983 LOGINFO("Cannot load settings -- encrypted.\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400984 return;
985 }
986
987 memset(mkdir_path, 0, sizeof(mkdir_path));
988 memset(settings_file, 0, sizeof(settings_file));
Vojtech Bocekfda239b2015-01-07 22:55:13 +0100989 sprintf(mkdir_path, "%s/TWRP", GetSettingsStoragePath().c_str());
Dees_Troy51a0e822012-09-05 15:24:24 -0400990 sprintf(settings_file, "%s/.twrps", mkdir_path);
991
Dees_Troy5bf43922012-09-07 16:07:55 -0400992 if (!PartitionManager.Mount_Settings_Storage(false))
Dees_Troy51a0e822012-09-05 15:24:24 -0400993 {
994 usleep(500000);
Dees_Troy5bf43922012-09-07 16:07:55 -0400995 if (!PartitionManager.Mount_Settings_Storage(false))
Ethan Yonker74db1572015-10-28 12:44:49 -0500996 gui_msg(Msg(msg::kError, "unable_to_mount=Unable to mount {1}")(settings_file));
Dees_Troy51a0e822012-09-05 15:24:24 -0400997 }
998
999 mkdir(mkdir_path, 0777);
1000
Dees_Troy2673cec2013-04-02 20:22:16 +00001001 LOGINFO("Attempt to load settings from settings file...\n");
Dees_Troy51a0e822012-09-05 15:24:24 -04001002 LoadValues(settings_file);
Dees_Troy01a9b7a2012-10-01 09:01:03 -04001003 Output_Version();
Ethan Yonker83e82572014-04-04 10:59:28 -05001004#endif // ifdef TW_OEM_BUILD
Ethan Yonker7af51ce2014-04-04 13:33:30 -05001005 PartitionManager.Mount_All_Storage();
Dees_Troy8170a922012-09-18 15:40:25 -04001006 update_tz_environment_variables();
Tatsuyuki Ishi548a1752015-12-28 10:08:58 +09001007 TWFunc::Set_Brightness(GetStrValue("tw_brightness"));
Dees_Troy51a0e822012-09-05 15:24:24 -04001008}
1009
1010string DataManager::GetCurrentStoragePath(void)
1011{
Dees_Troya13d74f2013-03-24 08:54:55 -05001012 return GetStrValue("tw_storage_path");
Dees_Troy51a0e822012-09-05 15:24:24 -04001013}
1014
Dees_Troy51a0e822012-09-05 15:24:24 -04001015string DataManager::GetSettingsStoragePath(void)
1016{
Dees_Troya13d74f2013-03-24 08:54:55 -05001017 return GetStrValue("tw_settings_path");
Dees_Troy51a0e822012-09-05 15:24:24 -04001018}
1019
Ethan Yonkerfe916112016-03-14 14:54:37 -05001020void DataManager::Vibrate(const string& varName)
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +00001021{
1022 int vib_value = 0;
1023 GetValue(varName, vib_value);
1024 if (vib_value) {
1025 vibrate(vib_value);
1026 }
1027}