blob: 4770ed5839c697a350f50d9adc86c4ab391a344f [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#ifndef _DATAMANAGER_HPP_HEADER
20#define _DATAMANAGER_HPP_HEADER
21
22#include <string>
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050023#include <pthread.h>
Ethan Yonkerfe916112016-03-14 14:54:37 -050024#include "infomanager.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040025
nkk7198fc3992017-12-16 16:26:42 +020026#define PERSIST_SETTINGS_FILE "/persist/.twrps"
27
Dees_Troy51a0e822012-09-05 15:24:24 -040028using namespace std;
29
30class DataManager
31{
32public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020033 static int ResetDefaults();
Ethan Yonkerfe916112016-03-14 14:54:37 -050034 static int LoadValues(const string& filename);
nkk7198fc3992017-12-16 16:26:42 +020035 static int LoadPersistValues(void);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020036 static int Flush();
Dees_Troy51a0e822012-09-05 15:24:24 -040037
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020038 // Core get routines
Ethan Yonkerfe916112016-03-14 14:54:37 -050039 static int GetValue(const string& varName, string& value);
40 static int GetValue(const string& varName, int& value);
41 static int GetValue(const string& varName, float& value);
nkk7198fc3992017-12-16 16:26:42 +020042 static int GetValue(const string& varName, unsigned long long& value);
Dees_Troy51a0e822012-09-05 15:24:24 -040043
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020044 // Helper functions
Ethan Yonkerfe916112016-03-14 14:54:37 -050045 static string GetStrValue(const string& varName);
46 static int GetIntValue(const string& varName);
Dees_Troy51a0e822012-09-05 15:24:24 -040047
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020048 // Core set routines
Ethan Yonkerfe916112016-03-14 14:54:37 -050049 static int SetValue(const string& varName, const string& value, const int persist = 0);
50 static int SetValue(const string& varName, const int value, const int persist = 0);
51 static int SetValue(const string& varName, const float value, const int persist = 0);
52 static int SetValue(const string& varName, const unsigned long long& value, const int persist = 0);
53 static int SetProgress(const float Fraction);
Chaosmasterab164372020-02-03 15:38:02 +010054 static int _SetProgress(float Fraction);
55 static int ShowProgress(float Portion, const float Seconds);
Dees_Troy51a0e822012-09-05 15:24:24 -040056
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020057 static void DumpValues();
Dees_Troy8170a922012-09-18 15:40:25 -040058 static void update_tz_environment_variables();
Ethan Yonkerfe916112016-03-14 14:54:37 -050059 static void Vibrate(const string& varName);
Dees_Troy16b74352012-11-14 22:27:31 +000060 static void SetBackupFolder();
Dees_Troy51a0e822012-09-05 15:24:24 -040061 static void SetDefaultValues();
Dees_Troy01a9b7a2012-10-01 09:01:03 -040062 static void Output_Version(void); // Outputs the version to a file in the TWRP folder
Dees_Troy51a0e822012-09-05 15:24:24 -040063 static void ReadSettingsFile(void);
bigbiff bigbiff2c57d782013-02-19 10:09:21 -050064
Dees_Troy51a0e822012-09-05 15:24:24 -040065 static string GetCurrentStoragePath(void);
Dees_Troy51a0e822012-09-05 15:24:24 -040066 static string GetSettingsStoragePath(void);
Dees_Troy51a0e822012-09-05 15:24:24 -040067
68protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020069 static string mBackingFile;
70 static int mInitialized;
Ethan Yonkerfe916112016-03-14 14:54:37 -050071 static InfoManager mPersist;
72 static InfoManager mData;
73 static InfoManager mConst;
Dees_Troy51a0e822012-09-05 15:24:24 -040074
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020075 static map<string, string> mConstValues;
Dees_Troy51a0e822012-09-05 15:24:24 -040076
77protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020078 static int SaveValues();
Dees_Troy51a0e822012-09-05 15:24:24 -040079
Ethan Yonkerfe916112016-03-14 14:54:37 -050080 static int GetMagicValue(const string& varName, string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -040081
Dees_Troyfdf5fcc2012-09-11 10:27:01 -040082private:
83 static void sanitize_device_id(char* device_id);
84 static void get_device_id(void);
85
Vojtech Bocekfda239b2015-01-07 22:55:13 +010086 static pthread_mutex_t m_valuesLock;
Dees_Troy51a0e822012-09-05 15:24:24 -040087};
88
89#endif // _DATAMANAGER_HPP_HEADER
90