Merge "Don't add empty entry to PATH."
diff --git a/core/Makefile b/core/Makefile
index e94939b..e71ba25 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -70,6 +70,27 @@
 	@cp -f $< $@
 endif
 
+ndk_doxygen_out := $(OUT_NDK_DOCS)
+ndk_headers := $(SOONG_OUT_DIR)/ndk/sysroot/usr/include
+ndk_docs_src_dir := frameworks/native/docs
+ndk_doxyfile := $(ndk_docs_src_dir)/Doxyfile
+ifneq ($(wildcard $(ndk_docs_src_dir)),)
+ndk_docs_srcs := $(addprefix $(ndk_docs_src_dir)/,\
+    $(call find-files-in-subdirs,$(ndk_docs_src_dir),"*",.))
+$(ndk_doxygen_out)/index.html: $(ndk_docs_srcs) $(SOONG_OUT_DIR)/ndk.timestamp
+	@mkdir -p $(ndk_doxygen_out)
+	@echo "Generating NDK docs to $(ndk_doxygen_out)"
+	@( cat $(ndk_doxyfile); \
+	    echo "INPUT=$(ndk_headers)"; \
+	    echo "HTML_OUTPUT=$(ndk_doxygen_out)" \
+	) | doxygen -
+
+# Note: Not a part of the docs target because we don't have doxygen available.
+# You can run this target locally if you have doxygen installed.
+ndk-docs: $(ndk_doxygen_out)/index.html
+.PHONY: ndk-docs
+endif
+
 # -----------------------------------------------------------------
 # property_overrides_split_enabled
 property_overrides_split_enabled :=
@@ -167,9 +188,7 @@
 # The string used to uniquely identify the combined build and product; used by the OTA server.
 ifeq (,$(strip $(BUILD_FINGERPRINT)))
   ifneq ($(filter eng.%,$(BUILD_NUMBER)),)
-    # Trim down BUILD_FINGERPRINT: the default BUILD_NUMBER makes it easily exceed
-    # the Android system property length limit (PROPERTY_VALUE_MAX=92).
-    BF_BUILD_NUMBER := $(shell echo $${USER:0:6})$(shell $(DATE) +%m%d%H%M)
+    BF_BUILD_NUMBER := $(USER)$(shell $(DATE) +%m%d%H%M)
   else
     BF_BUILD_NUMBER := $(BUILD_NUMBER)
   endif
@@ -997,6 +1016,7 @@
 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity_key=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY)" >> $(1))
 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity_signer_cmd=$(notdir $(VERITY_SIGNER))" >> $(1))
 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY_FEC),$(hide) echo "verity_fec=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY_FEC)" >> $(1))
+$(if $(filter eng, $(TARGET_BUILD_VARIANT)),$(hide) echo "verity_disable=true" >> $(1))
 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_VERITY_PARTITION),$(hide) echo "system_verity_block_device=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_VERITY_PARTITION)" >> $(1))
 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_VERITY_PARTITION),$(hide) echo "vendor_verity_block_device=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_VERITY_PARTITION)" >> $(1))
 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT)" >> $(1))
@@ -1302,12 +1322,12 @@
 .PHONY: recoveryimage
 recoveryimage: $(INSTALLED_RECOVERYIMAGE_TARGET) $(RECOVERY_RESOURCE_ZIP)
 
-ifeq ($(BOARD_NAND_PAGE_SIZE),)
-BOARD_NAND_PAGE_SIZE := 2048
+ifneq ($(BOARD_NAND_PAGE_SIZE),)
+$(error MTD device is no longer supported and thus BOARD_NAND_PAGE_SIZE is deprecated.)
 endif
 
-ifeq ($(BOARD_NAND_SPARE_SIZE),)
-BOARD_NAND_SPARE_SIZE := 64
+ifneq ($(BOARD_NAND_SPARE_SIZE),)
+$(error MTD device is no longer supported and thus BOARD_NAND_SPARE_SIZE is deprecated.)
 endif
 
 # -----------------------------------------------------------------
@@ -2624,7 +2644,7 @@
 name := $(name)-symbols-$(FILE_NAME_TAG)
 
 SYMBOLS_ZIP := $(PRODUCT_OUT)/$(name).zip
-# For apps_only build we'll establish the dependency later in build/core/main.mk.
+# For apps_only build we'll establish the dependency later in build/make/core/main.mk.
 ifndef TARGET_BUILD_APPS
 $(SYMBOLS_ZIP): $(INSTALLED_SYSTEMIMAGE) \
 		$(INSTALLED_BOOTIMAGE_TARGET) \
@@ -2690,7 +2710,7 @@
 # An archive of classes for use in generating code-coverage reports
 # These are the uninstrumented versions of any classes that were
 # to be instrumented.
-# Any dependencies are set up later in build/core/main.mk.
+# Any dependencies are set up later in build/make/core/main.mk.
 
 JACOCO_REPORT_CLASSES_ALL := $(PRODUCT_OUT)/jacoco-report-classes-all.jar
 $(JACOCO_REPORT_CLASSES_ALL) :
@@ -2712,7 +2732,7 @@
 #
 ifdef TARGET_BUILD_APPS
 PROGUARD_DICT_ZIP := $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-dict-$(FILE_NAME_TAG).zip
-# the dependency will be set up later in build/core/main.mk.
+# the dependency will be set up later in build/make/core/main.mk.
 $(PROGUARD_DICT_ZIP) :
 	@echo "Packaging Proguard obfuscation dictionary files."
 	$(hide) dict_files=`find $(TARGET_OUT_COMMON_INTERMEDIATES)/APPS -name proguard_dictionary`; \
diff --git a/core/base_rules.mk b/core/base_rules.mk
index e7da560..a178b55 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -622,7 +622,7 @@
 
 # Add this module name to the tag list of each specified tag.
 $(foreach tag,$(my_module_tags),\
-    $(eval ALL_MODULE_NAME_TAGS.$(tag) += $(my_register_name)))
+    $(eval ALL_MODULE_NAME_TAGS.$(tag) := $$(ALL_MODULE_NAME_TAGS.$(tag)) $(my_register_name)))
 
 ###########################################################
 ## umbrella targets used to verify builds
diff --git a/core/binary.mk b/core/binary.mk
index 45c2477..3e31d9a 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -1415,9 +1415,22 @@
 my_warn_types :=
 my_allowed_types := native:ndk
 else ifdef LOCAL_USE_VNDK
-my_link_type := native:vendor
-my_warn_types :=
-my_allowed_types := native:vendor
+    _name := $(patsubst %.vendor,%,$(LOCAL_MODULE))
+    ifneq ($(filter $(_name),$(VNDK_CORE_LIBRARIES) $(VNDK_SAMEPROCESS_LIBRARIES) $(LLNDK_LIBRARIES)),)
+        ifeq ($(filter $(_name),$(VNDK_PRIVATE_LIBRARIES)),)
+            my_link_type := native:vndk
+        else
+            my_link_type := native:vndk_private
+        endif
+        my_warn_types :=
+        my_allowed_types := native:vndk native:vndk_private
+    else
+        # Modules installed to /vendor cannot directly depend on modules marked
+        # with vendor_available: false
+        my_link_type := native:vendor
+        my_warn_types :=
+        my_allowed_types := native:vendor native:vndk
+    endif
 else
 my_link_type := native:platform
 my_warn_types :=
diff --git a/core/cleanbuild.mk b/core/cleanbuild.mk
index 64c5ae1..5576785 100644
--- a/core/cleanbuild.mk
+++ b/core/cleanbuild.mk
@@ -21,7 +21,7 @@
 TOP := .
 TOPDIR :=
 
-BUILD_SYSTEM := $(TOPDIR)build/core
+BUILD_SYSTEM := $(TOPDIR)build/make/core
 
 # Set up various standard variables based on configuration
 # and host information.
@@ -48,7 +48,7 @@
 #
 # $(1): shell command to run
 # $(2): indicate to not use makefile path as part of step id if not empty.
-#       $(2) should only be used in build/core/cleanspec.mk: just for compatibility.
+#       $(2) should only be used in build/make/core/cleanspec.mk: just for compatibility.
 define _add-clean-step
   $(if $(strip $(INTERNAL_CLEAN_BUILD_VERSION)),, \
       $(error INTERNAL_CLEAN_BUILD_VERSION not set))
@@ -67,7 +67,7 @@
   $(eval _acs_makefile_prefix :=)
 endef
 define add-clean-step
-$(eval # for build/core/cleanspec.mk, dont use makefile path as part of step id) \
+$(eval # for build/make/core/cleanspec.mk, dont use makefile path as part of step id) \
 $(if $(filter %/cleanspec.mk,$(lastword $(MAKEFILE_LIST))),\
     $(eval $(call _add-clean-step,$(1),true)),\
     $(eval $(call _add-clean-step,$(1))))
diff --git a/core/clear_vars.mk b/core/clear_vars.mk
index c38059c..b5bb963 100644
--- a/core/clear_vars.mk
+++ b/core/clear_vars.mk
@@ -120,6 +120,7 @@
 LOCAL_JAR_PROCESSOR:=
 LOCAL_JAR_PROCESSOR_ARGS:=
 LOCAL_JAVACFLAGS:=
+LOCAL_JAVAC_SHARD_SIZE:=
 LOCAL_JAVA_LANGUAGE_VERSION:=
 LOCAL_JAVA_LAYERS_FILE:=
 LOCAL_JAVA_LIBRARIES:=
diff --git a/core/combo/arch/x86/atom.mk b/core/combo/arch/x86/atom.mk
index d313a9a..43a170c 100644
--- a/core/combo/arch/x86/atom.mk
+++ b/core/combo/arch/x86/atom.mk
@@ -2,7 +2,7 @@
 # 'x86-atom' arch variant. This is an extension of the 'x86' base variant
 # that adds Atom-specific features.
 #
-# See build/core/combo/arch/x86/x86.mk for differences.
+# See build/make/core/combo/arch/x86/x86.mk for differences.
 #
 ARCH_X86_HAVE_SSSE3 := true
 ARCH_X86_HAVE_MOVBE := true
diff --git a/core/combo/arch/x86/silvermont.mk b/core/combo/arch/x86/silvermont.mk
index 70b718c..cba1079 100644
--- a/core/combo/arch/x86/silvermont.mk
+++ b/core/combo/arch/x86/silvermont.mk
@@ -1,7 +1,7 @@
 # This file contains feature macro definitions specific to the
 # silvermont arch variant.
 #
-# See build/core/combo/arch/x86/x86-atom.mk for differences.
+# See build/make/core/combo/arch/x86/x86-atom.mk for differences.
 #
 
 ARCH_X86_HAVE_SSSE3  := true
diff --git a/core/combo/arch/x86_64/silvermont.mk b/core/combo/arch/x86_64/silvermont.mk
index 70b718c..cba1079 100644
--- a/core/combo/arch/x86_64/silvermont.mk
+++ b/core/combo/arch/x86_64/silvermont.mk
@@ -1,7 +1,7 @@
 # This file contains feature macro definitions specific to the
 # silvermont arch variant.
 #
-# See build/core/combo/arch/x86/x86-atom.mk for differences.
+# See build/make/core/combo/arch/x86/x86-atom.mk for differences.
 #
 
 ARCH_X86_HAVE_SSSE3  := true
diff --git a/core/combo/javac.mk b/core/combo/javac.mk
index 41ebc57..122d8bc 100644
--- a/core/combo/javac.mk
+++ b/core/combo/javac.mk
@@ -16,12 +16,17 @@
   endif
 endif
 
-ifeq ($(OVERRIDE_ANDROID_JAVA_HOME),)
-ANDROID_JAVA_HOME := prebuilts/jdk/jdk8/$(HOST_PREBUILT_TAG)
-else
-# Use this build toolchain instead of the bundled one.
-ANDROID_JAVA_HOME := $(OVERRIDE_ANDROID_JAVA_HOME)
+ifneq ($(OVERRIDE_ANDROID_JAVA_HOME),)
+  # Use this build toolchain instead of the bundled one.
+  ANDROID_JAVA_HOME := $(OVERRIDE_ANDROID_JAVA_HOME)
+else # !OVERRIDE_ANDROID_JAVA_HOME
+  ifneq ($(EXPERIMENTAL_USE_OPENJDK9),)
+    ANDROID_JAVA_HOME := prebuilts/jdk/jdk9/$(HOST_PREBUILT_TAG)
+  else
+    ANDROID_JAVA_HOME := prebuilts/jdk/jdk8/$(HOST_PREBUILT_TAG)
+  endif
 endif
+
 ANDROID_JAVA_TOOLCHAIN := $(ANDROID_JAVA_HOME)/bin
 export JAVA_HOME := $(abspath $(ANDROID_JAVA_HOME))
 
diff --git a/core/config.mk b/core/config.mk
index 34e9681..61f7743 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -304,7 +304,7 @@
 include $(BUILD_SYSTEM)/combo/select.mk
 endif
 
-ifndef KATI
+ifeq ($(CALLED_FROM_SETUP),true)
 include $(BUILD_SYSTEM)/ccache.mk
 include $(BUILD_SYSTEM)/goma.mk
 
@@ -524,12 +524,6 @@
   SIGNAPK_JNI_LIBRARY_PATH := $(HOST_OUT_SHARED_LIBRARIES)
   ZIPALIGN := $(HOST_OUT_EXECUTABLES)/zipalign
 
-  ifeq ($(USE_D8),true)
-    DX := $(HOST_OUT_EXECUTABLES)/d8
-  else
-    DX := $(HOST_OUT_EXECUTABLES)/dx
-  endif
-
 else # TARGET_BUILD_APPS || TARGET_BUILD_PDK
   AIDL := $(prebuilt_sdk_tools_bin)/aidl
   AAPT := $(prebuilt_sdk_tools_bin)/aapt
@@ -540,15 +534,8 @@
   SIGNAPK_JNI_LIBRARY_PATH := $(prebuilt_sdk_tools)/$(HOST_OS)/lib64
   ZIPALIGN := $(prebuilt_sdk_tools_bin)/zipalign
 
-  ifeq ($(USE_D8),true)
-    DX := $(prebuilt_build_tools_wrappers)/d8
-  else
-    DX := $(prebuilt_build_tools_wrappers)/dx
-  endif
 endif # TARGET_BUILD_APPS || TARGET_BUILD_PDK
 
-DX_COMMAND := $(DX) -JXms16M -JXmx2048M
-
 ifeq (,$(TARGET_BUILD_APPS))
   # Use RenderScript prebuilts for unbundled builds but not PDK builds
   LLVM_RS_CC := $(HOST_OUT_EXECUTABLES)/llvm-rs-cc
@@ -644,7 +631,6 @@
 FAT16COPY := build/tools/fat16copy.py
 CHECK_LINK_TYPE := build/tools/check_link_type.py
 
-TURBINE := $(HOST_OUT_JAVA_LIBRARIES)/turbine$(COMMON_JAVA_PACKAGE_SUFFIX)
 PROGUARD := external/proguard/bin/proguard.sh
 JAVATAGS := build/tools/java-event-log-tags.py
 MERGETAGS := build/tools/merge-event-log-tags.py
@@ -798,6 +784,9 @@
 # We don't have prebuilt test_current SDK yet.
 TARGET_AVAILABLE_SDK_VERSIONS := test_current $(TARGET_AVAILABLE_SDK_VERSIONS)
 
+TARGET_SDK_VERSIONS_WITHOUT_JAVA_18_SUPPORT := $(call numbers_less_than,24,$(TARGET_AVAILABLE_SDK_VERSIONS))
+TARGET_SDK_VERSIONS_WITHOUT_JAVA_19_SUPPORT := $(call numbers_less_than,27,$(TARGET_AVAILABLE_SDK_VERSIONS))
+
 INTERNAL_PLATFORM_API_FILE := $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/public_api.txt
 INTERNAL_PLATFORM_REMOVED_API_FILE := $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/removed.txt
 INTERNAL_PLATFORM_SYSTEM_API_FILE := $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/system-api.txt
@@ -894,7 +883,7 @@
     vbmetaimage-nodeps \
     product-graph dump-products
 
-ifndef KATI
+ifeq ($(CALLED_FROM_SETUP),true)
 include $(BUILD_SYSTEM)/ninja_config.mk
 include $(BUILD_SYSTEM)/soong_config.mk
 endif
diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk
index e01fbbf..f5b45db 100644
--- a/core/config_sanitizers.mk
+++ b/core/config_sanitizers.mk
@@ -137,6 +137,8 @@
     else
         $(error $(LOCAL_PATH): $(LOCAL_MODULE): TSAN cannot be used for 32-bit modules.)
     endif
+  else
+    my_shared_libraries += $(TSAN_RUNTIME_LIBRARY)
   endif
 endif
 
diff --git a/core/definitions.mk b/core/definitions.mk
index 550634b..99d048b 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -2205,6 +2205,17 @@
     @<(find $(1) -type f | sort | $(JAR_ARGS) $(1); echo "-C $(EMPTY_DIRECTORY) .")
 endef
 
+# append additional Java sources(resources/Proto sources, and etc) to $(1).
+define fetch-additional-java-source
+$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
+    find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' -and -not -name '.*' >> $(1); \
+fi
+$(if $(PRIVATE_HAS_PROTO_SOURCES), \
+    $(hide) find $(PRIVATE_PROTO_SOURCE_INTERMEDIATES_DIR) -name '*.java' -and -not -name '.*' >> $(1))
+$(if $(PRIVATE_HAS_RS_SOURCES), \
+    $(hide) find $(PRIVATE_RS_SOURCE_INTERMEDIATES_DIR) -name '*.java' -and -not -name '.*' >> $(1))
+endef
+
 # Some historical notes:
 # - below we write the list of java files to java-source-list to avoid argument
 #   list length problems with Cygwin
@@ -2214,16 +2225,20 @@
 @echo "$($(PRIVATE_PREFIX)DISPLAY) Java source list: $(PRIVATE_MODULE)"
 $(hide) rm -f $@
 $(call dump-words-to-file,$(sort $(PRIVATE_JAVA_SOURCES)),$@.tmp)
-$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
-    find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' -and -not -name '.*' >> $@.tmp; \
-fi
-$(if $(PRIVATE_HAS_PROTO_SOURCES), \
-    $(hide) find $(PRIVATE_PROTO_SOURCE_INTERMEDIATES_DIR) -name '*.java' -and -not -name '.*' >> $@.tmp)
-$(if $(PRIVATE_HAS_RS_SOURCES), \
-    $(hide) find $(PRIVATE_RS_SOURCE_INTERMEDIATES_DIR) -name '*.java' -and -not -name '.*' >> $@.tmp)
+$(call fetch-additional-java-source,$@.tmp)
 $(hide) tr ' ' '\n' < $@.tmp | $(NORMALIZE_PATH) | sort -u > $@
 endef
 
+# $(1): sharding number.
+# $(2): Java source files paths.
+define save-sharded-java-source-list
+$(java_source_list_file).shard.$(1): $(2) $$(NORMALIZE_PATH)
+	@echo "shard java source list: $$@"
+	rm -f $$@
+	$$(call dump-words-to-file,$(2),$$@.tmp)
+	$(hide) tr ' ' '\n' < $$@.tmp | $$(NORMALIZE_PATH) | sort -u > $$@
+endef
+
 # Common definition to invoke javac on the host and target.
 #
 # $(1): javac
@@ -2234,11 +2249,13 @@
 $(hide) mkdir -p $(dir $@)
 $(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR) $(PRIVATE_ANNO_INTERMEDIATES_DIR)
 $(hide) if [ -s $(PRIVATE_JAVA_SOURCE_LIST) ] ; then \
-    $(SOONG_JAVAC_WRAPPER) $(1) -encoding UTF-8 \
+    $(SOONG_JAVAC_WRAPPER) $(JAVAC_WRAPPER) $(1) -encoding UTF-8 \
     $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
-    $(addprefix -bootclasspath ,$(strip \
-        $(call normalize-path-list,$(PRIVATE_BOOTCLASSPATH)) \
-        $(PRIVATE_EMPTY_BOOTCLASSPATH))) \
+    $(if $(PRIVATE_USE_SYSTEM_MODULES), \
+      $(addprefix --system=,$(PRIVATE_SYSTEM_MODULES)), \
+      $(addprefix -bootclasspath ,$(strip \
+          $(call normalize-path-list,$(PRIVATE_BOOTCLASSPATH)) \
+          $(PRIVATE_EMPTY_BOOTCLASSPATH)))) \
     $(addprefix -classpath ,$(strip \
         $(call normalize-path-list,$(2)))) \
     $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
@@ -2265,9 +2282,34 @@
 $(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@))
 endef
 
-define transform-java-to-classes.jar
-@echo "$($(PRIVATE_PREFIX)DISPLAY) Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
-$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_ALL_JAVA_HEADER_LIBRARIES))
+# $(1): Javac output jar name.
+# $(2): Java source list file.
+# $(3): Java header libs.
+# $(4): Javac sharding number.
+# $(5): Javac sources deps (the arg may neeed $$ in case of containing '#')
+define create-classes-full-debug.jar
+$(1): PRIVATE_JAVACFLAGS := $$(LOCAL_JAVACFLAGS) $$(annotation_processor_flags)
+$(1): PRIVATE_JAR_EXCLUDE_FILES := $$(LOCAL_JAR_EXCLUDE_FILES)
+$(1): PRIVATE_JAR_PACKAGES := $$(LOCAL_JAR_PACKAGES)
+$(1): PRIVATE_JAR_EXCLUDE_PACKAGES := $$(LOCAL_JAR_EXCLUDE_PACKAGES)
+$(1): PRIVATE_DONT_DELETE_JAR_META_INF := $$(LOCAL_DONT_DELETE_JAR_META_INF)
+$(1): PRIVATE_JAVA_SOURCE_LIST := $(2)
+$(1): PRIVATE_ALL_JAVA_HEADER_LIBRARIES := $(3)
+$(1): PRIVATE_CLASS_INTERMEDIATES_DIR := $(intermediates.COMMON)/classes$(4)
+$(1): PRIVATE_ANNO_INTERMEDIATES_DIR := $(intermediates.COMMON)/anno$(4)
+$(1): \
+    $(2) \
+    $(3) \
+    $(5) \
+    $$(full_java_bootclasspath_libs) \
+    $$(full_java_system_modules_deps) \
+    $$(layers_file) \
+    $$(annotation_processor_deps) \
+    $$(NORMALIZE_PATH) \
+    $$(JAR_ARGS) \
+    | $$(SOONG_JAVAC_WRAPPER)
+	@echo "Target Java: $$@ ($$(PRIVATE_CLASS_INTERMEDIATES_DIR))"
+	$$(call compile-java,$$(TARGET_JAVAC),$$(PRIVATE_ALL_JAVA_HEADER_LIBRARIES))
 endef
 
 define transform-java-to-header.jar
@@ -2638,7 +2680,7 @@
 define copy-file-to-target
 @mkdir -p $(dir $@)
 $(hide) rm -f $@
-$(hide) cp $< $@
+$(hide) cp "$<" "$@"
 endef
 
 # The same as copy-file-to-target, but use the local
@@ -2646,7 +2688,7 @@
 define copy-file-to-target-with-cp
 @mkdir -p $(dir $@)
 $(hide) rm -f $@
-$(hide) cp -p $< $@
+$(hide) cp -p "$<" "$@"
 endef
 
 # The same as copy-file-to-target, but strip out "# comment"-style
@@ -2714,6 +2756,26 @@
 	$(hide) ln -sf $(2) $$@
 endef
 
+# Copy an apk to a target location while removing classes*.dex
+# $(1): source file
+# $(2): destination file
+# $(3): LOCAL_DEX_PREOPT, if nostripping then leave classes*.dex
+define dexpreopt-copy-jar
+$(2): $(1)
+	@echo $(if $(filter nostripping,$(3)),"Copy: $$@","Copy without dex: $$@")
+	$$(copy-file-to-target)
+	$(if $(filter nostripping,$(3)),,$$(call dexpreopt-remove-classes.dex,$$@))
+endef
+
+# $(1): the .jar or .apk to remove classes.dex
+define dexpreopt-remove-classes.dex
+$(hide) zip --quiet --delete $(1) classes.dex; \
+dex_index=2; \
+while zip --quiet --delete $(1) classes$${dex_index}.dex > /dev/null; do \
+  let dex_index=dex_index+1; \
+done
+endef
+
 ###########################################################
 ## Commands to call Proguard
 ###########################################################
@@ -2745,39 +2807,16 @@
 $(error HOST_OS must define get-file-size)
 endif
 
-# Convert a partition data size (eg, as reported in /proc/mtd) to the
-# size of the image used to flash that partition (which includes a
-# spare area for each page).
-# $(1): the partition data size
-define image-size-from-data-size
-$(strip $(eval _isfds_value := $$(shell echo $$$$(($(1) / $(BOARD_NAND_PAGE_SIZE) * \
-  ($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE))))))\
-$(if $(filter 0, $(_isfds_value)),$(shell echo $$(($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE)))),$(_isfds_value))\
-$(eval _isfds_value :=))
-endef
-
 # $(1): The file(s) to check (often $@)
-# $(2): The maximum total image size, in decimal bytes.
-#    Make sure to take into account any reserved space needed for the FS.
-#
-# If $(2) is empty, evaluates to "true"
-#
-# Reserve bad blocks.  Make sure that MAX(1% of partition size, 2 blocks)
-# is left over after the image has been flashed.  Round the 1% up to the
-# next whole flash block size.
-define assert-max-file-size
+# $(2): The partition size.
+define assert-max-image-size
 $(if $(2), \
   size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \
   total=$$(( $$( echo "$$size" ) )); \
   printname=$$(echo -n "$(1)" | tr " " +); \
-  img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \
-  twoblocks=$$((img_blocksize * 2)); \
-  onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \
-  reserve=$$((twoblocks > onepct ? twoblocks : onepct)); \
-  maxsize=$$(($(2) - reserve)); \
-  echo "$$printname maxsize=$$maxsize blocksize=$$img_blocksize total=$$total reserve=$$reserve"; \
+  maxsize=$(2); \
   if [ "$$total" -gt "$$maxsize" ]; then \
-    echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \
+    echo "error: $$printname too large ($$total > $$maxsize)"; \
     false; \
   elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \
     echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \
@@ -2787,17 +2826,6 @@
  )
 endef
 
-# Like assert-max-file-size, but the second argument is a partition
-# size, which we'll convert to a max image size before checking it
-# against the files.
-#
-# $(1): The file(s) to check (often $@)
-# $(2): The partition size.
-define assert-max-image-size
-$(if $(2), \
-  $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))))
-endef
-
 
 ###########################################################
 ## Define device-specific radio files
@@ -2976,7 +3004,7 @@
   base_rules \
   HEADER_LIBRARY
 
-$(foreach $(s),$(STATS.MODULE_TYPE),$(eval STATS.MODULE_TYPE.$(s) :=))
+$(foreach s,$(STATS.MODULE_TYPE),$(eval STATS.MODULE_TYPE.$(s) :=))
 define record-module-type
 $(strip $(if $(LOCAL_RECORDED_MODULE_TYPE),,
   $(if $(filter-out $(SOONG_ANDROID_MK),$(LOCAL_MODULE_MAKEFILE)),
diff --git a/core/dex_preopt.mk b/core/dex_preopt.mk
index 439f7e5..0dcb07f 100644
--- a/core/dex_preopt.mk
+++ b/core/dex_preopt.mk
@@ -35,10 +35,10 @@
 # Conditional to building on linux, as dex2oat currently does not work on darwin.
 ifeq ($(HOST_OS),linux)
   WITH_DEXPREOPT ?= true
-# For an eng build only pre-opt the boot image. This gives reasonable performance and still
-# allows a simple workflow: building in frameworks/base and syncing.
+# For an eng build only pre-opt the boot image and system server. This gives reasonable performance
+# and still allows a simple workflow: building in frameworks/base and syncing.
   ifeq (eng,$(TARGET_BUILD_VARIANT))
-    WITH_DEXPREOPT_BOOT_IMG_ONLY ?= true
+    WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY ?= true
   endif
 # Add mini-debug-info to the boot classpath unless explicitly asked not to.
   ifneq (false,$(WITH_DEXPREOPT_DEBUG_INFO))
@@ -48,15 +48,6 @@
 
 GLOBAL_DEXPREOPT_FLAGS :=
 
-# $(1): the .jar or .apk to remove classes.dex
-define dexpreopt-remove-classes.dex
-$(hide) zip --quiet --delete $(1) classes.dex; \
-dex_index=2; \
-while zip --quiet --delete $(1) classes$${dex_index}.dex > /dev/null; do \
-  let dex_index=dex_index+1; \
-done
-endef
-
 # Special rules for building stripped boot jars that override java_library.mk rules
 
 # $(1): boot jar module name
@@ -64,11 +55,7 @@
 _dbj_jar_no_dex := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(1)_nodex.jar
 _dbj_src_jar := $(call intermediates-dir-for,JAVA_LIBRARIES,$(1),,COMMON)/javalib.jar
 
-$$(_dbj_jar_no_dex) : $$(_dbj_src_jar)
-	$$(call copy-file-to-target)
-ifneq ($(DEX_PREOPT_DEFAULT),nostripping)
-	$$(call dexpreopt-remove-classes.dex,$$@)
-endif
+$(call dexpreopt-copy-jar,$$(_dbj_src_jar),$$(_dbj_jar_no_dex),$(DEX_PREOPT_DEFAULT))
 
 _dbj_jar_no_dex :=
 _dbj_src_jar :=
diff --git a/core/dex_preopt_libart.mk b/core/dex_preopt_libart.mk
index 9616036..de34d88 100644
--- a/core/dex_preopt_libart.mk
+++ b/core/dex_preopt_libart.mk
@@ -11,10 +11,6 @@
 DEX2OAT := $(HOST_OUT_EXECUTABLES)/dex2oatd$(HOST_EXECUTABLE_SUFFIX)
 endif
 
-# Pass special class loader context to skip the classpath and collision check.
-# Should modify build system to pass used libraries properly later.
-DEX2OAT_CLASS_LOADER_CONTEXT := "&"
-
 DEX2OAT_DEPENDENCY += $(DEX2OAT)
 
 # Use the first preloaded-classes file in PRODUCT_COPY_FILES.
@@ -150,7 +146,7 @@
 $(hide) mkdir -p $(dir $(2))
 $(hide) ANDROID_LOG_TAGS="*:e" $(DEX2OAT) \
 	--runtime-arg -Xms$(DEX2OAT_XMS) --runtime-arg -Xmx$(DEX2OAT_XMX) \
-	--class-loader-context=$(DEX2OAT_CLASS_LOADER_CONTEXT) \
+	--class-loader-context=$(PRIVATE_DEX2OAT_CLASS_LOADER_CONTEXT) \
 	--boot-image=$(PRIVATE_DEX_PREOPT_IMAGE_LOCATION) \
 	--dex-file=$(1) \
 	--dex-location=$(PRIVATE_DEX_LOCATION) \
diff --git a/core/dex_preopt_libart_boot.mk b/core/dex_preopt_libart_boot.mk
index a06aaca..302cc8b 100644
--- a/core/dex_preopt_libart_boot.mk
+++ b/core/dex_preopt_libart_boot.mk
@@ -81,7 +81,7 @@
 	@rm -f $(dir $@)/*.art $(dir $@)/*.oat
 	@rm -f $(dir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)LIBART_TARGET_BOOT_OAT_UNSTRIPPED))/*.art
 	@rm -f $(dir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)LIBART_TARGET_BOOT_OAT_UNSTRIPPED))/*.oat
-	$(DEX2OAT) --runtime-arg -Xms$(DEX2OAT_IMAGE_XMS) \
+	$(hide) ANDROID_LOG_TAGS="*:e" $(DEX2OAT) --runtime-arg -Xms$(DEX2OAT_IMAGE_XMS) \
 		--runtime-arg -Xmx$(DEX2OAT_IMAGE_XMX) \
 		$(PRIVATE_BOOT_IMAGE_FLAGS) \
 		$(addprefix --dex-file=,$(LIBART_TARGET_BOOT_DEX_FILES)) \
diff --git a/core/dex_preopt_odex_install.mk b/core/dex_preopt_odex_install.mk
index 136def4..f420b18 100644
--- a/core/dex_preopt_odex_install.mk
+++ b/core/dex_preopt_odex_install.mk
@@ -30,15 +30,22 @@
 ifdef LOCAL_UNINSTALLABLE_MODULE
 LOCAL_DEX_PREOPT :=
 endif
-ifeq (,$(strip $(built_dex)$(my_prebuilt_src_file))) # contains no java code
+ifeq (,$(strip $(built_dex)$(my_prebuilt_src_file)$(LOCAL_SOONG_DEX_JAR))) # contains no java code
 LOCAL_DEX_PREOPT :=
 endif
-# if WITH_DEXPREOPT_BOOT_IMG_ONLY=true and module is not in boot class path skip
-ifeq (true,$(WITH_DEXPREOPT_BOOT_IMG_ONLY))
-ifeq ($(filter $(DEXPREOPT_BOOT_JARS_MODULES),$(LOCAL_MODULE)),)
+# if WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY=true and module is not in boot class path skip
+# Also preopt system server jars since selinux prevents system server from loading anything from
+# /data. If we don't do this they will need to be extracted which is not favorable for RAM usage
+# or performance. If my_preopt_for_extracted_apk is true, we ignore the only preopt boot image
+# options.
+ifneq (true,$(my_preopt_for_extracted_apk))
+ifeq (true,$(WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY))
+ifeq ($(filter $(PRODUCT_SYSTEM_SERVER_JARS) $(DEXPREOPT_BOOT_JARS_MODULES),$(LOCAL_MODULE)),)
 LOCAL_DEX_PREOPT :=
 endif
 endif
+endif
+
 # if installing into system, and odex are being installed into system_other, don't strip
 ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true)
 ifeq ($(LOCAL_DEX_PREOPT),true)
diff --git a/core/envsetup.mk b/core/envsetup.mk
index c99c70f..8749a32 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -343,6 +343,7 @@
 PRODUCT_OUT := $(TARGET_PRODUCT_OUT_ROOT)/$(TARGET_DEVICE)
 
 OUT_DOCS := $(TARGET_COMMON_OUT_ROOT)/docs
+OUT_NDK_DOCS := $(TARGET_COMMON_OUT_ROOT)/ndk-docs
 
 BUILD_OUT_EXECUTABLES := $(BUILD_OUT)/bin
 SOONG_HOST_OUT_EXECUTABLES := $(SOONG_HOST_OUT)/bin
@@ -639,7 +640,7 @@
   DIST_DIR := $(OUT_DIR)/dist
 endif
 
-ifndef KATI
+ifeq ($(CALLED_FROM_SETUP),true)
 PRINT_BUILD_CONFIG ?= true
 endif
 
diff --git a/core/host_dalvik_java_library.mk b/core/host_dalvik_java_library.mk
index 96796df..4bfe288 100644
--- a/core/host_dalvik_java_library.mk
+++ b/core/host_dalvik_java_library.mk
@@ -93,6 +93,7 @@
     $(java_sources_deps) \
     $(full_java_header_libs) \
     $(full_java_bootclasspath_libs) \
+    $(full_java_system_modules_deps) \
     $(annotation_processor_deps) \
     $(NORMALIZE_PATH) \
     $(JAR_ARGS) \
diff --git a/core/install_jni_libs_internal.mk b/core/install_jni_libs_internal.mk
index b5f10cf..265d482 100644
--- a/core/install_jni_libs_internal.mk
+++ b/core/install_jni_libs_internal.mk
@@ -116,7 +116,7 @@
 else
 my_link_type := app:platform
 my_warn_types :=
-my_allowed_types := native:ndk native:platform native:vendor
+my_allowed_types := native:ndk native:platform native:vendor native:vndk native:vndk_private
 endif
 
 my_link_deps := $(addprefix SHARED_LIBRARIES:,$(LOCAL_JNI_SHARED_LIBRARIES))
diff --git a/core/java.mk b/core/java.mk
index 5eddb0e..7584479 100644
--- a/core/java.mk
+++ b/core/java.mk
@@ -352,7 +352,36 @@
 ##########################################
 java_sources := $(addprefix $(LOCAL_PATH)/, $(filter %.java,$(LOCAL_SRC_FILES))) $(aidl_java_sources) $(logtags_java_sources) \
                 $(filter %.java,$(LOCAL_GENERATED_SOURCES))
-all_java_sources := $(java_sources) $(addprefix $(TARGET_OUT_COMMON_INTERMEDIATES)/, $(filter %.java,$(LOCAL_INTERMEDIATE_SOURCES)))
+java_intermediate_sources := $(addprefix $(TARGET_OUT_COMMON_INTERMEDIATES)/, $(filter %.java,$(LOCAL_INTERMEDIATE_SOURCES)))
+all_java_sources := $(java_sources) $(java_intermediate_sources)
+
+enable_sharding :=
+ifneq ($(TURBINE_ENABLED),false)
+ifneq ($(LOCAL_JAVAC_SHARD_SIZE),)
+ifneq ($(LOCAL_JAR_PROCESSOR),)
+$(call pretty-error,Cannot set both LOCAL_JAVAC_SHARD_SIZE and LOCAL_JAR_PROCESSOR!)
+endif # LOCAL_JAR_PROCESSOR is not empty
+enable_sharding := true
+
+num_shards := $(call int_divide,$(words $(java_sources)),$(LOCAL_JAVAC_SHARD_SIZE))
+ifneq ($(words $(java_sources)),$(call int_multiply,$(LOCAL_JAVAC_SHARD_SIZE),$(num_shards)))
+# increment number of shards by 1.
+num_shards := $(call int_plus,$(num_shards),1)
+endif
+
+shard_idx_list := $(call int_range_list,1,$(num_shards))
+sharded_java_source_list_files += $(foreach x,$(shard_idx_list),$(java_source_list_file).shard.$(x))
+sharded_jar_list += $(foreach x,$(shard_idx_list),$(full_classes_compiled_jar).shard.$(x))
+
+# always put dynamically-located .java files (generated by Proto/resource, etc) in a new final shard.
+# increment number of shards by 1.
+num_shards := $(call int_plus,$(num_shards),1)
+sharded_java_source_list_files += $(java_source_list_file).shard.$(num_shards)
+sharded_jar_list += $(full_classes_compiled_jar).shard.$(num_shards)
+LOCAL_INTERMEDIATE_TARGETS += $(sharded_java_source_list_files)
+LOCAL_INTERMEDIATE_TARGETS += $(sharded_jar_list)
+endif # LOCAL_JAVAC_SHARD_SIZE is not empty
+endif # TURBINE_ENABLED != false
 
 include $(BUILD_SYSTEM)/java_common.mk
 
@@ -419,23 +448,47 @@
 $(java_source_list_file): $(java_sources_deps)
 	$(write-java-source-list)
 
-$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS) $(annotation_processor_flags)
-$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_FILES := $(LOCAL_JAR_EXCLUDE_FILES)
-$(full_classes_compiled_jar): PRIVATE_JAR_PACKAGES := $(LOCAL_JAR_PACKAGES)
-$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_PACKAGES := $(LOCAL_JAR_EXCLUDE_PACKAGES)
-$(full_classes_compiled_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
-$(full_classes_compiled_jar): PRIVATE_JAVA_SOURCE_LIST := $(java_source_list_file)
-$(full_classes_compiled_jar): \
-    $(java_source_list_file) \
-    $(java_sources_deps) \
-    $(full_java_header_libs) \
-    $(full_java_bootclasspath_libs) \
-    $(layers_file) \
-    $(annotation_processor_deps) \
-    $(NORMALIZE_PATH) \
-    $(JAR_ARGS) \
-    | $(SOONG_JAVAC_WRAPPER)
-	$(transform-java-to-classes.jar)
+ifdef enable_sharding
+$(foreach x,$(shard_idx_list),\
+  $(eval $(call save-sharded-java-source-list,$(x),\
+    $(wordlist $(call int_plus,1,$(call int_multiply,$(LOCAL_JAVAC_SHARD_SIZE),$(call int_subtract,$(x),1))),\
+      $(call int_multiply,$(LOCAL_JAVAC_SHARD_SIZE),$(x)),$(sort $(java_sources))))))
+
+# always put dynamically-located .java files (generated by Proto/resource, etc) in a new final shard.
+$(java_source_list_file).shard.$(num_shards): PRIVATE_JAVA_INTERMEDIATE_SOURCES := $(java_intermediate_sources)
+$(java_source_list_file).shard.$(num_shards): $(java_resource_sources) \
+    $(RenderScript_file_stamp) \
+    $(proto_java_sources_file_stamp) \
+    $(LOCAL_ADDITIONAL_DEPENDENCIES) \
+    $(NORMALIZE_PATH)
+	$(hide) rm -f $@
+	$(call dump-words-to-file,$(PRIVATE_JAVA_INTERMEDIATE_SOURCES),$@.tmp)
+	$(call fetch-additional-java-source,$@.tmp)
+	$(hide) tr ' ' '\n' < $@.tmp | $(NORMALIZE_PATH) | sort -u > $@
+
+# Javac sharding with header libs including its own header jar as one of dependency.
+$(foreach x,$(shard_idx_list),\
+  $(eval $(call create-classes-full-debug.jar,$(full_classes_compiled_jar).shard.$(x),\
+    $(java_source_list_file).shard.$(x),\
+      $(full_java_header_libs) $(full_classes_header_jar),$(x),\
+        $(wordlist $(call int_plus,1,$(call int_multiply,$(LOCAL_JAVAC_SHARD_SIZE),$(call int_subtract,$(x),1))),\
+          $(call int_multiply,$(LOCAL_JAVAC_SHARD_SIZE),$(x)),$(sort $(java_sources))))))
+
+# Javac sharding for last shard with additional Java dependencies.
+$(eval $(call create-classes-full-debug.jar,$(full_classes_compiled_jar).shard.$(num_shards),\
+  $(java_source_list_file).shard.$(num_shards),$(full_java_header_libs) $(full_classes_header_jar),$(strip \
+    $(num_shards)),$$(java_resource_sources) $$(RenderScript_file_stamp) \
+      $$(proto_java_sources_file_stamp) $$(LOCAL_ADDITIONAL_DEPENDENCIES)))
+
+$(full_classes_compiled_jar): PRIVATE_SHARDED_JAR_LIST := $(sharded_jar_list)
+$(full_classes_compiled_jar): $(sharded_jar_list) | $(MERGE_ZIPS)
+	$(MERGE_ZIPS) -j $@ $(PRIVATE_SHARDED_JAR_LIST)
+else
+# we can't use single $ for java_sources_deps since it may contain hash '#' sign.
+$(eval $(call create-classes-full-debug.jar,$(full_classes_compiled_jar),\
+  $(java_source_list_file),$(full_java_header_libs),,$$(java_sources_deps)))
+
+endif # ifdef enable_sharding
 
 ifneq ($(TURBINE_ENABLED),false)
 
@@ -446,6 +499,7 @@
     $(java_sources_deps) \
     $(full_java_header_libs) \
     $(full_java_bootclasspath_libs) \
+    $(full_java_system_modules_deps) \
     $(NORMALIZE_PATH) \
     $(JAR_ARGS) \
     $(ZIPTIME) \
diff --git a/core/java_common.mk b/core/java_common.mk
index 837983b..a73c6db 100644
--- a/core/java_common.mk
+++ b/core/java_common.mk
@@ -15,15 +15,17 @@
 # Modules can override this logic by specifying
 # LOCAL_JAVA_LANGUAGE_VERSION explicitly.
 ifeq (,$(LOCAL_JAVA_LANGUAGE_VERSION))
-  private_sdk_versions_without_any_java_18_support := 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
-  ifneq (,$(filter $(LOCAL_SDK_VERSION), $(private_sdk_versions_without_any_java_18_support)))
+  ifneq (,$(filter $(LOCAL_SDK_VERSION), $(TARGET_SDK_VERSIONS_WITHOUT_JAVA_18_SUPPORT)))
     LOCAL_JAVA_LANGUAGE_VERSION := 1.7
+  else ifneq (,$(filter $(LOCAL_SDK_VERSION), $(TARGET_SDK_VERSIONS_WITHOUT_JAVA_19_SUPPORT)))
+    LOCAL_JAVA_LANGUAGE_VERSION := 1.8
+  else ifneq (,$(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS))
+    # TODO(ccross): allow 1.9 for current and unbundled once we have SDK system modules
+    LOCAL_JAVA_LANGUAGE_VERSION := 1.8
   else
-    ifneq ($(EXPERIMENTAL_USE_OPENJDK9),true)
-      LOCAL_JAVA_LANGUAGE_VERSION := 1.8
-    else
-      LOCAL_JAVA_LANGUAGE_VERSION := 1.9
-    endif
+    # DEFAULT_JAVA_LANGUAGE_VERSION is 1.8 unless EXPERIMENTAL_USE_OPENJDK9=true
+    # in which case it is 1.9
+    LOCAL_JAVA_LANGUAGE_VERSION := $(DEFAULT_JAVA_LANGUAGE_VERSION)
   endif
 endif
 LOCAL_JAVACFLAGS += -source $(LOCAL_JAVA_LANGUAGE_VERSION) -target $(LOCAL_JAVA_LANGUAGE_VERSION)
@@ -196,6 +198,7 @@
 
 full_java_bootclasspath_libs :=
 empty_bootclasspath :=
+my_system_modules :=
 
 # full_java_libs: The list of files that should be used as the classpath.
 #                 Using this list as a dependency list WILL NOT WORK.
@@ -204,8 +207,13 @@
     ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
       # No bootclasspath. But we still need "" to prevent javac from using default host bootclasspath.
       empty_bootclasspath := ""
+      # Most users of LOCAL_NO_STANDARD_LIBRARIES really mean no framework libs,
+      # and manually add back the core libs.  The ones that don't are in soong
+      # now, so just always assume that they want the default system modules
+      my_system_modules := $(DEFAULT_SYSTEM_MODULES)
     else  # LOCAL_NO_STANDARD_LIBRARIES
       full_java_bootclasspath_libs := $(call java-lib-header-files,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES))
+      my_system_modules := $(DEFAULT_SYSTEM_MODULES)
     endif  # LOCAL_NO_STANDARD_LIBRARIES
   else
     ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
@@ -250,6 +258,7 @@
       full_java_bootclasspath_libs := $(call java-lib-header-files,$(addsuffix -hostdex,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES)),true)
     endif
 
+    my_system_modules := $(DEFAULT_SYSTEM_MODULES)
     full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),true)
     full_shared_java_header_libs := $(call java-lib-header-files,$(LOCAL_JAVA_LIBRARIES),true)
   else # !USE_CORE_LIB_BOOTCLASSPATH
@@ -265,8 +274,25 @@
   endif
 endif
 
+full_java_system_modules_deps :=
+my_system_modules_dir :=
+$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_USE_SYSTEM_MODULES :=
+ifeq ($(LOCAL_JAVA_LANGUAGE_VERSION),1.9)
+  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_USE_SYSTEM_MODULES := true
+  ifdef my_system_modules
+    ifneq ($(my_system_modules),none)
+      ifndef SOONG_SYSTEM_MODULES_$(my_system_modules)
+        $(call pretty-error, Invalid system modules $(my_system_modules))
+      endif
+      full_java_system_modules_deps := $(SOONG_SYSTEM_MODULES_$(my_system_modules))
+      my_system_modules_dir := $(patsubst %/lib/modules,%,$(SOONG_SYSTEM_MODULES_$(my_system_modules)))
+    endif
+  endif
+endif
+
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := $(full_java_bootclasspath_libs)
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EMPTY_BOOTCLASSPATH := $(empty_bootclasspath)
+$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SYSTEM_MODULES := $(my_system_modules_dir)
 
 full_java_libs := $(full_shared_java_libs) $(full_static_java_libs) $(LOCAL_CLASSPATH)
 full_java_header_libs := $(full_shared_java_header_libs) $(full_static_java_header_libs)
diff --git a/core/java_library.mk b/core/java_library.mk
index f933653..d728c53 100644
--- a/core/java_library.mk
+++ b/core/java_library.mk
@@ -86,10 +86,7 @@
 	@echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)"
 	$(call dexpreopt-one-file,$<,$@)
 
-$(eval $(call copy-one-file,$(common_javalib.jar),$(LOCAL_BUILT_MODULE)))
-ifneq (nostripping,$(LOCAL_DEX_PREOPT))
-	$(call dexpreopt-remove-classes.dex,$@)
-endif
+$(eval $(call dexpreopt-copy-jar,$(common_javalib.jar),$(LOCAL_BUILT_MODULE),$(LOCAL_DEX_PREOPT)))
 
 endif # ! boot jar
 
diff --git a/core/main.mk b/core/main.mk
index 8ace91d..b71e245 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -34,7 +34,7 @@
 TOP := .
 TOPDIR :=
 
-BUILD_SYSTEM := $(TOPDIR)build/core
+BUILD_SYSTEM := $(TOPDIR)build/make/core
 
 # This is the default target.  It must be the first declared target.
 .PHONY: droid
@@ -173,7 +173,7 @@
 
 # -----------------------------------------------------------------
 # The pdk (Platform Development Kit) build
-include build/core/pdk_config.mk
+include build/make/core/pdk_config.mk
 
 #
 # -----------------------------------------------------------------
@@ -936,7 +936,7 @@
       $(warning $(ALL_MODULES.$(m).MAKEFILE): Module '$(m)' in PRODUCT_PACKAGES_TESTS has nothing to install!)))
 endif
 
-# build/core/Makefile contains extra stuff that we don't want to pollute this
+# build/make/core/Makefile contains extra stuff that we don't want to pollute this
 # top-level makefile with.  It expects that ALL_DEFAULT_INSTALLED_MODULES
 # contains everything that's built during the current make, but it also further
 # extends ALL_DEFAULT_INSTALLED_MODULES.
diff --git a/core/math.mk b/core/math.mk
index 047d046..44e03ce 100644
--- a/core/math.mk
+++ b/core/math.mk
@@ -42,6 +42,11 @@
 $(if $(call math_is_number,$(1)),,$(error Only positive integers <= 100 are supported (not $(1))))
 endef
 
+# return a list containing integers ranging from [$(1),$(2)]
+define int_range_list
+$(call _math_check_valid,$(1))$(call _math_check_valid,$(2))$(wordlist $(1),$(2),$(__MATH_NUMBERS))
+endef
+
 #$(call _math_check_valid,0)
 #$(call _math_check_valid,1)
 #$(call _math_check_valid,100)
@@ -67,6 +72,10 @@
 $(if $(filter $(1),$(call math_max,$(1),$(2))),true)
 endef
 
+define math_lt
+$(if $(call math_gt_or_eq,$(1),$(2)),,true)
+endef
+
 #$(warning $(call math_gt_or_eq, 2, 1))
 #$(warning $(call math_gt_or_eq, 1, 1))
 #$(warning $(if $(call math_gt_or_eq, 1, 2),false,true))
@@ -75,3 +84,69 @@
 define inc_and_print
 $(strip $(eval $(1) := $($(1)) .)$(words $($(1))))
 endef
+
+# Returns the words in $2 that are numbers and are less than $1
+define numbers_less_than
+$(strip \
+  $(foreach n,$2, \
+    $(if $(call math_is_number,$(n)), \
+      $(if $(call math_lt,$(n),$(1)), \
+        $(n)))))
+endef
+
+_INT_LIMIT_WORDS := $(foreach a,x x,$(foreach b,x x x x x x x x x x x x x x x x,\
+  $(foreach c,x x x x x x x x x x x x x x x x,x x x x x x x x x x x x x x x x)))
+
+define _int_encode
+$(if $(filter $(words x $(_INT_LIMIT_WORDS)),$(words $(wordlist 1,$(1),x $(_INT_LIMIT_WORDS)))),\
+  $(call pretty-error,integer greater than $(words $(_INT_LIMIT_WORDS)) is not supported!),\
+    $(wordlist 1,$(1),$(_INT_LIMIT_WORDS)))
+endef
+
+# _int_max returns the maximum of the two arguments
+# input: two (x) lists; output: one (x) list
+# integer cannot be passed in directly. It has to be converted using _int_encode.
+define _int_max
+$(subst xx,x,$(join $(1),$(2)))
+endef
+
+# first argument is greater than second argument
+# output: non-empty if true
+# integer cannot be passed in directly. It has to be converted using _int_encode.
+define _int_greater-than
+$(filter-out $(words $(2)),$(words $(call _int_max,$(1),$(2))))
+endef
+
+# first argument equals to second argument
+# output: non-empty if true
+# integer cannot be passed in directly. It has to be converted using _int_encode.
+define _int_equal
+$(filter $(words $(1)),$(words $(2)))
+endef
+
+# first argument is greater than or equal to second argument
+# output: non-empty if true
+# integer cannot be passed in directly. It has to be converted using _int_encode.
+define _int_greater-or-equal
+$(call _int_greater-than,$(1),$(2))$(call _int_equal,$(1),$(2))
+endef
+
+define int_plus
+$(words $(call _int_encode,$(1)) $(call _int_encode,$(2)))
+endef
+
+define int_subtract
+$(if $(call _int_greater-or-equal,$(call _int_encode,$(1)),$(call _int_encode,$(2))),\
+  $(words $(filter-out xx,$(join $(call _int_encode,$(1)),$(call _int_encode,$(2))))),\
+    $(call pretty-error,$(1) subtract underflow $(2)))
+endef
+
+define int_multiply
+$(words $(foreach a,$(call _int_encode,$(1)),$(call _int_encode,$(2))))
+endef
+
+define int_divide
+$(if $(filter 0,$(2)),$(call pretty-error,division by zero is not allowed!),$(strip \
+  $(if $(call _int_greater-or-equal,$(call _int_encode,$(1)),$(call _int_encode,$(2))), \
+    $(call int_plus,$(call int_divide,$(call int_subtract,$(1),$(2)),$(2)),1),0)))
+endef
diff --git a/core/package_internal.mk b/core/package_internal.mk
index 5a1ef05..01e2463 100644
--- a/core/package_internal.mk
+++ b/core/package_internal.mk
@@ -333,6 +333,7 @@
 # Make sure the data-binding process happens before javac and generation of R.java.
 $(R_file_stamp): $(data_binding_stamp)
 $(java_source_list_file): $(data_binding_stamp)
+$(foreach x,$(sharded_java_source_list_files),$(eval $(x): $(data_binding_stamp)))
 $(full_classes_compiled_jar): $(data_binding_stamp)
 endif  # LOCAL_DATA_BINDING
 
@@ -426,6 +427,7 @@
 # The R.java file must exist by the time the java source
 # list is generated
 $(java_source_list_file): $(R_file_stamp)
+$(foreach x,$(sharded_java_source_list_files),$(eval $(x): $(R_file_stamp)))
 
 endif  # need_compile_res
 
diff --git a/core/pathmap.mk b/core/pathmap.mk
index e2331c6..a1c20c9 100644
--- a/core/pathmap.mk
+++ b/core/pathmap.mk
@@ -40,7 +40,6 @@
     libhardware:hardware/libhardware/include \
     libhardware_legacy:hardware/libhardware_legacy/include \
     libril:hardware/ril/include \
-    opengl-tests-includes:frameworks/native/opengl/tests/include \
     recovery:bootable/recovery \
     system-core:system/core/include \
     audio:system/media/audio/include \
diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk
index 3622c9c..ba10b37 100644
--- a/core/prebuilt_internal.mk
+++ b/core/prebuilt_internal.mk
@@ -155,7 +155,16 @@
 ifdef LOCAL_SDK_VERSION
 my_link_type := native:ndk
 else ifdef LOCAL_USE_VNDK
-my_link_type := native:vendor
+    _name := $(patsubst %.vendor,%,$(LOCAL_MODULE))
+    ifneq ($(filter $(_name),$(VNDK_CORE_LIBRARIES) $(VNDK_SAMEPROCESS_LIBRARIES) $(LLNDK_LIBRARIES)),)
+        ifeq ($(filter $(_name),$(VNDK_PRIVATE_LIBRARIES)),)
+            my_link_type := native:vndk
+        else
+            my_link_type := native:vndk_private
+        endif
+    else
+        my_link_type := native:vendor
+    endif
 else
 my_link_type := native:platform
 endif
@@ -260,6 +269,11 @@
 my_prebuilt_src_file := $(my_extracted_apk)
 my_extracted_apk :=
 my_extract_apk :=
+ifeq ($(PRODUCT_ALWAYS_PREOPT_EXTRACTED_APK),true)
+# If the product property is set, always preopt for extracted modules to prevent executing out of
+# the APK.
+my_preopt_for_extracted_apk := true
+endif
 endif
 
 rs_compatibility_jni_libs :=
@@ -430,11 +444,7 @@
 	@echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)"
 	$(call dexpreopt-one-file,$<,$@)
 
-$(built_module) : $(my_prebuilt_src_file)
-	$(call copy-file-to-target)
-ifneq (nostripping,$(LOCAL_DEX_PREOPT))
-	$(call dexpreopt-remove-classes.dex,$@)
-endif
+$(eval $(call dexpreopt-copy-jar,$(my_prebuilt_src_file),$(built_module),$(LOCAL_DEX_PREOPT)))
 endif # boot jar
 else # ! LOCAL_DEX_PREOPT
 $(built_module) : $(my_prebuilt_src_file)
@@ -560,7 +570,7 @@
 
 # We needed only very few PRIVATE variables and aapt2.mk input variables. Reset the unnecessary ones.
 $(my_res_package): PRIVATE_AAPT2_CFLAGS :=
-$(my_res_package): PRIVATE_AAPT_FLAGS := --static-lib --no-static-lib-packages
+$(my_res_package): PRIVATE_AAPT_FLAGS := --static-lib --no-static-lib-packages --auto-add-overlay
 $(my_res_package): PRIVATE_ANDROID_MANIFEST := $(intermediates.COMMON)/aar/AndroidManifest.xml
 $(my_res_package): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
 $(my_res_package): PRIVATE_SOURCE_INTERMEDIATES_DIR :=
@@ -597,3 +607,4 @@
 $(built_module) : $(LOCAL_ADDITIONAL_DEPENDENCIES)
 
 my_prebuilt_src_file :=
+my_preopt_for_extracted_apk :=
diff --git a/core/product-graph.mk b/core/product-graph.mk
index 36e9037..633ac37 100644
--- a/core/product-graph.mk
+++ b/core/product-graph.mk
@@ -34,7 +34,7 @@
 endef
 
 
-this_makefile := build/core/product-graph.mk
+this_makefile := build/make/core/product-graph.mk
 
 products_svg := $(OUT_DIR)/products.svg
 products_pdf := $(OUT_DIR)/products.pdf
diff --git a/core/product.mk b/core/product.mk
index cf62283..4682dac 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -115,6 +115,7 @@
     PRODUCT_SYSTEM_PROPERTY_BLACKLIST \
     PRODUCT_SYSTEM_SERVER_APPS \
     PRODUCT_SYSTEM_SERVER_JARS \
+    PRODUCT_ALWAYS_PREOPT_EXTRACTED_APK \
     PRODUCT_DEXPREOPT_SPEED_APPS \
     PRODUCT_VBOOT_SIGNING_KEY \
     PRODUCT_VBOOT_SIGNING_SUBKEY \
@@ -303,7 +304,7 @@
 _product_stash_var_list += \
 	DEFAULT_SYSTEM_DEV_CERTIFICATE \
 	WITH_DEXPREOPT \
-	WITH_DEXPREOPT_BOOT_IMG_ONLY \
+	WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY \
 	WITH_DEXPREOPT_APP_IMAGE
 
 #
diff --git a/core/product_config.mk b/core/product_config.mk
index cd62fb2..04f02da 100644
--- a/core/product_config.mk
+++ b/core/product_config.mk
@@ -88,7 +88,7 @@
 # Provide "PRODUCT-<prodname>-<goal>" targets, which lets you build
 # a particular configuration without needing to set up the environment.
 #
-ifndef KATI
+ifeq ($(CALLED_FROM_SETUP),true)
 product_goals := $(strip $(filter PRODUCT-%,$(MAKECMDGOALS)))
 ifdef product_goals
   # Scrape the product and build names out of the goal,
@@ -129,14 +129,14 @@
   # position, in case it matters.
   override MAKECMDGOALS := $(patsubst $(goal_name),$(default_goal_substitution),$(MAKECMDGOALS))
 endif
-endif # !KATI
+endif # CALLED_FROM_SETUP
 # else: Use the value set in the environment or buildspec.mk.
 
 # ---------------------------------------------------------------
 # Provide "APP-<appname>" targets, which lets you build
 # an unbundled app.
 #
-ifndef KATI
+ifeq ($(CALLED_FROM_SETUP),true)
 unbundled_goals := $(strip $(filter APP-%,$(MAKECMDGOALS)))
 ifdef unbundled_goals
   ifneq ($(words $(unbundled_goals)),1)
@@ -260,6 +260,9 @@
 PRODUCT_SYSTEM_SERVER_APPS := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_SERVER_APPS))
 PRODUCT_DEXPREOPT_SPEED_APPS := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_DEXPREOPT_SPEED_APPS))
 
+# All of the apps that we force preopt, this overrides WITH_DEXPREOPT.
+PRODUCT_ALWAYS_PREOPT_EXTRACTED_APK := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_ALWAYS_PREOPT_EXTRACTED_APK))
+
 # Find the device that this product maps to.
 TARGET_DEVICE := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_DEVICE)
 
@@ -336,7 +339,7 @@
 # The file at the source path should be copied to the destination path
 # when building  this product.  <destination path> is relative to
 # $(PRODUCT_OUT), so it should look like, e.g., "system/etc/file.xml".
-# The rules for these copy steps are defined in build/core/Makefile.
+# The rules for these copy steps are defined in build/make/core/Makefile.
 # The optional :<owner> is used to indicate the owner of a vendor file.
 PRODUCT_COPY_FILES := \
     $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_COPY_FILES))
diff --git a/core/root.mk b/core/root.mk
index 6c8f795..1ef9aca 100644
--- a/core/root.mk
+++ b/core/root.mk
@@ -1,3 +1,3 @@
 ### DO NOT EDIT THIS FILE ###
-include build/core/main.mk
+include build/make/core/main.mk
 ### DO NOT EDIT THIS FILE ###
diff --git a/core/setup_one_odex.mk b/core/setup_one_odex.mk
index f0ffe81..e0d9926 100644
--- a/core/setup_one_odex.mk
+++ b/core/setup_one_odex.mk
@@ -32,6 +32,10 @@
     $(DEXPREOPT_ONE_FILE_DEPENDENCY_TOOLS) \
     $(my_dex_preopt_image_filename)
 
+# Pass special class loader context to skip the classpath and collision check.
+# Should modify build system to pass used libraries properly later.
+$(my_built_odex): PRIVATE_DEX2OAT_CLASS_LOADER_CONTEXT := \&
+
 my_installed_odex := $(call get-odex-installed-file-path,$($(my_2nd_arch_prefix)DEX2OAT_TARGET_ARCH),$(LOCAL_INSTALLED_MODULE))
 
 my_built_vdex := $(patsubst %.odex,%.vdex,$(my_built_odex))
diff --git a/core/soong_config.mk b/core/soong_config.mk
index ae0a0b2..629edfc 100644
--- a/core/soong_config.mk
+++ b/core/soong_config.mk
@@ -13,6 +13,7 @@
 endif
 endif
 
+ifeq ($(WRITE_SOONG_VARIABLES),true)
 # Converts a list to a JSON list.
 # $1: List separator.
 # $2: List.
@@ -24,77 +25,105 @@
 # Converts a comma-separated list to a JSON list.
 csv_to_json_list = $(call _json_list,$(comma),$(1))
 
+# 1: Key name
+# 2: Value
+add_json_val = $(eval _contents := $$(_contents)    "$$(strip $$(1))":$$(space)$$(strip $$(2))$$(comma)$$(newline))
+add_json_str = $(call add_json_val,$(1),"$(strip $(2))")
+add_json_list = $(call add_json_val,$(1),$(call json_list,$(patsubst %,%,$(2))))
+add_json_csv = $(call add_json_val,$(1),$(call csv_to_json_list,$(strip $(2))))
+add_json_bool = $(call add_json_val,$(1),$(if $(strip $(2)),true,false))
+
+invert_bool = $(if $(strip $(1)),,true)
+
 # Create soong.variables with copies of makefile settings.  Runs every build,
 # but only updates soong.variables if it changes
-SOONG_VARIABLES_TMP := $(SOONG_VARIABLES).$$$$
-$(SOONG_VARIABLES): FORCE
-	$(hide) mkdir -p $(dir $@)
-	$(hide) (\
-	echo '{'; \
-	echo '    "Make_suffix": "-$(TARGET_PRODUCT)",'; \
-	echo ''; \
-	echo '    "Platform_sdk_version": $(PLATFORM_SDK_VERSION),'; \
-	echo '    "Platform_version_active_codenames": $(call csv_to_json_list,$(PLATFORM_VERSION_ALL_CODENAMES)),'; \
-	echo '    "Platform_version_future_codenames": $(call csv_to_json_list,$(PLATFORM_VERSION_FUTURE_CODENAMES)),'; \
-	echo '    "Unbundled_build": $(if $(TARGET_BUILD_APPS),true,false),'; \
-	echo '    "Brillo": $(if $(BRILLO),true,false),'; \
-	echo '    "Malloc_not_svelte": $(if $(filter true,$(MALLOC_SVELTE)),false,true),'; \
-	echo '    "Allow_missing_dependencies": $(if $(ALLOW_MISSING_DEPENDENCIES),true,false),'; \
-	echo '    "SanitizeHost": $(call json_list,$(SANITIZE_HOST)),'; \
-	echo '    "SanitizeDevice": $(call json_list,$(SANITIZE_TARGET)),'; \
-	echo '    "SanitizeDeviceDiag": $(call json_list,$(SANITIZE_TARGET_DIAG)),'; \
-	echo '    "SanitizeDeviceArch": $(call json_list,$(SANITIZE_TARGET_ARCH)),'; \
-	echo '    "HostStaticBinaries": $(if $(strip $(BUILD_HOST_static)),true,false),'; \
-	echo '    "Binder32bit": $(if $(BINDER32BIT),true,false),'; \
-	echo '    "DevicePrefer32BitExecutables": $(if $(filter true,$(TARGET_PREFER_32_BIT_EXECUTABLES)),true,false),'; \
-	echo '    "UseGoma": $(if $(filter-out false,$(USE_GOMA)),true,false),'; \
-	echo '    "Debuggable": $(if $(filter userdebug eng,$(TARGET_BUILD_VARIANT)),true,false),'; \
-	echo '    "Eng": $(if $(filter eng,$(TARGET_BUILD_VARIANT)),true,false),'; \
-	echo '    "VendorPath": "$(TARGET_COPY_OUT_VENDOR)",'; \
-	echo ''; \
-	echo '    "ClangTidy": $(if $(filter 1 true,$(WITH_TIDY)),true,false),'; \
-	echo '    "TidyChecks": "$(WITH_TIDY_CHECKS)",'; \
-	echo ''; \
-	echo '    "NativeCoverage": $(if $(filter true,$(NATIVE_COVERAGE)),true,false),'; \
-	echo '    "CoveragePaths": $(call csv_to_json_list,$(COVERAGE_PATHS)),'; \
-	echo '    "CoverageExcludePaths": $(call csv_to_json_list,$(COVERAGE_EXCLUDE_PATHS)),'; \
-	echo ''; \
-	echo '    "DeviceName": "$(TARGET_DEVICE)",'; \
-	echo '    "DeviceArch": "$(TARGET_ARCH)",'; \
-	echo '    "DeviceArchVariant": "$(TARGET_ARCH_VARIANT)",'; \
-	echo '    "DeviceCpuVariant": "$(TARGET_CPU_VARIANT)",'; \
-	echo '    "DeviceAbi": ["$(TARGET_CPU_ABI)", "$(TARGET_CPU_ABI2)"],'; \
-	echo '    "DeviceUsesClang": $(if $(USE_CLANG_PLATFORM_BUILD),$(USE_CLANG_PLATFORM_BUILD),false),'; \
-	echo '    "DeviceVndkVersion": "$(BOARD_VNDK_VERSION)",'; \
-	echo ''; \
-	echo '    "DeviceSecondaryArch": "$(TARGET_2ND_ARCH)",'; \
-	echo '    "DeviceSecondaryArchVariant": "$(TARGET_2ND_ARCH_VARIANT)",'; \
-	echo '    "DeviceSecondaryCpuVariant": "$(TARGET_2ND_CPU_VARIANT)",'; \
-	echo '    "DeviceSecondaryAbi": ["$(TARGET_2ND_CPU_ABI)", "$(TARGET_2ND_CPU_ABI2)"],'; \
-	echo ''; \
-	echo '    "HostArch": "$(HOST_ARCH)",'; \
-	echo '    "HostSecondaryArch": "$(HOST_2ND_ARCH)",'; \
-	echo ''; \
-	echo '    "CrossHost": "$(HOST_CROSS_OS)",'; \
-	echo '    "CrossHostArch": "$(HOST_CROSS_ARCH)",'; \
-	echo '    "CrossHostSecondaryArch": "$(HOST_CROSS_2ND_ARCH)",'; \
-	echo '    "Safestack": $(if $(filter true,$(USE_SAFESTACK)),true,false),'; \
-	echo '    "EnableCFI": $(if $(filter false,$(ENABLE_CFI)),false,true),'; \
-	echo '    "IntegerOverflowExcludePaths": $(call json_list,$(INTEGER_OVERFLOW_EXCLUDE_PATHS) $(PRODUCT_INTEGER_OVERFLOW_EXCLUDE_PATHS)),'; \
-	echo '    "Device_uses_hwc2": $(if $(filter true,$(TARGET_USES_HWC2)),true,false),'; \
-	echo '    "Override_rs_driver": "$(OVERRIDE_RS_DRIVER)",'; \
-	echo '    "Treble": $(if $(filter true,$(PRODUCT_FULL_TREBLE)),true,false),'; \
-	echo '    "Pdk": $(if $(filter true,$(TARGET_BUILD_PDK)),true,false),'; \
-	echo '    "Uml": $(if $(filter true,$(TARGET_USER_MODE_LINUX)),true,false),'; \
-	echo ''; \
-	echo '    "ArtUseReadBarrier": $(if $(filter false,$(PRODUCT_ART_USE_READ_BARRIER)),false,true),'; \
-	echo ''; \
-	echo '    "BtConfigIncludeDir": "$(BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR)",'; \
-	echo ''; \
-	echo '    "DeviceKernelHeaders": $(call json_list,$(strip $(TARGET_PROJECT_SYSTEM_INCLUDES)))'; \
-	echo '}') > $(SOONG_VARIABLES_TMP); \
-	if ! cmp -s $(SOONG_VARIABLES_TMP) $(SOONG_VARIABLES); then \
-	  mv $(SOONG_VARIABLES_TMP) $(SOONG_VARIABLES); \
+$(shell mkdir -p $(dir $(SOONG_VARIABLES)))
+_contents := {$(newline)
+
+$(call add_json_str,  Make_suffix, -$(TARGET_PRODUCT))
+
+$(call add_json_val,  Platform_sdk_version,              $(PLATFORM_SDK_VERSION))
+$(call add_json_csv,  Platform_version_active_codenames, $(PLATFORM_VERSION_ALL_CODENAMES))
+$(call add_json_csv,  Platform_version_future_codenames, $(PLATFORM_VERSION_FUTURE_CODENAMES))
+
+$(call add_json_bool, Allow_missing_dependencies,        $(ALLOW_MISSING_DEPENDENCIES))
+$(call add_json_bool, Unbundled_build,                   $(TARGET_BUILD_APPS))
+$(call add_json_bool, Pdk,                               $(filter true,$(TARGET_BUILD_PDK)))
+
+$(call add_json_bool, Debuggable,                        $(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
+$(call add_json_bool, Eng,                               $(filter eng,$(TARGET_BUILD_VARIANT)))
+
+$(call add_json_str,  DeviceName,                        $(TARGET_DEVICE))
+$(call add_json_str,  DeviceArch,                        $(TARGET_ARCH))
+$(call add_json_str,  DeviceArchVariant,                 $(TARGET_ARCH_VARIANT))
+$(call add_json_str,  DeviceCpuVariant,                  $(TARGET_CPU_VARIANT))
+$(call add_json_list, DeviceAbi,                         $(TARGET_CPU_ABI) $(TARGET_CPU_ABI2))
+
+$(call add_json_str,  DeviceSecondaryArch,               $(TARGET_2ND_ARCH))
+$(call add_json_str,  DeviceSecondaryArchVariant,        $(TARGET_2ND_ARCH_VARIANT))
+$(call add_json_str,  DeviceSecondaryCpuVariant,         $(TARGET_2ND_CPU_VARIANT))
+$(call add_json_list, DeviceSecondaryAbi,                $(TARGET_2ND_CPU_ABI) $(TARGET_2ND_CPU_ABI2))
+
+$(call add_json_str,  HostArch,                          $(HOST_ARCH))
+$(call add_json_str,  HostSecondaryArch,                 $(HOST_2ND_ARCH))
+$(call add_json_bool, HostStaticBinaries,                $(BUILD_HOST_static))
+
+$(call add_json_str,  CrossHost,                         $(HOST_CROSS_OS))
+$(call add_json_str,  CrossHostArch,                     $(HOST_CROSS_ARCH))
+$(call add_json_str,  CrossHostSecondaryArch,            $(HOST_CROSS_2ND_ARCH))
+
+$(call add_json_list, SanitizeHost,                      $(SANITIZE_HOST))
+$(call add_json_list, SanitizeDevice,                    $(SANITIZE_TARGET))
+$(call add_json_list, SanitizeDeviceDiag,                $(SANITIZE_TARGET_DIAG))
+$(call add_json_list, SanitizeDeviceArch,                $(SANITIZE_TARGET_ARCH))
+
+$(call add_json_bool, Safestack,                         $(filter true,$(USE_SAFESTACK)))
+$(call add_json_bool, EnableCFI,                         $(call invert_bool,$(filter false,$(ENABLE_CFI))))
+$(call add_json_list, IntegerOverflowExcludePaths,       $(INTEGER_OVERFLOW_EXCLUDE_PATHS) $(PRODUCT_INTEGER_OVERFLOW_EXCLUDE_PATHS))
+
+$(call add_json_bool, ClangTidy,                         $(filter 1 true,$(WITH_TIDY)))
+$(call add_json_str,  TidyChecks,                        $(WITH_TIDY_CHECKS))
+
+$(call add_json_bool, NativeCoverage,                    $(filter true,$(NATIVE_COVERAGE)))
+$(call add_json_csv,  CoveragePaths,                     $(COVERAGE_PATHS))
+$(call add_json_csv,  CoverageExcludePaths,              $(COVERAGE_EXCLUDE_PATHS))
+
+$(call add_json_bool, ArtUseReadBarrier,                 $(call invert_bool,$(filter false,$(PRODUCT_ART_USE_READ_BARRIER))))
+$(call add_json_bool, Binder32bit,                       $(BINDER32BIT))
+$(call add_json_bool, Brillo,                            $(BRILLO))
+$(call add_json_str,  BtConfigIncludeDir,                $(BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR))
+$(call add_json_bool, Device_uses_hwc2,                  $(filter true,$(TARGET_USES_HWC2)))
+$(call add_json_list, DeviceKernelHeaders,               $(TARGET_PROJECT_SYSTEM_INCLUDES))
+$(call add_json_bool, DevicePrefer32BitExecutables,      $(filter true,$(TARGET_PREFER_32_BIT_EXECUTABLES)))
+$(call add_json_val,  DeviceUsesClang,                   $(if $(USE_CLANG_PLATFORM_BUILD),$(USE_CLANG_PLATFORM_BUILD),false))
+$(call add_json_str,  DeviceVndkVersion,                 $(BOARD_VNDK_VERSION))
+$(call add_json_bool, Malloc_not_svelte,                 $(call invert_bool,$(filter true,$(MALLOC_SVELTE))))
+$(call add_json_str,  Override_rs_driver,                $(OVERRIDE_RS_DRIVER))
+$(call add_json_bool, Treble,                            $(filter true,$(PRODUCT_FULL_TREBLE)))
+$(call add_json_bool, Uml,                               $(filter true,$(TARGET_USER_MODE_LINUX)))
+$(call add_json_str,  VendorPath,                        $(TARGET_COPY_OUT_VENDOR))
+
+$(call add_json_bool, UseGoma,                           $(filter-out false,$(USE_GOMA)))
+
+_contents := $(subst $(comma)$(newline)__SV_END,$(newline)}$(newline),$(_contents)__SV_END)
+
+$(file >$(SOONG_VARIABLES).tmp,$(_contents))
+
+$(shell if ! cmp -s $(SOONG_VARIABLES).tmp $(SOONG_VARIABLES); then \
+	  mv $(SOONG_VARIABLES).tmp $(SOONG_VARIABLES); \
 	else \
-	  rm $(SOONG_VARIABLES_TMP); \
-	fi
+	  rm $(SOONG_VARIABLES).tmp; \
+	fi)
+
+_json_list :=
+json_list :=
+csv_to_json_list :=
+add_json_val :=
+add_json_str :=
+add_json_list :=
+add_json_csv :=
+add_json_bool :=
+invert_bool :=
+_contents :=
+
+endif # CONFIGURE_SOONG
diff --git a/core/soong_java_prebuilt.mk b/core/soong_java_prebuilt.mk
index 9198d68..53ad50d 100644
--- a/core/soong_java_prebuilt.mk
+++ b/core/soong_java_prebuilt.mk
@@ -35,11 +35,40 @@
 endif # TURBINE_DISABLED != false
 
 ifdef LOCAL_SOONG_DEX_JAR
-$(eval $(call copy-one-file,$(LOCAL_SOONG_DEX_JAR),$(common_javalib.jar)))
-$(eval $(call copy-one-file,$(LOCAL_SOONG_DEX_JAR),$(LOCAL_BUILT_MODULE)))
-java-dex : $(LOCAL_BUILT_MODULE)
+  ifndef LOCAL_IS_HOST_MODULE
+    $(eval $(call copy-one-file,$(LOCAL_SOONG_DEX_JAR),$(common_javalib.jar)))
+    $(eval $(call add-dependency,$(common_javalib.jar),$(full_classes_jar) $(full_classes_header_jar)))
+
+    # defines built_odex along with rule to install odex
+    include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
+
+    ifdef LOCAL_DEX_PREOPT
+      ifneq ($(dexpreopt_boot_jar_module),) # boot jar
+        # boot jar's rules are defined in dex_preopt.mk
+        dexpreopted_boot_jar := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(dexpreopt_boot_jar_module)_nodex.jar
+        $(eval $(call copy-one-file,$(dexpreopted_boot_jar),$(LOCAL_BUILT_MODULE)))
+
+        # For libart boot jars, we don't have .odex files.
+      else # ! boot jar
+        $(built_odex): PRIVATE_MODULE := $(LOCAL_MODULE)
+        # Use pattern rule - we may have multiple built odex files.
+$(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(common_javalib.jar)
+	@echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)"
+	$(call dexpreopt-one-file,$<,$@)
+
+       $(eval $(call dexpreopt-copy-jar,$(common_javalib.jar),$(LOCAL_BUILT_MODULE),$(LOCAL_DEX_PREOPT)))
+      endif # ! boot jar
+    else # LOCAL_DEX_PREOPT
+      $(eval $(call copy-one-file,$(common_javalib.jar),$(LOCAL_BUILT_MODULE)))
+    endif # LOCAL_DEX_PREOPT
+  else # LOCAL_IS_HOST_MODULE
+    $(eval $(call copy-one-file,$(LOCAL_SOONG_DEX_JAR),$(LOCAL_BUILT_MODULE)))
+    $(eval $(call add-dependency,$(LOCAL_BUILT_MODULE),$(full_classes_jar) $(full_classes_header_jar)))
+  endif
+
+  java-dex : $(LOCAL_BUILT_MODULE)
 else
-$(eval $(call copy-one-file,$(full_classes_jar),$(LOCAL_BUILT_MODULE)))
+  $(eval $(call copy-one-file,$(full_classes_jar),$(LOCAL_BUILT_MODULE)))
 endif
 
 javac-check : $(full_classes_jar)
diff --git a/core/static_java_library.mk b/core/static_java_library.mk
index ca3b071..c402dce 100644
--- a/core/static_java_library.mk
+++ b/core/static_java_library.mk
@@ -168,6 +168,7 @@
 
 $(LOCAL_BUILT_MODULE): $(R_file_stamp)
 $(java_source_list_file): $(R_file_stamp)
+$(foreach x,$(sharded_java_source_list_files),$(eval $(x): $(R_file_stamp)))
 $(full_classes_compiled_jar): $(R_file_stamp)
 $(full_classes_turbine_jar): $(R_file_stamp)
 
diff --git a/core/tasks/boot_jars_package_check.mk b/core/tasks/boot_jars_package_check.mk
index 188c267..dc79e23 100644
--- a/core/tasks/boot_jars_package_check.mk
+++ b/core/tasks/boot_jars_package_check.mk
@@ -24,8 +24,8 @@
 stamp := $(intermediates)/stamp
 built_boot_jars := $(foreach j, $(PRODUCT_BOOT_JARS), \
   $(call intermediates-dir-for, JAVA_LIBRARIES, $(j),,COMMON)/classes.jar)
-script := build/core/tasks/check_boot_jars/check_boot_jars.py
-whitelist_file := build/core/tasks/check_boot_jars/package_whitelist.txt
+script := build/make/core/tasks/check_boot_jars/check_boot_jars.py
+whitelist_file := build/make/core/tasks/check_boot_jars/package_whitelist.txt
 
 $(stamp): PRIVATE_BOOT_JARS := $(built_boot_jars)
 $(stamp): PRIVATE_SCRIPT := $(script)
diff --git a/core/tasks/tools/build_custom_image.mk b/core/tasks/tools/build_custom_image.mk
index 370934b..7c38546 100644
--- a/core/tasks/tools/build_custom_image.mk
+++ b/core/tasks/tools/build_custom_image.mk
@@ -135,6 +135,7 @@
 	    echo "verity_block_device=$(PRIVATE_VERITY_BLOCK_DEVICE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt)
 	$(if $(PRIVATE_SUPPORT_VERITY_FEC),\
 	  $(hide) echo "verity_fec=$(PRIVATE_SUPPORT_VERITY_FEC)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt)
+	$(if $(filter eng, $(TARGET_BUILD_VARIANT)),$(hide) echo "verity_disable=true" >> $(PRIVATE_INTERMEDIATES)/image_info.txt)
 	$(hide) echo "avb_avbtool=$(PRIVATE_AVB_AVBTOOL)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt
 	$(if $(PRIVATE_AVB_KEY_PATH),\
 	  $(hide) echo "avb_key_path=$(PRIVATE_AVB_KEY_PATH)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\
diff --git a/envsetup.sh b/envsetup.sh
index 9bb0d24..47bbdc0 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -51,20 +51,18 @@
     cached_vars=`cat $T/build/envsetup.sh | tr '()' '  ' | awk '{for(i=1;i<=NF;i++) if($i~/get_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`
     cached_abs_vars=`cat $T/build/envsetup.sh | tr '()' '  ' | awk '{for(i=1;i<=NF;i++) if($i~/get_abs_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`
     # Call the build system to dump the "<val>=<value>" pairs as a shell script.
-    build_dicts_script=`\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
-                        command make --no-print-directory -f build/core/config.mk \
-                        dump-many-vars \
-                        DUMP_MANY_VARS="$cached_vars" \
-                        DUMP_MANY_ABS_VARS="$cached_abs_vars" \
-                        DUMP_VAR_PREFIX="var_cache_" \
-                        DUMP_ABS_VAR_PREFIX="abs_var_cache_"`
+    build_dicts_script=`\cd $T; build/soong/soong_ui.bash --dumpvars-mode \
+                        --vars="$cached_vars" \
+                        --abs-vars="$cached_abs_vars" \
+                        --var-prefix=var_cache_ \
+                        --abs-var-prefix=abs_var_cache_`
     local ret=$?
     if [ $ret -ne 0 ]
     then
         unset build_dicts_script
         return $ret
     fi
-    # Excute the script to store the "<val>=<value>" pairs as shell variables.
+    # Execute the script to store the "<val>=<value>" pairs as shell variables.
     eval "$build_dicts_script"
     ret=$?
     unset build_dicts_script
@@ -105,8 +103,7 @@
         echo "Couldn't locate the top of the tree.  Try setting TOP." >&2
         return
     fi
-    (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
-      command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
+    (\cd $T; build/soong/soong_ui.bash --dumpvar-mode --abs $1)
 }
 
 # Get the exact value of a build variable.
@@ -123,8 +120,7 @@
         echo "Couldn't locate the top of the tree.  Try setting TOP." >&2
         return
     fi
-    (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
-      command make --no-print-directory -f build/core/config.mk dumpvar-$1)
+    (\cd $T; build/soong/soong_ui.bash --dumpvar-mode $1)
 }
 
 # check to see if the supplied product is one we can build
@@ -649,11 +645,17 @@
 # Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
 function tapas()
 {
+    local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
     local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
     local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
     local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
     local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|arm64|x86_64|mips64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
 
+    if [ "$showHelp" != "" ]; then
+      $(gettop)/build/make/tapasHelp.sh
+      return
+    fi
+
     if [ $(echo $arch | wc -w) -gt 1 ]; then
         echo "tapas: Error: Multiple build archs supplied: $arch"
         return
@@ -700,7 +702,7 @@
 
 function gettop
 {
-    local TOPFILE=build/core/envsetup.mk
+    local TOPFILE=build/make/core/envsetup.mk
     if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
         # The following circumlocution ensures we remove symlinks from TOP.
         (cd $TOP; PWD= /bin/pwd)
@@ -734,7 +736,7 @@
         # Use scan-build to collect all static analyzer reports into directory
         # /tmp/scan-build-yyyy-mm-dd-hhmmss-*
         # The clang compiler passed by --use-analyzer here is not important.
-        # build/core/binary.mk will set CLANG_CXX and CLANG before calling
+        # build/make/core/binary.mk will set CLANG_CXX and CLANG before calling
         # c++-analyzer and ccc-analyzer.
         local CLANG_VERSION=$(get_build_var LLVM_PREBUILTS_VERSION)
         local BUILD_OS=$(get_build_var BUILD_OS)
@@ -760,7 +762,7 @@
 
 function findmakefile()
 {
-    local TOPFILE=build/core/envsetup.mk
+    local TOPFILE=build/make/core/envsetup.mk
     local HERE=$PWD
     local T=
     while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
@@ -970,7 +972,7 @@
 
 function cproj()
 {
-    local TOPFILE=build/core/envsetup.mk
+    local TOPFILE=build/make/core/envsetup.mk
     local HERE=$PWD
     local T=
     while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
diff --git a/tapasHelp.sh b/tapasHelp.sh
new file mode 100755
index 0000000..058ac1d
--- /dev/null
+++ b/tapasHelp.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+# locate some directories
+cd "$(dirname $0)"
+SCRIPT_DIR="${PWD}"
+cd ../..
+TOP="${PWD}"
+
+message='usage: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]
+
+tapas selects individual apps to be built by the Android build system. Unlike
+"lunch", "tapas" does not request the building of images for a device.
+Additionally, an app built with "tapas" will have its dex file inside its apk,
+which should cause it to be suitable for installing on any api-compatible
+device. In other words, "tapas" configures the build of unbundled apps.
+
+The names <App1> <App2> ... should match LOCAL_PACKAGE_NAME as defined in an
+Android.mk
+
+The usage of the other arguments matches that of the rest of the platform
+build system and can be found by running `m help`'
+
+echo "$message"
diff --git a/target/board/generic/BoardConfig.mk b/target/board/generic/BoardConfig.mk
index 8bb3ed0..331f082 100644
--- a/target/board/generic/BoardConfig.mk
+++ b/target/board/generic/BoardConfig.mk
@@ -34,7 +34,7 @@
 ifeq ($(HOST_OS),linux)
   ifeq ($(WITH_DEXPREOPT),)
     WITH_DEXPREOPT := true
-    WITH_DEXPREOPT_BOOT_IMG_ONLY := false
+    WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY := false
   endif
 endif
 
diff --git a/target/board/generic/sepolicy/OWNERS b/target/board/generic/sepolicy/OWNERS
new file mode 100644
index 0000000..4bd7e34
--- /dev/null
+++ b/target/board/generic/sepolicy/OWNERS
@@ -0,0 +1,6 @@
+nnk@google.com
+jeffv@google.com
+klyubin@google.com
+dcashman@google.com
+jbires@google.com
+sspatil@google.com
diff --git a/target/board/generic/sepolicy/domain.te b/target/board/generic/sepolicy/domain.te
index 5d5e4ac..3706dba 100644
--- a/target/board/generic/sepolicy/domain.te
+++ b/target/board/generic/sepolicy/domain.te
@@ -1,6 +1,3 @@
-# For /sys/qemu_trace files in the emulator.
-allow domain sysfs_writable:dir search;
-allow domain sysfs_writable:file rw_file_perms;
 allow domain qemu_device:chr_file rw_file_perms;
 
 get_prop(domain, qemu_prop)
diff --git a/target/board/generic/sepolicy/file.te b/target/board/generic/sepolicy/file.te
deleted file mode 100644
index f4ae9e4..0000000
--- a/target/board/generic/sepolicy/file.te
+++ /dev/null
@@ -1 +0,0 @@
-type sysfs_writable, fs_type, sysfs_type, mlstrustedobject;
diff --git a/target/board/generic/sepolicy/file_contexts b/target/board/generic/sepolicy/file_contexts
index f550f4d..a9b1472 100644
--- a/target/board/generic/sepolicy/file_contexts
+++ b/target/board/generic/sepolicy/file_contexts
@@ -15,7 +15,6 @@
 /dev/qemu_.*                 u:object_r:qemu_device:s0
 /dev/ttyGF[0-9]*             u:object_r:serial_device:s0
 /dev/ttyS2                   u:object_r:console_device:s0
-/sys/qemu_trace(/.*)?        u:object_r:sysfs_writable:s0
 /vendor/bin/init\.ranchu-core\.sh u:object_r:goldfish_setup_exec:s0
 /vendor/bin/init\.ranchu-net\.sh u:object_r:goldfish_setup_exec:s0
 /vendor/bin/qemu-props       u:object_r:qemu_props_exec:s0
diff --git a/target/board/generic/sepolicy/qemu_props.te b/target/board/generic/sepolicy/qemu_props.te
index 0f5ec8c..33055c8 100644
--- a/target/board/generic/sepolicy/qemu_props.te
+++ b/target/board/generic/sepolicy/qemu_props.te
@@ -4,6 +4,7 @@
 
 init_daemon_domain(qemu_props)
 
+set_prop(qemu_props, opengles_prop)
 set_prop(qemu_props, qemu_prop)
 set_prop(qemu_props, dalvik_prop)
 set_prop(qemu_props, qemu_cmdline)
diff --git a/target/board/generic_arm64/BoardConfig.mk b/target/board/generic_arm64/BoardConfig.mk
index 2feba6b..d6df2cf 100644
--- a/target/board/generic_arm64/BoardConfig.mk
+++ b/target/board/generic_arm64/BoardConfig.mk
@@ -65,7 +65,7 @@
 ifeq ($(HOST_OS),linux)
   ifeq ($(WITH_DEXPREOPT),)
     WITH_DEXPREOPT := true
-    WITH_DEXPREOPT_BOOT_IMG_ONLY := false
+    WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY := false
   endif
 endif
 
diff --git a/target/board/generic_arm64_a/BoardConfig.mk b/target/board/generic_arm64_a/BoardConfig.mk
index fbac417..88bd87c 100644
--- a/target/board/generic_arm64_a/BoardConfig.mk
+++ b/target/board/generic_arm64_a/BoardConfig.mk
@@ -63,8 +63,6 @@
 
 BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1610612736	# 1.5 GB
 
-# TODO(b/35790399): remove when b/35790399 is fixed.
-BOARD_NAND_SPARE_SIZE := 0
 BOARD_FLASH_BLOCK_SIZE := 512
 
 BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED := true
diff --git a/target/board/generic_arm64_ab/BoardConfig.mk b/target/board/generic_arm64_ab/BoardConfig.mk
index 99dbe9f..dafd592 100644
--- a/target/board/generic_arm64_ab/BoardConfig.mk
+++ b/target/board/generic_arm64_ab/BoardConfig.mk
@@ -74,8 +74,6 @@
 # Fix this!
 BOARD_SYSTEMIMAGE_PARTITION_SIZE := 2147483648
 
-# TODO(b/35790399): remove when b/35790399 is fixed.
-BOARD_NAND_SPARE_SIZE := 0
 BOARD_FLASH_BLOCK_SIZE := 512
 
 BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED := true
diff --git a/target/board/generic_arm64_ab/sepolicy/OWNERS b/target/board/generic_arm64_ab/sepolicy/OWNERS
new file mode 100644
index 0000000..4bd7e34
--- /dev/null
+++ b/target/board/generic_arm64_ab/sepolicy/OWNERS
@@ -0,0 +1,6 @@
+nnk@google.com
+jeffv@google.com
+klyubin@google.com
+dcashman@google.com
+jbires@google.com
+sspatil@google.com
diff --git a/target/board/generic_arm_a/BoardConfig.mk b/target/board/generic_arm_a/BoardConfig.mk
index 6c1b36f..6530e6e 100644
--- a/target/board/generic_arm_a/BoardConfig.mk
+++ b/target/board/generic_arm_a/BoardConfig.mk
@@ -55,8 +55,6 @@
 
 BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1610612736
 
-# TODO(b/35790399): remove when b/35790399 is fixed.
-BOARD_NAND_SPARE_SIZE := 0
 BOARD_FLASH_BLOCK_SIZE := 512
 
 BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED := true
diff --git a/target/board/generic_mips/BoardConfig.mk b/target/board/generic_mips/BoardConfig.mk
index a9e46b4..fb66d21 100644
--- a/target/board/generic_mips/BoardConfig.mk
+++ b/target/board/generic_mips/BoardConfig.mk
@@ -42,7 +42,7 @@
 ifeq ($(HOST_OS),linux)
   ifeq ($(WITH_DEXPREOPT),)
     WITH_DEXPREOPT := true
-    WITH_DEXPREOPT_BOOT_IMG_ONLY := false
+    WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY := false
   endif
 endif
 
diff --git a/target/board/generic_mips64/BoardConfig.mk b/target/board/generic_mips64/BoardConfig.mk
index 6cb6c11..67bb51f 100644
--- a/target/board/generic_mips64/BoardConfig.mk
+++ b/target/board/generic_mips64/BoardConfig.mk
@@ -57,7 +57,7 @@
 ifeq ($(HOST_OS),linux)
   ifeq ($(WITH_DEXPREOPT),)
     WITH_DEXPREOPT := true
-    WITH_DEXPREOPT_BOOT_IMG_ONLY := false
+    WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY := false
   endif
 endif
 
diff --git a/target/board/generic_x86/BoardConfig.mk b/target/board/generic_x86/BoardConfig.mk
index bb2166b..000a9a3 100644
--- a/target/board/generic_x86/BoardConfig.mk
+++ b/target/board/generic_x86/BoardConfig.mk
@@ -22,7 +22,7 @@
 # of an SDK AVD. Note that this operation only works on Linux for now
 ifeq ($(HOST_OS),linux)
 WITH_DEXPREOPT ?= true
-WITH_DEXPREOPT_BOOT_IMG_ONLY ?= false
+WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY ?= false
 endif
 
 TARGET_USES_HWC2 := true
diff --git a/target/board/generic_x86/sepolicy/OWNERS b/target/board/generic_x86/sepolicy/OWNERS
new file mode 100644
index 0000000..4bd7e34
--- /dev/null
+++ b/target/board/generic_x86/sepolicy/OWNERS
@@ -0,0 +1,6 @@
+nnk@google.com
+jeffv@google.com
+klyubin@google.com
+dcashman@google.com
+jbires@google.com
+sspatil@google.com
diff --git a/target/board/generic_x86_64/BoardConfig.mk b/target/board/generic_x86_64/BoardConfig.mk
index b49a10c..883dd2e 100755
--- a/target/board/generic_x86_64/BoardConfig.mk
+++ b/target/board/generic_x86_64/BoardConfig.mk
@@ -28,7 +28,7 @@
 # of an SDK AVD. Note that this operation only works on Linux for now
 ifeq ($(HOST_OS),linux)
 WITH_DEXPREOPT ?= true
-WITH_DEXPREOPT_BOOT_IMG_ONLY ?= false
+WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY ?= false
 endif
 
 TARGET_USES_HWC2 := true
diff --git a/target/board/generic_x86_arm/BoardConfig.mk b/target/board/generic_x86_arm/BoardConfig.mk
index 4a2e159..847ad80 100644
--- a/target/board/generic_x86_arm/BoardConfig.mk
+++ b/target/board/generic_x86_arm/BoardConfig.mk
@@ -39,7 +39,7 @@
 ifeq ($(HOST_OS),linux)
   ifeq ($(WITH_DEXPREOPT),)
     WITH_DEXPREOPT := true
-    WITH_DEXPREOPT_BOOT_IMG_ONLY := false
+    WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY := false
   endif
 endif
 
diff --git a/target/product/base.mk b/target/product/base.mk
index 0e3647d..a182f18 100644
--- a/target/product/base.mk
+++ b/target/product/base.mk
@@ -150,7 +150,8 @@
 PRODUCT_PACKAGES_DEBUG := \
     logpersist.start \
     perfprofd \
-    sqlite3
+    sqlite3 \
+    strace
 
 PRODUCT_COPY_FILES := $(call add-to-product-copy-files-if-exists,\
     frameworks/base/config/preloaded-classes:system/etc/preloaded-classes)
diff --git a/target/product/core.mk b/target/product/core.mk
index a2b0f1c..cab8d97 100644
--- a/target/product/core.mk
+++ b/target/product/core.mk
@@ -45,7 +45,6 @@
     Launcher2 \
     ManagedProvisioning \
     MtpDocumentsProvider \
-    PicoTts \
     PacProcessor \
     libpac \
     PrintSpooler \
diff --git a/target/product/core_minimal.mk b/target/product/core_minimal.mk
index 523df7a..dd23a35 100644
--- a/target/product/core_minimal.mk
+++ b/target/product/core_minimal.mk
@@ -60,7 +60,6 @@
     iptables \
     gatekeeperd \
     keystore \
-    keystore.default \
     ld.config.txt \
     ld.mc \
     libaaudio \
diff --git a/target/product/core_tiny.mk b/target/product/core_tiny.mk
index 5ced1a6..e49ef19 100644
--- a/target/product/core_tiny.mk
+++ b/target/product/core_tiny.mk
@@ -59,7 +59,6 @@
     iptables \
     gatekeeperd \
     keystore \
-    keystore.default \
     ld.mc \
     libaaudio \
     libOpenMAXAL \
diff --git a/target/product/full_base.mk b/target/product/full_base.mk
index 65bdf0f..f2652eb 100644
--- a/target/product/full_base.mk
+++ b/target/product/full_base.mk
@@ -48,9 +48,6 @@
 # Get some sounds
 $(call inherit-product-if-exists, frameworks/base/data/sounds/AllAudio.mk)
 
-# Get the TTS language packs
-$(call inherit-product-if-exists, external/svox/pico/lang/all_pico_languages.mk)
-
 # Get a list of languages.
 $(call inherit-product, $(SRC_TARGET_DIR)/product/locales_full.mk)
 
diff --git a/target/product/sdk_base.mk b/target/product/sdk_base.mk
index 93356d6..44ee3f8 100644
--- a/target/product/sdk_base.mk
+++ b/target/product/sdk_base.mk
@@ -118,14 +118,6 @@
 $(call inherit-product-if-exists, frameworks/webview/chromium/chromium.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/product/core.mk)
 
-# include available languages for TTS in the system image
--include external/svox/pico/lang/PicoLangDeDeInSystem.mk
--include external/svox/pico/lang/PicoLangEnGBInSystem.mk
--include external/svox/pico/lang/PicoLangEnUsInSystem.mk
--include external/svox/pico/lang/PicoLangEsEsInSystem.mk
--include external/svox/pico/lang/PicoLangFrFrInSystem.mk
--include external/svox/pico/lang/PicoLangItItInSystem.mk
-
 # locale. en_US is both first and in alphabetical order to
 # ensure this is the default locale.
 PRODUCT_LOCALES := \
diff --git a/target/product/security/README b/target/product/security/README
index 15f2e93..6a6e62d 100644
--- a/target/product/security/README
+++ b/target/product/security/README
@@ -34,5 +34,5 @@
     $ java -jar out/host/linux-x86/framework/dumpkey.jar build/target/product/security/testkey.x509.pem
     {64,0xc926ad21,{1795090719,2141396315,950055447,2581568430,4268923165,1920809988,546586521,3498997798,1776797858,3740060814,1805317999,1429410244,129622599,1422441418,1783893377,1222374759,2563319927,323993566,28517732,609753416,1826472888,215237850,4261642700,4049082591,3228462402,774857746,154822455,2497198897,2758199418,3019015328,2794777644,87251430,2534927978,120774784,571297800,3695899472,2479925187,3811625450,3401832990,2394869647,3267246207,950095497,555058928,414729973,1136544882,3044590084,465547824,4058146728,2731796054,1689838846,3890756939,1048029507,895090649,247140249,178744550,3547885223,3165179243,109881576,3944604415,1044303212,3772373029,2985150306,3737520932,3599964420},{3437017481,3784475129,2800224972,3086222688,251333580,2131931323,512774938,325948880,2657486437,2102694287,3820568226,792812816,1026422502,2053275343,2800889200,3113586810,165549746,4273519969,4065247892,1902789247,772932719,3941848426,3652744109,216871947,3164400649,1942378755,3996765851,1055777370,964047799,629391717,2232744317,3910558992,191868569,2758883837,3682816752,2997714732,2702529250,3570700455,3776873832,3924067546,3555689545,2758825434,1323144535,61311905,1997411085,376844204,213777604,4077323584,9135381,1625809335,2804742137,2952293945,1117190829,4237312782,1825108855,3013147971,1111251351,2568837572,1684324211,2520978805,367251975,810756730,2353784344,1175080310}}
 
-This is called by build/core/Makefile to incorporate the OTA signing keys
+This is called by build/make/core/Makefile to incorporate the OTA signing keys
 into the recovery image.
diff --git a/target/product/verity.mk b/target/product/verity.mk
index 0badb9f..d954159 100644
--- a/target/product/verity.mk
+++ b/target/product/verity.mk
@@ -14,20 +14,16 @@
 # limitations under the License.
 #
 
-# Provides dependencies necessary for verified boot (only for user and
-# userdebug builds)
+# Provides dependencies necessary for verified boot.
 
-user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT))
-ifneq (,$(user_variant))
-    PRODUCT_SUPPORTS_BOOT_SIGNER := true
-    PRODUCT_SUPPORTS_VERITY := true
-    PRODUCT_SUPPORTS_VERITY_FEC := true
+PRODUCT_SUPPORTS_BOOT_SIGNER := true
+PRODUCT_SUPPORTS_VERITY := true
+PRODUCT_SUPPORTS_VERITY_FEC := true
 
-    # The dev key is used to sign boot and recovery images, and the verity
-    # metadata table. Actual product deliverables will be re-signed by hand.
-    # We expect this file to exist with the suffixes ".x509.pem" and ".pk8".
-    PRODUCT_VERITY_SIGNING_KEY := build/target/product/security/verity
+# The dev key is used to sign boot and recovery images, and the verity
+# metadata table. Actual product deliverables will be re-signed by hand.
+# We expect this file to exist with the suffixes ".x509.pem" and ".pk8".
+PRODUCT_VERITY_SIGNING_KEY := build/target/product/security/verity
 
-    PRODUCT_PACKAGES += \
-            verity_key
-endif
+PRODUCT_PACKAGES += \
+        verity_key
diff --git a/target/product/vndk/Android.mk b/target/product/vndk/Android.mk
index 20e8436..e7f07e7 100644
--- a/target/product/vndk/Android.mk
+++ b/target/product/vndk/Android.mk
@@ -1,7 +1,101 @@
+ifneq ($(BOARD_VNDK_VERSION),)
 LOCAL_PATH:= $(call my-dir)
 
-include $(CLEAR_VARS)
+#####################################################################
+# Setting the VNDK version. Version is 10000.0 for not-yet-published
+# platform and xx.y for released platform.
+vndk_major_ver := 10000
+vndk_minor_ver := 0
 
+#TODO(b/68027291): Revive this check when we have stable VNDK in P or later.
+#ifneq ($(vndk_major_ver), $(PLATFORM_SDK_VERSION))
+#$(error vndk_major_version does not match PLATFORM_SDK_VERSION, please update.)
+#endif
+
+ifneq (REL,$(PLATFORM_VERSION_CODENAME))
+    vndk_major_ver := 10000
+    vndk_minor_ver := 0
+endif
+PLATFORM_VNDK_VERSION := $(vndk_major_ver).$(vndk_minor_ver)
+vndk_major_ver :=
+vndk_minor_ver :=
+
+#####################################################################
+# Create the list of vndk libraries from the source code.
+INTERNAL_VNDK_LIB_LIST := $(call intermediates-dir-for,PACKAGING,vndk)/libs.txt
+$(INTERNAL_VNDK_LIB_LIST):
+	@echo "Generate: $@"
+	@mkdir -p $(dir $@)
+	$(hide) echo -n > $@
+	$(hide) $(foreach lib, $(LLNDK_LIBRARIES), \
+	  echo LLNDK: $(lib).so >> $@;)
+	$(hide) $(foreach lib, $(VNDK_SAMEPROCESS_LIBRARIES), \
+	  echo VNDK-SP: $(lib).so >> $@;)
+	$(hide) $(foreach lib, $(VNDK_CORE_LIBRARIES), \
+	  echo VNDK-core: $(lib).so >> $@;)
+	$(hide) $(foreach lib, $(VNDK_PRIVATE_LIBRARIES), \
+	  echo VNDK-private: $(lib).so >> $@;)
+
+#####################################################################
+# This is the up-to-date list of vndk libs.
+# TODO(b/62012285): the lib list should be stored somewhere under
+# /prebuilts/vndk
+LATEST_VNDK_LIB_LIST := $(LOCAL_PATH)/$(PLATFORM_VNDK_VERSION).txt
+
+#####################################################################
+# Check the generate list against the latest list stored in the
+# source tree
+.PHONY: check-vndk-list
+
+ifeq (REL,$(PLATFORM_VERSION_CODENAME))
+# The check is enforced in release branches
+droidcore: check-vndk-list
+endif
+
+check-vndk-list-timestamp := $(call intermediates-dir-for,PACKAGING,vndk)/check-list-timestamp
+check-vndk-list: $(check-vndk-list-timestamp)
+
+_vndk_check_failure_message := "VNDK library list has changed."
+ifeq (REL,$(PLATFORM_VERSION_CODENAME)
+_vndk_check_failure_message += "This isn't allowed in API locked branches."
+else
+_vndk_check_failure_message += "Run update-vndk-list.sh to update the list."
+endif
+
+$(check-vndk-list-timestamp): $(INTERNAL_VNDK_LIB_LIST) $(LATEST_VNDK_LIB_LIST) $(HOST_OUT_EXECUTABLES)/update-vndk-list.sh
+	$(hide) ( diff --old-line-format="Removed %L" \
+	  --new-line-format="Added %L" \
+	  --unchanged-line-format="" \
+	  $(LATEST_VNDK_LIB_LIST) $(INTERNAL_VNDK_LIB_LIST) \
+	  || ( echo $(_vndk_check_failure_message); exit 1 ))
+	$(hide) mkdir -p $(dir $@)
+	$(hide) touch $@
+
+#####################################################################
+# Script to update the latest VNDK lib list
+include $(CLEAR_VARS)
+LOCAL_MODULE := update-vndk-list.sh
+LOCAL_MODULE_CLASS := EXECUTABLES
+LOCAL_MODULE_STEM := $(LOCAL_MODULE)
+LOCAL_IS_HOST_MODULE := true
+include $(BUILD_SYSTEM)/base_rules.mk
+$(LOCAL_BUILT_MODULE): PRIVATE_INTERNAL_VNDK_LIB_LIST := $(INTERNAL_VNDK_LIB_LIST)
+$(LOCAL_BUILT_MODULE): PRIVATE_LATEST_VNDK_LIB_LIST := $(LATEST_VNDK_LIB_LIST)
+$(LOCAL_BUILT_MODULE):
+	@echo "Generate: $@"
+	@mkdir -p $(dir $@)
+	@rm -f $@
+	$(hide) echo "#!/bin/bash" > $@
+ifeq (REL,$(PLATFORM_VERSION_CODENAME))
+	$(hide) echo "echo Updating VNDK library list is NOT allowed in API locked branches." >> $@; \
+	        echo "exit 1" >> $@
+else
+	$(hide) echo "cp $(PRIVATE_INTERNAL_VNDK_LIB_LIST) $(PRIVATE_LATEST_VNDK_LIB_LIST)" >> $@; \
+	        echo "echo $(PRIVATE_LATEST_VNDK_LIB_LIST) updated." >> $@
+endif
+	@chmod a+x $@
+
+include $(CLEAR_VARS)
 LOCAL_MODULE := vndk_package
 LOCAL_REQUIRED_MODULES := \
     $(addsuffix .vendor,$(VNDK_CORE_LIBRARIES)) \
@@ -9,3 +103,4 @@
     $(LLNDK_LIBRARIES)
 
 include $(BUILD_PHONY_PACKAGE)
+endif # BOARD_VNDK_VERSION is set
diff --git a/tools/apicheck/etc/apicheck b/tools/apicheck/etc/apicheck
index c710c46..e4ffb77 100644
--- a/tools/apicheck/etc/apicheck
+++ b/tools/apicheck/etc/apicheck
@@ -18,7 +18,7 @@
 # and set up progdir to be the fully-qualified pathname of its directory.
 #
 # The classpath and other java options used in apicheck are specified in
-# build/core/tasks/apicheck.mk.
+# build/make/core/tasks/apicheck.mk.
 
 prog="$0"
 while [ -h "${prog}" ]; do
diff --git a/tools/post_process_props.py b/tools/post_process_props.py
index 83c6f9a..2d9451e 100755
--- a/tools/post_process_props.py
+++ b/tools/post_process_props.py
@@ -64,7 +64,7 @@
   buildprops = prop.to_dict()
   for key, value in buildprops.iteritems():
     # Check build properties' length.
-    if len(value) > PROP_VALUE_MAX:
+    if len(value) > PROP_VALUE_MAX and not key.startswith("ro."):
       check_pass = False
       sys.stderr.write("error: %s cannot exceed %d bytes: " %
                        (key, PROP_VALUE_MAX))
diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py
index 91213ba..d31a297 100755
--- a/tools/releasetools/add_img_to_target_files.py
+++ b/tools/releasetools/add_img_to_target_files.py
@@ -52,13 +52,13 @@
   sys.exit(1)
 
 import datetime
-import errno
 import hashlib
 import os
 import shlex
 import shutil
 import subprocess
 import tempfile
+import uuid
 import zipfile
 
 import build_image
@@ -214,22 +214,6 @@
 def CreateImage(input_dir, info_dict, what, output_file, block_list=None):
   print("creating " + what + ".img...")
 
-  # The name of the directory it is making an image out of matters to
-  # mkyaffs2image.  It wants "system" but we have a directory named
-  # "SYSTEM", so create a symlink.
-  temp_dir = tempfile.mkdtemp()
-  OPTIONS.tempfiles.append(temp_dir)
-  try:
-    os.symlink(os.path.join(input_dir, what.upper()),
-               os.path.join(temp_dir, what))
-  except OSError as e:
-    # bogus error on my mac version?
-    #   File "./build/tools/releasetools/img_from_target_files"
-    #     os.path.join(OPTIONS.input_tmp, "system"))
-    # OSError: [Errno 17] File exists
-    if e.errno == errno.EEXIST:
-      pass
-
   image_props = build_image.ImagePropFromGlobalDict(info_dict, what)
   fstab = info_dict["fstab"]
   mount_point = "/" + what
@@ -258,7 +242,20 @@
   if block_list:
     image_props["block_list"] = block_list.name
 
-  succ = build_image.BuildImage(os.path.join(temp_dir, what),
+  # Use repeatable ext4 FS UUID and hash_seed UUID (based on partition name and
+  # build fingerprint).
+  uuid_seed = what + "-"
+  if "build.prop" in info_dict:
+    build_prop = info_dict["build.prop"]
+    if "ro.build.fingerprint" in build_prop:
+      uuid_seed += build_prop["ro.build.fingerprint"]
+    elif "ro.build.thumbprint" in build_prop:
+      uuid_seed += build_prop["ro.build.thumbprint"]
+  image_props["uuid"] = str(uuid.uuid5(uuid.NAMESPACE_URL, uuid_seed))
+  hash_seed = "hash_seed-" + uuid_seed
+  image_props["hash_seed"] = str(uuid.uuid5(uuid.NAMESPACE_URL, hash_seed))
+
+  succ = build_image.BuildImage(os.path.join(input_dir, what.upper()),
                                 image_props, output_file.name)
   assert succ, "build " + what + ".img image failed"
 
@@ -308,21 +305,11 @@
   timestamp = (datetime.datetime(2009, 1, 1) - epoch).total_seconds()
   image_props["timestamp"] = int(timestamp)
 
-  # The name of the directory it is making an image out of matters to
-  # mkyaffs2image.  So we create a temp dir, and within it we create an
-  # empty dir named "data", or a symlink to the DATA dir,
-  # and build the image from that.
-  temp_dir = tempfile.mkdtemp()
-  OPTIONS.tempfiles.append(temp_dir)
-  user_dir = os.path.join(temp_dir, "data")
-  empty = (OPTIONS.info_dict.get("userdata_img_with_data") != "true")
-  if empty:
-    # Create an empty dir.
-    os.mkdir(user_dir)
+  if OPTIONS.info_dict.get("userdata_img_with_data") == "true":
+    user_dir = os.path.join(OPTIONS.input_tmp, "DATA")
   else:
-    # Symlink to the DATA dir.
-    os.symlink(os.path.join(OPTIONS.input_tmp, "DATA"),
-               user_dir)
+    user_dir = tempfile.mkdtemp()
+    OPTIONS.tempfiles.append(user_dir)
 
   fstab = OPTIONS.info_dict["fstab"]
   if fstab:
@@ -455,13 +442,8 @@
   timestamp = (datetime.datetime(2009, 1, 1) - epoch).total_seconds()
   image_props["timestamp"] = int(timestamp)
 
-  # The name of the directory it is making an image out of matters to
-  # mkyaffs2image.  So we create a temp dir, and within it we create an
-  # empty dir named "cache", and build the image from that.
-  temp_dir = tempfile.mkdtemp()
-  OPTIONS.tempfiles.append(temp_dir)
-  user_dir = os.path.join(temp_dir, "cache")
-  os.mkdir(user_dir)
+  user_dir = tempfile.mkdtemp()
+  OPTIONS.tempfiles.append(user_dir)
 
   fstab = OPTIONS.info_dict["fstab"]
   if fstab:
diff --git a/tools/releasetools/blockimgdiff.py b/tools/releasetools/blockimgdiff.py
index b8123c0..c95512d 100644
--- a/tools/releasetools/blockimgdiff.py
+++ b/tools/releasetools/blockimgdiff.py
@@ -717,6 +717,7 @@
       diff_total = len(diff_queue)
       patches = [None] * diff_total
       error_messages = []
+      warning_messages = []
       if sys.stdout.isatty():
         global diff_done
         diff_done = 0
@@ -750,16 +751,34 @@
             with open(tgt_file, "wb") as fd:
               self.tgt.WriteRangeDataToFd(tgt_ranges, fd)
 
+          message = []
           try:
             patch = compute_patch(src_file, tgt_file, imgdiff)
           except ValueError as e:
+            message.append(
+                "Failed to generate %s for %s: tgt=%s, src=%s:\n%s" % (
+                "imgdiff" if imgdiff else "bsdiff",
+                xf.tgt_name if xf.tgt_name == xf.src_name else
+                    xf.tgt_name + " (from " + xf.src_name + ")",
+                xf.tgt_ranges, xf.src_ranges, e.message))
+            # TODO(b/68016761): Better handle the holes in mke2fs created images.
+            if imgdiff:
+              try:
+                patch = compute_patch(src_file, tgt_file, imgdiff=False)
+                message.append(
+                    "Fell back and generated with bsdiff instead for %s" % (
+                    xf.tgt_name,))
+                with lock:
+                  warning_messages.extend(message)
+                del message[:]
+              except ValueError as e:
+                message.append(
+                    "Also failed to generate with bsdiff for %s:\n%s" % (
+                    xf.tgt_name, e.message))
+
+          if message:
             with lock:
-              error_messages.append(
-                  "Failed to generate %s for %s: tgt=%s, src=%s:\n%s" % (
-                      "imgdiff" if imgdiff else "bsdiff",
-                      xf.tgt_name if xf.tgt_name == xf.src_name else
-                          xf.tgt_name + " (from " + xf.src_name + ")",
-                      xf.tgt_ranges, xf.src_ranges, e.message))
+              error_messages.extend(message)
 
           with lock:
             patches[patch_index] = (xf_index, patch)
@@ -781,8 +800,15 @@
       if sys.stdout.isatty():
         print('\n')
 
+      if warning_messages:
+        print('WARNING:')
+        print('\n'.join(warning_messages))
+        print('\n\n\n')
+
       if error_messages:
+        print('ERROR:')
         print('\n'.join(error_messages))
+        print('\n\n\n')
         sys.exit(1)
     else:
       patches = []
diff --git a/tools/releasetools/build_image.py b/tools/releasetools/build_image.py
index 94626d7..a388f8a 100755
--- a/tools/releasetools/build_image.py
+++ b/tools/releasetools/build_image.py
@@ -225,12 +225,15 @@
   return True
 
 def BuildVerityMetadata(image_size, verity_metadata_path, root_hash, salt,
-                        block_device, signer_path, key, signer_args):
+                        block_device, signer_path, key, signer_args,
+                        verity_disable):
   cmd = ["system/extras/verity/build_verity_metadata.py", "build",
          str(image_size), verity_metadata_path, root_hash, salt, block_device,
          signer_path, key]
   if signer_args:
     cmd.append("--signer_args=\"%s\"" % (' '.join(signer_args),))
+  if verity_disable:
+    cmd.append("--verity_disable")
   output, exit_code = RunCommand(cmd)
   if exit_code != 0:
     print "Could not build verity metadata! Error: %s" % output
@@ -334,8 +337,10 @@
   # build the metadata blocks
   root_hash = prop_dict["verity_root_hash"]
   salt = prop_dict["verity_salt"]
+  verity_disable = "verity_disable" in prop_dict
   if not BuildVerityMetadata(image_size, verity_metadata_path, root_hash, salt,
-                             block_dev, signer_path, signer_key, signer_args):
+                             block_dev, signer_path, signer_key, signer_args,
+                             verity_disable):
     shutil.rmtree(tempdir_name, ignore_errors=True)
     return False
 
@@ -478,6 +483,12 @@
       build_command.extend(["-e", prop_dict["flash_erase_block_size"]])
     if "flash_logical_block_size" in prop_dict:
       build_command.extend(["-o", prop_dict["flash_logical_block_size"]])
+    # Specify UUID and hash_seed if using mke2fs.
+    if prop_dict["ext_mkuserimg"] == "mkuserimg_mke2fs.sh":
+      if "uuid" in prop_dict:
+        build_command.extend(["-U", prop_dict["uuid"]])
+      if "hash_seed" in prop_dict:
+        build_command.extend(["-S", prop_dict["hash_seed"]])
     if "selinux_fc" in prop_dict:
       build_command.append(prop_dict["selinux_fc"])
   elif fs_type.startswith("squash"):
@@ -644,6 +655,7 @@
       "verity_key",
       "verity_signer_cmd",
       "verity_fec",
+      "verity_disable",
       "avb_enable",
       "avb_avbtool",
       "avb_salt",
diff --git a/tools/signapk/Android.mk b/tools/signapk/Android.mk
index 051a51d..8082842 100644
--- a/tools/signapk/Android.mk
+++ b/tools/signapk/Android.mk
@@ -23,9 +23,9 @@
 LOCAL_JAR_MANIFEST := SignApk.mf
 LOCAL_STATIC_JAVA_LIBRARIES := \
     apksig \
-    bouncycastle-host \
-    bouncycastle-bcpkix-host \
-    conscrypt-host
+    bouncycastle \
+    bouncycastle-bcpkix \
+    conscrypt
 LOCAL_REQUIRED_MODULES := libconscrypt_openjdk_jni
 include $(BUILD_HOST_JAVA_LIBRARY)
 
diff --git a/tools/signtos/Android.mk b/tools/signtos/Android.mk
index 94ab944..3e869b3 100644
--- a/tools/signtos/Android.mk
+++ b/tools/signtos/Android.mk
@@ -21,5 +21,5 @@
 LOCAL_MODULE := signtos
 LOCAL_SRC_FILES := SignTos.java
 LOCAL_JAR_MANIFEST := SignTos.mf
-LOCAL_STATIC_JAVA_LIBRARIES := bouncycastle-host bouncycastle-bcpkix-host
+LOCAL_STATIC_JAVA_LIBRARIES := bouncycastle bouncycastle-bcpkix
 include $(BUILD_HOST_JAVA_LIBRARY)