Merge change 9004

* changes:
  Fix NullPointerException when checking if its a sinkDevice.
diff --git a/libs/audioflinger/Android.mk b/libs/audioflinger/Android.mk
index c10e02b..f5c03bb 100644
--- a/libs/audioflinger/Android.mk
+++ b/libs/audioflinger/Android.mk
@@ -107,6 +107,7 @@
 
 ifeq ($(BOARD_HAVE_BLUETOOTH),true)
   LOCAL_CFLAGS += -DWITH_BLUETOOTH -DWITH_A2DP
+  LOCAL_SHARED_LIBRARIES += liba2dp
 endif
 
 ifeq ($(AUDIO_POLICY_TEST),true)
diff --git a/libs/audioflinger/AudioFlinger.cpp b/libs/audioflinger/AudioFlinger.cpp
index 1336131..232ffb0 100644
--- a/libs/audioflinger/AudioFlinger.cpp
+++ b/libs/audioflinger/AudioFlinger.cpp
@@ -3443,8 +3443,8 @@
             srcThread->getTracks(tracks, activeTracks, stream);
             if (tracks.size()) {
                 dstThread->putTracks(tracks, activeTracks);
-                dstThread->sendConfigEvent(AudioSystem::STREAM_CONFIG_CHANGED, stream);
             }
+            dstThread->sendConfigEvent(AudioSystem::STREAM_CONFIG_CHANGED, stream);
         }
     }
 
diff --git a/libs/surfaceflinger/LayerBitmap.cpp b/libs/surfaceflinger/LayerBitmap.cpp
index 9fffbbf..ff49c87 100644
--- a/libs/surfaceflinger/LayerBitmap.cpp
+++ b/libs/surfaceflinger/LayerBitmap.cpp
@@ -177,22 +177,17 @@
 sp<Buffer> LayerBitmap::allocate()
 {
     Mutex::Autolock _l(mLock);
-    sp<Buffer> buffer(mBuffer);
-    const uint32_t w = mWidth; 
-    const uint32_t h = mHeight;
-    if (buffer!=0 && (w != buffer->getWidth() || h != buffer->getHeight())) {
-        surface_info_t* info = mInfo;
-        buffer = new Buffer(w, h, mFormat, mFlags);
-        status_t err = buffer->initCheck();
-        if (LIKELY(err == NO_ERROR)) {
-            info->flags  = surface_info_t::eBufferDirty;
-            info->status = NO_ERROR;
-        } else {
-            memset(info, 0, sizeof(surface_info_t));
-            info->status = NO_MEMORY;
-        }
-        mBuffer = buffer;
+    surface_info_t* info = mInfo;
+    sp<Buffer> buffer = new Buffer(mWidth, mHeight, mFormat, mFlags);
+    status_t err = buffer->initCheck();
+    if (LIKELY(err == NO_ERROR)) {
+        info->flags  = surface_info_t::eBufferDirty;
+        info->status = NO_ERROR;
+    } else {
+        memset(info, 0, sizeof(surface_info_t));
+        info->status = NO_MEMORY;
     }
+    mBuffer = buffer;
     return buffer;
 }
 
diff --git a/libs/surfaceflinger/SurfaceFlinger.cpp b/libs/surfaceflinger/SurfaceFlinger.cpp
index 7a7574f..102899c 100644
--- a/libs/surfaceflinger/SurfaceFlinger.cpp
+++ b/libs/surfaceflinger/SurfaceFlinger.cpp
@@ -650,6 +650,7 @@
                 if (currentLayers.indexOf( layer ) < 0) {
                     // this layer is not visible anymore
                     ditchedLayers.add(layer);
+                    mDirtyRegionRemovedLayer.orSelf(layer->visibleRegionScreen);
                 }
             }
         }
@@ -685,17 +686,15 @@
         layer->validateVisibility(planeTransform);
 
         // start with the whole surface at its current location
-        const Layer::State& s = layer->drawingState();
-        const Rect bounds(layer->visibleBounds());
+        const Layer::State& s(layer->drawingState());
 
         // handle hidden surfaces by setting the visible region to empty
         Region opaqueRegion;
         Region visibleRegion;
         Region coveredRegion;
-        if (UNLIKELY((s.flags & ISurfaceComposer::eLayerHidden) || !s.alpha)) {
-            visibleRegion.clear();
-        } else {
+        if (LIKELY(!(s.flags & ISurfaceComposer::eLayerHidden) && s.alpha)) {
             const bool translucent = layer->needsBlending();
+            const Rect bounds(layer->visibleBounds());
             visibleRegion.set(bounds);
             coveredRegion = visibleRegion;
 
@@ -742,12 +741,16 @@
         layer->setVisibleRegion(visibleRegion);
         layer->setCoveredRegion(coveredRegion);
 
-        // If a secure layer is partially visible, lock down the screen!
+        // If a secure layer is partially visible, lock-down the screen!
         if (layer->isSecure() && !visibleRegion.isEmpty()) {
             secureFrameBuffer = true;
         }
     }
 
+    // invalidate the areas where a layer was removed
+    dirtyRegion.orSelf(mDirtyRegionRemovedLayer);
+    mDirtyRegionRemovedLayer.clear();
+
     mSecureFrameBuffer = secureFrameBuffer;
     opaqueRegion = aboveOpaqueLayers;
 }
diff --git a/libs/surfaceflinger/SurfaceFlinger.h b/libs/surfaceflinger/SurfaceFlinger.h
index e8687a7..2569a0f 100644
--- a/libs/surfaceflinger/SurfaceFlinger.h
+++ b/libs/surfaceflinger/SurfaceFlinger.h
@@ -334,6 +334,7 @@
                 // Can only accessed from the main thread, these members
                 // don't need synchronization
                 Region                      mDirtyRegion;
+                Region                      mDirtyRegionRemovedLayer;
                 Region                      mInvalidRegion;
                 Region                      mWormholeRegion;
                 wp<Client>                  mLastScheduledBroadcast;
diff --git a/libs/utils/BackupData.cpp b/libs/utils/BackupData.cpp
index be04777..c51d989 100644
--- a/libs/utils/BackupData.cpp
+++ b/libs/utils/BackupData.cpp
@@ -196,6 +196,7 @@
             } else { \
                 m_status = errno; \
             } \
+            LOGD("CHECK_SIZE failed with at line %d m_status='%s'", __LINE__, strerror(m_status)); \
             return m_status; \
         } \
     } while(0)
@@ -203,6 +204,7 @@
     do { \
         status_t err = skip_padding(); \
         if (err != NO_ERROR) { \
+            LOGD("SKIP_PADDING FAILED at line %d", __LINE__); \
             m_status = err; \
             return err; \
         } \
@@ -218,10 +220,19 @@
 
     int amt;
 
-    // No error checking here, in case we're at the end of the stream.  Just let read() fail.
-    skip_padding();
+    amt = skip_padding();
+    if (amt == EIO) {
+        *done = true;
+        return NO_ERROR;
+    }
+    else if (amt != NO_ERROR) {
+        return amt;
+    }
     amt = read(m_fd, &m_header, sizeof(m_header));
     *done = m_done = (amt == 0);
+    if (*done) {
+        return NO_ERROR;
+    }
     CHECK_SIZE(amt, sizeof(m_header));
     m_pos += sizeof(m_header);
     if (type) {
diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp
index 7f3f114..445e681 100644
--- a/opengl/libs/EGL/Loader.cpp
+++ b/opengl/libs/EGL/Loader.cpp
@@ -149,7 +149,7 @@
             hnd = new driver_t(dso);
         } else {
             // Always load EGL first
-            snprintf(path, PATH_MAX, "lib%s_%s.so", "EGL", tag);
+            snprintf(path, PATH_MAX, format, "EGL", tag);
             dso = load_driver(path, hooks, EGL);
             if (dso) {
                 hnd = new driver_t(dso);