Accompany HardwareBuffer with generation number

attachBuffer() should take a generation number and requestBuffer()
should return a generation number because AHardwareBuffer does not carry
the generation number.

Test: make cts -j123 && cts-tradefed run cts-dev -m \
CtsMediaTestCases --compatibility:module-arg \
CtsMediaTestCases:include-annotation:\
android.platform.test.annotations.RequiresDevice

Bug: 127778192
Change-Id: I201f84cf66f0e19b794a05c5ba88066360a37d96
diff --git a/current.txt b/current.txt
index 75b297d..3921eb1 100644
--- a/current.txt
+++ b/current.txt
@@ -475,7 +475,7 @@
 0d278956d7fc6fdf9ca9c42962ff2d73967bbb1c9f0b3e0b58d71b7095c286bc android.hardware.gnss.visibility_control@1.0::IGnssVisibilityControl
 0d99e34500cfc2d40b684cb4dea7ebd89d4aff9f5315ed36b33442a7a88c138c android.hardware.gnss.visibility_control@1.0::IGnssVisibilityControlCallback
 6b2d8dfa3db505c34a3a19082d8737c86bd859ec00f0e6c5fd19cce3c1ef95d1 android.hardware.graphics.allocator@3.0::IAllocator
-2a81d3132df91614a30ca45dfe088d67ddbb30240ab8c25feb6b8110d7ec3800 android.hardware.graphics.bufferqueue@2.0::IGraphicBufferProducer
+eb3bcf4e8afacc72fd09821920f277fbbe8b9837513c1f5549fb42588580cbe4 android.hardware.graphics.bufferqueue@2.0::IGraphicBufferProducer
 b826892686850a9cf2b60ca5845db7185c2196ea4dd765cd80cd163169678a78 android.hardware.graphics.bufferqueue@2.0::IProducerListener
 01c6398c90fc6be0640810e2c5d8a4863b457280132bb3f97dd5682e19632b62 android.hardware.graphics.bufferqueue@2.0::types
 7a2d64095252f85781b2d521f4f11d04ce774544feececcec2088c568656e93c android.hardware.graphics.common@1.2::types
diff --git a/graphics/bufferqueue/2.0/IGraphicBufferProducer.hal b/graphics/bufferqueue/2.0/IGraphicBufferProducer.hal
index 734c0b4..23b360a 100644
--- a/graphics/bufferqueue/2.0/IGraphicBufferProducer.hal
+++ b/graphics/bufferqueue/2.0/IGraphicBufferProducer.hal
@@ -75,12 +75,19 @@
      * @param slot Slot index.
      * @return status Status of the call.
      * @return buffer New buffer associated to the given slot index.
+     * @return generationNumber Generation number of the buffer. If
+     *     requestBuffer() is called immediately after dequeueBuffer() returns
+     *     with `bufferNeedsReallocation` set to `true`, @p generationNumber must
+     *     match the current generation number of the buffer queue previously
+     *     set by setGenerationNumber(). Otherwise, @p generationNumber may not
+     *     match the current generation number of the buffer queue.
      */
     requestBuffer(
             int32_t slot
         ) generates (
             Status status,
-            HardwareBuffer buffer
+            HardwareBuffer buffer,
+            uint32_t generationNumber
         );
 
     /**
@@ -212,9 +219,9 @@
      * parameter.
      *
      * @param input See #DequeueBufferInput for more information.
-     * @param status Status of the call.
-     * @param slot Slot index.
-     * @param output See #DequeueBufferOutput for more information.
+     * @return status Status of the call.
+     * @return slot Slot index.
+     * @return output See #DequeueBufferOutput for more information.
      *
      * @sa queueBuffer(), requestBuffer().
      */
@@ -286,6 +293,9 @@
      * See dequeueBuffer() for conditions that may cause the call to fail.
      *
      * @param buffer Buffer to attach to the buffer queue.
+     * @param generationNumber Generation number of the buffer. If this does not
+     *     match the current generation number of the buffer queue, the call
+     *     must fail with @p status set to `BAD_VALUE`.
      * @return status Status of the call.
      * @return slot Slot index assigned to @p buffer.
      * @return releaseAllBuffers Whether the caller is expected to release all
@@ -294,7 +304,8 @@
      * @sa dequeueBuffer().
      */
     attachBuffer(
-            HardwareBuffer buffer
+            HardwareBuffer buffer,
+            uint32_t generationNumber
         ) generates (
             Status status,
             int32_t slot,