auto import from //branches/cupcake/...@126645
diff --git a/cmds/runtime/Android.mk b/cmds/runtime/Android.mk
index 00fa8a2..521eb2b 100644
--- a/cmds/runtime/Android.mk
+++ b/cmds/runtime/Android.mk
@@ -14,7 +14,7 @@
 	libcutils \
 	libui \
 	libsystem_server \
-	libhardware
+	libhardware_legacy
 
 LOCAL_C_INCLUDES := \
 	$(JNI_H_INCLUDE)
diff --git a/include/private/opengles/gl_context.h b/include/private/opengles/gl_context.h
index 2aa78d8..3056139 100644
--- a/include/private/opengles/gl_context.h
+++ b/include/private/opengles/gl_context.h
@@ -22,7 +22,7 @@
 #include <sys/types.h>
 #include <pthread.h>
 #ifdef HAVE_ANDROID_OS
-#include <sys/tls.h>
+#include <bionic_tls.h>
 #endif
 
 #include <private/pixelflinger/ggl_context.h>
diff --git a/include/ui/EventHub.h b/include/ui/EventHub.h
index 101a920..017c145 100644
--- a/include/ui/EventHub.h
+++ b/include/ui/EventHub.h
@@ -50,8 +50,9 @@
     // bit fields for classes of devices.
     enum {
         CLASS_KEYBOARD      = 0x00000001,
-        CLASS_TOUCHSCREEN   = 0x00000002,
-        CLASS_TRACKBALL     = 0x00000004
+        CLASS_ALPHAKEY      = 0x00000002,
+        CLASS_TOUCHSCREEN   = 0x00000004,
+        CLASS_TRACKBALL     = 0x00000008
     };
     uint32_t getDeviceClasses(int32_t deviceId) const;
     
diff --git a/include/ui/Overlay.h b/include/ui/Overlay.h
index 23cdee8..9c7bc47 100644
--- a/include/ui/Overlay.h
+++ b/include/ui/Overlay.h
@@ -54,7 +54,7 @@
     virtual ~OverlayRef();
 
     overlay_handle_t const *mOverlayHandle;
-    sp<IOverlay> mOverlayChanel;
+    sp<IOverlay> mOverlayChannel;
     uint32_t mWidth;
     uint32_t mHeight;
     int32_t  mFormat;
@@ -77,10 +77,10 @@
     overlay_handle_t const* getHandleRef() const;
 
     /* blocks until an overlay buffer is available and return that buffer. */
-    overlay_buffer_t dequeueBuffer();
+    status_t dequeueBuffer(overlay_buffer_t* buffer);
 
     /* release the overlay buffer and post it */
-    int queueBuffer(overlay_buffer_t buffer);
+    status_t queueBuffer(overlay_buffer_t buffer);
 
     /* returns the address of a given buffer if supported, NULL otherwise. */
     void* getBufferAddress(overlay_buffer_t buffer);
diff --git a/include/ui/Surface.h b/include/ui/Surface.h
index 2e24f86..33953a9 100644
--- a/include/ui/Surface.h
+++ b/include/ui/Surface.h
@@ -92,6 +92,7 @@
     friend class MediaRecorder;
     // mediaplayer needs access to ISurface for display
     friend class MediaPlayer;
+    friend class Test;
     const sp<ISurface>& getISurface() const { return mSurface; }
 
     // can't be copied
diff --git a/include/ui/SurfaceComposerClient.h b/include/ui/SurfaceComposerClient.h
index 3b875be..5d9222d 100644
--- a/include/ui/SurfaceComposerClient.h
+++ b/include/ui/SurfaceComposerClient.h
@@ -72,7 +72,7 @@
     );
 
     // ------------------------------------------------------------------------
-    // Composer paramters
+    // Composer parameters
     // All composer parameters must be changed within a transaction
     // several surfaces can be updated in one transaction, all changes are
     // committed at once when the transaction is closed.
diff --git a/libs/audioflinger/A2dpAudioInterface.cpp b/libs/audioflinger/A2dpAudioInterface.cpp
index b2a8e96..7242575 100644
--- a/libs/audioflinger/A2dpAudioInterface.cpp
+++ b/libs/audioflinger/A2dpAudioInterface.cpp
@@ -92,6 +92,14 @@
 status_t A2dpAudioInterface::setParameter(const char *key, const char *value)
 {
     LOGD("setParameter %s,%s\n", key, value);
+    
+    if (!key || !value)
+        return -EINVAL;
+    
+    if (strcmp(key, "a2dp_sink_address") == 0) {        
+        return mOutput->setAddress(value);
+    }
+
     return 0;
 }
 
@@ -121,6 +129,8 @@
     mFd(-1), mStandby(false), mStartCount(0), mRetryCount(0), mData(NULL),
     mInitialized(false)
 {
+    // use any address by default
+    strncpy(mA2dpAddress, "00:00:00:00:00:00", sizeof(mA2dpAddress));
 }
 
 status_t A2dpAudioInterface::A2dpAudioStreamOut::set(
@@ -154,7 +164,7 @@
     size_t remaining = bytes;
 
     if (!mInitialized) {
-        status = a2dp_init("00:00:00:00:00:00", 44100, 2, &mData);
+        status = a2dp_init(mA2dpAddress, 44100, 2, &mData);
         if (status < 0) {
             LOGE("a2dp_init failed err: %d\n", status);
             goto Error;
@@ -196,6 +206,24 @@
     return result;
 }
 
+status_t A2dpAudioInterface::A2dpAudioStreamOut::setAddress(const char* address)
+{
+    if (strlen(address) < sizeof(mA2dpAddress))
+        return -EINVAL;
+
+    if (strcmp(address, mA2dpAddress)) {
+        strcpy(mA2dpAddress, address);
+        
+        if (mInitialized) {
+            a2dp_cleanup(mData);
+            mData = NULL;
+            mInitialized = false;
+        }
+    }
+    
+    return NO_ERROR;
+}
+
 status_t A2dpAudioInterface::A2dpAudioStreamOut::dump(int fd, const Vector<String16>& args)
 {
     return NO_ERROR;
diff --git a/libs/audioflinger/A2dpAudioInterface.h b/libs/audioflinger/A2dpAudioInterface.h
index b8119a1..2197d0e 100644
--- a/libs/audioflinger/A2dpAudioInterface.h
+++ b/libs/audioflinger/A2dpAudioInterface.h
@@ -22,7 +22,7 @@
 
 #include <utils/threads.h>
 
-#include <hardware/AudioHardwareBase.h>
+#include <hardware_legacy/AudioHardwareBase.h>
 
 
 namespace android {
@@ -74,7 +74,7 @@
                                 uint32_t sampleRate);
         virtual uint32_t    sampleRate() const { return 44100; }
         // SBC codec wants a multiple of 512
-        virtual size_t      bufferSize() const { return 512 * 30; }
+        virtual size_t      bufferSize() const { return 512 * 20; }
         virtual int         channelCount() const { return 2; }
         virtual int         format() const { return AudioSystem::PCM_16_BIT; }
         virtual uint32_t    latency() const { return ((1000*channelCount()*bufferSize())/frameSize())/sampleRate() + 200; }
@@ -84,10 +84,15 @@
         virtual status_t    dump(int fd, const Vector<String16>& args);
 
     private:
+        friend class A2dpAudioInterface;
+        status_t            setAddress(const char* address);
+
+    private:
                 int         mFd;
                 bool        mStandby;
                 int         mStartCount;
                 int         mRetryCount;
+                char        mA2dpAddress[20];
                 void*       mData;
                 bool        mInitialized;
     };
diff --git a/libs/audioflinger/Android.mk b/libs/audioflinger/Android.mk
index d16e3e1..50d516b 100644
--- a/libs/audioflinger/Android.mk
+++ b/libs/audioflinger/Android.mk
@@ -12,7 +12,7 @@
     libcutils \
     libutils \
     libmedia \
-    libhardware
+    libhardware_legacy
 
 ifeq ($(strip $(BOARD_USES_GENERIC_AUDIO)),true)
   LOCAL_CFLAGS += -DGENERIC_AUDIO
@@ -35,7 +35,7 @@
     libcutils \
     libutils \
     libmedia \
-    libhardware
+    libhardware_legacy
 
 ifeq ($(strip $(BOARD_USES_GENERIC_AUDIO)),true)
   LOCAL_STATIC_LIBRARIES += libaudiointerface
diff --git a/libs/audioflinger/AudioDumpInterface.h b/libs/audioflinger/AudioDumpInterface.h
index 82b5250..42204d6 100644
--- a/libs/audioflinger/AudioDumpInterface.h
+++ b/libs/audioflinger/AudioDumpInterface.h
@@ -21,7 +21,7 @@
 #include <stdint.h>
 #include <sys/types.h>
 
-#include <hardware/AudioHardwareBase.h>
+#include <hardware_legacy/AudioHardwareBase.h>
 
 namespace android {
 
diff --git a/libs/audioflinger/AudioFlinger.cpp b/libs/audioflinger/AudioFlinger.cpp
index d4692ad..51b800c 100644
--- a/libs/audioflinger/AudioFlinger.cpp
+++ b/libs/audioflinger/AudioFlinger.cpp
@@ -38,7 +38,7 @@
 
 #include <private/media/AudioTrackShared.h>
 
-#include <hardware/AudioHardwareInterface.h>
+#include <hardware_legacy/AudioHardwareInterface.h>
 
 #include "AudioMixer.h"
 #include "AudioFlinger.h"
@@ -832,10 +832,15 @@
 
 status_t AudioFlinger::setParameter(const char* key, const char* value)
 {
-    status_t result;
+    status_t result, result2;
     AutoMutex lock(mHardwareLock);
     mHardwareStatus = AUDIO_SET_PARAMETER;
     result = mAudioHardware->setParameter(key, value);
+    if (mA2dpAudioInterface) {
+        result2 = mA2dpAudioInterface->setParameter(key, value);
+        if (result2)
+            result = result2;
+    }
     mHardwareStatus = AUDIO_HW_IDLE;
     return result;
 }
diff --git a/libs/audioflinger/AudioFlinger.h b/libs/audioflinger/AudioFlinger.h
index 7c84e62..90bc72d 100644
--- a/libs/audioflinger/AudioFlinger.h
+++ b/libs/audioflinger/AudioFlinger.h
@@ -33,7 +33,7 @@
 #include <utils/KeyedVector.h>
 #include <utils/SortedVector.h>
 
-#include <hardware/AudioHardwareInterface.h>
+#include <hardware_legacy/AudioHardwareInterface.h>
 
 #include "AudioBufferProvider.h"
 
diff --git a/libs/audioflinger/AudioHardwareGeneric.h b/libs/audioflinger/AudioHardwareGeneric.h
index bc006b8..a7822e1 100644
--- a/libs/audioflinger/AudioHardwareGeneric.h
+++ b/libs/audioflinger/AudioHardwareGeneric.h
@@ -23,7 +23,7 @@
 
 #include <utils/threads.h>
 
-#include <hardware/AudioHardwareBase.h>
+#include <hardware_legacy/AudioHardwareBase.h>
 
 namespace android {
 
diff --git a/libs/audioflinger/AudioHardwareStub.h b/libs/audioflinger/AudioHardwareStub.h
index 7ec5b95..24736ed 100644
--- a/libs/audioflinger/AudioHardwareStub.h
+++ b/libs/audioflinger/AudioHardwareStub.h
@@ -21,7 +21,7 @@
 #include <stdint.h>
 #include <sys/types.h>
 
-#include <hardware/AudioHardwareBase.h>
+#include <hardware_legacy/AudioHardwareBase.h>
 
 namespace android {
 
diff --git a/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp b/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp
index 19e32ec..92588fa 100644
--- a/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp
+++ b/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp
@@ -23,6 +23,8 @@
 
 #include <GLES/egl.h>
 
+#include <cutils/properties.h>
+
 #include <utils/Log.h>
 
 #include <ui/EGLDisplaySurface.h>
@@ -193,11 +195,14 @@
     }
     mRefreshRate = 60.f;    // TODO: get the real refresh rate 
     
-    // compute a "density" automatically as a scale factor from 160 dpi
-    // TODO: this value should be calculated a compile time based on the
-    // board.
-    mDensity = floorf((mDpiX>mDpiY ? mDpiX : mDpiY)*0.1f + 0.5f) * (10.0f/160.0f);
-    LOGI("density = %f", mDensity);
+    
+    char property[PROPERTY_VALUE_MAX];
+    if (property_get("ro.sf.lcd_density", property, NULL) <= 0) {
+        LOGW("ro.sf.lcd_density not defined, using 160 dpi by default.");
+        strcpy(property, "160");
+    }
+    mDensity = atoi(property) * (1.0f/160.0f);
+
 
     /*
      * Create our OpenGL ES context
diff --git a/libs/surfaceflinger/LayerBuffer.cpp b/libs/surfaceflinger/LayerBuffer.cpp
index 700e4f5..c9cebf4 100644
--- a/libs/surfaceflinger/LayerBuffer.cpp
+++ b/libs/surfaceflinger/LayerBuffer.cpp
@@ -95,10 +95,9 @@
 
 void LayerBuffer::unregisterBuffers()
 {
-    sp<Source> source(getSource());
+    sp<Source> source(clearSource());
     if (source != 0)
         source->unregisterBuffers();
-    // XXX: clear mSource
 }
 
 uint32_t LayerBuffer::doTransaction(uint32_t flags)
@@ -172,6 +171,14 @@
     return mSource;
 }
 
+sp<LayerBuffer::Source> LayerBuffer::clearSource() {
+    sp<Source> source;
+    Mutex::Autolock _l(mLock);
+    source = mSource;
+    mSource.clear();
+    return source;
+}
+
 // ============================================================================
 // LayerBuffer::SurfaceBuffer
 // ============================================================================
@@ -477,15 +484,16 @@
 LayerBuffer::OverlaySource::OverlaySource(LayerBuffer& layer,
         sp<OverlayRef>* overlayRef, 
         uint32_t w, uint32_t h, int32_t format)
-    : Source(layer), mVisibilityChanged(false), mOverlay(0), mOverlayHandle(0)
+    : Source(layer), mVisibilityChanged(false),
+    mOverlay(0), mOverlayHandle(0), mOverlayDevice(0)
 {
     overlay_control_device_t* overlay_dev = mLayer.mFlinger->getOverlayEngine();
-
     if (overlay_dev == NULL) {
         // overlays not supported
         return;
     }
 
+    mOverlayDevice = overlay_dev;
     overlay_t* overlay = overlay_dev->createOverlay(overlay_dev, w, h, format);
     if (overlay == NULL) {
         // couldn't create the overlay (no memory? no more overlays?)
@@ -507,14 +515,18 @@
     
     // NOTE: here it's okay to acquire a reference to "this"m as long as
     // the reference is not released before we leave the ctor.
-    sp<OverlayChanel> chanel = new OverlayChanel(this);
+    sp<OverlayChannel> channel = new OverlayChannel(this);
 
-    *overlayRef = new OverlayRef(mOverlayHandle, chanel,
+    *overlayRef = new OverlayRef(mOverlayHandle, channel,
             mWidth, mHeight, mFormat, mWidthStride, mHeightStride);
 }
 
 LayerBuffer::OverlaySource::~OverlaySource()
-{    
+{
+    if (mOverlay && mOverlayDevice) {
+        overlay_control_device_t* overlay_dev = mOverlayDevice;
+        overlay_dev->destroyOverlay(overlay_dev, mOverlay);
+    }
 }
 
 void LayerBuffer::OverlaySource::onTransaction(uint32_t flags)
@@ -543,8 +555,7 @@
             // we need a lock here to protect "destroy"
             Mutex::Autolock _l(mLock);
             if (mOverlay) {
-                overlay_control_device_t* overlay_dev = 
-                    mLayer.mFlinger->getOverlayEngine();
+                overlay_control_device_t* overlay_dev = mOverlayDevice;
                 overlay_dev->setPosition(overlay_dev, mOverlay, x,y,w,h);
                 overlay_dev->setParameter(overlay_dev, mOverlay, 
                         OVERLAY_TRANSFORM, mLayer.getOrientation());
@@ -555,11 +566,16 @@
 
 void LayerBuffer::OverlaySource::serverDestroy() 
 {
+    mLayer.clearSource();
+    destroyOverlay();
+}
+
+void LayerBuffer::OverlaySource::destroyOverlay() 
+{
     // we need a lock here to protect "onVisibilityResolved"
     Mutex::Autolock _l(mLock);
     if (mOverlay) {
-        overlay_control_device_t* overlay_dev = 
-                mLayer.mFlinger->getOverlayEngine();
+        overlay_control_device_t* overlay_dev = mOverlayDevice;
         overlay_dev->destroyOverlay(overlay_dev, mOverlay);
         mOverlay = 0;
     }
diff --git a/libs/surfaceflinger/LayerBuffer.h b/libs/surfaceflinger/LayerBuffer.h
index 63ec2cf..3286535 100644
--- a/libs/surfaceflinger/LayerBuffer.h
+++ b/libs/surfaceflinger/LayerBuffer.h
@@ -75,6 +75,7 @@
     sp<OverlayRef> createOverlay(uint32_t w, uint32_t h, int32_t format);
     
     sp<Source> getSource() const;
+    sp<Source> clearSource();
     void setNeedsBlending(bool blending);
     const Rect& getTransformedBounds() const {
         return mTransformedBounds;
@@ -145,7 +146,8 @@
         virtual void onVisibilityResolved(const Transform& planeTransform);
     private:
         void serverDestroy(); 
-        class OverlayChanel : public BnOverlay {
+        void destroyOverlay(); 
+        class OverlayChannel : public BnOverlay {
             mutable Mutex mLock;
             sp<OverlaySource> mSource;
             virtual void destroy() {
@@ -160,15 +162,16 @@
                 }
             }
         public:
-            OverlayChanel(const sp<OverlaySource>& source)
+            OverlayChannel(const sp<OverlaySource>& source)
                 : mSource(source) {
             }
         };
-        friend class OverlayChanel;
+        friend class OverlayChannel;
         bool mVisibilityChanged;
 
         overlay_t* mOverlay;        
         overlay_handle_t const *mOverlayHandle;
+        overlay_control_device_t* mOverlayDevice;
         uint32_t mWidth;
         uint32_t mHeight;
         int32_t mFormat;
diff --git a/libs/surfaceflinger/tests/Android.mk b/libs/surfaceflinger/tests/Android.mk
new file mode 100644
index 0000000..5053e7d
--- /dev/null
+++ b/libs/surfaceflinger/tests/Android.mk
@@ -0,0 +1 @@
+include $(call all-subdir-makefiles)
diff --git a/libs/surfaceflinger/tests/overlays/Android.mk b/libs/surfaceflinger/tests/overlays/Android.mk
new file mode 100644
index 0000000..dc47e45
--- /dev/null
+++ b/libs/surfaceflinger/tests/overlays/Android.mk
@@ -0,0 +1,16 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+	overlays.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+	libcutils \
+	libutils \
+    libui
+
+LOCAL_MODULE:= test-overlays
+
+LOCAL_MODULE_TAGS := tests
+
+include $(BUILD_EXECUTABLE)
diff --git a/libs/surfaceflinger/tests/overlays/overlays.cpp b/libs/surfaceflinger/tests/overlays/overlays.cpp
new file mode 100644
index 0000000..f3c046f
--- /dev/null
+++ b/libs/surfaceflinger/tests/overlays/overlays.cpp
@@ -0,0 +1,58 @@
+#include <utils/IPCThreadState.h>
+#include <utils/ProcessState.h>
+#include <utils/IServiceManager.h>
+#include <utils/Log.h>
+
+#include <ui/Surface.h>
+#include <ui/ISurface.h>
+#include <ui/Overlay.h>
+#include <ui/SurfaceComposerClient.h>
+
+using namespace android;
+
+namespace android {
+class Test {
+public:
+    static const sp<ISurface>& getISurface(const sp<Surface>& s) {
+        return s->getISurface();
+    }
+};
+};
+
+int main(int argc, char** argv)
+{
+    // set up the thread-pool
+    sp<ProcessState> proc(ProcessState::self());
+    ProcessState::self()->startThreadPool();
+
+    // create a client to surfaceflinger
+    sp<SurfaceComposerClient> client = new SurfaceComposerClient();
+    
+    // create pushbuffer surface
+    sp<Surface> surface = client->createSurface(getpid(), 0, 320, 240, 
+            PIXEL_FORMAT_UNKNOWN, ISurfaceComposer::ePushBuffers);
+
+    // get to the isurface
+    sp<ISurface> isurface = Test::getISurface(surface);
+    printf("isurface = %p\n", isurface.get());
+    
+    // now request an overlay
+    sp<OverlayRef> ref = isurface->createOverlay(320, 240, PIXEL_FORMAT_RGB_565);
+    sp<Overlay> overlay = new Overlay(ref);
+    
+
+    /*
+     * here we can use the overlay API 
+     */
+    
+    overlay_buffer_t buffer; 
+    overlay->dequeueBuffer(&buffer);
+    printf("buffer = %p\n", buffer);
+    
+    void* address = overlay->getBufferAddress(buffer);
+    printf("address = %p\n", address);
+
+    overlay->queueBuffer(buffer);
+
+    return 0;
+}
diff --git a/libs/ui/Android.mk b/libs/ui/Android.mk
index 7b51300..f944357 100644
--- a/libs/ui/Android.mk
+++ b/libs/ui/Android.mk
@@ -33,7 +33,8 @@
 	libcutils \
 	libutils \
 	libpixelflinger \
-	libhardware
+	libhardware \
+	libhardware_legacy
 
 LOCAL_MODULE:= libui
 
diff --git a/libs/ui/EventHub.cpp b/libs/ui/EventHub.cpp
index abe7407..700aa3a 100644
--- a/libs/ui/EventHub.cpp
+++ b/libs/ui/EventHub.cpp
@@ -16,7 +16,7 @@
 //#define LOG_NDEBUG 0
 
 #include <ui/EventHub.h>
-#include <hardware/power.h>
+#include <hardware_legacy/power.h>
 
 #include <cutils/properties.h>
 #include <utils/IServiceManager.h>
@@ -520,6 +520,10 @@
         for (int i=0; i<((BTN_MISC+7)/8); i++) {
             if (key_bitmask[i] != 0) {
                 device->classes |= CLASS_KEYBOARD;
+                // 'Q' key support = cheap test of whether this is an alpha-capable kbd
+                if (test_bit(KEY_Q, key_bitmask)) {
+                    device->classes |= CLASS_ALPHAKEY;
+                }
                 break;
             }
         }
diff --git a/libs/ui/ISurface.cpp b/libs/ui/ISurface.cpp
index 54f78fe..6f3cd47 100644
--- a/libs/ui/ISurface.cpp
+++ b/libs/ui/ISurface.cpp
@@ -128,7 +128,7 @@
             int w = data.readInt32();
             int h = data.readInt32();
             int f = data.readInt32();
-            sp<OverlayRef> o = createOverlay(w, h, w);
+            sp<OverlayRef> o = createOverlay(w, h, f);
             return OverlayRef::writeToParcel(reply, o);
         } break;
         default:
diff --git a/libs/ui/Overlay.cpp b/libs/ui/Overlay.cpp
index a79950c..2745f52 100644
--- a/libs/ui/Overlay.cpp
+++ b/libs/ui/Overlay.cpp
@@ -31,10 +31,12 @@
 {
     mOverlayData = NULL;
     hw_module_t const* module;
-    if (hw_get_module(OVERLAY_HARDWARE_MODULE_ID, &module) == 0) {
-        if (overlay_data_open(module, &mOverlayData) == NO_ERROR) {
-            mStatus = mOverlayData->initialize(mOverlayData,
-                    overlayRef->mOverlayHandle);
+    if (overlayRef != 0) {
+        if (hw_get_module(OVERLAY_HARDWARE_MODULE_ID, &module) == 0) {
+            if (overlay_data_open(module, &mOverlayData) == NO_ERROR) {
+                mStatus = mOverlayData->initialize(mOverlayData,
+                        overlayRef->mOverlayHandle);
+            }
         }
     }
 }
@@ -45,23 +47,27 @@
     }
 }
 
-overlay_buffer_t Overlay::dequeueBuffer()
+status_t Overlay::dequeueBuffer(overlay_buffer_t* buffer)
 {
-    return mOverlayData->dequeueBuffer(mOverlayData);
+    if (mStatus != NO_ERROR) return mStatus;
+    return  mOverlayData->dequeueBuffer(mOverlayData, buffer);
 }
 
-int Overlay::queueBuffer(overlay_buffer_t buffer)
+status_t Overlay::queueBuffer(overlay_buffer_t buffer)
 {
+    if (mStatus != NO_ERROR) return mStatus;
     return mOverlayData->queueBuffer(mOverlayData, buffer);
 }
 
 void* Overlay::getBufferAddress(overlay_buffer_t buffer)
 {
+    if (mStatus != NO_ERROR) return NULL;
     return mOverlayData->getBufferAddress(mOverlayData, buffer);
 }
 
 void Overlay::destroy() {  
-    mOverlayRef->mOverlayChanel->destroy();
+    if (mStatus != NO_ERROR) return;
+    mOverlayRef->mOverlayChannel->destroy();
 }
 
 status_t Overlay::getStatus() const {
@@ -69,26 +75,32 @@
 }
 
 overlay_handle_t const* Overlay::getHandleRef() const {
+    if (mStatus != NO_ERROR) return NULL;
     return mOverlayRef->mOverlayHandle;
 }
 
 uint32_t Overlay::getWidth() const {
+    if (mStatus != NO_ERROR) return 0;
     return mOverlayRef->mWidth;
 }
 
 uint32_t Overlay::getHeight() const {
+    if (mStatus != NO_ERROR) return 0;
     return mOverlayRef->mHeight;
 }
 
 int32_t Overlay::getFormat() const {
+    if (mStatus != NO_ERROR) return -1;
     return mOverlayRef->mFormat;
 }
 
 int32_t Overlay::getWidthStride() const {
+    if (mStatus != NO_ERROR) return 0;
     return mOverlayRef->mWidthStride;
 }
 
 int32_t Overlay::getHeightStride() const {
+    if (mStatus != NO_ERROR) return 0;
     return mOverlayRef->mHeightStride;
 }
 // ----------------------------------------------------------------------------
@@ -100,9 +112,9 @@
 {    
 }
 
-OverlayRef::OverlayRef(overlay_handle_t const* handle, const sp<IOverlay>& chanel,
+OverlayRef::OverlayRef(overlay_handle_t const* handle, const sp<IOverlay>& channel,
          uint32_t w, uint32_t h, int32_t f, uint32_t ws, uint32_t hs)
-    : mOverlayHandle(handle), mOverlayChanel(chanel),
+    : mOverlayHandle(handle), mOverlayChannel(channel),
     mWidth(w), mHeight(h), mFormat(f), mWidthStride(ws), mHeightStride(hs),
     mOwnHandle(false)
 {
@@ -141,7 +153,7 @@
             handle->data[i] = data.readInt32();
         result = new OverlayRef();
         result->mOverlayHandle = handle;
-        result->mOverlayChanel = overlay;
+        result->mOverlayChannel = overlay;
         result->mWidth = w;
         result->mHeight = h;
         result->mFormat = f;
@@ -153,7 +165,7 @@
 
 status_t OverlayRef::writeToParcel(Parcel* reply, const sp<OverlayRef>& o) {
     if (o != NULL) {
-        reply->writeStrongBinder(o->mOverlayChanel->asBinder());
+        reply->writeStrongBinder(o->mOverlayChannel->asBinder());
         reply->writeInt32(o->mWidth);
         reply->writeInt32(o->mHeight);
         reply->writeInt32(o->mFormat);
@@ -176,4 +188,3 @@
 // ----------------------------------------------------------------------------
 
 }; // namespace android
-
diff --git a/opengl/libGLES_CM/Android.mk b/opengl/libGLES_CM/Android.mk
index a0081ef..e350e02 100644
--- a/opengl/libGLES_CM/Android.mk
+++ b/opengl/libGLES_CM/Android.mk
@@ -15,7 +15,9 @@
 # needed on sim build because of weird logging issues
 ifeq ($(TARGET_SIMULATOR),true)
 else
-	LOCAL_SHARED_LIBRARIES += libdl
+    LOCAL_SHARED_LIBRARIES += libdl
+    # we need to access the Bionic private header <bionic_tls.h>
+    LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../bionic/libc/private
 endif
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/opengl/libGLES_CM/gl_wrapper.cpp b/opengl/libGLES_CM/gl_wrapper.cpp
index 3b7f45e..3197535 100644
--- a/opengl/libGLES_CM/gl_wrapper.cpp
+++ b/opengl/libGLES_CM/gl_wrapper.cpp
@@ -203,7 +203,8 @@
 
 #if defined(HAVE_ANDROID_OS) && !USE_SLOW_BINDING && !GL_LOGGER
 
-#include <sys/tls.h>
+/* special private C library header */
+#include <bionic_tls.h>
 // We have a dedicated TLS slot in bionic
 static inline void setGlThreadSpecific(gl_hooks_t const *value) {
     ((uint32_t *)__get_tls())[TLS_SLOT_OPENGL_API] = (uint32_t)value;
diff --git a/opengl/libagl/Android.mk b/opengl/libagl/Android.mk
index a3dff76..99efe4c 100644
--- a/opengl/libagl/Android.mk
+++ b/opengl/libagl/Android.mk
@@ -27,6 +27,11 @@
 	LOCAL_CFLAGS += -fstrict-aliasing
 endif
 
+ifneq ($(TARGET_SIMULATOR),true)
+    # we need to access the private Bionic header <bionic_tls.h>
+    LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../bionic/libc/private
+endif
+
 LOCAL_SHARED_LIBRARIES := libcutils libutils libpixelflinger
 LOCAL_LDLIBS := -lpthread -ldl
 LOCAL_MODULE:= libagl