auto import from //branches/cupcake/...@137197
diff --git a/core/base_rules.mk b/core/base_rules.mk
index ba89c40..4ee2985 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -82,7 +82,7 @@
 endif
 
 # The definition of should-install-to-system will be different depending
-# on which goal (e.g., user/eng/sdk) is being built.
+# on which goal (e.g., sdk or just droid) is being built.
 ifdef LOCAL_IS_HOST_MODULE
   use_data :=
 else
diff --git a/core/main.mk b/core/main.mk
index 1f3412f..454527d 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -101,6 +101,8 @@
 $(info ***************************************************************)
 $(info Don't pass '$(filter eng user userdebug tests,$(MAKECMDGOALS))' on \
 		the make command line.)
+# XXX The single quote on this line fixes gvim's syntax highlighting.
+# Without which, the rest of this file is impossible to read.
 $(info Set TARGET_BUILD_VARIANT in buildspec.mk, or use lunch or)
 $(info choosecombo.)
 $(info ***************************************************************)
@@ -108,6 +110,15 @@
 $(error stopping)
 endif
 
+ifneq ($(filter-out $(INTERNAL_VALID_VARIANTS),$(TARGET_BUILD_VARIANT)),)
+$(info ***************************************************************)
+$(info ***************************************************************)
+$(info Invalid variant: $(TARGET_BUILD_VARIANT)
+$(info Valid values are: $(INTERNAL_VALID_VARIANTS)
+$(info ***************************************************************)
+$(info ***************************************************************)
+$(error stopping)
+endif
 
 ###
 ### In this section we set up the things that are different
@@ -122,10 +133,10 @@
   # Target is secure in user builds.
   ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
 
-  override_build_tags := user
+  tags_to_install := user
   ifeq ($(user_variant),userdebug)
     # Pick up some extra useful tools
-    override_build_tags += debug
+    tags_to_install += debug
   else
     # Disable debugging in plain user builds.
     enable_target_debugging :=
@@ -159,10 +170,16 @@
   ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 persist.service.adb.enable=0
 endif # !enable_target_debugging
 
+## eng ##
+
+ifeq ($(TARGET_BUILD_VARIANT),eng)
+tags_to_install := user debug eng
+endif
+
 ## tests ##
 
 ifeq ($(TARGET_BUILD_VARIANT),tests)
-override_build_tags := eng debug user development tests
+tags_to_install := user debug eng tests
 endif
 
 ## sdk ##
@@ -171,7 +188,9 @@
 ifneq ($(words $(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS))),1)
 $(error The 'sdk' target may not be specified with any other targets)
 endif
-override_build_tags := user
+# TODO: this should be eng I think.  Since the sdk is built from the eng
+# variant.
+tags_to_install := user
 ADDITIONAL_BUILD_PROPERTIES += xmpp.auto-presence=true
 ADDITIONAL_BUILD_PROPERTIES += ro.config.nocheckin=yes
 else # !sdk
@@ -198,24 +217,17 @@
 # Define a function that, given a list of module tags, returns
 # non-empty if that module should be installed in /system.
 
-# For most goals, anything tagged with "eng"/"debug"/"user" should
+# For most goals, anything not tagged with the "tests" tag should
 # be installed in /system.
 define should-install-to-system
-$(filter eng debug user,$(1))
+$(if $(filter tests,$(1)),,true)
 endef
 
 ifneq (,$(filter sdk,$(MAKECMDGOALS)))
 # For the sdk goal, anything with the "samples" tag should be
 # installed in /data even if that module also has "eng"/"debug"/"user".
 define should-install-to-system
-$(if $(filter samples,$(1)),,$(filter eng debug user development,$(1)))
-endef
-endif
-
-ifeq ($(TARGET_BUILD_VARIANT),)
-# For the default goal, everything should be installed in /system.
-define should-install-to-system
-true
+$(if $(filter samples tests,$(1)),,true)
 endef
 endif
 
@@ -454,6 +466,8 @@
 Default_MODULES := $(sort $(ALL_DEFAULT_INSTALLED_MODULES) \
                           $(ALL_BUILT_MODULES) \
                           $(CUSTOM_MODULES))
+# TODO: Remove the 3 places in the tree that use
+# ALL_DEFAULT_INSTALLED_MODULES and get rid of it from this list.
 
 ifdef FULL_BUILD
   # The base list of modules to build for this product is specified
@@ -482,30 +496,23 @@
 debug_MODULES := $(sort $(call get-tagged-modules,debug,restricted))
 tests_MODULES := $(sort $(call get-tagged-modules,tests,restricted))
 
-droid_MODULES := $(sort $(Default_MODULES) \
-			$(eng_MODULES) \
-			$(debug_MODULES) \
-			$(user_MODULES) \
-			$(all_development_MODULES))
-
-# THIS IS A TOTAL HACK AND SHOULD NOT BE USED AS AN EXAMPLE
-modules_to_build := $(droid_MODULES)
-ifneq ($(override_build_tags),)
-  modules_to_build := $(sort $(Default_MODULES) \
-		      $(foreach tag,$(override_build_tags),$($(tag)_MODULES)))
-#$(error skipping modules $(filter-out $(modules_to_build),$(Default_MODULES) $(droid_MODULES)))
+ifeq ($(strip $(tags_to_install)),)
+$(error ASSERTION FAILED: tags_to_install should not be empty)
 endif
+modules_to_install := $(sort $(Default_MODULES) \
+          $(foreach tag,$(tags_to_install),$($(tag)_MODULES)))
 
 # Some packages may override others using LOCAL_OVERRIDES_PACKAGES.
 # Filter out (do not install) any overridden packages.
-overridden_packages := $(call get-package-overrides,$(modules_to_build))
+overridden_packages := $(call get-package-overrides,$(modules_to_install))
 ifdef overridden_packages
-#  old_modules_to_build := $(modules_to_build)
-  modules_to_build := \
+#  old_modules_to_install := $(modules_to_install)
+  modules_to_install := \
       $(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk), \
-          $(modules_to_build))
+          $(modules_to_install))
 endif
-#$(error filtered out $(filter-out $(modules_to_build),$(old_modules_to_build)))
+#$(error filtered out
+#           $(filter-out $(modules_to_install),$(old_modules_to_install)))
 
 # Don't include any GNU targets in the SDK.  It's ok (and necessary)
 # to build the host tools, but nothing that's going to be installed
@@ -518,8 +525,8 @@
                       $(TARGET_OUT_DATA)/%, \
                               $(sort $(call get-tagged-modules,gnu)))
   $(info Removing from sdk:)$(foreach d,$(target_gnu_MODULES),$(info : $(d)))
-  modules_to_build := \
-              $(filter-out $(target_gnu_MODULES),$(modules_to_build))
+  modules_to_install := \
+              $(filter-out $(target_gnu_MODULES),$(modules_to_install))
 endif
 
 
@@ -527,9 +534,9 @@
 # top-level makefile with.  It expects that ALL_DEFAULT_INSTALLED_MODULES
 # contains everything that's built during the current make, but it also further
 # extends ALL_DEFAULT_INSTALLED_MODULES.
-ALL_DEFAULT_INSTALLED_MODULES := $(modules_to_build)
+ALL_DEFAULT_INSTALLED_MODULES := $(modules_to_install)
 include $(BUILD_SYSTEM)/Makefile
-modules_to_build := $(sort $(ALL_DEFAULT_INSTALLED_MODULES))
+modules_to_install := $(sort $(ALL_DEFAULT_INSTALLED_MODULES))
 ALL_DEFAULT_INSTALLED_MODULES :=
 
 endif # dont_bother
@@ -551,7 +558,7 @@
 
 # All the droid stuff, in directories
 .PHONY: files
-files: prebuilt $(modules_to_build) $(INSTALLED_ANDROID_INFO_TXT_TARGET)
+files: prebuilt $(modules_to_install) $(INSTALLED_ANDROID_INFO_TXT_TARGET)
 
 # -------------------------------------------------------------------
 
diff --git a/core/package.mk b/core/package.mk
index a212553..6b09bda 100644
--- a/core/package.mk
+++ b/core/package.mk
@@ -30,13 +30,6 @@
 $(error $(LOCAL_PATH): Package modules must define LOCAL_PACKAGE_NAME)
 endif
 
-LOCAL_MODULE_TAGS := $(strip $(LOCAL_MODULE_TAGS))
-ifeq ($(LOCAL_MODULE_TAGS),)
-$(error $(LOCAL_PATH): Package modules must define LOCAL_MODULE_TAGS)
-endif
-
-#$(warning $(LOCAL_PATH) $(LOCAL_PACKAGE_NAME) $(sort $(LOCAL_MODULE_TAGS)))
-
 ifneq ($(strip $(LOCAL_MODULE_SUFFIX)),)
 $(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE_SUFFIX)
 endif
@@ -60,6 +53,14 @@
 endif
 LOCAL_MODULE_CLASS := APPS
 
+# Package LOCAL_MODULE_TAGS default to optional
+LOCAL_MODULE_TAGS := $(strip $(LOCAL_MODULE_TAGS))
+ifeq ($(LOCAL_MODULE_TAGS),)
+LOCAL_MODULE_TAGS := optional
+endif
+
+#$(warning $(LOCAL_PATH) $(LOCAL_PACKAGE_NAME) $(sort $(LOCAL_MODULE_TAGS)))
+
 ifeq (,$(LOCAL_ASSET_DIR))
 LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
 endif
diff --git a/core/product_config.mk b/core/product_config.mk
index 93671f4..b55760f 100644
--- a/core/product_config.mk
+++ b/core/product_config.mk
@@ -50,6 +50,11 @@
 endef
 
 
+# These are the valid values of TARGET_BUILD_VARIANT.  Also, if anything else is passed
+# as the variant in the PRODUCT-$TARGET_BUILD_PRODUCT-$TARGET_BUILD_VARIANT form,
+# it will be treated as a goal, and the eng variant will be used.
+INTERNAL_VALID_VARIANTS := user userdebug eng tests
+
 # ---------------------------------------------------------------
 # Provide "PRODUCT-<prodname>-<goal>" targets, which lets you build
 # a particular configuration without needing to set up the environment.
@@ -75,17 +80,15 @@
   # The variant they want
   TARGET_BUILD_VARIANT := $(word 2,$(product_goals))
 
-  # HACK HACK HACK
   # The build server wants to do make PRODUCT-dream-installclean
   # which really means TARGET_PRODUCT=dream make installclean.  
-  ifneq ($(filter-out eng user userdebug tests,$(TARGET_BUILD_VARIANT)),)
+  ifneq ($(filter-out $(INTERNAL_VALID_VARIANTS),$(TARGET_BUILD_VARIANT)),)
 	MAKECMDGOALS := $(MAKECMDGOALS) $(TARGET_BUILD_VARIANT)
 	TARGET_BUILD_VARIANT := eng
     default_goal_substitution := 
   else
     default_goal_substitution := $(DEFAULT_GOAL)
   endif
-  # HACK HACK HACK
 
   # Hack to make the linux build servers use dexpreopt.
   # OSX is still a little flaky.  Most engineers don't use this
diff --git a/core/tasks/cts.mk b/core/tasks/cts.mk
index 4008fac..8cea2c5 100644
--- a/core/tasks/cts.mk
+++ b/core/tasks/cts.mk
@@ -74,9 +74,11 @@
 GEN_CLASSPATH := $(CORE_INTERMEDIATES)/classes.jar:$(TESTS_INTERMEDIATES)/classes.jar:$(CORE_INTERMEDIATES)/javalib.jar:$(TESTS_INTERMEDIATES)/javalib.jar:$(HOST_OUT_JAVA_LIBRARIES)/descGen.jar:$(HOST_JDK_TOOLS_JAR)
 
 $(CORE_TEST_PLAN): PRIVATE_CLASSPATH:=$(GEN_CLASSPATH)
+$(CORE_TEST_PLAN): PRIVATE_JAVAOPTS:=-Xmx256M
 $(CORE_TEST_PLAN): PRIVATE_PARAMS:=-Dcts.useSuppliedTestResult=true
 $(CORE_TEST_PLAN): PRIVATE_PARAMS+=-Dcts.useEnhancedJunit=true
-$(CORE_TEST_PLAN): PRIVATE_CUSTOM_TOOL := java -classpath $(PRIVATE_CLASSPATH) \
+$(CORE_TEST_PLAN): PRIVATE_CUSTOM_TOOL := java $(PRIVATE_JAVAOPTS) \
+	-classpath $(PRIVATE_CLASSPATH) \
 	$(PRIVATE_PARAMS) CollectAllTests $(CORE_TEST_PLAN) \
 	cts/tests/core/AndroidManifest.xml tests.AllTests
 # Why does this depend on javalib.jar instead of classes.jar?  Because
@@ -104,7 +106,9 @@
 $(CORE_VM_TEST_PLAN): PRIVATE_CLASSPATH:=$(GEN_CLASSPATH)
 $(CORE_VM_TEST_PLAN): PRIVATE_PARAMS:=-Dcts.useSuppliedTestResult=true
 $(CORE_VM_TEST_PLAN): PRIVATE_PARAMS+=-Dcts.useEnhancedJunit=true
-$(CORE_VM_TEST_PLAN): PRIVATE_CUSTOM_TOOL := java -classpath $(PRIVATE_CLASSPATH) \
+$(CORE_VM_TEST_PLAN): PRIVATE_JAVAOPTS:=-Xmx256M
+$(CORE_VM_TEST_PLAN): PRIVATE_CUSTOM_TOOL := java $(PRIVATE_JAVAOPTS) \
+	-classpath $(PRIVATE_CLASSPATH) \
 	$(PRIVATE_PARAMS) CollectAllTests $(CORE_VM_TEST_PLAN) \
 	cts/tests/vm-tests/AndroidManifest.xml dot.junit.AllJunitHostTests
 # Please see big comment above on why this line depends on javalib.jar instead of classes.jar
diff --git a/target/product/core.mk b/target/product/core.mk
index 117bb11..83e2b3a 100644
--- a/target/product/core.mk
+++ b/target/product/core.mk
@@ -21,3 +21,7 @@
     UserDictionaryProvider \
     PackageInstaller \
     Bugreport
+
+#include basic ringtones
+include frameworks/base/data/sounds/OriginalAudio.mk
+
diff --git a/tools/check_builds.sh b/tools/check_builds.sh
index 14dfec6..599aafa 100755
--- a/tools/check_builds.sh
+++ b/tools/check_builds.sh
@@ -55,13 +55,22 @@
     do_builds golden "$@"
 }
 
+function compare_builds
+{
+    local inputs=
+    while [ -n "$1" ]
+    do
+        inputs="$inputs $TEST_BUILD_DIR/golden-$1/installed-files.txt"
+        inputs="$inputs $TEST_BUILD_DIR/dist-$1/installed-files.txt"
+        shift
+    done
+    build/tools/compare_fileslist.py $inputs > $TEST_BUILD_DIR/sizes.html
+}
+
 function check_builds
 {
     rm -rf $TEST_BUILD_DIR/dist-*
     do_builds dist "$@"
-    build/tools/compare_fileslist.py \
-            $TEST_BUILD_DIR/golden-*/installed-files.txt \
-            $TEST_BUILD_DIR/dist-*/installed-files.txt \
-        > $TEST_BUILD_DIR/sizes.html
+    compare_builds "$@"
 }
 
diff --git a/tools/droiddoc/src/Android.mk b/tools/droiddoc/src/Android.mk
index abd2581..bf404b7 100644
--- a/tools/droiddoc/src/Android.mk
+++ b/tools/droiddoc/src/Android.mk
@@ -15,8 +15,6 @@
 LOCAL_PATH:= $(call my-dir)
 include $(CLEAR_VARS)
 
-LOCAL_MODULE_TAGS := docs
-
 LOCAL_SRC_FILES := \
     AnnotationInstanceInfo.java \
     AnnotationValueInfo.java \
diff --git a/tools/droiddoc/templates/assets/android-developer-core.css b/tools/droiddoc/templates/assets/android-developer-core.css
index eaa1176..81e233a 100644
--- a/tools/droiddoc/templates/assets/android-developer-core.css
+++ b/tools/droiddoc/templates/assets/android-developer-core.css
@@ -690,6 +690,7 @@
 
 #doc-content .gsc-tabsArea {
   position:relative;
+  white-space:nowrap;
 }
 
 #doc-content .gsc-tabHeader {