Update ANativeWindow client code for sync

This change updates all the uses of ANativeWindow to use the new ANW functions
that accept and return Sync HAL fence file descriptors.

Change-Id: Id7db42d8d6380f8b440d88476ce9211c6225fb16
diff --git a/services/camera/libcameraservice/Android.mk b/services/camera/libcameraservice/Android.mk
index 9f713fa..8cccf49 100644
--- a/services/camera/libcameraservice/Android.mk
+++ b/services/camera/libcameraservice/Android.mk
@@ -22,6 +22,7 @@
     libcamera_client \
     libgui \
     libhardware \
+    libsync \
     libcamera_metadata
 
 LOCAL_C_INCLUDES += \
diff --git a/services/camera/libcameraservice/Camera2Device.cpp b/services/camera/libcameraservice/Camera2Device.cpp
index 5a37c8d..8d07eee 100644
--- a/services/camera/libcameraservice/Camera2Device.cpp
+++ b/services/camera/libcameraservice/Camera2Device.cpp
@@ -758,7 +758,7 @@
     ANativeWindowBuffer **anwBuffers = new ANativeWindowBuffer*[mTotalBuffers];
     uint32_t bufferIdx = 0;
     for (; bufferIdx < mTotalBuffers; bufferIdx++) {
-        res = mConsumerInterface->dequeueBuffer(mConsumerInterface.get(),
+        res = native_window_dequeue_buffer_and_wait(mConsumerInterface.get(),
                 &anwBuffers[bufferIdx]);
         if (res != OK) {
             ALOGE("%s: Unable to dequeue buffer %d for initial registration for"
@@ -766,15 +766,6 @@
             goto cleanUpBuffers;
         }
 
-        res = mConsumerInterface->lockBuffer(mConsumerInterface.get(),
-                anwBuffers[bufferIdx]);
-        if (res != OK) {
-            ALOGE("%s: Unable to lock buffer %d for initial registration for"
-                    "stream %d", __FUNCTION__, bufferIdx, mId);
-            bufferIdx++;
-            goto cleanUpBuffers;
-        }
-
         buffers[bufferIdx] = anwBuffers[bufferIdx]->handle;
     }
 
@@ -792,7 +783,7 @@
 cleanUpBuffers:
     for (uint32_t i = 0; i < bufferIdx; i++) {
         res = mConsumerInterface->cancelBuffer(mConsumerInterface.get(),
-                anwBuffers[i]);
+                anwBuffers[i], -1);
         if (res != OK) {
             ALOGE("%s: Unable to cancel buffer %d after registration",
                     __FUNCTION__, i);
@@ -878,9 +869,7 @@
 
     ANativeWindow *a = toANW(w);
     ANativeWindowBuffer* anb;
-    res = a->dequeueBuffer(a, &anb);
-    if (res != OK) return res;
-    res = a->lockBuffer(a, anb);
+    res = native_window_dequeue_buffer_and_wait(a, &anb);
     if (res != OK) return res;
 
     *buffer = &(anb->handle);
@@ -911,7 +900,7 @@
         return err;
     }
     err = a->queueBuffer(a,
-            container_of(buffer, ANativeWindowBuffer, handle));
+            container_of(buffer, ANativeWindowBuffer, handle), -1);
     if (err != OK) {
         ALOGE("%s: Error queueing buffer to native window: %s (%d)",
                 __FUNCTION__, strerror(-err), err);
@@ -933,7 +922,7 @@
     stream->mActiveBuffers--;
     ANativeWindow *a = toANW(w);
     return a->cancelBuffer(a,
-            container_of(buffer, ANativeWindowBuffer, handle));
+            container_of(buffer, ANativeWindowBuffer, handle), -1);
 }
 
 int Camera2Device::StreamAdapter::set_crop(const camera2_stream_ops_t* w,
diff --git a/services/camera/libcameraservice/CameraHardwareInterface.h b/services/camera/libcameraservice/CameraHardwareInterface.h
index 87a0802..05ac9fa 100644
--- a/services/camera/libcameraservice/CameraHardwareInterface.h
+++ b/services/camera/libcameraservice/CameraHardwareInterface.h
@@ -569,7 +569,7 @@
         int rc;
         ANativeWindow *a = anw(w);
         ANativeWindowBuffer* anb;
-        rc = a->dequeueBuffer(a, &anb);
+        rc = native_window_dequeue_buffer_and_wait(a, &anb);
         if (!rc) {
             *buffer = &anb->handle;
             *stride = anb->stride;
@@ -587,8 +587,7 @@
                       buffer_handle_t* buffer)
     {
         ANativeWindow *a = anw(w);
-        return a->lockBuffer(a,
-                  container_of(buffer, ANativeWindowBuffer, handle));
+        return 0;
     }
 
     static int __enqueue_buffer(struct preview_stream_ops* w,
@@ -596,7 +595,7 @@
     {
         ANativeWindow *a = anw(w);
         return a->queueBuffer(a,
-                  container_of(buffer, ANativeWindowBuffer, handle));
+                  container_of(buffer, ANativeWindowBuffer, handle), -1);
     }
 
     static int __cancel_buffer(struct preview_stream_ops* w,
@@ -604,7 +603,7 @@
     {
         ANativeWindow *a = anw(w);
         return a->cancelBuffer(a,
-                  container_of(buffer, ANativeWindowBuffer, handle));
+                  container_of(buffer, ANativeWindowBuffer, handle), -1);
     }
 
     static int __set_buffer_count(struct preview_stream_ops* w, int count)