Skip to content
This repository was archived by the owner on Nov 23, 2022. It is now read-only.

Commit

Permalink
Make it backwards compatible with 4.4
Browse files Browse the repository at this point in the history
Change-Id: I668604cddc8e8afbf78709f3f872bea4e9f4aa06
  • Loading branch information
Dees-Troy committed Aug 25, 2016
1 parent 34ae483 commit f117962
Show file tree
Hide file tree
Showing 25 changed files with 741 additions and 61 deletions.
76 changes: 55 additions & 21 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,18 @@ LOCAL_SHARED_LIBRARIES :=

LOCAL_STATIC_LIBRARIES += libguitwrp
LOCAL_SHARED_LIBRARIES += libaosprecovery libz libc libcutils libstdc++ libtar libblkid libminuitwrp libminadbd libmtdutils libminzip libtwadbbu
LOCAL_SHARED_LIBRARIES += libcrecovery libbase libcrypto
LOCAL_SHARED_LIBRARIES += libcrecovery

ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
LOCAL_SHARED_LIBRARIES += libstlport
LOCAL_SHARED_LIBRARIES += libstlport libmincrypttwrp
LOCAL_C_INCLUDES += $(LOCAL_PATH)/libmincrypt/includes
LOCAL_CFLAGS += -DUSE_OLD_VERIFIER
else
LOCAL_SHARED_LIBRARIES += libc++
LOCAL_SHARED_LIBRARIES += libc++ libcrypto
endif

ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 24; echo $$?),0)
LOCAL_SHARED_LIBRARIES += libbase
endif

ifneq ($(wildcard system/core/libsparse/Android.mk),)
Expand Down Expand Up @@ -340,13 +346,15 @@ LOCAL_ADDITIONAL_DEPENDENCIES := \
mke2fs.conf \
pigz \
teamwin \
toolbox_symlinks \
twrp \
unpigz_symlink \
fsck.fat \
fatlabel \
mkfs.fat \
permissive.sh \
simg2img_twrp
simg2img_twrp \
init.recovery.service.rc

ifneq ($(TARGET_ARCH), arm64)
ifneq ($(TARGET_ARCH), x86_64)
Expand Down Expand Up @@ -503,23 +511,27 @@ endif # !TW_USE_TOOLBOX

# recovery-persist (system partition dynamic executable run after /data mounts)
# ===============================
include $(CLEAR_VARS)
LOCAL_SRC_FILES := recovery-persist.cpp
LOCAL_MODULE := recovery-persist
LOCAL_SHARED_LIBRARIES := liblog libbase
LOCAL_CFLAGS := -Werror
LOCAL_INIT_RC := recovery-persist.rc
include $(BUILD_EXECUTABLE)
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 24; echo $$?),0)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := recovery-persist.cpp
LOCAL_MODULE := recovery-persist
LOCAL_SHARED_LIBRARIES := liblog libbase
LOCAL_CFLAGS := -Werror
LOCAL_INIT_RC := recovery-persist.rc
include $(BUILD_EXECUTABLE)
endif

# recovery-refresh (system partition dynamic executable run at init)
# ===============================
include $(CLEAR_VARS)
LOCAL_SRC_FILES := recovery-refresh.cpp
LOCAL_MODULE := recovery-refresh
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_CFLAGS := -Werror
LOCAL_INIT_RC := recovery-refresh.rc
include $(BUILD_EXECUTABLE)
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 24; echo $$?),0)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := recovery-refresh.cpp
LOCAL_MODULE := recovery-refresh
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_CFLAGS := -Werror
LOCAL_INIT_RC := recovery-refresh.rc
include $(BUILD_EXECUTABLE)
endif

# shared libfusesideload
# ===============================
Expand All @@ -531,7 +543,14 @@ LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE

LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libfusesideload
LOCAL_SHARED_LIBRARIES := libcutils libc libcrypto
LOCAL_SHARED_LIBRARIES := libcutils libc
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 22; echo $$?),0)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/libmincrypt/includes
LOCAL_SHARED_LIBRARIES += libmincrypttwrp
LOCAL_CFLAGS += -DUSE_MINCRYPT
else
LOCAL_SHARED_LIBRARIES += libcrypto
endif
include $(BUILD_SHARED_LIBRARY)

# shared libaosprecovery for Apache code
Expand All @@ -540,8 +559,18 @@ include $(CLEAR_VARS)

LOCAL_MODULE := libaosprecovery
LOCAL_MODULE_TAGS := eng optional
LOCAL_SRC_FILES := adb_install.cpp asn1_decoder.cpp bootloader.cpp legacy_property_service.c verifier.cpp set_metadata.c tw_atomic.cpp
LOCAL_SHARED_LIBRARIES += libc liblog libcutils libmtdutils libfusesideload libselinux libcrypto
LOCAL_CFLAGS := -std=gnu++0x
LOCAL_SRC_FILES := adb_install.cpp asn1_decoder.cpp bootloader.cpp legacy_property_service.cpp set_metadata.cpp tw_atomic.cpp
LOCAL_SHARED_LIBRARIES += libc liblog libcutils libmtdutils libfusesideload libselinux
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
LOCAL_SHARED_LIBRARIES += libstdc++ libstlport libmincrypttwrp
LOCAL_C_INCLUDES := bionic external/stlport/stlport $(LOCAL_PATH)/libmincrypt/includes
LOCAL_SRC_FILES += oldverifier/verifier.cpp
LOCAL_CFLAGS += -DUSE_OLD_VERIFIER
else
LOCAL_SHARED_LIBRARIES += libc++ libcrypto
LOCAL_SRC_FILES += verifier.cpp
endif

ifneq ($(BOARD_RECOVERY_BLDRMSG_OFFSET),)
LOCAL_CFLAGS += -DBOARD_RECOVERY_BLDRMSG_OFFSET=$(BOARD_RECOVERY_BLDRMSG_OFFSET)
Expand Down Expand Up @@ -598,6 +627,7 @@ include $(commands_recovery_local_path)/injecttwrp/Android.mk \
$(commands_recovery_local_path)/libblkid/Android.mk \
$(commands_recovery_local_path)/minuitwrp/Android.mk \
$(commands_recovery_local_path)/openaes/Android.mk \
$(commands_recovery_local_path)/toolbox/Android.mk \
$(commands_recovery_local_path)/twrpTarMain/Android.mk \
$(commands_recovery_local_path)/mtp/Android.mk \
$(commands_recovery_local_path)/minzip/Android.mk \
Expand All @@ -608,6 +638,10 @@ include $(commands_recovery_local_path)/injecttwrp/Android.mk \
$(commands_recovery_local_path)/adbbu/Android.mk \
$(commands_recovery_local_path)/libpixelflinger/Android.mk

ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
include $(commands_recovery_local_path)/libmincrypt/Android.mk
endif

ifeq ($(TW_INCLUDE_CRYPTO), true)
include $(commands_recovery_local_path)/crypto/lollipop/Android.mk
include $(commands_recovery_local_path)/crypto/scrypt/Android.mk
Expand Down
4 changes: 4 additions & 0 deletions adb_install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
#include "adb_install.h"
#include "minadbd/fuse_adb_provider.h"
#include "fuse_sideload.h"
#ifdef USE_OLD_VERIFIER
#include "oldverifier/verifier.h"
#else
#include "verifier.h"
#endif

static RecoveryUI* ui = NULL;

Expand Down
19 changes: 11 additions & 8 deletions bootloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extern "C" {
#include "common.h"
#include "mtdutils/mtdutils.h"
//#include "roots.h"
#include "unique_fd.h"
//#include "unique_fd.h"

// fake Volume struct that allows us to use the AOSP code easily
struct Volume
Expand Down Expand Up @@ -232,33 +232,36 @@ static int get_bootloader_message_block(bootloader_message* out,
static int set_bootloader_message_block(const bootloader_message* in,
const Volume* v) {
wait_for_device(v->blk_device);
unique_fd fd(open(v->blk_device, O_WRONLY | O_SYNC));
if (fd.get() == -1) {
int fd = open(v->blk_device, O_WRONLY | O_SYNC);
if (fd == -1) {
LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno));
return -1;
}

#ifdef BOARD_RECOVERY_BLDRMSG_OFFSET
lseek(fd.get(), BOARD_RECOVERY_BLDRMSG_OFFSET, SEEK_SET);
lseek(fd, BOARD_RECOVERY_BLDRMSG_OFFSET, SEEK_SET);
#endif

size_t written = 0;
const uint8_t* start = reinterpret_cast<const uint8_t*>(in);
size_t total = sizeof(*in);
while (written < total) {
ssize_t wrote = TEMP_FAILURE_RETRY(write(fd.get(), start + written, total - written));
ssize_t wrote = TEMP_FAILURE_RETRY(write(fd, start + written, total - written));
if (wrote == -1) {
LOGE("failed to write %" PRId64 " bytes: %s\n",
static_cast<off64_t>(written), strerror(errno));
LOGE("failed to write some bytes: %s\n",
strerror(errno));
close(fd);
return -1;
}
written += wrote;
}

if (fsync(fd.get()) == -1) {
if (fsync(fd) == -1) {
LOGE("failed to fsync \"%s\": %s\n", v->blk_device, strerror(errno));
close(fd);
return -1;
}
close(fd);
return 0;
}

Expand Down
20 changes: 20 additions & 0 deletions etc/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ include $(BUILD_PREBUILT)

endif

ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 22; echo $$?),0)
include $(CLEAR_VARS)
LOCAL_MODULE := init.recovery.service.rc
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)

LOCAL_SRC_FILES := init.recovery.servicenew.rc
include $(BUILD_PREBUILT)
else
include $(CLEAR_VARS)
LOCAL_MODULE := init.recovery.service.rc
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)

LOCAL_SRC_FILES := init.recovery.serviceold.rc
include $(BUILD_PREBUILT)
endif

ifeq ($(TWRP_INCLUDE_LOGCAT), true)
ifeq ($(TARGET_USES_LOGD), true)

Expand Down
4 changes: 1 addition & 3 deletions etc/init.rc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import /init.recovery.logd.rc
import /init.recovery.usb.rc
import /init.recovery.service.rc
import /init.recovery.${ro.hardware}.rc

on early-init
Expand Down Expand Up @@ -109,9 +110,6 @@ service healthd /sbin/healthd -r
critical
seclabel u:r:healthd:s0

service recovery /sbin/recovery
seclabel u:r:recovery:s0

service adbd /sbin/adbd --root_seclabel=u:r:su:s0 --device_banner=recovery
disabled
socket adbd stream 660 system system
Expand Down
5 changes: 5 additions & 0 deletions etc/init.recovery.servicenew.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
on boot

# For starting recovery on 5.0 and newer
service recovery /sbin/recovery
seclabel u:r:recovery:s0
4 changes: 4 additions & 0 deletions etc/init.recovery.serviceold.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
on boot

# For starting recovery on 4.4 and older
service recovery /sbin/recovery
15 changes: 15 additions & 0 deletions fuse_sideload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@
#include <sys/uio.h>
#include <unistd.h>

#ifdef USE_MINCRYPT
#include "mincrypt/sha256.h"
#define SHA256_DIGEST_LENGTH SHA256_DIGEST_SIZE
#else
#include <openssl/sha.h>
#endif

#include "fuse_sideload.h"

Expand Down Expand Up @@ -275,7 +280,11 @@ static int fetch_block(struct fuse_data* fd, uint32_t block) {
// - Otherwise, return -EINVAL for the read.

uint8_t hash[SHA256_DIGEST_LENGTH];
#ifdef USE_MINCRYPT
SHA256_hash(fd->block_data, fd->block_size, hash);
#else
SHA256(fd->block_data, fd->block_size, hash);
#endif
uint8_t* blockhash = fd->hashes + block * SHA256_DIGEST_LENGTH;
if (memcmp(hash, blockhash, SHA256_DIGEST_LENGTH) == 0) {
return 0;
Expand Down Expand Up @@ -527,3 +536,9 @@ int run_fuse_sideload(struct provider_vtab* vtab, void* cookie,

return result;
}

extern "C" int run_old_fuse_sideload(struct provider_vtab* vtab, void* cookie,
uint64_t file_size, uint32_t block_size)
{
return run_fuse_sideload(vtab, cookie, file_size, block_size);
}
9 changes: 9 additions & 0 deletions fuse_sideload.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,13 @@ struct provider_vtab {
int run_fuse_sideload(struct provider_vtab* vtab, void* cookie,
uint64_t file_size, uint32_t block_size);

#ifdef __cplusplus
extern "C" {
#endif
int run_old_fuse_sideload(struct provider_vtab* vtab, void* cookie,
uint64_t file_size, uint32_t block_size);
#ifdef __cplusplus
}
#endif

#endif
2 changes: 1 addition & 1 deletion gui/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ extern "C" {
#include "../twinstall.h"
#include "cutils/properties.h"
#include "../adb_install.h"
#include "../set_metadata.h"
};
#include "../set_metadata.h"
#include "../minuitwrp/minui.h"

#include "rapidxml.hpp"
Expand Down
8 changes: 6 additions & 2 deletions legacy_property_service.c → legacy_property_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
//#include <sys/atomics.h>
#include "legacy_property_service.h"

#ifndef INT32_MAX
#define INT32_MAX (2147483647)
#endif

static int persistent_properties_loaded = 0;
static int property_area_inited = 0;

Expand Down Expand Up @@ -108,9 +112,9 @@ static int init_property_area(void)

fcntl(pa_workspace.fd, F_SETFD, FD_CLOEXEC);

pa_info_array = (void*) (((char*) pa_workspace.data) + PA_INFO_START);
pa_info_array = (prop_info*) (((char*) pa_workspace.data) + PA_INFO_START);

pa = pa_workspace.data;
pa = (prop_area*)(pa_workspace.data);
memset(pa, 0, PA_SIZE);
pa->magic = PROP_AREA_MAGIC;
pa->version = PROP_AREA_VERSION;
Expand Down
2 changes: 1 addition & 1 deletion minadbd.old/fuse_adb_provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ int run_adb_fuse(int sfd, uint64_t file_size, uint32_t block_size) {
vtab.read_block = read_block_adb;
vtab.close = close_adb;

return run_fuse_sideload(&vtab, &ad, file_size, block_size);
return run_old_fuse_sideload(&vtab, &ad, file_size, block_size);
}
Loading

0 comments on commit f117962

Please sign in to comment.