fix [2132563] stuck in boot animation (framebuffer_device_open: Failed to create flip chain)
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp
index 99e513c..80c8ee4 100644
--- a/cmds/bootanimation/BootAnimation.cpp
+++ b/cmds/bootanimation/BootAnimation.cpp
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#define LOG_TAG "BootAnimation"
+
 #include <stdint.h>
 #include <sys/types.h>
 #include <math.h>
@@ -58,13 +60,29 @@
 }
 
 void BootAnimation::onFirstRef() {
-    run("BootAnimation", PRIORITY_DISPLAY);
+    status_t err = mSession->linkToComposerDeath(this);
+    LOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err));
+    if (err != NO_ERROR) {
+        run("BootAnimation", PRIORITY_DISPLAY);
+    }
 }
 
-const sp<SurfaceComposerClient>& BootAnimation::session() const {
+sp<SurfaceComposerClient> BootAnimation::session() const {
     return mSession;
 }
 
+
+void BootAnimation::binderDied(const wp<IBinder>& who)
+{
+    // woah, surfaceflinger died!
+    LOGD("SurfaceFlinger died, exiting...");
+
+    // calling requestExit() is not enough here because the Surface code
+    // might be blocked on a condition variable that will never be updated.
+    kill( getpid(), SIGKILL );
+    requestExit();
+}
+
 status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets,
         const char* name) {
     Asset* asset = assets.open(name, Asset::ACCESS_BUFFER);