83 lines
2.4 KiB
C
83 lines
2.4 KiB
C
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <jni.h>
|
|
#include "jni_android.h"
|
|
#include "_cgo_export.h"
|
|
|
|
void
|
|
GetId(JNIEnv* env, jobject p, int chint) {
|
|
jclass cls = (*env)->GetObjectClass(env, p);
|
|
printf("GetId(): cls = %p", cls);
|
|
jmethodID mid = (*env)->GetMethodID(env, cls, "GetId", "(I)V");
|
|
printf("GetId(): mid = %p", mid);
|
|
(*env)->CallObjectMethod(env, p, mid, chint);
|
|
}
|
|
|
|
void
|
|
Decrypt(JNIEnv* env, jobject p, char* cdata, int datalen, int chint) {
|
|
jbyteArray data = (*env)->NewByteArray(env, datalen);
|
|
if (datalen > 0) {
|
|
(*env)->SetByteArrayRegion(env, data, 0, datalen, cdata);
|
|
}
|
|
jclass cls = (*env)->GetObjectClass(env, p);
|
|
jmethodID mid = (*env)->GetMethodID(env, cls, "Decrypt", "([BI)V");
|
|
(*env)->CallVoidMethod(env, p, mid, data, chint);
|
|
}
|
|
|
|
void Java_st_wow_git_passgo_PgpConnect_stringResult(JNIEnv* env, jclass cls, jint requestCode, jobject response) {
|
|
if (response == 0) {
|
|
goStringResult(env, cls, requestCode, 0);
|
|
} else {
|
|
char* str = (*env)->GetStringUTFChars(env, response, NULL);
|
|
goStringResult(env, cls, requestCode, str);
|
|
}
|
|
}
|
|
|
|
void
|
|
Encrypt(JNIEnv* env, jobject p, char* cid, int idlen, char* cdata, int datalen, int chint) {
|
|
jbyteArray id = (*env)->NewByteArray(env, idlen);
|
|
if (idlen > 0) {
|
|
(*env)->SetByteArrayRegion(env, id, 0, idlen, cid);
|
|
}
|
|
jbyteArray data = (*env)->NewByteArray(env, datalen);
|
|
if (datalen > 0) {
|
|
(*env)->SetByteArrayRegion(env, data, 0, datalen, cdata);
|
|
}
|
|
jclass cls = (*env)->GetObjectClass(env, p);
|
|
jmethodID mid = (*env)->GetMethodID(env, cls, "Encrypt", "([B[BI)V");
|
|
(*env)->CallVoidMethod(env, p, mid, id, data, chint);
|
|
}
|
|
|
|
void
|
|
Clip(JNIEnv* env, jobject p, char* cdata, int datalen) {
|
|
jbyteArray data = (*env)->NewByteArray(env, datalen);
|
|
if (datalen > 0) {
|
|
(*env)->SetByteArrayRegion(env, data, 0, datalen, cdata);
|
|
}
|
|
jclass cls = (*env)->GetObjectClass(env, p);
|
|
jmethodID mid = (*env)->GetMethodID(env, cls, "Clip", "([B)V");
|
|
(*env)->CallVoidMethod(env, p, mid, data);
|
|
}
|
|
|
|
void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID) {
|
|
(*env)->CallVoidMethod(env, obj, methodID);
|
|
}
|
|
|
|
jint GetEnv(JavaVM *vm, JNIEnv **env, jint version) {
|
|
return (*vm)->GetEnv(vm, (void **)env, version);
|
|
}
|
|
|
|
jint AttachCurrentThread(JavaVM *vm, JNIEnv **p_env, void *thr_args) {
|
|
return (*vm)->AttachCurrentThread(vm, p_env, thr_args);
|
|
}
|
|
|
|
jint DetachCurrentThread(JavaVM *vm) {
|
|
return (*vm)->DetachCurrentThread(vm);
|
|
}
|
|
|
|
jobject
|
|
NewGlobalRef(JNIEnv *env, jobject o) {
|
|
return (*env)->NewGlobalRef(env, o);
|
|
}
|