Merge "AAPT2: library resource compilation" into nyc-dev
diff --git a/core/Makefile b/core/Makefile
index 5ad6505..5423322 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -47,6 +47,20 @@
 unique_product_copy_files_destinations :=
 
 # -----------------------------------------------------------------
+# Define rules to copy headers defined in copy_headers.mk
+# If more than one makefile declared a header, print a warning,
+# then copy the last one defined. This matches the previous make
+# behavior.
+$(foreach dest,$(ALL_COPIED_HEADERS), \
+    $(eval _srcs := $(ALL_COPIED_HEADERS.$(dest).SRC)) \
+    $(eval _src := $(word $(words $(_srcs)),$(_srcs))) \
+    $(if $(call streq,$(_src),$(_srcs)),, \
+        $(warning Duplicate header copy: $(dest)) \
+	$(warning Defined in: $(ALL_COPIED_HEADERS.$(dest).MAKEFILE))) \
+    $(eval $(call copy-one-header,$(_src),$(dest))))
+all_copied_headers: $(ALL_COPIED_HEADERS)
+
+# -----------------------------------------------------------------
 # docs/index.html
 ifeq (,$(TARGET_BUILD_APPS))
 gen := $(OUT_DOCS)/index.html
@@ -469,7 +483,6 @@
 # the ramdisk
 INTERNAL_RAMDISK_FILES := $(filter $(TARGET_ROOT_OUT)/%, \
 	$(ALL_PREBUILT) \
-	$(ALL_COPIED_HEADERS) \
 	$(ALL_GENERATED_SOURCES) \
 	$(ALL_DEFAULT_INSTALLED_MODULES))
 
@@ -1034,7 +1047,6 @@
 
 INTERNAL_SYSTEMIMAGE_FILES := $(filter $(TARGET_OUT)/%, \
     $(ALL_PREBUILT) \
-    $(ALL_COPIED_HEADERS) \
     $(ALL_GENERATED_SOURCES) \
     $(ALL_DEFAULT_INSTALLED_MODULES) \
     $(PDK_FUSION_SYSIMG_FILES) \
@@ -1951,7 +1963,6 @@
 ifeq ($(strip $(ATREE_FILES)),)
 ATREE_FILES := \
 	$(ALL_PREBUILT) \
-	$(ALL_COPIED_HEADERS) \
 	$(ALL_DEFAULT_INSTALLED_MODULES) \
 	$(INSTALLED_RAMDISK_TARGET) \
 	$(ALL_DOCS) \
diff --git a/core/cleanbuild.mk b/core/cleanbuild.mk
index f7722d2..c5b15bc 100644
--- a/core/cleanbuild.mk
+++ b/core/cleanbuild.mk
@@ -248,6 +248,7 @@
 	$(PRODUCT_OUT)/obj/JAVA_LIBRARIES \
 	$(PRODUCT_OUT)/obj/FAKE \
 	$(PRODUCT_OUT)/obj/EXECUTABLES/adbd_intermediates \
+	$(PRODUCT_OUT)/obj/EXECUTABLES/logd_intermediates \
 	$(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libfs_mgr_intermediates \
 	$(PRODUCT_OUT)/obj/EXECUTABLES/init_intermediates \
 	$(PRODUCT_OUT)/obj/ETC/mac_permissions.xml_intermediates \
diff --git a/core/combo/arch/arm/armv7-a-neon.mk b/core/combo/arch/arm/armv7-a-neon.mk
index 5dc1fec..5d5b050 100644
--- a/core/combo/arch/arm/armv7-a-neon.mk
+++ b/core/combo/arch/arm/armv7-a-neon.mk
@@ -6,6 +6,8 @@
 ARCH_ARM_HAVE_VFP_D32           := true
 ARCH_ARM_HAVE_NEON              := true
 
+local_arch_has_lpae := false
+
 ifneq (,$(filter cortex-a15 krait denver,$(TARGET_$(combo_2nd_arch_prefix)CPU_VARIANT)))
 	# TODO: krait is not a cortex-a15, we set the variant to cortex-a15 so that
 	#       hardware divide operations are generated. This should be removed and a
@@ -13,9 +15,7 @@
 	#       core/clang/arm.mk.
 	arch_variant_cflags := -mcpu=cortex-a15
 
-	# Fake an ARM compiler flag as these processors support LPAE which GCC/clang
-	# don't advertise.
-	arch_variant_cflags += -D__ARM_FEATURE_LPAE=1
+	local_arch_has_lpae := true
 	arch_variant_ldflags := \
 		-Wl,--no-fix-cortex-a8
 else
@@ -26,6 +26,8 @@
 else
 ifneq (,$(filter cortex-a7 cortex-a53 cortex-a53.a57,$(TARGET_$(combo_2nd_arch_prefix)CPU_VARIANT)))
 	arch_variant_cflags := -mcpu=cortex-a7
+
+	local_arch_has_lpae := true
 	arch_variant_ldflags := \
 		-Wl,--no-fix-cortex-a8
 else
@@ -37,6 +39,16 @@
 endif
 endif
 
+ifeq (true,$(local_arch_has_lpae))
+	# Fake an ARM compiler flag as these processors support LPAE which GCC/clang
+	# don't advertise.
+	# TODO This is a hack and we need to add it for each processor that supports LPAE until some
+	# better solution comes around. See Bug 27340895
+	arch_variant_cflags += -D__ARM_FEATURE_LPAE=1
+endif
+
+local_arch_has_lpae :=
+
 arch_variant_cflags += \
     -mfloat-abi=softfp \
     -mfpu=neon
diff --git a/core/copy_headers.mk b/core/copy_headers.mk
index e16560f..7d5a5d9 100644
--- a/core/copy_headers.mk
+++ b/core/copy_headers.mk
@@ -18,8 +18,10 @@
       $(if $(LOCAL_COPY_HEADERS_TO),\
         $($(my_prefix)OUT_HEADERS)/$(LOCAL_COPY_HEADERS_TO)/$(notdir $(header)),\
         $($(my_prefix)OUT_HEADERS)/$(notdir $(header)))) \
-  $(eval $(call copy-one-header,$(_chFrom),$(_chTo))) \
-  $(eval all_copied_headers: $(_chTo)) \
+  $(eval ALL_COPIED_HEADERS.$(_chTo).MAKEFILE += $(LOCAL_MODULE_MAKEFILE)) \
+  $(eval ALL_COPIED_HEADERS.$(_chTo).SRC += $(_chFrom)) \
+  $(if $(filter $(_chTo),$(ALL_COPIED_HEADERS)),, \
+      $(eval ALL_COPIED_HEADERS += $(_chTo))) \
  )
 _chFrom :=
 _chTo :=
diff --git a/core/java_common.mk b/core/java_common.mk
index b88bfe4..59f473c 100644
--- a/core/java_common.mk
+++ b/core/java_common.mk
@@ -4,7 +4,7 @@
 ## Java version
 ###########################################################
 ifeq (,$(LOCAL_JAVA_LANGUAGE_VERSION))
-  LOCAL_JAVA_LANGUAGE_VERSION := 1.7
+  LOCAL_JAVA_LANGUAGE_VERSION := 1.8
 endif
 LOCAL_JAVACFLAGS += -source $(LOCAL_JAVA_LANGUAGE_VERSION) -target $(LOCAL_JAVA_LANGUAGE_VERSION)
 
diff --git a/core/main.mk b/core/main.mk
index ae53c37..5c2e3a1 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -137,6 +137,8 @@
 
 # CTS-specific config.
 -include cts/build/config.mk
+# VTS-specific config.
+-include test/vts/tools/vts-tradefed/build/config.mk
 
 # This allows us to force a clean build - included after the config.mk
 # environment setup is done, but before we generate any dependencies.  This
diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk
index 36d2df5..7c08af7 100644
--- a/core/prebuilt_internal.mk
+++ b/core/prebuilt_internal.mk
@@ -289,7 +289,9 @@
 endif
 endif # LOCAL_MODULE_CLASS != APPS
 
-ifeq ($(LOCAL_IS_HOST_MODULE)$(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
+ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
+my_src_jar := $(my_prebuilt_src_file)
+ifeq ($(LOCAL_IS_HOST_MODULE),)
 # for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir,
 # while the deps should be in the common dir, so we make a copy in the common dir.
 # For nonstatic library, $(common_javalib_jar) is the dependency file,
@@ -310,9 +312,6 @@
 	# Make sure the extracted classes.jar has a new timestamp.
 	$(hide) touch $@
 
-else
-# This is jar file.
-my_src_jar := $(my_prebuilt_src_file)
 endif
 $(common_classes_jar) : $(my_src_jar) | $(ACP)
 	$(transform-prebuilt-to-target)
@@ -352,14 +351,13 @@
 endif  # LOCAL_USE_AAPT2
 # make sure the classes.jar and javalib.jar are built before $(LOCAL_BUILT_MODULE)
 $(built_module) : $(common_javalib_jar)
-endif # TARGET JAVA_LIBRARIES
-
-ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
+endif # LOCAL_IS_HOST_MODULE is not set
 
 ifneq ($(LOCAL_JILL_FLAGS),)
 $(error LOCAL_JILL_FLAGS is not supported any more, please use jack options in LOCAL_JACK_FLAGS instead)
 endif
 
+# We may be building classes.jack from a host jar for host dalvik Java library.
 $(intermediates.COMMON)/classes.jack : PRIVATE_JACK_FLAGS:=$(LOCAL_JACK_FLAGS)
 $(intermediates.COMMON)/classes.jack : $(my_src_jar) $(LOCAL_MODULE_MAKEFILE_DEP) \
         $(LOCAL_ADDITIONAL_DEPENDENCIES) $(JACK) | setup-jack-server
diff --git a/core/tasks/vts.mk b/core/tasks/vts.mk
new file mode 100644
index 0000000..507f22e
--- /dev/null
+++ b/core/tasks/vts.mk
@@ -0,0 +1,23 @@
+# Copyright (C) 2016 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.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+test_suite_name := vts
+test_suite_tradefed := vts-tradefed
+test_suite_readme := test/vts/README.md
+
+include $(BUILD_SYSTEM)/tasks/tools/compatibility.mk
+
+.PHONY: vts
+vts: $(compatibility_zip)
+$(call dist-for-goals, vts, $(compatibility_zip))
diff --git a/target/board/generic/sepolicy/surfaceflinger.te b/target/board/generic/sepolicy/surfaceflinger.te
index 4c35469..e03d07e 100644
--- a/target/board/generic/sepolicy/surfaceflinger.te
+++ b/target/board/generic/sepolicy/surfaceflinger.te
@@ -1,2 +1,4 @@
 allow surfaceflinger self:process execmem;
 allow surfaceflinger ashmem_device:chr_file execute;
+
+set_prop(surfaceflinger, qemu_prop)
diff --git a/target/board/generic_x86_64/BoardConfig.mk b/target/board/generic_x86_64/BoardConfig.mk
index 214454e..553bec9 100755
--- a/target/board/generic_x86_64/BoardConfig.mk
+++ b/target/board/generic_x86_64/BoardConfig.mk
@@ -38,7 +38,7 @@
 USE_OPENGL_RENDERER := true
 
 TARGET_USERIMAGES_USE_EXT4 := true
-BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1610612736
+BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1879048192  # 1.75 GB
 BOARD_USERDATAIMAGE_PARTITION_SIZE := 576716800
 BOARD_CACHEIMAGE_PARTITION_SIZE := 69206016
 BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
diff --git a/target/product/base.mk b/target/product/base.mk
index acc643b..dba2fb7 100644
--- a/target/product/base.mk
+++ b/target/product/base.mk
@@ -32,8 +32,6 @@
     bugreport \
     cameraserver \
     content \
-    dhcpcd \
-    dhcpcd-run-hooks \
     dnsmasq \
     dpm \
     framework \
diff --git a/target/product/sdk_base.mk b/target/product/sdk_base.mk
index 7cb1fd3..2945f8c 100644
--- a/target/product/sdk_base.mk
+++ b/target/product/sdk_base.mk
@@ -73,6 +73,7 @@
 	device/generic/goldfish/camera/media_codecs.xml:system/etc/media_codecs.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.autofocus.xml:system/etc/permissions/android.hardware.camera.autofocus.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 \
 	hardware/libhardware_legacy/audio/audio_policy.conf:system/etc/audio_policy.conf
 
diff --git a/target/product/sdk_phone_arm64.mk b/target/product/sdk_phone_arm64.mk
index c770663..a689475 100644
--- a/target/product/sdk_phone_arm64.mk
+++ b/target/product/sdk_phone_arm64.mk
@@ -23,6 +23,9 @@
 $(call inherit-product, $(SRC_TARGET_DIR)/product/sdk_base.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/board/generic_arm64/device.mk)
 
+# AOSP emulator images build the AOSP messaging app.
+# Google API images override with the Google API app.
+# See vendor/google/products/sdk_google_phone_*.mk
 PRODUCT_PACKAGES += \
     messaging
 
diff --git a/target/product/sdk_phone_armv7.mk b/target/product/sdk_phone_armv7.mk
index 0851318..ebdd0e7 100644
--- a/target/product/sdk_phone_armv7.mk
+++ b/target/product/sdk_phone_armv7.mk
@@ -16,6 +16,9 @@
 
 $(call inherit-product, $(SRC_TARGET_DIR)/product/sdk_base.mk)
 
+# AOSP emulator images build the AOSP messaging app.
+# Google API images override with the Google API app.
+# See vendor/google/products/sdk_google_phone_*.mk
 PRODUCT_PACKAGES += \
     messaging
 
diff --git a/target/product/sdk_phone_mips.mk b/target/product/sdk_phone_mips.mk
index 2f577d3..1cc2fe4 100644
--- a/target/product/sdk_phone_mips.mk
+++ b/target/product/sdk_phone_mips.mk
@@ -21,6 +21,9 @@
 
 $(call inherit-product, $(SRC_TARGET_DIR)/product/sdk_base.mk)
 
+# AOSP emulator images build the AOSP messaging app.
+# Google API images override with the Google API app.
+# See vendor/google/products/sdk_google_phone_*.mk
 PRODUCT_PACKAGES += \
     messaging
 
diff --git a/target/product/sdk_phone_mips64.mk b/target/product/sdk_phone_mips64.mk
index 2c05f31..e45d71b 100644
--- a/target/product/sdk_phone_mips64.mk
+++ b/target/product/sdk_phone_mips64.mk
@@ -22,6 +22,9 @@
 $(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/product/sdk_base.mk)
 
+# AOSP emulator images build the AOSP messaging app.
+# Google API images override with the Google API app.
+# See vendor/google/products/sdk_google_phone_*.mk
 PRODUCT_PACKAGES += \
     messaging
 
diff --git a/target/product/sdk_phone_x86.mk b/target/product/sdk_phone_x86.mk
index 2feb6cc..01c2e83 100644
--- a/target/product/sdk_phone_x86.mk
+++ b/target/product/sdk_phone_x86.mk
@@ -21,6 +21,9 @@
 
 $(call inherit-product, $(SRC_TARGET_DIR)/product/sdk_base.mk)
 
+# AOSP emulator images build the AOSP messaging app.
+# Google API images override with the Google API app.
+# See vendor/google/products/sdk_google_phone_*.mk
 PRODUCT_PACKAGES += \
     messaging
 
diff --git a/target/product/sdk_phone_x86_64.mk b/target/product/sdk_phone_x86_64.mk
index f3573a2..c3bc5e9 100644
--- a/target/product/sdk_phone_x86_64.mk
+++ b/target/product/sdk_phone_x86_64.mk
@@ -22,6 +22,9 @@
 $(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/product/sdk_base.mk)
 
+# AOSP emulator images build the AOSP messaging app.
+# Google API images override with the Google API app.
+# See vendor/google/products/sdk_google_phone_*.mk
 PRODUCT_PACKAGES += \
     messaging
 
diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py
index bea33a3..73f7e33 100755
--- a/tools/releasetools/ota_from_target_files.py
+++ b/tools/releasetools/ota_from_target_files.py
@@ -63,6 +63,13 @@
       the build scripts (used for developer OTA packages which
       legitimately need to go back and forth).
 
+  --downgrade
+      Intentionally generate an incremental OTA that updates from a newer
+      build to an older one (based on timestamp comparison). "post-timestamp"
+      will be replaced by "ota-downgrade=yes" in the metadata file. A data
+      wipe will always be enforced, so "ota-wipe=yes" will also be included in
+      the metadata file.
+
   -e  (--extra_script)  <file>
       Insert the contents of file at the end of the update script.
 
@@ -126,6 +133,7 @@
 OPTIONS.patch_threshold = 0.95
 OPTIONS.wipe_user_data = False
 OPTIONS.omit_prereq = False
+OPTIONS.downgrade = False
 OPTIONS.extra_script = None
 OPTIONS.aslr_mode = True
 OPTIONS.worker_threads = multiprocessing.cpu_count() // 2
@@ -698,8 +706,9 @@
 endif;
 endif;
 """ % bcb_dev)
-  script.AddToZip(input_zip, output_zip, input_path=OPTIONS.updater_binary)
 
+  script.SetProgress(1)
+  script.AddToZip(input_zip, output_zip, input_path=OPTIONS.updater_binary)
   metadata["ota-required-cache"] = str(script.required_cache)
   WriteMetadata(metadata, output_zip)
 
@@ -775,11 +784,30 @@
   metadata = {
       "pre-device": GetOemProperty("ro.product.device", oem_props, oem_dict,
                                    OPTIONS.source_info_dict),
-      "post-timestamp": GetBuildProp("ro.build.date.utc",
-                                     OPTIONS.target_info_dict),
       "ota-type": "BLOCK",
   }
 
+  post_timestamp = GetBuildProp("ro.build.date.utc", OPTIONS.target_info_dict)
+  pre_timestamp = GetBuildProp("ro.build.date.utc", OPTIONS.source_info_dict)
+  is_downgrade = long(post_timestamp) < long(pre_timestamp)
+
+  if OPTIONS.downgrade:
+    metadata["ota-downgrade"] = "yes"
+    if not is_downgrade:
+      raise RuntimeError("--downgrade specified but no downgrade detected: "
+                         "pre: %s, post: %s" % (pre_timestamp, post_timestamp))
+  else:
+    if is_downgrade:
+      # Non-fatal here to allow generating such a package which may require
+      # manual work to adjust the post-timestamp. A legit use case is that we
+      # cut a new build C (after having A and B), but want to enfore the
+      # update path of A -> C -> B. Specifying --downgrade may not help since
+      # that would enforce a data wipe for C -> B update.
+      print("\nWARNING: downgrade detected: pre: %s, post: %s.\n"
+            "The package may not be deployed properly. "
+            "Try --downgrade?\n" % (pre_timestamp, post_timestamp))
+    metadata["post-timestamp"] = post_timestamp
+
   device_specific = common.DeviceSpecificParams(
       source_zip=source_zip,
       source_version=source_version,
@@ -1009,6 +1037,7 @@
   if OPTIONS.wipe_user_data:
     script.Print("Erasing user data...")
     script.FormatPartition("/data")
+    metadata["ota-wipe"] = "yes"
 
   if OPTIONS.two_step:
     script.AppendExtra("""
@@ -1392,11 +1421,30 @@
   metadata = {
       "pre-device": GetOemProperty("ro.product.device", oem_props, oem_dict,
                                    OPTIONS.source_info_dict),
-      "post-timestamp": GetBuildProp("ro.build.date.utc",
-                                     OPTIONS.target_info_dict),
       "ota-type": "FILE",
   }
 
+  post_timestamp = GetBuildProp("ro.build.date.utc", OPTIONS.target_info_dict)
+  pre_timestamp = GetBuildProp("ro.build.date.utc", OPTIONS.source_info_dict)
+  is_downgrade = long(post_timestamp) < long(pre_timestamp)
+
+  if OPTIONS.downgrade:
+    metadata["ota-downgrade"] = "yes"
+    if not is_downgrade:
+      raise RuntimeError("--downgrade specified but no downgrade detected: "
+                         "pre: %s, post: %s" % (pre_timestamp, post_timestamp))
+  else:
+    if is_downgrade:
+      # Non-fatal here to allow generating such a package which may require
+      # manual work to adjust the post-timestamp. A legit use case is that we
+      # cut a new build C (after having A and B), but want to enfore the
+      # update path of A -> C -> B. Specifying --downgrade may not help since
+      # that would enforce a data wipe for C -> B update.
+      print("\nWARNING: downgrade detected: pre: %s, post: %s.\n"
+            "The package may not be deployed properly. "
+            "Try --downgrade?\n" % (pre_timestamp, post_timestamp))
+    metadata["post-timestamp"] = post_timestamp
+
   device_specific = common.DeviceSpecificParams(
       source_zip=source_zip,
       source_version=source_version,
@@ -1725,6 +1773,7 @@
   if OPTIONS.wipe_user_data:
     script.Print("Erasing user data...")
     script.FormatPartition("/data")
+    metadata["ota-wipe"] = "yes"
 
   if OPTIONS.two_step:
     script.AppendExtra("""
@@ -1767,6 +1816,9 @@
       OPTIONS.wipe_user_data = True
     elif o in ("-n", "--no_prereq"):
       OPTIONS.omit_prereq = True
+    elif o == "--downgrade":
+      OPTIONS.downgrade = True
+      OPTIONS.wipe_user_data = True
     elif o in ("-o", "--oem_settings"):
       OPTIONS.oem_source = a
     elif o in ("-e", "--extra_script"):
@@ -1818,6 +1870,7 @@
                                  "full_bootloader",
                                  "wipe_user_data",
                                  "no_prereq",
+                                 "downgrade",
                                  "extra_script=",
                                  "worker_threads=",
                                  "aslr_mode=",
@@ -1837,6 +1890,18 @@
     common.Usage(__doc__)
     sys.exit(1)
 
+  if OPTIONS.downgrade:
+    # Sanity check to enforce a data wipe.
+    if not OPTIONS.wipe_user_data:
+      raise ValueError("Cannot downgrade without a data wipe")
+
+    # We should only allow downgrading incrementals (as opposed to full).
+    # Otherwise the device may go back from arbitrary build with this full
+    # OTA package.
+    if OPTIONS.incremental_source is None:
+      raise ValueError("Cannot generate downgradable full OTAs - consider"
+                       "using --omit_prereq?")
+
   # Load the dict file from the zip directly to have a peek at the OTA type.
   # For packages using A/B update, unzipping is not needed.
   input_zip = zipfile.ZipFile(args[0], "r")