Commit a13d74fc authored by Dees_Troy's avatar Dees_Troy

Add partition list GUI element

Add partition list GUI element and update backup, restore, mount,
storage selection, and wipe sections of GUI and partition manager
code to reflect the new GUI element. Update ORS engine to handle
new backup and restore setup.

Fix a bug with decrypt.
Add 1080x1920 layout.

Change-Id: Iaa2f44cb707167e66f935452f076ba00e68a2aa4
parent 3b511633
......@@ -211,7 +211,7 @@ static int get_crypt_ftr_and_key(char *real_blk_name, struct crypt_mnt_ftr *cryp
/* the footer size is bigger than we expected.
* Skip to it's stated end so we can read the key.
*/
if (lseek(fd, crypt_ftr->ftr_size - sizeof(struct crypt_mnt_ftr), SEEK_CUR) == -1) {
if (lseek64(fd, crypt_ftr->ftr_size - sizeof(struct crypt_mnt_ftr), SEEK_CUR) == -1) {
printf("Cannot seek to start of key\n");
goto errout;
}
......
......@@ -317,7 +317,7 @@ static int get_crypt_ftr_and_key(char *real_blk_name, struct crypt_mnt_ftr *cryp
/* the footer size is bigger than we expected.
* Skip to it's stated end so we can read the key.
*/
if (lseek(fd, crypt_ftr->ftr_size - sizeof(struct crypt_mnt_ftr), SEEK_CUR) == -1) {
if (lseek64(fd, crypt_ftr->ftr_size - sizeof(struct crypt_mnt_ftr), SEEK_CUR) == -1) {
SLOGE("Cannot seek to start of key\n");
goto errout;
}
......
......@@ -226,7 +226,12 @@ int DataManager::LoadValues(const string filename)
// Read in the file, if possible
FILE* in = fopen(filename.c_str(), "rb");
if (!in) return 0;
if (!in) {
LOGI("Settings file '%s' not found.\n", filename.c_str());
return 0;
} else {
LOGI("Loading settings from '%s'.\n", filename.c_str());
}
int file_version;
if (fread(&file_version, 1, sizeof(int), in) != sizeof(int)) goto error;
......@@ -259,24 +264,19 @@ int DataManager::LoadValues(const string filename)
}
else
mValues.insert(TNameValuePair(Name, TStrIntPair(Value, 1)));
if (Name == "tw_screen_timeout_secs")
blankTimer.setTime(atoi(Value.c_str()));
}
fclose(in);
str = GetCurrentStoragePath();
str += "/TWRP/BACKUPS/";
str += dev_id;
SetValue(TW_BACKUPS_FOLDER_VAR, str, 0);
return 0;
error:
// File version mismatch. Use defaults.
fclose(in);
str = GetCurrentStoragePath();
str += "/TWRP/BACKUPS/";
str += dev_id;
SetValue(TW_BACKUPS_FOLDER_VAR, str, 0);
return -1;
string current = GetCurrentStoragePath();
string settings = GetSettingsStoragePath();
if (current != settings && !PartitionManager.Mount_By_Path(current, false)) {
SetValue("tw_storage_path", settings);
} else {
SetBackupFolder();
}
return 0;
}
int DataManager::Flush()
......@@ -433,10 +433,10 @@ int DataManager::SetValue(const string varName, string value, int persist /* = 0
SaveValues();
if (varName == "tw_screen_timeout_secs") {
blankTimer.setTime(atoi(value.c_str()));
} else if (varName == "tw_storage_path") {
SetBackupFolder();
}
else {
gui_notifyVarChange(varName.c_str(), value.c_str());
}
gui_notifyVarChange(varName.c_str(), value.c_str());
return 0;
}
......@@ -458,13 +458,8 @@ int DataManager::SetValue(const string varName, int value, int persist /* = 0 */
else
str = GetStrValue(TW_EXTERNAL_PATH);
string dev_id;
GetValue("device_id", dev_id);
str += "/TWRP/BACKUPS/";
str += dev_id;
SetValue(TW_BACKUPS_FOLDER_VAR, str);
SetValue("tw_storage_path", str);
SetBackupFolder();
}
return SetValue(varName, valStr.str(), persist);;
}
......@@ -501,13 +496,38 @@ void DataManager::update_tz_environment_variables(void) {
void DataManager::SetBackupFolder()
{
string str = GetCurrentStoragePath();
TWPartition* partition = PartitionManager.Find_Partition_By_Path(str);
str += "/TWRP/BACKUPS/";
string dev_id;
GetValue("device_id", dev_id);
str += dev_id;
LOGI("Backup folder set to '%s'\n", str.c_str());
SetValue(TW_BACKUPS_FOLDER_VAR, str, 0);
if (partition != NULL) {
SetValue("tw_storage_display_name", partition->Storage_Name);
char free_space[255];
sprintf(free_space, "%llu", partition->Free / 1024 / 1024);
SetValue("tw_storage_free_size", free_space);
string zip_path, zip_root, storage_path;
GetValue(TW_ZIP_LOCATION_VAR, zip_path);
if (partition->Has_Data_Media)
storage_path = partition->Symlink_Mount_Point;
else
storage_path = partition->Storage_Path;
if (zip_path.size() < storage_path.size()) {
SetValue(TW_ZIP_LOCATION_VAR, storage_path);
} else {
zip_root= zip_path;
zip_root.resize(storage_path.size() + 1);
if (zip_root != storage_path)
SetValue(TW_ZIP_LOCATION_VAR, storage_path);
}
} else {
if (PartitionManager.Fstab_Processed() != 0)
LOGE("Storage partition '%s' not found\n", str.c_str());
}
}
void DataManager::SetDefaultValues()
......@@ -522,6 +542,7 @@ void DataManager::SetDefaultValues()
mConstValues.insert(make_pair("false", "0"));
mConstValues.insert(make_pair(TW_VERSION_VAR, TW_VERSION_STR));
mValues.insert(make_pair("tw_storage_path", make_pair("/", 1)));
#ifdef TW_FORCE_CPUINFO_FOR_DEVICE_ID
printf("TW_FORCE_CPUINFO_FOR_DEVICE_ID := true\n");
......@@ -788,7 +809,12 @@ void DataManager::SetDefaultValues()
mConstValues.insert(make_pair(TW_SDEXT_DISABLE_EXT4, "0"));
#endif
mConstValues.insert(make_pair(TW_MIN_SYSTEM_VAR, TW_MIN_SYSTEM_SIZE));
#ifdef TW_HAS_NO_BOOT_PARTITION
mValues.insert(make_pair("tw_backup_list", make_pair("/system;/data;", 0)));
#else
mValues.insert(make_pair("tw_backup_list", make_pair("/system;/data;/boot;", 0)));
#endif
mConstValues.insert(make_pair(TW_MIN_SYSTEM_VAR, TW_MIN_SYSTEM_SIZE));
mValues.insert(make_pair(TW_BACKUP_NAME, make_pair("(Current Date)", 0)));
mValues.insert(make_pair(TW_BACKUP_SYSTEM_VAR, make_pair("1", 1)));
mValues.insert(make_pair(TW_BACKUP_DATA_VAR, make_pair("1", 1)));
......@@ -882,7 +908,7 @@ void DataManager::SetDefaultValues()
mConstValues.insert(make_pair("tw_has_brightnesss_file", "0"));
}
#endif
mValues.insert(make_pair(TW_MILITARY_TIME, make_pair("0", 0)));
mValues.insert(make_pair(TW_MILITARY_TIME, make_pair("0", 1)));
}
// Magic Values
......@@ -1018,7 +1044,7 @@ void DataManager::ReadSettingsFile(void)
{
usleep(500000);
if (!PartitionManager.Mount_Settings_Storage(false))
LOGE("Unable to mount %s when trying to read settings file.\n", DataManager_GetSettingsStorageMount());
LOGE("Unable to mount %s when trying to read settings file.\n", settings_file);
}
mkdir(mkdir_path, 0777);
......@@ -1063,86 +1089,22 @@ void DataManager::ReadSettingsFile(void)
string DataManager::GetCurrentStoragePath(void)
{
if (GetIntValue(TW_HAS_DUAL_STORAGE) == 1) {
if (GetIntValue(TW_USE_EXTERNAL_STORAGE) == 0)
return GetStrValue(TW_INTERNAL_PATH);
else
return GetStrValue(TW_EXTERNAL_PATH);
} else if (GetIntValue(TW_HAS_INTERNAL) == 1)
return GetStrValue(TW_INTERNAL_PATH);
else
return GetStrValue(TW_EXTERNAL_PATH);
return GetStrValue("tw_storage_path");
}
string& DataManager::CGetCurrentStoragePath()
{
if (GetIntValue(TW_HAS_DUAL_STORAGE) == 1) {
if (GetIntValue(TW_USE_EXTERNAL_STORAGE) == 0)
return GetValueRef(TW_INTERNAL_PATH);
else
return GetValueRef(TW_EXTERNAL_PATH);
} else if (GetIntValue(TW_HAS_INTERNAL) == 1)
return GetValueRef(TW_INTERNAL_PATH);
else
return GetValueRef(TW_EXTERNAL_PATH);
}
string DataManager::GetCurrentStorageMount(void)
{
if (GetIntValue(TW_HAS_DUAL_STORAGE) == 1) {
if (GetIntValue(TW_USE_EXTERNAL_STORAGE) == 0)
return GetStrValue(TW_INTERNAL_MOUNT);
else
return GetStrValue(TW_EXTERNAL_MOUNT);
} else if (GetIntValue(TW_HAS_INTERNAL) == 1)
return GetStrValue(TW_INTERNAL_MOUNT);
else
return GetStrValue(TW_EXTERNAL_MOUNT);
}
string& DataManager::CGetCurrentStorageMount()
{
if (GetIntValue(TW_HAS_DUAL_STORAGE) == 1) {
if (GetIntValue(TW_USE_EXTERNAL_STORAGE) == 0)
return GetValueRef(TW_INTERNAL_MOUNT);
else
return GetValueRef(TW_EXTERNAL_MOUNT);
} else if (GetIntValue(TW_HAS_INTERNAL) == 1)
return GetValueRef(TW_INTERNAL_MOUNT);
else
return GetValueRef(TW_EXTERNAL_MOUNT);
return GetValueRef("tw_storage_path");
}
string DataManager::GetSettingsStoragePath(void)
{
if (GetIntValue(TW_HAS_INTERNAL) == 1)
return GetStrValue(TW_INTERNAL_PATH);
else
return GetStrValue(TW_EXTERNAL_PATH);
return GetStrValue("tw_settings_path");
}
string& DataManager::CGetSettingsStoragePath()
{
if (GetIntValue(TW_HAS_INTERNAL) == 1)
return GetValueRef(TW_INTERNAL_PATH);
else
return GetValueRef(TW_EXTERNAL_PATH);
}
string DataManager::GetSettingsStorageMount(void)
{
if (GetIntValue(TW_HAS_INTERNAL) == 1)
return GetStrValue(TW_INTERNAL_MOUNT);
else
return GetStrValue(TW_EXTERNAL_MOUNT);
}
string& DataManager::CGetSettingsStorageMount()
{
if (GetIntValue(TW_HAS_INTERNAL) == 1)
return GetValueRef(TW_INTERNAL_MOUNT);
else
return GetValueRef(TW_EXTERNAL_MOUNT);
return GetValueRef("tw_settings_path");
}
extern "C" int DataManager_ResetDefaults()
......@@ -1194,18 +1156,6 @@ extern "C" const char* DataManager_GetSettingsStoragePath(void)
return str.c_str();
}
extern "C" const char* DataManager_GetCurrentStorageMount(void)
{
string& str = DataManager::CGetCurrentStorageMount();
return str.c_str();
}
extern "C" const char* DataManager_GetSettingsStorageMount(void)
{
string& str = DataManager::CGetSettingsStorageMount();
return str.c_str();
}
extern "C" int DataManager_GetIntValue(const char* varName)
{
return DataManager::GetIntValue(varName);
......
......@@ -23,9 +23,7 @@ int DataManager_LoadValues(const char* filename);
int DataManager_Flush();
const char* DataManager_GetStrValue(const char* varName);
const char* DataManager_GetCurrentStoragePath();
const char* DataManager_GetCurrentStorageMount();
const char* DataManager_GetSettingsStoragePath();
const char* DataManager_GetSettingsStorageMount();
int DataManager_GetIntValue(const char* varName);
int DataManager_SetStrValue(const char* varName, char* value);
......
......@@ -57,12 +57,8 @@ public:
static string GetCurrentStoragePath(void);
static string& CGetCurrentStoragePath();
static string GetCurrentStorageMount(void);
static string& CGetCurrentStorageMount();
static string GetSettingsStoragePath(void);
static string& CGetSettingsStoragePath();
static string GetSettingsStorageMount(void);
static string& CGetSettingsStorageMount();
protected:
typedef pair<string, int> TStrIntPair;
......
......@@ -21,6 +21,7 @@ LOCAL_SRC_FILES := \
keyboard.cpp \
input.cpp \
blanktimer.cpp \
partitionlist.cpp \
../minuitwrp/graphics.c
ifneq ($(TWRP_CUSTOM_KEYBOARD),)
......
// image.cpp - GUIImage object
/*
Copyright 2013 bigbiff/Dees_Troy TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
TWRP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TWRP. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
#include <stdio.h>
......@@ -745,6 +761,51 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
ret_val = PartitionManager.Wipe_By_Path(External_Path);
} else if (arg == "ANDROIDSECURE") {
ret_val = PartitionManager.Wipe_Android_Secure();
} else if (arg == "LIST") {
string Wipe_List, wipe_path;
bool skip = false;
ret_val = true;
TWPartition* wipe_part = NULL;
DataManager::GetValue("tw_wipe_list", Wipe_List);
LOGI("wipe list '%s'\n", Wipe_List.c_str());
if (!Wipe_List.empty()) {
size_t start_pos = 0, end_pos = Wipe_List.find(";", start_pos);
while (end_pos != string::npos && start_pos < Wipe_List.size()) {
wipe_path = Wipe_List.substr(start_pos, end_pos - start_pos);
LOGI("wipe_path '%s'\n", wipe_path.c_str());
if (wipe_path == "/and-sec") {
if (!PartitionManager.Wipe_Android_Secure()) {
LOGE("Unable to wipe android secure\n");
ret_val = false;
break;
} else {
skip = true;
}
} else if (wipe_path == "DALVIK") {
if (!PartitionManager.Wipe_Dalvik_Cache()) {
LOGE("Failed to wipe dalvik\n");
ret_val = false;
break;
} else {
skip = true;
}
}
if (!skip) {
if (!PartitionManager.Wipe_By_Path(wipe_path)) {
LOGE("Unable to wipe '%s'\n", wipe_path.c_str());
ret_val = false;
break;
} else if (wipe_path == DataManager::GetSettingsStoragePath()) {
arg = wipe_path;
}
} else {
skip = false;
}
start_pos = end_pos + 1;
end_pos = Wipe_List.find(";", start_pos);
}
}
} else
ret_val = PartitionManager.Wipe_By_Path(arg);
......
......@@ -109,7 +109,17 @@ int blanktimer::getBrightness(void) {
string brightness_path = EXPAND(TW_BRIGHTNESS_PATH);
if ((TWFunc::read_file(brightness_path, results)) != 0)
return -1;
return atoi(results.c_str());
int result = atoi(results.c_str());
if (result == 0) {
int tw_brightness;
DataManager::GetValue("tw_brightness", tw_brightness);
if (tw_brightness) {
result = tw_brightness;
} else {
result = 255;
}
}
return result;
}
......
// button.cpp - GUIButton object
/*
Copyright 2012 bigbiff/Dees_Troy TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
TWRP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TWRP. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
#include <stdio.h>
......@@ -39,6 +55,7 @@ GUIButton::GUIButton(xml_node<>* node)
mRendered = false;
hasHighlightColor = false;
renderHighlight = false;
hasFill = false;
if (!node) return;
......@@ -49,7 +66,6 @@ GUIButton::GUIButton(xml_node<>* node)
if (mButtonImg->Render() < 0)
{
LOGE("Unable to locate button image\n");
delete mButtonImg;
mButtonImg = NULL;
}
......@@ -58,6 +74,21 @@ GUIButton::GUIButton(xml_node<>* node)
delete mButtonLabel;
mButtonLabel = NULL;
}
// Load fill if it exists
memset(&mFillColor, 0, sizeof(COLOR));
child = node->first_node("fill");
if (child)
{
attr = child->first_attribute("color");
if (attr) {
hasFill = true;
std::string color = attr->value();
ConvertStrToColor(color, &mFillColor);
}
}
if (!hasFill && mButtonImg == NULL) {
LOGE("No image resource or fill specified for button.\n");
}
// The icon is a special case
child = node->first_node("icon");
......@@ -80,8 +111,12 @@ GUIButton::GUIButton(xml_node<>* node)
}
int x, y, w, h;
if (mButtonImg) mButtonImg->GetRenderPos(x, y, w, h);
SetRenderPos(x, y, w, h);
if (mButtonImg) {
mButtonImg->GetRenderPos(x, y, w, h);
} else if (hasFill) {
LoadPlacement(node->first_node("placement"), &x, &y, &w, &h);
}
SetRenderPos(x, y, w, h);
return;
}
......@@ -105,10 +140,32 @@ int GUIButton::Render(void)
if (mButtonImg) ret = mButtonImg->Render();
if (ret < 0) return ret;
if (hasFill) {
gr_color(mFillColor.red, mFillColor.green, mFillColor.blue, mFillColor.alpha);
gr_fill(mRenderX, mRenderY, mRenderW, mRenderH);
}
if (mButtonIcon && mButtonIcon->GetResource())
gr_blit(mButtonIcon->GetResource(), 0, 0, mIconW, mIconH, mIconX, mIconY);
if (mButtonLabel) ret = mButtonLabel->Render();
if (ret < 0) return ret;
if (mButtonLabel) {
int w, h;
mButtonLabel->GetCurrentBounds(w, h);
if (w != mTextW) {
mTextW = w;
// As a special case, we'll allow large text which automatically moves it to the right.
if (mTextW > mRenderW)
{
mTextX = mRenderW + mRenderX + 5;
mRenderW += mTextW + 5;
}
else
{
mTextX = mRenderX + ((mRenderW - mTextW) / 2);
}
mButtonLabel->SetRenderPos(mTextX, mTextY);
}
ret = mButtonLabel->Render();
if (ret < 0) return ret;
}
if (renderHighlight && hasHighlightColor) {
gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha);
gr_fill(mRenderX, mRenderY, mRenderW, mRenderH);
......@@ -129,9 +186,11 @@ int GUIButton::Update(void)
if (ret == 0)
{
if (mButtonLabel) ret2 = mButtonLabel->Update();
if (ret2 < 0) return ret2;
if (ret2 > ret) ret = ret2;
if (mButtonLabel) {
ret2 = mButtonLabel->Update();
if (ret2 < 0) return ret2;
if (ret2 > ret) ret = ret2;
}
}
else if (ret == 1)
{
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// FileSelector.cpp - GUIFileSelector object
/*
Copyright 2012 bigbiff/Dees_Troy TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
TWRP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TWRP. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/input.h>
#include <pthread.h>
......@@ -1003,4 +1019,4 @@ void GUIFileSelector::SetPageFocus(int inFocus)
scrollingSpeed = 0;
mUpdate = 1;
}
}
\ No newline at end of file
}
......@@ -35,8 +35,10 @@ GUIFill::GUIFill(xml_node<>* node)
return;
attr = node->first_attribute("color");
if (!attr)
if (!attr) {
LOGE("No color specified for fill\n");
return;
}
std::string color = attr->value();
ConvertStrToColor(color, &mColor);
......
// FileSelector.cpp - GUIFileSelector object
/*
Copyright 2013 bigbiff/Dees_Troy TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
TWRP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TWRP. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/input.h>
#include <pthread.h>
......
/*
Copyright 2013 bigbiff/Dees_Troy TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or