diff --git a/impl_android.go b/impl_android.go index fb205e0..badac3f 100644 --- a/impl_android.go +++ b/impl_android.go @@ -67,7 +67,7 @@ func connect() { //Clip copies a string to the clipboard func Clip(x string) { - fmt.Println("Clipboard not implemented for this platform") + pgp.Clip(x) } func (s *Store) nativeDecrypt(name string) (string, error) { diff --git a/jni_android.c b/jni_android.c index 5521615..96bff92 100644 --- a/jni_android.c +++ b/jni_android.c @@ -101,6 +101,17 @@ Encrypt(JNIEnv* env, jobject p, char* cid, int idlen, char* cdata, int datalen, (*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(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); } diff --git a/jni_android.go b/jni_android.go index e626204..efb85b6 100644 --- a/jni_android.go +++ b/jni_android.go @@ -149,6 +149,14 @@ func (p PGP) Encrypt(id, data string) (string, error) { } } +func (p PGP) Clip(data string) { + cdata := C.CString(data) + defer C.free(unsafe.Pointer(cdata)) + RunInJVM(func(env *JNIEnv) { + C.Clip(env, (C.jobject)(p), (*C.char)(unsafe.Pointer(cdata)), (C.int)(len(data))) + }) +} + func RunInJVM(f func(env *C.JNIEnv)) { runtime.LockOSThread() defer runtime.UnlockOSThread() diff --git a/jni_android.h b/jni_android.h index a7d68b1..e9f7205 100644 --- a/jni_android.h +++ b/jni_android.h @@ -7,6 +7,7 @@ void InitPgpConnect(JNIEnv* env); void GetId(JNIEnv* env, jobject p, int chint); void Decrypt(JNIEnv* env, jobject p, char* cdata, int datalen, int chint); void Encrypt(JNIEnv* env, jobject p, char* cid, int idlen, char* cdata, int datalen, int chint); +void Clip(JNIEnv* env, jobject p, char* cdata, int datalen); void stringResult(JNIEnv* env, jclass cls, jint requestCode, jobject response); void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID); void CallVoidMethod1(JNIEnv *env, jobject obj, jmethodID methodID, jobject arg);