passgo/jni_android.c

83 lines
2.4 KiB
C
Raw Normal View History

2019-11-20 11:52:19 -05:00
#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);
2019-11-20 13:53:40 -05:00
if (datalen > 0) {
(*env)->SetByteArrayRegion(env, data, 0, datalen, cdata);
}
2019-11-20 11:52:19 -05:00
jclass cls = (*env)->GetObjectClass(env, p);
jmethodID mid = (*env)->GetMethodID(env, cls, "Decrypt", "([BI)V");
2019-11-20 13:53:40 -05:00
(*env)->CallVoidMethod(env, p, mid, data, chint);
2019-11-20 11:52:19 -05:00
}
void Java_st_wow_git_passgo_PgpConnect_stringResult(JNIEnv* env, jclass cls, jint requestCode, jobject response) {
2019-11-20 11:52:19 -05:00
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);
2019-11-20 13:53:40 -05:00
if (idlen > 0) {
(*env)->SetByteArrayRegion(env, id, 0, idlen, cid);
}
2019-11-20 11:52:19 -05:00
jbyteArray data = (*env)->NewByteArray(env, datalen);
2019-11-20 13:53:40 -05:00
if (datalen > 0) {
(*env)->SetByteArrayRegion(env, data, 0, datalen, cdata);
}
2019-11-20 11:52:19 -05:00
jclass cls = (*env)->GetObjectClass(env, p);
jmethodID mid = (*env)->GetMethodID(env, cls, "Encrypt", "([B[BI)V");
2019-11-20 13:53:40 -05:00
(*env)->CallVoidMethod(env, p, mid, id, data, chint);
2019-11-20 11:52:19 -05:00
}
2019-11-20 14:56:11 -05:00
void
Clip(JNIEnv* env, jobject p, char* cdata, int datalen) {
jbyteArray data = (*env)->NewByteArray(env, datalen);
2019-11-20 15:00:53 -05:00
if (datalen > 0) {
2019-11-20 14:56:11 -05:00
(*env)->SetByteArrayRegion(env, data, 0, datalen, cdata);
}
2019-11-20 15:00:53 -05:00
jclass cls = (*env)->GetObjectClass(env, p);
jmethodID mid = (*env)->GetMethodID(env, cls, "Clip", "([B)V");
2019-11-20 14:56:11 -05:00
(*env)->CallVoidMethod(env, p, mid, data);
}
2019-11-20 11:52:19 -05:00
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);
}