Clean-up exported API

Move functions in API to libnativehelper_api.h and retire macros
formerly in module_api.h.

Add doc comments methods in the API.

Move various C++ internal definitions to anonymous namespaces.

Bug: 123003088
Test: m
Change-Id: I216f13e2627f7f402b399bb96aec358ee127e4b9
diff --git a/include/nativehelper/JNIHelp.h b/include/nativehelper/JNIHelp.h
index 92a3882..914c150 100644
--- a/include/nativehelper/JNIHelp.h
+++ b/include/nativehelper/JNIHelp.h
@@ -26,166 +26,13 @@
 #include <errno.h>
 #include <unistd.h>
 
-#include <jni.h>
-#include "module_api.h"
+#include "libnativehelper_api.h"
 
 #ifndef NELEM
-# define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
+#define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
 #endif
 
 /*
- * Register one or more native methods with a particular class.
- * "className" looks like "java/lang/String". Aborts on failure.
- * TODO: fix all callers and change the return type to void.
- */
-MODULE_API int jniRegisterNativeMethods(C_JNIEnv* env,
-                                        const char* className,
-                                        const JNINativeMethod* gMethods,
-                                        int numMethods);
-
-/*
- * Throw an exception with the specified class and an optional message.
- *
- * The "className" argument will be passed directly to FindClass, which
- * takes strings with slashes (e.g. "java/lang/Object").
- *
- * If an exception is currently pending, we log a warning message and
- * clear it.
- *
- * Returns 0 on success, nonzero if something failed (e.g. the exception
- * class couldn't be found, so *an* exception will still be pending).
- *
- * Currently aborts the VM if it can't throw the exception.
- */
-MODULE_API int jniThrowException(C_JNIEnv* env, const char* className, const char* msg);
-
-/*
- * Throw an exception with the specified class and formatted error message.
- *
- * The "className" argument will be passed directly to FindClass, which
- * takes strings with slashes (e.g. "java/lang/Object").
- *
- * If an exception is currently pending, we log a warning message and
- * clear it.
- *
- * Returns 0 on success, nonzero if something failed (e.g. the exception
- * class couldn't be found, so *an* exception will still be pending).
- *
- * Currently aborts the VM if it can't throw the exception.
- */
-MODULE_API int jniThrowExceptionFmt(C_JNIEnv* env, const char* className, const char* fmt, va_list args);
-
-/*
- * Throw a java.lang.NullPointerException, with an optional message.
- */
-MODULE_API int jniThrowNullPointerException(C_JNIEnv* env, const char* msg);
-
-/*
- * Throw a java.lang.RuntimeException, with an optional message.
- */
-MODULE_API int jniThrowRuntimeException(C_JNIEnv* env, const char* msg);
-
-/*
- * Throw a java.io.IOException, generating the message from errno.
- */
-MODULE_API int jniThrowIOException(C_JNIEnv* env, int errnum);
-
-/*
- * Return a pointer to a locale-dependent error string explaining errno
- * value 'errnum'. The returned pointer may or may not be equal to 'buf'.
- * This function is thread-safe (unlike strerror) and portable (unlike
- * strerror_r).
- */
-MODULE_API const char* jniStrError(int errnum, char* buf, size_t buflen);
-
-/*
- * Returns a new java.io.FileDescriptor for the given int fd.
- */
-MODULE_API jobject jniCreateFileDescriptor(C_JNIEnv* env, int fd);
-
-/*
- * Returns the int fd from a java.io.FileDescriptor.
- */
-MODULE_API int jniGetFDFromFileDescriptor(C_JNIEnv* env, jobject fileDescriptor);
-
-/*
- * Sets the int fd in a java.io.FileDescriptor.  Throws java.lang.NullPointerException
- * if fileDescriptor is null.
- */
-MODULE_API void jniSetFileDescriptorOfFD(C_JNIEnv* env,
-                                         jobject fileDescriptor,
-                                         int value);
-
-/*
- * Returns the long ownerId from a java.io.FileDescriptor.
- */
-MODULE_API jlong jniGetOwnerIdFromFileDescriptor(C_JNIEnv* env, jobject fileDescriptor);
-
-/*
- * Gets the managed heap array backing a java.nio.Buffer instance.
- *
- * Returns nullptr if there is no array backing.
- *
- * This method performs a JNI call to java.nio.NIOAccess.getBaseArray().
- */
-MODULE_API jarray jniGetNioBufferBaseArray(C_JNIEnv* env, jobject nioBuffer);
-
-/*
- * Gets the offset in bytes from the start of the managed heap array backing the buffer.
- *
- * Returns 0 if there is no array backing.
- *
- * This method performs a JNI call to java.nio.NIOAccess.getBaseArrayOffset().
- */
-MODULE_API jint jniGetNioBufferBaseArrayOffset(C_JNIEnv* env, jobject nioBuffer);
-
-/*
- * Gets field information from a java.nio.Buffer instance.
- *
- * Reads the |position|, |limit|, and |elementSizeShift| fields from the buffer instance.
- *
- * Returns the |address| field of the java.nio.Buffer instance which is only valid (non-zero) when
- * the buffer is backed by a direct buffer.
- */
-MODULE_API jlong jniGetNioBufferFields(C_JNIEnv* env,
-                                       jobject nioBuffer,
-                                       /*out*/jint* position,
-                                       /*out*/jint* limit,
-                                       /*out*/jint* elementSizeShift);
-
-/*
- * Gets the current position from a java.nio.Buffer as a pointer to memory in a fixed buffer.
- *
- * Returns 0 if |nioBuffer| is not backed by a direct buffer.
- *
- * This method reads the |address|, |position|, and |elementSizeShift| fields from the
- * java.nio.Buffer instance to calculate the pointer address for the current position.
- */
-MODULE_API jlong jniGetNioBufferPointer(C_JNIEnv* env, jobject nioBuffer);
-
-/*
- * Returns the reference from a java.lang.ref.Reference.
- */
-MODULE_API jobject jniGetReferent(C_JNIEnv* env, jobject ref);
-
-/*
- * Returns a Java String object created from UTF-16 data either from jchar or,
- * if called from C++11, char16_t (a bitwise identical distinct type).
- */
-MODULE_API jstring jniCreateString(C_JNIEnv* env, const jchar* unicodeChars, jsize len);
-
-/*
- * Log a message and an exception.
- * If exception is NULL, logs the current exception in the JNI environment.
- */
-MODULE_API void jniLogException(C_JNIEnv* env, int priority, const char* tag, jthrowable exception);
-
-/*
- * Clear the cache of constants libnativehelper is using.
- */
-MODULE_API void jniUninitializeConstants();
-
-/*
  * For C++ code, we provide inlines that map to the C functions.  g++ always
  * inlines these, even on non-optimized builds.
  */