Merge changes from topic "revert-1191937-art_apex_available-DWXQGTKMAR"

* changes:
  Revert submission 1191937-art_apex_available
  Revert submission 1191937-art_apex_available
diff --git a/CleanSpec.mk b/CleanSpec.mk
index 42bcb3c..673856c 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -702,6 +702,17 @@
 # The core image variant has been renamed to ""
 $(call add-clean-step, find $(SOONG_OUT_DIR)/.intermediates -type d -name "android_*_core*" -print0 | xargs -0 rm -rf)
 
+# Remove CtsShim apks from system partition, since the have been moved inside
+# the cts shim apex. Also remove the cts shim apex prebuilt since it has been
+# removed in flattened apexs configurations.
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/priv-app/CtsShimPrivPrebuilt)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/app/CtsShimPrebuilt)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/apex/com.android.apex.cts.shim.apex)
+
+# Remove vendor and recovery variants, the directory name has changed.
+$(call add-clean-step, find $(SOONG_OUT_DIR)/.intermediates -type d -name "android_*_recovery*" -print0 | xargs -0 rm -rf)
+$(call add-clean-step, find $(SOONG_OUT_DIR)/.intermediates -type d -name "android_*_vendor*" -print0 | xargs -0 rm -rf)
+
 # ************************************************
 # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
 # ************************************************
diff --git a/core/board_config.mk b/core/board_config.mk
index 0e3c52f..00ac0be 100644
--- a/core/board_config.mk
+++ b/core/board_config.mk
@@ -255,6 +255,19 @@
 TARGET_CPU_ABI_LIST_32_BIT := $(subst $(space),$(comma),$(strip $(TARGET_CPU_ABI_LIST_32_BIT)))
 TARGET_CPU_ABI_LIST_64_BIT := $(subst $(space),$(comma),$(strip $(TARGET_CPU_ABI_LIST_64_BIT)))
 
+# Check if config about image building is valid or not.
+define check_image_config
+  $(eval _uc_name := $(call to-upper,$(1))) \
+  $(eval _lc_name := $(call to-lower,$(1))) \
+  $(if $(filter $(_lc_name),$(TARGET_COPY_OUT_$(_uc_name))), \
+    $(if $(BOARD_USES_$(_uc_name)IMAGE),, \
+      $(error If TARGET_COPY_OUT_$(_uc_name) is '$(_lc_name)', either BOARD_PREBUILT_$(_uc_name)IMAGE or BOARD_$(_uc_name)IMAGE_FILE_SYSTEM_TYPE must be set)), \
+  $(if $(BOARD_USES_$(_uc_name)IMAGE), \
+    $(error TARGET_COPY_OUT_$(_uc_name) must be set to '$(_lc_name)' to use a $(_lc_name) image))) \
+  $(eval _uc_name :=) \
+  $(eval _lc_name :=)
+endef
+
 ###########################################
 # Now we can substitute with the real value of TARGET_COPY_OUT_RAMDISK
 ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
@@ -399,6 +412,8 @@
 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   BOARD_USES_VENDORIMAGE := true
 endif
+# TODO(b/137169253): For now, some AOSP targets build with prebuilt vendor image.
+# But target's BOARD_PREBUILT_VENDORIMAGE is not filled.
 ifeq ($(TARGET_COPY_OUT_VENDOR),vendor)
   BOARD_USES_VENDORIMAGE := true
 else ifdef BOARD_USES_VENDORIMAGE
@@ -438,11 +453,7 @@
 ifdef BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE
   BOARD_USES_PRODUCTIMAGE := true
 endif
-ifeq ($(TARGET_COPY_OUT_PRODUCT),product)
-  BOARD_USES_PRODUCTIMAGE := true
-else ifdef BOARD_USES_PRODUCTIMAGE
-  $(error TARGET_COPY_OUT_PRODUCT must be set to 'product' to use a product image)
-endif
+$(call check_image_config,product)
 .KATI_READONLY := BOARD_USES_PRODUCTIMAGE
 
 BUILDING_PRODUCT_IMAGE :=
@@ -482,11 +493,7 @@
 ifdef BOARD_SYSTEM_EXTIMAGE_FILE_SYSTEM_TYPE
   BOARD_USES_SYSTEM_EXTIMAGE := true
 endif
-ifeq ($(TARGET_COPY_OUT_SYSTEM_EXT),system_ext)
-  BOARD_USES_SYSTEM_EXTIMAGE := true
-else ifdef BOARD_USES_SYSTEM_EXTIMAGE
-  $(error TARGET_COPY_OUT_SYSTEM_EXT must be set to 'system_ext' to use a system_ext image)
-endif
+$(call check_image_config,system_ext)
 .KATI_READONLY := BOARD_USES_SYSTEM_EXTIMAGE
 
 BUILDING_SYSTEM_EXT_IMAGE :=
@@ -521,11 +528,7 @@
 ifdef BOARD_ODMIMAGE_FILE_SYSTEM_TYPE
   BOARD_USES_ODMIMAGE := true
 endif
-ifeq ($(TARGET_COPY_OUT_ODM),odm)
-  BOARD_USES_ODMIMAGE := true
-else ifdef BOARD_USES_ODMIMAGE
-  $(error TARGET_COPY_OUT_ODM must be set to 'odm' to use an odm image)
-endif
+$(call check_image_config,odm)
 
 BUILDING_ODM_IMAGE :=
 ifeq ($(PRODUCT_BUILD_ODM_IMAGE),)
diff --git a/core/main.mk b/core/main.mk
index 6935efa..5a1693f 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -1159,6 +1159,7 @@
   libc_malloc_debug.so \
   libc_malloc_hooks.so \
   libdl.so \
+  libdl_android.so \
   libm.so \
 
 # Conscrypt APEX libraries
diff --git a/target/product/base_system.mk b/target/product/base_system.mk
index 95e6fb0..d15e262 100644
--- a/target/product/base_system.mk
+++ b/target/product/base_system.mk
@@ -48,7 +48,7 @@
     charger \
     cmd \
     com.android.adbd \
-    com.android.apex.cts.shim.v1_prebuilt \
+    com.android.apex.cts.shim.v1 \
     com.android.conscrypt \
     com.android.cronet \
     com.android.i18n \
@@ -64,8 +64,6 @@
     ContactsProvider \
     content \
     crash_dump \
-    CtsShimPrebuilt \
-    CtsShimPrivPrebuilt \
     debuggerd\
     device_config \
     dmctl \
diff --git a/target/product/base_vendor.mk b/target/product/base_vendor.mk
index 134ff31..1657e71 100644
--- a/target/product/base_vendor.mk
+++ b/target/product/base_vendor.mk
@@ -23,7 +23,6 @@
     init_second_stage.recovery \
     ld.config.recovery.txt \
     linker.recovery \
-    linkerconfig.recovery \
     otacerts.recovery \
     recovery \
     shell_and_utilities_recovery \
diff --git a/target/product/updatable_apex.mk b/target/product/updatable_apex.mk
index bdaf545..e5a647c 100644
--- a/target/product/updatable_apex.mk
+++ b/target/product/updatable_apex.mk
@@ -17,6 +17,7 @@
 # Inherit this when the target needs to support updating APEXes
 
 ifneq ($(OVERRIDE_TARGET_FLATTEN_APEX),true)
+  PRODUCT_PACKAGES += com.android.apex.cts.shim.v1_prebuilt
   PRODUCT_PROPERTY_OVERRIDES := ro.apex.updatable=true
   TARGET_FLATTEN_APEX := false
 endif
diff --git a/tools/releasetools/build_super_image.py b/tools/releasetools/build_super_image.py
index 6c4d6cb..fb31415 100755
--- a/tools/releasetools/build_super_image.py
+++ b/tools/releasetools/build_super_image.py
@@ -76,6 +76,8 @@
          "--super-name", info_dict["super_metadata_device"]]
 
   ab_update = info_dict.get("ab_update") == "true"
+  virtual_ab = info_dict.get("virtual_ab") == "true"
+  virtual_ab_retrofit = info_dict.get("virtual_ab_retrofit") == "true"
   retrofit = info_dict.get("dynamic_partition_retrofit") == "true"
   block_devices = shlex.split(info_dict.get("super_block_devices", "").strip())
   groups = shlex.split(info_dict.get("super_partition_groups", "").strip())
@@ -89,6 +91,8 @@
 
   if ab_update and retrofit:
     cmd.append("--auto-slot-suffixing")
+  if virtual_ab and not virtual_ab_retrofit:
+    cmd.append("--virtual-ab")
 
   for device in block_devices:
     size = info_dict["super_{}_device_size".format(device)]