Retry: Enable mainline prebuilts on tm-dev branch.

Except for santizer and framework Java coverage tests as they require
specialized prebuilts built from a matching configuration and we do not
provide them.

And products that use dex2oat(d)s as they are not available as a
prebuilt.

And products that cross compile to arm64 and linux_bionic on the host
as prebuilts for that are not available.

And atv/tv products as they break when building against prebuilts.

Bug: 230478310
Bug: 223592962
Test: presubmit
Merged-In: I3ed091156c4b39dad6eaf578144ac3d070025988
Merged-In: I9731400acfade95b3eab8f2d99fddb4cf856aa91
Merged-In: I43fa4ae8db51012eaf78d70fe65e9e0a3f7eca16
Change-Id: Ib01ba9e2e3c2225c88d52b6811edf04aff02c81e
diff --git a/core/android_soong_config_vars.mk b/core/android_soong_config_vars.mk
index 329847f..a6116f2 100644
--- a/core/android_soong_config_vars.mk
+++ b/core/android_soong_config_vars.mk
@@ -39,7 +39,45 @@
 # Default behavior for the tree wrt building modules or using prebuilts. This
 # can always be overridden by setting the environment variable
 # MODULE_BUILD_FROM_SOURCE.
-BRANCH_DEFAULT_MODULE_BUILD_FROM_SOURCE := true
+BRANCH_DEFAULT_MODULE_BUILD_FROM_SOURCE := false
+
+ifneq ($(SANITIZE_TARGET)$(EMMA_INSTRUMENT_FRAMEWORK),)
+  # Always use sources when building the framework with Java coverage or
+  # sanitized builds as they both require purpose built prebuilts which we do
+  # not provide.
+  BRANCH_DEFAULT_MODULE_BUILD_FROM_SOURCE := true
+endif
+
+# TODO(b/172063604): Remove once products no longer use dex2oat(d)s.
+# If the product uses dex2oats and/or dex2oatds then build from sources as
+# ART does not currently provide prebuilts of those tools.
+ifneq (,$(filter dex2oats dex2oatds,$(PRODUCT_HOST_PACKAGES)))
+  BRANCH_DEFAULT_MODULE_BUILD_FROM_SOURCE := true
+endif
+
+# ART does not provide linux_bionic variants needed for products that
+# set HOST_CROSS_OS=linux_bionic.
+ifeq (linux_bionic,${HOST_CROSS_OS})
+  BRANCH_DEFAULT_MODULE_BUILD_FROM_SOURCE := true
+endif
+
+# ART does not provide host side arm64 variants needed for products that
+# set HOST_CROSS_ARCH=arm64.
+ifeq (arm64,${HOST_CROSS_ARCH})
+  BRANCH_DEFAULT_MODULE_BUILD_FROM_SOURCE := true
+endif
+
+# TV based devices do not seem to work with prebuilts, so build from source
+# for now and fix in a follow up.
+ifneq (,$(filter tv,$(subst $(comma),$(space),${PRODUCT_CHARACTERISTICS})))
+  BRANCH_DEFAULT_MODULE_BUILD_FROM_SOURCE := true
+endif
+
+# ATV based devices do not seem to work with prebuilts, so build from source
+# for now and fix in a follow up.
+ifneq (,${PRODUCT_IS_ATV})
+  BRANCH_DEFAULT_MODULE_BUILD_FROM_SOURCE := true
+endif
 
 ifneq (,$(MODULE_BUILD_FROM_SOURCE))
   # Keep an explicit setting.