java: V23GoRunnable android lib.

Android applications can use V23GoRunnable to run go code that needs
to use a vanadium context in an android application.

MultiPart: 1/2
Change-Id: I6bb62d457ee3ea015f94e26ca0e314224bcb52d0
diff --git a/impl/google/services/jni.go b/impl/google/services/jni.go
index 0ea7dd8..3e79ffc 100644
--- a/impl/google/services/jni.go
+++ b/impl/google/services/jni.go
@@ -10,6 +10,7 @@
 	jgroups "v.io/x/jni/impl/google/services/groups"
 	jmounttable "v.io/x/jni/impl/google/services/mounttable"
 	jsyncbase "v.io/x/jni/impl/google/services/syncbase"
+	_ "v.io/x/jni/impl/google/services/v23_go_runnable"
 	jutil "v.io/x/jni/util"
 )
 
diff --git a/impl/google/services/v23_go_runnable/jni.go b/impl/google/services/v23_go_runnable/jni.go
new file mode 100644
index 0000000..7247401
--- /dev/null
+++ b/impl/google/services/v23_go_runnable/jni.go
@@ -0,0 +1,41 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build java android
+
+package v23_go_runnable
+
+import (
+	"unsafe"
+	"v.io/v23/context"
+
+	jutil "v.io/x/jni/util"
+	jcontext "v.io/x/jni/v23/context"
+)
+
+// #include "jni.h"
+import "C"
+
+// V23GoRunnableFunc is the go code that is run by java/android callers of
+// V23GoRunnable.run().
+// Users must edit this function and rebuild the java lib/android-lib.
+// Then android apps may run this Go code.
+func V23GoRunnableFunc(ctx *context.T) error {
+	ctx.Infof("Running V23GoRunnableFunc")
+	return nil
+}
+
+//export Java_io_v_android_util_V23GoRunnable_nativeGoContextCall
+func Java_io_v_android_util_V23GoRunnable_nativeGoContextCall(jenv *C.JNIEnv, jV23GoRunner C.jobject, jContext C.jobject) {
+	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
+	ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
+	if err != nil {
+		jutil.JThrowV(env, err)
+		return
+	}
+	if err := V23GoRunnableFunc(ctx); err != nil {
+		jutil.JThrowV(env, err)
+		return
+	}
+}