From 19874f14699edf411951a62f5ac880ca6a84d824 Mon Sep 17 00:00:00 2001 From: bigbiff bigbiff Date: Tue, 8 Jan 2019 20:06:57 -0500 Subject: [PATCH] AB/Non AB Devices: updates for moving cache This patchset updates all the places we touch cache on AB devices and non AB devices so that we can write to the appropriate location. AB devices removed the cache partition and moved it to /data/cache. Change-Id: I485ec205a604f1f07ceb7700ae9c4e720fd55c3e --- data.cpp | 39 +++++------ gui/action.cpp | 3 +- gui/theme/common/landscape.xml | 19 +++++- gui/theme/common/languages/en.xml | 11 +++- gui/theme/common/portrait.xml | 19 +++++- gui/theme/common/watch.xml | 19 +++++- openrecoveryscript.cpp | 21 +++--- partitionmanager.cpp | 31 +++++++-- twrp-functions.cpp | 105 +++++++++++++++++++++++------- twrp-functions.hpp | 5 ++ twrp.cpp | 61 ++++------------- variables.h | 2 - 12 files changed, 220 insertions(+), 115 deletions(-) mode change 100644 => 100755 openrecoveryscript.cpp mode change 100644 => 100755 partitionmanager.cpp mode change 100644 => 100755 twrp-functions.cpp mode change 100644 => 100755 twrp-functions.hpp mode change 100644 => 100755 twrp.cpp diff --git a/data.cpp b/data.cpp index cf8349ba..0ece4e79 100755 --- a/data.cpp +++ b/data.cpp @@ -1038,33 +1038,38 @@ void DataManager::Output_Version(void) string Path; char version[255]; - if (!PartitionManager.Mount_By_Path("/cache", false)) { - LOGINFO("Unable to mount '%s' to write version number.\n", Path.c_str()); - return; - } - if (!TWFunc::Path_Exists("/cache/recovery/.")) { - LOGINFO("Recreating /cache/recovery folder.\n"); - if (mkdir("/cache/recovery", S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP) != 0) { - LOGERR("DataManager::Output_Version -- Unable to make /cache/recovery\n"); + std::string cacheDir = TWFunc::get_cache_dir(); + std::string recoveryCacheDir = cacheDir + "recovery/"; + + if (cacheDir == NON_AB_CACHE_DIR) { + if (!PartitionManager.Mount_By_Path(NON_AB_CACHE_DIR, false)) { + LOGINFO("Unable to mount '%s' to write version number.\n", Path.c_str()); return; } } - Path = "/cache/recovery/.version"; - if (TWFunc::Path_Exists(Path)) { - unlink(Path.c_str()); + if (!TWFunc::Path_Exists(recoveryCacheDir)) { + LOGINFO("Recreating %s folder.\n", recoveryCacheDir.c_str()); + if (mkdir(recoveryCacheDir.c_str(), S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP) != 0) { + LOGERR("DataManager::Output_Version -- Unable to make %s: %s\n", recoveryCacheDir.c_str(), strerror(errno)); + return; + } } - FILE *fp = fopen(Path.c_str(), "w"); + std::string verPath = recoveryCacheDir + ".version"; + if (TWFunc::Path_Exists(verPath)) { + unlink(verPath.c_str()); + } + FILE *fp = fopen(verPath.c_str(), "w"); if (fp == NULL) { - gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(Path)(strerror(errno))); + gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(verPath)(strerror(errno))); return; } strcpy(version, TW_VERSION_STR); fwrite(version, sizeof(version[0]), strlen(version) / sizeof(version[0]), fp); fclose(fp); - TWFunc::copy_file("/etc/recovery.fstab", "/cache/recovery/recovery.fstab", 0644); + TWFunc::copy_file("/etc/recovery.fstab", recoveryCacheDir + "recovery.fstab", 0644); PartitionManager.Output_Storage_Fstab(); sync(); - LOGINFO("Version number saved to '%s'\n", Path.c_str()); + LOGINFO("Version number saved to '%s'\n", verPath.c_str()); #endif } @@ -1077,10 +1082,6 @@ void DataManager::ReadSettingsFile(void) GetValue(TW_IS_ENCRYPTED, is_enc); GetValue(TW_HAS_DATA_MEDIA, has_data_media); - if (is_enc == 1 && has_data_media == 1) { - LOGINFO("Cannot load settings -- encrypted.\n"); - return; - } memset(mkdir_path, 0, sizeof(mkdir_path)); memset(settings_file, 0, sizeof(settings_file)); diff --git a/gui/action.cpp b/gui/action.cpp index 11d9580f..4b644a9b 100755 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -490,6 +490,8 @@ void GUIAction::operation_start(const string operation_name) DataManager::SetValue("tw_operation", operation_name); DataManager::SetValue("tw_operation_state", 0); DataManager::SetValue("tw_operation_status", 0); + bool tw_ab_device = TWFunc::get_cache_dir() != NON_AB_CACHE_DIR; + DataManager::SetValue("tw_ab_device", tw_ab_device); } void GUIAction::operation_end(const int operation_status) @@ -1059,7 +1061,6 @@ int GUIAction::wipe(std::string arg) { operation_start("Format"); DataManager::SetValue("tw_partition", arg); - int ret_val = false; if (simulate) { diff --git a/gui/theme/common/landscape.xml b/gui/theme/common/landscape.xml index f6f14bc5..d1bce168 100755 --- a/gui/theme/common/landscape.xml +++ b/gui/theme/common/landscape.xml @@ -527,8 +527,9 @@