Allow the same producer to gain a buffer twice.

This change makes the same producer gaining the same buffer the second
time a no-op, and prevent other clients of the buffer from gaining it.

Currently, EALREADY error will return if a producer gain a buffer which
is already gained by the producer. Problem: there is an actual use case
in passthrough processor that a producer may need to gain a buffer to
mimic a "release" of a buffer in the consumer point of view.

Test: buffer_hub-test
Bug: 118718713
Change-Id: If958c95165a5ad62f51c46b01fa43b576d3b20ae
diff --git a/libs/vr/libbufferhub/producer_buffer.cpp b/libs/vr/libbufferhub/producer_buffer.cpp
index 1bfdc8f..c177970 100644
--- a/libs/vr/libbufferhub/producer_buffer.cpp
+++ b/libs/vr/libbufferhub/producer_buffer.cpp
@@ -172,9 +172,10 @@
   if (BufferHubDefs::IsClientGained(current_buffer_state,
                                     client_state_mask())) {
     ALOGI("%s: already gained id=%d.", __FUNCTION__, id());
-    return -EALREADY;
+    return 0;
   }
   if (BufferHubDefs::AnyClientAcquired(current_buffer_state) ||
+      BufferHubDefs::AnyClientGained(current_buffer_state) ||
       (BufferHubDefs::AnyClientPosted(current_buffer_state) &&
        !gain_posted_buffer)) {
     ALOGE("%s: not released id=%d state=%" PRIx64 ".", __FUNCTION__, id(),
@@ -196,6 +197,7 @@
         __FUNCTION__, current_buffer_state, updated_buffer_state);
 
     if (BufferHubDefs::AnyClientAcquired(current_buffer_state) ||
+        BufferHubDefs::AnyClientGained(current_buffer_state) ||
         (BufferHubDefs::AnyClientPosted(current_buffer_state) &&
          !gain_posted_buffer)) {
       ALOGE(