Implement Clip on Android.

This commit is contained in:
Greg 2019-11-20 14:56:11 -05:00
parent ea9b4b3861
commit 8aacb243d2
4 changed files with 21 additions and 1 deletions

View File

@ -67,7 +67,7 @@ func connect() {
//Clip copies a string to the clipboard //Clip copies a string to the clipboard
func Clip(x string) { func Clip(x string) {
fmt.Println("Clipboard not implemented for this platform") pgp.Clip(x)
} }
func (s *Store) nativeDecrypt(name string) (string, error) { func (s *Store) nativeDecrypt(name string) (string, error) {

View File

@ -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); (*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) { void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID) {
(*env)->CallVoidMethod(env, obj, methodID); (*env)->CallVoidMethod(env, obj, methodID);
} }

View File

@ -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)) { func RunInJVM(f func(env *C.JNIEnv)) {
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()

View File

@ -7,6 +7,7 @@ void InitPgpConnect(JNIEnv* env);
void GetId(JNIEnv* env, jobject p, int chint); void GetId(JNIEnv* env, jobject p, int chint);
void Decrypt(JNIEnv* env, jobject p, char* cdata, int datalen, 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 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 stringResult(JNIEnv* env, jclass cls, jint requestCode, jobject response);
void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID); void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID);
void CallVoidMethod1(JNIEnv *env, jobject obj, jmethodID methodID, jobject arg); void CallVoidMethod1(JNIEnv *env, jobject obj, jmethodID methodID, jobject arg);