Merge "Make room for AVB hashtree and metadata."
diff --git a/core/base_rules.mk b/core/base_rules.mk
index 56df2a9..13d20e0 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -269,9 +269,6 @@
 # dependent binaries of a .toc file will be rebuilt only when the content of
 # the .toc file is changed.
 ###########################################################
-ifndef LOCAL_IS_HOST_MODULE
-# Disable .toc optimization for host modules: we may run the host binaries during the build process
-# and the libraries' implementation matters.
 ifeq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES)
 LOCAL_INTERMEDIATE_TARGETS += $(LOCAL_BUILT_MODULE).toc
 $(LOCAL_BUILT_MODULE).toc: $(LOCAL_BUILT_MODULE)
@@ -283,7 +280,6 @@
 # Build .toc file when using mm, mma, or make $(my_register_name)
 $(my_all_targets): $(LOCAL_BUILT_MODULE).toc
 endif
-endif
 
 ###########################################################
 ## logtags: Add .logtags files to global list
diff --git a/core/binary.mk b/core/binary.mk
index 7f6f2fb..4dcb152 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -103,9 +103,7 @@
   # missing API levels to existing ones where necessary, but we're not doing
   # that for the generated libraries. Clip the API level to the minimum where
   # appropriate.
-  my_ndk_api := \
-    $(shell if [ $(LOCAL_SDK_VERSION) -lt $(my_min_sdk_version) ]; then \
-        echo $(my_min_sdk_version); else echo $(LOCAL_SDK_VERSION); fi)
+  my_ndk_api := $(call math_max,$(LOCAL_SDK_VERSION),$(my_min_sdk_version))
 
   # Traditionally this has come from android/api-level.h, but with the libc
   # headers unified it must be set by the build system since we don't have
@@ -1509,13 +1507,7 @@
     $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
       $(addsuffix $(so_suffix), \
         $(installed_shared_library_module_names)))
-ifdef LOCAL_IS_HOST_MODULE
-# Disable .toc optimization for host modules: we may run the host binaries during the build process
-# and the libraries' implementation matters.
-built_shared_library_deps := $(built_shared_libraries)
-else
 built_shared_library_deps := $(addsuffix .toc, $(built_shared_libraries))
-endif
 my_system_shared_libraries_fullpath :=
 endif
 
diff --git a/core/clang/tidy.mk b/core/clang/tidy.mk
index c1d485d..a081056 100644
--- a/core/clang/tidy.mk
+++ b/core/clang/tidy.mk
@@ -18,7 +18,7 @@
 # Global tidy checks include only google*, performance*,
 # and misc-macro-parentheses, but not google-readability*
 # or google-runtime-references.
-DEFAULT_GLOBAL_TIDY_CHECKS := \
+DEFAULT_GLOBAL_TIDY_CHECKS ?= \
   $(subst $(space),, \
     -*,google* \
     ,misc-macro-parentheses \
@@ -29,7 +29,7 @@
 
 # There are too many clang-tidy warnings in external and vendor projects.
 # Enable only some google checks for these projects.
-DEFAULT_EXTERNAL_VENDOR_TIDY_CHECKS := \
+DEFAULT_EXTERNAL_VENDOR_TIDY_CHECKS ?= \
   $(subst $(space),, \
     -*,google* \
     ,-google-build-using-namespace \
@@ -51,6 +51,7 @@
   hardware/qcom:$(DEFAULT_EXTERNAL_VENDOR_TIDY_CHECKS) \
   vendor/:$(DEFAULT_EXTERNAL_VENDOR_TIDY_CHECKS) \
   vendor/google:$(DEFAULT_GLOBAL_TIDY_CHECKS) \
+  vendor/google_devices:$(DEFAULT_EXTERNAL_VENDOR_TIDY_CHECKS) \
 
 # Returns 2nd word of $(1) if $(2) has prefix of the 1st word of $(1).
 define find_default_local_tidy_check2
diff --git a/core/clear_vars.mk b/core/clear_vars.mk
index 1d927b0..faf18e3 100644
--- a/core/clear_vars.mk
+++ b/core/clear_vars.mk
@@ -376,7 +376,6 @@
 LOCAL_MODULE_SYMLINKS_32:=
 LOCAL_MODULE_SYMLINKS_64:=
 LOCAL_JAVA_LANGUAGE_VERSION:=
-LOCAL_CTS_GTEST_LIST_EXECUTABLE:=
 
 LOCAL_IS_AUX_MODULE :=
 LOCAL_AUX_TOOLCHAIN :=
diff --git a/core/definitions.mk b/core/definitions.mk
index 83f7efc..61e0461 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -718,15 +718,6 @@
 endef
 
 ###########################################################
-## Run rot13 on a string
-## $(1): the string.  Must be one line.
-###########################################################
-define rot13
-$(shell echo $(1) | tr 'a-zA-Z' 'n-za-mN-ZA-M')
-endef
-
-
-###########################################################
 ## Returns true if $(1) and $(2) are equal.  Returns
 ## the empty string if they are not equal.
 ###########################################################
@@ -3170,6 +3161,55 @@
 endef
 
 ###########################################################
+# Basic math functions for positive integers <= 100
+#
+# (SDK versions for example)
+###########################################################
+__MATH_NUMBERS :=  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 \
+                  21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
+                  41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \
+                  61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 \
+                  81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
+
+# Returns true if $(1) is a positive integer <= 100, otherwise returns nothing.
+define math_is_number
+$(strip \
+  $(if $(1),,$(error Argument missing)) \
+  $(if $(word 2,$(1)),$(error Multiple words in a single argument: $(1))) \
+  $(if $(filter $(1),$(__MATH_NUMBERS)),true))
+endef
+
+#$(warning true == $(call math_is_number,2))
+#$(warning == $(call math_is_number,foo))
+#$(call math_is_number,1 2)
+#$(call math_is_number,no 2)
+
+define _math_check_valid
+$(if $(call math_is_number,$(1)),,$(error Only positive integers <= 100 are supported (not $(1))))
+endef
+
+#$(call _math_check_valid,0)
+#$(call _math_check_valid,1)
+#$(call _math_check_valid,100)
+#$(call _math_check_valid,101)
+#$(call _math_check_valid,)
+#$(call _math_check_valid,1 2)
+
+# Returns the greater of $1 or $2.
+# If $1 or $2 is not a positive integer <= 100, then an error is generated.
+define math_max
+$(strip $(call _math_check_valid,$(1)) $(call _math_check_valid,$(2)) \
+  $(lastword $(filter $(1) $(2),$(__MATH_NUMBERS))))
+endef
+
+#$(call math_max)
+#$(call math_max,1)
+#$(call math_max,1 2,3)
+#$(warning 1 == $(call math_max,1,1))
+#$(warning 42 == $(call math_max,5,42))
+#$(warning 42 == $(call math_max,42,5))
+
+###########################################################
 ## Other includes
 ###########################################################
 
diff --git a/core/main.mk b/core/main.mk
index fee2995..de77927 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -660,6 +660,14 @@
 $(1): | $(2)
 endef
 
+# Use a normal dependency instead of an order-only dependency when installing
+# host dynamic binaries so that the timestamp of the final binary always
+# changes, even if the toc optimization has skipped relinking the binary
+# and its dependant shared libraries.
+define add-required-host-so-deps
+$(1): $(2)
+endef
+
 $(foreach m,$(ALL_MODULES), \
   $(eval r := $(ALL_MODULES.$(m).REQUIRED)) \
   $(if $(r), \
@@ -702,7 +710,9 @@
   $(if $(3),$(eval deps := $(addprefix host_cross_,$(deps))))\
   $(eval r := $(filter $($(root))/%,$(call module-installed-files,\
     $(deps))))\
-  $(eval $(call add-required-deps,$(word 2,$(p)),$(r)))\
+  $(if $(filter $(1),HOST_),\
+    $(eval $(call add-required-host-so-deps,$(word 2,$(p)),$(r))),\
+    $(eval $(call add-required-deps,$(word 2,$(p)),$(r))))\
   $(eval ALL_MODULES.$(mod).REQUIRED += $(deps)))
 endef
 
diff --git a/core/ninja.mk b/core/ninja.mk
index f3aa70e..3779df3 100644
--- a/core/ninja.mk
+++ b/core/ninja.mk
@@ -148,7 +148,7 @@
 .PHONY: ninja_wrapper
 ninja_wrapper: $(COMBINED_BUILD_NINJA) $(MAKEPARALLEL)
 	@echo Starting build with ninja
-	+$(hide) export NINJA_STATUS="$(NINJA_STATUS)" && source $(KATI_ENV_SH) && $(NINJA_MAKEPARALLEL) $(NINJA) $(NINJA_GOALS) -C $(TOP) -f $(COMBINED_BUILD_NINJA) $(NINJA_ARGS)
+	+$(hide) export NINJA_STATUS="$(NINJA_STATUS)" && source $(KATI_ENV_SH) && exec $(NINJA_MAKEPARALLEL) $(NINJA) -d keepdepfile $(NINJA_GOALS) -C $(TOP) -f $(COMBINED_BUILD_NINJA) $(NINJA_ARGS)
 
 # Dummy Android.mk and CleanSpec.mk files so that kati won't recurse into the
 # out directory
diff --git a/core/product.mk b/core/product.mk
index ad9b022..7193cf7 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -301,7 +301,7 @@
 #
 define stash-product-vars
 $(foreach v,$(_product_stash_var_list), \
-        $(eval $(strip $(1))_$(call rot13,$(v)):=$$($$(v))) \
+        $(eval $(strip $(1))_rot26_$(v):=$$($$(v))) \
  )
 endef
 
@@ -313,7 +313,7 @@
 $(strip \
   $(eval changed_variables:=)
   $(foreach v,$(_product_stash_var_list), \
-    $(if $(call streq,$($(v)),$($(strip $(1))_$(call rot13,$(v)))),, \
+    $(if $(call streq,$($(v)),$($(strip $(1))_rot26_$(v))),, \
         $(eval $(warning $(v) has been modified: $($(v)))) \
         $(eval $(warning previous value: $($(strip $(1))_$(call rot13,$(v))))) \
         $(eval changed_variables := $(changed_variables) $(v))) \
diff --git a/tools/droiddoc/templates-ndk/assets/css/default.css b/tools/droiddoc/templates-ndk/assets/css/default.css
index f411d93..036c0eb 100644
--- a/tools/droiddoc/templates-ndk/assets/css/default.css
+++ b/tools/droiddoc/templates-ndk/assets/css/default.css
@@ -4217,7 +4217,7 @@
 }
 
 /* offset the <a name=""> tags to account for sticky nav */
-body.reference a[name] {
+body.reference a[name]:empty {
   visibility: hidden;
   display: block;
   position: relative;
diff --git a/tools/droiddoc/templates-sdk-dev/assets/css/default.css b/tools/droiddoc/templates-sdk-dev/assets/css/default.css
index 43449d4..11bbacf 100644
--- a/tools/droiddoc/templates-sdk-dev/assets/css/default.css
+++ b/tools/droiddoc/templates-sdk-dev/assets/css/default.css
@@ -3209,7 +3209,7 @@
 }
 
 /* offset the <a name=""> tags to account for sticky nav */
-body.reference a[name] {
+body.reference a[name]:empty {
   visibility: hidden;
   display: block;
   position: relative;
diff --git a/tools/droiddoc/templates-sdk-refonly/assets/css/default.css b/tools/droiddoc/templates-sdk-refonly/assets/css/default.css
index 106ab2f..d12852a 100644
--- a/tools/droiddoc/templates-sdk-refonly/assets/css/default.css
+++ b/tools/droiddoc/templates-sdk-refonly/assets/css/default.css
@@ -732,7 +732,7 @@
     text-align:center;
     width: 50%;
   }
-  
+
   .training-nav-top a.prev-page-link {
     padding-left: 15px;
     text-align: left;
@@ -840,7 +840,7 @@
     margin: 0 0 6px;
     line-height: 16px;
   }
-  
+
   /* Class colors */
   ol.class-list li:nth-child(10n+1) .title {
     background: #00bcd4;
@@ -872,7 +872,7 @@
   ol.class-list li:nth-child(10n+10) .title {
     background: #7e57c2;
   }
-  
+
   @media (max-width: 719px) {
     ol.class-list ol,
     ol.class-list .description {
@@ -3822,8 +3822,8 @@
   display: none;
 }
 
-/* offset the <a name=""> tags to account for sticky nav */
-body.reference a[name] {
+/* offset the empty <a name=""> tags to account for sticky nav */
+body.reference a[name]:empty {
   visibility: hidden;
   display: block;
   position: relative;
@@ -6376,7 +6376,7 @@
 .dac-button.dac-raised.dac-primary, .landing-secondary, .button {
   background-color: #039bef; }
   .dac-button.dac-raised.dac-primary:hover, .landing-secondary:hover, .button:hover {
-    background-color: #0288d1; 
+    background-color: #0288d1;
     color:#fff; }
   .dac-button.dac-raised.dac-primary:active, .landing-secondary:active, .button:active {
     background-color: #0277bd;
diff --git a/tools/droiddoc/templates-sdk/assets/css/default.css b/tools/droiddoc/templates-sdk/assets/css/default.css
index accf7bf..c71f4f4 100644
--- a/tools/droiddoc/templates-sdk/assets/css/default.css
+++ b/tools/droiddoc/templates-sdk/assets/css/default.css
@@ -3822,15 +3822,14 @@
   display: none;
 }
 
-/* offset the <a name=""> tags to account for sticky nav */
-body.reference a[name] {
+/* offset the empty <a name=""> tags to account for sticky nav */
+body.reference a[name]:empty {
   visibility: hidden;
   display: block;
   position: relative;
   top: -56px;
 }
 
-
 /* Quicknav */
 .btn-quicknav {
   width:20px;
diff --git a/tools/makeparallel/makeparallel.cpp b/tools/makeparallel/makeparallel.cpp
index c70fa9a..4ae8f61 100644
--- a/tools/makeparallel/makeparallel.cpp
+++ b/tools/makeparallel/makeparallel.cpp
@@ -337,7 +337,29 @@
 
   args.push_back(nullptr);
 
-  pid_t pid = fork();
+  static pid_t pid;
+
+  // Set up signal handlers to forward SIGHUP, SIGINT, SIGQUIT, SIGTERM, and
+  // SIGALRM to child
+  struct sigaction action = {};
+  action.sa_flags = SA_SIGINFO | SA_RESTART,
+  action.sa_sigaction = [](int signal, siginfo_t*, void*) {
+    if (pid > 0) {
+      kill(pid, signal);
+    }
+  };
+
+  int ret = 0;
+  if (!ret) ret = sigaction(SIGHUP, &action, NULL);
+  if (!ret) ret = sigaction(SIGINT, &action, NULL);
+  if (!ret) ret = sigaction(SIGQUIT, &action, NULL);
+  if (!ret) ret = sigaction(SIGTERM, &action, NULL);
+  if (!ret) ret = sigaction(SIGALRM, &action, NULL);
+  if (ret < 0) {
+    error(errno, errno, "sigaction failed");
+  }
+
+  pid = fork();
   if (pid < 0) {
     error(errno, errno, "fork failed");
   } else if (pid == 0) {
@@ -361,9 +383,10 @@
   }
 
   // parent
+
   siginfo_t status = {};
   int exit_status = 0;
-  int ret = waitid(P_PID, pid, &status, WEXITED);
+  ret = waitid(P_PID, pid, &status, WEXITED);
   if (ret < 0) {
     error(errno, errno, "waitpid failed");
   } else if (status.si_code == CLD_EXITED) {
diff --git a/tools/releasetools/sign_target_files_apks.py b/tools/releasetools/sign_target_files_apks.py
index 6d68be1..7f69a57 100755
--- a/tools/releasetools/sign_target_files_apks.py
+++ b/tools/releasetools/sign_target_files_apks.py
@@ -280,7 +280,7 @@
       pass
 
     # Skip the care_map as we will regenerate the system/vendor images.
-    elif (info.filename == "META/care_map.txt"):
+    elif info.filename == "META/care_map.txt":
       pass
 
     # Copy BOOT/, RECOVERY/, META/, ROOT/ to rebuild recovery patch. This case
@@ -553,9 +553,12 @@
   for param in in_cmdline.split():
     if "veritykeyid" in param:
       # extract keyid using openssl command
-      p = common.Run(["openssl", "x509", "-in", keypath, "-text"], stdout=subprocess.PIPE)
+      p = common.Run(
+          ["openssl", "x509", "-in", keypath, "-text"],
+          stdout=subprocess.PIPE)
       keyid, stderr = p.communicate()
-      keyid = re.search(r'keyid:([0-9a-fA-F:]*)', keyid).group(1).replace(':', '').lower()
+      keyid = re.search(
+          r'keyid:([0-9a-fA-F:]*)', keyid).group(1).replace(':', '').lower()
       print "Replacing verity keyid with %s error=%s" % (keyid, stderr)
       out_cmdline.append("veritykeyid=id:%s" % (keyid,))
     else:
@@ -592,7 +595,6 @@
   codename = None
   for line in data.split("\n"):
     line = line.strip()
-    original_line = line
     if line and line[0] != '#' and "=" in line:
       key, value = line.split("=", 1)
       key = key.strip()
@@ -615,7 +617,6 @@
   codenames = None
   for line in data.split("\n"):
     line = line.strip()
-    original_line = line
     if line and line[0] != '#' and "=" in line:
       key, value = line.split("=", 1)
       key = key.strip()
@@ -698,12 +699,8 @@
   CheckAllApksSigned(input_zip, apk_key_map)
 
   key_passwords = common.GetKeyPasswords(set(apk_key_map.values()))
-  platform_api_level, platform_codename = GetApiLevelAndCodename(input_zip)
+  platform_api_level, _ = GetApiLevelAndCodename(input_zip)
   codename_to_api_level_map = GetCodenameToApiLevelMap(input_zip)
-  # Android N will be API Level 24, but isn't yet.
-  # TODO: Remove this workaround once Android N is officially API Level 24.
-  if platform_api_level == 23 and platform_codename == "N":
-    platform_api_level = 24
 
   ProcessTargetFiles(input_zip, output_zip, misc_info,
                      apk_key_map, key_passwords,