Merge "Add atrace to core.mk" into jb-dev
diff --git a/core/java.mk b/core/java.mk
index 2b6851b..4e33ef2 100644
--- a/core/java.mk
+++ b/core/java.mk
@@ -4,7 +4,7 @@
 # all_res_assets
 
 ifeq ($(TARGET_BUILD_PDK),true)
-ifeq ($(TARGET_BUILD_PDK_JAVA),)
+ifeq ($(TARGET_BUILD_PDK_JAVA_PLATFORM),)
 # LOCAL_SDK not defined or set to current
 ifeq ($(filter-out current,$(LOCAL_SDK_VERSION)),)
 LOCAL_SDK_VERSION := $(PDK_BUILD_SDK_VERSION)
diff --git a/core/main.mk b/core/main.mk
index 3c64d95..407a529 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -213,6 +213,14 @@
 endif
 
 # -----------------------------------------------------------------
+# Variable to check java support level inside PDK build.
+# Not necessary if the components is not in PDK.
+# not defined : not supported
+# "sdk" : sdk API only
+# "platform" : platform API supproted
+TARGET_BUILD_JAVA_SUPPORT_LEVEL := platform
+
+# -----------------------------------------------------------------
 # The pdk (Platform Development Kit) build
 include build/core/pdk_config.mk
 
@@ -466,8 +474,12 @@
 	$(shell build/tools/findleaves.py --prune=out --prune=.repo --prune=.git $(subdirs) Android.mk)
 
 include $(subdir_makefiles)
+
 endif # ONE_SHOT_MAKEFILE
 
+# Now with all Android.mks loaded we can do post cleaning steps.
+include $(BUILD_SYSTEM)/post_clean.mk
+
 ifeq ($(stash_product_vars),true)
   $(call assert-product-vars, __STASHED)
 endif
diff --git a/core/package.mk b/core/package.mk
index 195b346..c689031 100644
--- a/core/package.mk
+++ b/core/package.mk
@@ -94,12 +94,14 @@
 ifeq (,$(LOCAL_RESOURCE_DIR))
   LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
 endif
-LOCAL_RESOURCE_DIR := \
-  $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \
-    $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
-  $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \
-    $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
-  $(LOCAL_RESOURCE_DIR)
+
+package_resource_overlays := $(strip \
+    $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \
+      $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
+    $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \
+      $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))))
+
+LOCAL_RESOURCE_DIR := $(package_resource_overlays) $(LOCAL_RESOURCE_DIR)
 
 all_assets := $(call find-subdir-assets,$(LOCAL_ASSET_DIR))
 all_assets := $(addprefix $(LOCAL_ASSET_DIR)/,$(patsubst assets/%,%,$(all_assets)))
@@ -399,6 +401,9 @@
 # Save information about this package
 PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
 PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
+ifdef package_resource_overlays
+PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_OVERLAYS := $(package_resource_overlays)
+endif
 
 PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
 
diff --git a/core/pdk_config.mk b/core/pdk_config.mk
index 492a9c4..9df2ce2 100644
--- a/core/pdk_config.mk
+++ b/core/pdk_config.mk
@@ -51,6 +51,15 @@
 PDK_PLATFORM_JAVA_ZIP_CONTENTS += $(foreach lib_dir,$(PDK_PLATFORM_JAVA_ZIP_JAVA_LIB_DIR),\
     $(lib_dir)/classes.jar $(lib_dir)/javalib.jar)
 
+# check and override java support level
+ifeq ($(TARGET_BUILD_PDK),true)
+ifneq ($(wildcard external/proguard),)
+TARGET_BUILD_JAVA_SUPPORT_LEVEL := sdk
+else # no proguard
+TARGET_BUILD_JAVA_SUPPORT_LEVEL :=
+endif
+# platform supprot is set after checking platform.zip
+endif # PDK
 
 ifdef PDK_FUSION_PLATFORM_ZIP
 TARGET_BUILD_PDK := true
@@ -67,8 +76,14 @@
 	$(shell unzip -Z -1 $(PDK_FUSION_PLATFORM_ZIP) 'target/common/*' 2>/dev/null)
 _pdk_fusion_files := $(addprefix $(_pdk_fusion_intermediates)/,\
     $(_pdk_fusion_file_list) $(_pdk_fusion_java_file_list))
+
 ifneq ($(_pdk_fusion_java_file_list),)
-TARGET_BUILD_PDK_JAVA := true
+# This represents whether java build can use platform API or not
+# This should not be used in Android.mk
+TARGET_BUILD_PDK_JAVA_PLATFORM := true
+ifneq ($(TARGET_BUILD_JAVA_SUPPORT_LEVEL),)
+TARGET_BUILD_JAVA_SUPPORT_LEVEL := platform
+endif
 endif
 
 $(_pdk_fusion_stamp) : $(PDK_FUSION_PLATFORM_ZIP)
@@ -91,7 +106,7 @@
 	@mkdir -p $(dir $@)
 	$(hide) cp -fpPR $< $@
 
-ifeq (true,$(TARGET_BUILD_PDK_JAVA))
+ifeq (true,$(TARGET_BUILD_PDK_JAVA_PLATFORM))
 
 define JAVA_dependency_template
 $(OUT_DIR)/$(strip $(1)): $(_pdk_fusion_intermediates)/$(strip $(1)) $(OUT_DIR)/$(strip $(2)) \
@@ -122,7 +137,7 @@
 
 ifeq ($(TARGET_BUILD_PDK),true)
 
-ifeq ($(TARGET_BUILD_PDK_JAVA),)
+ifeq ($(TARGET_BUILD_PDK_JAVA_PLATFORM),)
 
 # SDK used for Java build under PDK
 PDK_BUILD_SDK_VERSION := $(lastword $(TARGET_AVAILABLE_SDK_VERSIONS))
diff --git a/core/post_clean.mk b/core/post_clean.mk
new file mode 100644
index 0000000..213c43c
--- /dev/null
+++ b/core/post_clean.mk
@@ -0,0 +1,53 @@
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Clean steps that need global knowledge of individual modules.
+# This file must be included after all Android.mks have been loaded.
+
+# Checks the current build configurations against the previous build,
+# clean artifacts in TARGET_COMMON_OUT_ROOT if necessary.
+# If a package's resource overlay has been changed, its R class needs to be
+# regenerated.
+previous_package_overlay_config := $(TARGET_OUT_COMMON_INTERMEDIATES)/APPS/previous_overlays.txt
+current_package_overlay_config := $(TARGET_OUT_COMMON_INTERMEDIATES)/APPS/current_overlays.txt
+current_all_packages_config := $(dir $(current_package_overlay_config))current_packages.txt
+
+$(shell rm -rf $(current_package_overlay_config) \
+    && mkdir -p $(dir $(current_package_overlay_config)) \
+    && touch $(current_package_overlay_config))
+$(shell echo '$(PACKAGES)' > $(current_all_packages_config))
+$(foreach p, $(PACKAGES), $(if $(PACKAGES.$(p).RESOURCE_OVERLAYS), \
+  $(shell echo '$(p)' '$(PACKAGES.$(p).RESOURCE_OVERLAYS)' >> $(current_package_overlay_config))))
+
+ifneq (,$(wildcard $(previous_package_overlay_config)))
+packages_overlay_changed := $(shell build/tools/diff_package_overlays.py \
+    $(current_all_packages_config) $(current_package_overlay_config) \
+    $(previous_package_overlay_config))
+ifneq (,$(packages_overlay_changed))
+overlay_cleanup_cmd := $(strip rm -rf $(foreach p, $(packages_overlay_changed),\
+    $(TARGET_OUT_COMMON_INTERMEDIATES)/APPS/$(p)_intermediates))
+$(info *** Overlay change detected, clean shared intermediate files...)
+$(info *** $(overlay_cleanup_cmd))
+$(shell $(overlay_cleanup_cmd))
+overlay_cleanup_cmd :=
+endif
+packages_overlay_changed :=
+endif
+
+# Now current becomes previous.
+$(shell mv -f $(current_package_overlay_config) $(previous_package_overlay_config))
+
+previous_package_overlay_config :=
+current_package_overlay_config :=
+current_all_packages_config :=
diff --git a/core/tasks/vendor_module_check.mk b/core/tasks/vendor_module_check.mk
index d26a045..f492468 100644
--- a/core/tasks/vendor_module_check.mk
+++ b/core/tasks/vendor_module_check.mk
@@ -16,11 +16,14 @@
 
 # Restrict the vendor module owners here.
 _vendor_owner_whitelist := \
+        asus \
 	audience \
 	broadcom \
 	csr \
+        elan \
 	imgtec \
 	invensense \
+        nvidia \
 	nxp \
 	samsung \
 	samsung_arm \
diff --git a/core/user_tags.mk b/core/user_tags.mk
index ca2594b..22582a1 100644
--- a/core/user_tags.mk
+++ b/core/user_tags.mk
@@ -217,7 +217,6 @@
 	libESR_Portable \
 	libESR_Shared \
 	libETC1 \
-	libexif \
 	libext \
 	libext2_blkid \
 	libext2_blkid_host \
diff --git a/target/board/generic/device.mk b/target/board/generic/device.mk
index 843f038..737a607 100644
--- a/target/board/generic/device.mk
+++ b/target/board/generic/device.mk
@@ -25,8 +25,8 @@
 PRODUCT_COPY_FILES := \
     device/generic/goldfish/data/etc/apns-conf.xml:system/etc/apns-conf.xml \
     device/generic/goldfish/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_codecs.xml:system/etc/media_codecs.xml \
+    $(call add-to-product-copy-files-if-exists,development/tools/emulator/system/camera/media_profiles.xml:system/etc/media_profiles.xml) \
+    $(call add-to-product-copy-files-if-exists,development/tools/emulator/system/camera/media_codecs.xml:system/etc/media_codecs.xml) \
     hardware/libhardware_legacy/audio/audio_policy.conf:system/etc/audio_policy.conf
 
 PRODUCT_PACKAGES := \
diff --git a/target/product/mini.mk b/target/product/mini.mk
new file mode 100644
index 0000000..8a74428
--- /dev/null
+++ b/target/product/mini.mk
@@ -0,0 +1,207 @@
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Common configurations for mini_XXX lunch targets
+# This is mainly for creating small system image during early development stage.
+
+PRODUCT_BRAND := mini
+PRODUCT_DEVICE := mini
+PRODUCT_NAME := mini
+
+# add all configurations
+PRODUCT_AAPT_CONFIG := normal ldpi mdpi hdpi xhdpi xxhdpi
+PRODUCT_AAPT_PREF_CONFIG := hdpi
+
+# en_US only
+PRODUCT_LOCALES := en_US
+
+# dummy definitions to use += in later parts
+PRODUCT_PROPERTY_OVERRIDES :=
+PRODUCT_COPY_FILES :=
+
+
+# for CtsVerifier
+PRODUCT_PACKAGES += \
+    com.android.future.usb.accessory
+
+# It does not mean that all features are supproted, but only for meeting
+# configuration requirements for some CTS
+PRODUCT_COPY_FILES += \
+    frameworks/native/data/etc/handheld_core_hardware.xml:system/etc/permissions/handheld_core_hardware.xml \
+    frameworks/native/data/etc/android.hardware.location.gps.xml:system/etc/permissions/android.hardware.location.gps.xml \
+    frameworks/native/data/etc/android.hardware.sensor.light.xml:system/etc/permissions/android.hardware.sensor.light.xml \
+    frameworks/native/data/etc/android.hardware.sensor.barometer.xml:system/etc/permissions/android.hardware.sensor.barometer.xml \
+    frameworks/native/data/etc/android.hardware.sensor.gyroscope.xml:system/etc/permissions/android.hardware.sensor.gyroscope.xml \
+    frameworks/native/data/etc/android.hardware.usb.accessory.xml:system/etc/permissions/android.hardware.usb.accessory.xml
+
+#----------------- originally from core.mk ----------------
+
+PRODUCT_PROPERTY_OVERRIDES += \
+    ro.config.notification_sound=OnTheHunt.ogg \
+    ro.config.alarm_alert=Alarm_Classic.ogg
+
+PRODUCT_PACKAGES += \
+    ApplicationsProvider \
+    ContactsProvider \
+    DefaultContainerService \
+    DownloadProvider \
+    DownloadProviderUi \
+    MediaProvider \
+    PackageInstaller \
+    SettingsProvider \
+    TelephonyProvider \
+    UserDictionaryProvider \
+    apache-xml \
+    bouncycastle \
+    bu \
+    cacerts \
+    com.android.location.provider \
+    com.android.location.provider.xml \
+    core \
+    core-junit \
+    dalvikvm \
+    dexdeps \
+    dexdump \
+    dexlist \
+    dexopt \
+    dmtracedump \
+    drmserver \
+    dx \
+    ext \
+    framework-res \
+    hprof-conv \
+    icu.dat \
+    installd \
+    ip \
+    ip-up-vpn \
+    ip6tables \
+    iptables \
+    keystore \
+    keystore.default \
+    libandroidfw \
+    libOpenMAXAL \
+    libOpenSLES \
+    libaudiopreprocessing \
+    libaudioutils \
+    libcrypto \
+    libdownmix \
+    libdvm \
+    libdrmframework \
+    libdrmframework_jni \
+    libexpat \
+    libfilterfw \
+    libfilterpack_imageproc \
+    libgabi++ \
+    libicui18n \
+    libicuuc \
+    libjavacore \
+    libkeystore \
+    libmdnssd \
+    libnativehelper \
+    libnfc_ndef \
+    libpowermanager \
+    libspeexresampler \
+    libsqlite_jni \
+    libssl \
+    libstagefright_soft_aacdec \
+    libstagefright_soft_aacenc \
+    libstagefright_soft_amrdec \
+    libstagefright_soft_amrnbenc \
+    libstagefright_soft_amrwbenc \
+    libstagefright_soft_flacenc \
+    libstagefright_soft_g711dec \
+    libstagefright_soft_h264dec \
+    libstagefright_soft_h264enc \
+    libstagefright_soft_mp3dec \
+    libstagefright_soft_mpeg4dec \
+    libstagefright_soft_mpeg4enc \
+    libstagefright_soft_vorbisdec \
+    libstagefright_soft_vpxdec \
+    libstagefright_soft_rawdec \
+    libvariablespeed \
+    libwebrtc_audio_preprocessing \
+    libwilhelm \
+    libz \
+    mdnsd \
+    requestsync \
+    screencap \
+    sensorservice \
+    lint
+
+PRODUCT_COPY_FILES += \
+    system/core/rootdir/init.usb.rc:root/init.usb.rc \
+
+#----------------- originally from generic_no_telephony.mk ----------------
+
+PRODUCT_PACKAGES += \
+    Bluetooth \
+    InputDevices \
+    LatinIME \
+    Launcher2 \
+    Phone \
+    Provision \
+    Settings \
+    SystemUI \
+    hostapd \
+    wpa_supplicant.conf
+
+
+PRODUCT_PACKAGES += \
+    icu.dat
+
+PRODUCT_PACKAGES += \
+    librs_jni \
+    libvideoeditor_jni \
+    libvideoeditor_core \
+    libvideoeditor_osal \
+    libvideoeditor_videofilters \
+    libvideoeditorplayer \
+
+PRODUCT_PACKAGES += \
+    audio.primary.default \
+    audio_policy.default \
+    local_time.default \
+    power.default
+
+PRODUCT_PACKAGES += \
+    local_time.default
+
+PRODUCT_COPY_FILES += \
+    system/bluetooth/data/audio.conf:system/etc/bluetooth/audio.conf \
+    system/bluetooth/data/auto_pairing.conf:system/etc/bluetooth/auto_pairing.conf \
+    system/bluetooth/data/blacklist.conf:system/etc/bluetooth/blacklist.conf \
+    system/bluetooth/data/input.conf:system/etc/bluetooth/input.conf \
+    system/bluetooth/data/network.conf:system/etc/bluetooth/network.conf \
+    frameworks/av/media/libeffects/data/audio_effects.conf:system/etc/audio_effects.conf
+
+PRODUCT_PROPERTY_OVERRIDES += \
+    ro.carrier=unknown
+
+#----------------- originally from full_base.mk ----------------
+
+PRODUCT_PACKAGES += \
+    drmserver \
+    libdrmframework \
+    libdrmframework_jni
+
+
+# Additional settings used in all AOSP builds
+PRODUCT_PROPERTY_OVERRIDES += \
+    ro.com.android.dateformat=MM-dd-yyyy \
+    ro.config.ringtone=Ring_Synth_04.ogg \
+    ro.config.notification_sound=pixiedust.ogg
+
+$(call inherit-product-if-exists, frameworks/base/data/keyboards/keyboards.mk)
+$(call inherit-product-if-exists, frameworks/base/data/fonts/fonts.mk)
+$(call inherit-product-if-exists, frameworks/base/data/sounds/AudioPackage5.mk)
diff --git a/target/product/sdk.mk b/target/product/sdk.mk
index a5890a9..6165f71 100644
--- a/target/product/sdk.mk
+++ b/target/product/sdk.mk
@@ -63,7 +63,8 @@
 	Calendar \
 	SmokeTest \
 	SmokeTestApp \
-	rild
+	rild \
+	LegacyCamera
 
 
 # Define the host tools and libs that are parts of the SDK.
diff --git a/tools/diff_package_overlays.py b/tools/diff_package_overlays.py
new file mode 100755
index 0000000..0e2c773
--- /dev/null
+++ b/tools/diff_package_overlays.py
@@ -0,0 +1,91 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""
+Prints to stdout the package names that have overlay changes between
+current_overlays.txt and previous_overlays.txt.
+
+Usage: diff_package_overlays.py <current_packages.txt> <current_overlays.txt> <previous_overlays.txt>
+current_packages.txt contains all package names separated by space in the current build.
+This script modfies current_packages.txt if necessary: if there is a package in
+previous_overlays.txt but absent from current_packages.txt, we copy that line
+from previous_overlays.txt over to current_packages.txt. Usually that means we
+just don't care that package in the current build (for example we are switching
+from a full build to a partial build with mm/mmm), and we should carry on the
+previous overlay config so current_overlays.txt always reflects the current
+status of the entire tree.
+
+Format of current_overlays.txt and previous_overlays.txt:
+  <package_name> <resource_overlay> [resource_overlay ...]
+  <package_name> <resource_overlay> [resource_overlay ...]
+  ...
+"""
+
+import sys
+
+def main(argv):
+  if len(argv) != 4:
+    print >> sys.stderr, __doc__
+    sys.exit(1)
+
+  f = open(argv[1])
+  all_packages = set(f.read().split())
+  f.close()
+
+  def load_overlay_config(filename):
+    f = open(filename)
+    result = {}
+    for line in f:
+      line = line.strip()
+      if not line or line.startswith("#"):
+        continue
+      words = line.split()
+      result[words[0]] = " ".join(words[1:])
+    f.close()
+    return result
+
+  current_overlays = load_overlay_config(argv[2])
+  previous_overlays = load_overlay_config(argv[3])
+
+  result = []
+  carryon = []
+  for p in current_overlays:
+    if p not in previous_overlays:
+      result.append(p)
+    elif current_overlays[p] != previous_overlays[p]:
+      result.append(p)
+  for p in previous_overlays:
+    if p not in current_overlays:
+      if p in all_packages:
+        # overlay changed
+        result.append(p)
+      else:
+        # we don't build p in the current build.
+        carryon.append(p)
+
+  # Add carryon to the current overlay config file.
+  if carryon:
+    f = open(argv[2], "a")
+    for p in carryon:
+      f.write(p + " " + previous_overlays[p] + "\n")
+    f.close()
+
+  # Print out the package names that have overlay change.
+  for r in result:
+    print r
+
+if __name__ == "__main__":
+  main(sys.argv)