am 6d85b7c7: am 243d9ae2: am 4d67e916: am d09b2e55: Merge "WAPPushManager, WAP Push over SMS message handler"

* commit '6d85b7c774d224825f7ecd6e7819499daadc4c78':
  WAPPushManager, WAP Push over SMS message handler
diff --git a/core/Makefile b/core/Makefile
index b7e481a..f75f140 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -215,16 +215,9 @@
 intermediates := \
 	$(call intermediates-dir-for,PACKAGING,apkcerts)
 APKCERTS_FILE := $(intermediates)/$(name).txt
-# Depending on the built packages isn't exactly right,
-# but it should guarantee that the apkcerts file is rebuilt
-# if any packages change which certs they're signed with.
-all_built_packages := $(foreach p,$(PACKAGES),$(ALL_MODULES.$(p).BUILT))
-ifneq ($(TARGET_BUILD_APPS),)
-# We don't need to really build all the modules for apps_only build.
+# We don't need to really build all the modules.
+# TODO: rebuild APKCERTS_FILE if any app change its cert.
 $(APKCERTS_FILE):
-else
-$(APKCERTS_FILE): $(all_built_packages)
-endif
 	@echo APK certs list: $@
 	@mkdir -p $(dir $@)
 	@rm -f $@
@@ -238,7 +231,9 @@
 .PHONY: apkcerts-list
 apkcerts-list: $(APKCERTS_FILE)
 
-$(call dist-for-goals, apps_only, $(APKCERTS_FILE):apkcerts.txt)
+ifneq (,$(TARGET_BUILD_APPS))
+  $(call dist-for-goals, apps_only, $(APKCERTS_FILE):apkcerts.txt)
+endif
 
 # -----------------------------------------------------------------
 # module info file
@@ -597,7 +592,7 @@
 # $(5): size of the partition
 define build-userimage-ext-target
   @mkdir -p $(dir $(2))
-  $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$(PATH) \
+  $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
 	  $(MKEXTUSERIMG) $(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG) $(1) $(2) $(4) $(3) $(5)
 endef
 else
@@ -659,11 +654,12 @@
 	$(call intermediates-dir-for,PACKAGING,ota_keys)/keys
 DUMPKEY_JAR := $(HOST_OUT_JAVA_LIBRARIES)/dumpkey.jar
 $(RECOVERY_INSTALL_OTA_KEYS): PRIVATE_OTA_PUBLIC_KEYS := $(OTA_PUBLIC_KEYS)
-$(RECOVERY_INSTALL_OTA_KEYS): $(OTA_PUBLIC_KEYS) $(DUMPKEY_JAR)
-	@echo "DumpPublicKey: $@ <= $(PRIVATE_OTA_PUBLIC_KEYS)"
+$(RECOVERY_INSTALL_OTA_KEYS): extra_keys := $(patsubst %,%.x509.pem,$(TARGET_EXTRA_RECOVERY_KEYS))
+$(RECOVERY_INSTALL_OTA_KEYS): $(OTA_PUBLIC_KEYS) $(DUMPKEY_JAR) $(extra_keys)
+	@echo "DumpPublicKey: $@ <= $(PRIVATE_OTA_PUBLIC_KEYS) $(extra_keys)"
 	@rm -rf $@
 	@mkdir -p $(dir $@)
-	java -jar $(DUMPKEY_JAR) $(PRIVATE_OTA_PUBLIC_KEYS) > $@
+	java -jar $(DUMPKEY_JAR) $(PRIVATE_OTA_PUBLIC_KEYS) $(extra_keys) > $@
 
 $(INSTALLED_RECOVERYIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) \
 		$(INSTALLED_RAMDISK_TARGET) \
@@ -1072,6 +1068,9 @@
 ifdef INTERNAL_USERIMAGES_SPARSE_EXT_FLAG
 	$(hide) echo "extfs_sparse_flag=$(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG)" >> $(zip_root)/META/misc_info.txt
 endif
+ifdef TARGET_EXTRA_RECOVERY_KEYS
+	$(hide) echo "extra_recovery_keys=$(TARGET_EXTRA_RECOVERY_KEYS)" >> $(zip_root)/META/misc_info.txt
+endif
 	@# Zip everything up, preserving symlinks
 	$(hide) (cd $(zip_root) && zip -qry ../$(notdir $@) .)
 	@# Run fs_config on all the system files in the zip, and save the output
@@ -1084,7 +1083,7 @@
 
 ifneq ($(TARGET_SIMULATOR),true)
 ifneq ($(TARGET_PRODUCT),sdk)
-ifneq ($(TARGET_DEVICE),generic)
+ifeq ($(filter generic%,$(TARGET_DEVICE)),)
 ifneq ($(TARGET_NO_KERNEL),true)
 
 # -----------------------------------------------------------------
@@ -1139,7 +1138,7 @@
 updatepackage: $(INTERNAL_UPDATE_PACKAGE_TARGET)
 
 endif    # TARGET_NO_KERNEL != true
-endif    # TARGET_DEVICE != generic
+endif    # TARGET_DEVICE != generic*
 endif    # TARGET_PRODUCT != sdk
 endif    # TARGET_SIMULATOR != true
 
@@ -1156,8 +1155,8 @@
 
 .PHONY: installed-file-list
 installed-file-list: $(INSTALLED_FILES_FILE)
-ifneq ($(filter sdk,$(MAKECMDGOALS)),)
-$(call dist-for-goals, sdk, $(INSTALLED_FILES_FILE))
+ifneq ($(filter sdk win_sdk,$(MAKECMDGOALS)),)
+$(call dist-for-goals, sdk win_sdk, $(INSTALLED_FILES_FILE))
 endif
 ifneq ($(filter sdk_addon,$(MAKECMDGOALS)),)
 $(call dist-for-goals, sdk_addon, $(INSTALLED_FILES_FILE))
@@ -1400,6 +1399,7 @@
 			-I $(TARGET_COMMON_OUT_ROOT) \
 			-v "PLATFORM_NAME=android-$(PLATFORM_VERSION)" \
 			-v "OUT_DIR=$(OUT_DIR)" \
+			-v "DIST_DIR=$(DIST_DIR)" \
 			-o $(PRIVATE_DIR) && \
 		cp -f $(target_notice_file_txt) \
 				$(PRIVATE_DIR)/platforms/android-$(PLATFORM_VERSION)/images/NOTICE.txt && \
@@ -1416,9 +1416,10 @@
 
 # Is a Windows SDK requested? If so, we need some definitions from here
 # in order to find the Linux SDK used to create the Windows one.
+MAIN_SDK_NAME := $(sdk_name)
+MAIN_SDK_DIR  := $(sdk_dir)
+MAIN_SDK_ZIP  := $(INTERNAL_SDK_TARGET)
 ifneq ($(filter win_sdk,$(MAKECMDGOALS)),)
-LINUX_SDK_NAME := $(sdk_name)
-LINUX_SDK_DIR  := $(sdk_dir)
 include $(TOPDIR)development/build/tools/windows_sdk.mk
 endif
 
@@ -1444,3 +1445,10 @@
 # These are some additional build tasks that need to be run.
 include $(sort $(wildcard $(BUILD_SYSTEM)/tasks/*.mk))
 -include $(sort $(wildcard vendor/*/build/tasks/*.mk))
+
+# -----------------------------------------------------------------
+# Create SDK repository packages. Must be done after tasks/* since
+# we need the addon rules defined.
+ifneq ($(sdk_repo_goal),)
+include $(TOPDIR)development/build/tools/sdk_repo.mk
+endif
diff --git a/core/base_rules.mk b/core/base_rules.mk
index b1480e1..1178800 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -416,12 +416,14 @@
 #                 to guarantee that the files in full_java_libs will
 #                 be up-to-date.
 ifdef LOCAL_IS_HOST_MODULE
-# TODO: make prebuilt java libraries use the same
-#       intermediates path pattern as target java libraries.
 ifeq ($(LOCAL_BUILD_HOST_DEX),true)
+$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := -bootclasspath $(call java-lib-files,core-hostdex,$(LOCAL_IS_HOST_MODULE))
+
 full_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
 full_java_lib_deps := $(call java-lib-deps,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
 else
+$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH :=
+
 full_java_libs := $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/,$(addsuffix $(COMMON_JAVA_PACKAGE_SUFFIX),$(LOCAL_JAVA_LIBRARIES)))
 full_java_lib_deps := $(full_java_libs)
 endif # LOCAL_BUILD_HOST_DEX
diff --git a/core/binary.mk b/core/binary.mk
index dcac435..7a17ccd 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -28,6 +28,7 @@
   ifndef LOCAL_SDK_VERSION
     $(error $(LOCAL_PATH): LOCAL_NDK_VERSION must be defined with LOCAL_SDK_VERSION)
   endif
+  my_ndk_source_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/android-ndk-r$(LOCAL_NDK_VERSION)/sources
   my_ndk_version_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/android-ndk-r$(LOCAL_NDK_VERSION)/platforms/android-$(LOCAL_SDK_VERSION)/arch-$(TARGET_ARCH)
   ifeq ($(wildcard $(my_ndk_version_root)),)
     $(error $(LOCAL_PATH): ndk version root does not exist: $(my_ndk_version_root))
@@ -59,6 +60,8 @@
 ifdef LOCAL_NDK_VERSION
 my_target_project_includes :=
 my_target_c_inclues := $(my_ndk_version_root)/usr/include
+# Starting from NDK-r5 the c++ stl headers reside in a separate directory
+my_target_c_inclues += $(my_ndk_source_root)/cxx-stl/system/include
 # TODO: more reliable way to remove platform stuff.
 my_target_global_cflags := $(filter-out -include -I system/%, $(TARGET_GLOBAL_CFLAGS))
 my_target_global_cppflags := $(filter-out -include -I system/%, $(TARGET_GLOBAL_CPPFLAGS))
diff --git a/core/build_id.mk b/core/build_id.mk
index e954794..40bb35d 100644
--- a/core/build_id.mk
+++ b/core/build_id.mk
@@ -23,7 +23,7 @@
 # (like "TC1-RC5").  It must be a single word, and is
 # capitalized by convention.
 #
-BUILD_ID := OPENMASTER
+BUILD_ID := MASTER
 
 # DISPLAY_BUILD_NUMBER should only be set for development branches,
 # If set, the BUILD_NUMBER (cl) is appended to the BUILD_ID for
diff --git a/core/combo/HOST_darwin-x86.mk b/core/combo/HOST_darwin-x86.mk
index 121f89b..b829108 100644
--- a/core/combo/HOST_darwin-x86.mk
+++ b/core/combo/HOST_darwin-x86.mk
@@ -59,14 +59,14 @@
 HOST_CUSTOM_LD_COMMAND := true
 
 define transform-host-o-to-shared-lib-inner
-    $(HOST_CXX) \
+$(hide) $(PRIVATE_CXX) \
         -dynamiclib -single_module -read_only_relocs suppress \
         $(HOST_GLOBAL_LD_DIRS) \
         $(HOST_GLOBAL_LDFLAGS) \
         $(PRIVATE_ALL_OBJECTS) \
-        $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
-        $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
-        $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
+        $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
+        $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
+        $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
         $(PRIVATE_LDLIBS) \
         -o $@ \
         $(PRIVATE_LDFLAGS) \
@@ -74,15 +74,15 @@
 endef
 
 define transform-host-o-to-executable-inner
-$(HOST_CXX) \
+$(hide) $(PRIVATE_CXX) \
         -o $@ \
         -Wl,-dynamic -headerpad_max_install_names \
         $(HOST_GLOBAL_LD_DIRS) \
         $(HOST_GLOBAL_LDFLAGS) \
-        $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
+        $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
         $(PRIVATE_ALL_OBJECTS) \
-        $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
-        $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
+        $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
+        $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
         $(PRIVATE_LDFLAGS) \
         $(PRIVATE_LDLIBS) \
         $(HOST_LIBGCC)
diff --git a/core/combo/TARGET_linux-arm.mk b/core/combo/TARGET_linux-arm.mk
index 8b0a6c1..3a3a5bd 100644
--- a/core/combo/TARGET_linux-arm.mk
+++ b/core/combo/TARGET_linux-arm.mk
@@ -133,10 +133,6 @@
 TARGET_GLOBAL_CPPFLAGS += -fvisibility-inlines-hidden
 
 # More flags/options can be added here
-ifeq ($(NEED_WORKAROUND_CORTEX_A9_745320),true)
-TARGET_GLOBAL_CFLAGS += -DWORKAROUND_CORTEX_A9_745320
-endif
-
 TARGET_RELEASE_CFLAGS := \
 			-DNDEBUG \
 			-g \
@@ -231,7 +227,7 @@
 endif
 
 define transform-o-to-shared-lib-inner
-$(TARGET_CXX) \
+$(hide) $(PRIVATE_CXX) \
 	-nostdlib -Wl,-soname,$(notdir $@) -Wl,-T,$(BUILD_SYSTEM)/armelf.xsc \
 	-Wl,--gc-sections \
 	-Wl,-shared,-Bsymbolic \
@@ -239,7 +235,7 @@
 	$(PRIVATE_ALL_OBJECTS) \
 	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
 	-Wl,--whole-archive \
-	$(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
+	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
 	-Wl,--no-whole-archive \
 	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
 	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
@@ -252,7 +248,7 @@
 endef
 
 define transform-o-to-executable-inner
-$(TARGET_CXX) -nostdlib -Bdynamic -Wl,-T,$(BUILD_SYSTEM)/armelf.x \
+$(hide) $(PRIVATE_CXX) -nostdlib -Bdynamic -Wl,-T,$(BUILD_SYSTEM)/armelf.x \
 	-Wl,-dynamic-linker,/system/bin/linker \
     -Wl,--gc-sections \
 	-Wl,-z,nocopyreloc \
@@ -271,7 +267,7 @@
 endef
 
 define transform-o-to-static-executable-inner
-$(TARGET_CXX) -nostdlib -Bstatic -Wl,-T,$(BUILD_SYSTEM)/armelf.x \
+$(hide) $(PRIVATE_CXX) -nostdlib -Bstatic -Wl,-T,$(BUILD_SYSTEM)/armelf.x \
     -Wl,--gc-sections \
 	-o $@ \
 	$(TARGET_GLOBAL_LD_DIRS) \
diff --git a/core/combo/TARGET_linux-sh.mk b/core/combo/TARGET_linux-sh.mk
index 05d18d8..654539c 100644
--- a/core/combo/TARGET_linux-sh.mk
+++ b/core/combo/TARGET_linux-sh.mk
@@ -115,7 +115,7 @@
 
 TARGET_CUSTOM_LD_COMMAND := true
 define transform-o-to-shared-lib-inner
-$(TARGET_CXX) \
+$(hide) $(PRIVATE_CXX) \
 	-nostdlib -Wl,-soname,$(notdir $@) -Wl,-T,$(BUILD_SYSTEM)/shlelf.xsc \
 	-Wl,--gc-sections -Wl,-z,norelro \
 	-Wl,-shared,-Bsymbolic \
@@ -123,7 +123,7 @@
 	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
 	$(PRIVATE_ALL_OBJECTS) \
 	-Wl,--whole-archive \
-	$(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
+	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
 	-Wl,--no-whole-archive \
 	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
 	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
@@ -135,7 +135,7 @@
 endef
 
 define transform-o-to-executable-inner
-$(TARGET_CXX) -nostdlib -Bdynamic  -Wl,-T,$(BUILD_SYSTEM)/shlelf.x \
+$(hide) $(PRIVATE_CXX) -nostdlib -Bdynamic  -Wl,-T,$(BUILD_SYSTEM)/shlelf.x \
 	-Wl,-dynamic-linker,/system/bin/linker \
 	-Wl,--gc-sections -Wl,-z,norelro \
 	-Wl,-z,nocopyreloc \
@@ -153,7 +153,7 @@
 endef
 
 define transform-o-to-static-executable-inner
-$(TARGET_CXX) -nostdlib -Bstatic  -Wl,-T,$(BUILD_SYSTEM)/shlelf.x \
+$(hide) $(PRIVATE_CXX) -nostdlib -Bstatic  -Wl,-T,$(BUILD_SYSTEM)/shlelf.x \
 	-Wl,--gc-sections -Wl,-z,norelro \
 	-o $@ \
 	$(TARGET_GLOBAL_LD_DIRS) \
diff --git a/core/combo/TARGET_linux-x86.mk b/core/combo/TARGET_linux-x86.mk
index 633c202..412ec69 100644
--- a/core/combo/TARGET_linux-x86.mk
+++ b/core/combo/TARGET_linux-x86.mk
@@ -116,7 +116,7 @@
 
 TARGET_CUSTOM_LD_COMMAND := true
 define transform-o-to-shared-lib-inner
-$(TARGET_CXX) \
+$(hide) $(PRIVATE_CXX) \
 	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
 	 -nostdlib -Wl,-soname,$(notdir $@) \
 	 -shared -Bsymbolic \
@@ -125,7 +125,7 @@
 	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
 	$(PRIVATE_ALL_OBJECTS) \
 	-Wl,--whole-archive \
-	$(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
+	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
 	-Wl,--no-whole-archive \
 	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
 	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
@@ -137,7 +137,7 @@
 
 
 define transform-o-to-executable-inner
-$(TARGET_CXX) \
+$(hide) $(PRIVATE_CXX) \
 	$(TARGET_GLOBAL_LDFLAGS) \
 	-nostdlib -Bdynamic \
 	-Wl,-dynamic-linker,/system/bin/linker \
@@ -155,7 +155,7 @@
 endef
 
 define transform-o-to-static-executable-inner
-$(TARGET_CXX) \
+$(hide) $(PRIVATE_CXX) \
 	$(TARGET_GLOBAL_LDFLAGS) \
 	-nostdlib -Bstatic \
 	-o $@ \
diff --git a/core/config.mk b/core/config.mk
index 6cf8f1f..c6f6288 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -70,7 +70,6 @@
 BUILD_HOST_JAVA_LIBRARY:= $(BUILD_SYSTEM)/host_java_library.mk
 BUILD_DROIDDOC:= $(BUILD_SYSTEM)/droiddoc.mk
 BUILD_COPY_HEADERS := $(BUILD_SYSTEM)/copy_headers.mk
-BUILD_KEY_CHAR_MAP := $(BUILD_SYSTEM)/key_char_map.mk
 BUILD_NATIVE_TEST := $(BUILD_SYSTEM)/native_test.mk
 BUILD_HOST_NATIVE_TEST := $(BUILD_SYSTEM)/host_native_test.mk
 
@@ -232,7 +231,6 @@
 
 # dx is java behind a shell script; no .exe necessary.
 DX := $(HOST_OUT_EXECUTABLES)/dx
-KCM := $(HOST_OUT_EXECUTABLES)/kcm$(HOST_EXECUTABLE_SUFFIX)
 ZIPALIGN := $(HOST_OUT_EXECUTABLES)/zipalign$(HOST_EXECUTABLE_SUFFIX)
 FINDBUGS := prebuilt/common/findbugs/bin/findbugs
 LOCALIZE := $(HOST_OUT_EXECUTABLES)/localize$(HOST_EXECUTABLE_SUFFIX)
diff --git a/core/definitions.mk b/core/definitions.mk
index 1f3a446..2875e28 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -736,7 +736,7 @@
 ###########################################################
 
 define transform-d-to-p
-@cp $(@:%.o=%.d) $(@:%.o=%.P); \
+$(hide) cp $(@:%.o=%.d) $(@:%.o=%.P); \
 	sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
 		-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
 	rm -f $(@:%.o=%.d)
@@ -876,7 +876,7 @@
 	$(PRIVATE_CPPFLAGS) \
 	$(PRIVATE_DEBUG_CFLAGS) \
 	-MD -o $@ $<
-$(hide) $(transform-d-to-p)
+$(transform-d-to-p)
 endef
 
 
@@ -920,12 +920,12 @@
 
 define transform-c-to-o
 $(transform-c-to-o-no-deps)
-$(hide) $(transform-d-to-p)
+$(transform-d-to-p)
 endef
 
 define transform-s-to-o
 $(transform-s-to-o-no-deps)
-$(hide) $(transform-d-to-p)
+$(transform-d-to-p)
 endef
 
 ###########################################################
@@ -941,7 +941,7 @@
 
 define transform-m-to-o
 $(transform-m-to-o-no-deps)
-$(hide) $(transform-d-to-p)
+$(transform-d-to-p)
 endef
 
 ###########################################################
@@ -1057,19 +1057,24 @@
 $(call _concat-if-arg2-not-empty,$(1),$(wordlist 3001,99999,$(2)))
 endef
 
+# $(1): the full path of the source static library.
+define _extract-and-include-single-target-whole-static-lib
+@echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(1)]"
+$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
+    rm -rf $$ldir; \
+    mkdir -p $$ldir; \
+    filelist=; \
+    for f in `$(TARGET_AR) t $(1)`; do \
+        $(TARGET_AR) p $(1) $$f > $$ldir/$$f; \
+        filelist="$$filelist $$ldir/$$f"; \
+    done ; \
+    $(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist
+
+endef
+
 define extract-and-include-target-whole-static-libs
 $(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
-	$(hide) echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(lib)]"; \
-	ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(lib)))_objs;\
-	rm -rf $$ldir; \
-	mkdir -p $$ldir; \
-	filelist=; \
-	for f in `$(TARGET_AR) t $(lib)`; do \
-	    $(TARGET_AR) p $(lib) $$f > $$ldir/$$f; \
-	    filelist="$$filelist $$ldir/$$f"; \
-	done ; \
-	$(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist;\
-)
+    $(call _extract-and-include-single-target-whole-static-lib, $(lib)))
 endef
 
 # Explicitly delete the archive first so that ar doesn't
@@ -1086,19 +1091,24 @@
 ## Commands for running host ar
 ###########################################################
 
+# $(1): the full path of the source static library.
+define _extract-and-include-single-host-whole-static-lib
+@echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(1)]"
+$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
+    rm -rf $$ldir; \
+    mkdir -p $$ldir; \
+    filelist=; \
+    for f in `$(HOST_AR) t $(1) | grep '\.o$$'`; do \
+        $(HOST_AR) p $(1) $$f > $$ldir/$$f; \
+        filelist="$$filelist $$ldir/$$f"; \
+    done ; \
+    $(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist
+
+endef
+
 define extract-and-include-host-whole-static-libs
 $(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
-	$(hide) echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(lib)]"; \
-	ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(lib)))_objs;\
-	rm -rf $$ldir; \
-	mkdir -p $$ldir; \
-	filelist=; \
-	for f in `$(HOST_AR) t $(lib) | grep '\.o$$'`; do \
-	    $(HOST_AR) p $(lib) $$f > $$ldir/$$f; \
-	    filelist="$$filelist $$ldir/$$f"; \
-	done ; \
-	$(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist;\
-)
+    $(call _extract-and-include-single-host-whole-static-lib, $(lib)))
 endef
 
 # Explicitly delete the archive first so that ar doesn't
@@ -1120,8 +1130,8 @@
 # it to be overriden en-masse see combo/linux-arm.make for an example.
 ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
 define transform-host-o-to-shared-lib-inner
-$(PRIVATE_CXX) \
-	-Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
+$(hide) $(PRIVATE_CXX) \
+	-Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \
 	-Wl,-rpath,\$$ORIGIN/../lib \
 	-shared -Wl,-soname,$(notdir $@) \
 	$(PRIVATE_LDFLAGS) \
@@ -1143,13 +1153,13 @@
 define transform-host-o-to-shared-lib
 @mkdir -p $(dir $@)
 @echo "host SharedLib: $(PRIVATE_MODULE) ($@)"
-$(hide) $(transform-host-o-to-shared-lib-inner)
+$(transform-host-o-to-shared-lib-inner)
 endef
 
 define transform-host-o-to-package
 @mkdir -p $(dir $@)
 @echo "host Package: $(PRIVATE_MODULE) ($@)"
-$(hide) $(transform-host-o-to-shared-lib-inner)
+$(transform-host-o-to-shared-lib-inner)
 endef
 
 
@@ -1170,7 +1180,7 @@
 # it to be overriden en-masse see combo/linux-arm.make for an example.
 ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
 define transform-o-to-shared-lib-inner
-$(PRIVATE_CXX) \
+$(hide) $(PRIVATE_CXX) \
 	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
 	-Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
 	-Wl,-rpath,\$$ORIGIN/../lib \
@@ -1179,7 +1189,7 @@
 	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
 	$(PRIVATE_ALL_OBJECTS) \
 	-Wl,--whole-archive \
-	$(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
+	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
 	-Wl,--no-whole-archive \
 	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
 	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
@@ -1191,13 +1201,13 @@
 define transform-o-to-shared-lib
 @mkdir -p $(dir $@)
 @echo "target SharedLib: $(PRIVATE_MODULE) ($@)"
-$(hide) $(transform-o-to-shared-lib-inner)
+$(transform-o-to-shared-lib-inner)
 endef
 
 define transform-o-to-package
 @mkdir -p $(dir $@)
 @echo "target Package: $(PRIVATE_MODULE) ($@)"
-$(hide) $(transform-o-to-shared-lib-inner)
+$(transform-o-to-shared-lib-inner)
 endef
 
 
@@ -1229,7 +1239,7 @@
 
 ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
 define transform-o-to-executable-inner
-$(PRIVATE_CXX) \
+$(hide) $(PRIVATE_CXX) \
 	$(TARGET_GLOBAL_LDFLAGS) \
 	-Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
 	$(TARGET_GLOBAL_LD_DIRS) \
@@ -1251,7 +1261,7 @@
 define transform-o-to-executable
 @mkdir -p $(dir $@)
 @echo "target Executable: $(PRIVATE_MODULE) ($@)"
-$(hide) $(transform-o-to-executable-inner)
+$(transform-o-to-executable-inner)
 endef
 
 
@@ -1270,7 +1280,7 @@
 define transform-o-to-static-executable
 @mkdir -p $(dir $@)
 @echo "target StaticExecutable: $(PRIVATE_MODULE) ($@)"
-$(hide) $(transform-o-to-static-executable-inner)
+$(transform-o-to-static-executable-inner)
 endef
 
 
@@ -1280,8 +1290,8 @@
 
 ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
 define transform-host-o-to-executable-inner
-$(PRIVATE_CXX) \
-	-Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
+$(hide) $(PRIVATE_CXX) \
+	-Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \
 	-Wl,-rpath,\$$ORIGIN/../lib \
 	$(HOST_GLOBAL_LD_DIRS) \
 	$(PRIVATE_LDFLAGS) \
@@ -1302,7 +1312,7 @@
 define transform-host-o-to-executable
 @mkdir -p $(dir $@)
 @echo "host Executable: $(PRIVATE_MODULE) ($@)"
-$(hide) $(transform-host-o-to-executable-inner)
+$(transform-host-o-to-executable-inner)
 endef
 
 
@@ -1419,12 +1429,12 @@
 $(hide) mkdir -p $(dir $@)
 $(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
 $(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR))
-$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list)
+$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list)
 $(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
-	    find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list; \
+	    find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \
 fi
-$(hide) tr ' ' '\n' < $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))java-source-list \
-    | sort -u > $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))java-source-list-uniq
+$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \
+    | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
 $(hide) $(1) -encoding ascii \
     $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \
     $(if $(findstring true,$(LOCAL_WARNINGS_ENABLE)),$(xlint_unchecked),) \
@@ -1434,10 +1444,10 @@
     $(if $(findstring true,$(LOCAL_WARNINGS_ENABLE)),$(xlint_unchecked),) \
     -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
     $(PRIVATE_JAVACFLAGS) \
-    \@$(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))java-source-list-uniq \
+    \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \
     || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
-$(hide) rm -f $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list
-$(hide) rm -f $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq
+$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list
+$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
 $(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
     $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
 endef
@@ -1448,6 +1458,51 @@
 $(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
 endef
 
+# Override the above definitions if we want to do incremetal javac
+ifeq (true, $(ENABLE_INCREMENTALJAVAC))
+define compile-java
+$(hide) mkdir -p $(dir $@)
+$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
+$(hide) touch $(PRIVATE_CLASS_INTERMEDIATES_DIR)/newstamp
+$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR))
+$(hide) if [ -e $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp ] ; then \
+        newerFlag=$$(echo -n "-newer $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp") ; \
+    fi ; \
+    find $(PRIVATE_JAVA_SOURCES) $$newerFlag > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list ; \
+    if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
+        find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' $$newerFlag >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \
+    fi
+$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \
+    | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
+@echo "(Incremental) build source files:"
+@cat $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
+$(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
+    $(1) -encoding ascii \
+    $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \
+    $(if $(findstring true,$(LOCAL_WARNINGS_ENABLE)),$(xlint_unchecked),) \
+    $(2) \
+    $(addprefix -classpath ,$(strip \
+        $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES) $(PRIVATE_CLASS_INTERMEDIATES_DIR)))) \
+    $(if $(findstring true,$(LOCAL_WARNINGS_ENABLE)),$(xlint_unchecked),) \
+    -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
+    $(PRIVATE_JAVACFLAGS) \
+    \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \
+    || ( exit 41 ) \
+fi
+$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list
+$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
+$(hide) rm -f $@
+$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
+    $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
+$(hide) mv $(PRIVATE_CLASS_INTERMEDIATES_DIR)/newstamp $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp
+endef
+
+define transform-java-to-classes.jar
+@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
+$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH))
+endef
+endif # ENABLE_INCREMENTALJAVAC
+
 define transform-classes.jar-to-emma
 $(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \
     $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \
@@ -1571,7 +1626,7 @@
 # in transform-java-to-classes for the sake of vm-tests.
 define transform-host-java-to-package
 @echo "host Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
-$(call compile-java,$(HOST_JAVAC),)
+$(call compile-java,$(HOST_JAVAC),$(PRIVATE_BOOTCLASSPATH))
 $(hide) if [ ! -z "$(PRIVATE_EXTRA_JAR_ARGS)" ]; then jar uf $@ $(PRIVATE_EXTRA_JAR_ARGS); fi
 endef
 
@@ -1778,8 +1833,10 @@
 # spare area for each page).
 # $(1): the partition data size
 define image-size-from-data-size
-$(shell echo $$(($(1) / $(BOARD_NAND_PAGE_SIZE) * \
-  ($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE)))))
+$(strip $(eval _isfds_value := $$(shell echo $$$$(($(1) / $(BOARD_NAND_PAGE_SIZE) * \
+  ($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE))))))\
+$(if $(filter 0, $(_isfds_value)),$(shell echo $$(($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE)))),$(_isfds_value))\
+$(eval _isfds_value :=))
 endef
 
 # $(1): The file(s) to check (often $@)
diff --git a/core/dex_preopt.mk b/core/dex_preopt.mk
index 4da2632..9f44c32 100644
--- a/core/dex_preopt.mk
+++ b/core/dex_preopt.mk
@@ -4,7 +4,7 @@
 ####################################
 
 # TODO: replace it with device's BOOTCLASSPATH
-DEXPREOPT_BOOT_JARS := core:bouncycastle:ext:framework:android.policy:services:core-junit
+DEXPREOPT_BOOT_JARS := core:apache-xml:bouncycastle:ext:framework:android.policy:services:core-junit
 DEXPREOPT_BOOT_JARS_MODULES := $(subst :, ,$(DEXPREOPT_BOOT_JARS))
 
 DEXPREOPT_BUILD_DIR := $(OUT_DIR)
diff --git a/core/key_char_map.mk b/core/key_char_map.mk
deleted file mode 100644
index 0f112f2..0000000
--- a/core/key_char_map.mk
+++ /dev/null
@@ -1,27 +0,0 @@
-###########################################################
-## Standard rules for building an executable file.
-##
-## Additional inputs from base_rules.make:
-## None.
-###########################################################
-
-ifeq ($(strip $(LOCAL_MODULE_CLASS)),)
-LOCAL_MODULE_CLASS := KEYCHARS
-endif
-ifeq ($(strip $(LOCAL_MODULE_SUFFIX)),)
-LOCAL_MODULE_SUFFIX := .bin
-endif
-
-LOCAL_MODULE := $(LOCAL_SRC_FILES)
-
-include $(BUILD_SYSTEM)/base_rules.mk
-
-full_src_files := $(addprefix $(LOCAL_PATH)/,$(LOCAL_SRC_FILES))
-
-$(LOCAL_BUILT_MODULE) : PRIVATE_SRC_FILES := $(full_src_files)
-
-$(LOCAL_BUILT_MODULE) : $(full_src_files) $(KCM)
-	@echo KeyCharMap: $@
-	@mkdir -p $(dir $@)
-	$(hide) $(KCM) $(PRIVATE_SRC_FILES) $@
-    
diff --git a/core/main.mk b/core/main.mk
index 6c53b8a..e5824db 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -155,7 +155,23 @@
 # These are the modifier targets that don't do anything themselves, but
 # change the behavior of the build.
 # (must be defined before including definitions.make)
-INTERNAL_MODIFIER_TARGETS := showcommands checkbuild all
+INTERNAL_MODIFIER_TARGETS := showcommands checkbuild all incrementaljavac
+
+.PHONY: incrementaljavac
+incrementaljavac: ;
+
+# WARNING:
+# ENABLE_INCREMENTALJAVAC should NOT be enabled by default, because change of
+# a Java source file won't trigger rebuild of its dependent Java files.
+# You can only enable it by adding "incrementaljavac" to your make command line.
+# You are responsible for the correctness of the incremental build.
+# This may decrease incremental build time dramatically for large Java libraries,
+# such as core.jar, framework.jar, etc.
+ENABLE_INCREMENTALJAVAC :=
+ifneq (,$(filter incrementaljavac, $(MAKECMDGOALS)))
+ENABLE_INCREMENTALJAVAC := true
+MAKECMDGOALS := $(filter-out incrementaljavac, $(MAKECMDGOALS))
+endif
 
 # Bring in standard build system definitions.
 include $(BUILD_SYSTEM)/definitions.mk
@@ -193,13 +209,8 @@
 ###
 
 is_sdk_build :=
-ifneq ($(filter sdk,$(MAKECMDGOALS)),)
-is_sdk_build := true
-endif
-ifneq ($(filter win_sdk,$(MAKECMDGOALS)),)
-is_sdk_build := true
-endif
-ifneq ($(filter sdk_addon,$(MAKECMDGOALS)),)
+
+ifneq ($(filter sdk win_sdk sdk_addon,$(MAKECMDGOALS)),)
 is_sdk_build := true
 endif
 
@@ -274,6 +285,11 @@
 ## sdk ##
 
 ifdef is_sdk_build
+
+# Detect if we want to build a repository for the SDK
+sdk_repo_goal := $(strip $(filter sdk_repo,$(MAKECMDGOALS)))
+MAKECMDGOALS := $(strip $(filter-out sdk_repo,$(MAKECMDGOALS)))
+
 ifneq ($(words $(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS))),1)
 $(error The 'sdk' target may not be specified with any other targets)
 endif
@@ -298,6 +314,7 @@
   ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.dexopt-flags=m=y
 endif
 
+ifneq ($(BUILD_TINY_ANDROID),true)
 # Install an apns-conf.xml file if one's not already being installed.
 ifeq (,$(filter %:system/etc/apns-conf.xml, $(PRODUCT_COPY_FILES)))
   PRODUCT_COPY_FILES += \
@@ -318,6 +335,7 @@
     endif
   endif
 endif
+endif
 
 ADDITIONAL_BUILD_PROPERTIES += net.bt.name=Android
 
@@ -457,11 +475,11 @@
 	bionic \
 	system/core \
 	system/extras/ext4_utils \
+	system/extras/su \
 	build/libs \
 	build/target \
 	build/tools/acp \
 	build/tools/apriori \
-	build/tools/kcm \
 	build/tools/soslim \
 	external/elfcopy \
 	external/elfutils \
@@ -810,8 +828,8 @@
 .PHONY: sdk
 ALL_SDK_TARGETS := $(INTERNAL_SDK_TARGET)
 sdk: $(ALL_SDK_TARGETS)
-ifneq ($(filter sdk,$(MAKECMDGOALS)),)
-$(call dist-for-goals,sdk, \
+ifneq ($(filter sdk win_sdk,$(MAKECMDGOALS)),)
+$(call dist-for-goals,sdk win_sdk, \
 	$(ALL_SDK_TARGETS) \
 	$(SYMBOLS_ZIP) \
  )
diff --git a/core/package.mk b/core/package.mk
index 57d6f4b..8ca9033 100644
--- a/core/package.mk
+++ b/core/package.mk
@@ -157,15 +157,9 @@
 endif
 endif
 
-# The dex files go in the package, so we don't
-# want to install them separately for this module.
-old_DONT_INSTALL_DEX_FILES := $(DONT_INSTALL_DEX_FILES)
-DONT_INSTALL_DEX_FILES := true
 #################################
 include $(BUILD_SYSTEM)/java.mk
 #################################
-DONT_INSTALL_DEX_FILES := $(old_DONT_INSTALL_DEX_FILES)
-old_DONT_INSTALL_DEX_FILES =
 
 full_android_manifest := $(LOCAL_PATH)/$(LOCAL_MANIFEST_FILE)
 $(LOCAL_INTERMEDIATE_TARGETS): \
diff --git a/core/prelink-linux-arm.map b/core/prelink-linux-arm.map
index 86cec55..41cd8cd 100644
--- a/core/prelink-linux-arm.map
+++ b/core/prelink-linux-arm.map
@@ -93,7 +93,6 @@
 libskiagl.so            0xA9C00000 # [~1M]
 
 # audio
-libFLAC.so              0xA9B00000 # [???]
 libaudiopolicy.so       0xA9A00000 # [~1M]
 libeffects.so           0xA9980000 # [<64K]
 libaudioeffect_jni.so   0xA9900000 # [<64K]
@@ -182,7 +181,6 @@
 libgsl.so               0xA2A00000 # [~1M]
 libhtc_acoustic.so      0xA2900000 # [<64K]
 libhtc_ril.so           0xA2800000 # [~1M]
-liblvmxipc.so           0xA2700000 # [~1M] for vendor/nxp
 libreference-cdma-sms.so 0xA2600000 # [<64K] for hardware/ril
 
 # libraries for specific apps or temporary libraries
diff --git a/core/tasks/sdk-addon.mk b/core/tasks/sdk-addon.mk
index 9133312..afcda23 100644
--- a/core/tasks/sdk-addon.mk
+++ b/core/tasks/sdk-addon.mk
@@ -94,7 +94,16 @@
 .PHONY: sdk_addon
 sdk_addon: $(full_target)
 
+ifneq ($(sdk_repo_goal),)
+# If we're building the sdk_repo, keep the name of the addon zip
+# around so that development/build/tools/sdk_repo.mk can dist it
+# at the appropriate location.
+ADDON_SDK_ZIP := $(full_target)
+else
+# When not building an sdk_repo, just dist the addon zip file
+# as-is.
 $(call dist-for-goals, sdk_addon, $(full_target))
+endif
 
 else # addon_name
 ifneq ($(filter sdk_addon,$(MAKECMDGOALS)),)
diff --git a/core/user_tags.mk b/core/user_tags.mk
index 1b4ef65..090b7fa 100644
--- a/core/user_tags.mk
+++ b/core/user_tags.mk
@@ -169,7 +169,6 @@
 	jsr305lib \
 	junit \
 	jython \
-	kcm \
 	keystore \
 	kxml2-2.3.0 \
 	launch-wrapper \
@@ -395,7 +394,6 @@
 	logcat \
 	logwrapper \
 	lsd \
-	mahimahi-keypad.kcm \
 	make_cfst \
 	makedict \
 	make_ext4fs \
@@ -446,8 +444,6 @@
 	q2dm \
 	q2g \
 	qemu-android \
-	qwerty2.kcm \
-	qwerty.kcm \
 	racoon \
 	read_addr \
 	read_method \
@@ -489,7 +485,6 @@
 	spec-progress \
 	sqlite3 \
 	stack_dump \
-	stingray-keypad.kcm \
 	stringtemplate \
 	surfaceflinger \
 	svc \
diff --git a/core/version_defaults.mk b/core/version_defaults.mk
index 23e45a2..7109989 100644
--- a/core/version_defaults.mk
+++ b/core/version_defaults.mk
@@ -59,7 +59,7 @@
 ifeq "" "$(PLATFORM_VERSION_CODENAME)"
   # This is the current development code-name, if the build is not a final
   # release build.  If this is a final release build, it is simply "REL".
-  PLATFORM_VERSION_CODENAME := AOSP
+  PLATFORM_VERSION_CODENAME := Honeycomb
 endif
 
 ifeq "" "$(DEFAULT_APP_TARGET_SDK)"
@@ -96,3 +96,4 @@
   # anyone trying to parse it as an integer will probably get "0".
   BUILD_NUMBER := eng.$(USER).$(shell date +%Y%m%d.%H%M%S)
 endif
+
diff --git a/envsetup.sh b/envsetup.sh
index 4b2c19e..2faeed1 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -695,6 +695,8 @@
                     ARGS="$ARGS showcommands"
                 elif [ "$DIR" = dist ]; then
                     ARGS="$ARGS dist"
+                elif [ "$DIR" = incrementaljavac ]; then
+                    ARGS="$ARGS incrementaljavac"
                 else
                     echo "No Android.mk in $DIR."
                     return 1
diff --git a/target/board/generic_x86/BoardConfig.mk b/target/board/generic_x86/BoardConfig.mk
index 2268d41..83a8c3e 100644
--- a/target/board/generic_x86/BoardConfig.mk
+++ b/target/board/generic_x86/BoardConfig.mk
@@ -20,8 +20,9 @@
 BOARD_BOOTIMAGE_MAX_SIZE := 8388608
 BOARD_SYSLOADER_MAX_SIZE := 7340032
 BOARD_FLASH_BLOCK_SIZE := 512
-BOARD_USERDATAIMAGE_PARTITION_SIZE := 50M
-BOARD_INSTALLERIMAGE_PARTITION_SIZE := 500M
+BOARD_SYSTEMIMAGE_PARTITION_SIZE := 157286400
+BOARD_USERDATAIMAGE_PARTITION_SIZE := 52428800
+BOARD_INSTALLERIMAGE_PARTITION_SIZE := 524288000
 TARGET_USERIMAGES_SPARSE_EXT_DISABLED := true
 
 
diff --git a/target/board/generic_x86/AndroidBoard.mk b/target/board/generic_x86/device.mk
similarity index 73%
rename from target/board/generic_x86/AndroidBoard.mk
rename to target/board/generic_x86/device.mk
index 01ca1b7..bbdc8f4 100644
--- a/target/board/generic_x86/AndroidBoard.mk
+++ b/target/board/generic_x86/device.mk
@@ -1,5 +1,3 @@
-LOCAL_PATH := $(call my-dir)
-
 ifeq ($(TARGET_PREBUILT_KERNEL),)
 LOCAL_KERNEL := prebuilt/android-x86/kernel/kernel
 else
@@ -8,4 +6,4 @@
 
 PRODUCT_COPY_FILES += \
     $(LOCAL_KERNEL):kernel \
-    $(LOCAL_PATH)/init.rc:root/init.rc
+    build/target/board/generic_x86/init.rc:root/init.rc
diff --git a/target/product/core.mk b/target/product/core.mk
index 06b7003..7957a07 100644
--- a/target/product/core.mk
+++ b/target/product/core.mk
@@ -23,6 +23,7 @@
     ro.config.alarm_alert=Alarm_Classic.ogg
 
 PRODUCT_PACKAGES := \
+    apache-xml \
     bouncycastle \
     com.android.location.provider \
     com.android.location.provider.xml \
diff --git a/target/product/full_x86.mk b/target/product/full_x86.mk
index f137b8a..9e22bc5 100644
--- a/target/product/full_x86.mk
+++ b/target/product/full_x86.mk
@@ -27,8 +27,10 @@
 endif
 
 $(call inherit-product, $(SRC_TARGET_DIR)/product/full_base.mk)
+$(call inherit-product, $(SRC_TARGET_DIR)/board/generic_x86/device.mk)
 
 # Overrides
 PRODUCT_NAME := full_x86
 PRODUCT_DEVICE := generic_x86
+PRODUCT_BRAND := Android
 PRODUCT_MODEL := Full Android x86
diff --git a/target/product/generic_no_telephony.mk b/target/product/generic_no_telephony.mk
index db74a7f..2a3aae7 100644
--- a/target/product/generic_no_telephony.mk
+++ b/target/product/generic_no_telephony.mk
@@ -30,6 +30,7 @@
     CertInstaller \
     DrmProvider \
     Email \
+    Exchange \
     Gallery3D \
     LatinIME \
     Launcher2 \
diff --git a/target/product/large_emu_hw.mk b/target/product/large_emu_hw.mk
index 07991ac..139a9da 100644
--- a/target/product/large_emu_hw.mk
+++ b/target/product/large_emu_hw.mk
@@ -31,6 +31,7 @@
     CertInstaller \
     DrmProvider \
     Email \
+    Exchange \
     Gallery3D \
     LatinIME \
     Launcher2 \
diff --git a/target/product/sdk.mk b/target/product/sdk.mk
index cfc518a..d020ec8 100644
--- a/target/product/sdk.mk
+++ b/target/product/sdk.mk
@@ -22,6 +22,7 @@
 	Camera \
 	DeskClock \
 	Email \
+	Exchange \
 	Gallery \
 	Music \
 	Mms \
@@ -196,9 +197,9 @@
 	zh_TW
 
 # include available languages for TTS in the system image
-include external/svox/pico/lang/PicoLangDeDeInSystem.mk
-include external/svox/pico/lang/PicoLangEnGBInSystem.mk
-include external/svox/pico/lang/PicoLangEnUsInSystem.mk
-include external/svox/pico/lang/PicoLangEsEsInSystem.mk
-include external/svox/pico/lang/PicoLangFrFrInSystem.mk
-include external/svox/pico/lang/PicoLangItItInSystem.mk
+-include external/svox/pico/lang/PicoLangDeDeInSystem.mk
+-include external/svox/pico/lang/PicoLangEnGBInSystem.mk
+-include external/svox/pico/lang/PicoLangEnUsInSystem.mk
+-include external/svox/pico/lang/PicoLangEsEsInSystem.mk
+-include external/svox/pico/lang/PicoLangFrFrInSystem.mk
+-include external/svox/pico/lang/PicoLangItItInSystem.mk
diff --git a/tools/adbs b/tools/adbs
index 4fb94d5..b571d48 100755
--- a/tools/adbs
+++ b/tools/adbs
@@ -113,7 +113,7 @@
     path = os.environ['ANDROID_PRODUCT_OUT'] + "/symbols"
   except:
     cmd = "CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core " \
-      + "SRC_TARGET_DIR=build/target make -f build/core/envsetup.mk " \
+      + "SRC_TARGET_DIR=build/target make -f build/core/config.mk " \
       + "dumpvar-abs-TARGET_OUT_UNSTRIPPED"
     stream = os.popen(cmd)
     str = stream.read()
diff --git a/tools/event_log_tags.py b/tools/event_log_tags.py
index 81e8b39..645839e 100644
--- a/tools/event_log_tags.py
+++ b/tools/event_log_tags.py
@@ -90,6 +90,14 @@
         else:
           description = None
 
+        if description:
+          # EventLog.java checks that the description field is
+          # surrounded by parens, so we should too (to avoid a runtime
+          # crash from badly-formatted descriptions).
+          if not re.match(r"\(.*\)\s*$", description):
+            self.AddError("tag \"%s\" has unparseable description" % (tagname,))
+            continue
+
         self.tags.append(Tag(tag, tagname, description,
                              self.filename, self.linenum))
     except (IOError, OSError), e:
diff --git a/tools/kcm/Android.mk b/tools/kcm/Android.mk
deleted file mode 100644
index 130a13a..0000000
--- a/tools/kcm/Android.mk
+++ /dev/null
@@ -1,15 +0,0 @@
-# Copyright 2007 The Android Open Source Project
-#
-# Copies files into the directory structure described by a manifest
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-	kcm.cpp
-
-LOCAL_MODULE := kcm
-
-include $(BUILD_HOST_EXECUTABLE)
-
-
diff --git a/tools/kcm/kcm.cpp b/tools/kcm/kcm.cpp
deleted file mode 100644
index 23ac377..0000000
--- a/tools/kcm/kcm.cpp
+++ /dev/null
@@ -1,421 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <ui/KeycodeLabels.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <map>
-#include <string>
-#include <utils/ByteOrder.h>
-
-using namespace std;
-
-enum {
-    LENDIAN,
-    BENDIAN
-};
-
-/*
- * 1: KeyEvent name
- * 2: display_label
- * 3: number
- * 4..7: base, shift, alt, shift-alt
- */
-#define COLUMNS (3+4)
-
-struct KeyRecord
-{
-    int lineno;
-    int values[COLUMNS];
-};
-
-struct PropValue
-{
-    PropValue() { lineno = -1; }
-    PropValue(const PropValue& that) { lineno=that.lineno; value=that.value; }
-    PropValue(int l, const string& v) { lineno = l; value = v; }
-
-    int lineno;
-    string value;
-};
-
-static int usage();
-
-//  0 -- ok
-// >0 -- error
-static int parse_key_line(const char* filename, int lineno, char* line,
-        KeyRecord* out);
-static int write_kr(int fd, const KeyRecord& kr);
-
-int g_endian;
-
-int
-main(int argc, char** argv)
-{
-    int err;
-    if (argc != 3) {
-        return usage();
-    }
-
-    const char* filename = argv[1];
-    const char* outfilename = argv[2];
-
-    int in = open(filename, O_RDONLY);
-    if (in == -1) {
-        fprintf(stderr, "kcm: error opening file for read: %s\n", filename);
-        return 1;
-    }
-
-    off_t size = lseek(in, 0, SEEK_END);
-    lseek(in, 0, SEEK_SET);
-
-    char* input = (char*)malloc(size+1);
-    read(in, input, size);
-    input[size] = '\0';
-
-    close(in);
-    in = -1;
-
-    map<string,PropValue> properties;
-    map<int,KeyRecord> keys;
-    int errorcount = 0;
-    int lineno = 1;
-    char *thisline = input;
-    while (*thisline) {
-        KeyRecord kr;
-        char *nextline = thisline;
-        
-        while (*nextline != '\0' && *nextline != '\n' && *nextline != '\r') {
-            nextline++;
-        }
-
-        // eat whitespace, but not newlines
-        while (*thisline != '\0' && (*thisline == ' ' || *thisline == '\t')) {
-            thisline++;
-        }
-
-        // find the end of the line
-        char lineend = *nextline;
-        *nextline = '\0';
-        if (lineend == '\r' && nextline[1] == '\n') {
-            nextline++;
-        }
-
-        if (*thisline == '\0' || *thisline == '\r' || *thisline == '\n'
-                 || *thisline == '#') {
-            // comment or blank line
-        }
-        else if (*thisline == '[') {
-            // property - syntax [name=value]
-            // look for =
-            char* prop = thisline+1;
-            char* end = prop;
-            while (*end != '\0' && *end != '=') {
-                end++;
-            }
-            if (*end != '=') {
-                fprintf(stderr, "%s:%d: invalid property line: %s\n",
-                        filename, lineno, thisline);
-                errorcount++;
-            } else {
-                *end = '\0';
-                char* value = end+1;
-                end = nextline;
-                while (end > prop && *end != ']') {
-                    end--;
-                }
-                if (*end != ']') {
-                    fprintf(stderr, "%s:%d: property missing closing ]: %s\n",
-                            filename, lineno, thisline);
-                    errorcount++;
-                } else {
-                    *end = '\0';
-                    properties[prop] = PropValue(lineno, value);
-                }
-            }
-        }
-        else {
-            // key
-            err = parse_key_line(filename, lineno, thisline, &kr);
-            if (err == 0) {
-                kr.lineno = lineno;
-
-                map<int,KeyRecord>::iterator old = keys.find(kr.values[0]);
-                if (old != keys.end()) {
-                    fprintf(stderr, "%s:%d: keycode %d already defined\n",
-                            filename, lineno, kr.values[0]);
-                    fprintf(stderr, "%s:%d: previously defined here\n",
-                            filename, old->second.lineno);
-                    errorcount++;
-                }
-
-                keys[kr.values[0]] = kr;
-            }
-            else if (err > 0) {
-                errorcount += err;
-            }
-        }
-        lineno++;
-
-        nextline++;
-        thisline = nextline;
-
-        if (errorcount > 20) {
-            fprintf(stderr, "%s:%d: too many errors.  stopping.\n", filename,
-                    lineno);
-            return 1;
-        }
-    }
-
-    free(input);
-
-    map<string,PropValue>::iterator sit = properties.find("type");
-    if (sit == properties.end()) {
-        fprintf(stderr, "%s: key character map must contain type property.\n",
-		argv[0]);
-        errorcount++;
-    }
-    PropValue pv = sit->second;
-    unsigned char kbdtype = 0;
-    if (pv.value == "NUMERIC") {
-        kbdtype = 1;
-    }
-    else if (pv.value == "Q14") {
-        kbdtype = 2;
-    }
-    else if (pv.value == "QWERTY") {
-        kbdtype = 3;
-    }
-    else {
-        fprintf(stderr, "%s:%d: keyboard type must be one of NUMERIC, Q14 "
-                " or QWERTY, not %s\n", filename, pv.lineno, pv.value.c_str());
-    }
-
-    if (errorcount != 0) {
-        return 1;
-    }
-
-    int out = open(outfilename, O_RDWR|O_CREAT|O_TRUNC, 0664);
-    if (out == -1) {
-        fprintf(stderr, "kcm: error opening file for write: %s\n", outfilename);
-        return 1;
-    }
-
-    int count = keys.size();
-    
-    map<int,KeyRecord>::iterator it;
-    int n;
-
-    /**
-     * File Format:
-     *    Offset    Description     Value
-     *    0         magic string    "keychar"
-     *    8         endian marker   0x12345678
-     *    12        version         0x00000002
-     *    16        key count       number of key entries
-     *    20        keyboard type   NUMERIC, Q14, QWERTY, etc.
-     *    21        padding         0
-     *    32        the keys
-     */
-    err = write(out, "keychar", 8);
-    if (err == -1) goto bad_write;
-
-    n = htodl(0x12345678);
-    err = write(out, &n, 4);
-    if (err == -1) goto bad_write;
-
-    n = htodl(0x00000002);
-    err = write(out, &n, 4);
-    if (err == -1) goto bad_write;
-
-    n = htodl(count);
-    err = write(out, &n, 4);
-    if (err == -1) goto bad_write;
-
-    err = write(out, &kbdtype, 1);
-    if (err == -1) goto bad_write;
-
-    char zero[11];
-    memset(zero, 0, 11);
-    err = write(out, zero, 11);
-    if (err == -1) goto bad_write;
-
-    for (it = keys.begin(); it != keys.end(); it++) {
-        const KeyRecord& kr = it->second;
-        /*
-        printf("%2d/ [%d] [%d] [%d] [%d] [%d] [%d] [%d]\n", kr.lineno,
-                kr.values[0], kr.values[1], kr.values[2], kr.values[3],
-                kr.values[4], kr.values[5], kr.values[6]);
-        */
-        err = write_kr(out, kr);
-        if (err == -1) goto bad_write;
-    }
-
-    close(out);
-    return 0;
-
-bad_write:
-    fprintf(stderr, "kcm: fatal error writing to file: %s\n", outfilename);
-    close(out);
-    unlink(outfilename);
-    return 1;
-}
-
-static int usage()
-{
-    fprintf(stderr,
-            "usage: kcm INPUT OUTPUT\n"
-            "\n"
-            "INPUT   keycharmap file\n"
-            "OUTPUT  compiled keycharmap file\n"
-        );
-    return 1;
-}
-
-static int
-is_whitespace(const char* p)
-{
-    while (*p) {
-        if (!isspace(*p)) {
-            return 0;
-        }
-        p++;
-    }
-    return 1;
-}
-
-
-static int
-parse_keycode(const char* filename, int lineno, char* str, int* value)
-{
-    const KeycodeLabel *list = KEYCODES;
-    while (list->literal) {
-        if (0 == strcmp(str, list->literal)) {
-            *value = list->value;
-            return 0;
-        }
-        list++;
-    }
-
-    char* endptr;
-    *value = strtol(str, &endptr, 0);
-    if (*endptr != '\0') {
-        fprintf(stderr, "%s:%d: expected keycode label or number near: "
-                "%s\n", filename, lineno, str);
-        return 1;
-    }
-
-    if (*value == 0) {
-        fprintf(stderr, "%s:%d: 0 is not a valid keycode.\n",
-                filename, lineno);
-        return 1;
-    }
-
-    return 0;
-}
-
-static int
-parse_number(const char* filename, int lineno, char* str, int* value)
-{
-    int len = strlen(str);
-
-    if (len == 3 && str[0] == '\'' && str[2] == '\'') {
-        if (str[1] > 0 && str[1] < 127) {
-            *value = (int)str[1];
-            return 0;
-        } else {
-            fprintf(stderr, "%s:%d: only low ascii characters are allowed in"
-                    " quotes near: %s\n", filename, lineno, str);
-            return 1;
-        }
-    }
-
-    char* endptr;
-    *value = strtol(str, &endptr, 0);
-    if (*endptr != '\0') {
-        fprintf(stderr, "%s:%d: expected number or quoted ascii but got: %s\n",
-                filename, lineno, str);
-        return 1;
-    }
-
-    if (*value >= 0xfffe || *value < 0) {
-        fprintf(stderr, "%s:%d: unicode char out of range (no negatives, "
-                "nothing larger than 0xfffe): %s\n", filename, lineno, str);
-        return 1;
-    }
-
-    return 0;
-}
-
-static int
-parse_key_line(const char* filename, int lineno, char* line, KeyRecord* out)
-{
-    char* p = line;
-
-    int len = strlen(line);
-    char* s[COLUMNS];
-    for (int i=0; i<COLUMNS; i++) {
-        s[i] = (char*)malloc(len+1);
-    }
-
-    for (int i = 0; i < COLUMNS; i++) {
-        while (*p != '\0' && isspace(*p)) {
-            p++;
-        }
-
-        if (*p == '\0') {
-            fprintf(stderr, "%s:%d: not enough on this line: %s\n", filename,
-                    lineno, line);
-            return 1;
-        }
-
-        char *p1 = p;
-        while (*p != '\0' && !isspace(*p)) {
-            p++;
-        }
-
-        memcpy(s[i], p1, p - p1);
-        s[i][p - p1] = '\0';
-    }
-
-    while (*p != '\0' && isspace(*p)) {
-        *p++;
-    }
-    if (*p != '\0') {
-        fprintf(stderr, "%s:%d: too much on one line near: %s\n", filename,
-                lineno, p);
-        fprintf(stderr, "%s:%d: -->%s<--\n", filename, lineno, line);
-        return 1;
-    }
-
-    int errorcount = parse_keycode(filename, lineno, s[0], &out->values[0]);
-    for (int i=1; i<COLUMNS && errorcount == 0; i++) {
-        errorcount += parse_number(filename, lineno, s[i], &out->values[i]);
-    }
-
-    return errorcount;
-}
-
-struct WrittenRecord
-{
-    unsigned int keycode;       // 4 bytes
-    unsigned short values[COLUMNS - 1];   // 6*2 bytes = 12
-                                // 16 bytes total 
-};
-
-static int
-write_kr(int fd, const KeyRecord& kr)
-{
-    WrittenRecord wr;
-
-    wr.keycode = htodl(kr.values[0]);
-    for (int i=0; i<COLUMNS - 1; i++) {
-        wr.values[i] = htods(kr.values[i+1]);
-    }
-
-    return write(fd, &wr, sizeof(WrittenRecord));
-}
-
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index fbdd5eb..bcfacb2 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -18,6 +18,7 @@
 import getpass
 import imp
 import os
+import platform
 import re
 import shutil
 import subprocess
@@ -63,6 +64,22 @@
   return subprocess.Popen(args, **kwargs)
 
 
+def CloseInheritedPipes():
+  """ Gmake in MAC OS has file descriptor (PIPE) leak. We close those fds
+  before doing other work."""
+  if platform.system() != "Darwin":
+    return
+  for d in range(3, 1025):
+    try:
+      stat = os.fstat(d)
+      if stat is not None:
+        pipebit = stat[0] & 0x1000
+        if pipebit != 0:
+          os.close(d)
+    except OSError:
+      pass
+
+
 def LoadInfoDict(zip):
   """Read and parse the META/misc_info.txt key/value pairs from the
   input target files and return a dict."""
@@ -345,7 +362,7 @@
   else:
     sign_name = output_name
 
-  cmd = ["java", "-Xmx512m", "-jar",
+  cmd = ["java", "-Xmx2048m", "-jar",
            os.path.join(OPTIONS.search_path, "framework", "signapk.jar")]
   if whole_file:
     cmd.append("-w")
diff --git a/tools/releasetools/edify_generator.py b/tools/releasetools/edify_generator.py
index 893cb45..c2b0056 100644
--- a/tools/releasetools/edify_generator.py
+++ b/tools/releasetools/edify_generator.py
@@ -202,18 +202,6 @@
     cmd = "".join(cmd)
     self.script.append(self._WordWrap(cmd))
 
-  def WriteFirmwareImage(self, kind, fn):
-    """Arrange to update the given firmware image (kind must be
-    "hboot" or "radio") when recovery finishes."""
-    if self.version == 1:
-      self.script.append(
-          ('assert(package_extract_file("%(fn)s", "/tmp/%(kind)s.img"),\n'
-           '       write_firmware_image("/tmp/%(kind)s.img", "%(kind)s"));')
-          % {'kind': kind, 'fn': fn})
-    else:
-      self.script.append(
-          'write_firmware_image("PACKAGE:%s", "%s");' % (fn, kind))
-
   def WriteRawImage(self, mount_point, fn):
     """Write the given package file into the partition for the given
     mount point."""
diff --git a/tools/releasetools/img_from_target_files b/tools/releasetools/img_from_target_files
index 08817ca..c5b9886 100755
--- a/tools/releasetools/img_from_target_files
+++ b/tools/releasetools/img_from_target_files
@@ -201,6 +201,7 @@
 
 if __name__ == '__main__':
   try:
+    common.CloseInheritedPipes()
     main(sys.argv[1:])
   except common.ExternalError, e:
     print
diff --git a/tools/releasetools/ota_from_target_files b/tools/releasetools/ota_from_target_files
index 79c5465..8f5c3fe 100755
--- a/tools/releasetools/ota_from_target_files
+++ b/tools/releasetools/ota_from_target_files
@@ -807,6 +807,7 @@
 
 if __name__ == '__main__':
   try:
+    common.CloseInheritedPipes()
     main(sys.argv[1:])
   except common.ExternalError, e:
     print
diff --git a/tools/releasetools/sign_target_files_apks b/tools/releasetools/sign_target_files_apks
index 5fca691..5353063 100755
--- a/tools/releasetools/sign_target_files_apks
+++ b/tools/releasetools/sign_target_files_apks
@@ -204,6 +204,17 @@
   except KeyError:
     raise ExternalError("can't read META/otakeys.txt from input")
 
+  misc_info = common.LoadInfoDict(input_tf_zip)
+
+  extra_recovery_keys = misc_info.get("extra_recovery_keys", None)
+  if extra_recovery_keys:
+    extra_recovery_keys = [OPTIONS.key_map.get(k, k) + ".x509.pem"
+                           for k in extra_recovery_keys.split()]
+    if extra_recovery_keys:
+      print "extra recovery-only key(s): " + ", ".join(extra_recovery_keys)
+  else:
+    extra_recovery_keys = []
+
   mapped_keys = []
   for k in keylist:
     m = re.match(r"^(.*)\.x509\.pem$", k)
@@ -217,15 +228,18 @@
     print "for OTA package verification"
   else:
     mapped_keys.append(
-        OPTIONS.key_map["build/target/product/security/testkey"] + ".x509.pem")
+        OPTIONS.key_map.get("build/target/product/security/testkey",
+                            "build/target/product/security/testkey")
+        + ".x509.pem")
     print "META/otakeys.txt has no keys; using", mapped_keys[0]
 
   # recovery uses a version of the key that has been slightly
   # predigested (by DumpPublicKey.java) and put in res/keys.
+  # extra_recovery_keys are used only in recovery.
 
   p = common.Run(["java", "-jar",
                   os.path.join(OPTIONS.search_path, "framework", "dumpkey.jar")]
-                 + mapped_keys,
+                 + mapped_keys + extra_recovery_keys,
                  stdout=subprocess.PIPE)
   data, _ = p.communicate()
   if p.returncode != 0:
@@ -234,6 +248,7 @@
 
   # SystemUpdateActivity uses the x509.pem version of the keys, but
   # put into a zipfile system/etc/security/otacerts.zip.
+  # We DO NOT include the extra_recovery_keys (if any) here.
 
   tempfile = cStringIO.StringIO()
   certs_zip = zipfile.ZipFile(tempfile, "w")