Merge remote-tracking branch 'TeamWin/android-11' into android-11

Change-Id: Id1d534cce0969c98e2b8b6484278342201dd562d
This commit is contained in:
Konsta
2022-01-12 16:55:24 +02:00
27 changed files with 215 additions and 103 deletions

View File

@@ -166,6 +166,10 @@ ifeq ($(PRODUCT_USE_DYNAMIC_PARTITIONS),true)
endif
endif
ifneq ($(TW_SYSTEM_BUILD_PROP_ADDITIONAL_PATHS),)
LOCAL_CFLAGS += -DTW_SYSTEM_BUILD_PROP_ADDITIONAL_PATHS='"$(TW_SYSTEM_BUILD_PROP_ADDITIONAL_PATHS)"'
endif
ifeq ($(TW_USES_VENDOR_LIBS),true)
LOCAL_CFLAGS += -DUSE_VENDOR_LIBS=1
endif

View File

@@ -33,6 +33,7 @@
#include <logwrap/logwrap.h>
#include <utils/misc.h>
#include <fscrypt/fscrypt.h>
#include "KeyUtil.h"
#include "fscrypt_policy.h"
@@ -144,14 +145,22 @@ extern "C" bool fscrypt_policy_set_struct(const char *directory, const struct fs
#endif
int fd = open(directory, O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
if (fd == -1) {
printf("failed to open %s\n", directory);
printf("failed to open %s\n", directory);
PLOG(ERROR) << "Failed to open directory " << directory;
return false;
}
if (ioctl(fd, FS_IOC_SET_ENCRYPTION_POLICY, fep)) {
PLOG(ERROR) << "Failed to set encryption policy for " << directory;
close(fd);
return false;
if (isFsKeyringSupported()) {
if (ioctl(fd, FS_IOC_SET_ENCRYPTION_POLICY, fep)) {
PLOG(ERROR) << "Failed to set encryption policy for " << directory;
close(fd);
return false;
}
} else {
if (ioctl(fd, FS_IOC_SET_ENCRYPTION_POLICY, fep)) {
PLOG(ERROR) << "Failed to set encryption policy for " << directory;
close(fd);
return false;
}
}
close(fd);
return true;
@@ -172,19 +181,28 @@ extern "C" bool fscrypt_policy_get_struct(const char *directory, struct fscrypt_
#else
memset(fep, 0, sizeof(fscrypt_policy_v2));
#endif
struct fscrypt_get_policy_ex_arg ex_policy = {0};
ex_policy.policy_size = sizeof(ex_policy.policy);
if (ioctl(fd, FS_IOC_GET_ENCRYPTION_POLICY_EX, &ex_policy) != 0) {
PLOG(ERROR) << "Failed to get encryption policy for " << directory;
close(fd);
return false;
}
if (isFsKeyringSupported()) {
ex_policy.policy_size = sizeof(ex_policy.policy);
if (ioctl(fd, FS_IOC_GET_ENCRYPTION_POLICY_EX, &ex_policy) != 0) {
PLOG(ERROR) << "Failed to get encryption policy for " << directory;
close(fd);
return false;
}
#ifdef USE_FSCRYPT_POLICY_V1
memcpy(fep, &ex_policy.policy.v1, sizeof(ex_policy.policy.v1));
memcpy(fep, &ex_policy.policy.v1, sizeof(ex_policy.policy.v1));
#else
memcpy(fep, &ex_policy.policy.v2, sizeof(ex_policy.policy.v2));
memcpy(fep, &ex_policy.policy.v2, sizeof(ex_policy.policy.v2));
#endif
} else {
if (ioctl(fd, FS_IOC_GET_ENCRYPTION_POLICY, &ex_policy.policy.v1) != 0) {
PLOG(ERROR) << "Failed to get encryption policy for " << directory;
close(fd);
return false;
}
memcpy(fep, &ex_policy.policy.v1, sizeof(ex_policy.policy.v1));
}
close(fd);
return true;
}

View File

@@ -780,6 +780,7 @@ void Set_Needed_Properties(void) {
property_set("vendor.sys.listeners.registered", "false");
}
#ifdef TW_INCLUDE_LIBRESETPROP // Patch_Level_Overrides
void Update_Patch_Level(void) {
// On Oreo and above, keymaster requires Android version & patch level to match installed system
string sdkverstr = TWFunc::System_Property_Get("ro.build.version.sdk");
@@ -901,6 +902,7 @@ void Revert_Patch_Level(void) {
return;
}
}
#endif // Patch_Level_Overrides
static unsigned int get_blkdev_size(int fd) {
unsigned long nr_sec;

View File

@@ -779,6 +779,7 @@ void DataManager::SetDefaultValues()
mData.SetValue(TW_IS_ENCRYPTED, "0");
mData.SetValue(TW_IS_DECRYPTED, "0");
mData.SetValue(TW_CRYPTO_PASSWORD, "0");
mData.SetValue(TW_CRYPTO_PWTYPE, "0"); // Set initial value so that recovery will not be confused when using unencrypted data or failed to decrypt data
mData.SetValue("tw_terminal_state", "0");
mData.SetValue("tw_background_thread_running", "0");
mData.SetValue(TW_RESTORE_FILE_DATE, "0");

View File

@@ -1,3 +1,3 @@
on fs
export TERMINFO /system/etc/terminfo
export TERM pcansi
export TERM bg1.25

View File

@@ -225,7 +225,7 @@ static int handle_release(void* /* data */, fuse_data* /* fd */, const fuse_in_h
// Fetch a block from the host into fd->curr_block and fd->block_data.
// Returns 0 on successful fetch, negative otherwise.
static int fetch_block(fuse_data* fd, uint32_t block) {
static int fetch_block(fuse_data* fd, uint64_t block) {
if (block == fd->curr_block) {
return 0;
}

View File

@@ -2199,7 +2199,7 @@
<action>
<condition var1="tw_crypto_pwtype" op="!=" var2="0"/>
<actions>
<action function="page">restore_pin</action>
<action function="page">restore_keymaster</action>
</actions>
</action>
@@ -2233,7 +2233,7 @@
<condition var1="tw_multiuser_warning_accepted" op="!=" var2="1"/>
</conditions>
<actions>
<action function="set">tw_multiuser_warning_destination=restore</action>
<action function="set">tw_multiuser_warning_destination=restore_force</action>
<action function="page">multiuser_warning</action>
</actions>
</action>
@@ -2267,12 +2267,6 @@
<action function="overlay">select_storage</action>
</actions>
</button>
<action>
<condition var1="tw_crypto_pwtype" op="!=" var2="0"/>
<actions>
<action function="page">restore_pin</action>
</actions>
</action>
<action>
<condition var1="tw_restore" op="modified"/>
@@ -3746,7 +3740,7 @@
<listbox style="advanced_listbox">
<placement x="%center_x%" y="%row2_y%" w="%content_half_width%" h="%fileselector_install_height%"/>
<listitem name="{@change_twrp_folder_btn=Change TWRP folder}">
<condition var1="tw_is_encrypted" var2="0"/>
<condition var1="tw_is_decrypted" var2="1"/>
<action function="page">changeTwrpFolder</action>
</listitem>
<listitem name="{@decrypt_users=Decrypt Users}">
@@ -6109,24 +6103,24 @@ edi <conditions>
</action>
</page>
<page name="restore_pin">
<page name="restore_keymaster">
<template name="page"/>
<text style="text_m_accent">
<condition var1="tw_crypto_pwtype" var2="1"/>
<placement x="%col1_x_header%" y="%row3_header_y%"/>
<text>{@restore_with_pin1=PIN/Password is enabled}</text>
<text>{@restore_with_pin_password1=PIN/Password is enabled}</text>
</text>
<text style="text_m_accent">
<condition var1="tw_crypto_pwtype" var2="1"/>
<placement x="%col1_x_header%" y="%row4_header_y%"/>
<text>{@restore_with_pin2=PIN/Password should be disabled before restore}</text>
<text>{@restore_with_pin_password2=PIN/Password should be disabled before restore}</text>
</text>
<text style="text_l">
<condition var1="tw_crypto_pwtype" var2="1"/>
<placement x="%center_x%" y="%row2_y%" placement="5"/>
<text>{@restore_pin=Restore While PIN/Password Enabled?}</text>
<text>{@restore_pin_password=Restore While PIN/Password Enabled?}</text>
</text>
<text style="text_m_accent">
@@ -6147,6 +6141,23 @@ edi <conditions>
<text>{@restore_pattern=Restore While Pattern Enabled?}</text>
</text>
<text style="text_m_accent">
<condition var1="tw_crypto_pwtype" var2="3"/>
<placement x="%col1_x_header%" y="%row3_header_y%"/>
<text>{@restore_with_pin1=PIN is enabled}</text>
</text>
<text style="text_m_accent">
<condition var1="tw_crypto_pwtype" var2="3"/>
<placement x="%col1_x_header%" y="%row4_header_y%"/>
<text>{@restore_with_pin2=PIN should be disabled before restore}</text>
</text>
<text style="text_l">
<condition var1="tw_crypto_pwtype" var2="3"/>
<placement x="%center_x%" y="%row2_y%" placement="5"/>
<text>{@restore_pin=Restore While PIN Enabled?}</text>
</text>
<slider>
<text>{@continue_restore_encrypted=Continue Restore?}</text>
<actions>

View File

@@ -507,8 +507,8 @@
<string name="install_complete">Установка завершена</string>
<string name="unpack_error">Ошибка распаковки образа.</string>
<string name="repack_error">Ошибка перепаковки образа.</string>
<string name="modified_ramdisk_error">файлы рамдиска были изменены, неудалось создать рамдиск для установки, используйте fastboot boot twrp и попробуйте эту функцию снова или воспользуйтесь Установка рекавери в ramdisk.</string>
<string name="create_ramdisk_error">неудалось создать рамдиск для установки.</string>
<string name="modified_ramdisk_error">файлы рамдиска были изменены, не удалось создать рамдиск для установки, используйте fastboot boot twrp и попробуйте эту функцию снова или воспользуйтесь Установка рекавери в ramdisk.</string>
<string name="create_ramdisk_error">не удалось создать рамдиск для установки.</string>
<string name="unpacking_image">Распаковка {1}...</string>
<string name="repacking_image">Перепаковка {1}...</string>
<string name="repack_image_hdr">Выбор образа</string>

View File

@@ -2395,7 +2395,7 @@
<condition var1="tw_multiuser_warning_accepted" op="!=" var2="1"/>
</conditions>
<actions>
<action function="set">tw_multiuser_warning_destination=restore</action>
<action function="set">tw_multiuser_warning_destination=restore_force</action>
<action function="page">multiuser_warning</action>
</actions>
</action>
@@ -3863,7 +3863,7 @@
<listbox style="advanced_listbox">
<placement x="%indent%" y="%row13a_y%" w="%content_width%" h="%listbox_advanced_height%"/>
<listitem name="{@change_twrp_folder_btn=Change TWRP folder}">
<condition var1="tw_is_encrypted" var2="0"/>
<condition var1="tw_is_decrypted" var2="1"/>
<action function="page">changeTwrpFolder</action>
</listitem>
<listitem name="{@decrypt_users=Decrypt Users}">

View File

@@ -2712,7 +2712,7 @@
<action>
<condition var1="tw_crypto_pwtype" op="!=" var2="0"/>
<actions>
<action function="page">restore_pin</action>
<action function="page">restore_keymaster</action>
</actions>
</action>
@@ -2746,7 +2746,7 @@
<condition var1="tw_multiuser_warning_accepted" op="!=" var2="1"/>
</conditions>
<actions>
<action function="set">tw_multiuser_warning_destination=restore</action>
<action function="set">tw_multiuser_warning_destination=restore_force</action>
<action function="page">multiuser_warning</action>
</actions>
</action>
@@ -4354,7 +4354,7 @@
<listbox style="advanced_listbox">
<placement x="%indent%" y="%row2_header_y%" w="%content_width%" h="%fileselector_install_height%"/>
<listitem name="{@change_twrp_folder_btn=Change TWRP folder}">
<condition var1="tw_is_encrypted" var2="0"/>
<condition var1="tw_is_decrypted" var2="1"/>
<action function="page">changeTwrpFolder</action>
</listitem>
<listitem name="{@decrypt_users=Decrypt Users}">
@@ -6207,22 +6207,22 @@
</action>
</page>
<page name="restore_pin">
<page name="restore_keymaster">
<template name="page"/>
<text style="text_m_accent">
<condition var1="tw_crypto_pwtype" var2="1"/>
<placement x="%center_x%" y="%row1_y%" placement="5"/>
<text>{@restore_with_pin1=PIN/Password is enabled}</text>
<text>{@restore_with_pin_password1=PIN/Password is enabled}</text>
</text>
<text style="text_m_accent">
<condition var1="tw_crypto_pwtype" var2="1"/>
<placement x="%center_x%" y="%row2_y%" placement="5"/>
<text>{@restore_with_pin2=PIN/Password should be disabled before restore}</text>
<text>{@restore_with_pin_password2=PIN/Password should be disabled before restore}</text>
</text>
<text style="text_l">
<condition var1="tw_crypto_pwtype" var2="1"/>
<placement x="%center_x%" y="%row3_y%" placement="5"/>
<text>{@restore_pin=Restore While PIN/Password Enabled?}</text>
<text>{@restore_pin_password=Restore While PIN/Password Enabled?}</text>
</text>
<text style="text_m_accent">
<condition var1="tw_crypto_pwtype" var2="2"/>

View File

@@ -56,7 +56,7 @@ bool ExtractPackageRecursive(ZipArchiveHandle zip, const std::string& zip_path,
}
const std::string zip_prefix(prefix_path.c_str());
int ret = StartIteration(zip, &cookie, zip_prefix, nullptr);
int ret = StartIteration(zip, &cookie, zip_prefix);
if (ret != 0) {
LOG(ERROR) << "failed to start iterating zip entries.";

View File

@@ -91,7 +91,7 @@ std::vector<string> KernelModuleLoader::Skip_Loaded_Kernel_Modules() {
std::string kernel_module_file = "/proc/modules";
if (TWFunc::read_file(kernel_module_file, loaded_modules) < 0)
LOGINFO("failed to get loaded kernel modules\n");
LOGINFO("number of modules loaded by init: %lu\n", loaded_modules.size());
LOGINFO("number of modules loaded by init: %zu\n", loaded_modules.size());
if (loaded_modules.size() == 0)
return kernel_modules;
for (auto&& module_line:loaded_modules) {

View File

@@ -146,6 +146,7 @@ LOCAL_SRC_FILES = src/cache.c \
src/superblocks/drbdproxy_datalog.c \
src/superblocks/exfat.c \
src/superblocks/ext.c \
src/superblocks/erofs.c \
src/superblocks/f2fs.c \
src/superblocks/gfs.c \
src/superblocks/hfs.c \

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2020 Gao Xiang
*
* This file may be redistributed under the terms of the
* GNU Lesser General Public License
*/
#include <stddef.h>
#include <string.h>
#include "superblocks.h"
#define EROFS_SUPER_OFFSET 1024
#define EROFS_SB_KBOFF (EROFS_SUPER_OFFSET >> 10)
#define EROFS_SUPER_MAGIC_V1 "\xe2\xe1\xf5\xe0"
#define EROFS_MAGIC_OFF 0
/* All in little-endian */
struct erofs_super_block {
uint32_t magic;
uint32_t checksum;
uint32_t feature_compat;
uint8_t blkszbits;
uint8_t reserved;
uint16_t root_nid;
uint64_t inos;
uint64_t build_time;
uint32_t build_time_nsec;
uint32_t blocks;
uint32_t meta_blkaddr;
uint32_t xattr_blkaddr;
uint8_t uuid[16];
uint8_t volume_name[16];
uint32_t feature_incompat;
uint8_t reserved2[44];
};
static int probe_erofs(blkid_probe pr, const struct blkid_idmag *mag)
{
struct erofs_super_block *sb;
sb = blkid_probe_get_sb(pr, mag, struct erofs_super_block);
if (!sb)
return errno ? -errno : BLKID_PROBE_NONE;
if (sb->volume_name[0])
blkid_probe_set_label(pr, (unsigned char *)sb->volume_name,
sizeof(sb->volume_name));
blkid_probe_set_uuid(pr, sb->uuid);
return BLKID_PROBE_OK;
}
const struct blkid_idinfo erofs_idinfo =
{
.name = "erofs",
.usage = BLKID_USAGE_FILESYSTEM,
.probefunc = probe_erofs,
.magics =
{
{
.magic = EROFS_SUPER_MAGIC_V1,
.len = 4,
.kboff = EROFS_SB_KBOFF,
.sboff = EROFS_MAGIC_OFF,
}, { NULL }
}
};

View File

@@ -155,7 +155,8 @@ static const struct blkid_idinfo *idinfos[] =
&befs_idinfo,
&nilfs2_idinfo,
&exfat_idinfo,
&f2fs_idinfo
&f2fs_idinfo,
&erofs_idinfo
};
/*

View File

@@ -74,6 +74,7 @@ extern const struct blkid_idinfo nilfs2_idinfo;
extern const struct blkid_idinfo exfat_idinfo;
extern const struct blkid_idinfo f2fs_idinfo;
extern const struct blkid_idinfo bcache_idinfo;
extern const struct blkid_idinfo erofs_idinfo;
/*
* superblock functions

View File

@@ -736,7 +736,6 @@ void TWPartition::Set_FBE_Status() {
bool TWPartition::Decrypt_FBE_DE() {
if (TWFunc::Path_Exists("/data/unencrypted/key/version")) {
DataManager::SetValue(TW_IS_FBE, 1);
DataManager::SetValue(TW_CRYPTO_PWTYPE, "0"); // Set initial value so that recovery will not be confused when using unencrypted data or failed to decrypt data
PartitionManager.Set_Crypto_State();
PartitionManager.Set_Crypto_Type("file");
LOGINFO("File Based Encryption is present\n");
@@ -1605,7 +1604,7 @@ bool TWPartition::Mount(bool Display_Error) {
if (Removable)
Update_Size(Display_Error);
if (!Symlink_Mount_Point.empty()) {
if (!Symlink_Mount_Point.empty() && Symlink_Mount_Point != "/sdcard") {
if (!Bind_Mount(false))
return false;
}

View File

@@ -110,8 +110,9 @@ extern "C" {
#endif
#ifdef AB_OTA_UPDATER
#include <hardware/hardware.h>
#include <hardware/boot_control.h>
#include <android/hardware/boot/1.0/IBootControl.h>
using android::hardware::boot::V1_0::CommandResult;
using android::hardware::boot::V1_0::IBootControl;
#endif
using android::fs_mgr::DestroyLogicalPartition;
@@ -3128,19 +3129,17 @@ void TWPartitionManager::Set_Active_Slot(const string& Slot) {
LOGINFO("Setting active slot %s\n", Slot.c_str());
#ifdef AB_OTA_UPDATER
if (!Active_Slot_Display.empty()) {
const hw_module_t *hw_module;
boot_control_module_t *module;
int ret;
ret = hw_get_module("bootctrl", &hw_module);
if (ret != 0) {
android::sp<IBootControl> module = IBootControl::getService();
if (module == nullptr) {
LOGERR("Error getting bootctrl module.\n");
} else {
module = (boot_control_module_t*) hw_module;
module->init(module);
int slot_number = 0;
uint32_t slot_number = 0;
if (Slot == "B")
slot_number = 1;
if (module->setActiveBootSlot(module, slot_number))
CommandResult result;
auto ret = module->setActiveBootSlot(slot_number, [&result]
(const CommandResult &cb_result) { result = cb_result; });
if (!ret.isOk() || !result.success)
gui_msg(Msg(msg::kError, "unable_set_boot_slot=Error changing bootloader boot slot to {1}")(Slot));
}
DataManager::SetValue("tw_active_slot", Slot); // Doing this outside of this if block may result in a seg fault because the DataManager may not be ready yet

View File

@@ -5,6 +5,7 @@ recovery_only(`
permissive adbd;
permissive fastbootd;
permissive postinstall;
permissive ueventd;
allow kernel unlabeled:file rw_file_perms;
allow kernel tmpfs:file { read };
allow kernel recovery:fd { use };

View File

@@ -63,7 +63,7 @@ extern "C" {
}
#ifdef TW_INCLUDE_LIBRESETPROP
#include <resetprop.h>
#include <resetprop.hpp>
#endif
struct selabel_handle *selinux_handle;
@@ -859,20 +859,22 @@ string TWFunc::Get_Current_Date() {
}
string TWFunc::System_Property_Get(string Prop_Name) {
return System_Property_Get(Prop_Name, PartitionManager, PartitionManager.Get_Android_Root_Path());
return System_Property_Get(Prop_Name, PartitionManager, PartitionManager.Get_Android_Root_Path(), "build.prop");
}
string TWFunc::System_Property_Get(string Prop_Name, TWPartitionManager &PartitionManager, string Mount_Point) {
string TWFunc::System_Property_Get(string Prop_Name, TWPartitionManager &PartitionManager, string Mount_Point, string prop_file_name) {
bool mount_state = PartitionManager.Is_Mounted_By_Path(Mount_Point);
std::vector<string> buildprop;
string propvalue;
if (!PartitionManager.Mount_By_Path(Mount_Point, true))
return propvalue;
string prop_file = Mount_Point + "/build.prop";
if (!TWFunc::Path_Exists(prop_file))
prop_file = Mount_Point + "/system/build.prop"; // for devices with system as a root file system (e.g. Pixel)
string prop_file = Mount_Point + "/system/" + prop_file_name;
if (!TWFunc::Path_Exists(prop_file)) {
LOGINFO("Unable to locate file: %s\n", prop_file.c_str());
return propvalue;
}
if (TWFunc::read_file(prop_file, buildprop) != 0) {
LOGINFO("Unable to open build.prop for getting '%s'.\n", Prop_Name.c_str());
LOGINFO("Unable to open %s for getting '%s'.\n", prop_file_name.c_str(), Prop_Name.c_str());
DataManager::SetValue(TW_BACKUP_NAME, Get_Current_Date());
if (!mount_state)
PartitionManager.UnMount_By_Path(Mount_Point, false);

View File

@@ -96,7 +96,7 @@ public:
static bool write_to_file(const string& fn, const std::vector<string> lines); // write vector of strings line by line with newlines
static bool Try_Decrypting_Backup(string Restore_Path, string Password); // true for success, false for failed to decrypt
static string System_Property_Get(string Prop_Name); // Returns value of Prop_Name from reading /system/build.prop
static string System_Property_Get(string Prop_Name, TWPartitionManager &PartitionManager, string Mount_Point); // Returns value of Prop_Name from reading /system/build.prop
static string System_Property_Get(string Prop_Name, TWPartitionManager &PartitionManager, string Mount_Point, string prop_file_name); // Returns value of Prop_Name from reading provided prop file
static string Get_Current_Date(void); // Returns the current date in ccyy-m-dd--hh-nn-ss format
static void Auto_Generate_Backup_Name(); // Populates TW_BACKUP_NAME with a backup name based on current date and ro.build.display.id from /system/build.prop
static void Fixup_Time_On_Boot(const string& time_paths = ""); // Fixes time on devices which need it (time_paths is a space separated list of paths to check for ats_* files)

View File

@@ -177,6 +177,11 @@ static void process_recovery_mode(twrpAdbBuFifo* adb_bu_fifo, bool skip_decrypti
} else {
stringstream override_props(EXPAND(TW_OVERRIDE_SYSTEM_PROPS));
string current_prop;
std::vector<std::string> build_prop_list = {"build.prop"};
#ifdef TW_SYSTEM_BUILD_PROP_ADDITIONAL_PATHS
std::vector<std::string> additional_build_prop_list = TWFunc::Split_String(TW_SYSTEM_BUILD_PROP_ADDITIONAL_PATHS, ";");
build_prop_list.insert(build_prop_list.end(), additional_build_prop_list.begin(), additional_build_prop_list.end());
#endif
while (getline(override_props, current_prop, ';')) {
string other_prop;
if (current_prop.find("=") != string::npos) {
@@ -187,15 +192,19 @@ static void process_recovery_mode(twrpAdbBuFifo* adb_bu_fifo, bool skip_decrypti
}
other_prop = android::base::Trim(other_prop);
current_prop = android::base::Trim(current_prop);
string sys_val = TWFunc::System_Property_Get(other_prop, PartitionManager, PartitionManager.Get_Android_Root_Path().c_str());
if (!sys_val.empty()) {
LOGINFO("Overriding %s with value: \"%s\" from system property %s\n", current_prop.c_str(), sys_val.c_str(), other_prop.c_str());
int error = TWFunc::Property_Override(current_prop, sys_val);
if (error) {
LOGERR("Failed overriding property %s, error_code: %d\n", current_prop.c_str(), error);
for (auto&& prop_file:build_prop_list) {
string sys_val = TWFunc::System_Property_Get(other_prop, PartitionManager, PartitionManager.Get_Android_Root_Path().c_str(), prop_file);
if (!sys_val.empty()) {
LOGINFO("Overriding %s with value: \"%s\" from system property %s from %s\n", current_prop.c_str(), sys_val.c_str(), other_prop.c_str(), prop_file.c_str());
int error = TWFunc::Property_Override(current_prop, sys_val);
if (error) {
LOGERR("Failed overriding property %s, error_code: %d\n", current_prop.c_str(), error);
}
break;
} else {
LOGINFO("Not overriding %s with empty value from system property %s from %s\n", current_prop.c_str(), other_prop.c_str(), prop_file.c_str());
}
} else {
LOGINFO("Not overriding %s with empty value from system property %s\n", current_prop.c_str(), other_prop.c_str());
}
}
PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), false);
@@ -204,7 +213,7 @@ static void process_recovery_mode(twrpAdbBuFifo* adb_bu_fifo, bool skip_decrypti
// Check for and run startup script if script exists
TWFunc::check_and_run_script("/system/bin/runatboot.sh", "boot");
TWFunc::check_and_run_script("/system/bin/postrecoveryboot.sh", "boot");
TWFunc::check_and_run_script("/system/bin/postrecoveryboot.sh", "recovery");
#ifdef TW_INCLUDE_INJECTTWRP
// Back up TWRP Ramdisk if needed:

View File

@@ -56,14 +56,14 @@ bool ExtractPackageRecursive(ZipArchiveHandle zip, const std::string& zip_path,
}
const ZipString zip_prefix(prefix_path.c_str());
int ret = StartIteration(zip, &cookie, &zip_prefix, nullptr);
int ret = StartIteration(zip, &cookie, &zip_prefix);
if (ret != 0) {
LOG(ERROR) << "failed to start iterating zip entries.";
return false;
}
std::unique_ptr<void, decltype(&EndIteration)> guard(cookie, EndIteration);
ZipEntry entry;
ZipEntry64 entry;
ZipString name;
int extractCount = 0;
while (Next(cookie, &entry, &name) == 0) {

View File

@@ -72,7 +72,7 @@ bool ReadMetadataFromPackage(ZipArchiveHandle zip, std::map<std::string, std::st
static constexpr const char* METADATA_PATH = "META-INF/com/android/metadata";
std::string path(METADATA_PATH);
ZipEntry entry;
ZipEntry64 entry;
if (FindEntry(zip, path, &entry) != 0) {
LOG(ERROR) << "Failed to find " << METADATA_PATH;
return false;
@@ -235,7 +235,7 @@ int SetUpAbUpdateCommands(const std::string& package, ZipArchiveHandle zip, int
// in the zip file.
static constexpr const char* AB_OTA_PAYLOAD_PROPERTIES = "payload_properties.txt";
std::string property_name(AB_OTA_PAYLOAD_PROPERTIES);
ZipEntry properties_entry;
ZipEntry64 properties_entry;
if (FindEntry(zip, property_name, &properties_entry) != 0) {
LOG(ERROR) << "Failed to find " << AB_OTA_PAYLOAD_PROPERTIES;
return INSTALL_CORRUPT;
@@ -251,7 +251,7 @@ int SetUpAbUpdateCommands(const std::string& package, ZipArchiveHandle zip, int
static constexpr const char* AB_OTA_PAYLOAD = "payload.bin";
std::string payload_name(AB_OTA_PAYLOAD);
ZipEntry payload_entry;
ZipEntry64 payload_entry;
if (FindEntry(zip, payload_name, &payload_entry) != 0) {
LOG(ERROR) << "Failed to find " << AB_OTA_PAYLOAD;
return INSTALL_CORRUPT;
@@ -273,7 +273,7 @@ int SetUpNonAbUpdateCommands(const std::string& package, ZipArchiveHandle zip, i
// In non-A/B updates we extract the update binary from the package.
std::string binary_name(UPDATE_BINARY_NAME);
ZipEntry binary_entry;
ZipEntry64 binary_entry;
if (FindEntry(zip, binary_name, &binary_entry) != 0) {
LOG(ERROR) << "Failed to find update binary " << UPDATE_BINARY_NAME;
return INSTALL_CORRUPT;
@@ -390,7 +390,7 @@ static int try_update_binary(const std::string& package, ZipArchiveHandle zip, b
is_ab = false;
std::string binary_name(UPDATE_BINARY_NAME);
ZipEntry binary_entry;
ZipEntry64 binary_entry;
if (FindEntry(zip, binary_name, &binary_entry) != 0) {
LOG(ERROR) << "Failed to find update binary " << UPDATE_BINARY_NAME;
is_ab = true;
@@ -521,7 +521,7 @@ static int try_update_binary(const std::string& package, ZipArchiveHandle zip, b
// static constexpr const char* COMPATIBILITY_ZIP_ENTRY = "compatibility.zip";
// ZipString compatibility_entry_name(COMPATIBILITY_ZIP_ENTRY);
// ZipEntry compatibility_entry;
// ZipEntry64 compatibility_entry;
// if (FindEntry(package_zip, compatibility_entry_name, &compatibility_entry) != 0) {
// LOG(INFO) << "Package doesn't contain " << COMPATIBILITY_ZIP_ENTRY << " entry";
// return true;
@@ -555,7 +555,7 @@ static int try_update_binary(const std::string& package, ZipArchiveHandle zip, b
// std::unique_ptr<void, decltype(&EndIteration)> guard(cookie, EndIteration);
// std::vector<std::string> compatibility_info;
// ZipEntry info_entry;
// ZipEntry64 info_entry;
// ZipString info_name;
// while (Next(cookie, &info_entry, &info_name) == 0) {
// std::string content(info_entry.uncompressed_length, '\0');

View File

@@ -55,7 +55,7 @@ static int parse_build_number(std::string str) {
bool read_metadata_from_package(ZipArchiveHandle zip, std::string* meta_data) {
std::string binary_name(METADATA_PATH);
ZipEntry binary_entry;
ZipEntry64 binary_entry;
if (FindEntry(zip, binary_name, &binary_entry) == 0) {
long size = binary_entry.uncompressed_length;
if (size <= 0)
@@ -66,7 +66,6 @@ bool read_metadata_from_package(ZipArchiveHandle zip, std::string* meta_data) {
size);
if (ret != 0) {
printf("Failed to read metadata in update package.\n");
CloseArchive(zip);
return false;
}
return true;
@@ -202,7 +201,7 @@ abupdate_binary_command(const char* path, int retry_count __unused,
// the RAW payload offset in the zip file.
// if (!Zip->EntryExists(AB_OTA_PAYLOAD_PROPERTIES)) {
std::string binary_name(AB_OTA_PAYLOAD_PROPERTIES);
ZipEntry binary_entry;
ZipEntry64 binary_entry;
if (FindEntry(Zip, binary_name, &binary_entry) != 0) {
printf("Can't find %s\n", AB_OTA_PAYLOAD_PROPERTIES);
return INSTALL_CORRUPT;
@@ -213,12 +212,11 @@ abupdate_binary_command(const char* path, int retry_count __unused,
binary_entry.uncompressed_length);
if (extract_ret != 0) {
printf("Can't extract %s\n", AB_OTA_PAYLOAD_PROPERTIES);
CloseArchive(Zip);
return false;
}
std::string ab_ota_payload(AB_OTA_PAYLOAD);
ZipEntry ab_ota_payload_entry;
ZipEntry64 ab_ota_payload_entry;
if (FindEntry(Zip, ab_ota_payload, &ab_ota_payload_entry) != 0) {
printf("Can't find %s\n", AB_OTA_PAYLOAD);
return INSTALL_CORRUPT;
@@ -279,7 +277,7 @@ bool verify_package_compatibility(ZipArchiveHandle zw) {
static constexpr const char* COMPATIBILITY_ZIP_ENTRY = "compatibility.zip";
std::string compatibility_entry_name(COMPATIBILITY_ZIP_ENTRY);
ZipEntry compatibility_entry;
ZipEntry64 compatibility_entry;
if (FindEntry(zw, compatibility_entry_name, &compatibility_entry) != 0) {
printf("Package doesn't contain %s entry\n", COMPATIBILITY_ZIP_ENTRY);
return true;
@@ -304,7 +302,7 @@ bool verify_package_compatibility(ZipArchiveHandle zw) {
// Iterate all the entries inside COMPATIBILITY_ZIP_ENTRY and read the contents.
void* cookie;
ret = StartIteration(zip_handle, &cookie, nullptr, nullptr);
ret = StartIteration(zip_handle, &cookie);
if (ret != 0) {
printf("Failed to start iterating zip entries: %s\n", ErrorCodeString(ret));
CloseArchive(zip_handle);
@@ -313,7 +311,7 @@ bool verify_package_compatibility(ZipArchiveHandle zw) {
std::unique_ptr<void, decltype(&EndIteration)> guard(cookie, EndIteration);
std::vector<std::string> compatibility_info;
ZipEntry info_entry;
ZipEntry64 info_entry;
std::string info_name;
while (Next(cookie, &info_entry, &info_name) == 0) {
std::string content(info_entry.uncompressed_length, '\0');

View File

@@ -71,13 +71,11 @@ enum zip_type {
static int Install_Theme(const char* path, ZipArchiveHandle Zip) {
#ifdef TW_OEM_BUILD // We don't do custom themes in OEM builds
CloseArchive(Zip);
return INSTALL_CORRUPT;
#else
std::string binary_name("ui.xml");
ZipEntry binary_entry;
ZipEntry64 binary_entry;
if (FindEntry(Zip, binary_name, &binary_entry) != 0) {
CloseArchive(Zip);
return INSTALL_CORRUPT;
}
if (!PartitionManager.Mount_Settings_Storage(true))
@@ -108,7 +106,7 @@ static int Prepare_Update_Binary(ZipArchiveHandle Zip) {
std::vector<string>::iterator arch;
std::string base_name = UPDATE_BINARY_NAME;
base_name += "-";
ZipEntry binary_entry;
ZipEntry64 binary_entry;
std::string update_binary_string(UPDATE_BINARY_NAME);
if (FindEntry(Zip, update_binary_string, &binary_entry) != 0) {
for (arch = split.begin(); arch != split.end(); arch++) {
@@ -129,14 +127,13 @@ static int Prepare_Update_Binary(ZipArchiveHandle Zip) {
}
int32_t err = ExtractEntryToFile(Zip, &binary_entry, fd);
if (err != 0) {
CloseArchive(Zip);
LOGERR("Could not extract '%s'\n", UPDATE_BINARY_NAME);
return INSTALL_ERROR;
}
// If exists, extract file_contexts from the zip file
std::string file_contexts("file_contexts");
ZipEntry file_contexts_entry;
ZipEntry64 file_contexts_entry;
if (FindEntry(Zip, file_contexts, &file_contexts_entry) != 0) {
LOGINFO("Zip does not contain SELinux file_contexts file in its root.\n");
} else {
@@ -148,7 +145,6 @@ static int Prepare_Update_Binary(ZipArchiveHandle Zip) {
return INSTALL_ERROR;
}
if (ExtractEntryToFile(Zip, &file_contexts_entry, fd)) {
CloseArchive(Zip);
LOGERR("Could not extract '%s'\n", output_filename.c_str());
return INSTALL_ERROR;
}
@@ -313,13 +309,12 @@ int TWinstall_zip(const char* path, int* wipe_cache, bool check_for_digest) {
time(&start);
std::string update_binary_name(UPDATE_BINARY_NAME);
ZipEntry update_binary_entry;
ZipEntry64 update_binary_entry;
if (FindEntry(Zip, update_binary_name, &update_binary_entry) == 0) {
LOGINFO("Update binary zip\n");
// Additionally verify the compatibility of the package.
if (!verify_package_compatibility(Zip)) {
gui_err("zip_compatible_err=Zip Treble compatibility error!");
CloseArchive(Zip);
ret_val = INSTALL_CORRUPT;
} else {
ret_val = Prepare_Update_Binary(Zip);
@@ -328,7 +323,7 @@ int TWinstall_zip(const char* path, int* wipe_cache, bool check_for_digest) {
}
} else {
std::string ab_binary_name(AB_OTA);
ZipEntry ab_binary_entry;
ZipEntry64 ab_binary_entry;
if (FindEntry(Zip, ab_binary_name, &ab_binary_entry) == 0) {
LOGINFO("AB zip\n");
gui_msg(Msg(msg::kHighlight, "flash_ab_inactive=Flashing A/B zip to inactive slot: {1}")(PartitionManager.Get_Active_Slot_Display()=="A"?"B":"A"));
@@ -358,12 +353,11 @@ int TWinstall_zip(const char* path, int* wipe_cache, bool check_for_digest) {
}
} else {
std::string binary_name("ui.xml");
ZipEntry binary_entry;
ZipEntry64 binary_entry;
if (FindEntry(Zip, binary_name, &binary_entry) != 0) {
LOGINFO("TWRP theme zip\n");
ret_val = Install_Theme(path, Zip);
} else {
CloseArchive(Zip);
ret_val = INSTALL_CORRUPT;
}
}

View File

@@ -328,7 +328,7 @@ static std::vector<Certificate> IterateZipEntriesAndSearchForKeys(const ZipArchi
std::vector<Certificate> result;
std::string_view name;
ZipEntry entry;
ZipEntry64 entry;
while ((iter_status = Next(cookie, &entry, &name)) == 0) {
std::vector<uint8_t> pem_content(entry.uncompressed_length);
if (int32_t extract_status =