Merge "Use LOCAL_CLANG := false for GLES wrappers for now"
diff --git a/libs/binder/IInterface.cpp b/libs/binder/IInterface.cpp
index 29acf5d..99a9ffe 100644
--- a/libs/binder/IInterface.cpp
+++ b/libs/binder/IInterface.cpp
@@ -29,12 +29,12 @@
 
 sp<IBinder> IInterface::asBinder()
 {
-    return this ? onAsBinder() : NULL;
+    return onAsBinder();
 }
 
 sp<const IBinder> IInterface::asBinder() const
 {
-    return this ? const_cast<IInterface*>(this)->onAsBinder() : NULL;
+    return const_cast<IInterface*>(this)->onAsBinder();
 }
 
 // ---------------------------------------------------------------------------
diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp
index acdbd77..498953f 100644
--- a/libs/gui/LayerState.cpp
+++ b/libs/gui/LayerState.cpp
@@ -75,7 +75,7 @@
 
 status_t DisplayState::write(Parcel& output) const {
     output.writeStrongBinder(token);
-    output.writeStrongBinder(surface->asBinder());
+    output.writeStrongBinder(surface != NULL ? surface->asBinder() : NULL);
     output.writeInt32(what);
     output.writeInt32(layerStack);
     output.writeInt32(orientation);
diff --git a/services/surfaceflinger/Android.mk b/services/surfaceflinger/Android.mk
index 49a017f..3416e48 100644
--- a/services/surfaceflinger/Android.mk
+++ b/services/surfaceflinger/Android.mk
@@ -106,17 +106,24 @@
 # build surfaceflinger's executable
 include $(CLEAR_VARS)
 
-LOCAL_CFLAGS:= -DLOG_TAG=\"SurfaceFlinger\"
+LOCAL_LDFLAGS := -Wl,--version-script,art/sigchainlib/version-script.txt -Wl,--export-dynamic
+LOCAL_CFLAGS:= -DLOG_TAG=\"SurfaceFlinger\" -Iart
+LOCAL_CPPFLAGS:= -std=c++11
 
+# TODO: Trying to link libsigchain as a static library prevents
+# static linker from exporting necessary symbols. So as a workaround
+# we use sigchain.o
 LOCAL_SRC_FILES:= \
-	main_surfaceflinger.cpp 
+	main_surfaceflinger.cpp \
+	sigchain_proxy.cpp
 
 LOCAL_SHARED_LIBRARIES := \
 	libsurfaceflinger \
 	libcutils \
 	liblog \
 	libbinder \
-	libutils
+	libutils \
+	libdl
 
 LOCAL_MODULE:= surfaceflinger
 
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 774654e..71795a2 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -1110,7 +1110,11 @@
                     // this display is in both lists. see if something changed.
                     const DisplayDeviceState& state(curr[j]);
                     const wp<IBinder>& display(curr.keyAt(j));
-                    if (state.surface->asBinder() != draw[i].surface->asBinder()) {
+                    const sp<IBinder> state_binder =
+                        state.surface != NULL ? state.surface->asBinder() : NULL;
+                    const sp<IBinder> draw_binder =
+                        draw[i].surface != NULL ? draw[i].surface->asBinder() : NULL;
+                    if (state_binder != draw_binder) {
                         // changing the surface is like destroying and
                         // recreating the DisplayDevice, so we just remove it
                         // from the drawing state, so that it get re-added
diff --git a/services/surfaceflinger/sigchain_proxy.cpp b/services/surfaceflinger/sigchain_proxy.cpp
new file mode 100644
index 0000000..bb7a678
--- /dev/null
+++ b/services/surfaceflinger/sigchain_proxy.cpp
@@ -0,0 +1,17 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+#include "sigchainlib/sigchain.cc"