Honor `PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD` in Runtime APEX selection.

Include the Release Runtime APEX module on user builds and the "Debug"
Runtime APEX module on userdebug and eng builds, unless
`PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD` is set. If so, and if this
variable is `true`, include the Release (smaller) Runtime APEX module;
if it is `false`, include the "Debug" (larger) Runtime APEX module.

This logic is similar to the one used for module `art-runtime`
regarding debug variants (also located in art/Android).

Test: make systemimage with user target.
Test: make systemimage with userdebug/eng target.
Bug: 113373927
Change-Id: Ib7f567a0d9910c4e60631565310369f383045076
diff --git a/Android.mk b/Android.mk
index d639220..3388b35 100644
--- a/Android.mk
+++ b/Android.mk
@@ -329,10 +329,46 @@
 # Android Runtime APEX.
 
 include $(CLEAR_VARS)
+
+# The Android Runtime APEX comes in two flavors:
+# - the release module (`com.android.runtime.release`), containing
+#   only "release" artifacts;
+# - the debug module (`com.android.runtime.debug`), containing both
+#   "release" and "debug" artifacts, as well as additional tools.
+#
+# The Android Runtime APEX module (`com.android.runtime`) is an
+# "alias" for one of the previous modules. By default, "user" build
+# variants contain the release module, while "userdebug" and "eng"
+# build variant contain the debug module. However, if
+# `PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD` is defined, it overrides
+# the previous logic:
+# - if `PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD` is set to `false`, the
+#   build will include the release module (whatever the build
+#   variant);
+# - if `PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD` is set to `true`, the
+#   build will include the debug module (whatever the build variant).
+
+art_target_include_debug_build := $(PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD)
+ifneq (false,$(art_target_include_debug_build))
+  ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
+    art_target_include_debug_build := true
+  endif
+endif
+ifeq (true,$(art_target_include_debug_build))
+  # Module with both release and debug variants, as well as
+  # additional tools.
+  TARGET_RUNTIME_APEX := com.android.runtime.debug
+else
+  # Release module (without debug variants nor tools).
+  TARGET_RUNTIME_APEX := com.android.runtime.release
+endif
+
 LOCAL_MODULE := com.android.runtime
-# TODO: Select the debug module (`com.android.runtime.debug`) for
-# userdebug and eng products.
-LOCAL_REQUIRED_MODULES := com.android.runtime.release
+LOCAL_REQUIRED_MODULES := $(TARGET_RUNTIME_APEX)
+
+# Clear locally used variable.
+art_target_include_debug_build :=
+
 include $(BUILD_PHONY_PACKAGE)