Reconcile with ics-mr1-release

Change-Id: I7c50185d28ff8b3818d66b2e232e5e5507fa7902
diff --git a/core/Makefile b/core/Makefile
index a81c981..e136c45 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -342,9 +342,13 @@
 
 BUILT_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk.img
 
+ifeq ($(HAVE_SELINUX),true)
+SELINUX_DEPENDS := sepolicy file_contexts seapp_contexts
+endif
+
 # We just build this directly to the install location.
 INSTALLED_RAMDISK_TARGET := $(BUILT_RAMDISK_TARGET)
-$(INSTALLED_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_RAMDISK_FILES) | $(MINIGZIP)
+$(INSTALLED_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_RAMDISK_FILES) $(SELINUX_DEPENDS) | $(MINIGZIP)
 	$(call pretty,"Target ram disk: $@")
 	$(hide) $(MKBOOTFS) $(TARGET_ROOT_OUT) | $(MINIGZIP) > $@
 
@@ -553,7 +557,7 @@
 # make the target NOTICE files depend on this particular file too, which will
 # then be in the right directory for the find in combine-notice-files to work.
 $(kernel_notice_file): \
-	    prebuilt/$(TARGET_PREBUILT_TAG)/kernel/LINUX_KERNEL_COPYING \
+	    prebuilts/qemu-kernel/arm/LINUX_KERNEL_COPYING \
 	    | $(ACP)
 	@echo Copying: $@
 	$(hide) mkdir -p $(dir $@)
@@ -612,8 +616,11 @@
 # $(5): size of the partition
 define build-userimage-ext-target
   @mkdir -p $(dir $(2))
-  $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
-	  $(MKEXTUSERIMG) $(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG) $(1) $(2) $(4) $(3) $(5)
+  $(if $(filter true, $(strip $(HAVE_SELINUX))), \
+	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
+		$(MKEXTUSERIMG) $(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG) $(1) $(2) $(4) $(3) $(5) $(TARGET_ROOT_OUT)/file_contexts, \
+	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
+		$(MKEXTUSERIMG) $(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG) $(1) $(2) $(4) $(3) $(5))
 endef
 else
 INTERNAL_USERIMAGES_DEPS := $(MKYAFFS2)
@@ -745,7 +752,7 @@
 	$(ALL_GENERATED_SOURCES) \
 	$(ALL_DEFAULT_INSTALLED_MODULES))
 
-FULL_SYSTEMIMAGE_DEPS := $(INTERNAL_SYSTEMIMAGE_FILES) $(INTERNAL_USERIMAGES_DEPS)
+FULL_SYSTEMIMAGE_DEPS := $(INTERNAL_SYSTEMIMAGE_FILES) $(INTERNAL_USERIMAGES_DEPS) $(SELINUX_DEPENDS)
 # -----------------------------------------------------------------
 # installed file list
 # Depending on anything that $(BUILT_SYSTEMIMAGE) depends on.
@@ -787,7 +794,9 @@
 define build-systemimage-target
     @echo "Target system fs image: $(1)"
     @mkdir -p $(dir $(1))
-    $(hide) $(MKYAFFS2) -f $(mkyaffs2_extra_flags) $(TARGET_OUT) $(1)
+    $(if $(filter true, $(strip $(HAVE_SELINUX))), \
+        $(hide) $(MKYAFFS2) -f $(mkyaffs2_extra_flags) $(TARGET_OUT) $(1) $(TARGET_ROOT_OUT)/file_contexts /system, \
+        $(hide) $(MKYAFFS2) -f $(mkyaffs2_extra_flags) $(TARGET_OUT) $(1))
 endef
 endif # INTERNAL_USERIMAGES_USE_EXT
 
@@ -829,6 +838,12 @@
 	$(call build-systemimage-target,$(INSTALLED_SYSTEMIMAGE))
 	$(hide) $(call assert-max-image-size,$(INSTALLED_SYSTEMIMAGE),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE),yaffs)
 
+ifneq (,$(filter systemimage-nodeps snod, $(MAKECMDGOALS)))
+ifeq (true,$(WITH_DEXPREOPT))
+$(warning Warning: with dexpreopt enabled, you may need a full rebuild.)
+endif
+endif
+
 #######
 ## system tarball
 define build-systemtarball-target
@@ -905,7 +920,9 @@
 define build-userdataimage-target
     $(call pretty,"Target userdata fs image: $(INSTALLED_USERDATAIMAGE_TARGET)")
     @mkdir -p $(TARGET_OUT_DATA)
-    $(hide) $(MKYAFFS2) -f $(mkyaffs2_extra_flags) $(TARGET_OUT_DATA) $(INSTALLED_USERDATAIMAGE_TARGET)
+    $(if $(filter true, $(strip $(HAVE_SELINUX))), \
+        $(hide) $(MKYAFFS2) -f $(mkyaffs2_extra_flags) $(TARGET_OUT_DATA) $(INSTALLED_USERDATAIMAGE_TARGET) $(TARGET_ROOT_OUT)/file_contexts /data, \
+        $(hide) $(MKYAFFS2) -f $(mkyaffs2_extra_flags) $(TARGET_OUT_DATA) $(INSTALLED_USERDATAIMAGE_TARGET))
     $(hide) $(call assert-max-image-size,$(INSTALLED_USERDATAIMAGE_TARGET),$(BOARD_USERDATAIMAGE_PARTITION_SIZE),yaffs)
 endef
 endif # INTERNAL_USERIMAGES_USE_EXT
@@ -1147,12 +1164,13 @@
 
 $(INTERNAL_OTA_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
 
-$(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(OTATOOLS)
+$(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(OTATOOLS) $(SELINUX_DEPENDS)
 	@echo "Package OTA: $@"
 	$(hide) ./build/tools/releasetools/ota_from_target_files -v \
+	   $(if $(filter true, $(strip $(HAVE_SELINUX))),-S $(TARGET_ROOT_OUT)/file_contexts) \
 	   -p $(HOST_OUT) \
-           -k $(KEY_CERT_PAIR) \
-           $(BUILT_TARGET_FILES_PACKAGE) $@
+	   -k $(KEY_CERT_PAIR) \
+	   $(BUILT_TARGET_FILES_PACKAGE) $@
 
 .PHONY: otapackage
 otapackage: $(INTERNAL_OTA_PACKAGE_TARGET)
@@ -1175,11 +1193,12 @@
 $(INTERNAL_UPDATE_PACKAGE_TARGET): extensions := $(TARGET_RELEASETOOLS_EXTENSIONS)
 endif
 
-$(INTERNAL_UPDATE_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(OTATOOLS)
+$(INTERNAL_UPDATE_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(OTATOOLS) $(SELINUX_DEPENDS)
 	@echo "Package: $@"
 	$(hide) ./build/tools/releasetools/img_from_target_files -v \
 	   -s $(extensions) \
 	   -p $(HOST_OUT) \
+	   $(if $(filter true, $(strip $(HAVE_SELINUX))),-S $(TARGET_ROOT_OUT)/file_contexts) \
 	   $(BUILT_TARGET_FILES_PACKAGE) $@
 
 .PHONY: updatepackage
@@ -1298,7 +1317,7 @@
 
 INTERNAL_EMULATOR_PACKAGE_FILES += \
         $(HOST_OUT_EXECUTABLES)/emulator$(HOST_EXECUTABLE_SUFFIX) \
-        prebuilt/android-$(TARGET_ARCH)/kernel/kernel-qemu \
+        prebuilts/qemu-kernel/$(TARGET_ARCH)/kernel-qemu \
         $(INSTALLED_RAMDISK_TARGET) \
 		$(INSTALLED_SYSTEMIMAGE) \
 		$(INSTALLED_USERDATAIMAGE_TARGET)
@@ -1369,6 +1388,12 @@
 ifneq (,$(strip $(wildcard sdk/build/tools.$(TARGET_ARCH).atree)))
   sdk_tools_atree_files += sdk/build/tools.$(TARGET_ARCH).atree
 endif
+ifneq (,$(strip $(wildcard sdk/build/tools.$(HOST_OS).atree)))
+  sdk_tools_atree_files += sdk/build/tools.$(HOST_OS).atree
+endif
+ifneq (,$(strip $(wildcard sdk/build/tools.$(HOST_OS)-$(HOST_ARCH).atree)))
+  sdk_tools_atree_files += sdk/build/tools.$(HOST_OS)-$(HOST_ARCH).atree
+endif
 
 sdk_atree_files := \
 	$(atree_dir)/sdk.exclude.atree \
@@ -1431,6 +1456,7 @@
 			-I $(TARGET_COMMON_OUT_ROOT) \
 			-v "PLATFORM_NAME=android-$(PLATFORM_VERSION)" \
 			-v "OUT_DIR=$(OUT_DIR)" \
+			-v "HOST_OUT=$(HOST_OUT)" \
 			-v "TARGET_ARCH=$(TARGET_ARCH)" \
 			-v "TARGET_CPU_ABI=$(TARGET_CPU_ABI)" \
 			-v "DLL_EXTENSION=$(HOST_SHLIB_SUFFIX)" \
diff --git a/core/build_id.mk b/core/build_id.mk
index 77e9923..e954794 100644
--- a/core/build_id.mk
+++ b/core/build_id.mk
@@ -1,4 +1,3 @@
-
 #
 # Copyright (C) 2008 The Android Open Source Project
 #
@@ -14,9 +13,20 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+
+#
+# Defines branch-specific values.
+#
+
 # BUILD_ID is usually used to specify the branch name
 # (like "MAIN") or a branch name and a release candidate
-# (like "CRB01").  It must be a single word, and is
+# (like "TC1-RC5").  It must be a single word, and is
 # capitalized by convention.
+#
+BUILD_ID := OPENMASTER
 
-export BUILD_ID=IMM76K
+# DISPLAY_BUILD_NUMBER should only be set for development branches,
+# If set, the BUILD_NUMBER (cl) is appended to the BUILD_ID for
+# a more descriptive BUILD_ID_DISPLAY, otherwise BUILD_ID_DISPLAY
+# is the same as BUILD_ID
+DISPLAY_BUILD_NUMBER := true
diff --git a/core/combo/HOST_darwin-x86.mk b/core/combo/HOST_darwin-x86.mk
index 544a29e..54a64a3 100644
--- a/core/combo/HOST_darwin-x86.mk
+++ b/core/combo/HOST_darwin-x86.mk
@@ -53,7 +53,12 @@
 
 HOST_GLOBAL_CFLAGS += \
 	-include $(call select-android-config-h,darwin-x86)
-HOST_RUN_RANLIB_AFTER_COPYING := true
+ifneq ($(filter 10.7.%, $(build_mac_version)),)
+       HOST_RUN_RANLIB_AFTER_COPYING := false
+else
+       HOST_RUN_RANLIB_AFTER_COPYING := true
+       PRE_LION_DYNAMIC_LINKER_OPTIONS := -Wl,-dynamic
+endif
 HOST_GLOBAL_ARFLAGS := cqs
 
 HOST_CUSTOM_LD_COMMAND := true
@@ -78,7 +83,7 @@
 define transform-host-o-to-executable-inner
 $(hide) $(PRIVATE_CXX) \
         -o $@ \
-        -Wl,-dynamic -headerpad_max_install_names \
+        $(PRE_LION_DYNAMIC_LINKER_OPTIONS) -headerpad_max_install_names \
         $(HOST_GLOBAL_LD_DIRS) \
         $(HOST_GLOBAL_LDFLAGS) \
         $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
diff --git a/core/combo/HOST_linux-x86.mk b/core/combo/HOST_linux-x86.mk
index 5ae4972..1014f4b 100644
--- a/core/combo/HOST_linux-x86.mk
+++ b/core/combo/HOST_linux-x86.mk
@@ -33,13 +33,13 @@
 # LOCAL_CC and LOCAL_CXX to override this.
 #
 ifeq ($(TARGET_PRODUCT),sdk)
-HOST_SDK_TOOLCHAIN_PREFIX := prebuilt/linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/bin/i686-linux
+HOST_SDK_TOOLCHAIN_PREFIX := prebuilts/tools/gcc-sdk
 # Don't do anything if the toolchain is not there
-ifneq (,$(strip $(wildcard $(HOST_SDK_TOOLCHAIN_PREFIX)-gcc)))
-HOST_CC  := $(HOST_SDK_TOOLCHAIN_PREFIX)-gcc
-HOST_CXX := $(HOST_SDK_TOOLCHAIN_PREFIX)-g++
-HOST_AR  := $(HOST_SDK_TOOLCHAIN_PREFIX)-ar
-endif # $(HOST_SDK_TOOLCHAIN_PREFIX)-gcc exists
+ifneq (,$(strip $(wildcard $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc)))
+HOST_CC  := $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc
+HOST_CXX := $(HOST_SDK_TOOLCHAIN_PREFIX)/g++
+HOST_AR  := $(HOST_SDK_TOOLCHAIN_PREFIX)/ar
+endif # $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc exists
 endif # TARGET_PRODUCT == sdk
 
 # We build everything in 32-bit, because some host tools are
@@ -53,6 +53,6 @@
 	-include $(call select-android-config-h,linux-x86)
 
 # Disable new longjmp in glibc 2.11 and later. See bug 2967937.
-HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
+HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
 
 HOST_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
diff --git a/core/combo/TARGET_linux-arm.mk b/core/combo/TARGET_linux-arm.mk
index 8c89143..77e656b 100644
--- a/core/combo/TARGET_linux-arm.mk
+++ b/core/combo/TARGET_linux-arm.mk
@@ -44,7 +44,7 @@
 # You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
 ifeq ($(strip $(TARGET_TOOLS_PREFIX)),)
 TARGET_TOOLS_PREFIX := \
-	prebuilt/$(HOST_PREBUILT_TAG)/toolchain/arm-linux-androideabi-4.4.x/bin/arm-linux-androideabi-
+	prebuilts/gcc/$(HOST_PREBUILT_TAG)/arm/arm-linux-androideabi-4.6/bin/arm-linux-androideabi-
 endif
 
 # Only define these if there's actually a gcc in there.
@@ -114,11 +114,13 @@
 			-include $(android_config_h) \
 			-I $(arch_include_dir)
 
-# This warning causes dalvik not to build with gcc 4.6 and -Werror.
+# This warning causes dalvik not to build with gcc 4.6.x and -Werror.
 # We cannot turn it off blindly since the option is not available
-# in gcc-4.4.x
-ifneq ($(filter 4.6.0%, $(shell $(TARGET_CC) --version)),)
-TARGET_GLOBAL_CFLAGS += -Wno-unused-but-set-variable
+# in gcc-4.4.x.  We also want to disable sincos optimization globally
+# by turning off the builtin sin function.
+ifneq ($(filter 4.6.%, $(shell $(TARGET_CC) --version)),)
+TARGET_GLOBAL_CFLAGS += -Wno-unused-but-set-variable -fno-builtin-sin \
+			-fno-strict-volatile-bitfields
 endif
 
 # This is to avoid the dreaded warning compiler message:
diff --git a/core/combo/TARGET_linux-x86.mk b/core/combo/TARGET_linux-x86.mk
index 0fb6edc..df5ebee 100644
--- a/core/combo/TARGET_linux-x86.mk
+++ b/core/combo/TARGET_linux-x86.mk
@@ -25,7 +25,7 @@
 # You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
 ifeq ($(strip $(TARGET_TOOLS_PREFIX)),)
 TARGET_TOOLS_PREFIX := \
-	prebuilt/$(HOST_PREBUILT_TAG)/toolchain/i686-android-linux-4.4.3/bin/i686-android-linux-
+	prebuilts/gcc/$(HOST_PREBUILT_TAG)/x86/i686-android-linux-4.4.3/bin/i686-android-linux-
 endif
 
 TARGET_CC := $(TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)
@@ -96,8 +96,25 @@
 			-fno-use-cxa-atexit
 
 ifeq ($(TARGET_ARCH_VARIANT),x86-atom)
-    TARGET_GLOBAL_CFLAGS += -march=atom -mstackrealign -DUSE_SSSE3 -DUSE_SSE2 -mfpmath=sse
+    # Basic ATOM flags.
+    TARGET_GLOBAL_CFLAGS += -march=atom -mstackrealign -mfpmath=sse
+
+    # There are various levels of ATOM processors out there. Different ones have different
+    # capabilities. This first define matches the NDK's minimum ABI requirements.
+    # Note: Not all of the flags set here are actually used in Android. They are provided
+    # to allow for the addition of corresponding optimizations.
+    TARGET_GLOBAL_CFLAGS += -DUSE_MMX -DUSE_SSE -DUSE_SSE2 -DUSE_SSE3
+
+    # If you wish to build a BSP that will only be used on hardware that has additional
+    # available instructions, enable them here. By default, this is commented off so that
+    # the default images can run on all processors that are NDK ABI compliant.
+    # TARGET_GLOBAL_CFLAGS += -DUSE_SSSE3
 else
+    # Plain 'x86' - lowest common denominator. This should run pretty much on any hardware.
+    #
+    # Note: The NDK's ABI (see the NDK ABI documentation) requires many of the more recent
+    # instruction set additions. You can build an "x86" BSP that will run on very old hardware,
+    # but it won't be able to run much of the x86 NDK compliant code.
     TARGET_GLOBAL_CFLAGS += -march=i686
 endif
 
diff --git a/core/definitions.mk b/core/definitions.mk
index 683ae16..b678158 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -691,7 +691,7 @@
 endef
 
 define get-package-overrides
-$(strip $(sort $(call _get-package-overrides,$(1))))
+$(sort $(strip $(call _get-package-overrides,$(1))))
 endef
 
 ###########################################################
@@ -890,7 +890,7 @@
 	$(PRIVATE_CFLAGS) \
 	$(PRIVATE_CPPFLAGS) \
 	$(PRIVATE_DEBUG_CFLAGS) \
-	-MD -o $@ $<
+	-MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
 $(transform-d-to-p)
 endef
 
@@ -917,7 +917,7 @@
 	$(PRIVATE_CFLAGS) \
 	$(1) \
 	$(PRIVATE_DEBUG_CFLAGS) \
-	-MD -o $@ $<
+	-MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
 endef
 
 define transform-c-to-o-no-deps
@@ -978,7 +978,7 @@
 	$(PRIVATE_CFLAGS) \
 	$(PRIVATE_CPPFLAGS) \
 	$(PRIVATE_DEBUG_CFLAGS) \
-	-MD -o $@ $<
+	-MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
 $(transform-d-to-p)
 endef
 
@@ -1004,7 +1004,7 @@
 	$(PRIVATE_CFLAGS) \
 	$(1) \
 	$(PRIVATE_DEBUG_CFLAGS) \
-	-MD -o $@ $<
+	-MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
 endef
 
 define transform-host-c-to-o-no-deps
@@ -1292,13 +1292,6 @@
 ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
 define transform-host-o-to-executable-inner
 $(hide) $(PRIVATE_CXX) \
-	-Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \
-	-Wl,-rpath,\$$ORIGIN/../lib \
-	$(HOST_GLOBAL_LD_DIRS) \
-	$(PRIVATE_LDFLAGS) \
-	$(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
-		$(HOST_GLOBAL_LDFLAGS) \
-	) \
 	$(PRIVATE_ALL_OBJECTS) \
 	-Wl,--whole-archive \
 	$(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
@@ -1307,6 +1300,13 @@
 	$(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
 	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
 	$(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
+	-Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \
+	-Wl,-rpath,\$$ORIGIN/../lib \
+	$(HOST_GLOBAL_LD_DIRS) \
+	$(PRIVATE_LDFLAGS) \
+	$(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
+		$(HOST_GLOBAL_LDFLAGS) \
+	) \
 	-o $@ \
 	$(PRIVATE_LDLIBS)
 endef
@@ -1525,7 +1525,7 @@
 @echo "target Dex: $(PRIVATE_MODULE)"
 @mkdir -p $(dir $@)
 $(hide) $(DX) \
-    $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx1536M) \
+    $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx2048M) \
     --dex --output=$@ \
     $(incremental_dex) \
     $(if $(NO_OPTIMIZE_DX), \
diff --git a/core/dumpvar.mk b/core/dumpvar.mk
index e0de464..7929dbb 100644
--- a/core/dumpvar.mk
+++ b/core/dumpvar.mk
@@ -3,15 +3,20 @@
 # what to add to the path given the config we have chosen.
 ifeq ($(CALLED_FROM_SETUP),true)
 
+ifneq ($(filter /%,$(HOST_OUT_EXECUTABLES)),)
+ABP:=$(HOST_OUT_EXECUTABLES)
+else
 ABP:=$(PWD)/$(HOST_OUT_EXECUTABLES)
+endif
 
 # Add the toolchain bin dir if it actually exists
-ifneq ($(wildcard $(PWD)/prebuilt/$(HOST_PREBUILT_TAG)/toolchain/arm-linux-androideabi-4.4.x/bin),)
+ifneq ($(wildcard $(PWD)/prebuilts/gcc/$(HOST_PREBUILT_TAG)/arm/arm-linux-androideabi-4.6/bin),)
 	# this should be copied to HOST_OUT_EXECUTABLES instead
-	ABP:=$(ABP):$(PWD)/prebuilt/$(HOST_PREBUILT_TAG)/toolchain/arm-linux-androideabi-4.4.x/bin
+	ABP:=$(ABP):$(PWD)/prebuilts/gcc/$(HOST_PREBUILT_TAG)/arm/arm-linux-androideabi-4.6/bin
 endif
 ANDROID_BUILD_PATHS := $(ABP)
 ANDROID_PREBUILTS := prebuilt/$(HOST_PREBUILT_TAG)
+ANDROID_GCC_PREBUILTS := prebuilts/gcc/$(HOST_PREBUILT_TAG)
 
 # The "dumpvar" stuff lets you say something like
 #
@@ -38,7 +43,11 @@
   absolute_dumpvar := $(strip $(filter abs-%,$(dumpvar_goals)))
   ifdef absolute_dumpvar
     dumpvar_goals := $(patsubst abs-%,%,$(dumpvar_goals))
-    DUMPVAR_VALUE := $(PWD)/$($(dumpvar_goals))
+    ifneq ($(filter /%,$($(dumpvar_goals))),)
+      DUMPVAR_VALUE := $($(dumpvar_goals))
+    else
+      DUMPVAR_VALUE := $(PWD)/$($(dumpvar_goals))
+    endif
     dumpvar_target := dumpvar-abs-$(dumpvar_goals)
   else
     DUMPVAR_VALUE := $($(dumpvar_goals))
@@ -59,6 +68,7 @@
 
 
 ifneq ($(PRINT_BUILD_CONFIG),)
+HOST_OS_EXTRA:=$(shell python -c "import platform; print(platform.platform())")
 $(info ============================================)
 $(info   PLATFORM_VERSION_CODENAME=$(PLATFORM_VERSION_CODENAME))
 $(info   PLATFORM_VERSION=$(PLATFORM_VERSION))
@@ -70,7 +80,9 @@
 $(info   TARGET_ARCH_VARIANT=$(TARGET_ARCH_VARIANT))
 $(info   HOST_ARCH=$(HOST_ARCH))
 $(info   HOST_OS=$(HOST_OS))
+$(info   HOST_OS_EXTRA=$(HOST_OS_EXTRA))
 $(info   HOST_BUILD_TYPE=$(HOST_BUILD_TYPE))
 $(info   BUILD_ID=$(BUILD_ID))
+$(info   OUT_DIR=$(OUT_DIR))
 $(info ============================================)
 endif
diff --git a/core/envsetup.mk b/core/envsetup.mk
index c3ae3b0..e8c924e 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -133,7 +133,11 @@
 # figure out the output directories
 
 ifeq (,$(strip $(OUT_DIR)))
+ifeq (,$(strip $(OUT_DIR_COMMON_BASE)))
 OUT_DIR := $(TOPDIR)out
+else
+OUT_DIR := $(OUT_DIR_COMMON_BASE)/$(notdir $(PWD))
+endif
 endif
 
 DEBUG_OUT_DIR := $(OUT_DIR)/debug
diff --git a/core/find-jdk-tools-jar.sh b/core/find-jdk-tools-jar.sh
index e1278c3..f150a9a 100755
--- a/core/find-jdk-tools-jar.sh
+++ b/core/find-jdk-tools-jar.sh
@@ -1,3 +1,4 @@
+#!/bin/sh
 if [ "x$ANDROID_JAVA_HOME" != x ] && [ -e "$ANDROID_JAVA_HOME/lib/tools.jar" ] ; then
     echo $ANDROID_JAVA_HOME/lib/tools.jar
 else
diff --git a/core/java_library.mk b/core/java_library.mk
index fa40c0e..c210be6 100644
--- a/core/java_library.mk
+++ b/core/java_library.mk
@@ -90,6 +90,7 @@
 $(built_odex) : $(common_javalib.jar) | $(DEXPREOPT) $(DEXOPT)
 	@echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)"
 	$(hide) rm -f $@
+	@mkdir -p $(dir $@)
 	$(call dexpreopt-one-file,$<,$@)
 
 $(LOCAL_BUILT_MODULE) : $(common_javalib.jar) | $(ACP) $(AAPT)
diff --git a/core/main.mk b/core/main.mk
index 569d4dc..3d8d6e0 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -37,15 +37,20 @@
 #TOPDIR := $(TOP)/
 #endif
 
-# check for broken versions of make
+# Check for broken versions of make.
+# (Allow any version under Cygwin since we don't actually build the platform there.)
+ifeq (,$(findstring CYGWIN,$(shell uname -sm)))
 ifeq (0,$(shell expr $$(echo $(MAKE_VERSION) | sed "s/[^0-9\.].*//") = 3.81))
+ifeq (0,$(shell expr $$(echo $(MAKE_VERSION) | sed "s/[^0-9\.].*//") = 3.82))
 $(warning ********************************************************************************)
 $(warning *  You are using version $(MAKE_VERSION) of make.)
-$(warning *  Android can only be built by version 3.81.)
+$(warning *  Android can only be built by versions 3.81 and 3.82.)
 $(warning *  see http://source.android.com/source/download.html)
 $(warning ********************************************************************************)
 $(error stopping)
 endif
+endif
+endif
 
 TOP := .
 TOPDIR :=
@@ -271,11 +276,13 @@
 
 ifeq ($(TARGET_BUILD_VARIANT),eng)
 tags_to_install := user debug eng
+ifneq ($(filter ro.setupwizard.mode=ENABLED, $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))),)
   # Don't require the setup wizard on eng builds
   ADDITIONAL_BUILD_PROPERTIES := $(filter-out ro.setupwizard.mode=%,\
           $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))) \
           ro.setupwizard.mode=OPTIONAL
 endif
+endif
 
 ## tests ##
 
@@ -387,74 +394,8 @@
 endif
 
 ifeq ($(SDK_ONLY),true)
-
-# ----- SDK for Windows ------
-# These configure the build targets that are available for the SDK under Windows.
-# The first section defines all the C/C++ tools that can be compiled in C/C++,
-# the second section defines all the Java ones (assuming javac is available.)
-
-subdirs := \
-	prebuilt \
-	build/libs/host \
-	build/tools/zipalign \
-	dalvik/dexdump \
-	dalvik/libdex \
-	dalvik/tools/dmtracedump \
-	dalvik/tools/hprof-conv \
-	development/host \
-	development/tools/etc1tool \
-	development/tools/line_endings \
-	development/tools/emulator/opengl \
-	external/clang \
-	external/easymock \
-	external/expat \
-	external/libpng \
-	external/llvm \
-	external/qemu \
-	external/sqlite/dist \
-	external/zlib \
-	frameworks/base \
-	frameworks/compile \
-	sdk/avdlauncher \
-	sdk/emulator/mksdcard \
-	sdk/sdklauncher \
-	system/core/adb \
-	system/core/fastboot \
-	system/core/libcutils \
-	system/core/liblog \
-	system/core/libzipfile
-
-# The following can only be built if "javac" is available.
-# This check is used when building parts of the SDK under Cygwin.
-ifneq (,$(shell which javac 2>/dev/null))
-subdirs += \
-	build/tools/signapk \
-	dalvik/dx \
-	libcore \
-	sdk/archquery \
-	sdk/androidprefs \
-	sdk/apkbuilder \
-	sdk/assetstudio \
-	sdk/common \
-	sdk/ddms \
-	sdk/hierarchyviewer2 \
-	sdk/ide_common \
-	sdk/jarutils \
-	sdk/layoutlib_api \
-	sdk/layoutopt \
-	sdk/ninepatch \
-	sdk/rule_api \
-	sdk/lint \
-	sdk/sdkstats \
-	sdk/sdkmanager \
-	sdk/swtmenubar \
-	sdk/traceview \
-	development/apps \
-	development/tools/mkstubs \
-	packages
-else
-$(warning SDK_ONLY: javac not available.)
-endif
+include $(TOPDIR)sdk/build/sdk_only_whitelist.mk
+include $(TOPDIR)development/build/sdk_only_whitelist.mk
 
 # Exclude tools/acp when cross-compiling windows under linux
 ifeq ($(findstring Linux,$(UNAME)),)
diff --git a/core/pathmap.mk b/core/pathmap.mk
index 60fbfd2..6b84418 100644
--- a/core/pathmap.mk
+++ b/core/pathmap.mk
@@ -49,6 +49,8 @@
     mkbootimg:system/core/mkbootimg \
     recovery:bootable/recovery \
     system-core:system/core/include \
+    wilhelm:system/media/wilhelm/include \
+    wilhelm-ut:system/media/wilhelm/src/ut \
     speex:external/speex/include
 
 #
diff --git a/core/user_tags.mk b/core/user_tags.mk
index 2e7017e..b88e541 100644
--- a/core/user_tags.mk
+++ b/core/user_tags.mk
@@ -171,7 +171,6 @@
 	layoutlib_api \
 	layoutlib_create \
 	layoutlib_utils \
-	layoutopt \
 	liba2dp \
 	libabi \
 	libandroid \
@@ -494,7 +493,6 @@
 	traceview \
 	tune2fs \
 	tune2fs_host \
-	uix \
 	usbtest \
 	vdc \
 	vm-tests \
diff --git a/core/version_defaults.mk b/core/version_defaults.mk
index bff8ef9..274a15a 100644
--- a/core/version_defaults.mk
+++ b/core/version_defaults.mk
@@ -41,7 +41,7 @@
   # which is the version that we reveal to the end user.
   # Update this value when the platform version changes (rather
   # than overriding it somewhere else).  Can be an arbitrary string.
-  PLATFORM_VERSION := 4.0.4
+  PLATFORM_VERSION := 4.0.4.0.4.0.4
 endif
 
 ifeq "" "$(PLATFORM_SDK_VERSION)"
@@ -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 := REL
+  PLATFORM_VERSION_CODENAME := AOSP
 endif
 
 ifeq "" "$(DEFAULT_APP_TARGET_SDK)"
diff --git a/envsetup.sh b/envsetup.sh
index bab2d25..609e1af 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -112,10 +112,16 @@
     # and in with the new
     CODE_REVIEWS=
     prebuiltdir=$(getprebuilt)
+    gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
 
     # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
     export ANDROID_EABI_TOOLCHAIN=
-    toolchaindir=toolchain/arm-linux-androideabi-4.4.x/bin
+    case $(get_build_var TARGET_ARCH) in
+        x86) toolchaindir=x86/i686-android-linux-4.4.3/bin
+            ;;
+        arm|*) toolchaindir=arm/arm-linux-androideabi-4.6/bin
+            ;;
+    esac
     if [ -d "$prebuiltdir/$toolchaindir" ]; then
         export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/$toolchaindir
     fi
@@ -744,7 +750,7 @@
        echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
        echo >>"$OUT_ROOT/gdbclient.cmds" ""
 
-       arm-linux-androideabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
+       $ANDROID_EABI_TOOLCHAIN/*-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
   else
        echo "Unable to determine build system output dir."
    fi
diff --git a/target/board/generic_x86/device.mk b/target/board/generic_x86/device.mk
index 0dd2bc0..fdd74bd 100644
--- a/target/board/generic_x86/device.mk
+++ b/target/board/generic_x86/device.mk
@@ -25,4 +25,7 @@
 PRODUCT_COPY_FILES := \
     development/data/etc/apns-conf.xml:system/etc/apns-conf.xml \
     development/data/etc/vold.conf:system/etc/vold.conf \
-    development/tools/emulator/system/camera/media_profiles.xml:system/etc/media_profiles.xml \
+    development/tools/emulator/system/camera/media_profiles.xml:system/etc/media_profiles.xml
+
+PRODUCT_PACKAGES := \
+    audio.primary.goldfish
diff --git a/target/board/vbox_x86/device.mk b/target/board/vbox_x86/device.mk
index 66a6e84..07ebb1c 100644
--- a/target/board/vbox_x86/device.mk
+++ b/target/board/vbox_x86/device.mk
@@ -24,7 +24,7 @@
     ro.ril.gprsclass=10 \
     ro.adb.qemud=1
 
-LOCAL_KERNEL := prebuilt/android-x86/kernel/kernel-vbox
+LOCAL_KERNEL := prebuilts/qemu-kernel/x86/kernel-vbox
 
 PRODUCT_COPY_FILES := \
     development/data/etc/apns-conf.xml:system/etc/apns-conf.xml \
diff --git a/target/product/generic_no_telephony.mk b/target/product/generic_no_telephony.mk
index 0d87fc3..dbdc500 100644
--- a/target/product/generic_no_telephony.mk
+++ b/target/product/generic_no_telephony.mk
@@ -21,7 +21,6 @@
 
 PRODUCT_PACKAGES := \
     DeskClock \
-    AlarmProvider \
     Bluetooth \
     Calculator \
     Calendar \
diff --git a/target/product/large_emu_hw.mk b/target/product/large_emu_hw.mk
index 15b1bed..847e10a 100644
--- a/target/product/large_emu_hw.mk
+++ b/target/product/large_emu_hw.mk
@@ -22,7 +22,6 @@
 PRODUCT_PACKAGES := \
     CarHome \
     DeskClock \
-    AlarmProvider \
     Bluetooth \
     Calculator \
     Calendar \
diff --git a/target/product/locales_full.mk b/target/product/locales_full.mk
index 1031303..8b8ab05 100644
--- a/target/product/locales_full.mk
+++ b/target/product/locales_full.mk
@@ -1,3 +1,3 @@
-PRODUCT_LOCALES := cs_CZ da_DK de_AT de_CH de_DE de_LI el_GR en_AU en_CA en_GB en_NZ en_SG en_US es_ES fr_CA fr_CH fr_BE fr_FR it_CH it_IT ja_JP ko_KR nb_NO nl_BE nl_NL pl_PL pt_PT ru_RU sv_SE tr_TR zh_CN zh_HK zh_TW am_ET hi_IN
+PRODUCT_LOCALES := en_US cs_CZ da_DK de_AT de_CH de_DE de_LI el_GR en_AU en_CA en_GB en_NZ en_SG es_ES fr_CA fr_CH fr_BE fr_FR it_CH it_IT ja_JP ko_KR nb_NO nl_BE nl_NL pl_PL pt_PT ru_RU sv_SE tr_TR zh_CN zh_HK zh_TW am_ET hi_IN
 
 $(call inherit-product, build/target/product/languages_full.mk)
diff --git a/target/product/sdk.mk b/target/product/sdk.mk
index 1a71bf1..a60a77a 100644
--- a/target/product/sdk.mk
+++ b/target/product/sdk.mk
@@ -77,7 +77,6 @@
 	ddms \
 	hierarchyviewer \
 	draw9patch \
-	layoutopt \
 	traceview \
 	android \
 	dexdump \
@@ -88,6 +87,7 @@
 # See development/build/sdk.atree
 PRODUCT_PACKAGES += \
 	androidprefs \
+	annotations \
 	sdkstats \
 	archquery \
 	ddms \
@@ -95,8 +95,6 @@
 	ddmuilib \
 	draw9patch \
 	hierarchyviewer \
-	layoutopt \
-	uix \
 	traceview \
 	anttasks \
 	sdklib \
diff --git a/tools/adbs b/tools/adbs
index b571d48..961169b 100755
--- a/tools/adbs
+++ b/tools/adbs
@@ -144,13 +144,13 @@
       uname = "darwin-ppc"
   elif uname == "Linux":
     uname = "linux-x86"
-  prefix = "./prebuilt/" + uname + "/toolchain/arm-linux-androideabi-4.4.x/bin/"
+  prefix = "./prebuilts/gcc/" + uname + "/arm/arm-linux-androideabi-4.6/bin/"
   addr2line_cmd = prefix + "arm-linux-androideabi-addr2line"
 
   if (not os.path.exists(addr2line_cmd)):
     try:
-      prefix = os.environ['ANDROID_BUILD_TOP'] + "/prebuilt/" + uname + \
-               "/toolchain/arm-linux-androideabi-4.4.x/bin/"
+      prefix = os.environ['ANDROID_BUILD_TOP'] + "/prebuilts/gcc/" + uname + \
+               "/arm/arm-linux-androideabi-4.6/bin/"
     except:
       prefix = "";
 
diff --git a/tools/droiddoc/templates-sdk/assets/android-developer-docs.css b/tools/droiddoc/templates-sdk/assets/android-developer-docs.css
index 6cc4a97..b8b9c71 100644
--- a/tools/droiddoc/templates-sdk/assets/android-developer-docs.css
+++ b/tools/droiddoc/templates-sdk/assets/android-developer-docs.css
@@ -68,7 +68,6 @@
 #side-nav li {
   padding:0;
   padding:1px 0 1px 0;
-  white-space:nowrap;
   zoom:1;
 }
 
@@ -85,7 +84,6 @@
   display: inline-block; /* needed to apply padding to line-wraps */
   text-decoration:none;
   padding: 0 0 0 18px;
-  white-space:normal;
   zoom:1;
 }
 
@@ -579,7 +577,7 @@
 
 #jd-content li img,
 #jd-content dd img {
-  margin:.5em 0 0 1em;
+  margin:.5em 0 .5em 1em;
 }
 
 .nolist {
@@ -713,7 +711,7 @@
   border-bottom:1px solid #33B5E5;
   padding:5px 10px 10px 55px;
   margin:2em 0;
-  background:url('../design/static/ico_styleguide.png') 5px 13px no-repeat;
+  background:url('images/icon_design.png') 5px 13px no-repeat;
 }
 
 div.design-announce p {
@@ -844,6 +842,7 @@
   text-decoration: none;
   vertical-align:top;
   line-height:.9em;
+  white-space:nowrap;
 }
 
 .toggle-list.open .new-child {
diff --git a/tools/droiddoc/templates-sdk/assets/android-developer-docs.js b/tools/droiddoc/templates-sdk/assets/android-developer-docs.js
index c88f726..5fc7e09 100644
--- a/tools/droiddoc/templates-sdk/assets/android-developer-docs.js
+++ b/tools/droiddoc/templates-sdk/assets/android-developer-docs.js
@@ -372,6 +372,7 @@
   if (sidenav.length) { // Must check if the nav exists because IE6 calls resizeWidth() from resizeAll() for all pages
     var basePath = getBaseUri(location.pathname);
     var section = basePath.substring(1,basePath.indexOf("/",1));
+    section = section.indexOf("training") != -1 ? "resources" : section;
     writeCookie("width", sidenavWidth, section, null);
   }
 }
diff --git a/tools/droiddoc/templates-sdk/assets/design/default.css b/tools/droiddoc/templates-sdk/assets/design/default.css
index 5000ce8..c568424 100644
--- a/tools/droiddoc/templates-sdk/assets/design/default.css
+++ b/tools/droiddoc/templates-sdk/assets/design/default.css
@@ -18,8 +18,8 @@
   background-image: -moz-linear-gradient(top, #dddddd, #f2f2f2, #f2f2f2, #dddddd);
   -webkit-font-smoothing: antialiased;
   /* prevent subpixel antialiasing, which thickens the text */
-  text-rendering: optimizeLegibility;
-  /* opentype ftw */ }
+  /* text-rendering: optimizeLegibility; */
+  /* turned off ligatures due to bug 5945455 */ }
 
 body {
   color: #555555;
@@ -552,7 +552,7 @@
 
 /* video  containers */
 .framed-galaxynexus-land-span-13 {
-  background: transparent url(content/misc_full_galaxynexus_blank_land_span13.png) no-repeat scroll top left;
+  background: transparent url(device_galaxynexus_blank_land_span13.png) no-repeat scroll top left;
   padding: 42px 122px 62px 126px;
   overflow: hidden; }
   .framed-galaxynexus-land-span-13, .framed-galaxynexus-land-span-13 video, .framed-galaxynexus-land-span-13 img {
@@ -560,7 +560,7 @@
     height: 286px; }
 
 .framed-galaxynexus-port-span-9 {
-  background: transparent url(content/misc_full_galaxynexus_blank_port_span9.png) no-repeat scroll top left;
+  background: transparent url(device_galaxynexus_blank_port_span9.png) no-repeat scroll top left;
   padding: 95px 122px 107px 124px;
   overflow: hidden; }
   .framed-galaxynexus-port-span-9, .framed-galaxynexus-port-span-9 video, .framed-galaxynexus-port-span-9 img {
@@ -568,7 +568,7 @@
     height: 488px; }
 
 .framed-galaxynexus-port-span-5 {
-  background: transparent url(content/misc_full_galaxynexus_blank_port_span5.png) no-repeat scroll top left;
+  background: transparent url(device_galaxynexus_blank_port_span5.png) no-repeat scroll top left;
   padding: 75px 31px 76px 33px;
   overflow: hidden; }
   .framed-galaxynexus-port-span-5, .framed-galaxynexus-port-span-5 video, .framed-galaxynexus-port-span-5 img {
@@ -639,3 +639,38 @@
     color: #fff !important; }
   .download-button:active {
     background-color: #006699; }
+
+/* UI tables and other things found in Writing style and Settings pattern */
+.ui-table {
+  width: 100%;
+  background: #282828;
+  color: #fff;
+  border-radius: 2px;
+  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
+  border-collapse: separate; }
+  .ui-table th,
+  .ui-table td {
+    padding: 5px 10px; }
+  .ui-table thead th {
+    font-weight: 600; }
+  .ui-table tfoot td {
+    border-top: 1px solid #494949;
+    border-right: 1px solid #494949;
+    text-align: center; }
+    .ui-table tfoot td:last-child {
+      border-right: 0; }
+
+.layout-with-list-item-margins {
+  margin-left: 30px !important; }
+
+.emulate-content-left-padding {
+  margin-left: 10px; }
+
+.do-dont-label {
+  margin-bottom: 10px;
+  padding-left: 20px;
+  background: transparent none no-repeat scroll 0px 3px; }
+  .do-dont-label.bad {
+    background-image: url(ico_wrong.png); }
+  .do-dont-label.good {
+    background-image: url(ico_good.png); }
diff --git a/tools/droiddoc/templates-sdk/assets/design/default.scss b/tools/droiddoc/templates-sdk/assets/design/default.scss
index 536ee16..d874ee5 100644
--- a/tools/droiddoc/templates-sdk/assets/design/default.scss
+++ b/tools/droiddoc/templates-sdk/assets/design/default.scss
@@ -79,7 +79,7 @@
   background-image: -webkit-gradient(linear, 100% 0%, 100% 100%, from(#ddd), color-stop(25%, #f2f2f2), color-stop(75%, #f2f2f2), to(#ddd));
   background-image: -moz-linear-gradient(top, #ddd, #f2f2f2, #f2f2f2, #ddd);
   -webkit-font-smoothing: antialiased; /* prevent subpixel antialiasing, which thickens the text */
-  text-rendering: optimizeLegibility; /* opentype ftw */
+  /* text-rendering: optimizeLegibility; */ /* turned off ligatures due to bug 5945455 */
 }
 
 body {
@@ -617,7 +617,7 @@
 /* video  containers */
 
 .framed-galaxynexus-land-span-13 {
-  background: transparent url(content/misc_full_galaxynexus_blank_land_span13.png) no-repeat scroll top left;
+  background: transparent url(device_galaxynexus_blank_land_span13.png) no-repeat scroll top left;
   padding: 42px 122px 62px 126px;
   overflow: hidden;
 
@@ -630,7 +630,7 @@
 }
 
 .framed-galaxynexus-port-span-9 {
-  background: transparent url(content/misc_full_galaxynexus_blank_port_span9.png) no-repeat scroll top left;
+  background: transparent url(device_galaxynexus_blank_port_span9.png) no-repeat scroll top left;
   padding: 95px 122px 107px 124px;
   overflow: hidden;
 
@@ -643,7 +643,7 @@
 }
 
 .framed-galaxynexus-port-span-5 {
-  background: transparent url(content/misc_full_galaxynexus_blank_port_span5.png) no-repeat scroll top left;
+  background: transparent url(device_galaxynexus_blank_port_span5.png) no-repeat scroll top left;
   padding: 75px 31px 76px 33px;
   overflow: hidden;
 
@@ -737,4 +737,56 @@
   &:active {
     background-color: $ics_blue_darkest;
   }
+}
+
+/* UI tables and other things found in Writing style and Settings pattern */
+
+.ui-table {
+  width: 100%;
+  background: #282828;
+  color: #fff;
+  border-radius: 2px;
+  box-shadow: 0 2px 4px rgba(0,0,0,0.25);
+  border-collapse: separate;
+
+  th,
+  td {
+    padding: 5px 10px;
+  }
+
+  thead th {
+    font-weight: 600;
+  }
+
+  tfoot td {
+    border-top: 1px solid #494949;
+    border-right: 1px solid #494949;
+    text-align: center;
+
+    &:last-child {
+      border-right: 0;
+    }
+  }
+}
+
+.layout-with-list-item-margins {
+  margin-left: 30px !important;
+}
+
+.emulate-content-left-padding {
+  margin-left: 10px;
+}
+
+.do-dont-label {
+  margin-bottom: 10px;
+  padding-left: 20px;
+  background: transparent none no-repeat scroll 0px 3px;
+
+  &.bad {
+    background-image: url(ico_wrong.png);
+  }
+
+  &.good {
+    background-image: url(ico_good.png);
+  }
 }
\ No newline at end of file
diff --git a/tools/droiddoc/templates-sdk/assets/design/device_galaxynexus_blank_land_span13.png b/tools/droiddoc/templates-sdk/assets/design/device_galaxynexus_blank_land_span13.png
new file mode 100644
index 0000000..bab6aca
--- /dev/null
+++ b/tools/droiddoc/templates-sdk/assets/design/device_galaxynexus_blank_land_span13.png
Binary files differ
diff --git a/tools/droiddoc/templates-sdk/assets/design/device_galaxynexus_blank_port_span5.png b/tools/droiddoc/templates-sdk/assets/design/device_galaxynexus_blank_port_span5.png
new file mode 100644
index 0000000..bdccc2f
--- /dev/null
+++ b/tools/droiddoc/templates-sdk/assets/design/device_galaxynexus_blank_port_span5.png
Binary files differ
diff --git a/tools/droiddoc/templates-sdk/assets/design/device_galaxynexus_blank_port_span9.png b/tools/droiddoc/templates-sdk/assets/design/device_galaxynexus_blank_port_span9.png
new file mode 100644
index 0000000..5e0135b
--- /dev/null
+++ b/tools/droiddoc/templates-sdk/assets/design/device_galaxynexus_blank_port_span9.png
Binary files differ
diff --git a/tools/droiddoc/templates-sdk/assets/images/icon_design.png b/tools/droiddoc/templates-sdk/assets/images/icon_design.png
new file mode 100644
index 0000000..c12907c
--- /dev/null
+++ b/tools/droiddoc/templates-sdk/assets/images/icon_design.png
Binary files differ
diff --git a/tools/droiddoc/templates-sdk/customizations.cs b/tools/droiddoc/templates-sdk/customizations.cs
index 41559be..3b5f3eb 100644
--- a/tools/droiddoc/templates-sdk/customizations.cs
+++ b/tools/droiddoc/templates-sdk/customizations.cs
@@ -9,7 +9,7 @@
 <?cs /def ?>
 <?cs 
 def:resources_tab_nav() ?>
-  <div class="g-section g-tpl-200" id="body-content">
+  <div class="g-section g-tpl-240" id="body-content">
     <div class="g-unit g-first" id="side-nav" itemscope itemtype="http://schema.org/SiteNavigationElement">
       <div id="devdoc-nav"><?cs 
         include:"../../../../frameworks/base/docs/html/resources/resources_toc.cs" ?>
diff --git a/tools/releasetools/edify_generator.py b/tools/releasetools/edify_generator.py
index d7b924b..12bb48b 100644
--- a/tools/releasetools/edify_generator.py
+++ b/tools/releasetools/edify_generator.py
@@ -165,9 +165,9 @@
     fstab = self.info.get("fstab", None)
     if fstab:
       p = fstab[partition]
-      self.script.append('format("%s", "%s", "%s", "%s");' %
+      self.script.append('format("%s", "%s", "%s", "%s", "%s");' %
                          (p.fs_type, common.PARTITION_TYPES[p.fs_type],
-                          p.device, p.length))
+                          p.device, p.length, p.mount_point))
 
   def DeleteFiles(self, file_list):
     """Delete all files in file_list."""
diff --git a/tools/releasetools/img_from_target_files b/tools/releasetools/img_from_target_files
index c5b9886..ad03398 100755
--- a/tools/releasetools/img_from_target_files
+++ b/tools/releasetools/img_from_target_files
@@ -27,6 +27,10 @@
       Include only the bootable images (eg 'boot' and 'recovery') in
       the output.
 
+  -S  (--file_context) <file>
+      the file contexts configuration used to assign SELinux file
+      context attributes.
+
 """
 
 import sys
@@ -50,6 +54,7 @@
 import common
 
 OPTIONS = common.OPTIONS
+OPTIONS.selinux_fc = None
 
 def AddUserdata(output_zip):
   """Create an empty userdata image and store it in output_zip."""
@@ -74,6 +79,8 @@
                      fstab["/data"].fs_type, "data"])
     if "userdata_size" in OPTIONS.info_dict:
       build_command.append(str(OPTIONS.info_dict["userdata_size"]))
+    if OPTIONS.selinux_fc is not None:
+      build_command.append(OPTIONS.selinux_fc)
   else:
     build_command = ["mkyaffs2image", "-f"]
     extra = OPTIONS.info_dict.get("mkyaffs2_extra_flags", None)
@@ -81,6 +88,9 @@
       build_command.extend(extra.split())
     build_command.append(user_dir)
     build_command.append(img.name)
+    if OPTIONS.selinux_fc is not None:
+      build_command.append(OPTIONS.selinux_fc)
+      build_command.append("/data")
 
   p = common.Run(build_command);
   p.communicate()
@@ -126,6 +136,8 @@
                      fstab["/system"].fs_type, "system"])
     if "system_size" in OPTIONS.info_dict:
       build_command.append(str(OPTIONS.info_dict["system_size"]))
+    if OPTIONS.selinux_fc is not None:
+      build_command.append(OPTIONS.selinux_fc)
   else:
     build_command = ["mkyaffs2image", "-f"]
     extra = OPTIONS.info_dict.get("mkyaffs2_extra_flags", None)
@@ -133,6 +145,9 @@
       build_command.extend(extra.split())
     build_command.append(os.path.join(OPTIONS.input_tmp, "system"))
     build_command.append(img.name)
+    if OPTIONS.selinux_fc is not None:
+      build_command.append(OPTIONS.selinux_fc)
+      build_command.append("/system")
 
   p = common.Run(build_command)
   p.communicate()
@@ -160,14 +175,17 @@
       pass       # deprecated
     if o in ("-z", "--bootable_zip"):
       bootable_only[0] = True
+    if o in ("-S", "--file_context"):
+      OPTIONS.selinux_fc = a
     else:
       return False
     return True
 
   args = common.ParseOptions(argv, __doc__,
-                             extra_opts="b:z",
+                             extra_opts="b:zS:",
                              extra_long_opts=["board_config=",
-                                              "bootable_zip"],
+                                              "bootable_zip",
+                                              "file_context="],
                              extra_option_handler=option_handler)
 
   bootable_only = bootable_only[0]
diff --git a/tools/releasetools/ota_from_target_files b/tools/releasetools/ota_from_target_files
index 1514ea7..f838c22 100755
--- a/tools/releasetools/ota_from_target_files
+++ b/tools/releasetools/ota_from_target_files
@@ -51,6 +51,11 @@
 
   -a  (--aslr_mode)  <on|off>
       Specify whether to turn on ASLR for the package (on by default).
+
+  -S  (--file_context) <file>
+      the file contexts configuration used to assign SELinux file
+      context attributes
+
 """
 
 import sys
@@ -87,6 +92,7 @@
 OPTIONS.extra_script = None
 OPTIONS.aslr_mode = True
 OPTIONS.worker_threads = 3
+OPTIONS.selinux_fc = None
 
 def MostPopularKey(d, default):
   """Given a dict, return the key corresponding to the largest
@@ -388,6 +394,9 @@
   if OPTIONS.wipe_user_data:
     script.FormatPartition("/data")
 
+  if OPTIONS.selinux_fc is not None:
+    WritePolicyConfig(OPTIONS.selinux_fc, output_zip)
+
   script.FormatPartition("/system")
   script.Mount("/system")
   script.UnpackPackageDir("recovery", "/system")
@@ -426,15 +435,17 @@
   script.AddToZip(input_zip, output_zip)
   WriteMetadata(metadata, output_zip)
 
+def WritePolicyConfig(file_context, output_zip):
+  f = open(file_context, 'r');
+  basename = os.path.basename(file_context)
+  common.ZipWriteStr(output_zip, basename, f.read())
+
 
 def WriteMetadata(metadata, output_zip):
   common.ZipWriteStr(output_zip, "META-INF/com/android/metadata",
                      "".join(["%s=%s\n" % kv
                               for kv in sorted(metadata.iteritems())]))
 
-
-
-
 def LoadSystemFiles(z):
   """Load all the files from SYSTEM/... in a given target-files
   ZipFile, and return a dict of {filename: File object}."""
@@ -753,12 +764,14 @@
         OPTIONS.aslr_mode = False
     elif o in ("--worker_threads"):
       OPTIONS.worker_threads = int(a)
+    elif o in ("-S", "--file_context"):
+      OPTIONS.selinux_fc = a
     else:
       return False
     return True
 
   args = common.ParseOptions(argv, __doc__,
-                             extra_opts="b:k:i:d:wne:a:",
+                             extra_opts="b:k:i:d:wne:a:S:",
                              extra_long_opts=["board_config=",
                                               "package_key=",
                                               "incremental_from=",
@@ -767,6 +780,7 @@
                                               "extra_script=",
                                               "worker_threads=",
                                               "aslr_mode=",
+                                              "file_context=",
                                               ],
                              extra_option_handler=option_handler)