Merge "Include target api version in build system for rscpp."
diff --git a/core/Makefile b/core/Makefile
index 41a169a..73d6e4b 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -695,7 +695,7 @@
 INTERNAL_USERIMAGES_DEPS += $(BUILD_VERITY_TREE) $(APPEND2SIMG) $(VERITY_SIGNER)
 endif
 
-SELINUX_FC := $(TARGET_ROOT_OUT)/file_contexts
+SELINUX_FC := $(TARGET_ROOT_OUT)/file_contexts.bin
 INTERNAL_USERIMAGES_DEPS += $(SELINUX_FC)
 
 # $(1): the path of the output dictionary file
@@ -1483,7 +1483,7 @@
 	$(hide) $(ACP) $(APKCERTS_FILE) $(zip_root)/META/apkcerts.txt
 	$(hide) if test -e $(tool_extensions)/releasetools.py; then $(ACP) $(tool_extensions)/releasetools.py $(zip_root)/META/; fi
 	$(hide) echo "$(PRODUCT_OTA_PUBLIC_KEYS)" > $(zip_root)/META/otakeys.txt
-	$(hide) $(ACP) $(SELINUX_FC) $(zip_root)/META/file_contexts
+	$(hide) $(ACP) $(SELINUX_FC) $(zip_root)/META/file_contexts.bin
 	$(hide) echo "recovery_api_version=$(PRIVATE_RECOVERY_API_VERSION)" > $(zip_root)/META/misc_info.txt
 	$(hide) echo "fstab_version=$(PRIVATE_RECOVERY_FSTAB_VERSION)" >> $(zip_root)/META/misc_info.txt
 ifdef BOARD_FLASH_BLOCK_SIZE
diff --git a/core/binary.mk b/core/binary.mk
index 7d6ee40..35ecaa3 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -1140,6 +1140,15 @@
   my_cflags := $(filter-out $(fdo_incompatible_flags),$(my_cflags))
 endif
 
+# No one should ever use this flag. On GCC it's mere presence will disable all
+# warnings, even those that are specified after it (contrary to typical warning
+# flag behavior). This circumvents CFLAGS_NO_OVERRIDE from forcibly enabling the
+# warnings that are *always* bugs.
+my_illegal_flags := -w
+my_cflags := $(filter-out $(my_illegal_flags),$(my_cflags))
+my_cppflags := $(filter-out $(my_illegal_flags),$(my_cppflags))
+my_conlyflags := $(filter-out $(my_illegal_flags),$(my_conlyflags))
+
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(my_asflags)
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CONLYFLAGS := $(my_conlyflags)
diff --git a/core/config.mk b/core/config.mk
index 876161b..498c793 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -595,7 +595,7 @@
 
 # allow overriding default Java libraries on a per-target basis
 ifeq ($(TARGET_DEFAULT_JAVA_LIBRARIES),)
-  TARGET_DEFAULT_JAVA_LIBRARIES := core-libart core-junit ext framework
+  TARGET_DEFAULT_JAVA_LIBRARIES := core-libart core-junit ext framework okhttp
 endif
 
 # Flags for DEX2OAT
diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk
index 41956cb..78cedad 100644
--- a/core/config_sanitizers.mk
+++ b/core/config_sanitizers.mk
@@ -82,7 +82,7 @@
   ifdef LOCAL_IS_HOST_MODULE
     my_cflags += -fno-sanitize-recover=all
     my_ldflags += -fsanitize=$(fsanitize_arg)
-    my_ldlibs += -ldl
+    my_ldlibs += -lrt -ldl
   else
     my_cflags += -fsanitize-undefined-trap-on-error
     my_cflags += -ftrap-function=abort
diff --git a/target/product/embedded.mk b/target/product/embedded.mk
index c40de4f..468fbe5 100644
--- a/target/product/embedded.mk
+++ b/target/product/embedded.mk
@@ -75,7 +75,7 @@
 # SELinux packages
 PRODUCT_PACKAGES += \
     sepolicy \
-    file_contexts \
+    file_contexts.bin \
     seapp_contexts \
     property_contexts \
     mac_permissions.xml \
diff --git a/tools/releasetools/blockimgdiff.py b/tools/releasetools/blockimgdiff.py
index a32c6b1..e042e03 100644
--- a/tools/releasetools/blockimgdiff.py
+++ b/tools/releasetools/blockimgdiff.py
@@ -350,6 +350,12 @@
           mapped_stashes.append(sr)
           if self.version == 2:
             src_str.append("%d:%s" % (sid, sr.to_string_raw()))
+            # A stash will be used only once. We need to free the stash
+            # immediately after the use, instead of waiting for the automatic
+            # clean-up at the end. Because otherwise it may take up extra space
+            # and lead to OTA failures.
+            # Bug: 23119955
+            free_string.append("free %d\n" % (sid,))
           else:
             assert sh in stashes
             src_str.append("%s:%s" % (sh, sr.to_string_raw()))
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 051a22d..d56c0fd 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -154,16 +154,16 @@
   # are doing repacking. Redirect those properties to the actual files in the
   # unzipped directory.
   if input_dir is not None:
-    # We carry a copy of file_contexts under META/. If not available, search
-    # BOOT/RAMDISK/. Note that sometimes we may need a different file_contexts
+    # We carry a copy of file_contexts.bin under META/. If not available,
+    # search BOOT/RAMDISK/. Note that sometimes we may need a different file
     # to build images than the one running on device, such as when enabling
     # system_root_image. In that case, we must have the one for image
     # generation copied to META/.
-    fc_config = os.path.join(input_dir, "META", "file_contexts")
+    fc_config = os.path.join(input_dir, "META", "file_contexts.bin")
     if d.get("system_root_image") == "true":
       assert os.path.exists(fc_config)
     if not os.path.exists(fc_config):
-      fc_config = os.path.join(input_dir, "BOOT", "RAMDISK", "file_contexts")
+      fc_config = os.path.join(input_dir, "BOOT", "RAMDISK", "file_contexts.bin")
       if not os.path.exists(fc_config):
         fc_config = None
 
diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py
index e40d06a..9ab8cb3 100755
--- a/tools/releasetools/ota_from_target_files.py
+++ b/tools/releasetools/ota_from_target_files.py
@@ -585,8 +585,8 @@
   if HasVendorPartition(input_zip):
     system_progress -= 0.1
 
-  # Place a copy of file_contexts into the OTA package which will be used by
-  # the recovery program.
+  # Place a copy of file_contexts.bin into the OTA package which will be used
+  # by the recovery program.
   if "selinux_fc" in OPTIONS.info_dict:
     WritePolicyConfig(OPTIONS.info_dict["selinux_fc"], output_zip)