Merge changes I30a83721,I1094f213

* changes:
  Validate args passed by jacoco.mk to rm -rf
  Implement validate-paths-are-subdirs
diff --git a/CleanSpec.mk b/CleanSpec.mk
index 23eba4f..3ba1f45 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -442,6 +442,8 @@
 $(call add-clean-step, rm -rf $(OUT_DIR)/host/common/obj/*/*_intermediates/src)
 $(call add-clean-step, rm -f $(OUT_DIR)/host/common/obj/*/*_intermediates/java-source-list)
 
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/APPS/*/flat-res)
+
 # ************************************************
 # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
 # ************************************************
diff --git a/core/Makefile b/core/Makefile
index cac6ba9..53db680 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -40,7 +40,9 @@
         $(eval _fulldest := $(call append-path,$(PRODUCT_OUT),$(_dest))) \
         $(if $(filter %.xml,$(_dest)),\
             $(eval $(call copy-xml-file-checked,$(_src),$(_fulldest))),\
-            $(eval $(call copy-one-file,$(_src),$(_fulldest)))) \
+            $(if $(and $(filter %.jar,$(_dest)),$(filter $(basename $(notdir $(_dest))),$(PRODUCT_LOADED_BY_PRIVILEGED_MODULES))),\
+                $(eval $(call copy-and-uncompress-dexs,$(_src),$(_fulldest))), \
+                $(eval $(call copy-one-file,$(_src),$(_fulldest))))) \
         $(eval ALL_DEFAULT_INSTALLED_MODULES += $(_fulldest)) \
         $(eval unique_product_copy_files_destinations += $(_dest))))
 unique_product_copy_files_pairs :=
@@ -275,7 +277,7 @@
 else
 system_prop_file := $(wildcard $(TARGET_DEVICE_DIR)/system.prop)
 endif
-$(intermediate_system_build_prop): $(VENDOR_BUILDINFO_SH) $(BUILDINFO_SH) $(INTERNAL_BUILD_ID_MAKEFILE) $(BUILD_SYSTEM)/version_defaults.mk $(system_prop_file) $(INSTALLED_ANDROID_INFO_TXT_TARGET)
+$(intermediate_system_build_prop): $(BUILDINFO_SH) $(INTERNAL_BUILD_ID_MAKEFILE) $(BUILD_SYSTEM)/version_defaults.mk $(system_prop_file) $(INSTALLED_ANDROID_INFO_TXT_TARGET)
 	@echo Target buildinfo: $@
 	@mkdir -p $(dir $@)
 	$(hide) echo > $@
@@ -319,16 +321,6 @@
 			TARGET_CPU_ABI2="$(TARGET_CPU_ABI2)" \
 			TARGET_AAPT_CHARACTERISTICS="$(TARGET_AAPT_CHARACTERISTICS)" \
 	        bash $(BUILDINFO_SH) >> $@
-ifndef property_overrides_split_enabled
-	$(hide) TARGET_DEVICE="$(TARGET_DEVICE)" \
-			PRODUCT_NAME="$(TARGET_PRODUCT)" \
-			PRODUCT_BRAND="$(PRODUCT_BRAND)" \
-			PRODUCT_MODEL="$(PRODUCT_MODEL)" \
-			PRODUCT_MANUFACTURER="$(PRODUCT_MANUFACTURER)" \
-			TARGET_BOOTLOADER_BOARD_NAME="$(TARGET_BOOTLOADER_BOARD_NAME)" \
-			TARGET_BOARD_PLATFORM="$(TARGET_BOARD_PLATFORM)" \
-	        bash $(VENDOR_BUILDINFO_SH) >> $@
-endif
 	$(hide) $(foreach file,$(system_prop_file), \
 		if [ -f "$(file)" ]; then \
 			echo "#" >> $@; \
@@ -357,11 +349,7 @@
 
 $(INSTALLED_BUILD_PROP_TARGET): $(intermediate_system_build_prop) $(INSTALLED_RECOVERYIMAGE_TARGET)
 	@echo "Target build info: $@"
-ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
 	$(hide) grep -v 'ro.product.first_api_level' $(intermediate_system_build_prop) > $@
-else
-	$(hide) cat $(intermediate_system_build_prop) > $@
-endif
 ifdef INSTALLED_RECOVERYIMAGE_TARGET
 	$(hide) echo ro.expect.recovery_id=`cat $(RECOVERYIMAGE_ID_FILE)` >> $@
 endif
@@ -370,7 +358,6 @@
 # vendor build.prop
 #
 # For verifying that the vendor build is what we think it is
-ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
 INSTALLED_VENDOR_BUILD_PROP_TARGET := $(TARGET_OUT_VENDOR)/build.prop
 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_VENDOR_BUILD_PROP_TARGET)
 
@@ -389,7 +376,6 @@
 	$(hide) echo ro.vendor.build.date=`$(DATE_FROM_FILE)`>>$@
 	$(hide) echo ro.vendor.build.date.utc=`$(DATE_FROM_FILE) +%s`>>$@
 	$(hide) echo ro.vendor.build.fingerprint="$(BUILD_FINGERPRINT_FROM_FILE)">>$@
-ifdef property_overrides_split_enabled
 	$(hide) TARGET_DEVICE="$(TARGET_DEVICE)" \
 			PRODUCT_NAME="$(TARGET_PRODUCT)" \
 			PRODUCT_BRAND="$(PRODUCT_BRAND)" \
@@ -398,6 +384,7 @@
 			TARGET_BOOTLOADER_BOARD_NAME="$(TARGET_BOOTLOADER_BOARD_NAME)" \
 			TARGET_BOARD_PLATFORM="$(TARGET_BOARD_PLATFORM)" \
 	        bash $(VENDOR_BUILDINFO_SH) >> $@
+ifdef property_overrides_split_enabled
 	$(hide) echo "#" >> $@; \
 	        echo "# ADDITIONAL VENDOR BUILD PROPERTIES" >> $@; \
 	        echo "#" >> $@;
@@ -405,7 +392,6 @@
 		echo "$(line)" >> $@;)
 	$(hide) build/tools/post_process_props.py $@
 endif  # property_overrides_split_enabled
-endif  # BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
 
 # ----------------------------------------------------------------
 
@@ -2111,8 +2097,6 @@
   $(HOST_OUT_JAVA_LIBRARIES)/signapk.jar \
   $(HOST_OUT_JAVA_LIBRARIES)/BootSignature.jar \
   $(HOST_OUT_JAVA_LIBRARIES)/VeritySigner.jar \
-  $(HOST_OUT_EXECUTABLES)/make_ext4fs \
-  $(HOST_OUT_EXECUTABLES)/mkuserimg.sh \
   $(HOST_OUT_EXECUTABLES)/mke2fs \
   $(HOST_OUT_EXECUTABLES)/mkuserimg_mke2fs.sh \
   $(HOST_OUT_EXECUTABLES)/e2fsdroid \
diff --git a/core/aapt2.mk b/core/aapt2.mk
index c7cae44..8bb2d4b 100644
--- a/core/aapt2.mk
+++ b/core/aapt2.mk
@@ -47,8 +47,10 @@
 my_generated_resources_flata += $(my_generated_resources_flata)
 endif
 
+# Always set --pseudo-localize, it will be stripped out later for release
+# builds that don't want it.
 $(my_res_resources_flat) $(my_overlay_resources_flat) $(my_generated_resources_flata): \
-  PRIVATE_AAPT2_CFLAGS := $(PRODUCT_AAPT2_CFLAGS)
+  PRIVATE_AAPT2_CFLAGS := --pseudo-localize
 
 my_static_library_resources := $(foreach l, $(call reverse-list,$(LOCAL_STATIC_ANDROID_LIBRARIES)),\
   $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/package-res.apk)
diff --git a/core/base_rules.mk b/core/base_rules.mk
index a178b55..a5ba75b 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -96,6 +96,13 @@
 # base_rules.mk, but it will fix the most common ones.
 LOCAL_ADDITIONAL_DEPENDENCIES := $(filter-out %.mk,$(LOCAL_ADDITIONAL_DEPENDENCIES))
 
+my_bad_deps := $(strip $(foreach dep,$(filter-out | ||,$(LOCAL_ADDITIONAL_DEPENDENCIES)),\
+                 $(if $(findstring /,$(dep)),,$(dep))))
+ifneq ($(my_bad_deps),)
+$(call pretty-warning,"Bad LOCAL_ADDITIONAL_DEPENDENCIES: $(my_bad_deps)")
+$(call pretty-error,"LOCAL_ADDITIONAL_DEPENDENCIES must only contain paths (not module names)")
+endif
+
 ###########################################################
 ## Validate and define fallbacks for input LOCAL_* variables.
 ###########################################################
diff --git a/core/clang/versions.mk b/core/clang/versions.mk
index c2473cd..f3a206a 100644
--- a/core/clang/versions.mk
+++ b/core/clang/versions.mk
@@ -1,4 +1,4 @@
 ## Clang/LLVM release versions.
 
-LLVM_PREBUILTS_VERSION ?= clang-4053586
+LLVM_PREBUILTS_VERSION ?= clang-4393122
 LLVM_PREBUILTS_BASE ?= prebuilts/clang/host
diff --git a/core/config.mk b/core/config.mk
index 4ff3648..1692f2f 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -3,6 +3,20 @@
 # current configuration and platform, which
 # are not specific to what is being built.
 
+ifndef KATI
+$(warning Directly using config.mk from make is no longer supported.)
+$(warning )
+$(warning If you are just attempting to build, you probably need to re-source envsetup.sh:)
+$(warning )
+$(warning $$ source build/envsetup.sh)
+$(warning )
+$(warning If you are attempting to emulate get_build_var, use one of the following:)
+$(warning $$ build/soong/soong_ui.bash --dumpvar-mode)
+$(warning $$ build/soong/soong_ui.bash --dumpvars-mode)
+$(warning )
+$(error done)
+endif
+
 # Only use ANDROID_BUILD_SHELL to wrap around bash.
 # DO NOT use other shells such as zsh.
 ifdef ANDROID_BUILD_SHELL
@@ -44,18 +58,6 @@
 # If a rule fails, delete $@.
 .DELETE_ON_ERROR:
 
-# Check for broken versions of make.
-ifndef KATI
-ifneq (1,$(strip $(shell expr $(MAKE_VERSION) \>= 3.81)))
-$(warning ********************************************************************************)
-$(warning *  You are using version $(MAKE_VERSION) of make.)
-$(warning *  Android can only be built by versions 3.81 and higher.)
-$(warning *  see https://source.android.com/source/download.html)
-$(warning ********************************************************************************)
-$(error stopping)
-endif
-endif
-
 # Used to force goals to build.  Only use for conditionally defined goals.
 .PHONY: FORCE
 FORCE:
@@ -511,6 +513,12 @@
 
 USE_PREBUILT_SDK_TOOLS_IN_PLACE := true
 
+# Work around for b/68406220
+# This should match the soong version.
+ifndef USE_D8
+  USE_D8 := true
+endif
+
 #
 # Tools that are prebuilts for TARGET_BUILD_APPS
 #
@@ -608,15 +616,9 @@
 endif
 APICHECK := $(HOST_OUT_EXECUTABLES)/apicheck$(HOST_EXECUTABLE_SUFFIX)
 FS_GET_STATS := $(HOST_OUT_EXECUTABLES)/fs_get_stats$(HOST_EXECUTABLE_SUFFIX)
-ifeq ($(TARGET_USES_MKE2FS),true)
 MAKE_EXT4FS := $(HOST_OUT_EXECUTABLES)/mke2fs$(HOST_EXECUTABLE_SUFFIX)
 MKEXTUSERIMG := $(HOST_OUT_EXECUTABLES)/mkuserimg_mke2fs.sh
 MKE2FS_CONF := system/extras/ext4_utils/mke2fs.conf
-else
-MAKE_EXT4FS := $(HOST_OUT_EXECUTABLES)/make_ext4fs$(HOST_EXECUTABLE_SUFFIX)
-MKEXTUSERIMG := $(HOST_OUT_EXECUTABLES)/mkuserimg.sh
-MKE2FS_CONF :=
-endif
 BLK_ALLOC_TO_BASE_FS := $(HOST_OUT_EXECUTABLES)/blk_alloc_to_base_fs$(HOST_EXECUTABLE_SUFFIX)
 MAKE_SQUASHFS := $(HOST_OUT_EXECUTABLES)/mksquashfs$(HOST_EXECUTABLE_SUFFIX)
 MKSQUASHFSUSERIMG := $(HOST_OUT_EXECUTABLES)/mksquashfsimage.sh
@@ -736,6 +738,9 @@
   FRAMEWORK_COMPATIBILITY_MATRIX_FILE := hardware/interfaces/compatibility_matrix.current.xml
 endif
 
+BUILD_NUMBER_FROM_FILE := $$(cat $(OUT_DIR)/build_number.txt)
+BUILD_DATETIME_FROM_FILE := $$(cat $(OUT_DIR)/build_date.txt)
+
 # ###############################################################
 # Set up final options.
 # ###############################################################
@@ -844,6 +849,17 @@
 RSCOMPAT_32BIT_ONLY_API_LEVELS := 8 9 10 11 12 13 14 15 16 17 18 19 20
 RSCOMPAT_NO_USAGEIO_API_LEVELS := 8 9 10 11 12 13
 
+# Add BUILD_NUMBER to apps default version name if it's unbundled build.
+ifdef TARGET_BUILD_APPS
+TARGET_BUILD_WITH_APPS_VERSION_NAME := true
+endif
+
+ifdef TARGET_BUILD_WITH_APPS_VERSION_NAME
+APPS_DEFAULT_VERSION_NAME := $(PLATFORM_VERSION)-$(BUILD_NUMBER_FROM_FILE)
+else
+APPS_DEFAULT_VERSION_NAME := $(PLATFORM_VERSION)
+endif
+
 ifeq ($(JAVA_NOT_REQUIRED),true)
 # Remove java and tools from our path so that we make sure nobody uses them.
 unexport ANDROID_JAVA_HOME
diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk
index f5b45db..fce0b5a 100644
--- a/core/config_sanitizers.mk
+++ b/core/config_sanitizers.mk
@@ -235,12 +235,21 @@
   # entire module.
   LOCAL_ARM_MODE := thumb
   my_cflags += $(CFI_EXTRA_CFLAGS)
+  # Only append the default visibility flag if -fvisibility has not already been
+  # set to hidden.
+  ifeq ($(filter -fvisibility=hidden,$(LOCAL_CFLAGS)),)
+    my_cflags += -fvisibility=default
+  endif
   my_ldflags += $(CFI_EXTRA_LDFLAGS)
   my_arflags += --plugin $(LLVM_PREBUILTS_PATH)/../lib64/LLVMgold.so
-  # Workaround for b/33678192. CFI jumptables need Thumb2 codegen.  Revert when
-  # Clang is updated past r290384.
-  ifneq ($(filter arm,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),)
-    my_ldflags += -march=armv7-a
+
+  ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
+        my_ldflags := $(filter-out -fsanitize-cfi-cross-dso,$(my_ldflags))
+        my_cflags := $(filter-out -fsanitize-cfi-cross-dso,$(my_cflags))
+  else
+        # Apply the version script to non-static executables
+        my_ldflags += -Wl,--version-script,build/soong/cc/config/cfi_exports.map
+        LOCAL_ADDITIONAL_DEPENDENCIES += build/soong/cc/config/cfi_exports.map
   endif
 endif
 
@@ -293,11 +302,16 @@
 endif
 
 ifneq ($(my_sanitize_diag),)
-  notrap_arg := $(subst $(space),$(comma),$(my_sanitize_diag)),
-  my_cflags += -fno-sanitize-trap=$(notrap_arg)
-  # Diagnostic requires a runtime library, unless ASan or TSan are also enabled.
-  ifeq ($(filter address thread,$(my_sanitize)),)
-    # Does not have to be the first DT_NEEDED unlike ASan.
-    my_shared_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_RUNTIME_LIBRARY)
+  # TODO(vishwath): Add diagnostic support for static executables once
+  # we switch to clang-4393122 (which adds the static ubsan runtime
+  # that this depends on)
+  ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
+    notrap_arg := $(subst $(space),$(comma),$(my_sanitize_diag)),
+    my_cflags += -fno-sanitize-trap=$(notrap_arg)
+    # Diagnostic requires a runtime library, unless ASan or TSan are also enabled.
+    ifeq ($(filter address thread,$(my_sanitize)),)
+      # Does not have to be the first DT_NEEDED unlike ASan.
+      my_shared_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_RUNTIME_LIBRARY)
+    endif
   endif
 endif
diff --git a/core/definitions.mk b/core/definitions.mk
index 12a8b1e..68854d8 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -1556,7 +1556,7 @@
         filelist="$$filelist $$ldir/$$ext$$f"; \
     done ; \
     $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
-        $(2) $$filelist
+        $(PRIVATE_ARFLAGS) $(2) $$filelist
 
 endef
 
@@ -2002,17 +2002,6 @@
 ## Commands for running javac to make .class files
 ###########################################################
 
-# Add BUILD_NUMBER to apps default version name if it's unbundled build.
-ifdef TARGET_BUILD_APPS
-TARGET_BUILD_WITH_APPS_VERSION_NAME := true
-endif
-
-ifdef TARGET_BUILD_WITH_APPS_VERSION_NAME
-APPS_DEFAULT_VERSION_NAME := $(PLATFORM_VERSION)-$(BUILD_NUMBER_FROM_FILE)
-else
-APPS_DEFAULT_VERSION_NAME := $(PLATFORM_VERSION)
-endif
-
 # b/37750224
 AAPT_ASAN_OPTIONS := ASAN_OPTIONS=detect_leaks=0
 
@@ -2385,7 +2374,6 @@
 endef
 
 # --add-opens is required because desugar reflects via java.lang.invoke.MethodHandles.Lookup
-# --desugar_try_with_resources_if_needed=false is needed due to b/63180735, b/63901645, b/63900665
 define desugar-classes-jar
 @echo Desugar: $@
 @mkdir -p $(dir $@)
@@ -2397,9 +2385,8 @@
     -Djdk.internal.lambda.dumpProxyClasses=$(abspath $(dir $@))/desugar_dumped_classes \
     -jar $(DESUGAR) \
     $(addprefix --bootclasspath_entry ,$(PRIVATE_BOOTCLASSPATH)) \
-    $(addprefix --classpath_entry ,$(PRIVATE_ALL_JAVA_HEADER_LIBRARIES)) \
-    --min_sdk_version $(call codename-or-sdk-to-sdk,$(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
-    --desugar_try_with_resources_if_needed=false \
+    $(addprefix --classpath_entry ,$(PRIVATE_SHARED_JAVA_HEADER_LIBRARIES)) \
+    --min_sdk_version $(call codename-or-sdk-to-sdk,$(PRIVATE_MIN_SDK_VERSION)) \
     --allow_empty_bootclasspath \
     $(if $(filter --core-library,$(PRIVATE_DX_FLAGS)),--core_library) \
     -i $< -o $@.tmp
@@ -2641,6 +2628,14 @@
 	$$(copy-file-to-target)
 endef
 
+define copy-and-uncompress-dexs
+$(2): $(1) $(ZIPALIGN)
+	@echo "Uncompress dexs in: $$@"
+	$$(copy-file-to-target)
+	$$(uncompress-dexs)
+	$$(align-package)
+endef
+
 # Copies many files.
 # $(1): The files to copy.  Each entry is a ':' separated src:dst pair
 # Evaluates to the list of the dst files (ie suitable for a dependency list)
@@ -2779,6 +2774,12 @@
 ###########################################################
 ## Commands to call Proguard
 ###########################################################
+ifeq ($(EXPERIMENTAL_USE_OPENJDK9),true)
+define transform-jar-to-proguard
+@echo Skipping Proguard: $<$(PRIVATE_PROGUARD_INJAR_FILTERS) $@
+$(hide) cp '$<' $@
+endef
+else
 define transform-jar-to-proguard
 @echo Proguard: $@
 $(hide) $(PROGUARD) -injars '$<$(PRIVATE_PROGUARD_INJAR_FILTERS)' \
@@ -2786,6 +2787,8 @@
     $(PRIVATE_PROGUARD_FLAGS) \
     $(addprefix -injars , $(PRIVATE_EXTRA_INPUT_JAR))
 endef
+endif
+
 
 ###########################################################
 ## Commands to call R8
diff --git a/core/dpi_specific_apk.mk b/core/dpi_specific_apk.mk
index 18c8d6e..ac5c4a9 100644
--- a/core/dpi_specific_apk.mk
+++ b/core/dpi_specific_apk.mk
@@ -9,7 +9,7 @@
 
 # Set up all the target-specific variables.
 $(built_dpi_apk): PRIVATE_MODULE := $(dpi_apk_name)
-$(built_dpi_apk): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) $(PRODUCT_AAPT_FLAGS) $($(LOCAL_PACKAGE_NAME)_aapt_flags_$(my_dpi))
+$(built_dpi_apk): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --pseudo-localize $($(LOCAL_PACKAGE_NAME)_aapt_flags_$(my_dpi))
 # Clear PRIVATE_PRODUCT_AAPT_CONFIG to include everything by default.
 $(built_dpi_apk): PRIVATE_PRODUCT_AAPT_CONFIG :=
 $(built_dpi_apk): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := $(my_dpi)
diff --git a/core/dumpvar.mk b/core/dumpvar.mk
index acae48e..59efb04 100644
--- a/core/dumpvar.mk
+++ b/core/dumpvar.mk
@@ -1,37 +1,3 @@
-
-# List of variables we want to print in the build banner.
-print_build_config_vars := \
-  PLATFORM_VERSION_CODENAME \
-  PLATFORM_VERSION \
-  TARGET_PRODUCT \
-  TARGET_BUILD_VARIANT \
-  TARGET_BUILD_TYPE \
-  TARGET_PLATFORM_VERSION \
-  TARGET_BUILD_APPS \
-  TARGET_ARCH \
-  TARGET_ARCH_VARIANT \
-  TARGET_CPU_VARIANT \
-  TARGET_2ND_ARCH \
-  TARGET_2ND_ARCH_VARIANT \
-  TARGET_2ND_CPU_VARIANT \
-  HOST_ARCH \
-  HOST_2ND_ARCH \
-  HOST_OS \
-  HOST_OS_EXTRA \
-  HOST_CROSS_OS \
-  HOST_CROSS_ARCH \
-  HOST_CROSS_2ND_ARCH \
-  HOST_BUILD_TYPE \
-  BUILD_ID \
-  OUT_DIR \
-  AUX_OS_VARIANT_LIST
-
-ifeq ($(TARGET_BUILD_PDK),true)
-print_build_config_vars += \
-  TARGET_BUILD_PDK \
-  PDK_FUSION_PLATFORM_ZIP
-endif
-
 # ---------------------------------------------------------------
 # the setpath shell function in envsetup.sh uses this to figure out
 # what to add to the path given the config we have chosen.
@@ -52,79 +18,14 @@
 ANDROID_PREBUILTS := prebuilt/$(HOST_PREBUILT_TAG)
 ANDROID_GCC_PREBUILTS := prebuilts/gcc/$(HOST_PREBUILT_TAG)
 
-# The "dumpvar" stuff lets you say something like
-#
-#     CALLED_FROM_SETUP=true \
-#       make -f config/envsetup.make dumpvar-TARGET_OUT
-# or
-#     CALLED_FROM_SETUP=true \
-#       make -f config/envsetup.make dumpvar-abs-HOST_OUT_EXECUTABLES
-#
-# The plain (non-abs) version just dumps the value of the named variable.
-# The "abs" version will treat the variable as a path, and dumps an
-# absolute path to it.
-#
-dumpvar_goals := \
-	$(strip $(patsubst dumpvar-%,%,$(filter dumpvar-%,$(MAKECMDGOALS))))
-ifdef dumpvar_goals
-
-  ifneq ($(words $(dumpvar_goals)),1)
-    $(error Only one "dumpvar-" goal allowed. Saw "$(MAKECMDGOALS)")
-  endif
-
-  # If the goal is of the form "dumpvar-abs-VARNAME", then
-  # treat VARNAME as a path and return the absolute path to it.
-  absolute_dumpvar := $(strip $(filter abs-%,$(dumpvar_goals)))
-  ifdef absolute_dumpvar
-    dumpvar_goals := $(patsubst abs-%,%,$(dumpvar_goals))
-    DUMPVAR_VALUE := $(abspath $($(dumpvar_goals)))
-    dumpvar_target := dumpvar-abs-$(dumpvar_goals)
-  else
-    DUMPVAR_VALUE := $($(dumpvar_goals))
-    dumpvar_target := dumpvar-$(dumpvar_goals)
-  endif
-
-.PHONY: $(dumpvar_target)
-$(dumpvar_target):
-	@echo $(DUMPVAR_VALUE)
-
-endif # dumpvar_goals
-
-ifneq ($(dumpvar_goals),report_config)
-PRINT_BUILD_CONFIG:=
-endif
-
-ifneq ($(filter report_config,$(DUMP_MANY_VARS)),)
-# Construct the shell commands that print the config banner.
-report_config_sh := echo '============================================';
-report_config_sh += $(foreach v,$(print_build_config_vars),echo '$v=$($(v))';)
-report_config_sh += echo '============================================';
-endif
-
 # Dump mulitple variables to "<var>=<value>" pairs, one per line.
 # The output may be executed as bash script.
 # Input variables:
 #   DUMP_MANY_VARS: the list of variable names.
 #   DUMP_VAR_PREFIX: an optional prefix of the variable name added to the output.
-#   DUMP_MANY_ABS_VARS: the list of abs variable names.
-#   DUMP_ABS_VAR_PREFIX: an optional prefix of the abs variable name added to the output.
 .PHONY: dump-many-vars
 dump-many-vars :
-	@$(foreach v, $(filter-out report_config, $(DUMP_MANY_VARS)),\
+	@$(foreach v, $(DUMP_MANY_VARS),\
 	  echo "$(DUMP_VAR_PREFIX)$(v)='$($(v))'";)
-ifneq ($(filter report_config, $(DUMP_MANY_VARS)),)
-	@# Construct a special variable for report_config.
-	@# Escape \` to defer the execution of report_config_sh to preserve the line breaks.
-	@echo "$(DUMP_VAR_PREFIX)report_config=\`$(report_config_sh)\`"
-endif
-	@$(foreach v, $(sort $(DUMP_MANY_ABS_VARS)),\
-	  echo "$(DUMP_ABS_VAR_PREFIX)$(v)='$(abspath $($(v)))'";)
 
 endif # CALLED_FROM_SETUP
-
-ifneq ($(PRINT_BUILD_CONFIG),)
-$(info ============================================)
-$(foreach v, $(print_build_config_vars),\
-  $(info $v=$($(v))))
-$(info ============================================)
-endif
diff --git a/core/host_dalvik_java_library.mk b/core/host_dalvik_java_library.mk
index 4bfe288..a522f0b 100644
--- a/core/host_dalvik_java_library.mk
+++ b/core/host_dalvik_java_library.mk
@@ -28,10 +28,6 @@
 include $(BUILD_SYSTEM)/host_java_library_common.mk
 #######################################
 
-ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
-  LOCAL_JAVA_LIBRARIES :=  core-oj-hostdex core-libart-hostdex $(LOCAL_JAVA_LIBRARIES)
-endif
-
 full_classes_turbine_jar := $(intermediates.COMMON)/classes-turbine.jar
 full_classes_header_jarjar := $(intermediates.COMMON)/classes-header-jarjar.jar
 full_classes_header_jar := $(intermediates.COMMON)/classes-header.jar
diff --git a/core/java.mk b/core/java.mk
index aa6331b..c12e0ee 100644
--- a/core/java.mk
+++ b/core/java.mk
@@ -18,25 +18,6 @@
 LOCAL_NO_STANDARD_LIBRARIES:=$(strip $(LOCAL_NO_STANDARD_LIBRARIES))
 LOCAL_SDK_VERSION:=$(strip $(LOCAL_SDK_VERSION))
 
-ifneq ($(LOCAL_MODULE),jacocoagent)
-  ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
-    ifeq ($(EMMA_INSTRUMENT),true)
-      ifneq ($(EMMA_INSTRUMENT_STATIC),true)
-        # For instrumented build, if Jacoco is not being included statically
-        # in instrumented packages then include Jacoco classes into the
-        # bootclasspath.
-        LOCAL_JAVA_LIBRARIES := jacocoagent $(LOCAL_JAVA_LIBRARIES)
-      endif # EMMA_INSTRUMENT_STATIC
-    endif # EMMA_INSTRUMENT
-  endif # !LOCAL_NO_STANDARD_LIBRARIES
-endif # LOCAL_MODULE == jacocoagent
-
-ifndef LOCAL_SDK_VERSION
-  ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
-    LOCAL_JAVA_LIBRARIES := $(TARGET_DEFAULT_JAVA_LIBRARIES) $(LOCAL_JAVA_LIBRARIES)
-  endif
-endif
-
 proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
 ifneq ($(proto_sources),)
 ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro)
@@ -574,6 +555,10 @@
 
 $(eval $(call copy-one-file,$(full_classes_jarjar_jar),$(full_classes_jar)))
 
+ifeq ($(EXPERIMENTAL_USE_OPENJDK9),true)
+LOCAL_DX_FLAGS := $(filter-out --multi-dex,$(LOCAL_DX_FLAGS)) --multi-dex
+endif
+
 my_desugaring :=
 ifndef LOCAL_IS_STATIC_JAVA_LIBRARY
 my_desugaring := true
@@ -605,33 +590,33 @@
 endif
 proguard_dictionary := $(intermediates.COMMON)/proguard_dictionary
 
-# Hack: see b/20667396
-# When an app's LOCAL_SDK_VERSION is lower than the support library's LOCAL_SDK_VERSION,
-# we artifically raises the "SDK version" "linked" by ProGuard, to
+# When an app contains references to APIs that are not in the SDK specified by
+# its LOCAL_SDK_VERSION for example added by support library or by runtime 
+# classes added by desugar, we artifically raise the "SDK version" "linked" by
+# ProGuard, to
 # - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version.
 # - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version.
-my_support_library_sdk_raise :=
-ifneq (,$(filter android-support-%,$(LOCAL_STATIC_JAVA_LIBRARIES)))
+# See b/20667396
+my_proguard_sdk_raise :=
 ifdef LOCAL_SDK_VERSION
 ifdef TARGET_BUILD_APPS
 ifeq (,$(filter current system_current test_current, $(LOCAL_SDK_VERSION)))
-  my_support_library_sdk_raise := $(call java-lib-header-files, sdk_vcurrent)
+  my_proguard_sdk_raise := $(call java-lib-header-files, sdk_vcurrent)
 endif
 else
   # For platform build, we can't just raise to the "current" SDK,
   # that would break apps that use APIs removed from the current SDK.
-  my_support_library_sdk_raise := $(call java-lib-header-files,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES) $(TARGET_DEFAULT_JAVA_LIBRARIES))
-endif
+  my_proguard_sdk_raise := $(call java-lib-header-files,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES) $(TARGET_DEFAULT_JAVA_LIBRARIES))
 endif
 endif
 
-legacy_proguard_flags := $(addprefix -libraryjars ,$(my_support_library_sdk_raise) \
-  $(filter-out $(my_support_library_sdk_raise), \
+legacy_proguard_flags := $(addprefix -libraryjars ,$(my_proguard_sdk_raise) \
+  $(filter-out $(my_proguard_sdk_raise), \
     $(full_java_bootclasspath_libs) \
     $(full_shared_java_header_libs)))
 
-legacy_proguard_lib_deps := $(my_support_library_sdk_raise) \
-  $(filter-out $(my_support_library_sdk_raise),$(full_shared_java_header_libs))
+legacy_proguard_lib_deps := $(my_proguard_sdk_raise) \
+  $(filter-out $(my_proguard_sdk_raise),$(full_shared_java_header_libs))
 
 legacy_proguard_flags += -printmapping $(proguard_dictionary)
 
@@ -719,7 +704,11 @@
 endif
 
 ifneq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
+ifneq ($(USE_R8),true)
   $(full_classes_proguard_jar): .KATI_IMPLICIT_OUTPUTS := $(proguard_dictionary)
+else
+  $(built_dex_intermediate): .KATI_IMPLICIT_OUTPUTS := $(proguard_dictionary)
+endif
 endif
 
 # If R8 is not enabled run Proguard.
@@ -729,7 +718,7 @@
 $(full_classes_proguard_jar): PRIVATE_PROGUARD_INJAR_FILTERS := $(proguard_injar_filters)
 $(full_classes_proguard_jar): PRIVATE_EXTRA_INPUT_JAR := $(extra_input_jar)
 $(full_classes_proguard_jar): PRIVATE_PROGUARD_FLAGS := $(legacy_proguard_flags) $(common_proguard_flags) $(LOCAL_PROGUARD_FLAGS)
-$(full_classes_proguard_jar) : $(full_classes_pre_proguard_jar) $(extra_input_jar) $(my_support_library_sdk_raise) $(common_proguard_flag_files) $(proguard_flag_files) $(legacy_proguard_lib_deps) | $(PROGUARD)
+$(full_classes_proguard_jar) : $(full_classes_pre_proguard_jar) $(extra_input_jar) $(my_proguard_sdk_raise) $(common_proguard_flag_files) $(proguard_flag_files) $(legacy_proguard_lib_deps) | $(PROGUARD)
 	$(call transform-jar-to-proguard)
 else # !USE_R8
 # Running R8 instead of Proguard, proguarded jar is actually the pre-Proguarded jar.
diff --git a/core/java_common.mk b/core/java_common.mk
index a73c6db..37de700 100644
--- a/core/java_common.mk
+++ b/core/java_common.mk
@@ -200,8 +200,6 @@
 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.
 ifndef LOCAL_IS_HOST_MODULE
   ifeq ($(LOCAL_SDK_VERSION),)
     ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
@@ -212,7 +210,8 @@
       # 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))
+      full_java_bootclasspath_libs := $(call java-lib-header-files,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES) $(TARGET_DEFAULT_JAVA_LIBRARIES))
+      LOCAL_JAVA_LIBRARIES := $(filter-out $(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES) $(TARGET_DEFAULT_JAVA_LIBRARIES),$(LOCAL_JAVA_LIBRARIES))
       my_system_modules := $(DEFAULT_SYSTEM_MODULES)
     endif  # LOCAL_NO_STANDARD_LIBRARIES
   else
@@ -235,6 +234,19 @@
     endif # current, system_current, or test_current
   endif # LOCAL_SDK_VERSION
 
+  ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
+    ifneq ($(LOCAL_MODULE),jacocoagent)
+      ifeq ($(EMMA_INSTRUMENT),true)
+        ifneq ($(EMMA_INSTRUMENT_STATIC),true)
+          # For instrumented build, if Jacoco is not being included statically
+          # in instrumented packages then include Jacoco classes into the
+          # bootclasspath.
+          full_java_bootclasspath_libs += $(call java-lib-header-files,jacocoagent)
+        endif # EMMA_INSTRUMENT_STATIC
+      endif # EMMA_INSTRUMENT
+    endif # LOCAL_MODULE == jacocoagent
+  endif # LOCAL_NO_STANDARD_LIBRARIES
+
   # In order to compile lambda code javac requires various invokedynamic-
   # related classes to be present. This change adds stubs needed for
   # javac to compile lambdas.
@@ -265,6 +277,7 @@
 
     full_shared_java_libs := $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/,\
       $(addsuffix $(COMMON_JAVA_PACKAGE_SUFFIX),$(LOCAL_JAVA_LIBRARIES)))
+    full_shared_java_header_libs := $(full_shared_java_libs)
   endif # USE_CORE_LIB_BOOTCLASSPATH
 endif # !LOCAL_IS_HOST_MODULE
 
@@ -294,9 +307,6 @@
 $(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)
-
 ifndef LOCAL_IS_HOST_MODULE
 # This is set by packages that are linking to other packages that export
 # shared libraries, allowing them to make use of the code in the linked apk.
@@ -307,8 +317,7 @@
 
   # link against the jar with full original names (before proguard processing).
   full_shared_java_libs += $(link_apk_libraries)
-  full_java_libs += $(link_apk_libraries)
-  full_java_header_libs += $(link_apk_header_libs)
+  full_shared_java_header_libs += $(link_apk_header_libs)
 endif
 
 # This is set by packages that contain instrumentation, allowing them to
@@ -330,8 +339,8 @@
   else
     link_instr_classes_header_jar := $(link_instr_intermediates_dir.COMMON)/classes.jar
   endif
-  full_java_libs += $(link_instr_classes_jar)
-  full_java_header_libs += $(link_instr_classes_header_jar)
+  full_shared_java_libs += $(link_instr_classes_jar)
+  full_shared_java_header_libs += $(link_instr_classes_header_jar)
 endif  # LOCAL_INSTRUMENTATION_FOR
 endif  # LOCAL_IS_HOST_MODULE
 
@@ -378,8 +387,12 @@
 endif
 endif  # !LOCAL_IS_HOST_MODULE
 
+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)
+
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_JAVA_LIBRARIES := $(full_java_libs)
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_JAVA_HEADER_LIBRARIES := $(full_java_header_libs)
+$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SHARED_JAVA_HEADER_LIBRARIES := $(full_shared_java_header_libs)
 
 ALL_MODULES.$(my_register_name).INTERMEDIATE_SOURCE_DIR := \
     $(ALL_MODULES.$(my_register_name).INTERMEDIATE_SOURCE_DIR) $(LOCAL_INTERMEDIATE_SOURCE_DIR)
diff --git a/core/java_library.mk b/core/java_library.mk
index d728c53..d7c08cc 100644
--- a/core/java_library.mk
+++ b/core/java_library.mk
@@ -63,12 +63,16 @@
 $(common_javalib.jar): PRIVATE_DEX_FILE := $(built_dex)
 $(common_javalib.jar): PRIVATE_SOURCE_ARCHIVE := $(full_classes_pre_proguard_jar)
 $(common_javalib.jar): PRIVATE_DONT_DELETE_JAR_DIRS := $(LOCAL_DONT_DELETE_JAR_DIRS)
-$(common_javalib.jar) : $(built_dex) $(java_resource_sources) | $(ZIPTIME)
+$(common_javalib.jar) : $(built_dex) $(java_resource_sources) | $(ZIPTIME) $(ZIPALIGN)
 	@echo "target Jar: $(PRIVATE_MODULE) ($@)"
 	$(call initialize-package-file,$(PRIVATE_SOURCE_ARCHIVE),$@.tmp)
 	$(call add-dex-to-package-arg,$@.tmp)
 	$(hide) $(ZIPTIME) $@.tmp
 	$(call commit-change-for-toc,$@)
+ifneq (,$(filter $(PRODUCT_LOADED_BY_PRIVILEGED_MODULES), $(LOCAL_MODULE)))
+	$(uncompress-dexs)
+	$(align-package)
+endif  # PRODUCT_LOADED_BY_PRIVILEGED_MODULES
 
 .KATI_RESTAT: $(common_javalib.jar)
 
diff --git a/core/main.mk b/core/main.mk
index 3044762..e7ecd5e 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -62,8 +62,6 @@
 $(shell mkdir -p $(OUT_DIR) && \
     echo -n $(BUILD_NUMBER) > $(OUT_DIR)/build_number.txt && \
     echo -n $(BUILD_DATETIME) > $(OUT_DIR)/build_date.txt)
-BUILD_NUMBER_FROM_FILE := $$(cat $(OUT_DIR)/build_number.txt)
-BUILD_DATETIME_FROM_FILE := $$(cat $(OUT_DIR)/build_date.txt)
 ifeq ($(HOST_OS),darwin)
 DATE_FROM_FILE := date -r $(BUILD_DATETIME_FROM_FILE)
 else
@@ -915,6 +913,8 @@
                       $(TARGET_OUT_DATA)/%, \
                               $(sort $(call get-tagged-modules,gnu)))
   target_gnu_MODULES := $(filter-out $(TARGET_OUT_EXECUTABLES)/%,$(target_gnu_MODULES))
+  target_gnu_MODULES := $(filter-out %/libopenjdkjvmti.so,$(target_gnu_MODULES))
+  target_gnu_MODULES := $(filter-out %/libopenjdkjvmtid.so,$(target_gnu_MODULES))
   $(info Removing from sdk:)$(foreach d,$(target_gnu_MODULES),$(info : $(d)))
   modules_to_install := \
               $(filter-out $(target_gnu_MODULES),$(modules_to_install))
diff --git a/core/package_internal.mk b/core/package_internal.mk
index 01e2463..9bf173f 100644
--- a/core/package_internal.mk
+++ b/core/package_internal.mk
@@ -353,7 +353,7 @@
 endif
 
 ifdef LOCAL_USE_AAPT2
-my_compiled_res_base_dir := $(intermediates)/flat-res
+my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res
 renderscript_target_api :=
 ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API))
 renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API)
@@ -548,7 +548,7 @@
 $(LOCAL_BUILT_MODULE) : $(my_res_package) $(AAPT2) | $(ACP)
 else
 $(LOCAL_BUILT_MODULE): PRIVATE_RESOURCE_LIST := $(all_res_assets)
-$(LOCAL_BUILT_MODULE) : $(all_res_assets) $(full_android_manifest) $(AAPT)
+$(LOCAL_BUILT_MODULE) : $(all_res_assets) $(full_android_manifest) $(AAPT) $(ZIPALIGN)
 endif
 	@echo "target Package: $(PRIVATE_MODULE) ($@)"
 ifdef LOCAL_USE_AAPT2
@@ -586,6 +586,9 @@
 	$(call dexpreopt-remove-classes.dex,$@)
 endif
 endif
+ifneq (,$(filter $(PRODUCT_LOADED_BY_PRIVILEGED_MODULES), $(LOCAL_MODULE)))
+	$(uncompress-dexs)
+endif  # PRODUCT_LOADED_BY_PRIVILEGED_MODULES
 	$(sign-package)
 
 ###############################
diff --git a/core/pdk_config.mk b/core/pdk_config.mk
index 43875df..dba748c 100644
--- a/core/pdk_config.mk
+++ b/core/pdk_config.mk
@@ -10,6 +10,9 @@
 # all paths under out dir
 PDK_PLATFORM_JAVA_ZIP_JAVA_TARGET_LIB_DIR += \
   target/common/obj/JAVA_LIBRARIES/android.test.runner_intermediates \
+  target/common/obj/JAVA_LIBRARIES/android.hidl.base-V1.0-java_intermediates \
+  target/common/obj/JAVA_LIBRARIES/android.hidl.base-V1.0-java-static_intermediates \
+  target/common/obj/JAVA_LIBRARIES/android.hidl.manager-V1.0-java_intermediates \
   target/common/obj/JAVA_LIBRARIES/android-common_intermediates \
   target/common/obj/JAVA_LIBRARIES/android-ex-camera2_intermediates \
   target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates \
@@ -20,6 +23,7 @@
   target/common/obj/JAVA_LIBRARIES/legacy-test_intermediates \
   target/common/obj/JAVA_LIBRARIES/ext_intermediates \
   target/common/obj/JAVA_LIBRARIES/framework_intermediates \
+  target/common/obj/JAVA_LIBRARIES/hwbinder_intermediates \
   target/common/obj/JAVA_LIBRARIES/ims-common_intermediates \
   target/common/obj/JAVA_LIBRARIES/okhttp_intermediates \
   target/common/obj/JAVA_LIBRARIES/telephony-common_intermediates \
diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk
index ba10b37..48e410b 100644
--- a/core/prebuilt_internal.mk
+++ b/core/prebuilt_internal.mk
@@ -358,6 +358,10 @@
 ifneq (true,$(DONT_UNCOMPRESS_PRIV_APPS_DEXS))
 ifeq (true,$(LOCAL_PRIVILEGED_MODULE))
 	$(uncompress-dexs)
+else
+  ifneq (,$(filter $(PRODUCT_LOADED_BY_PRIVILEGED_MODULES), $(LOCAL_MODULE)))
+	  $(uncompress-dexs)
+  endif  # PRODUCT_LOADED_BY_PRIVILEGED_MODULES
 endif  # LOCAL_PRIVILEGED_MODULE
 endif  # DONT_UNCOMPRESS_PRIV_APPS_DEXS
 ifdef LOCAL_DEX_PREOPT
diff --git a/core/product.mk b/core/product.mk
index 4682dac..1819293 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -117,6 +117,7 @@
     PRODUCT_SYSTEM_SERVER_JARS \
     PRODUCT_ALWAYS_PREOPT_EXTRACTED_APK \
     PRODUCT_DEXPREOPT_SPEED_APPS \
+    PRODUCT_LOADED_BY_PRIVILEGED_MODULES \
     PRODUCT_VBOOT_SIGNING_KEY \
     PRODUCT_VBOOT_SIGNING_SUBKEY \
     PRODUCT_VERITY_SIGNING_KEY \
diff --git a/core/product_config.mk b/core/product_config.mk
index 04f02da..777c29d 100644
--- a/core/product_config.mk
+++ b/core/product_config.mk
@@ -151,6 +151,13 @@
 endif # unbundled_goals
 endif
 
+# Now that we've parsed APP-* and PRODUCT-*, mark these as readonly
+TARGET_BUILD_APPS ?=
+.KATI_READONLY := \
+  TARGET_PRODUCT \
+  TARGET_BUILD_VARIANT \
+  TARGET_BUILD_APPS
+
 # Default to building dalvikvm on hosts that support it...
 ifeq ($(HOST_OS),linux)
 # ... or if the if the option is already set
@@ -259,6 +266,7 @@
 PRODUCT_SYSTEM_SERVER_JARS := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_SERVER_JARS))
 PRODUCT_SYSTEM_SERVER_APPS := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_SERVER_APPS))
 PRODUCT_DEXPREOPT_SPEED_APPS := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_DEXPREOPT_SPEED_APPS))
+PRODUCT_LOADED_BY_PRIVILEGED_MODULES := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_LOADED_BY_PRIVILEGED_MODULES))
 
 # 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))
@@ -295,15 +303,6 @@
 PRODUCT_AAPT_CONFIG := \
     $(subst $(space),$(comma),$(strip $(PRODUCT_AAPT_CONFIG)))
 
-# product-scoped aapt flags
-PRODUCT_AAPT_FLAGS :=
-PRODUCT_AAPT2_CFLAGS :=
-ifneq ($(filter en_XA ar_XB,$(PRODUCT_LOCALES)),)
-  # Force generating resources for pseudo-locales.
-  PRODUCT_AAPT2_CFLAGS += --pseudo-localize
-  PRODUCT_AAPT_FLAGS += --pseudo-localize
-endif
-
 PRODUCT_BRAND := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_BRAND))
 
 PRODUCT_MODEL := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_MODEL))
diff --git a/core/soong_config.mk b/core/soong_config.mk
index e774fc8..41e2382 100644
--- a/core/soong_config.mk
+++ b/core/soong_config.mk
@@ -72,6 +72,17 @@
 $(call add_json_str,  CrossHostArch,                     $(HOST_CROSS_ARCH))
 $(call add_json_str,  CrossHostSecondaryArch,            $(HOST_CROSS_2ND_ARCH))
 
+$(call add_json_list, ResourceOverlays,                  $(PRODUCT_PACKAGE_OVERLAYS) $(DEVICE_PACKAGE_OVERLAYS))
+$(call add_json_list, EnforceRROTargets,                 $(PRODUCT_ENFORCE_RRO_TARGETS))
+$(call add_json_list, EnforceRROExcludedOverlays,        $(PRODUCT_ENFORCE_RRO_EXCLUDED_OVERLAYS))
+
+$(call add_json_str,  AAPTCharacteristics,               $(TARGET_AAPT_CHARACTERISTICS))
+$(call add_json_list, AAPTConfig,                        $(PRODUCT_AAPT_CONFIG))
+$(call add_json_str,  AAPTPreferredConfig,               $(PRODUCT_AAPT_PREF_CONFIG))
+$(call add_json_list, AAPTPrebuiltDPI,                   $(PRODUCT_AAPT_PREBUILT_DPI))
+
+$(call add_json_str,  AppsDefaultVersionName,            $(APPS_DEFAULT_VERSION_NAME))
+
 $(call add_json_list, SanitizeHost,                      $(SANITIZE_HOST))
 $(call add_json_list, SanitizeDevice,                    $(SANITIZE_TARGET))
 $(call add_json_list, SanitizeDeviceDiag,                $(SANITIZE_TARGET_DIAG))
@@ -102,6 +113,7 @@
 $(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, MinimizeJavaDebugInfo,             $(filter true,$(PRODUCT_MINIMIZE_JAVA_DEBUG_INFO)))
 
 $(call add_json_bool, UseGoma,                           $(filter-out false,$(USE_GOMA)))
 
diff --git a/core/tasks/sdk-addon.mk b/core/tasks/sdk-addon.mk
index 3caa772..593c3cd 100644
--- a/core/tasks/sdk-addon.mk
+++ b/core/tasks/sdk-addon.mk
@@ -64,6 +64,7 @@
 # Files copied in the system-image directory
 files_to_copy += \
 	$(addon_dir_img):$(INSTALLED_QEMU_SYSTEMIMAGE):images/$(TARGET_CPU_ABI)/system.img \
+	$(addon_dir_img):$(INSTALLED_QEMU_VENDORIMAGE):images/$(TARGET_CPU_ABI)/vendor.img \
 	$(addon_dir_img):$(BUILT_USERDATAIMAGE_TARGET):images/$(TARGET_CPU_ABI)/userdata.img \
 	$(addon_dir_img):$(BUILT_RAMDISK_TARGET):images/$(TARGET_CPU_ABI)/ramdisk.img \
 	$(addon_dir_img):$(PRODUCT_OUT)/system/build.prop:images/$(TARGET_CPU_ABI)/build.prop \
@@ -117,6 +118,7 @@
 $(full_target_img): $(full_target) $(addon_img_source_prop) | $(SOONG_ZIP)
 	@echo Packaging SDK Addon System-Image: $@
 	$(hide) mkdir -p $(dir $@)
+	$(ACP) -r $(PRODUCT_OUT)/data $(PRIVATE_STAGING_DIR)/data
 	$(hide) $(SOONG_ZIP) -o $@ -C $(dir $(PRIVATE_STAGING_DIR)) -D $(PRIVATE_STAGING_DIR)
 
 
diff --git a/target/board/generic/BoardConfig.mk b/target/board/generic/BoardConfig.mk
index b57b162..331f082 100644
--- a/target/board/generic/BoardConfig.mk
+++ b/target/board/generic/BoardConfig.mk
@@ -52,10 +52,16 @@
 TARGET_USERIMAGES_USE_EXT4 := true
 BOARD_SYSTEMIMAGE_PARTITION_SIZE := 2147483648  # 2 GB
 BOARD_USERDATAIMAGE_PARTITION_SIZE := 576716800
+TARGET_COPY_OUT_VENDOR := vendor
+# ~100 MB vendor image. Please adjust system image / vendor image sizes
+# when finalizing them.
+BOARD_VENDORIMAGE_PARTITION_SIZE := 100000000
+BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_CACHEIMAGE_PARTITION_SIZE := 69206016
 BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_FLASH_BLOCK_SIZE := 512
 TARGET_USERIMAGES_SPARSE_EXT_DISABLED := true
+DEVICE_MATRIX_FILE   := device/generic/goldfish/compatibility_matrix.xml
 
 BOARD_SEPOLICY_DIRS += build/target/board/generic/sepolicy
-
+BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED := true
diff --git a/target/board/generic/device.mk b/target/board/generic/device.mk
index e56a4d1..e18c165 100644
--- a/target/board/generic/device.mk
+++ b/target/board/generic/device.mk
@@ -19,8 +19,7 @@
 
 PRODUCT_PROPERTY_OVERRIDES := \
     ro.ril.hsxpa=1 \
-    ro.ril.gprsclass=10 \
-    ro.adb.qemud=1
+    ro.ril.gprsclass=10
 
 PRODUCT_COPY_FILES := \
     device/generic/goldfish/data/etc/apns-conf.xml:system/etc/apns-conf.xml \
diff --git a/target/board/generic/sepolicy/adbd.te b/target/board/generic/sepolicy/adbd.te
new file mode 100644
index 0000000..9546c1a
--- /dev/null
+++ b/target/board/generic/sepolicy/adbd.te
@@ -0,0 +1 @@
+set_prop(adbd, ctl_mdnsd_prop);
diff --git a/target/board/generic/sepolicy/audioserver.te b/target/board/generic/sepolicy/audioserver.te
new file mode 100644
index 0000000..c3c4a3a
--- /dev/null
+++ b/target/board/generic/sepolicy/audioserver.te
@@ -0,0 +1 @@
+allow audioserver bootanim:binder call;
diff --git a/target/board/generic/sepolicy/bootanim.te b/target/board/generic/sepolicy/bootanim.te
index b4b1eef..4be1c8a 100644
--- a/target/board/generic/sepolicy/bootanim.te
+++ b/target/board/generic/sepolicy/bootanim.te
@@ -1,4 +1,5 @@
 allow bootanim self:process execmem;
 allow bootanim ashmem_device:chr_file execute;
-
+#TODO: This can safely be ignored until b/62954877 is fixed
+dontaudit bootanim system_data_file:dir read;
 set_prop(bootanim, qemu_prop)
diff --git a/target/board/generic/sepolicy/cameraserver.te b/target/board/generic/sepolicy/cameraserver.te
new file mode 100644
index 0000000..6cf5d6a
--- /dev/null
+++ b/target/board/generic/sepolicy/cameraserver.te
@@ -0,0 +1,2 @@
+allow cameraserver system_file:dir { open read };
+allow cameraserver hal_allocator:fd use;
diff --git a/target/board/generic/sepolicy/file.te b/target/board/generic/sepolicy/file.te
index 6fad80a..f4ae9e4 100644
--- a/target/board/generic/sepolicy/file.te
+++ b/target/board/generic/sepolicy/file.te
@@ -1 +1 @@
-type qemud_socket, file_type;
+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 d86a63b..f550f4d 100644
--- a/target/board/generic/sepolicy/file_contexts
+++ b/target/board/generic/sepolicy/file_contexts
@@ -7,15 +7,29 @@
 /dev/block/vda               u:object_r:system_block_device:s0
 /dev/block/vdb               u:object_r:cache_block_device:s0
 /dev/block/vdc               u:object_r:userdata_block_device:s0
+/dev/block/vdd               u:object_r:metadata_block_device:s0
+/dev/block/vde               u:object_r:system_block_device:s0
 
 /dev/goldfish_pipe           u:object_r:qemu_device:s0
 /dev/goldfish_sync           u:object_r:qemu_device:s0
 /dev/qemu_.*                 u:object_r:qemu_device:s0
-/dev/socket/qemud            u:object_r:qemud_socket:s0
 /dev/ttyGF[0-9]*             u:object_r:serial_device:s0
 /dev/ttyS2                   u:object_r:console_device:s0
-/system/bin/qemud            u:object_r:qemud_exec:s0
-/system/etc/init.goldfish.sh u:object_r:goldfish_setup_exec:s0
-/system/vendor/bin/init.ranchu-core.sh u:object_r:goldfish_setup_exec:s0
-/system/vendor/bin/init.ranchu-net.sh u:object_r:goldfish_setup_exec:s0
-/system/bin/qemu-props       u:object_r:qemu_props_exec: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
+
+/vendor/bin/hw/android\.hardware\.drm@1\.0-service\.widevine          u:object_r:hal_drm_widevine_exec:s0
+
+/vendor/lib(64)?/hw/gralloc\.ranchu\.so   u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libEGL_emulation\.so          u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libGLESv1_CM_emulation\.so    u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libGLESv2_emulation\.so       u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libEGL_swiftshader\.so          u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libGLESv1_CM_swiftshader\.so    u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libGLESv2_swiftshader\.so       u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libOpenglSystemCommon\.so       u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/lib_renderControl_enc\.so       u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libGLESv1_enc\.so       u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libGLESv2_enc\.so       u:object_r:same_process_hal_file:s0
diff --git a/target/board/generic/sepolicy/goldfish_setup.te b/target/board/generic/sepolicy/goldfish_setup.te
index 78d20fc..bcd49bd 100644
--- a/target/board/generic/sepolicy/goldfish_setup.te
+++ b/target/board/generic/sepolicy/goldfish_setup.te
@@ -1,29 +1,12 @@
 # goldfish-setup service: runs init.goldfish.sh script
 type goldfish_setup, domain;
-type goldfish_setup_exec, exec_type, file_type;
+type goldfish_setup_exec, vendor_file_type, exec_type, file_type;
 
 init_daemon_domain(goldfish_setup)
 
-# Inherit open file to shell (interpreter) for script.
-allow goldfish_setup shell_exec:file rx_file_perms;
-
-# Run ifconfig, route commands to configure interfaces and routes.
-allow goldfish_setup system_file:file execute_no_trans;
-allow goldfish_setup toolbox_exec:file rx_file_perms;
 allow goldfish_setup self:capability { net_admin net_raw };
-allow goldfish_setup self:udp_socket create_socket_perms;
+allow goldfish_setup self:udp_socket { create ioctl };
+allow goldfish_setup vendor_toolbox_exec:file execute_no_trans;
 allowxperm goldfish_setup self:udp_socket ioctl priv_sock_ioctls;
-
-wakelock_use(goldfish_setup)
-net_domain(goldfish_setup)
-
-# Set net.eth0.dns*, debug.sf.nobootanimation
-set_prop(goldfish_setup, system_prop)
-set_prop(goldfish_setup, debug_prop)
-
-# Set ro.radio.noril
-set_prop(goldfish_setup, radio_noril_prop)
-
-# Stop ril-daemon service (by setting ctl.stop to ril-daemon, which
-# transforms to a permission check on ctl.ril-daemon).
-set_prop(goldfish_setup, ctl_rildaemon_prop)
+wakelock_use(goldfish_setup);
+allow goldfish_setup vendor_shell_exec:file { rx_file_perms };
diff --git a/target/board/generic/sepolicy/hal_camera_default.te b/target/board/generic/sepolicy/hal_camera_default.te
new file mode 100644
index 0000000..eb88c36
--- /dev/null
+++ b/target/board/generic/sepolicy/hal_camera_default.te
@@ -0,0 +1,3 @@
+vndbinder_use(hal_camera_default);
+allow hal_camera_default hal_graphics_mapper_hwservice:hwservice_manager find;
+hal_client_domain(hal_camera_default, hal_graphics_composer)
diff --git a/target/board/generic/sepolicy/hal_drm_default.te b/target/board/generic/sepolicy/hal_drm_default.te
new file mode 100644
index 0000000..5a07433
--- /dev/null
+++ b/target/board/generic/sepolicy/hal_drm_default.te
@@ -0,0 +1,2 @@
+vndbinder_use(hal_drm_default);
+hal_client_domain(hal_drm_default, hal_graphics_composer)
diff --git a/target/board/generic/sepolicy/hal_drm_widevine.te b/target/board/generic/sepolicy/hal_drm_widevine.te
new file mode 100644
index 0000000..42d462a
--- /dev/null
+++ b/target/board/generic/sepolicy/hal_drm_widevine.te
@@ -0,0 +1,12 @@
+# define SELinux domain
+type hal_drm_widevine, domain;
+hal_server_domain(hal_drm_widevine, hal_drm)
+
+type hal_drm_widevine_exec, exec_type, vendor_file_type, file_type;
+init_daemon_domain(hal_drm_widevine)
+
+allow hal_drm mediacodec:fd use;
+allow hal_drm { appdomain -isolated_app }:fd use;
+
+vndbinder_use(hal_drm_widevine);
+hal_client_domain(hal_drm_widevine, hal_graphics_composer);
diff --git a/target/board/generic/sepolicy/hal_gnss_default.te b/target/board/generic/sepolicy/hal_gnss_default.te
index 0dd3d03..ddc68cc 100644
--- a/target/board/generic/sepolicy/hal_gnss_default.te
+++ b/target/board/generic/sepolicy/hal_gnss_default.te
@@ -1,3 +1 @@
-#============= hal_gnss_default ==============
-allow hal_gnss_default vndbinder_device:chr_file { ioctl open read write };
-
+vndbinder_use(hal_gnss_default);
diff --git a/target/board/generic/sepolicy/hal_graphics_composer_default.te b/target/board/generic/sepolicy/hal_graphics_composer_default.te
index 034bdef..40ecda6 100644
--- a/target/board/generic/sepolicy/hal_graphics_composer_default.te
+++ b/target/board/generic/sepolicy/hal_graphics_composer_default.te
@@ -1,3 +1 @@
-#============= hal_graphics_composer_default ==============
-allow hal_graphics_composer_default vndbinder_device:chr_file { ioctl open read write };
-
+vndbinder_use(hal_graphics_composer_default);
diff --git a/target/board/generic/sepolicy/init.te b/target/board/generic/sepolicy/init.te
index 3aa81d1..84a4e8d 100644
--- a/target/board/generic/sepolicy/init.te
+++ b/target/board/generic/sepolicy/init.te
@@ -1 +1,2 @@
 allow init tmpfs:lnk_file create_file_perms;
+dontaudit init kernel:system module_request;
diff --git a/target/board/generic/sepolicy/mediacodec.te b/target/board/generic/sepolicy/mediacodec.te
new file mode 100644
index 0000000..acf4e59
--- /dev/null
+++ b/target/board/generic/sepolicy/mediacodec.te
@@ -0,0 +1 @@
+allow mediacodec system_file:dir { open read };
diff --git a/target/board/generic/sepolicy/netd.te b/target/board/generic/sepolicy/netd.te
index 2b002ec..09a28b9 100644
--- a/target/board/generic/sepolicy/netd.te
+++ b/target/board/generic/sepolicy/netd.te
@@ -1 +1,3 @@
 dontaudit netd self:capability sys_module;
+#TODO: This can safely be ignored until b/62954877 is fixed
+dontaudit netd kernel:system module_request;
diff --git a/target/board/generic/sepolicy/priv_app.te b/target/board/generic/sepolicy/priv_app.te
new file mode 100644
index 0000000..3d16f32
--- /dev/null
+++ b/target/board/generic/sepolicy/priv_app.te
@@ -0,0 +1,5 @@
+#TODO: b/62908025
+dontaudit priv_app firstboot_prop:file { getattr open };
+dontaudit priv_app device:dir { open read };
+dontaudit priv_app proc_interrupts:file { getattr open read };
+dontaudit priv_app proc_modules:file { getattr open read };
diff --git a/target/board/generic/sepolicy/qemu_props.te b/target/board/generic/sepolicy/qemu_props.te
index d5571fd..0f5ec8c 100644
--- a/target/board/generic/sepolicy/qemu_props.te
+++ b/target/board/generic/sepolicy/qemu_props.te
@@ -1,12 +1,9 @@
 # qemu-props service:  Sets system properties on boot.
 type qemu_props, domain;
-type qemu_props_exec, exec_type, file_type;
+type qemu_props_exec, vendor_file_type, exec_type, file_type;
 
 init_daemon_domain(qemu_props)
 
-# Set properties.
 set_prop(qemu_props, qemu_prop)
 set_prop(qemu_props, dalvik_prop)
-set_prop(qemu_props, config_prop)
-set_prop(qemu_props, opengles_prop)
 set_prop(qemu_props, qemu_cmdline)
diff --git a/target/board/generic/sepolicy/qemud.te b/target/board/generic/sepolicy/qemud.te
deleted file mode 100644
index eee21c4..0000000
--- a/target/board/generic/sepolicy/qemud.te
+++ /dev/null
@@ -1,8 +0,0 @@
-# qemu support daemon
-type qemud, domain;
-type qemud_exec, exec_type, file_type;
-
-init_daemon_domain(qemud)
-
-# Access /dev/ttyS1 and /dev/ttyGF1.
-allow qemud serial_device:chr_file rw_file_perms;
diff --git a/target/board/generic/sepolicy/rild.te b/target/board/generic/sepolicy/rild.te
deleted file mode 100644
index e148b6c..0000000
--- a/target/board/generic/sepolicy/rild.te
+++ /dev/null
@@ -1 +0,0 @@
-unix_socket_connect(rild, qemud, qemud)
diff --git a/target/board/generic/sepolicy/system_server.te b/target/board/generic/sepolicy/system_server.te
index f9e277b..9063095 100644
--- a/target/board/generic/sepolicy/system_server.te
+++ b/target/board/generic/sepolicy/system_server.te
@@ -1,3 +1,2 @@
-unix_socket_connect(system_server, qemud, qemud)
 get_prop(system_server, opengles_prop)
 get_prop(system_server, radio_noril_prop)
diff --git a/target/board/generic/sepolicy/vold.te b/target/board/generic/sepolicy/vold.te
new file mode 100644
index 0000000..5f3bdd4
--- /dev/null
+++ b/target/board/generic/sepolicy/vold.te
@@ -0,0 +1 @@
+dontaudit vold kernel:system module_request;
diff --git a/target/board/generic/sepolicy/zygote.te b/target/board/generic/sepolicy/zygote.te
index a90f02b..e97d895 100644
--- a/target/board/generic/sepolicy/zygote.te
+++ b/target/board/generic/sepolicy/zygote.te
@@ -1 +1,4 @@
 set_prop(zygote, qemu_prop)
+# TODO (b/63631799) fix this access
+# Suppress denials to storage. Webview zygote should not be accessing.
+dontaudit webview_zygote mnt_expand_file:dir getattr;
diff --git a/target/board/generic/system.prop b/target/board/generic/system.prop
index f2424c9..ad8e5b8 100644
--- a/target/board/generic/system.prop
+++ b/target/board/generic/system.prop
@@ -2,5 +2,4 @@
 # system.prop for generic sdk 
 #
 
-rild.libpath=/system/lib/libreference-ril.so
-rild.libargs=-d /dev/ttyS0
+rild.libpath=/vendor/lib/libreference-ril.so
diff --git a/target/board/generic_arm64/BoardConfig.mk b/target/board/generic_arm64/BoardConfig.mk
index fa7de22..9beb9a3 100644
--- a/target/board/generic_arm64/BoardConfig.mk
+++ b/target/board/generic_arm64/BoardConfig.mk
@@ -83,9 +83,16 @@
 TARGET_USERIMAGES_USE_EXT4 := true
 BOARD_SYSTEMIMAGE_PARTITION_SIZE := 2684354560  # 2.5 GB
 BOARD_USERDATAIMAGE_PARTITION_SIZE := 576716800
+TARGET_COPY_OUT_VENDOR := vendor
+# ~100 MB vendor image. Please adjust system image / vendor image sizes
+# when finalizing them.
+BOARD_VENDORIMAGE_PARTITION_SIZE := 100000000
+BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_CACHEIMAGE_PARTITION_SIZE := 69206016
 BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_FLASH_BLOCK_SIZE := 512
 TARGET_USERIMAGES_SPARSE_EXT_DISABLED := true
+DEVICE_MATRIX_FILE   := device/generic/goldfish/compatibility_matrix.xml
 
+BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED := true
 BOARD_SEPOLICY_DIRS += build/target/board/generic/sepolicy
diff --git a/target/board/generic_arm64/device.mk b/target/board/generic_arm64/device.mk
index 9647a4e..ca287eb 100644
--- a/target/board/generic_arm64/device.mk
+++ b/target/board/generic_arm64/device.mk
@@ -19,8 +19,7 @@
 
 PRODUCT_PROPERTY_OVERRIDES := \
     ro.ril.hsxpa=1 \
-    ro.ril.gprsclass=10 \
-    ro.adb.qemud=1
+    ro.ril.gprsclass=10
 
 PRODUCT_COPY_FILES := \
     device/generic/goldfish/data/etc/apns-conf.xml:system/etc/apns-conf.xml \
diff --git a/target/board/generic_arm64/system.prop b/target/board/generic_arm64/system.prop
index 24578a9..5b0183a 100644
--- a/target/board/generic_arm64/system.prop
+++ b/target/board/generic_arm64/system.prop
@@ -2,5 +2,4 @@
 # system.prop for generic arm64 sdk
 #
 
-rild.libpath=/system/lib64/libreference-ril.so
-rild.libargs=-d /dev/ttyS0
+rild.libpath=/vendor/lib64/libreference-ril.so
diff --git a/target/board/generic_mips/BoardConfig.mk b/target/board/generic_mips/BoardConfig.mk
index 8fcef0a..fb66d21 100644
--- a/target/board/generic_mips/BoardConfig.mk
+++ b/target/board/generic_mips/BoardConfig.mk
@@ -60,9 +60,15 @@
 TARGET_USERIMAGES_USE_EXT4 := true
 BOARD_SYSTEMIMAGE_PARTITION_SIZE := 2147483648  # 2 GB
 BOARD_USERDATAIMAGE_PARTITION_SIZE := 734003200
+TARGET_COPY_OUT_VENDOR := vendor
+# ~100 MB vendor image. Please adjust system image / vendor image sizes
+# when finalizing them.
+BOARD_VENDORIMAGE_PARTITION_SIZE := 100000000
+BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_CACHEIMAGE_PARTITION_SIZE := 69206016
 BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_FLASH_BLOCK_SIZE := 512
 TARGET_USERIMAGES_SPARSE_EXT_DISABLED := true
+DEVICE_MATRIX_FILE   := device/generic/goldfish/compatibility_matrix.xml
 
 BOARD_SEPOLICY_DIRS += build/target/board/generic/sepolicy
diff --git a/target/board/generic_mips/device.mk b/target/board/generic_mips/device.mk
index 06a7d8a..a2633e1 100644
--- a/target/board/generic_mips/device.mk
+++ b/target/board/generic_mips/device.mk
@@ -19,8 +19,7 @@
 
 PRODUCT_PROPERTY_OVERRIDES := \
     ro.ril.hsxpa=1 \
-    ro.ril.gprsclass=10 \
-    ro.adb.qemud=1
+    ro.ril.gprsclass=10
 
 PRODUCT_COPY_FILES := \
     device/generic/goldfish/data/etc/apns-conf.xml:system/etc/apns-conf.xml \
diff --git a/target/board/generic_mips64/BoardConfig.mk b/target/board/generic_mips64/BoardConfig.mk
index e345b66..67bb51f 100644
--- a/target/board/generic_mips64/BoardConfig.mk
+++ b/target/board/generic_mips64/BoardConfig.mk
@@ -75,10 +75,16 @@
 TARGET_USERIMAGES_USE_EXT4 := true
 BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1879048192  # 1.75 GB
 BOARD_USERDATAIMAGE_PARTITION_SIZE := 1610612736  # 1.5 GB, lots of space for running tests
+TARGET_COPY_OUT_VENDOR := vendor
+# ~100 MB vendor image. Please adjust system image / vendor image sizes
+# when finalizing them.
+BOARD_VENDORIMAGE_PARTITION_SIZE := 100000000
+BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_CACHEIMAGE_PARTITION_SIZE := 69206016
 BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_FLASH_BLOCK_SIZE := 512
 TARGET_USERIMAGES_SPARSE_EXT_DISABLED := true
+DEVICE_MATRIX_FILE   := device/generic/goldfish/compatibility_matrix.xml
 
 BOARD_SEPOLICY_DIRS += build/target/board/generic/sepolicy
 
diff --git a/target/board/generic_mips64/device.mk b/target/board/generic_mips64/device.mk
index 66ec9db..2ccbcbd 100644
--- a/target/board/generic_mips64/device.mk
+++ b/target/board/generic_mips64/device.mk
@@ -19,8 +19,7 @@
 
 PRODUCT_PROPERTY_OVERRIDES := \
     ro.ril.hsxpa=1 \
-    ro.ril.gprsclass=10 \
-    ro.adb.qemud=1
+    ro.ril.gprsclass=10
 
 PRODUCT_COPY_FILES := \
     device/generic/goldfish/data/etc/apns-conf.xml:system/etc/apns-conf.xml \
diff --git a/target/board/generic_mips64/system.prop b/target/board/generic_mips64/system.prop
index aa03eae..4da69c0 100644
--- a/target/board/generic_mips64/system.prop
+++ b/target/board/generic_mips64/system.prop
@@ -2,5 +2,5 @@
 # system.prop for generic mips64 sdk
 #
 
-rild.libpath=/system/lib64/libreference-ril.so
+rild.libpath=/vendor/lib64/libreference-ril.so
 rild.libargs=-d /dev/ttyS0
diff --git a/target/board/generic_x86/BoardConfig.mk b/target/board/generic_x86/BoardConfig.mk
index 4cb8b7f..000a9a3 100644
--- a/target/board/generic_x86/BoardConfig.mk
+++ b/target/board/generic_x86/BoardConfig.mk
@@ -40,12 +40,19 @@
 USE_OPENGL_RENDERER := true
 
 TARGET_USERIMAGES_USE_EXT4 := true
-BOARD_SYSTEMIMAGE_PARTITION_SIZE := 2147483648
+BOARD_SYSTEMIMAGE_PARTITION_SIZE := 2684354560
 BOARD_USERDATAIMAGE_PARTITION_SIZE := 576716800
+TARGET_COPY_OUT_VENDOR := vendor
+BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED := true
+# ~100 MB vendor image. Please adjust system image / vendor image sizes
+# when finalizing them.
+BOARD_VENDORIMAGE_PARTITION_SIZE := 100000000
+BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_CACHEIMAGE_PARTITION_SIZE := 69206016
 BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_FLASH_BLOCK_SIZE := 512
 TARGET_USERIMAGES_SPARSE_EXT_DISABLED := true
+DEVICE_MATRIX_FILE   := device/generic/goldfish/compatibility_matrix.xml
 
 BOARD_SEPOLICY_DIRS += \
         build/target/board/generic/sepolicy \
diff --git a/target/board/generic_x86/device.mk b/target/board/generic_x86/device.mk
index b5b0faf..24c39a5 100644
--- a/target/board/generic_x86/device.mk
+++ b/target/board/generic_x86/device.mk
@@ -19,8 +19,7 @@
 
 PRODUCT_PROPERTY_OVERRIDES := \
     ro.ril.hsxpa=1 \
-    ro.ril.gprsclass=10 \
-    ro.adb.qemud=1
+    ro.ril.gprsclass=10
 
 PRODUCT_COPY_FILES := \
     device/generic/goldfish/data/etc/apns-conf.xml:system/etc/apns-conf.xml \
diff --git a/target/board/generic_x86/system.prop b/target/board/generic_x86/system.prop
index 137a0f9..64829f3 100644
--- a/target/board/generic_x86/system.prop
+++ b/target/board/generic_x86/system.prop
@@ -2,5 +2,4 @@
 # system.prop for generic sdk
 #
 
-rild.libpath=/system/lib/libreference-ril.so
-rild.libargs=-d /dev/ttyS0
+rild.libpath=/vendor/lib/libreference-ril.so
diff --git a/target/board/generic_x86_64/BoardConfig.mk b/target/board/generic_x86_64/BoardConfig.mk
index d0cc2c1..883dd2e 100755
--- a/target/board/generic_x86_64/BoardConfig.mk
+++ b/target/board/generic_x86_64/BoardConfig.mk
@@ -45,10 +45,17 @@
 TARGET_USERIMAGES_USE_EXT4 := true
 BOARD_SYSTEMIMAGE_PARTITION_SIZE := 2684354560 # 2.5 GB
 BOARD_USERDATAIMAGE_PARTITION_SIZE := 576716800
+TARGET_COPY_OUT_VENDOR := vendor
+# ~100 MB vendor image. Please adjust system image / vendor image sizes
+# when finalizing them.
+BOARD_VENDORIMAGE_PARTITION_SIZE := 100000000
+BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_CACHEIMAGE_PARTITION_SIZE := 69206016
 BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_FLASH_BLOCK_SIZE := 512
 TARGET_USERIMAGES_SPARSE_EXT_DISABLED := true
+BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED := true
+DEVICE_MATRIX_FILE   := device/generic/goldfish/compatibility_matrix.xml
 
 BOARD_SEPOLICY_DIRS += \
         build/target/board/generic/sepolicy \
diff --git a/target/board/generic_x86_64/device.mk b/target/board/generic_x86_64/device.mk
index b5b0faf..24c39a5 100755
--- a/target/board/generic_x86_64/device.mk
+++ b/target/board/generic_x86_64/device.mk
@@ -19,8 +19,7 @@
 
 PRODUCT_PROPERTY_OVERRIDES := \
     ro.ril.hsxpa=1 \
-    ro.ril.gprsclass=10 \
-    ro.adb.qemud=1
+    ro.ril.gprsclass=10
 
 PRODUCT_COPY_FILES := \
     device/generic/goldfish/data/etc/apns-conf.xml:system/etc/apns-conf.xml \
diff --git a/target/board/generic_x86_64/system.prop b/target/board/generic_x86_64/system.prop
index 43d4a88..ed9d173 100644
--- a/target/board/generic_x86_64/system.prop
+++ b/target/board/generic_x86_64/system.prop
@@ -2,5 +2,4 @@
 # system.prop for generic sdk
 #
 
-rild.libpath=/system/lib64/libreference-ril.so
-rild.libargs=-d /dev/ttyS0
+rild.libpath=/vendor/lib64/libreference-ril.so
diff --git a/target/product/aosp_arm.mk b/target/product/aosp_arm.mk
index 781cae6..9ed5284 100644
--- a/target/product/aosp_arm.mk
+++ b/target/product/aosp_arm.mk
@@ -1,5 +1,5 @@
 #
-# Copyright 2013 The Android Open-Source Project
+# Copyright 2017 The Android Open-Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -13,6 +13,19 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+
+PRODUCT_PROPERTY_OVERRIDES += \
+	rild.libpath=/vendor/lib/libreference-ril.so
+
+# Note: the following lines need to stay at the beginning so that it can
+# take priority  and override the rules it inherit from other mk files
+# see copy file rules in core/Makefile
+PRODUCT_COPY_FILES += \
+    development/sys-img/advancedFeatures.ini.arm:advancedFeatures.ini \
+    prebuilts/qemu-kernel/arm/3.18/kernel-qemu2:kernel-ranchu \
+    device/generic/goldfish/fstab.ranchu.arm:root/fstab.ranchu \
+    device/generic/goldfish/fstab.ranchu.early.arm:root/fstab.ranchu.early
+
 include $(SRC_TARGET_DIR)/product/full.mk
 
 PRODUCT_NAME := aosp_arm
diff --git a/target/product/aosp_arm64.mk b/target/product/aosp_arm64.mk
index 98afe5f..18d613b 100644
--- a/target/product/aosp_arm64.mk
+++ b/target/product/aosp_arm64.mk
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2013 The Android Open-Source Project
+# Copyright (C) 2017 The Android Open-Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -14,14 +14,22 @@
 # limitations under the License.
 #
 
+PRODUCT_PROPERTY_OVERRIDES += \
+	rild.libpath=/vendor/lib64/libreference-ril.so
+
 # This is a build configuration for a full-featured build of the
 # Open-Source part of the tree. It's geared toward a US-centric
 # build quite specifically for the emulator, and might not be
 # entirely appropriate to inherit from for on-device configurations.
 
-# This is for enabling ethernet support for ranchu.
-# Consider removing this after RIL support is provided in ranchu.
-PRODUCT_COPY_FILES += frameworks/native/data/etc/android.hardware.ethernet.xml:system/etc/permissions/android.hardware.ethernet.xml
+# Note: the following lines need to stay at the beginning so that it can
+# take priority  and override the rules it inherit from other mk files
+# see copy file rules in core/Makefile
+PRODUCT_COPY_FILES += \
+    development/sys-img/advancedFeatures.ini.arm:advancedFeatures.ini \
+    prebuilts/qemu-kernel/arm64/3.18/kernel-qemu2:kernel-ranchu \
+    device/generic/goldfish/fstab.ranchu.arm:root/fstab.ranchu \
+    device/generic/goldfish/fstab.ranchu.early.arm:root/fstab.ranchu.early
 
 $(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_base_telephony.mk)
diff --git a/target/product/aosp_x86.mk b/target/product/aosp_x86.mk
index cba43c4..03203ce 100644
--- a/target/product/aosp_x86.mk
+++ b/target/product/aosp_x86.mk
@@ -13,6 +13,19 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+
+PRODUCT_PROPERTY_OVERRIDES += \
+	rild.libpath=/vendor/lib/libreference-ril.so
+
+# This is a build configuration for a full-featured build of the
+# Open-Source part of the tree. It's geared toward a US-centric
+# build quite specifically for the emulator, and might not be
+# entirely appropriate to inherit from for on-device configurations.
+PRODUCT_COPY_FILES += \
+    development/sys-img/advancedFeatures.ini:advancedFeatures.ini \
+    device/generic/goldfish/data/etc/encryptionkey.img:encryptionkey.img \
+    prebuilts/qemu-kernel/x86/3.18/kernel-qemu2:kernel-ranchu
+
 include $(SRC_TARGET_DIR)/product/full_x86.mk
 
 PRODUCT_NAME := aosp_x86
diff --git a/target/product/aosp_x86_64.mk b/target/product/aosp_x86_64.mk
index 4006346..693bdaf 100644
--- a/target/product/aosp_x86_64.mk
+++ b/target/product/aosp_x86_64.mk
@@ -14,18 +14,18 @@
 # limitations under the License.
 #
 
+PRODUCT_PROPERTY_OVERRIDES += \
+	rild.libpath=/vendor/lib64/libreference-ril.so
+
 # This is a build configuration for a full-featured build of the
 # Open-Source part of the tree. It's geared toward a US-centric
 # build quite specifically for the emulator, and might not be
 # entirely appropriate to inherit from for on-device configurations.
 
-# If running on an emulator or some other device that has a LAN connection
-# that isn't a wifi connection. This will instruct init.rc to enable the
-# network connection so that you can use it with ADB
-
-# This is for enabling ethernet support for ranchu.
-# Consider removing this after RIL support is provided in ranchu.
-PRODUCT_COPY_FILES += frameworks/native/data/etc/android.hardware.ethernet.xml:system/etc/permissions/android.hardware.ethernet.xml
+PRODUCT_COPY_FILES += \
+    development/sys-img/advancedFeatures.ini:advancedFeatures.ini \
+    device/generic/goldfish/data/etc/encryptionkey.img:encryptionkey.img \
+    prebuilts/qemu-kernel/x86_64/3.18/kernel-qemu2:kernel-ranchu
 
 $(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_base_telephony.mk)
diff --git a/target/product/core_minimal.mk b/target/product/core_minimal.mk
index c3eb9ea..fc9da87 100644
--- a/target/product/core_minimal.mk
+++ b/target/product/core_minimal.mk
@@ -75,7 +75,7 @@
     libwebviewchromium_plat_support \
     libwilhelm \
     logd \
-    make_ext4fs \
+    mke2fs \
     e2fsck \
     resize2fs \
     tune2fs \
@@ -133,7 +133,7 @@
 # Adoptable external storage supports both ext4 and f2fs
 PRODUCT_PACKAGES += \
     e2fsck \
-    make_ext4fs \
+    mke2fs \
     fsck.f2fs \
     make_f2fs \
 
diff --git a/target/product/core_tiny.mk b/target/product/core_tiny.mk
index 944be74..c86b862 100644
--- a/target/product/core_tiny.mk
+++ b/target/product/core_tiny.mk
@@ -70,7 +70,7 @@
     libwilhelm \
     libdrmframework_jni \
     libdrmframework \
-    make_ext4fs \
+    mke2fs \
     e2fsck \
     resize2fs \
     tune2fs \
diff --git a/target/product/emulator.mk b/target/product/emulator.mk
index 5a5fb8e..58245cb 100644
--- a/target/product/emulator.mk
+++ b/target/product/emulator.mk
@@ -36,11 +36,13 @@
     libGLESv2_emulation \
     libGLESv1_enc \
     qemu-props \
-    qemud \
     camera.goldfish \
     camera.goldfish.jpeg \
     camera.ranchu \
     camera.ranchu.jpeg \
+    keystore.goldfish \
+    keystore.ranchu \
+    gatekeeper.ranchu \
     lights.goldfish \
     gps.goldfish \
     gps.ranchu \
@@ -62,7 +64,9 @@
     android.hardware.graphics.mapper@2.0-impl \
     hwcomposer.goldfish \
     hwcomposer.ranchu \
+    sh_vendor \
     vintf \
+    toybox_vendor \
     CarrierConfig
 
 PRODUCT_PACKAGES += \
@@ -72,40 +76,54 @@
     android.hardware.soundtrigger@2.0-impl
 
 PRODUCT_PACKAGES += \
-	android.hardware.keymaster@3.0-impl \
-	android.hardware.keymaster@3.0-service
+    android.hardware.keymaster@3.0-impl \
+    android.hardware.keymaster@3.0-service
 
 PRODUCT_PACKAGES += \
     android.hardware.gnss@1.0-service \
     android.hardware.gnss@1.0-impl
 
 PRODUCT_PACKAGES += \
-	android.hardware.sensors@1.0-impl \
-	android.hardware.sensors@1.0-service
+    android.hardware.sensors@1.0-impl \
+    android.hardware.sensors@1.0-service
+
+PRODUCT_PACKAGES += \
+    android.hardware.drm@1.0-service \
+    android.hardware.drm@1.0-impl
 
 PRODUCT_PACKAGES += \
     android.hardware.power@1.0-service \
     android.hardware.power@1.0-impl
 
-# camera service treble disable until all backwards compat is complete
-PRODUCT_PROPERTY_OVERRIDES += \
-    camera.disable_treble=1
+PRODUCT_PACKAGES += \
+    camera.device@1.0-impl \
+    android.hardware.camera.provider@2.4-service \
+    android.hardware.camera.provider@2.4-impl \
+
+PRODUCT_PACKAGES += \
+    android.hardware.gatekeeper@1.0-impl \
+    android.hardware.gatekeeper@1.0-service
+
+# need this for gles libraries to load properly
+# after moving to /vendor/lib/
+PRODUCT_PACKAGES += \
+    vndk-sp
 
 PRODUCT_COPY_FILES += \
-    device/generic/goldfish/fstab.goldfish:root/fstab.goldfish \
-    device/generic/goldfish/init.goldfish.rc:root/init.goldfish.rc \
-    device/generic/goldfish/init.goldfish.sh:system/etc/init.goldfish.sh \
     device/generic/goldfish/init.ranchu-core.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.ranchu-core.sh \
     device/generic/goldfish/init.ranchu-net.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.ranchu-net.sh \
     device/generic/goldfish/init.ranchu.rc:root/init.ranchu.rc \
-    device/generic/goldfish/ueventd.goldfish.rc:root/ueventd.goldfish.rc \
-    device/generic/goldfish/init.ranchu.rc:root/init.ranchu.rc \
     device/generic/goldfish/fstab.ranchu:root/fstab.ranchu \
+    device/generic/goldfish/fstab.ranchu.early:root/fstab.ranchu.early \
     device/generic/goldfish/ueventd.ranchu.rc:root/ueventd.ranchu.rc \
+    device/generic/goldfish/input/goldfish_rotary.idc:$(TARGET_COPY_OUT_VENDOR)/usr/idc/goldfish_rotary.idc \
     device/generic/goldfish/manifest.xml:$(TARGET_COPY_OUT_VENDOR)/manifest.xml \
-    device/generic/goldfish/input/goldfish_rotary.idc:system/usr/idc/goldfish_rotary.idc \
-    frameworks/native/data/etc/android.hardware.usb.accessory.xml:system/etc/permissions/android.hardware.usb.accessory.xml
+    device/generic/goldfish/data/etc/permissions/privapp-permissions-goldfish.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/privapp-permissions-goldfish.xml \
+    device/generic/goldfish/data/etc/config.ini:config.ini \
+    frameworks/native/data/etc/android.hardware.usb.accessory.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.usb.accessory.xml
 
 PRODUCT_PACKAGE_OVERLAYS := device/generic/goldfish/overlay
 
 PRODUCT_CHARACTERISTICS := emulator
+
+PRODUCT_FULL_TREBLE_OVERRIDE := true
diff --git a/target/product/full_base_telephony.mk b/target/product/full_base_telephony.mk
index 9a2c63a..375c679 100644
--- a/target/product/full_base_telephony.mk
+++ b/target/product/full_base_telephony.mk
@@ -25,7 +25,7 @@
 
 PRODUCT_COPY_FILES := \
     device/generic/goldfish/data/etc/apns-conf.xml:system/etc/apns-conf.xml \
-    frameworks/native/data/etc/handheld_core_hardware.xml:system/etc/permissions/handheld_core_hardware.xml
+    frameworks/native/data/etc/handheld_core_hardware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/handheld_core_hardware.xml
 
 $(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_base.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/product/telephony.mk)
diff --git a/target/product/runtime_libart.mk b/target/product/runtime_libart.mk
index 50b90ac..9108ac6 100644
--- a/target/product/runtime_libart.mk
+++ b/target/product/runtime_libart.mk
@@ -84,4 +84,10 @@
 PRODUCT_DEFAULT_PROPERTY_OVERRIDES += \
     pm.dexopt.install=quicken \
     pm.dexopt.bg-dexopt=speed-profile \
-    pm.dexopt.ab-ota=speed-profile
+    pm.dexopt.ab-ota=speed-profile \
+    pm.dexopt.inactive=verify \
+    pm.dexopt.shared=speed
+
+# Enable minidebuginfo generation unless overridden.
+PRODUCT_DEFAULT_PROPERTY_OVERRIDES += \
+    dalvik.vm.dex2oat-minidebuginfo=true
diff --git a/target/product/sdk_base.mk b/target/product/sdk_base.mk
index a99be2b..75a63e6 100644
--- a/target/product/sdk_base.mk
+++ b/target/product/sdk_base.mk
@@ -24,11 +24,10 @@
 	Development \
 	Dialer \
 	EmulatorSmokeTests \
-	Fallback \
 	Gallery2 \
 	GestureBuilder \
 	Launcher3 \
-	LegacyCamera \
+	Camera2 \
 	librs_jni \
 	libwnndict \
 	libWnnEngDic \
@@ -92,18 +91,19 @@
 	frameworks/base/data/sounds/effects/camera_click.ogg:system/media/audio/ui/camera_click.ogg \
 	frameworks/base/data/sounds/effects/VideoRecord.ogg:system/media/audio/ui/VideoRecord.ogg \
 	frameworks/base/data/sounds/effects/VideoStop.ogg:system/media/audio/ui/VideoStop.ogg \
-	device/generic/goldfish/data/etc/handheld_core_hardware.xml:system/etc/permissions/handheld_core_hardware.xml \
-	device/generic/goldfish/camera/media_profiles.xml:system/etc/media_profiles.xml \
-	frameworks/av/media/libstagefright/data/media_codecs_google_audio.xml:system/etc/media_codecs_google_audio.xml \
-	frameworks/av/media/libstagefright/data/media_codecs_google_telephony.xml:system/etc/media_codecs_google_telephony.xml \
-	device/generic/goldfish/camera/media_codecs_google_video.xml:system/etc/media_codecs_google_video.xml \
-	device/generic/goldfish/camera/media_codecs.xml:system/etc/media_codecs.xml \
-	device/generic/goldfish/camera/media_codecs_performance.xml:system/etc/media_codecs_performance.xml \
-	frameworks/native/data/etc/android.hardware.touchscreen.multitouch.jazzhand.xml:system/etc/permissions/android.hardware.touchscreen.multitouch.jazzhand.xml \
-	frameworks/native/data/etc/android.hardware.camera.xml:system/etc/permissions/android.hardware.camera.xml \
-	frameworks/native/data/etc/android.hardware.fingerprint.xml:system/etc/permissions/android.hardware.fingerprint.xml \
-	frameworks/av/media/libeffects/data/audio_effects.conf:system/etc/audio_effects.conf \
-	device/generic/goldfish/audio_policy.conf:system/etc/audio_policy.conf
+	device/generic/goldfish/data/etc/handheld_core_hardware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/handheld_core_hardware.xml \
+	device/generic/goldfish/camera/media_profiles.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_profiles_V1_0.xml \
+	frameworks/av/media/libstagefright/data/media_codecs_google_audio.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_google_audio.xml \
+	frameworks/av/media/libstagefright/data/media_codecs_google_telephony.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_google_telephony.xml \
+	device/generic/goldfish/camera/media_codecs_google_video.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_google_video.xml \
+	device/generic/goldfish/camera/media_codecs.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs.xml \
+	device/generic/goldfish/camera/media_codecs_performance.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_performance.xml \
+	frameworks/native/data/etc/android.hardware.touchscreen.multitouch.jazzhand.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.touchscreen.multitouch.jazzhand.xml \
+	frameworks/native/data/etc/android.hardware.camera.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.camera.xml \
+	frameworks/native/data/etc/android.hardware.fingerprint.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.fingerprint.xml \
+	frameworks/native/data/etc/android.software.autofill.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.autofill.xml \
+	frameworks/av/media/libeffects/data/audio_effects.conf:$(TARGET_COPY_OUT_VENDOR)/etc/audio_effects.conf \
+	device/generic/goldfish/audio_policy.conf:$(TARGET_COPY_OUT_VENDOR)/etc/audio_policy.conf
 
 include $(SRC_TARGET_DIR)/product/emulator.mk
 
diff --git a/target/product/sdk_phone_arm64.mk b/target/product/sdk_phone_arm64.mk
index a689475..2aa688b 100644
--- a/target/product/sdk_phone_arm64.mk
+++ b/target/product/sdk_phone_arm64.mk
@@ -14,11 +14,23 @@
 # limitations under the License.
 #
 
+PRODUCT_PROPERTY_OVERRIDES += \
+	rild.libpath=/vendor/lib64/libreference-ril.so
+
 # This is a build configuration for a full-featured build of the
 # Open-Source part of the tree. It's geared toward a US-centric
 # build quite specifically for the emulator, and might not be
 # entirely appropriate to inherit from for on-device configurations.
 
+# Note: the following lines need to stay at the beginning so that it can
+# take priority  and override the rules it inherit from other mk files
+# see copy file rules in core/Makefile
+PRODUCT_COPY_FILES += \
+    development/sys-img/advancedFeatures.ini.arm:advancedFeatures.ini \
+    prebuilts/qemu-kernel/arm64/3.18/kernel-qemu2:kernel-ranchu \
+    device/generic/goldfish/fstab.ranchu.arm:root/fstab.ranchu \
+    device/generic/goldfish/fstab.ranchu.early.arm:root/fstab.ranchu.early
+
 $(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/product/sdk_base.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/board/generic_arm64/device.mk)
@@ -34,3 +46,5 @@
 PRODUCT_NAME := sdk_phone_arm64
 PRODUCT_DEVICE := generic_arm64
 PRODUCT_MODEL := Android SDK built for arm64
+
+
diff --git a/target/product/sdk_phone_armv7.mk b/target/product/sdk_phone_armv7.mk
index ebdd0e7..e99f0f5 100644
--- a/target/product/sdk_phone_armv7.mk
+++ b/target/product/sdk_phone_armv7.mk
@@ -14,6 +14,18 @@
 # limitations under the License.
 #
 
+PRODUCT_PROPERTY_OVERRIDES += \
+	rild.libpath=/vendor/lib/libreference-ril.so
+
+# Note: the following lines need to stay at the beginning so that it can
+# take priority  and override the rules it inherit from other mk files
+# see copy file rules in core/Makefile
+PRODUCT_COPY_FILES += \
+    development/sys-img/advancedFeatures.ini.arm:advancedFeatures.ini \
+    prebuilts/qemu-kernel/arm/3.18/kernel-qemu2:kernel-ranchu \
+    device/generic/goldfish/fstab.ranchu.arm:root/fstab.ranchu \
+    device/generic/goldfish/fstab.ranchu.early.arm:root/fstab.ranchu.early
+
 $(call inherit-product, $(SRC_TARGET_DIR)/product/sdk_base.mk)
 
 # AOSP emulator images build the AOSP messaging app.
diff --git a/target/product/sdk_phone_x86.mk b/target/product/sdk_phone_x86.mk
index 01c2e83..1e82773 100644
--- a/target/product/sdk_phone_x86.mk
+++ b/target/product/sdk_phone_x86.mk
@@ -14,10 +14,17 @@
 # limitations under the License.
 #
 
+PRODUCT_PROPERTY_OVERRIDES += \
+	rild.libpath=/vendor/lib/libreference-ril.so
+
 # This is a build configuration for a full-featured build of the
 # Open-Source part of the tree. It's geared toward a US-centric
 # build quite specifically for the emulator, and might not be
 # entirely appropriate to inherit from for on-device configurations.
+PRODUCT_COPY_FILES += \
+    development/sys-img/advancedFeatures.ini:advancedFeatures.ini \
+    device/generic/goldfish/data/etc/encryptionkey.img:encryptionkey.img \
+    prebuilts/qemu-kernel/x86/3.18/kernel-qemu2:kernel-ranchu
 
 $(call inherit-product, $(SRC_TARGET_DIR)/product/sdk_base.mk)
 
diff --git a/target/product/sdk_phone_x86_64.mk b/target/product/sdk_phone_x86_64.mk
index c3bc5e9..a18c4f8 100644
--- a/target/product/sdk_phone_x86_64.mk
+++ b/target/product/sdk_phone_x86_64.mk
@@ -14,11 +14,19 @@
 # limitations under the License.
 #
 
+PRODUCT_PROPERTY_OVERRIDES += \
+	rild.libpath=/vendor/lib64/libreference-ril.so
+
 # This is a build configuration for a full-featured build of the
 # Open-Source part of the tree. It's geared toward a US-centric
 # build quite specifically for the emulator, and might not be
 # entirely appropriate to inherit from for on-device configurations.
 
+PRODUCT_COPY_FILES += \
+    development/sys-img/advancedFeatures.ini:advancedFeatures.ini \
+    device/generic/goldfish/data/etc/encryptionkey.img:encryptionkey.img \
+    prebuilts/qemu-kernel/x86_64/3.18/kernel-qemu2:kernel-ranchu
+
 $(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/product/sdk_base.mk)
 
diff --git a/tools/apicheck/Android.mk b/tools/apicheck/Android.mk
index b547058..ab3493d 100644
--- a/tools/apicheck/Android.mk
+++ b/tools/apicheck/Android.mk
@@ -12,7 +12,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-ifneq ($(TARGET_BUILD_PDK),true)
 LOCAL_PATH := $(call my-dir)
 
 # the hat script
@@ -26,4 +25,3 @@
 include $(BUILD_PREBUILT)
 
 # Apicheck is now part of Doclava -- See external/doclava.
-endif
diff --git a/tools/releasetools/blockimgdiff.py b/tools/releasetools/blockimgdiff.py
index c95512d..c184c42 100644
--- a/tools/releasetools/blockimgdiff.py
+++ b/tools/releasetools/blockimgdiff.py
@@ -768,6 +768,7 @@
                 message.append(
                     "Fell back and generated with bsdiff instead for %s" % (
                     xf.tgt_name,))
+                xf.style = "bsdiff"
                 with lock:
                   warning_messages.extend(message)
                 del message[:]
diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py
index a9e1606..60aa84e 100755
--- a/tools/releasetools/ota_from_target_files.py
+++ b/tools/releasetools/ota_from_target_files.py
@@ -21,9 +21,6 @@
 
 Usage:  ota_from_target_files [flags] input_target_files output_ota_package
 
-  --board_config  <file>
-      Deprecated.
-
   -k (--package_key) <key> Key to use to sign the package (default is
       the value of default_system_dev_certificate from the input
       target-files's META/misc_info.txt, or
@@ -46,9 +43,9 @@
       Similar to --full_radio. When generating an incremental OTA, always
       include a full copy of bootloader image.
 
-  -v  (--verify)
-      Remount and verify the checksums of the files written to the
-      system and vendor (if used) partitions.  Incremental builds only.
+  --verify
+      Remount and verify the checksums of the files written to the system and
+      vendor (if used) partitions. Non-A/B incremental OTAs only.
 
   -o  (--oem_settings)  <main_file[,additional_files...]>
       Comma seperated list of files used to specify the expected OEM-specific
@@ -1290,9 +1287,7 @@
 def main(argv):
 
   def option_handler(o, a):
-    if o == "--board_config":
-      pass   # deprecated
-    elif o in ("-k", "--package_key"):
+    if o in ("-k", "--package_key"):
       OPTIONS.package_key = a
     elif o in ("-i", "--incremental_from"):
       OPTIONS.incremental_source = a
@@ -1354,7 +1349,6 @@
   args = common.ParseOptions(argv, __doc__,
                              extra_opts="b:k:i:d:we:t:2o:",
                              extra_long_opts=[
-                                 "board_config=",
                                  "package_key=",
                                  "incremental_from=",
                                  "full_radio",
diff --git a/tools/releasetools/rangelib.py b/tools/releasetools/rangelib.py
index fa6eec1..87380a5 100644
--- a/tools/releasetools/rangelib.py
+++ b/tools/releasetools/rangelib.py
@@ -320,7 +320,7 @@
     [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
     >>> list(RangeSet("10-19 3-5").next_item())
     [3, 4, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
-    >>> list(rangelib.RangeSet("10-19 3 5 7").next_item())
+    >>> list(RangeSet("10-19 3 5 7").next_item())
     [3, 5, 7, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
     """
     for s, e in self:
diff --git a/tools/signapk/OWNERS b/tools/signapk/OWNERS
new file mode 100644
index 0000000..0b8d398
--- /dev/null
+++ b/tools/signapk/OWNERS
@@ -0,0 +1,2 @@
+cbrubaker@google.com
+klyubin@google.com
diff --git a/tools/signapk/src/com/android/signapk/SignApk.java b/tools/signapk/src/com/android/signapk/SignApk.java
index 3b00599..fdf6283 100644
--- a/tools/signapk/src/com/android/signapk/SignApk.java
+++ b/tools/signapk/src/com/android/signapk/SignApk.java
@@ -1082,14 +1082,15 @@
                     ByteBuffer[] outputChunks = new ByteBuffer[] {v1SignedApk};
 
                     ZipSections zipSections = findMainZipSections(v1SignedApk);
-                    ApkSignerEngine.OutputApkSigningBlockRequest addV2SignatureRequest =
-                            apkSigner.outputZipSections(
+                    ApkSignerEngine.OutputApkSigningBlockRequest2 addV2SignatureRequest =
+                            apkSigner.outputZipSections2(
                                     DataSources.asDataSource(zipSections.beforeCentralDir),
                                     DataSources.asDataSource(zipSections.centralDir),
                                     DataSources.asDataSource(zipSections.eocd));
                     if (addV2SignatureRequest != null) {
                         // Need to insert the returned APK Signing Block before ZIP Central
                         // Directory.
+                        int padding = addV2SignatureRequest.getPaddingSizeBeforeApkSigningBlock();
                         byte[] apkSigningBlock = addV2SignatureRequest.getApkSigningBlock();
                         // Because the APK Signing Block is inserted before the Central Directory,
                         // we need to adjust accordingly the offset of Central Directory inside the
@@ -1100,10 +1101,12 @@
                         modifiedEocd.order(ByteOrder.LITTLE_ENDIAN);
                         ApkUtils.setZipEocdCentralDirectoryOffset(
                                 modifiedEocd,
-                                zipSections.beforeCentralDir.remaining() + apkSigningBlock.length);
+                                zipSections.beforeCentralDir.remaining() + padding +
+                                apkSigningBlock.length);
                         outputChunks =
                                 new ByteBuffer[] {
                                         zipSections.beforeCentralDir,
+                                        ByteBuffer.allocate(padding),
                                         ByteBuffer.wrap(apkSigningBlock),
                                         zipSections.centralDir,
                                         modifiedEocd};
diff --git a/tools/vendor_buildinfo.sh b/tools/vendor_buildinfo.sh
index 485ada3..c12f7cb 100755
--- a/tools/vendor_buildinfo.sh
+++ b/tools/vendor_buildinfo.sh
@@ -6,10 +6,10 @@
 echo "ro.product.board=$TARGET_BOOTLOADER_BOARD_NAME"
 echo "ro.board.platform=$TARGET_BOARD_PLATFORM"
 
-echo "ro.vendor.product.manufacturer=$PRODUCT_MANUFACTURER"
-echo "ro.vendor.product.model=$PRODUCT_MODEL"
-echo "ro.vendor.product.brand=$PRODUCT_BRAND"
-echo "ro.vendor.product.name=$PRODUCT_NAME"
-echo "ro.vendor.product.device=$TARGET_DEVICE"
+echo "ro.product.vendor.manufacturer=$PRODUCT_MANUFACTURER"
+echo "ro.product.vendor.model=$PRODUCT_MODEL"
+echo "ro.product.vendor.brand=$PRODUCT_BRAND"
+echo "ro.product.vendor.name=$PRODUCT_NAME"
+echo "ro.product.vendor.device=$TARGET_DEVICE"
 
 echo "# end build properties"
diff --git a/tools/zipalign/Android.bp b/tools/zipalign/Android.bp
index 2aa6450..e80054a 100644
--- a/tools/zipalign/Android.bp
+++ b/tools/zipalign/Android.bp
@@ -16,12 +16,16 @@
     cflags: ["-Wall", "-Werror"],
 
     static_libs: [
-        "libandroidfw",
         "libutils",
         "libcutils",
         "liblog",
         "libzopfli",
-        "libz",
+    ],
+
+    shared_libs: [
+      "libbase",
+      "libz",
+      "libziparchive"
     ],
 
     target: {
diff --git a/tools/zipalign/ZipFile.cpp b/tools/zipalign/ZipFile.cpp
index 719c6b9..43bc9bf 100644
--- a/tools/zipalign/ZipFile.cpp
+++ b/tools/zipalign/ZipFile.cpp
@@ -20,13 +20,12 @@
 
 #define LOG_TAG "zip"
 
-#include <androidfw/ZipUtils.h>
 #include <utils/Log.h>
+#include <ziparchive/zip_archive.h>
 
 #include "ZipFile.h"
 
 #include <zlib.h>
-#define DEF_MEM_LEVEL 8                // normally in zutil.h?
 
 #include "zopfli/deflate.h"
 
@@ -135,7 +134,7 @@
 /*
  * Return the Nth entry in the archive.
  */
-ZipEntry* ZipFile::getEntryByIndex(int idx) const
+android::ZipEntry* ZipFile::getEntryByIndex(int idx) const
 {
     if (idx < 0 || idx >= (int) mEntries.size())
         return NULL;
@@ -146,7 +145,7 @@
 /*
  * Find an entry by name.
  */
-ZipEntry* ZipFile::getEntryByName(const char* fileName) const
+android::ZipEntry* ZipFile::getEntryByName(const char* fileName) const
 {
     /*
      * Do a stupid linear string-compare search.
@@ -1196,6 +1195,58 @@
 }
 #endif
 
+class BufferWriter : public zip_archive::Writer {
+  public:
+    BufferWriter(void* buf, size_t size) : Writer(),
+        buf_(reinterpret_cast<uint8_t*>(buf)), size_(size), bytes_written_(0) {}
+
+    bool Append(uint8_t* buf, size_t buf_size) override {
+        if (bytes_written_ + buf_size > size_) {
+            return false;
+        }
+
+        memcpy(buf_ + bytes_written_, buf, buf_size);
+        bytes_written_ += buf_size;
+        return true;
+    }
+
+  private:
+    uint8_t* const buf_;
+    const size_t size_;
+    size_t bytes_written_;
+};
+
+class FileReader : public zip_archive::Reader {
+  public:
+    FileReader(FILE* fp) : Reader(), fp_(fp), current_offset_(0) {
+    }
+
+    bool ReadAtOffset(uint8_t* buf, size_t len, uint32_t offset) const {
+        // Data is usually requested sequentially, so this helps avoid pointless
+        // fseeks every time we perform a read. There's an impedence mismatch
+        // here because the original API was designed around pread and pwrite.
+        if (offset != current_offset_) {
+            if (fseek(fp_, offset, SEEK_SET) != 0) {
+                return false;
+            }
+
+            current_offset_ = offset;
+        }
+
+        size_t read = fread(buf, 1, len, fp_);
+        if (read != len) {
+            return false;
+        }
+
+        current_offset_ += read;
+        return true;
+    }
+
+  private:
+    FILE* fp_;
+    mutable uint32_t current_offset_;
+};
+
 // free the memory when you're done
 void* ZipFile::uncompress(const ZipEntry* entry) const
 {
@@ -1238,11 +1289,13 @@
             }
             break;
         case ZipEntry::kCompressDeflated: {
-            if (!ZipUtils::inflateToBuffer(mZipFp, buf, unlen, clen)) {
+            const FileReader reader(mZipFp);
+            BufferWriter writer(buf, unlen);
+            if (zip_archive::Inflate(reader, clen, unlen, &writer, nullptr) != 0) {
                 goto bail;
             }
-            }
             break;
+        }
         default:
             goto bail;
     }