internal/mobileinit,app: declare C symbols static

The changes to internal/mobileinit fixes golang/go#26298; the
changes to the app package are only the easy pickings.

Fixes golang/go#26298

Change-Id: I1ac49c57e417b852cb5ab1bdcb18c73db8c4475a
Reviewed-on: https://go-review.googlesource.com/122897
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/app/android.c b/app/android.c
index b677869..bde2592 100644
--- a/app/android.c
+++ b/app/android.c
@@ -15,6 +15,8 @@
 #define LOG_INFO(...) __android_log_print(ANDROID_LOG_INFO, "Go", __VA_ARGS__)
 #define LOG_FATAL(...) __android_log_print(ANDROID_LOG_FATAL, "Go", __VA_ARGS__)
 
+static jobject current_ctx;
+
 static jclass find_class(JNIEnv *env, const char *class_name) {
 	jclass clazz = (*env)->FindClass(env, class_name);
 	if (clazz == NULL) {
@@ -46,7 +48,7 @@
 	return JNI_VERSION_1_6;
 }
 
-int main_running = 0;
+static int main_running = 0;
 
 // Entry point from our subclassed NativeActivity.
 //
@@ -61,13 +63,12 @@
 		JNIEnv* env = activity->env;
 
 		// Note that activity->clazz is mis-named.
-		current_vm = activity->vm;
 		current_ctx = activity->clazz;
 
 		jclass clazz = (*env)->GetObjectClass(env, current_ctx);
 		key_rune_method = find_method(env, clazz, "getRune", "(III)I");
 
-		setCurrentContext(current_vm, (*env)->NewGlobalRef(env, current_ctx));
+		setCurrentContext(activity->vm, (*env)->NewGlobalRef(env, current_ctx));
 
 		// Set TMPDIR.
 		jmethodID gettmpdir = find_method(env, clazz, "getTmpdir", "()Ljava/lang/String;");
@@ -111,7 +112,7 @@
 }
 
 // TODO(crawshaw): Test configuration on more devices.
-const EGLint RGB_888[] = {
+static const EGLint RGB_888[] = {
 	EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
 	EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
 	EGL_BLUE_SIZE, 8,
@@ -125,7 +126,7 @@
 EGLDisplay display = NULL;
 EGLSurface surface = NULL;
 
-char* initEGLDisplay() {
+static char* initEGLDisplay() {
 	display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
 	if (!eglInitialize(display, 0, 0)) {
 		return "EGL initialize failed";
diff --git a/app/android.go b/app/android.go
index 883a93c..27e33d4 100644
--- a/app/android.go
+++ b/app/android.go
@@ -35,15 +35,9 @@
 #include <pthread.h>
 #include <stdlib.h>
 
-JavaVM* current_vm;
-jobject current_ctx;
-
-jclass app_find_class(JNIEnv* env, const char* name);
-
 EGLDisplay display;
 EGLSurface surface;
 
-char* initEGLDisplay();
 char* createEGLSurface(ANativeWindow* window);
 char* destroyEGLSurface();
 int32_t getKeyRune(JNIEnv* env, AInputEvent* e);
diff --git a/internal/mobileinit/ctx_android.go b/internal/mobileinit/ctx_android.go
index e0dc166..b58881a 100644
--- a/internal/mobileinit/ctx_android.go
+++ b/internal/mobileinit/ctx_android.go
@@ -8,30 +8,19 @@
 #include <jni.h>
 #include <stdlib.h>
 
-// current_vm is stored to initialize other cgo packages.
-//
-// As all the Go packages in a program form a single shared library,
-// there can only be one JNI_OnLoad function for initialization. In
-// OpenJDK there is JNI_GetCreatedJavaVMs, but this is not available
-// on android.
-JavaVM* current_vm;
-
-// current_ctx is Android's android.context.Context. May be NULL.
-jobject current_ctx;
-
-char* lockJNI(uintptr_t* envp, int* attachedp) {
+static char* lockJNI(JavaVM *vm, uintptr_t* envp, int* attachedp) {
 	JNIEnv* env;
 
-	if (current_vm == NULL) {
+	if (vm == NULL) {
 		return "no current JVM";
 	}
 
 	*attachedp = 0;
-	switch ((*current_vm)->GetEnv(current_vm, (void**)&env, JNI_VERSION_1_6)) {
+	switch ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6)) {
 	case JNI_OK:
 		break;
 	case JNI_EDETACHED:
-		if ((*current_vm)->AttachCurrentThread(current_vm, &env, 0) != 0) {
+		if ((*vm)->AttachCurrentThread(vm, &env, 0) != 0) {
 			return "cannot attach to JVM";
 		}
 		*attachedp = 1;
@@ -46,7 +35,7 @@
 	return NULL;
 }
 
-char* checkException(uintptr_t jnienv) {
+static char* checkException(uintptr_t jnienv) {
 	jthrowable exc;
 	JNIEnv* env = (JNIEnv*)jnienv;
 
@@ -63,8 +52,8 @@
 	return (char*)(*env)->GetStringUTFChars(env, msgStr, 0);
 }
 
-void unlockJNI() {
-	(*current_vm)->DetachCurrentThread(current_vm);
+static void unlockJNI(JavaVM *vm) {
+	(*vm)->DetachCurrentThread(vm);
 }
 */
 import "C"
@@ -75,12 +64,23 @@
 	"unsafe"
 )
 
+// currentVM is stored to initialize other cgo packages.
+//
+// As all the Go packages in a program form a single shared library,
+// there can only be one JNI_OnLoad function for initialization. In
+// OpenJDK there is JNI_GetCreatedJavaVMs, but this is not available
+// on android.
+var currentVM *C.JavaVM
+
+// currentCtx is Android's android.context.Context. May be NULL.
+var currentCtx C.jobject
+
 // SetCurrentContext populates the global Context object with the specified
 // current JavaVM instance (vm) and android.context.Context object (ctx).
 // The android.context.Context object must be a global reference.
 func SetCurrentContext(vm unsafe.Pointer, ctx uintptr) {
-	C.current_vm = (*C.JavaVM)(vm)
-	C.current_ctx = (C.jobject)(ctx)
+	currentVM = (*C.JavaVM)(vm)
+	currentCtx = (C.jobject)(ctx)
 }
 
 // RunOnJVM runs fn on a new goroutine locked to an OS thread with a JNIEnv.
@@ -99,16 +99,16 @@
 
 		env := C.uintptr_t(0)
 		attached := C.int(0)
-		if errStr := C.lockJNI(&env, &attached); errStr != nil {
+		if errStr := C.lockJNI(currentVM, &env, &attached); errStr != nil {
 			errch <- errors.New(C.GoString(errStr))
 			return
 		}
 		if attached != 0 {
-			defer C.unlockJNI()
+			defer C.unlockJNI(currentVM)
 		}
 
-		vm := uintptr(unsafe.Pointer(C.current_vm))
-		if err := fn(vm, uintptr(env), uintptr(C.current_ctx)); err != nil {
+		vm := uintptr(unsafe.Pointer(currentVM))
+		if err := fn(vm, uintptr(env), uintptr(currentCtx)); err != nil {
 			errch <- err
 			return
 		}