Merge "Structure MediaProvider as an APEX."
diff --git a/Changes.md b/Changes.md
index 461de97..5a0fd23 100644
--- a/Changes.md
+++ b/Changes.md
@@ -1,5 +1,48 @@
 # Build System Changes for Android.mk Writers
 
+## LOCAL_C_INCLUDES outside the source/output trees are an error {#BUILD_BROKEN_OUTSIDE_INCLUDE_DIRS}
+
+Include directories are expected to be within the source tree (or in the output
+directory, generated during the build). This has been checked in some form
+since Oreo, but now has better checks.
+
+There's now a `BUILD_BROKEN_OUTSIDE_INCLUDE_DIRS` variable, that when set, will
+turn these errors into warnings temporarily. I don't expect this to last more
+than a release, since they're fairly easy to clean up.
+
+Neither of these cases are supported by Soong, and will produce errors when
+converting your module.
+
+### Absolute paths
+
+This has been checked since Oreo. The common reason to hit this is because a
+makefile is calculating a path, and ran abspath/realpath/etc. This is a problem
+because it makes your build non-reproducible. It's very unlikely that your
+source path is the same on every machine.
+
+### Using `../` to leave the source/output directories
+
+This is the new check that has been added. In every case I've found, this has
+been a mistake in the Android.mk -- assuming that `LOCAL_C_INCLUDES` (which is
+relative to the top of the source tree) acts like `LOCAL_SRC_FILES` (which is
+relative to `LOCAL_PATH`).
+
+Since this usually isn't a valid path, you can almost always just remove the
+offending line.
+
+
+# `BOARD_HAL_STATIC_LIBRARIES` and `LOCAL_HAL_STATIC_LIBRARIES` are obsolete {#BOARD_HAL_STATIC_LIBRARIES}
+
+Define proper HIDL / Stable AIDL HAL instead.
+
+* For libhealthd, use health HAL. See instructions for implementing
+  health HAL:
+
+  * [hardware/interfaces/health/2.1/README.md] for health 2.1 HAL (recommended)
+  * [hardware/interfaces/health/1.0/README.md] for health 1.0 HAL
+
+* For libdumpstate, use at least Dumpstate HAL 1.0.
+
 ## PRODUCT_STATIC_BOOT_CONTROL_HAL is obsolete {#PRODUCT_STATIC_BOOT_CONTROL_HAL}
 
 `PRODUCT_STATIC_BOOT_CONTROL_HAL` was the workaround to allow sideloading with
@@ -480,3 +523,5 @@
 [external/fonttools/Lib/fontTools/Android.bp]: https://android.googlesource.com/platform/external/fonttools/+/master/Lib/fontTools/Android.bp
 [frameworks/base/Android.bp]: https://android.googlesource.com/platform/frameworks/base/+/master/Android.bp
 [frameworks/base/data/fonts/Android.mk]: https://android.googlesource.com/platform/frameworks/base/+/master/data/fonts/Android.mk
+[hardware/interfaces/health/1.0/README.md]: https://android.googlesource.com/platform/hardware/interfaces/+/master/health/1.0/README.md
+[hardware/interfaces/health/2.1/README.md]: https://android.googlesource.com/platform/hardware/interfaces/+/master/health/2.1/README.md
diff --git a/core/binary.mk b/core/binary.mk
index e4805cd..ae456e3 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -84,6 +84,12 @@
   my_native_coverage := false
 endif
 
+# Exclude directories from manual binder interface whitelisting.
+# TODO(b/145621474): Move this check into IInterface.h when clang-tidy no longer uses absolute paths.
+ifneq (,$(filter $(addsuffix %,$(ALLOWED_MANUAL_INTERFACE_PATHS)),$(LOCAL_PATH)))
+  my_cflags += -DDO_NOT_CHECK_MANUAL_BINDER_INTERFACES
+endif
+
 ifneq ($(strip $(ENABLE_XOM)),false)
   ifndef LOCAL_IS_HOST_MODULE
     my_xom := true
@@ -435,15 +441,6 @@
 
 include $(BUILD_SYSTEM)/cxx_stl_setup.mk
 
-# Add static HAL libraries
-ifdef LOCAL_HAL_STATIC_LIBRARIES
-$(foreach lib, $(LOCAL_HAL_STATIC_LIBRARIES), \
-    $(eval b_lib := $(filter $(lib).%,$(BOARD_HAL_STATIC_LIBRARIES)))\
-    $(if $(b_lib), $(eval my_static_libraries += $(b_lib)),\
-                   $(eval my_static_libraries += $(lib).default)))
-b_lib :=
-endif
-
 ifneq ($(strip $(CUSTOM_$(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)LINKER)),)
   my_linker := $(CUSTOM_$(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)LINKER)
 else
@@ -1298,9 +1295,13 @@
 
 my_c_includes := $(foreach inc,$(my_c_includes),$(call clean-path,$(inc)))
 
-my_outside_includes := $(filter-out $(OUT_DIR)/%,$(filter /%,$(my_c_includes)))
+my_outside_includes := $(filter-out $(OUT_DIR)/%,$(filter /%,$(my_c_includes)) $(filter ../%,$(my_c_includes)))
 ifneq ($(my_outside_includes),)
-$(error $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): C_INCLUDES must be under the source or output directories: $(my_outside_includes))
+  ifeq ($(BUILD_BROKEN_OUTSIDE_INCLUDE_DIRS),true)
+    $(call pretty-warning,C_INCLUDES must be under the source or output directories: $(my_outside_includes))
+  else
+    $(call pretty-error,C_INCLUDES must be under the source or output directories: $(my_outside_includes))
+  endif
 endif
 
 # all_objects includes gen_o_objects which were part of LOCAL_GENERATED_SOURCES;
diff --git a/core/board_config.mk b/core/board_config.mk
index 4c128f1..0e3c52f 100644
--- a/core/board_config.mk
+++ b/core/board_config.mk
@@ -89,6 +89,7 @@
   BUILD_BROKEN_PREBUILT_ELF_FILES \
   BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW \
   BUILD_BROKEN_USES_NETWORK \
+  BUILD_BROKEN_OUTSIDE_INCLUDE_DIRS \
 
 _build_broken_var_list += \
   $(foreach m,$(AVAILABLE_BUILD_MODULE_TYPES) \
diff --git a/core/clear_vars.mk b/core/clear_vars.mk
index 9ff978b..6c3b249 100644
--- a/core/clear_vars.mk
+++ b/core/clear_vars.mk
@@ -112,7 +112,6 @@
 # Group static libraries with "-Wl,--start-group" and "-Wl,--end-group" when linking.
 LOCAL_GROUP_STATIC_LIBRARIES:=
 LOCAL_GTEST:=true
-LOCAL_HAL_STATIC_LIBRARIES:=
 LOCAL_HEADER_LIBRARIES:=
 LOCAL_HOST_PREFIX:=
 LOCAL_HOST_REQUIRED_MODULES:=
diff --git a/core/config.mk b/core/config.mk
index 9ab3fff..4cc78b8 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -120,6 +120,8 @@
 )
 $(KATI_obsolete_var PRODUCT_IOT)
 $(KATI_obsolete_var MD5SUM)
+$(KATI_obsolete_var BOARD_HAL_STATIC_LIBRARIES, See $(CHANGES_URL)#BOARD_HAL_STATIC_LIBRARIES)
+$(KATI_obsolete_var LOCAL_HAL_STATIC_LIBRARIES, See $(CHANGES_URL)#BOARD_HAL_STATIC_LIBRARIES)
 
 # Used to force goals to build.  Only use for conditionally defined goals.
 .PHONY: FORCE
diff --git a/core/dex_preopt.mk b/core/dex_preopt.mk
index 32690fe..55eeec6 100644
--- a/core/dex_preopt.mk
+++ b/core/dex_preopt.mk
@@ -34,13 +34,13 @@
 
 $(boot_zip): PRIVATE_BOOTCLASSPATH_JARS := $(bootclasspath_jars)
 $(boot_zip): PRIVATE_SYSTEM_SERVER_JARS := $(system_server_jars)
-$(boot_zip): $(bootclasspath_jars) $(system_server_jars) $(SOONG_ZIP) $(MERGE_ZIPS) $(DEXPREOPT_IMAGE_ZIP_boot)
+$(boot_zip): $(bootclasspath_jars) $(system_server_jars) $(SOONG_ZIP) $(MERGE_ZIPS) $(DEXPREOPT_IMAGE_ZIP_boot) $(DEXPREOPT_IMAGE_ZIP_art)
 	@echo "Create boot package: $@"
 	rm -f $@
 	$(SOONG_ZIP) -o $@.tmp \
 	  -C $(dir $(firstword $(PRIVATE_BOOTCLASSPATH_JARS)))/.. $(addprefix -f ,$(PRIVATE_BOOTCLASSPATH_JARS)) \
 	  -C $(PRODUCT_OUT) $(addprefix -f ,$(PRIVATE_SYSTEM_SERVER_JARS))
-	$(MERGE_ZIPS) $@ $@.tmp $(DEXPREOPT_IMAGE_ZIP_boot)
+	$(MERGE_ZIPS) $@ $@.tmp $(DEXPREOPT_IMAGE_ZIP_boot) $(DEXPREOPT_IMAGE_ZIP_art)
 	rm -f $@.tmp
 
 $(call dist-for-goals, droidcore, $(boot_zip))
diff --git a/core/java.mk b/core/java.mk
index cbcd1b5..907f2dc 100644
--- a/core/java.mk
+++ b/core/java.mk
@@ -413,8 +413,6 @@
 legacy_proguard_flags += -printmapping $(proguard_dictionary)
 legacy_proguard_flags += -printconfiguration $(proguard_configuration)
 
-common_proguard_flags := -forceprocessing
-
 common_proguard_flag_files := $(BUILD_SYSTEM)/proguard.flags
 ifneq ($(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS)),)
 common_proguard_flags += -dontshrink # don't shrink tests by default
diff --git a/core/tasks/with-license.mk b/core/tasks/with-license.mk
index daa6897..469ad76 100644
--- a/core/tasks/with-license.mk
+++ b/core/tasks/with-license.mk
@@ -20,7 +20,7 @@
 	name := $(name)_debug
 endif
 
-name := $(name)-img-$(FILE_NAME_TAG)-with-license
+name := $(name)-flashable-$(FILE_NAME_TAG)-with-license
 
 with_license_intermediates := \
 	$(call intermediates-dir-for,PACKAGING,with_license)
@@ -35,8 +35,7 @@
 else
 	$(ZIP2ZIP) -i $(BUILT_TARGET_FILES_PACKAGE) -o $@ \
 		RADIO/bootloader.img:bootloader.img RADIO/radio.img:radio.img \
-		IMAGES/system.img:system.img IMAGES/vendor.img:vendor.img \
-		IMAGES/boot.img:boot.img OTA/android-info.txt:android-info.txt
+		IMAGES/*.img:. OTA/android-info.txt:android-info.txt
 endif
 with_license_zip := $(PRODUCT_OUT)/$(name).sh
 $(with_license_zip): PRIVATE_NAME := $(name)
diff --git a/target/product/base_system.mk b/target/product/base_system.mk
index 588c41a..98da3fc 100644
--- a/target/product/base_system.mk
+++ b/target/product/base_system.mk
@@ -207,6 +207,7 @@
     media_profiles_V1_0.dtd \
     MediaProviderLegacy \
     mediaserver \
+    mediatranscoding \
     mke2fs \
     monkey \
     mtpd \
diff --git a/target/product/gsi/Android.mk b/target/product/gsi/Android.mk
index 536fe0c..424cf05 100644
--- a/target/product/gsi/Android.mk
+++ b/target/product/gsi/Android.mk
@@ -162,10 +162,14 @@
 # TODO(b/141450808): remove following VNDK phony targets when **.libraries.txt files are provided by apexes.
 LOCAL_REQUIRED_MODULES := \
     $(foreach vndk_ver,$(PRODUCT_EXTRA_VNDK_VERSIONS),vndk_v$(vndk_ver)_$(TARGET_ARCH)$(_binder32))
-LOCAL_REQUIRED_MODULES += $(foreach vndk_ver,$(PRODUCT_EXTRA_VNDK_VERSIONS),com.android.vndk.v$(vndk_ver))
 _binder32 :=
 include $(BUILD_PHONY_PACKAGE)
 
+include $(CLEAR_VARS)
+LOCAL_MODULE := vndk_apex_snapshot_package
+LOCAL_REQUIRED_MODULES := $(foreach vndk_ver,$(PRODUCT_EXTRA_VNDK_VERSIONS),com.android.vndk.v$(vndk_ver))
+include $(BUILD_PHONY_PACKAGE)
+
 endif # BOARD_VNDK_VERSION is set
 
 #####################################################################
diff --git a/target/product/gsi_release.mk b/target/product/gsi_release.mk
index faaa935..aee7959 100644
--- a/target/product/gsi_release.mk
+++ b/target/product/gsi_release.mk
@@ -29,12 +29,6 @@
     system/product/% \
     system/system_ext/%
 
-
-# GSI doesn't support apex for now.
-# Properties set in product take precedence over those in vendor.
-PRODUCT_PRODUCT_PROPERTIES += \
-    ro.apex.updatable=false
-
 # Split selinux policy
 PRODUCT_FULL_TREBLE_OVERRIDE := true
 
diff --git a/target/product/media_system_ext.mk b/target/product/media_system_ext.mk
index 78cc6aa..2e20af3 100644
--- a/target/product/media_system_ext.mk
+++ b/target/product/media_system_ext.mk
@@ -22,3 +22,4 @@
 
 # /system_ext packages
 PRODUCT_PACKAGES += \
+    vndk_apex_snapshot_package \
diff --git a/tools/event_log_tags.py b/tools/event_log_tags.py
index 645839e..35b2de0 100644
--- a/tools/event_log_tags.py
+++ b/tools/event_log_tags.py
@@ -62,9 +62,9 @@
     try:
       for self.linenum, line in enumerate(file_object):
         self.linenum += 1
-
+        line = re.sub('#.*$', '', line) # strip trailing comments
         line = line.strip()
-        if not line or line[0] == '#': continue
+        if not line: continue
         parts = re.split(r"\s+", line, 2)
 
         if len(parts) < 2:
diff --git a/tools/generate-self-extracting-archive.py b/tools/generate-self-extracting-archive.py
index 5a193ab..5b0628d 100755
--- a/tools/generate-self-extracting-archive.py
+++ b/tools/generate-self-extracting-archive.py
@@ -38,7 +38,7 @@
 import os
 import zipfile
 
-_HEADER_TEMPLATE = """#!/bin/sh
+_HEADER_TEMPLATE = """#!/bin/bash
 #
 {comment_line}
 #
@@ -92,7 +92,7 @@
     dst.write(b)
 
 _MAX_OFFSET_WIDTH = 20
-def _generate_extract_command(start, end, extract_name):
+def _generate_extract_command(start, size, extract_name):
   """Generate the extract command.
 
   The length of this string must be constant no matter what the start and end
@@ -101,7 +101,7 @@
 
   Args:
     start: offset in bytes of the start of the wrapped file
-    end: offset in bytes of the end of the wrapped file
+    size: size in bytes of the wrapped file
     extract_name: of the file to create when extracted
 
   """
@@ -111,11 +111,11 @@
   if len(start_str) != _MAX_OFFSET_WIDTH + 1:
     raise Exception('Start offset too large (%d)' % start)
 
-  end_str = ('%d' % end).rjust(_MAX_OFFSET_WIDTH)
-  if len(end_str) != _MAX_OFFSET_WIDTH:
-    raise Exception('End offset too large (%d)' % end)
+  size_str = ('%d' % size).rjust(_MAX_OFFSET_WIDTH)
+  if len(size_str) != _MAX_OFFSET_WIDTH:
+    raise Exception('Size too large (%d)' % size)
 
-  return "tail -c %s $0 | head -c %s > %s\n" % (start_str, end_str, extract_name)
+  return "tail -c %s $0 | head -c %s > %s\n" % (start_str, size_str, extract_name)
 
 
 def main(argv):