Merge "Remove services, wifi, ethernet from BOOTCLASSPATH." into lmp-dev
diff --git a/core/Makefile b/core/Makefile
index 91fbce7..7b3dfe4 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -940,7 +940,11 @@
       skip_fsck=true)
   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
       ./build/tools/releasetools/build_image.py \
-      $(TARGET_OUT) $(systemimage_intermediates)/system_image_info.txt $(1)
+      $(TARGET_OUT) $(systemimage_intermediates)/system_image_info.txt $(1) \
+      || ( echo "Out of space? the tree size of $(TARGET_OUT) is (MB): " 1>&2 ;\
+           du -sm $(TARGET_OUT) 1>&2;\
+           echo "The max is $$(( $(BOARD_SYSTEMIMAGE_PARTITION_SIZE) / 1048576 )) MB." 1>&2 ;\
+           exit 1 )
 endef
 
 $(BUILT_SYSTEMIMAGE): $(FULL_SYSTEMIMAGE_DEPS) $(INSTALLED_FILES_FILE)
@@ -1682,6 +1686,7 @@
 	  fi; \
 	done; \
 	if [ $$FAIL ]; then exit 1; fi
+	$(hide) echo $(notdir $(SDK_FONT_DEPS)) | tr " " "\n"  > $(SDK_FONT_TEMP)/fontsInSdk.txt
 	$(hide) ( \
 		ATREE_STRIP="strip -x" \
 		$(HOST_OUT_EXECUTABLES)/atree \
diff --git a/core/binary.mk b/core/binary.mk
index 6ba6bec..5da0c72 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -187,7 +187,7 @@
 ####################################################
 ## Add FDO flags if FDO is turned on and supported
 ####################################################
-ifneq ($(strip $(LOCAL_FDO_SUPPORT)),)
+ifeq ($(strip $(LOCAL_FDO_SUPPORT)), true)
   ifeq ($(strip $(LOCAL_IS_HOST_MODULE)),)
     my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_CFLAGS)
     my_ldflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_CFLAGS)
diff --git a/core/definitions.mk b/core/definitions.mk
index a6c473e..13959aa 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -884,7 +884,7 @@
 	-Wl,-rpath,\$$ORIGIN/../lib \
 	$(dir $@)/$(notdir $(<:.bc=.o)) \
 	$(RS_PREBUILT_COMPILER_RT) \
-	-o $@ -L prebuilts/gcc/ \
+	-o $@ $(TARGET_GLOBAL_LDFLAGS) -L prebuilts/gcc/ \
 	-L $(TARGET_OUT_INTERMEDIATE_LIBRARIES) $(RS_PREBUILT_LIBPATH) \
 	-lRSSupport -lm -lc
 endef
diff --git a/core/dex_preopt_odex_install.mk b/core/dex_preopt_odex_install.mk
index 613b058..10b41bd 100644
--- a/core/dex_preopt_odex_install.mk
+++ b/core/dex_preopt_odex_install.mk
@@ -32,6 +32,12 @@
 ifneq (,$(filter $(LOCAL_MODULE),$(PRODUCT_DEX_PREOPT_PACKAGES_IN_DATA)))
 LOCAL_DEX_PREOPT :=
 endif
+# if WITH_DEXPREOPT_BOOT_IMG_ONLY=true and module is not in boot class path skip
+ifeq (true,$(WITH_DEXPREOPT_BOOT_IMG_ONLY))
+ifeq ($(filter $(DEXPREOPT_BOOT_JARS_MODULES),$(LOCAL_MODULE)),)
+LOCAL_DEX_PREOPT :=
+endif
+endif
 
 built_odex :=
 installed_odex :=
diff --git a/core/dynamic_binary.mk b/core/dynamic_binary.mk
index 396199c..3d6ad4a 100644
--- a/core/dynamic_binary.mk
+++ b/core/dynamic_binary.mk
@@ -110,6 +110,15 @@
 $(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF)
 $(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
 	$(transform-to-stripped-keep-symbols)
+
+# A product may be configured to strip everything in some build variants.
+# We do the stripping as a post-install command so that LOCAL_BUILT_MODULE
+# is still with the symbols and we don't need to clean it (and relink) when
+# you switch build variant.
+ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),)
+$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \
+  $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE)
+endif
 else
 # Don't strip the binary, just copy it.  We can't skip this step
 # because a copy of the binary must appear at LOCAL_BUILT_MODULE.
diff --git a/core/envsetup.mk b/core/envsetup.mk
index 96044b3..124a91b 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -260,7 +260,11 @@
 
 # The default host library path.
 # It always points to the path where we build libraries in the default bitness.
-HOST_LIBRARY_PATH := $(HOST_OUT)/lib
+ifeq ($(HOST_PREFER_32_BIT),true)
+HOST_LIBRARY_PATH := $($(HOST_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES)
+else
+HOST_LIBRARY_PATH := $(HOST_OUT_SHARED_LIBRARIES)
+endif
 
 TARGET_OUT_INTERMEDIATES := $(PRODUCT_OUT)/obj
 TARGET_OUT_HEADERS := $(TARGET_OUT_INTERMEDIATES)/include
diff --git a/core/executable_prefer_symlink.mk b/core/executable_prefer_symlink.mk
index e4df92e..2326e83 100644
--- a/core/executable_prefer_symlink.mk
+++ b/core/executable_prefer_symlink.mk
@@ -15,7 +15,7 @@
       # We support both 32 and 64 bit apps, so we will have to
       # base our decision on whether the target prefers one or the
       # other.
-      ifneq ($(TARGET_PREFER_32_BIT_APPS),true)
+      ifeq ($(TARGET_PREFER_32_BIT_APPS),true)
         $(my_symlink): PRIVATE_SRC_BINARY_NAME := $(LOCAL_MODULE_STEM_32)
       else
         $(my_symlink): PRIVATE_SRC_BINARY_NAME := $(LOCAL_MODULE_STEM_64)
diff --git a/core/product.mk b/core/product.mk
index 91aa2b5..90d5851 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -264,7 +264,8 @@
 
 _product_stash_var_list += \
 	DEFAULT_SYSTEM_DEV_CERTIFICATE \
-	WITH_DEXPREOPT
+	WITH_DEXPREOPT \
+	WITH_DEXPREOPT_BOOT_IMG_ONLY
 
 #
 # Stash values of the variables in _product_stash_var_list.
diff --git a/core/sdk_font.mk b/core/sdk_font.mk
index aa6b94d..59aed8b 100644
--- a/core/sdk_font.mk
+++ b/core/sdk_font.mk
@@ -41,21 +41,26 @@
 	$(hide) mkdir -p $(dir $@)
 	$(hide) $(call sdk_rename_font,$<,$@)
 
-# Extra fonts that are not part of the device build. These are used as a
-# replacement for the OpenType fonts.
-sdk_fonts_extra := NanumGothic.ttf DroidSansFallback.ttf
-sdk_fonts_extra := $(addprefix $(SDK_FONT_TEMP)/, $(sdk_fonts_extra))
-
-$(SDK_FONT_TEMP)/NanumGothic.ttf: external/naver-fonts/NanumGothic.ttf \
-			$(sdk_font_rename_script)
-	$(hide) mkdir -p $(dir $@)
-	$(hide) $(call sdk_rename_font,$<,$@)
-
-$(SDK_FONT_TEMP)/DroidSansFallback.ttf: frameworks/base/data/fonts/DroidSansFallbackFull.ttf \
-			$(sdk_font_rename_script)
-	$(hide) mkdir -p $(dir $@)
-	$(hide) $(call sdk_rename_font,$<,$@)
-
 # List of all dependencies - all fonts and configuration files.
-SDK_FONT_DEPS := $(sdk_fonts_device) $(sdk_fonts_extra) $(sdk_font_config)
+SDK_FONT_DEPS := $(sdk_fonts_device) $(sdk_font_config)
 
+# Define a macro to create rule for addititional fonts that we want to include
+# in the SDK.
+# $1 Output font name
+# $2 Source font path
+define sdk-extra-font-rule
+fontfullname := $$(SDK_FONT_TEMP)/$1
+ifeq ($$(filter $(fontfullname),$$(sdk_fonts_device)),)
+SDK_FONT_DEPS += $$(fontfullname)
+$$(fontfullname): $2 $(sdk_font_rename_script)
+	$$(hide) mkdir -p $$(dir $$@)
+	$$(hide) $$(call sdk_rename_font,$$<,$$@)
+endif
+fontfullname :=
+endef
+
+# These extra fonts are used as a replacement for OpenType fonts.
+$(eval $(call sdk-extra-font-rule,NanumGothic.ttf,external/naver-fonts/NanumGothic.ttf))
+$(eval $(call sdk-extra-font-rule,DroidSansFallback.ttf,frameworks/base/data/fonts/DroidSansFallbackFull.ttf))
+
+sdk-extra-font-rule :=
diff --git a/core/tasks/vendor_module_check.mk b/core/tasks/vendor_module_check.mk
index fc9e867..d8e8ec7 100644
--- a/core/tasks/vendor_module_check.mk
+++ b/core/tasks/vendor_module_check.mk
@@ -18,6 +18,7 @@
 _vendor_owner_whitelist := \
         asus \
         audience \
+        atmel \
         broadcom \
         csr \
         elan \
diff --git a/envsetup.sh b/envsetup.sh
index ca282b6..42ac007 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -14,6 +14,7 @@
 - ggrep:   Greps on all local Gradle files.
 - jgrep:   Greps on all local Java files.
 - resgrep: Greps on all local res/*.xml files.
+- sgrep:   Greps on all local source files.
 - godir:   Go to the directory containing a file.
 
 Look at the source to view more functions. The complete list is:
@@ -21,7 +22,7 @@
     T=$(gettop)
     local A
     A=""
-    for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
+    for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
       A="$A $i"
     done
     echo $A
@@ -1088,14 +1089,14 @@
     Darwin)
         function sgrep()
         {
-            find -E . -name .repo -prune -o -name .git -prune -o  -type f -iregex '.*\.(c|h|cpp|S|java|xml|sh|mk)' -print0 | xargs -0 grep --color -n "$@"
+            find -E . -name .repo -prune -o -name .git -prune -o  -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl)' -print0 | xargs -0 grep --color -n "$@"
         }
 
         ;;
     *)
         function sgrep()
         {
-            find . -name .repo -prune -o -name .git -prune -o  -type f -iregex '.*\.\(c\|h\|cpp\|S\|java\|xml\|sh\|mk\)' -print0 | xargs -0 grep --color -n "$@"
+            find . -name .repo -prune -o -name .git -prune -o  -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\)' -print0 | xargs -0 grep --color -n "$@"
         }
         ;;
 esac
diff --git a/target/product/core_minimal.mk b/target/product/core_minimal.mk
index c03ade4..e4eb56a 100644
--- a/target/product/core_minimal.mk
+++ b/target/product/core_minimal.mk
@@ -36,6 +36,8 @@
     com.android.location.provider.xml \
     com.android.media.remotedisplay \
     com.android.media.remotedisplay.xml \
+    com.android.mediadrm.signer \
+    com.android.mediadrm.signer.xml \
     drmserver \
     ethernet-service \
     framework-res \
diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py
index 7be1929..568a3f1 100755
--- a/tools/releasetools/add_img_to_target_files.py
+++ b/tools/releasetools/add_img_to_target_files.py
@@ -49,23 +49,38 @@
 def AddSystem(output_zip, sparse=True, prefix="IMAGES/"):
   """Turn the contents of SYSTEM into a system image and store it in
   output_zip."""
-  data = BuildSystem(OPTIONS.input_tmp, OPTIONS.info_dict, sparse=sparse)
+  block_list = tempfile.NamedTemporaryFile()
+  data = BuildSystem(OPTIONS.input_tmp, OPTIONS.info_dict, sparse=sparse,
+                     block_list=block_list.name)
   common.ZipWriteStr(output_zip, prefix + "system.img", data)
+  with open(block_list.name, "rb") as f:
+    block_list_data = f.read()
+  common.ZipWriteStr(output_zip, prefix + "system.map", block_list_data)
+  block_list.close()
 
-def BuildSystem(input_dir, info_dict, sparse=True, map_file=None):
+def BuildSystem(input_dir, info_dict, sparse=True, map_file=None,
+                block_list=None):
   return CreateImage(input_dir, info_dict, "system",
-                     sparse=sparse, map_file=map_file)
+                     sparse=sparse, map_file=map_file, block_list=block_list)
 
 def AddVendor(output_zip, sparse=True, prefix="IMAGES/"):
-  data = BuildVendor(OPTIONS.input_tmp, OPTIONS.info_dict, sparse=sparse)
+  block_list = tempfile.NamedTemporaryFile()
+  data = BuildVendor(OPTIONS.input_tmp, OPTIONS.info_dict, sparse=sparse,
+                     block_list=block_list.name)
   common.ZipWriteStr(output_zip, prefix + "vendor.img", data)
+  with open(block_list.name, "rb") as f:
+    block_list_data = f.read()
+  common.ZipWriteStr(output_zip, prefix + "vendor.map", block_list_data)
+  block_list.close()
 
-def BuildVendor(input_dir, info_dict, sparse=True, map_file=None):
+def BuildVendor(input_dir, info_dict, sparse=True, map_file=None,
+                block_list=None):
   return CreateImage(input_dir, info_dict, "vendor",
-                     sparse=sparse, map_file=map_file)
+                     sparse=sparse, map_file=map_file, block_list=block_list)
 
 
-def CreateImage(input_dir, info_dict, what, sparse=True, map_file=None):
+def CreateImage(input_dir, info_dict, what, sparse=True, map_file=None,
+                block_list=None):
   print "creating " + what + ".img..."
 
   img = tempfile.NamedTemporaryFile()
@@ -104,7 +119,8 @@
   succ = build_image.BuildImage(os.path.join(input_dir, what),
                                 image_props, img.name,
                                 fs_config=fs_config,
-                                fc_config=fc_config)
+                                fc_config=fc_config,
+                                block_list=block_list)
   assert succ, "build " + what + ".img image failed"
 
   mapdata = None
diff --git a/tools/releasetools/build_image.py b/tools/releasetools/build_image.py
index 712e0cd..5ae8d3c 100755
--- a/tools/releasetools/build_image.py
+++ b/tools/releasetools/build_image.py
@@ -209,7 +209,8 @@
 
 def BuildImage(in_dir, prop_dict, out_file,
                fs_config=None,
-               fc_config=None):
+               fc_config=None,
+               block_list=None):
   """Build an image to out_file from in_dir with property prop_dict.
 
   Args:
@@ -252,6 +253,8 @@
       build_command.extend(["-T", str(prop_dict["timestamp"])])
     if fs_config is not None:
       build_command.extend(["-C", fs_config])
+    if block_list is not None:
+      build_command.extend(["-B", block_list])
     if fc_config is not None:
       build_command.append(fc_config)
     elif "selinux_fc" in prop_dict:
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 50ef451..947a9e4 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -303,6 +303,11 @@
 
   cmd = [mkbootimg, "--kernel", os.path.join(sourcedir, "kernel")]
 
+  fn = os.path.join(sourcedir, "second")
+  if os.access(fn, os.F_OK):
+    cmd.append("--second")
+    cmd.append(fn)
+
   fn = os.path.join(sourcedir, "cmdline")
   if os.access(fn, os.F_OK):
     cmd.append("--cmdline")
diff --git a/tools/releasetools/img_from_target_files.py b/tools/releasetools/img_from_target_files.py
index 6463047..4b88e73 100755
--- a/tools/releasetools/img_from_target_files.py
+++ b/tools/releasetools/img_from_target_files.py
@@ -90,6 +90,7 @@
       if images:
         for i in images:
           if bootable_only and i not in ("boot.img", "recovery.img"): continue
+          if not i.endswith(".img"): continue
           with open(os.path.join(images_path, i), "r") as f:
             common.ZipWriteStr(output_zip, i, f.read())
         done = True