jni

package module
v0.0.0-...-34026c7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2021 License: BSD-3-Clause Imports: 7 Imported by: 4

README

JNI

A JNI library cloned from github.com/tailscale/tailscale-android.

Documentation

Overview

Package jni implements various helper functions for communicating with the Android JVM though JNI.

Index

Constants

View Source
const (
	TRUE  = C.JNI_TRUE
	FALSE = C.JNI_FALSE
)

Variables

This section is empty.

Functions

func CallBooleanMethod

func CallBooleanMethod(e Env, obj Object, method MethodID, args ...Value) (bool, error)

CallBooleanMethod calls a method on an object, returning a bool.

func CallByteMethod

func CallByteMethod(e Env, obj Object, method MethodID, args ...Value) (byte, error)

CallByteMethod calls a method on an object, returning a byte.

func CallCharMethod

func CallCharMethod(e Env, obj Object, method MethodID, args ...Value) (rune, error)

CallCharMethod calls a method on an object, returning a rune.

func CallDoubleMethod

func CallDoubleMethod(e Env, obj Object, method MethodID, args ...Value) (float64, error)

CallDoubleMethod calls a method on an object, returning a float64.

func CallFloatMethod

func CallFloatMethod(e Env, obj Object, method MethodID, args ...Value) (float32, error)

CallFloatMethod calls a method on an object, returning a float32.

func CallIntMethod

func CallIntMethod(e Env, obj Object, method MethodID, args ...Value) (int32, error)

CallIntMethod calls a method on an object, returning an int32.

func CallLongMethod

func CallLongMethod(e Env, obj Object, method MethodID, args ...Value) (int64, error)

CallLongMethod calls a method on an object, returning an int64.

func CallShortMethod

func CallShortMethod(e Env, obj Object, method MethodID, args ...Value) (int16, error)

CallShortMethod calls a method on an object, returning an int32.

func CallStaticBooleanMethod

func CallStaticBooleanMethod(e Env, cls Class, method MethodID, args ...Value) (bool, error)

CallStaticBooleanMethod calls a static method on a Java class, returning an int.

func CallStaticIntMethod

func CallStaticIntMethod(e Env, cls Class, method MethodID, args ...Value) (int, error)

CallStaticIntMethod calls a static method on a Java class, returning an int.

func CallStaticVoidMethod

func CallStaticVoidMethod(e Env, cls Class, method MethodID, args ...Value) error

CallStaticVoidMethod calls a static method on a Java class, returning nothing.

func CallVoidMethod

func CallVoidMethod(e Env, obj Object, method MethodID, args ...Value) error

CallVoidMethod calls a method on an object, returning nothing.

func DeleteGlobalRef

func DeleteGlobalRef(e Env, obj Object)

DeleteGlobalRef delets a global reference.

func DeleteLocalRef

func DeleteLocalRef(e Env, obj Object)

DeleteLocalRef delets a local reference.

func Do

func Do(vm JVM, f func(env Env) error) error

Do invokes a function with a temporary JVM environment. The environment is not valid after the function returns.

func GetBooleanField

func GetBooleanField(env Env, obj Object, fieldID FieldID) bool

GetBooleanField looks up the value of a static field of type boolean. This should never throw an exception.

func GetByteArrayElements

func GetByteArrayElements(e Env, jarr ByteArray) []byte

GetByteArrayElements returns the contents of the array.

func GetByteField

func GetByteField(env Env, obj Object, fieldID FieldID) byte

GetByteField looks up the value of a static field of type byte. This should never throw an exception.

func GetCharField

func GetCharField(env Env, obj Object, fieldID FieldID) byte

GetCharField looks up the value of a static field of type char. This should never throw an exception.

func GetDoubleField

func GetDoubleField(env Env, obj Object, fieldID FieldID) float64

GetDoubleField looks up the value of a static field of type double. This should never throw an exception.

func GetFloatField

func GetFloatField(env Env, obj Object, fieldID FieldID) float32

GetFloatField looks up the value of a static field of type float. This should never throw an exception.

func GetIntField

func GetIntField(env Env, obj Object, fieldID FieldID) int32

GetIntField looks up the value of a static field of type int. This should never throw an exception.

func GetLongField

func GetLongField(env Env, obj Object, fieldID FieldID) int64

GetLongField looks up the value of a static field of type long. This should never throw an exception.

func GetShortField

func GetShortField(env Env, obj Object, fieldID FieldID) int16

GetShortField looks up the value of a static field of type short. This should never throw an exception.

func GetStaticBooleanField

func GetStaticBooleanField(env Env, clazz Class, fieldID FieldID) bool

GetStaticBooleanField looks up the value of a static field of type boolean. This should never throw an exception.

func GetStaticByteField

func GetStaticByteField(env Env, clazz Class, fieldID FieldID) byte

GetStaticByteField looks up the value of a static field of type byte. This should never throw an exception.

func GetStaticCharField

func GetStaticCharField(env Env, clazz Class, fieldID FieldID) byte

GetStaticCharField looks up the value of a static field of type char. This should never throw an exception.

func GetStaticDoubleField

func GetStaticDoubleField(env Env, clazz Class, fieldID FieldID) float64

GetStaticDoubleField looks up the value of a static field of type double. This should never throw an exception.

func GetStaticFloatField

func GetStaticFloatField(env Env, clazz Class, fieldID FieldID) float32

GetStaticFloatField looks up the value of a static field of type float. This should never throw an exception.

func GetStaticIntField

func GetStaticIntField(env Env, clazz Class, fieldID FieldID) int32

GetStaticIntField looks up the value of a static field of type int. This should never throw an exception.

func GetStaticLongField

func GetStaticLongField(env Env, clazz Class, fieldID FieldID) int64

GetStaticLongField looks up the value of a static field of type long. This should never throw an exception.

func GetStaticShortField

func GetStaticShortField(env Env, clazz Class, fieldID FieldID) int16

GetStaticShortField looks up the value of a static field of type short. This should never throw an exception.

func GoString

func GoString(e Env, str String) string

GoString converts the JVM jstring to a Go string.

func IsInstanceOf

func IsInstanceOf(e Env, obj Object, cls Class) bool

IsInstanceOf returns true if the given object is an instance of the given class.

func IsSameObject

func IsSameObject(e Env, ref1, ref2 Object) bool

IsSameObject returns true if the two given objects refer to the same Java object.

func SetObjectArrayElement

func SetObjectArrayElement(e Env, jarr ObjectArray, index Size, value Object) error

Types

type ByteArray

type ByteArray C.jbyteArray

func NewByteArray

func NewByteArray(e Env, content []byte) ByteArray

NewByteArray allocates a Java byte array with the content. It panics if the allocation fails.

type Class

type Class C.jclass

func FindClass

func FindClass(e Env, name string) Class

FindClass returns a reference to a Java class with a given name, using the JVM's default class loader. Any exceptions caused by the underlying JNI call (for example if the class is not found) will result in a panic.

func GetObjectClass

func GetObjectClass(e Env, obj Object) Class

GetObjectClass returns the Java Class for an Object.

func LoadClass

func LoadClass(e Env, loader Object, class string) (Class, error)

LoadClass invokes the underlying ClassLoader's loadClass method and returns the class.

type Env

type Env struct {
	// contains filtered or unexported fields
}

func EnvFor

func EnvFor(envPtr uintptr) Env

EnvFor creates an Env object, interpreting the given uintptr as a pointer to a C.JNIEnv object.

type FieldID

type FieldID C.jfieldID

func GetFieldID

func GetFieldID(e Env, cls Class, name, signature string) FieldID

GetFieldID returns the id for a field. It panics if the field wasn't found.

func GetStaticFieldID

func GetStaticFieldID(e Env, cls Class, name, signature string) FieldID

GetStaticFieldID returns the id for a static field. It panics if the field wasn't found.

type JVM

type JVM struct {
	// contains filtered or unexported fields
}

func CreateJavaVM

func CreateJavaVM() JVM

CreateJavaVM creates a new Java VM with the options specified (if any). This should not be called more than once as it can result in an error if a JVM already exists for a given process.

This is not implemented on Android and is therefore excluded on that platform by build flags and C.

func JVMFor

func JVMFor(jvmPtr uintptr) JVM

JVMFor creates a JVM object, interpreting the given uintptr as a pointer to a C.JavaVM object.

type MethodID

type MethodID C.jmethodID

func GetMethodID

func GetMethodID(e Env, cls Class, name, signature string) MethodID

GetMethodID returns the id for a method. It panics if the method wasn't found.

func GetStaticMethodID

func GetStaticMethodID(e Env, cls Class, name, signature string) MethodID

GetStaticMethodID returns the id for a static method. It panics if the method wasn't found.

type Object

type Object C.jobject

func CallObjectMethod

func CallObjectMethod(e Env, obj Object, method MethodID, args ...Value) (Object, error)

CallObjectMethod calls a method on an object, returning a Java object.

func CallStaticObjectMethod

func CallStaticObjectMethod(e Env, cls Class, method MethodID, args ...Value) (Object, error)

CallStaticObjectMethod calls a static method on a class, returning a Java object

func ClassLoaderFor

func ClassLoaderFor(e Env, obj Object) Object

ClassLoader returns a reference to the Java ClassLoader associated with obj.

func GetObjectArrayElement

func GetObjectArrayElement(e Env, jarr ObjectArray, index Size) (Object, error)

func GetObjectField

func GetObjectField(env Env, obj Object, fieldID FieldID) Object

GetObjectField looks up the value of a static field of type Object. This should never throw an exception.

func GetStaticObjectField

func GetStaticObjectField(env Env, clazz Class, fieldID FieldID) Object

GetStaticObjectField looks up the value of a static field of type Object. This should never throw an exception.

func NewGlobalRef

func NewGlobalRef(e Env, obj Object) Object

NewGlobalRef creates a new global reference.

func NewLocalRef

func NewLocalRef(e Env, obj Object) Object

NewLocalRef creates a new local reference to the given object.

func NewObject

func NewObject(e Env, cls Class, method MethodID, args ...Value) (Object, error)

NewObject creates a new object given a class, initializer method, and initializer arguments (if any).

type ObjectArray

type ObjectArray C.jobjectArray

func NewObjectArray

func NewObjectArray(e Env, len Size, class Class, elem Object) ObjectArray

type Size

type Size C.jsize

type String

type String C.jstring

func JavaString

func JavaString(e Env, str string) String

JavaString converts the string to a JVM jstring.

type Value

type Value uint64 // All JNI types fit into 64-bits.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL