am e02f0194: (-s ours) Updated kernel and wifi prebuilts -- DO NOT MERGE

* commit 'e02f019498ee11660a9af5c5c567dcdbbedb2746':
  Updated kernel and wifi prebuilts -- DO NOT MERGE
diff --git a/AndroidProducts.mk b/AndroidProducts.mk
new file mode 100644
index 0000000..13c2153
--- /dev/null
+++ b/AndroidProducts.mk
@@ -0,0 +1,2 @@
+PRODUCT_MAKEFILES := \
+	$(LOCAL_DIR)/full_wingray.mk
diff --git a/BoardConfig.mk b/BoardConfig.mk
index 01c6163..654cd28 100644
--- a/BoardConfig.mk
+++ b/BoardConfig.mk
@@ -50,15 +50,17 @@
 BOARD_FLASH_BLOCK_SIZE := 4096
 
 # Wifi related defines
-BOARD_WPA_SUPPLICANT_DRIVER := WEXT
-WPA_SUPPLICANT_VERSION      := VER_0_6_X
-BOARD_WLAN_DEVICE           := bcm4329
-WIFI_DRIVER_MODULE_PATH     := "/system/lib/modules/bcm4329.ko"
-WIFI_DRIVER_FW_STA_PATH     := "/vendor/firmware/fw_bcm4329.bin"
-WIFI_DRIVER_FW_AP_PATH      := "/vendor/firmware/fw_bcm4329_apsta.bin"
-WIFI_DRIVER_MODULE_ARG      := "iface_name=wlan0 firmware_path=/vendor/firmware/fw_bcm4329.bin nvram_path=/system/etc/wifi/bcm4329.cal"
-WIFI_DRIVER_MODULE_NAME     := "bcm4329"
-WIFI_BAND                   := 802_11_ABG
+BOARD_WPA_SUPPLICANT_DRIVER := NL80211
+WPA_SUPPLICANT_VERSION      := VER_0_8_X
+BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_bcmdhd
+BOARD_HOSTAPD_DRIVER        := NL80211
+BOARD_HOSTAPD_PRIVATE_LIB   := lib_driver_cmd_bcmdhd
+BOARD_WLAN_DEVICE           := bcmdhd
+#WIFI_DRIVER_MODULE_PATH     := "/system/lib/modules/bcm4329.ko"
+WIFI_DRIVER_FW_PATH_PARAM   := "/sys/module/bcmdhd/parameters/firmware_path"
+WIFI_DRIVER_FW_PATH_STA     := "/vendor/firmware/fw_bcmdhd.bin"
+WIFI_DRIVER_FW_PATH_AP      := "/vendor/firmware/fw_bcmdhd_apsta.bin"
+WIFI_DRIVER_FW_PATH_P2P     := "/vendor/firmware/fw_bcmdhd_p2p.bin"
 
 BOARD_USES_GENERIC_AUDIO := false
 
@@ -77,7 +79,7 @@
 endif
 
 TARGET_RECOVERY_UI_LIB := librecovery_ui_stingray
-RECOVERY_24_BIT := true
+TARGET_RECOVERY_PIXEL_FORMAT := "RGBX_8888"
 
 # Avoid the generation of ldrcc instructions
 NEED_WORKAROUND_CORTEX_A9_745320 := true
diff --git a/CleanSpec.mk b/CleanSpec.mk
new file mode 100644
index 0000000..df5b41e
--- /dev/null
+++ b/CleanSpec.mk
@@ -0,0 +1,50 @@
+# Copyright (C) 2007 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.
+#
+
+# If you don't need to do a full clean build but would like to touch
+# a file or delete some intermediate files, add a clean step to the end
+# of the list.  These steps will only be run once, if they haven't been
+# run before.
+#
+# E.g.:
+#     $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
+#     $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
+#
+# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
+# files that are missing or have been moved.
+#
+# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
+# Use $(OUT_DIR) to refer to the "out" directory.
+#
+# If you need to re-do something that's already mentioned, just copy
+# the command and add it to the bottom of the list.  E.g., if a change
+# that you made last week required touching a file and a change you
+# made today requires touching the same file, just copy the old
+# touch step and add it to the end of the list.
+#
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
+
+# For example:
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
+#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
+#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
+
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/root/default.prop)
diff --git a/bcm4329.ko b/bcm4329.ko
deleted file mode 100644
index 3b4f1c7..0000000
--- a/bcm4329.ko
+++ /dev/null
Binary files differ
diff --git a/board-info.txt b/board-info.txt
index 0fd8f1b..727b385 100644
--- a/board-info.txt
+++ b/board-info.txt
@@ -1,3 +1,3 @@
 require mid=001
 require product=xoom-wifi|xoom-cdma|stingray
-require version-bootloader=1045
+require version-bootloader=1039|1045
diff --git a/device_base.mk b/device_base.mk
index 77de674..1b71521 100644
--- a/device_base.mk
+++ b/device_base.mk
@@ -21,14 +21,23 @@
     wifi.interface=wlan0 \
     wifi.supplicant_scan_interval=15
 
+# Set default USB interface
+PRODUCT_DEFAULT_PROPERTY_OVERRIDES += \
+	persist.sys.usb.config=mtp
+
 include frameworks/base/build/tablet-dalvik-heap.mk
 
 PRODUCT_COPY_FILES += \
     device/moto/wingray/init.stingray.rc:root/init.stingray.rc \
+    device/moto/wingray/init.stingray.usb.rc:root/init.stingray.usb.rc \
     device/moto/wingray/ueventd.stingray.rc:root/ueventd.stingray.rc \
 
+ifneq ($(TARGET_PREBUILT_WIFI_MODULE),)
 PRODUCT_COPY_FILES += \
-    device/moto/wingray/bcm4329.ko:system/lib/modules/bcm4329.ko \
+    $(TARGET_PREBUILT_WIFI_MODULE):system/lib/modules/bcm4329.ko
+endif
+
+PRODUCT_COPY_FILES += \
     device/moto/wingray/mXT1386_08_AA.bin:system/etc/firmware/mXT1386_08_AA.bin \
     device/moto/wingray/mXT1386_08_E1.bin:system/etc/firmware/mXT1386_08_E1.bin \
     device/moto/wingray/mXT1386_09_AA.bin:system/etc/firmware/mXT1386_09_AA.bin \
@@ -59,8 +68,12 @@
         device/moto/wingray/stingray-keypad.kcm:system/usr/keychars/stingray-keypad.kcm
 
 PRODUCT_PACKAGES := \
+    camera.stingray \
     sensors.stingray \
     lights.stingray \
+    audio.primary.stingray \
+    audio.a2dp.default \
+    audio_policy.stingray \
     librs_jni \
     make_ext4fs \
     l2ping \
@@ -76,3 +89,13 @@
 # media config xml file
 PRODUCT_COPY_FILES += \
     device/moto/wingray/media_profiles.xml:system/etc/media_profiles.xml
+
+# Bluetooth config file
+PRODUCT_COPY_FILES += \
+    system/bluetooth/data/main.nonsmartphone.conf:system/etc/bluetooth/main.conf \
+
+# inherit from the non-open-source side, if present
+$(call inherit-product-if-exists, vendor/moto/stingray/stingray-vendor.mk)
+
+WIFI_BAND := 802_11_ABG
+$(call inherit-product-if-exists, hardware/broadcom/wlan/bcmdhd/firmware/bcm4329/device-bcm.mk)
diff --git a/full_wingray.mk b/full_wingray.mk
new file mode 100644
index 0000000..771f4b2
--- /dev/null
+++ b/full_wingray.mk
@@ -0,0 +1,42 @@
+# Copyright (C) 2010 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.
+
+#
+# This file is the build configuration for a full Android
+# build for stingray hardware. This cleanly combines a set of
+# device-specific aspects (drivers) with a device-agnostic
+# product configuration (apps).
+#
+
+# A few more packages that aren't quite used on all builds
+PRODUCT_PACKAGES := \
+	HoloSpiralWallpaper \
+	LiveWallpapersPicker \
+	VisualizationWallpapers
+
+# Camera
+PRODUCT_PACKAGES += \
+    Camera
+
+# Inherit from those products. Most specific first.
+$(call inherit-product, $(SRC_TARGET_DIR)/product/full_base.mk)
+# This is where we'd set a backup provider if we had one
+#$(call inherit-product, device/sample/products/backup_overlay.mk)
+$(call inherit-product, device/moto/wingray/device.mk)
+
+# Discard inherited values and use our own instead.
+PRODUCT_NAME := full_wingray
+PRODUCT_DEVICE := wingray
+PRODUCT_BRAND := Android
+PRODUCT_MODEL := Full Android on Wingray
diff --git a/init.stingray.rc b/init.stingray.rc
index 4e2ef6e..61a3a7f 100644
--- a/init.stingray.rc
+++ b/init.stingray.rc
@@ -1,7 +1,11 @@
+import init.stingray.usb.rc
+
 on early-init
     mount debugfs debugfs /sys/kernel/debug
 
+    # EXTERNAL_STORAGE and SECONDARY_STORAGE are needed for sqlite3 _DELETE_FILE trigger
     export EXTERNAL_STORAGE /mnt/sdcard
+    export SECONDARY_STORAGE /mnt/external1
     mkdir /mnt/sdcard 0000 system system
     # for backwards compatibility
     symlink /mnt/sdcard /sdcard
@@ -14,6 +18,7 @@
     mount ext4 /dev/block/platform/sdhci-tegra.3/by-name/userdata /data wait noatime nosuid nodev
     mount ext4 /dev/block/platform/sdhci-tegra.3/by-name/cache /cache wait noatime nosuid nodev
     mount ext2 /dev/block/platform/sdhci-tegra.3/by-name/pdsb /pds wait ro
+    setprop ro.crypto.fuse_sdcard true
 
 on post-fs-data
     mkdir /data/misc/wifi 0770 wifi wifi
@@ -158,7 +163,7 @@
     group compass misc input
 
 service wpa_supplicant /system/bin/wpa_supplicant \
-    -Dwext -iwlan0 -c/data/misc/wifi/wpa_supplicant.conf
+    -Dnl80211 -iwlan0 -c/data/misc/wifi/wpa_supplicant.conf
 #   we will start as root and wpa_supplicant will switch to user wifi
 #   after setting up the capabilities required for WEXT
 #   user wifi
@@ -206,8 +211,8 @@
     keycodes 115 114
 
 service hciattach /system/bin/brcm_patchram_plus --enable_hci --enable_lpm \
-    --baudrate 3000000 --patchram /etc/firmware/bcm4329.hcd --pcm_role slave \
-    --use_baudrate_for_download /dev/ttyHS2
+    --baudrate 3000000 --use_baudrate_for_download --scopcm 0,2,0,0,0,0,0,0,0,0 \
+    --patchram /etc/firmware/bcm4329.hcd /dev/ttyHS2
     class main
     user bluetooth
     group bluetooth net_bt_admin
diff --git a/init.stingray.usb.rc b/init.stingray.usb.rc
new file mode 100644
index 0000000..586cb02
--- /dev/null
+++ b/init.stingray.usb.rc
@@ -0,0 +1,107 @@
+on boot
+    write /sys/class/android_usb/android0/iManufacturer $ro.product.manufacturer
+    write /sys/class/android_usb/android0/iProduct $ro.product.model
+    write /sys/class/android_usb/android0/iSerial $ro.serialno
+    write /sys/class/android_usb/android0/f_rndis/manufacturer Motorola
+    write /sys/class/android_usb/android0/f_rndis/vendorID 22b8
+    write /sys/class/android_usb/android0/f_rndis/wceis 1
+
+on property:sys.usb.config=mtp
+    write /sys/class/android_usb/android0/enable 0
+    write /sys/class/android_usb/android0/idVendor 22b8
+    write /sys/class/android_usb/android0/idProduct 70a8
+    write /sys/class/android_usb/android0/functions $sys.usb.config
+    write /sys/class/android_usb/android0/enable 1
+    setprop sys.usb.state $sys.usb.config
+
+on property:sys.usb.config=mtp,adb
+    write /sys/class/android_usb/android0/enable 0
+    write /sys/class/android_usb/android0/idVendor 22b8
+    write /sys/class/android_usb/android0/idProduct 70a9
+    write /sys/class/android_usb/android0/functions $sys.usb.config
+    write /sys/class/android_usb/android0/enable 1
+    start adbd
+    setprop sys.usb.state $sys.usb.config
+
+on property:sys.usb.config=rndis
+    write /sys/class/android_usb/android0/enable 0
+    write /sys/class/android_usb/android0/idVendor 22b8
+    write /sys/class/android_usb/android0/idProduct 70ae
+    write /sys/class/android_usb/android0/functions $sys.usb.config
+    write /sys/class/android_usb/android0/bDeviceClass 224
+    write /sys/class/android_usb/android0/enable 1
+    setprop sys.usb.state $sys.usb.config
+
+on property:sys.usb.config=rndis,adb
+    write /sys/class/android_usb/android0/enable 0
+    write /sys/class/android_usb/android0/idVendor 22b8
+    write /sys/class/android_usb/android0/idProduct 70af
+    write /sys/class/android_usb/android0/functions $sys.usb.config
+    write /sys/class/android_usb/android0/bDeviceClass 224
+    write /sys/class/android_usb/android0/enable 1
+    start adbd
+    setprop sys.usb.state $sys.usb.config
+
+on property:sys.usb.config=ptp
+    write /sys/class/android_usb/android0/enable 0
+    write /sys/class/android_usb/android0/idVendor 22b8
+    write /sys/class/android_usb/android0/idProduct 70b4
+    write /sys/class/android_usb/android0/functions $sys.usb.config
+    write /sys/class/android_usb/android0/enable 1
+    setprop sys.usb.state $sys.usb.config
+
+on property:sys.usb.config=ptp,adb
+    write /sys/class/android_usb/android0/enable 0
+    write /sys/class/android_usb/android0/idVendor 22b8
+    write /sys/class/android_usb/android0/idProduct 70b5
+    write /sys/class/android_usb/android0/functions $sys.usb.config
+    write /sys/class/android_usb/android0/enable 1
+    start adbd
+    setprop sys.usb.state $sys.usb.config
+
+# factory test
+on property:sys.usb.config=usbnet
+    write /sys/class/android_usb/android0/enable 0
+    write /sys/class/android_usb/android0/idVendor 22b8
+    write /sys/class/android_usb/android0/idProduct 70a3
+    write /sys/class/android_usb/android0/functions $sys.usb.config
+    write /sys/class/android_usb/android0/enable 1
+    setprop sys.usb.state $sys.usb.config
+
+# BP configurations
+on property:sys.usb.config=acm,usbnet
+    write /sys/class/android_usb/android0/enable 0
+    write /sys/class/android_usb/android0/idVendor 22b8
+    write /sys/class/android_usb/android0/idProduct 70b0
+    write /sys/class/android_usb/android0/functions $sys.usb.config
+    write /sys/class/android_usb/android0/enable 1
+    setprop sys.usb.state $sys.usb.config
+
+on property:sys.usb.config=acm,usbnet,adb
+    write /sys/class/android_usb/android0/enable 0
+    write /sys/class/android_usb/android0/idVendor 22b8
+    write /sys/class/android_usb/android0/idProduct 70b1
+    write /sys/class/android_usb/android0/functions $sys.usb.config
+    write /sys/class/android_usb/android0/enable 1
+    start adbd
+    setprop sys.usb.state $sys.usb.config
+
+on property:sys.usb.config=rndis,acm,usbnet
+    write /sys/class/android_usb/android0/enable 0
+    write /sys/class/android_usb/android0/idVendor 22b8
+    write /sys/class/android_usb/android0/idProduct 70b2
+    write /sys/class/android_usb/android0/functions $sys.usb.config
+    write /sys/class/android_usb/android0/bDeviceClass 224
+    write /sys/class/android_usb/android0/enable 1
+    setprop sys.usb.state $sys.usb.config
+
+on property:sys.usb.config=rndis,acm,usbnet,adb
+    write /sys/class/android_usb/android0/enable 0
+    write /sys/class/android_usb/android0/idVendor 22b8
+    write /sys/class/android_usb/android0/idProduct 70b3
+    write /sys/class/android_usb/android0/functions $sys.usb.config
+    write /sys/class/android_usb/android0/bDeviceClass 224
+    write /sys/class/android_usb/android0/enable 1
+    start adbd
+    setprop sys.usb.state $sys.usb.config
+
diff --git a/kernel b/kernel
index d1ecea7..1018e3c 100644
--- a/kernel
+++ b/kernel
Binary files differ
diff --git a/libaudio/Android.mk b/libaudio/Android.mk
index 36c9696..d88c9ee 100644
--- a/libaudio/Android.mk
+++ b/libaudio/Android.mk
@@ -4,7 +4,7 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_SRC_FILES:=               \
+LOCAL_SRC_FILES := \
     AudioPolicyManager.cpp
 
 LOCAL_SHARED_LIBRARIES := \
@@ -12,9 +12,15 @@
     libutils \
     libmedia
 
-LOCAL_STATIC_LIBRARIES := libaudiopolicybase
+LOCAL_STATIC_LIBRARIES := \
+    libmedia_helper
 
-LOCAL_MODULE:= libaudiopolicy
+LOCAL_WHOLE_STATIC_LIBRARIES := \
+    libaudiopolicy_legacy
+
+LOCAL_MODULE := audio_policy.stingray
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_TAGS := optional
 
 ifeq ($(BOARD_HAVE_BLUETOOTH),true)
   LOCAL_CFLAGS += -DWITH_A2DP
@@ -25,7 +31,9 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_MODULE := libaudio
+LOCAL_MODULE := audio.primary.stingray
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_TAGS := optional
 
 LOCAL_SHARED_LIBRARIES := \
     libcutils \
@@ -33,19 +41,21 @@
     libmedia \
     libhardware_legacy
 
-ifeq ($TARGET_OS)-$(TARGET_SIMULATOR),linux-true)
-LOCAL_LDLIBS += -ldl
-endif
-
-ifneq ($(TARGET_SIMULATOR),true)
 LOCAL_SHARED_LIBRARIES += libdl
-endif
 
-LOCAL_SRC_FILES += AudioHardware.cpp
+LOCAL_SRC_FILES += \
+    AudioHardware.cpp
+
+LOCAL_C_INCLUDES += \
+    system/media/audio_effects/include
 
 LOCAL_CFLAGS += -fno-short-enums
 
-LOCAL_STATIC_LIBRARIES += libaudiointerface
+LOCAL_STATIC_LIBRARIES := \
+    libmedia_helper
+
+LOCAL_WHOLE_STATIC_LIBRARIES := \
+    libaudiohw_legacy
 
 ifeq ($(USE_PROPRIETARY_AUDIO_EXTENSIONS),true)
 LOCAL_SRC_FILES += AudioPostProcessor.cpp
@@ -64,10 +74,6 @@
 LOCAL_C_INCLUDES += vendor/moto/stingray/motomm/rate_conv
 endif
 
-ifeq ($(BOARD_HAVE_BLUETOOTH),true)
-  LOCAL_SHARED_LIBRARIES += liba2dp
-endif
-
 include $(BUILD_SHARED_LIBRARY)
 
 endif # not BUILD_TINY_ANDROID
diff --git a/libaudio/AudioHardware.cpp b/libaudio/AudioHardware.cpp
index 9011b8a..b615443 100644
--- a/libaudio/AudioHardware.cpp
+++ b/libaudio/AudioHardware.cpp
@@ -31,8 +31,10 @@
 
 #include "AudioHardware.h"
 #include <media/AudioRecord.h>
+#include <audio_effects/effect_aec.h>
+#include <audio_effects/effect_ns.h>
 
-namespace android {
+namespace android_audio_legacy {
 const uint32_t AudioHardware::inputSamplingRates[] = {
     8000, 11025, 12000, 16000, 22050, 32000, 44100, 48000
 };
@@ -54,7 +56,7 @@
     mOutput(0), /*mCurOut/InDevice*/ mCpcapCtlFd(-1), mHwOutRate(0), mHwInRate(0),
     mMasterVol(1.0), mVoiceVol(1.0),
     /*mCpcapGain*/
-    mSpkrVolume(-1), mMicVolume(-1), mEcnsEnabled(false), mBtScoOn(false)
+    mSpkrVolume(-1), mMicVolume(-1), mEcnsEnabled(0), mEcnsRequested(0), mBtScoOn(false)
 {
     LOGV("AudioHardware constructor");
 }
@@ -681,14 +683,12 @@
              mCurOutDevice.on ? "on" : "off");
     }
 
-    mEcnsEnabled = false;
     // enable EC if:
-    // - the audio mode is IN_CALL or IN_COMMUNICATION  AND
-    // - the output stream is active AND
-    // - an input stream with VOICE_COMMUNICATION source is active
-    if (isInCall() && !mOutput->getStandby() &&
-        input && input->source() == AUDIO_SOURCE_VOICE_COMMUNICATION) {
-        mEcnsEnabled = true;
+    // - mEcnsRequested AND
+    // - the output stream is active
+    mEcnsEnabled = mEcnsRequested;
+    if (mOutput->getStandby()) {
+        mEcnsEnabled &= ~PREPROC_AEC;
     }
 
 #ifdef USE_PROPRIETARY_AUDIO_EXTENSIONS
@@ -696,7 +696,12 @@
     // Check input/output rates for HW.
     if (mEcnsEnabled) {
         mHwInRate = ecnsRate;
-        mHwOutRate = mHwInRate;
+        // rx path is altered only if AEC is enabled
+        if (mEcnsEnabled & PREPROC_AEC) {
+            mHwOutRate = mHwInRate;
+        } else {
+            mHwOutRate = AUDIO_HW_OUT_SAMPLERATE;
+        }
         LOGD("EC/NS active, requests rate as %d for in/out", mHwInRate);
     }
     else
@@ -745,10 +750,10 @@
     if (btScoOn != mBtScoOn) {
         if (input) {
 #ifdef USE_PROPRIETARY_AUDIO_EXTENSIONS
-        if (mEcnsEnabled) {
-            mAudioPP.enableEcns(false);
-            mAudioPP.enableEcns(true);
-        }
+            if (mEcnsEnabled) {
+                mAudioPP.enableEcns(0);
+                mAudioPP.enableEcns(mEcnsEnabled);
+            }
 #endif
             input->lockFd();
             input->stop_l();
@@ -857,6 +862,15 @@
     return NULL;
 }
 
+void AudioHardware::setEcnsRequested_l(int ecns, bool enabled)
+{
+    if (enabled) {
+        mEcnsRequested |= ecns;
+    } else {
+        mEcnsRequested &= ~ecns;
+    }
+}
+
 // ----------------------------------------------------------------------------
 // Sample Rate Converter wrapper
 //
@@ -1145,7 +1159,7 @@
             mSrc.deinit();
         }
 
-        if (mHardware->mAudioPP.isEcnsEnabled() || mSrc.initted())
+        if (mHardware->mAudioPP.isEcEnabled() || mSrc.initted())
         {
             // cut audio down to Mono for SRC or ECNS
             if (channels() == AudioSystem::CHANNEL_OUT_STEREO)
@@ -1184,7 +1198,7 @@
             outsize = mSrc.mIoData.output_count*2;
             LOGV("Outsize is now %d", outsize);
         }
-        if (mHardware->mAudioPP.isEcnsEnabled()) {
+        if (mHardware->mAudioPP.isEcEnabled()) {
             // EC/NS is a blocking interface, to synchronise with read.
             // It also consumes data when EC/NS is running.
             // It expects MONO data.
@@ -1199,7 +1213,7 @@
                                                             stereo, outsize, &mFdLock);
             mLocked = false;
         }
-        if (mHardware->mAudioPP.isEcnsEnabled() || mSrc.initted()) {
+        if (mHardware->mAudioPP.isEcEnabled() || mSrc.initted()) {
             // Move audio back up to Stereo, if the EC/NS wasn't in fact running and we're
             // writing to a stereo device.
             if (stereo &&
@@ -1294,9 +1308,7 @@
             LOGV("output %p going online", this);
             mState = AUDIO_STREAM_CONFIG_REQ;
             // update EC state if necessary
-            AudioStreamInTegra *input = mHardware->getActiveInput_l();
-            if (mHardware->isInCall() &&
-                input && input->source() == AUDIO_SOURCE_VOICE_COMMUNICATION) {
+            if (mHardware->getActiveInput_l() && mHardware->isEcRequested()) {
                 // doRouting_l() will not try to lock mLock when calling setDriver_l()
                 mLocked = true;
                 mHardware->doRouting_l();
@@ -1336,6 +1348,23 @@
 
     mDriverRate = mHardware->mHwOutRate;
 
+    // If EC is on, pre load one DMA buffer with 20ms of silence to limit underruns
+    if (mHardware->mEcnsEnabled) {
+        int fd = -1;
+        if (mIsBtEnabled) {
+            fd = mBtFd;
+        } else if (mIsSpkrEnabled) {
+            fd = mFd;
+        }
+        if (fd >= 0) {
+            size_t bufSize = (mDriverRate * 2 /* stereo */ * sizeof(int16_t))/ 50;
+            char buf[bufSize];
+            memset(buf, 0, bufSize);
+            Mutex::Autolock lock2(mFdLock);
+            ::write(fd, buf, bufSize);
+        }
+    }
+
     mState = AUDIO_STREAM_CONFIGURED;
 
     return status;
@@ -1356,9 +1385,7 @@
         mState = AUDIO_STREAM_IDLE;
 
         // update EC state if necessary
-        AudioStreamInTegra *input = mHardware->getActiveInput_l();
-        if (mHardware->isInCall() &&
-            input && input->source() == AUDIO_SOURCE_VOICE_COMMUNICATION) {
+        if (mHardware->getActiveInput_l() && mHardware->isEcRequested()) {
             // doRouting_l will not try to lock mLock when calling setDriver_l()
             mLocked = true;
             mHardware->doRouting_l();
@@ -1473,7 +1500,7 @@
     mAcoustics((AudioSystem::audio_in_acoustics)0), mDevices(0),
     mIsMicEnabled(0), mIsBtEnabled(0),
     mSource(AUDIO_SOURCE_DEFAULT), mLocked(false), mTotalBuffersRead(0),
-    mDriverRate(AUDIO_HW_IN_SAMPLERATE)
+    mDriverRate(AUDIO_HW_IN_SAMPLERATE), mEcnsRequested(0)
 {
     LOGV("AudioStreamInTegra constructor");
 }
@@ -1651,7 +1678,7 @@
         }
         {
             Mutex::Autolock dfl(mFdLock);
-            ret = ::read(mFd, buffer, hwReadBytes);
+            ret = ::read(mFd, buffer, bytes);
         }
 #endif
 
@@ -1702,6 +1729,8 @@
     if (mState != AUDIO_STREAM_IDLE) {
         LOGV("input %p going into standby", this);
         mState = AUDIO_STREAM_IDLE;
+        // reset global pre processing state before disabling the input
+        mHardware->setEcnsRequested_l(PREPROC_AEC|PREPROC_NS, false);
         // setDriver_l() will not try to lock mLock when called by doRouting_l()
         mLocked = true;
         mHardware->doRouting_l();
@@ -1739,6 +1768,8 @@
         if (mState == AUDIO_STREAM_IDLE) {
             mState = AUDIO_STREAM_CONFIG_REQ;
             LOGV("input %p going online", this);
+            // apply pre processing requested for this input
+            mHardware->setEcnsRequested_l(mEcnsRequested, true);
             // setDriver_l() will not try to lock mLock when called by doRouting_l()
             mLocked = true;
             mHardware->doRouting_l();
@@ -1791,8 +1822,8 @@
 {
 #ifdef USE_PROPRIETARY_AUDIO_EXTENSIONS
     if (mHardware->mEcnsEnabled) {
-        mHardware->mAudioPP.enableEcns(false);
-        mHardware->mAudioPP.enableEcns(true);
+        mHardware->mAudioPP.enableEcns(0);
+        mHardware->mAudioPP.enableEcns(mHardware->mEcnsEnabled);
     }
 #endif
     // Need to "restart" the driver when changing the buffer configuration.
@@ -1933,6 +1964,42 @@
     LOGV("AudioStreamInTegra::stop_l() returns");
 }
 
+void AudioHardware::AudioStreamInTegra::updateEcnsRequested(effect_handle_t effect, bool enabled)
+{
+#ifdef USE_PROPRIETARY_AUDIO_EXTENSIONS
+    effect_descriptor_t desc;
+    status_t status = (*effect)->get_descriptor(effect, &desc);
+    if (status == 0) {
+        int ecns = 0;
+        if (memcmp(&desc.type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0) {
+            ecns = PREPROC_AEC;
+        } else if (memcmp(&desc.type, FX_IID_NS, sizeof(effect_uuid_t)) == 0) {
+            ecns = PREPROC_NS;
+        }
+        LOGV("AudioStreamInTegra::updateEcnsRequested() %s effect %s",
+             enabled ? "enabling" : "disabling", desc.name);
+        if (enabled) {
+            mEcnsRequested |= ecns;
+        } else {
+            mEcnsRequested &= ~ecns;
+        }
+        standby();
+    }
+#endif
+}
+
+status_t AudioHardware::AudioStreamInTegra::addAudioEffect(effect_handle_t effect)
+{
+    updateEcnsRequested(effect, true);
+    return NO_ERROR;
+}
+
+status_t AudioHardware::AudioStreamInTegra::removeAudioEffect(effect_handle_t effect)
+{
+    updateEcnsRequested(effect, false);
+    return NO_ERROR;
+}
+
 // ----------------------------------------------------------------------------
 
 extern "C" AudioHardwareInterface* createAudioHardware(void) {
diff --git a/libaudio/AudioHardware.h b/libaudio/AudioHardware.h
index 9a9ddb0..f56d58e 100644
--- a/libaudio/AudioHardware.h
+++ b/libaudio/AudioHardware.h
@@ -32,7 +32,10 @@
 }
 #endif
 
-namespace android {
+namespace android_audio_legacy {
+    using android::AutoMutex;
+    using android::Mutex;
+    using android::SortedVector;
 
 #include <linux/cpcap_audio.h>
 #include <linux/tegra_audio.h>
@@ -134,6 +137,19 @@
     // added by AudioHardware
                status_t    init();
 
+               // voice processing IDs for mEcnsRequested and mEcnsEnabled
+               enum {
+#ifdef USE_PROPRIETARY_AUDIO_EXTENSIONS
+                   PREPROC_AEC = AudioPostProcessor::AEC,   // AEC is enabled
+                   PREPROC_NS = AudioPostProcessor::NS,     // NS is enabled
+#else
+                   PREPROC_AEC = 0x1,                       // AEC is enabled
+                   PREPROC_NS = 0x2,                        // NS is enabled
+#endif
+               };
+
+               void        setEcnsRequested_l(int ecns, bool enabled);
+               bool        isEcRequested() { return !!(mEcnsRequested & PREPROC_AEC); }
 protected:
     // AudioHardwareBase provides default implementation
     //virtual  bool        isModeInCall(int mode);
@@ -145,6 +161,7 @@
     // added by AudioHardware
                 int        getActiveInputRate();
 
+
 private:
 
     status_t    dumpInternals(int fd, const Vector<String16>& args);
@@ -274,6 +291,9 @@
         virtual status_t    setParameters(const String8& keyValuePairs);
         virtual String8     getParameters(const String8& keys);
         virtual unsigned int  getInputFramesLost() const;
+        virtual status_t    addAudioEffect(effect_handle_t effect);
+        virtual status_t    removeAudioEffect(effect_handle_t effect);
+
                 uint32_t    devices() { return mDevices; }
                 void        setDriver_l(bool mic, bool bluetooth, int sampleRate);
                 int         source() const { return mSource; }
@@ -286,6 +306,7 @@
 
     private:
                 void        reopenReconfigDriver();
+                void        updateEcnsRequested(effect_handle_t effect, bool enabled);
 
                 AudioHardware* mHardware;
                 Mutex       mLock;
@@ -314,6 +335,7 @@
         mutable Mutex       mFramesLock;
                 Mutex       mFdLock;
                 bool        mSleepReq;
+                int         mEcnsRequested;   // bit field indicating if AEC and/or NS are requested
     };
 
             static const uint32_t inputSamplingRates[];
@@ -343,7 +365,9 @@
 #endif
             int mSpkrVolume;
             int mMicVolume;
-            bool mEcnsEnabled;
+
+            int mEcnsEnabled;   // bit field indicating if AEC and/or NS are enabled
+            int mEcnsRequested; // bit field indicating if AEC and/or NS are requested
             bool mBtScoOn;
 };
 
diff --git a/libaudio/AudioPolicyManager.cpp b/libaudio/AudioPolicyManager.cpp
index 42887f4..efec3e9 100644
--- a/libaudio/AudioPolicyManager.cpp
+++ b/libaudio/AudioPolicyManager.cpp
@@ -20,7 +20,7 @@
 #include "AudioPolicyManager.h"
 #include <media/mediarecorder.h>
 
-namespace android {
+namespace android_audio_legacy {
 
 
 
diff --git a/libaudio/AudioPolicyManager.h b/libaudio/AudioPolicyManager.h
index b591c1f..561e90b 100644
--- a/libaudio/AudioPolicyManager.h
+++ b/libaudio/AudioPolicyManager.h
@@ -23,7 +23,7 @@
 #include <hardware_legacy/AudioPolicyManagerBase.h>
 
 
-namespace android {
+namespace android_audio_legacy {
 
 class AudioPolicyManager: public AudioPolicyManagerBase
 {
diff --git a/libaudio/AudioPostProcessor.cpp b/libaudio/AudioPostProcessor.cpp
index 9d81654..a94204d 100644
--- a/libaudio/AudioPostProcessor.cpp
+++ b/libaudio/AudioPostProcessor.cpp
@@ -48,10 +48,10 @@
 #define GETTIMEOFDAY(a,b)
 #endif
 
-namespace android {
+namespace android_audio_legacy {
 
 AudioPostProcessor::AudioPostProcessor() :
-    mEcnsScratchBuf(0), mLogNumPoints(0),  mEcnsDlBuf(0), mEcnsThread(0)
+    mEcnsScratchBuf(0), mLogNumPoints(0),  mEcnsDlBuf(0), mEcnsDlBufSize(0), mEcnsThread(0)
 {
     LOGD("%s",__FUNCTION__);
 
@@ -74,7 +74,7 @@
 {
     if (mEcnsRunning) {
         LOGD("%s",__FUNCTION__);
-        enableEcns(false);
+        enableEcns(0);
     }
 }
 
@@ -137,16 +137,14 @@
     }
 }
 
-void AudioPostProcessor::enableEcns(bool value)
+void AudioPostProcessor::enableEcns(int value)
 {
     if (mEcnsEnabled!=value) {
-        LOGD("enableEcns(%s)",value?"true":"false");
+        LOGD("enableEcns() new %08x old %08x)", value, mEcnsEnabled);
+        mEcnsThread->requestExitAndWait();
+        stopEcns();
+        cleanupEcns();
         mEcnsEnabled = value;
-        if (value==false) {
-            mEcnsThread->requestExitAndWait();
-            stopEcns();
-            cleanupEcns();
-        }
     }
 }
 
@@ -316,6 +314,17 @@
                                           int bytes, Mutex *fdLock)
 {
     int written = 0;
+
+    // write directly to pcm out driver if only NS is enabled
+    if (!(mEcnsEnabled & AEC)) {
+        if (fd >= 0) {
+            fdLock->lock();
+            ::write(fd, buffer, bytes);
+            fdLock->unlock();
+        }
+        return bytes;
+    }
+
     mEcnsBufLock.lock();
     if (mEcnsEnabled && !mEcnsRunning) {
         long usecs = 20*1000;
@@ -388,86 +397,99 @@
 
     if (!mEcnsRunning) {
         LOGE("EC/NS failed to init, read returns.");
-        return -1;
-    }
-
-    mEcnsBufLock.lock();
-    // Need a contiguous stereo playback buffer in the end.
-    if (bytes*2 != mEcnsDlBufSize || !mEcnsDlBuf) {
-        if (mEcnsDlBuf)
-            free(mEcnsDlBuf);
-        mEcnsDlBuf = (int16_t*)malloc(bytes*2);
-        if (mEcnsDlBuf)
-            mEcnsDlBufSize = bytes*2;
-    }
-    dl_buf = mEcnsDlBuf;
-    if (!dl_buf) {
-        mEcnsBufLock.unlock();
-        return -1;
-    }
-
-    // Need to gather appropriate amount of downlink speech.
-    // Take oldest scratch data first.  The scratch buffer holds fractions of buffers
-    // that were too small for processing.
-    if (mEcnsScratchBuf && mEcnsScratchBufSize) {
-        dl_buf_bytes = mEcnsScratchBufSize > bytes ? bytes:mEcnsScratchBufSize;
-        memcpy(dl_buf, mEcnsScratchBuf, dl_buf_bytes);
-        //LOGD("Took %d bytes from mEcnsScratchBuf", dl_buf_bytes);
-        mEcnsScratchBufSize -= dl_buf_bytes;
-        if (mEcnsScratchBufSize==0) {
-            // This should always be true.
-            free(mEcnsScratchBuf);
-            mEcnsScratchBuf = 0;
-            mEcnsScratchBufSize = 0;
-        }
-    }
-    // Take fresh data from write thread second.
-    if (dl_buf_bytes < bytes) {
-        int bytes_to_copy = mEcnsOutBufSize - mEcnsOutBufReadOffset;
-        bytes_to_copy = bytes_to_copy + dl_buf_bytes > bytes?
-                      bytes-dl_buf_bytes:bytes_to_copy;
-        if (bytes_to_copy) {
-            memcpy((void *)((unsigned int)dl_buf+dl_buf_bytes),
-                   (void *)((unsigned int)mEcnsOutBuf+mEcnsOutBufReadOffset),
-                   bytes_to_copy);
-            dl_buf_bytes += bytes_to_copy;
-        }
-        //LOGD("Took %d bytes from mEcnsOutBuf.  Need %d more.", bytes_to_copy,
-        //      bytes-dl_buf_bytes);
-        mEcnsOutBufReadOffset += bytes_to_copy;
-        if (mEcnsOutBufSize - mEcnsOutBufReadOffset < bytes) {
-            // We've depleted the output buffer, it's smaller than one uplink "frame".
-            // First take any unused data into scratch, then free the write thread.
-            if (mEcnsScratchBuf) {
-                LOGE("Memleak - coding error");
-                free(mEcnsScratchBuf);
-            }
-            if (mEcnsOutBufSize - mEcnsOutBufReadOffset > 0) {
-                if ((mEcnsScratchBuf=malloc(mEcnsOutBufSize - mEcnsOutBufReadOffset)) == 0) {
-                    LOGE("%s: Alloc failed, scratch data lost.",__FUNCTION__);
-                } else {
-                    mEcnsScratchBufSize = mEcnsOutBufSize - mEcnsOutBufReadOffset;
-                    //LOGD("....store %d bytes into scratch buf %p",
-                    //     mEcnsScratchBufSize, mEcnsScratchBuf);
-                    memcpy(mEcnsScratchBuf,
-                           (void *)((unsigned int)mEcnsOutBuf+mEcnsOutBufReadOffset),
-                           mEcnsScratchBufSize);
-                }
-            }
-            mEcnsOutBuf = 0;
-            mEcnsOutBufSize = 0;
-            mEcnsOutBufReadOffset = 0;
-            //LOGD("Signal write thread - need data.");
+        if (mEcnsEnabled & AEC) {
             mEcnsBufCond.signal();
         }
+        return -1;
     }
 
-    mEcnsBufLock.unlock();
+    // do not get downlink audio if only NS is enabled
+    if (mEcnsEnabled & AEC) {
+        mEcnsBufLock.lock();
+        // Need a contiguous stereo playback buffer in the end.
+        if (bytes*2 != mEcnsDlBufSize || !mEcnsDlBuf) {
+            if (mEcnsDlBuf)
+                free(mEcnsDlBuf);
+            mEcnsDlBuf = (int16_t*)malloc(bytes*2);
+            if (mEcnsDlBuf)
+                mEcnsDlBufSize = bytes*2;
+        }
+        dl_buf = mEcnsDlBuf;
+        if (!dl_buf) {
+            mEcnsBufLock.unlock();
+            return -1;
+        }
+
+        // Need to gather appropriate amount of downlink speech.
+        // Take oldest scratch data first.  The scratch buffer holds fractions of buffers
+        // that were too small for processing.
+        if (mEcnsScratchBuf && mEcnsScratchBufSize) {
+            dl_buf_bytes = mEcnsScratchBufSize > bytes ? bytes:mEcnsScratchBufSize;
+            memcpy(dl_buf, mEcnsScratchBuf, dl_buf_bytes);
+            //LOGD("Took %d bytes from mEcnsScratchBuf", dl_buf_bytes);
+            mEcnsScratchBufSize -= dl_buf_bytes;
+            if (mEcnsScratchBufSize==0) {
+                // This should always be true.
+                free(mEcnsScratchBuf);
+                mEcnsScratchBuf = 0;
+                mEcnsScratchBufSize = 0;
+            }
+        }
+        // Take fresh data from write thread second.
+        if (dl_buf_bytes < bytes) {
+            int bytes_to_copy = mEcnsOutBufSize - mEcnsOutBufReadOffset;
+            bytes_to_copy = bytes_to_copy + dl_buf_bytes > bytes?
+                          bytes-dl_buf_bytes:bytes_to_copy;
+            if (bytes_to_copy) {
+                memcpy((void *)((unsigned int)dl_buf+dl_buf_bytes),
+                       (void *)((unsigned int)mEcnsOutBuf+mEcnsOutBufReadOffset),
+                       bytes_to_copy);
+                dl_buf_bytes += bytes_to_copy;
+            }
+            //LOGD("Took %d bytes from mEcnsOutBuf.  Need %d more.", bytes_to_copy,
+            //      bytes-dl_buf_bytes);
+            mEcnsOutBufReadOffset += bytes_to_copy;
+            if (mEcnsOutBufSize - mEcnsOutBufReadOffset < bytes) {
+                // We've depleted the output buffer, it's smaller than one uplink "frame".
+                // First take any unused data into scratch, then free the write thread.
+                if (mEcnsScratchBuf) {
+                    LOGE("Memleak - coding error");
+                    free(mEcnsScratchBuf);
+                }
+                if (mEcnsOutBufSize - mEcnsOutBufReadOffset > 0) {
+                    if ((mEcnsScratchBuf=malloc(mEcnsOutBufSize - mEcnsOutBufReadOffset)) == 0) {
+                        LOGE("%s: Alloc failed, scratch data lost.",__FUNCTION__);
+                    } else {
+                        mEcnsScratchBufSize = mEcnsOutBufSize - mEcnsOutBufReadOffset;
+                        //LOGD("....store %d bytes into scratch buf %p",
+                        //     mEcnsScratchBufSize, mEcnsScratchBuf);
+                        memcpy(mEcnsScratchBuf,
+                               (void *)((unsigned int)mEcnsOutBuf+mEcnsOutBufReadOffset),
+                               mEcnsScratchBufSize);
+                    }
+                }
+                mEcnsOutBuf = 0;
+                mEcnsOutBufSize = 0;
+                mEcnsOutBufReadOffset = 0;
+                //LOGD("Signal write thread - need data.");
+                mEcnsBufCond.signal();
+            }
+        }
+
+        LOGV_IF(dl_buf_bytes < bytes, "%s:EC/NS Starved for downlink data. have %d need %d.",
+             __FUNCTION__,dl_buf_bytes, bytes);
+
+        mEcnsBufLock.unlock();
+    } else {
+        if (mEcnsDlBufSize < bytes * 2) {
+           mEcnsDlBufSize = bytes * 2;
+           mEcnsDlBuf = (int16_t *)realloc(mEcnsDlBuf, mEcnsDlBufSize);
+        }
+        dl_buf = mEcnsDlBuf;
+    }
 
     // Pad downlink with zeroes as last resort.  We have to process the UL speech.
     if (dl_buf_bytes < bytes) {
-        LOGV("%s:EC/NS Starved for downlink data. have %d need %d.",
-             __FUNCTION__,dl_buf_bytes, bytes);
         memset(&dl_buf[dl_buf_bytes/sizeof(int16_t)],
                0,
                bytes-dl_buf_bytes);
@@ -476,25 +498,29 @@
     // Do Echo Cancellation
     GETTIMEOFDAY(&mtv4, NULL);
     API_MOT_LOG_RESET(&mEcnsCtrl, &mMemBlocks);
-    API_MOT_DOWNLINK(&mEcnsCtrl, &mMemBlocks, (int16*)dl_buf, (int16*)ul_buf, &(ul_gbuff2[0]));
+    if (mEcnsEnabled & AEC) {
+        API_MOT_DOWNLINK(&mEcnsCtrl, &mMemBlocks, (int16*)dl_buf, (int16*)ul_buf, &(ul_gbuff2[0]));
+    }
     API_MOT_UPLINK(&mEcnsCtrl, &mMemBlocks, (int16*)dl_buf, (int16*)ul_buf, &(ul_gbuff2[0]));
 
     // Playback the echo-cancelled speech to driver.
     // Include zero padding.  Our echo canceller needs a consistent path.
-    if (mEcnsOutStereo) {
-        // Convert up to stereo, in place.
-        for (int i = bytes/2-1; i >= 0; i--) {
-            dl_buf[i*2] = dl_buf[i];
-            dl_buf[i*2+1] = dl_buf[i];
+    if (mEcnsEnabled & AEC) {
+        if (mEcnsOutStereo) {
+            // Convert up to stereo, in place.
+            for (int i = bytes/2-1; i >= 0; i--) {
+                dl_buf[i*2] = dl_buf[i];
+                dl_buf[i*2+1] = dl_buf[i];
+            }
+            dl_buf_bytes *= 2;
         }
-        dl_buf_bytes *= 2;
-    }
-    GETTIMEOFDAY(&mtv5, NULL);
-    if (mEcnsOutFd != -1) {
-        mEcnsOutFdLockp->lock();
-        ::write(mEcnsOutFd, &dl_buf[0],
-                bytes*(mEcnsOutStereo?2:1));
-        mEcnsOutFdLockp->unlock();
+        GETTIMEOFDAY(&mtv5, NULL);
+        if (mEcnsOutFd != -1) {
+            mEcnsOutFdLockp->lock();
+            ::write(mEcnsOutFd, &dl_buf[0],
+                    bytes*(mEcnsOutStereo?2:1));
+            mEcnsOutFdLockp->unlock();
+        }
     }
     // Do the CTO SuperAPI internal logging.
     // (Do this after writing output to avoid adding latency.)
@@ -660,6 +686,7 @@
     struct timeval tv1, tv2;
     int  usecs;
     bool half_done = false;
+    int ecnsStatus = 0;
 
     LOGD("%s: Enter thread loop size %d rate %d", __FUNCTION__,
                                           mReadSize, mRate);
@@ -668,13 +695,15 @@
     if (!mReadBuf)
         goto error;
 
-    while (mProcessor->isEcnsEnabled()) {
+    while (!exitPending() && ecnsStatus != -1) {
         GETTIMEOFDAY(&mtv1, NULL);
         if (!half_done)
             ret1 = ::read(mFd, mReadBuf, mReadSize/2);
+        if(exitPending())
+            goto error;
         GETTIMEOFDAY(&mtv2, NULL);
         ret2 = ::read(mFd, (char *)mReadBuf+mReadSize/2, mReadSize/2);
-        if(!mProcessor->isEcnsEnabled())
+        if(exitPending())
             goto error;
         if (ret1 <= 0 || ret2 <= 0) {
             LOGE("%s: Problem reading.", __FUNCTION__);
@@ -682,7 +711,7 @@
         }
         GETTIMEOFDAY(&mtv3, NULL);
         mEcnsReadLock.lock();
-        mProcessor->applyUplinkEcns(mReadBuf, mReadSize, mRate);
+        ecnsStatus = mProcessor->applyUplinkEcns(mReadBuf, mReadSize, mRate);
         if (mClientBuf && mReadSize) {
             // Give the buffer to the client.
             memcpy(mClientBuf, mReadBuf, mReadSize);
@@ -694,7 +723,7 @@
             mClientBuf = 0;
         } else {
             half_done = false;
-            LOGD("%s: Read overflow (ECNS sanity preserved)", __FUNCTION__);
+            LOGV("%s: Read overflow (ECNS sanity preserved)", __FUNCTION__);
         }
         mEcnsReadLock.unlock();
         GETTIMEOFDAY(&mtv8, NULL);
diff --git a/libaudio/AudioPostProcessor.h b/libaudio/AudioPostProcessor.h
index 0d8201d..5ecf898 100644
--- a/libaudio/AudioPostProcessor.h
+++ b/libaudio/AudioPostProcessor.h
@@ -18,12 +18,19 @@
 #define ANDROID_AUDIO_POST_PROCESSOR_H
 #ifdef USE_PROPRIETARY_AUDIO_EXTENSIONS
 
+#include <utils/threads.h>
+
 extern "C" {
 #include "cto_audio_mm.h"
 }
 #include "mot_acoustics.h"
 
-namespace android {
+namespace android_audio_legacy {
+    using android::Mutex;
+    using android::AutoMutex;
+    using android::Condition;
+    using android::Thread;
+    using android::sp;
 
 class AudioPostProcessor
 {
@@ -37,12 +44,20 @@
             void        doMmProcessing(void * buffer, int numSamples);
             int         getEcnsRate(void);
 
-            void        enableEcns(bool value);
+            // voice processing IDs for enableEcns()
+            enum {
+                AEC = 0x1,   // AEC is enabled
+                NS = 0x2     // NS is enabled
+            };
+            // enable or disable voice processing according to bit field passed
+            void        enableEcns(int value);
+            bool        isEcnsEnabled(void) { return (mEcnsEnabled != 0); }
+            bool        isEcEnabled(void) { return !!(mEcnsEnabled & AEC); }
+
             int         writeDownlinkEcns(int fd, void * buffer,
                                           bool stereo, int bytes, Mutex * fdLockp);
             int         read(int fd, void * buffer, int bytes, int rate);
             int         applyUplinkEcns(void * buffer, int bytes, int rate);
-            bool        isEcnsEnabled(void) { return mEcnsEnabled; };
 
 private:
             void        configMmAudio(void);
@@ -68,7 +83,7 @@
         // EC/NS configuration etc.
             Mutex       mEcnsBufLock;
             Condition   mEcnsBufCond;  // Signal to unblock write thread
-            bool        mEcnsEnabled; // Enabled by libaudio
+            int         mEcnsEnabled; // Enabled by libaudio
             bool        mEcnsRunning; // ECNS module init done by read thread
             int         mEcnsRate;
             void *      mEcnsScratchBuf;  // holding cell for downlink speech "consumed".
diff --git a/media_profiles.xml b/media_profiles.xml
index f1216ea..d6961e8 100644
--- a/media_profiles.xml
+++ b/media_profiles.xml
@@ -70,6 +70,11 @@
   <!ELEMENT AudioDecoderCap EMPTY>
   <!ATTLIST AudioDecoderCap name (wma) #REQUIRED>
   <!ATTLIST AudioDecoderCap enabled (true|false) #REQUIRED>
+  <!ELEMENT VideoEditorCap EMPTY>
+  <!ATTLIST VideoEditorCap maxInputFrameWidth CDATA #REQUIRED>
+  <!ATTLIST VideoEditorCap maxInputFrameHeight CDATA #REQUIRED>
+  <!ATTLIST VideoEditorCap maxOutputFrameWidth CDATA #REQUIRED>
+  <!ATTLIST VideoEditorCap maxOutputFrameHeight CDATA #REQUIRED>
 ]>
 <!--
      This file is used to declare the multimedia profiles and capabilities
@@ -365,4 +370,7 @@
 
   <VideoDecoderCap name="wmv" enabled="false"/>
   <AudioDecoderCap name="wma" enabled="false"/>
+  <VideoEditorCap maxInputFrameWidth="1280"
+      maxInputFrameHeight="720" maxOutputFrameWidth="1280"
+      maxOutputFrameHeight="720"/>
 </MediaSettings>
diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml
index 0ef686b..ec460b0 100644
--- a/overlay/frameworks/base/core/res/res/values/config.xml
+++ b/overlay/frameworks/base/core/res/res/values/config.xml
@@ -68,7 +68,7 @@
     </string-array>
 
     <!-- Array of allowable ConnectivityManager network types for tethering -->
-    <integer-array translatable = "false" name="config_tether_upstream_types">
+    <integer-array translatable="false" name="config_tether_upstream_types">
         <item>0</item>
         <item>1</item>
         <item>5</item>
@@ -79,7 +79,7 @@
          Wifi interfaces.  If the device doesn't want to support tethering over Wifi this
          should be empty.  An example would be "softap.*" -->
     <string-array translatable="false" name="config_tether_wifi_regexs">
-        <item>"wl0.1"</item>
+        <item>"wlan0"</item>
     </string-array>
 
     <!-- List of regexpressions describing the interface (if any) that represent tetherable
@@ -222,4 +222,5 @@
     <!-- When a database query is executed, the results retuned are paginated
          in pages of size (in KB) indicated by this value -->
     <integer name="config_cursorWindowSize">2048</integer>
+
 </resources>
diff --git a/overlay/frameworks/base/core/res/res/xml/storage_list.xml b/overlay/frameworks/base/core/res/res/xml/storage_list.xml
index 10a0373..9679904 100644
--- a/overlay/frameworks/base/core/res/res/xml/storage_list.xml
+++ b/overlay/frameworks/base/core/res/res/xml/storage_list.xml
@@ -28,17 +28,22 @@
         emulated:   the storage is emulated via the FUSE sdcard daemon
         mtp-reserve: number of megabytes of storage MTP should reserve for free storage
                      (used for emulated storage that is shared with system's data partition)
+        allowMassStorage: (boolean) true if this volume can be shared via USB mass storage
+        maxFileSize: (integer) maximum file size in megabytes
 
       A storage should not have both emulated and removable set to true
 -->
 
 <StorageList xmlns:android="http://schemas.android.com/apk/res/android">
+    <!-- internal emulated storage -->
     <storage android:mountPoint="/mnt/sdcard"
-    		 android:storageDescription="@string/storage_internal"
-    		 android:primary="true"
-    		 android:emulated="true"
-    		 android:mtpReserve="100" />
+            android:storageDescription="@string/storage_internal"
+            android:primary="true"
+            android:emulated="true"
+            android:mtpReserve="100" />
+    <!-- external SD card -->
     <storage android:mountPoint="/mnt/external1"
-    		 android:storageDescription="@string/storage_sd_card"
-    		 android:removable="true" />
+            android:storageDescription="@string/storage_sd_card"
+            android:removable="true"
+            android:maxFileSize="4096" />
 </StorageList>
diff --git a/overlay/frameworks/base/packages/SettingsProvider/res/values/defaults.xml b/overlay/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
index d457809..71f9933 100644
--- a/overlay/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
+++ b/overlay/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
@@ -21,6 +21,4 @@
     <integer name="def_screen_off_timeout">120000</integer>
     <!-- Set the automatic brightness mode on by default -->
     <bool name="def_screen_brightness_automatic_mode">true</bool>
-    <!-- Notifications use ringer volume - not in tablets with no voice capability -->
-    <bool name="def_notifications_use_ring_volume">false</bool>
 </resources>
diff --git a/overlay/packages/apps/Launcher2/res/values/config.xml b/overlay/packages/apps/Launcher2/res/values/config.xml
deleted file mode 100644
index 197889b..0000000
--- a/overlay/packages/apps/Launcher2/res/values/config.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-<resources>
-    <bool name="config_hardwareAccelerated">true</bool>
-</resources>
diff --git a/overlay/packages/apps/Settings/res/values/bools.xml b/overlay/packages/apps/Settings/res/values/bools.xml
new file mode 100644
index 0000000..61e1d03
--- /dev/null
+++ b/overlay/packages/apps/Settings/res/values/bools.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+-->
+
+<resources>
+    <!-- No powercontrol widget for tablets -->
+    <bool name="has_powercontrol_widget">false</bool>
+</resources>
diff --git a/vendorsetup.sh b/vendorsetup.sh
new file mode 100644
index 0000000..1d1ea8d
--- /dev/null
+++ b/vendorsetup.sh
@@ -0,0 +1,23 @@
+#
+# Copyright (C) 2008 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.
+#
+
+# This file is executed by build/envsetup.sh, and can use anything
+# defined in envsetup.sh.
+#
+# In particular, you can add lunch options with the add_lunch_combo
+# function: add_lunch_combo generic-eng
+
+add_lunch_combo full_wingray-userdebug