ANativeWindow_toSurface implementation

This enables the conversion from an ANativeWindow (created by NDK API
such as: AImageReader_create) to a Java Surface, so that developers can
hookup a Java Producer to a native buffer consumer.

This CL also introduces android_view_Surface_createFromSurface helper
function in libandroid_runtime to convert a C++ sp<Surface> to a Java
Surface object.

Bug: 36862948
Test: android.media.cts.NativeImageReaderTest
Change-Id: Ia99adb654da505ac117a8e58153ac800df23a650
diff --git a/native/android/native_window_jni.cpp b/native/android/native_window_jni.cpp
index dc30405..859c550 100644
--- a/native/android/native_window_jni.cpp
+++ b/native/android/native_window_jni.cpp
@@ -20,6 +20,7 @@
 #include <android/native_window.h>
 #include <system/window.h>
 
+#include <gui/Surface.h>
 #include <utils/StrongPointer.h>
 
 #include <android_runtime/android_view_Surface.h>
@@ -33,3 +34,11 @@
     }
     return win.get();
 }
+
+jobject ANativeWindow_toSurface(JNIEnv* env, ANativeWindow* window) {
+    if (window == NULL) {
+        return NULL;
+    }
+    sp<Surface> surface = static_cast<Surface*>(window);
+    return android_view_Surface_createFromSurface(env, surface);
+}