Add an llndk api to get a native handle corresponding to ANativeWindow in AImageReader.

Since vendor modules sometimes might need to transfer ANativeWindow(specific to
AImageReader) over hidl to system processes, here, we introduce an llndk
function to convert the ANativeWindow owned by AImageReader into a
native_handle_t which may be transported over hwbinder.

We also introduce a platform only api to retrieve an HIDL
IGraphicBufferProducer from the handle received.

Bug: 110364143

Test: mm -j64
Test: AImageReaderWindowHandleTest

Change-Id: I5f2aec41d9c67c619413c02e48cd97933e3b2986
Signed-off-by: Jayant Chowdhary <jchowdhary@google.com>
diff --git a/media/ndk/NdkImageReaderPriv.h b/media/ndk/NdkImageReaderPriv.h
index bed8a21..a9b54a8 100644
--- a/media/ndk/NdkImageReaderPriv.h
+++ b/media/ndk/NdkImageReaderPriv.h
@@ -69,6 +69,8 @@
     media_status_t acquireNextImage(/*out*/AImage** image, /*out*/int* fenceFd);
     media_status_t acquireLatestImage(/*out*/AImage** image, /*out*/int* fenceFd);
 
+    media_status_t getWindowNativeHandle(/*out*/native_handle_t **handle);
+
     ANativeWindow* getWindow()    const { return mWindow.get(); };
     int32_t        getWidth()     const { return mWidth; };
     int32_t        getHeight()    const { return mHeight; };
@@ -160,10 +162,17 @@
     sp<Surface>                mSurface;
     sp<BufferItemConsumer>     mBufferItemConsumer;
     sp<ANativeWindow>          mWindow;
+    native_handle_t*           mWindowHandle = nullptr;
 
     List<AImage*>              mAcquiredImages;
 
     Mutex                      mLock;
 };
 
+// Retrieves HGraphicBufferProducer corresponding to the native_handle_t
+// provided. This method also deletes the HalToken corresponding to the
+// native_handle_t. Thus, if it is used twice in succession, the second call
+// returns nullptr;
+sp<HGraphicBufferProducer> AImageReader_getHGBPFromHandle(const native_handle_t *handle);
+
 #endif // _NDK_IMAGE_READER_PRIV_H