TWRP_REQUIRED_MODULES: add more criteria to exclude packages

Only include hwservicemanager if CRYPTO flag is set and
only include servicemanager if FBE is included.

Only include health-hal if device uses dynamic partitions

Change-Id: I056d0246e406dc9f00bda65247455741ef986a37
diff --git a/etc/Android.mk b/etc/Android.mk
index f07a2c6..26d86d6 100755
--- a/etc/Android.mk
+++ b/etc/Android.mk
@@ -58,33 +58,6 @@
 LOCAL_SRC_FILES := init.recovery.ldconfig.rc
 include $(BUILD_PREBUILT)
 
-include $(CLEAR_VARS)
-LOCAL_MODULE := hwservicemanager.rc
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/etc/init
-
-LOCAL_SRC_FILES := init/$(LOCAL_MODULE)
-include $(BUILD_PREBUILT)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := servicemanager.rc
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/etc/init
-
-LOCAL_SRC_FILES := init/$(LOCAL_MODULE)
-include $(BUILD_PREBUILT)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := android.hardware.health@2.0-service.rc
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/etc/init
-
-LOCAL_SRC_FILES := init/$(LOCAL_MODULE)
-include $(BUILD_PREBUILT)
-
 ifeq ($(AB_OTA_UPDATER),true)
 	include $(CLEAR_VARS)
 	LOCAL_MODULE := android.hardware.boot@1.0-service.rc
@@ -96,8 +69,28 @@
 	include $(BUILD_PREBUILT)
 endif
 
+ifeq ($(PRODUCT_USE_DYNAMIC_PARTITIONS),true)
+	include $(CLEAR_VARS)
+	LOCAL_MODULE := android.hardware.health@2.0-service.rc
+	LOCAL_MODULE_TAGS := optional
+	LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
+	LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/etc/init
+
+	LOCAL_SRC_FILES := init/$(LOCAL_MODULE)
+	include $(BUILD_PREBUILT)
+endif
+
 ifneq ($(TW_INCLUDE_CRYPTO),)
 	include $(CLEAR_VARS)
+	LOCAL_MODULE := hwservicemanager.rc
+	LOCAL_MODULE_TAGS := optional
+	LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
+	LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/etc/init
+
+	LOCAL_SRC_FILES := init/$(LOCAL_MODULE)
+	include $(BUILD_PREBUILT)
+
+	include $(CLEAR_VARS)
 	LOCAL_MODULE := vndservicemanager.rc
 	LOCAL_MODULE_TAGS := optional
 	LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
@@ -105,6 +98,17 @@
 
 	LOCAL_SRC_FILES := init/$(LOCAL_MODULE)
 	include $(BUILD_PREBUILT)
+
+	ifneq ($(TW_INCLUDE_CRYPTO_FBE),)
+		include $(CLEAR_VARS)
+		LOCAL_MODULE := servicemanager.rc
+		LOCAL_MODULE_TAGS := optional
+		LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
+		LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/etc/init
+
+		LOCAL_SRC_FILES := init/$(LOCAL_MODULE)
+		include $(BUILD_PREBUILT)
+	endif
 endif
 
 ifeq ($(TWRP_INCLUDE_LOGCAT), true)