AHB: add AHardwareBuffer_getId API in ndk

Add this api to ndk so that there's a reliable system-wide unique id for
caching.

libui is not linkable from sphal so vendors cannot convert an AHB into
GraphicBuffer to call getId(). This change solves the problem.

This change has been forced to refactor the existing docs and
annotations due to -Wnullability-completeness.

Bug: 162425097
Bug: 163615119
Test: atest libnativewindow_test:AHardwareBufferTest#GetIdTest
Change-Id: I91043b96b83bc9a896c361385581e9620fe373c3
diff --git a/libs/nativewindow/AHardwareBuffer.cpp b/libs/nativewindow/AHardwareBuffer.cpp
index 1ec73ce..a375d43 100644
--- a/libs/nativewindow/AHardwareBuffer.cpp
+++ b/libs/nativewindow/AHardwareBuffer.cpp
@@ -397,6 +397,16 @@
     return 0;
 }
 
+int AHardwareBuffer_getId(const AHardwareBuffer* buffer, uint64_t* outId) {
+    if (!buffer || !outId) return BAD_VALUE;
+
+    const GraphicBuffer* gb = AHardwareBuffer_to_GraphicBuffer(buffer);
+    if (!gb) return BAD_VALUE;
+
+    *outId = gb->getId();
+
+    return OK;
+}
 
 // ----------------------------------------------------------------------------
 // VNDK functions