repack: move sbin to /system ramdisk and update repacking
for android-10

This will support updating the ramdisk to a different
compression format and co-exist with magisk.

We are also cleaning up and removing non android-10
api makefile actions.

We are also moving twrp repacking to its own class. We
check the new ramdisk format and if it's different
we have magisk compress using the new ramdisk format.

Change-Id: I770030aae7797e75817178b2f0fccd9f39dc23af
diff --git a/crypto/ext4crypt/Android.mk b/crypto/ext4crypt/Android.mk
index 955bd3b..8b1372b 100755
--- a/crypto/ext4crypt/Android.mk
+++ b/crypto/ext4crypt/Android.mk
@@ -75,10 +75,9 @@
 LOCAL_MODULE := twrpfbe
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
+LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/
 LOCAL_SRC_FILES := main.cpp
 LOCAL_SHARED_LIBRARIES := libe4crypt
-#LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker64
 
 include $(BUILD_EXECUTABLE)
 
@@ -86,10 +85,10 @@
 LOCAL_MODULE := e4policyget
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
+LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/
 LOCAL_SRC_FILES := e4policyget.cpp
 LOCAL_SHARED_LIBRARIES := libe4crypt
-LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker64
+LOCAL_LDFLAGS += -Wl,-dynamic-linker,/system/bin/linker64
 
 include $(BUILD_EXECUTABLE)
 
@@ -97,7 +96,7 @@
 LOCAL_MODULE := keystore_auth
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
+LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/
 LOCAL_SRC_FILES := keystore_auth.cpp
 LOCAL_SHARED_LIBRARIES := libc libkeystore_binder libutils libbinder liblog
 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 28; echo $$?),0)
@@ -105,7 +104,7 @@
     LOCAL_CFLAGS += -DUSE_SECURITY_NAMESPACE
     LOCAL_SHARED_LIBRARIES += libkeystore_aidl
 endif
-LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker64
+LOCAL_LDFLAGS += -Wl,-dynamic-linker,/system/bin/linker64
 
 include $(BUILD_EXECUTABLE)
 
diff --git a/crypto/ext4crypt/Decrypt.cpp b/crypto/ext4crypt/Decrypt.cpp
index dcd390f..85d14ea 100755
--- a/crypto/ext4crypt/Decrypt.cpp
+++ b/crypto/ext4crypt/Decrypt.cpp
@@ -659,7 +659,7 @@
 			if (auth_wait_count == 0 || access("/auth_error", F_OK) == 0) {
 				printf("error during keymaster_auth service\n");
 				/* If you are getting this error, make sure that you have the keymaster_auth service defined in your init scripts, preferrably in init.recovery.{ro.hardware}.rc
-				 * service keystore_auth /sbin/keystore_auth
+				 * service keystore_auth /system/bin/keystore_auth
 				 *     disabled
 				 *     oneshot
 				 *     user system
@@ -804,7 +804,7 @@
 			if (auth_wait_count == 0 || access("/auth_error", F_OK) == 0) {
 				printf("error during keymaster_auth service\n");
 				/* If you are getting this error, make sure that you have the keymaster_auth service defined in your init scripts, preferrably in init.recovery.{ro.hardware}.rc
-				 * service keystore_auth /sbin/keystore_auth
+				 * service keystore_auth /system/bin/keystore_auth
 				 *     disabled
 				 *     oneshot
 				 *     user system
diff --git a/crypto/fde/Android.mk b/crypto/fde/Android.mk
index 4fd8b0b..f78697f 100755
--- a/crypto/fde/Android.mk
+++ b/crypto/fde/Android.mk
@@ -65,7 +65,7 @@
 LOCAL_MODULE := twrpdec
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
+LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/
 LOCAL_SRC_FILES := main.cpp cryptfs.cpp
 LOCAL_SHARED_LIBRARIES := libcrypto libhardware libcutils libc libstdc++
 LOCAL_C_INCLUDES := external/openssl/include $(commands_recovery_local_path)/crypto/scrypt/lib/crypto
diff --git a/crypto/fscrypt/Android.mk b/crypto/fscrypt/Android.mk
index 8000d5e..0fa36c8 100755
--- a/crypto/fscrypt/Android.mk
+++ b/crypto/fscrypt/Android.mk
@@ -49,7 +49,7 @@
 LOCAL_MODULE := twrpfbe
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
+LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/bin
 LOCAL_SRC_FILES := main.cpp
 LOCAL_SHARED_LIBRARIES := libtwrpfscrypt
 
@@ -59,10 +59,9 @@
 LOCAL_MODULE := fscryptpolicyget
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
+LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/bin
 LOCAL_SRC_FILES := fscryptpolicyget.cpp
 LOCAL_SHARED_LIBRARIES := libtwrpfscrypt
-LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker64
 
 include $(BUILD_EXECUTABLE)
 
@@ -70,12 +69,11 @@
 LOCAL_MODULE := keystore_auth
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
+LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/bin
 LOCAL_SRC_FILES := keystore_auth.cpp
 LOCAL_SHARED_LIBRARIES := libc libkeystore_binder libutils libbinder liblog
 LOCAL_CFLAGS += -DUSE_SECURITY_NAMESPACE
 LOCAL_SHARED_LIBRARIES += libkeystore_aidl
-LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker64
 
 include $(BUILD_EXECUTABLE)
 
diff --git a/crypto/fscrypt/Decrypt.cpp b/crypto/fscrypt/Decrypt.cpp
index b1a43c9..bd3d067 100755
--- a/crypto/fscrypt/Decrypt.cpp
+++ b/crypto/fscrypt/Decrypt.cpp
@@ -629,7 +629,7 @@
 			if (auth_wait_count == 0 || access("/auth_error", F_OK) == 0) {
 				printf("error during keymaster_auth service\n");
 				/* If you are getting this error, make sure that you have the keymaster_auth service defined in your init scripts, preferrably in init.recovery.{ro.hardware}.rc
-				 * service keystore_auth /sbin/keystore_auth
+				 * service keystore_auth /system/bin/keystore_auth
 				 *     disabled
 				 *     oneshot
 				 *     user system
diff --git a/crypto/fscrypt/FsCrypt.cpp b/crypto/fscrypt/FsCrypt.cpp
index 397f131..5d68fce 100755
--- a/crypto/fscrypt/FsCrypt.cpp
+++ b/crypto/fscrypt/FsCrypt.cpp
@@ -89,7 +89,7 @@
 
 const std::string user_key_dir = std::string() + DATA_MNT_POINT + "/misc/vold/user_keys";
 const std::string user_key_temp = user_key_dir + "/temp";
-const std::string prepare_subdirs_path = "/sbin/vold_prepare_subdirs";
+const std::string prepare_subdirs_path = "/system/bin/vold_prepare_subdirs";
 
 const std::string systemwide_volume_key_dir =
     std::string() + DATA_MNT_POINT + "/misc/vold/volume_keys";
diff --git a/crypto/vold_decrypt/Android.mk b/crypto/vold_decrypt/Android.mk
old mode 100644
new mode 100755
index 25d6ab0..a36abf4
--- a/crypto/vold_decrypt/Android.mk
+++ b/crypto/vold_decrypt/Android.mk
@@ -128,7 +128,7 @@
             LOCAL_SRC_FILES := vdc_pie.cpp
             LOCAL_MODULE_TAGS := optional
             LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
-            LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
+            LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/
             LOCAL_CLANG := true
             LOCAL_TIDY := true
             LOCAL_TIDY_FLAGS := -warnings-as-errors=clang-analyzer-security*,cert-*
@@ -141,12 +141,12 @@
             endif
             ifneq ($(TARGET_ARCH), arm64)
                 ifneq ($(TARGET_ARCH), x86_64)
-                    LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker
+                    LOCAL_LDFLAGS += -Wl,-dynamic-linker,/system/bin/linker
                 else
-                    LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker64
+                    LOCAL_LDFLAGS += -Wl,-dynamic-linker,/system/bin/linker64
                 endif
             else
-                LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker64
+                LOCAL_LDFLAGS += -Wl,-dynamic-linker,/system/bin/linker64
             endif
 
             include $(BUILD_EXECUTABLE)
diff --git a/crypto/vold_decrypt/vold_decrypt.cpp b/crypto/vold_decrypt/vold_decrypt.cpp
index 078cd5f..4a76405 100755
--- a/crypto/vold_decrypt/vold_decrypt.cpp
+++ b/crypto/vold_decrypt/vold_decrypt.cpp
@@ -81,7 +81,7 @@
 #ifdef TW_CRYPTO_SYSTEM_VOLD_DEBUG
 
 #ifndef VD_STRACE_BIN
-#define VD_STRACE_BIN "/sbin/strace"
+#define VD_STRACE_BIN "/system/bin/strace"
 #endif
 
 bool has_strace = false;
@@ -399,7 +399,7 @@
 	LOGINFO("%d file(s) symlinked.\n", (int)FirmwareFiles.size());
 }
 
-// Android 8.0 fs_mgr checks for "/sbin/recovery", in which case it will
+// Android 8.0 fs_mgr checks for "/system/bin/recovery", in which case it will
 // use /etc/recovery.fstab -> symlink it temporarily. Reference:
 // https://android.googlesource.com/platform/system/core/+/android-8.0.0_r17/fs_mgr/fs_mgr_fstab.cpp#693
 bool Symlink_Recovery_Fstab(void) {
@@ -716,8 +716,8 @@
 
 					if (Service_Exists(services[j].Service_Name))
 						services[j].TWRP_Service_Name = services[j].Service_Name;
-					else if (Service_Exists("sbin" + services[j].Service_Name))
-						services[j].TWRP_Service_Name = "sbin" + services[j].Service_Name;
+					else if (Service_Exists("system/bin" + services[j].Service_Name))
+						services[j].TWRP_Service_Name = "system/bin" + services[j].Service_Name;
 					else
 						services[j].TWRP_Service_Name.clear();
 
@@ -995,7 +995,7 @@
 	}
 
 	// getpwtype and checkpw commands are removed from Pie vdc, using modified vdc_pie
-	const char *cmd[] = { "/sbin/vdc_pie", "cryptfs" };
+	const char *cmd[] = { "/system/bin/vdc_pie", "cryptfs" };
 	if (sdkver < 28)
 		cmd[0] = "/system/bin/vdc";
 	const char *env[] = { "LD_LIBRARY_PATH=/system/lib64:/system/lib", NULL };