Update to 7.0

Change-Id: I621cc47352f7ac552d9602485825ae3a6f9ae516
diff --git a/Android.mk b/Android.mk
index bb22a3e..1e2141d 100644
--- a/Android.mk
+++ b/Android.mk
@@ -68,14 +68,17 @@
 
 #LOCAL_FORCE_STATIC_EXECUTABLE := true
 
+#ifeq ($(TARGET_USERIMAGES_USE_F2FS),true)
 #ifeq ($(HOST_OS),linux)
 #LOCAL_REQUIRED_MODULES := mkfs.f2fs
 #endif
+#endif
 
 RECOVERY_API_VERSION := 3
 RECOVERY_FSTAB_VERSION := 2
 LOCAL_CFLAGS += -DRECOVERY_API_VERSION=$(RECOVERY_API_VERSION)
 LOCAL_CFLAGS += -Wno-unused-parameter
+LOCAL_CLANG := true
 
 #LOCAL_STATIC_LIBRARIES := \
 #    libext4_utils_static \
@@ -103,7 +106,7 @@
     system/core/libsparse \
     external/zlib
 
-LOCAL_C_INCLUDES += bionic external/openssl/include $(LOCAL_PATH)/libmincrypt/includes
+LOCAL_C_INCLUDES += bionic external/openssl/include
 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
     LOCAL_C_INCLUDES += external/stlport/stlport
 endif
@@ -112,8 +115,8 @@
 LOCAL_SHARED_LIBRARIES :=
 
 LOCAL_STATIC_LIBRARIES += libguitwrp
-LOCAL_SHARED_LIBRARIES += libz libc libcutils libstdc++ libtar libblkid libminuitwrp libminadbd libmtdutils libminzip libaosprecovery libtwadbbu
-LOCAL_SHARED_LIBRARIES += libcrecovery
+LOCAL_SHARED_LIBRARIES += libaosprecovery libz libc libcutils libstdc++ libtar libblkid libminuitwrp libminadbd libmtdutils libminzip libtwadbbu
+LOCAL_SHARED_LIBRARIES += libcrecovery libbase libcrypto
 
 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
     LOCAL_SHARED_LIBRARIES += libstlport
@@ -132,6 +135,7 @@
     TW_EXCLUDE_SUPERSU := true
     TW_EXCLUDE_MTP := true
 endif
+
 ifeq ($(TARGET_USERIMAGES_USE_EXT4), true)
     LOCAL_CFLAGS += -DUSE_EXT4
     LOCAL_C_INCLUDES += system/extras/ext4_utils
@@ -336,7 +340,6 @@
     mke2fs.conf \
     pigz \
     teamwin \
-    toolbox_symlinks \
     twrp \
     unpigz_symlink \
     fsck.fat \
@@ -381,7 +384,7 @@
     endif
 endif
 ifneq ($(TW_EXCLUDE_ENCRYPTED_BACKUPS), true)
-    LOCAL_ADDITIONAL_DEPENDENCIES += openaes ../openaes/LICENSE
+    LOCAL_ADDITIONAL_DEPENDENCIES += openaes openaes_license
 endif
 ifeq ($(TW_INCLUDE_DUMLOCK), true)
     LOCAL_ADDITIONAL_DEPENDENCIES += \
@@ -448,6 +451,10 @@
 endif
 endif
 
+ifeq ($(BOARD_CACHEIMAGE_PARTITION_SIZE),)
+LOCAL_REQUIRED_MODULES := recovery-persist recovery-refresh
+endif
+
 include $(BUILD_EXECUTABLE)
 
 ifneq ($(TW_USE_TOOLBOX), true)
@@ -494,56 +501,47 @@
 RECOVERY_BUSYBOX_SYMLINKS :=
 endif # !TW_USE_TOOLBOX
 
-# All the APIs for testing
+# recovery-persist (system partition dynamic executable run after /data mounts)
+# ===============================
 include $(CLEAR_VARS)
-LOCAL_MODULE := libverifier
-LOCAL_MODULE_TAGS := tests
-LOCAL_SRC_FILES := \
-    asn1_decoder.cpp
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := fuse_sideload.c
-
-LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter
-LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE := libfusesideload
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/libmincrypt/includes
-LOCAL_SHARED_LIBRARIES := libcutils libc libmincrypttwrp
-include $(BUILD_SHARED_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := verifier_test
-LOCAL_FORCE_STATIC_EXECUTABLE := true
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/libmincrypt/includes
-
-LOCAL_CFLAGS += -DNO_RECOVERY_MOUNT
-LOCAL_CFLAGS += -Wno-unused-parameter
-
-LOCAL_SRC_FILES := \
-    verifier_test.cpp \
-    asn1_decoder.cpp \
-    verifier.cpp \
-    ui.cpp
-LOCAL_STATIC_LIBRARIES := \
-    libmincrypttwrp \
-    libminui \
-    libminzip \
-    libcutils \
-    libstdc++ \
-    libc
+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)
 
+# 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)
+
+# shared libfusesideload
+# ===============================
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := fuse_sideload.cpp
+LOCAL_CLANG := true
+LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter
+LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
+
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE := libfusesideload
+LOCAL_SHARED_LIBRARIES := libcutils libc libcrypto
+include $(BUILD_SHARED_LIBRARY)
+
+# shared libaosprecovery for Apache code
+# ===============================
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := libaosprecovery
 LOCAL_MODULE_TAGS := eng optional
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/libmincrypt/includes
 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 libmincrypttwrp libselinux
+LOCAL_SHARED_LIBRARIES += libc liblog libcutils libmtdutils libfusesideload libselinux libcrypto
 
 ifneq ($(BOARD_RECOVERY_BLDRMSG_OFFSET),)
     LOCAL_CFLAGS += -DBOARD_RECOVERY_BLDRMSG_OFFSET=$(BOARD_RECOVERY_BLDRMSG_OFFSET)
@@ -551,11 +549,25 @@
 
 include $(BUILD_SHARED_LIBRARY)
 
+# All the APIs for testing
+include $(CLEAR_VARS)
+LOCAL_CLANG := true
+LOCAL_MODULE := libverifier
+LOCAL_MODULE_TAGS := tests
+LOCAL_SRC_FILES := \
+    asn1_decoder.cpp \
+    verifier.cpp \
+    ui.cpp
+LOCAL_STATIC_LIBRARIES := libcrypto
+include $(BUILD_STATIC_LIBRARY)
+
 commands_recovery_local_path := $(LOCAL_PATH)
 include $(LOCAL_PATH)/tests/Android.mk \
     $(LOCAL_PATH)/tools/Android.mk \
     $(LOCAL_PATH)/edify/Android.mk \
+    $(LOCAL_PATH)/otafault/Android.mk \
     $(LOCAL_PATH)/updater/Android.mk \
+    $(LOCAL_PATH)/update_verifier/Android.mk \
     $(LOCAL_PATH)/applypatch/Android.mk
 
 ifeq ($(wildcard system/core/uncrypt/Android.mk),)
@@ -586,8 +598,6 @@
     $(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)/libmincrypt/Android.mk \
     $(commands_recovery_local_path)/twrpTarMain/Android.mk \
     $(commands_recovery_local_path)/mtp/Android.mk \
     $(commands_recovery_local_path)/minzip/Android.mk \