Merge "Add tool to package up built modules."
diff --git a/core/binary.mk b/core/binary.mk
index f0b3162..d5709ca 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -452,6 +452,9 @@
 proto_generated_objects := $(addprefix $(proto_generated_obj_dir)/, \
     $(patsubst %.proto,%.pb.o,$(proto_sources_fullpath)))
 
+# Auto-export the generated proto source dir.
+LOCAL_EXPORT_C_INCLUDE_DIRS += $(proto_generated_cc_sources_dir)
+
 # Ensure the transform-proto-to-cc rule is only defined once in multilib build.
 ifndef $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined
 $(proto_generated_cc_sources): PRIVATE_PROTO_INCLUDES := $(TOP)
@@ -918,7 +921,8 @@
 ###########################################################
 export_includes := $(intermediates)/export_includes
 $(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(LOCAL_EXPORT_C_INCLUDE_DIRS)
-$(export_includes) : $(LOCAL_MODULE_MAKEFILE)
+# Make sure .pb.h are already generated before any dependent source files get compiled.
+$(export_includes) : $(LOCAL_MODULE_MAKEFILE) $(proto_generated_headers)
 	@echo Export includes file: $< -- $@
 	$(hide) mkdir -p $(dir $@) && rm -f $@
 ifdef LOCAL_EXPORT_C_INCLUDE_DIRS
diff --git a/core/combo/arch/x86/silvermont.mk b/core/combo/arch/x86/silvermont.mk
new file mode 100644
index 0000000..3a8718d
--- /dev/null
+++ b/core/combo/arch/x86/silvermont.mk
@@ -0,0 +1,20 @@
+# This file contains feature macro definitions specific to the
+# silvermont arch variant.
+#
+# See build/core/combo/arch/x86/x86-atom.mk for differences.
+#
+
+ARCH_X86_HAVE_SSSE3  := true
+ARCH_X86_HAVE_SSE4   := true
+ARCH_X86_HAVE_SSE4_1 := true
+ARCH_X86_HAVE_SSE4_2 := true
+ARCH_X86_HAVE_AES_NI := true
+ARCH_X86_HAVE_POPCNT := true
+ARCH_X86_HAVE_MOVBE  := true
+
+# CFLAGS for this arch
+arch_variant_cflags := \
+	-march=slm \
+	-mstackrealign \
+	-mfpmath=sse \
+
diff --git a/core/combo/arch/x86_64/silvermont.mk b/core/combo/arch/x86_64/silvermont.mk
new file mode 100644
index 0000000..6c953a3
--- /dev/null
+++ b/core/combo/arch/x86_64/silvermont.mk
@@ -0,0 +1,17 @@
+# This file contains feature macro definitions specific to the
+# silvermont arch variant.
+#
+# See build/core/combo/arch/x86/x86-atom.mk for differences.
+#
+
+ARCH_X86_HAVE_SSSE3  := true
+ARCH_X86_HAVE_SSE4   := true
+ARCH_X86_HAVE_SSE4_1 := true
+ARCH_X86_HAVE_SSE4_2 := true
+ARCH_X86_HAVE_AES_NI := true
+ARCH_X86_HAVE_POPCNT := true
+ARCH_X86_HAVE_MOVBE  := true
+
+# CFLAGS for this arch
+arch_variant_cflags := \
+	-march=slm \
diff --git a/core/config.mk b/core/config.mk
index f79082e..61f1d79 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -230,12 +230,13 @@
 include $(BUILD_SYSTEM)/combo/select.mk
 endif
 
-# "ro.product.cpu.abilist" is a comma separated list of ABIs (in order
-# of preference) that the target supports. If a TARGET_CPU_ABI_LIST
-# is specified by the board configuration, we use that. If not, we
-# build a list out of the TARGET_CPU_ABIs specified by the config.
-ifeq (,$(TARGET_CPU_ABI_LIST))
-  TARGET_CPU_ABI_LIST := $(TARGET_CPU_ABI) $(TARGET_CPU_ABI2) $(TARGET_2ND_CPU_ABI) $(TARGET_2ND_CPU_ABI2)
+ifdef TARGET_PREFER_32_BIT
+TARGET_PREFER_32_BIT_APPS := true
+TARGET_PREFER_32_BIT_EXECUTABLES := true
+endif
+
+ifeq (,$(TARGET_SUPPORTS_32_BIT_APPS)$(TARGET_SUPPORTS_64_BIT_APPS))
+  TARGET_SUPPORTS_32_BIT_APPS := true
 endif
 
 # "ro.product.cpu.abilist32" and "ro.product.cpu.abilist64" are
@@ -248,7 +249,7 @@
 # is always 32 bits. If this isn't the case, these variables should
 # be overriden in the boarc configuration.
 ifeq (,$(TARGET_CPU_ABI_LIST_64_BIT))
-  ifeq (true,$(TARGET_IS_64_BIT))
+  ifeq (true|true,$(TARGET_IS_64_BIT)|$(TARGET_SUPPORTS_64_BIT_APPS))
     TARGET_CPU_ABI_LIST_64_BIT := $(TARGET_CPU_ABI) $(TARGET_CPU_ABI2)
   endif
 endif
@@ -257,9 +258,23 @@
   ifneq (true,$(TARGET_IS_64_BIT))
     TARGET_CPU_ABI_LIST_32_BIT := $(TARGET_CPU_ABI) $(TARGET_CPU_ABI2)
   else
-    # For a 64 bit target, assume that the 2ND_CPU_ABI
-    # is a 32 bit ABI.
-    TARGET_CPU_ABI_LIST_32_BIT := $(TARGET_2ND_CPU_ABI) $(TARGET_2ND_CPU_ABI2)
+    ifeq (true,$(TARGET_SUPPORTS_32_BIT_APPS))
+      # For a 64 bit target, assume that the 2ND_CPU_ABI
+      # is a 32 bit ABI.
+      TARGET_CPU_ABI_LIST_32_BIT := $(TARGET_2ND_CPU_ABI) $(TARGET_2ND_CPU_ABI2)
+    endif
+  endif
+endif
+
+# "ro.product.cpu.abilist" is a comma separated list of ABIs (in order
+# of preference) that the target supports. If a TARGET_CPU_ABI_LIST
+# is specified by the board configuration, we use that. If not, we
+# build a list out of the TARGET_CPU_ABIs specified by the config.
+ifeq (,$(TARGET_CPU_ABI_LIST))
+  ifeq ($(TARGET_IS_64_BIT)|$(TARGET_PREFER_32_BIT_APPS),true|true)
+    TARGET_CPU_ABI_LIST := $(TARGET_CPU_ABI_LIST_32_BIT) $(TARGET_CPU_ABI_LIST_64_BIT)
+  else
+    TARGET_CPU_ABI_LIST := $(TARGET_CPU_ABI_LIST_64_BIT) $(TARGET_CPU_ABI_LIST_32_BIT)
   endif
 endif
 
@@ -335,7 +350,7 @@
 # ---------------------------------------------------------------
 # Generic tools.
 
-LEX := flex
+LEX := prebuilts/misc/$(BUILD_OS)-$(BUILD_ARCH)/flex/flex-2.5.39
 # The default PKGDATADIR built in the prebuilt bison is a relative path
 # external/bison/data.
 # To run bison from elsewhere you need to set up enviromental variable
@@ -400,8 +415,6 @@
 COLUMN:= column
 endif
 
-OLD_FLEX := prebuilts/misc/$(HOST_PREBUILT_TAG)/flex/flex-2.5.4a$(HOST_EXECUTABLE_SUFFIX)
-
 ifeq ($(HOST_OS),darwin)
 ifeq ($(LEGACY_USE_JAVA6),)
 HOST_JDK_TOOLS_JAR:= $(shell $(BUILD_SYSTEM)/find-jdk-tools-jar.sh)
diff --git a/core/executable.mk b/core/executable.mk
index b67ac36..7a3e08e 100644
--- a/core/executable.mk
+++ b/core/executable.mk
@@ -19,9 +19,9 @@
 LOCAL_NO_2ND_ARCH_MODULE_SUFFIX := true
 endif
 
-# if TARGET_PREFER_32_BIT is set, try to build 32-bit first
+# if TARGET_PREFER_32_BIT_EXECUTABLES is set, try to build 32-bit first
 ifdef TARGET_2ND_ARCH
-ifeq ($(TARGET_PREFER_32_BIT),true)
+ifeq ($(TARGET_PREFER_32_BIT_EXECUTABLES),true)
 LOCAL_2ND_ARCH_VAR_PREFIX := $(TARGET_2ND_ARCH_VAR_PREFIX)
 else
 LOCAL_2ND_ARCH_VAR_PREFIX :=
@@ -45,7 +45,7 @@
 ifdef TARGET_2ND_ARCH
 
 # check if the non-preferred arch is the primary or secondary
-ifeq ($(TARGET_PREFER_32_BIT),true)
+ifeq ($(TARGET_PREFER_32_BIT_EXECUTABLES),true)
 LOCAL_2ND_ARCH_VAR_PREFIX :=
 else
 LOCAL_2ND_ARCH_VAR_PREFIX := $(TARGET_2ND_ARCH_VAR_PREFIX)
diff --git a/core/package.mk b/core/package.mk
index fe4d0e4..c7d68d9 100644
--- a/core/package.mk
+++ b/core/package.mk
@@ -40,9 +40,9 @@
 
 LOCAL_NO_2ND_ARCH_MODULE_SUFFIX := true
 
-# if TARGET_PREFER_32_BIT is set, try to build 32-bit first
+# if TARGET_PREFER_32_BIT_APPS is set, try to build 32-bit first
 ifdef TARGET_2ND_ARCH
-ifeq ($(TARGET_PREFER_32_BIT),true)
+ifeq ($(TARGET_PREFER_32_BIT_APPS),true)
 LOCAL_2ND_ARCH_VAR_PREFIX := $(TARGET_2ND_ARCH_VAR_PREFIX)
 else
 LOCAL_2ND_ARCH_VAR_PREFIX :=
@@ -56,7 +56,7 @@
 include $(BUILD_SYSTEM)/package_internal.mk
 else ifneq (,$(TARGET_2ND_ARCH))
 # check if the non-preferred arch is the primary or secondary
-ifeq ($(TARGET_PREFER_32_BIT),true)
+ifeq ($(TARGET_PREFER_32_BIT_APPS),true)
 LOCAL_2ND_ARCH_VAR_PREFIX :=
 else
 LOCAL_2ND_ARCH_VAR_PREFIX := $(TARGET_2ND_ARCH_VAR_PREFIX)
diff --git a/core/pathmap.mk b/core/pathmap.mk
index ce6befb..aaeb905 100644
--- a/core/pathmap.mk
+++ b/core/pathmap.mk
@@ -49,6 +49,7 @@
     audio-route:system/media/audio_route/include \
     wilhelm:frameworks/wilhelm/include \
     wilhelm-ut:frameworks/wilhelm/src/ut \
+    mediandk:frameworks/av/media/ndk/ \
     speex:external/speex/include
 
 #
diff --git a/envsetup.sh b/envsetup.sh
index 6891747..e5bd72e 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -189,6 +189,24 @@
     unset ANDROID_HOST_OUT
     export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
 
+    # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
+    # to ensure that the corresponding 'emulator' binaries are used.
+    case $(uname -s) in
+        Darwin)
+            ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
+            ;;
+        Linux)
+            ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
+            ;;
+        *)
+            ANDROID_EMULATOR_PREBUILTS=
+            ;;
+    esac
+    if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
+        PATH=$ANDROID_EMULATOR_PREBUILTS:$PATH
+        export ANDROID_EMULATOR_PREBUILTS
+    fi
+
     # needed for building linux on MacOS
     # TODO: fix the path
     #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
diff --git a/target/board/generic_x86_64/BoardConfig.mk b/target/board/generic_x86_64/BoardConfig.mk
index 2ed83bb..d0994b0 100755
--- a/target/board/generic_x86_64/BoardConfig.mk
+++ b/target/board/generic_x86_64/BoardConfig.mk
@@ -41,7 +41,7 @@
 USE_OPENGL_RENDERER := true
 
 TARGET_USERIMAGES_USE_EXT4 := true
-BOARD_SYSTEMIMAGE_PARTITION_SIZE := 576716800
+BOARD_SYSTEMIMAGE_PARTITION_SIZE := 786432000
 BOARD_USERDATAIMAGE_PARTITION_SIZE := 209715200
 BOARD_CACHEIMAGE_PARTITION_SIZE := 69206016
 BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
diff --git a/target/product/aosp_arm64.mk b/target/product/aosp_arm64.mk
index 8ff0bd1..e119466 100644
--- a/target/product/aosp_arm64.mk
+++ b/target/product/aosp_arm64.mk
@@ -19,6 +19,7 @@
 # build quite specifically for the emulator, and might not be
 # entirely appropriate to inherit from for on-device configurations.
 
+$(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_base_telephony.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/board/generic_arm64/device.mk)
 
diff --git a/target/product/base.mk b/target/product/base.mk
index 45dd9a7..6dd77a4 100644
--- a/target/product/base.mk
+++ b/target/product/base.mk
@@ -80,6 +80,7 @@
     libutils \
     libvisualizer \
     libvorbisidec \
+    libmediandk \
     libwifi-service \
     media \
     media_cmd \
diff --git a/target/product/core_64_bit.mk b/target/product/core_64_bit.mk
new file mode 100644
index 0000000..5d7abcb
--- /dev/null
+++ b/target/product/core_64_bit.mk
@@ -0,0 +1,39 @@
+#
+# Copyright (C) 2014 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.
+#
+
+# Inherit from this product for devices that support 64-bit apps using:
+# $(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)
+# The inheritance for this must come before the inheritance chain that leads
+# to core_minimal.mk
+
+# For now this will allow 64-bit apps, but still compile all apps with JNI
+# for 32-bit only.
+
+# Copy the 32-bit primary, 64-bit secondary zygote startup script
+PRODUCT_COPY_FILES += system/core/rootdir/init.zygote32_64.rc:root/init.zygote32_64.rc
+
+# Set the zygote property to select the 32-bit primary, 64-bit secondary script
+# This line must be parsed before the one in core_minimal.mk
+PRODUCT_DEFAULT_PROPERTY_OVERRIDES += ro.zygote=zygote32_64
+
+# Temporary hack to prefer launching processes as 32 bit
+# instead of 64 bit.
+#
+# STOPSHIP: Revert this to allow products to select it themselves
+TARGET_PREFER_32_BIT_APPS := true
+
+TARGET_SUPPORTS_32_BIT_APPS := true
+TARGET_SUPPORTS_64_BIT_APPS := true
diff --git a/target/product/core_tiny.mk b/target/product/core_tiny.mk
index 41508d9..9c40206 100644
--- a/target/product/core_tiny.mk
+++ b/target/product/core_tiny.mk
@@ -18,6 +18,7 @@
 
 PRODUCT_PACKAGES := \
     Bluetooth \
+    ContactsProvider \
     CertInstaller \
     FusedLocation \
     InputDevices
diff --git a/target/product/full_mips64.mk b/target/product/full_mips64.mk
index 3f171e0..408e81c 100644
--- a/target/product/full_mips64.mk
+++ b/target/product/full_mips64.mk
@@ -19,6 +19,7 @@
 # mips64 build quite specifically for the emulator, and might not be
 # entirely appropriate to inherit from for on-device configurations.
 
+$(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_base_telephony.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/board/generic_mips64/device.mk)
 
diff --git a/target/product/full_x86_64.mk b/target/product/full_x86_64.mk
index ce5dcf7..d9c0c1e 100755
--- a/target/product/full_x86_64.mk
+++ b/target/product/full_x86_64.mk
@@ -23,9 +23,7 @@
 # that isn't a wifi connection. This will instruct init.rc to enable the
 # network connection so that you can use it with ADB
 
-# Override and force 64-bit Zygote. Must come first.
-PRODUCT_DEFAULT_PROPERTY_OVERRIDES += ro.zygote=zygote64
-
+$(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_base_telephony.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/board/generic_x86_64/device.mk)
 
diff --git a/tools/releasetools/ota_from_target_files b/tools/releasetools/ota_from_target_files
index d3701e7..cbfc087 100755
--- a/tools/releasetools/ota_from_target_files
+++ b/tools/releasetools/ota_from_target_files
@@ -366,7 +366,7 @@
                   whole_file=True)
 
 
-def AppendAssertions(script, info_dict, oem_dict):
+def AppendAssertions(script, info_dict, oem_dict = None):
   oem_props = info_dict.get("oem_fingerprint_properties")
   if oem_props is None:
     device = GetBuildProp("ro.product.device", info_dict)
@@ -683,7 +683,15 @@
       tgt_mapfilename = system_patch.name + ".tgt.map"
       common.ZipWriteStr(output_zip, tgt_mapfilename, tgt_mapdata)
 
-  AppendAssertions(script, OPTIONS.target_info_dict)
+  oem_props = OPTIONS.target_info_dict.get("oem_fingerprint_properties")
+  oem_dict = None
+  if oem_props is not None:
+    if OPTIONS.oem_source is None:
+      raise common.ExternalError("OEM source required for this build")
+    script.Mount("/oem")
+    oem_dict = common.LoadDictionaryFromLines(open(OPTIONS.oem_source).readlines())
+
+  AppendAssertions(script, OPTIONS.target_info_dict, oem_dict)
   device_specific.IncrementalOTA_Assertions()
 
   # Two-step incremental package strategy (in chronological order,
@@ -730,7 +738,12 @@
 
   device_specific.IncrementalOTA_VerifyBegin()
 
-  script.AssertRecoveryFingerprint(source_fp, target_fp)
+  if oem_props is None:
+    script.AssertSomeFingerprint(source_fp, target_fp)
+  else:
+    script.AssertSomeThumbprint(
+        GetBuildProp("ro.build.thumbprint", OPTIONS.target_info_dict),
+        GetBuildProp("ro.build.thumbprint", OPTIONS.source_info_dict))
 
   if updating_boot:
     d = common.Difference(target_boot, source_boot)