Compare commits
No commits in common. "94cfbbeb41741d8cd0b5a431605d3f8af8c8bcab" and "23df75fd15b4c2d107fd35c8761855526b6df630" have entirely different histories.
94cfbbeb41
...
23df75fd15
|
@ -31,30 +31,43 @@ import android.Manifest;
|
|||
import android.content.pm.PackageManager;
|
||||
|
||||
public class PgpConnect extends Fragment {
|
||||
Activity act;
|
||||
Context ctx;
|
||||
Handler handler;
|
||||
ClipboardManager cb;
|
||||
OpenPgpServiceConnection mServiceConnection;
|
||||
ClipboardManager cb;
|
||||
final int PERMISSIONS_REQUEST = 1;
|
||||
|
||||
public PgpConnect() {
|
||||
Log.d("gio", "PgpConnect()");
|
||||
public PgpConnect(Activity act) {
|
||||
Log.d("gio", "PgpConnect(Activity)");
|
||||
act = act;
|
||||
ctx = act.getApplicationContext();
|
||||
this.handler = new Handler(ctx.getMainLooper());
|
||||
|
||||
final FragmentManager fm = act.getFragmentManager();
|
||||
final Fragment frag = this;
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
Log.d("gio", "PgpConnect(): adding fragment");
|
||||
FragmentTransaction ft = fm.beginTransaction();
|
||||
ft.add(frag, "PgpConnect");
|
||||
ft.commitNow();
|
||||
|
||||
if (ctx.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ctx.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public void onAttach(Context ctx) {
|
||||
super.onAttach(ctx);
|
||||
Log.d("gio", "onAttach()");
|
||||
if (ctx instanceof Activity) {
|
||||
Log.d("gio", "It's an Activity!");
|
||||
}
|
||||
this.ctx = ctx;
|
||||
this.handler = new Handler(ctx.getMainLooper());
|
||||
mServiceConnection = new OpenPgpServiceConnection(ctx, "org.sufficientlysecure.keychain");
|
||||
mServiceConnection.bindToService();
|
||||
cb = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
if (ctx.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ctx.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST);
|
||||
}
|
||||
installComplete(this);
|
||||
}
|
||||
|
||||
|
@ -71,6 +84,7 @@ public class PgpConnect extends Fragment {
|
|||
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
Log.d("gio", "onActivityResult(" + requestCode + "): " + resultCode);
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
//activityResult(requestCode, resultCode);
|
||||
if (resultCode != Activity.RESULT_OK) {
|
||||
Log.d("gio", "onActivityResult: not OK");
|
||||
stringResult(requestCode, null);
|
||||
|
@ -277,5 +291,6 @@ public class PgpConnect extends Fragment {
|
|||
}
|
||||
|
||||
static private native void installComplete(PgpConnect p);
|
||||
static private native void activityResult(int requestCode, int resultCode);
|
||||
static private native void stringResult(int requestCode, String result);
|
||||
}
|
||||
|
|
|
@ -196,7 +196,6 @@ func eventLoop() {
|
|||
w := app.NewWindow(
|
||||
app.Size(unit.Dp(250), unit.Dp(500)),
|
||||
app.Title("passgo"))
|
||||
initPgp(w)
|
||||
gtx := &layout.Context{Queue: w.Queue()}
|
||||
//time.Sleep(time.Second/5)
|
||||
|
||||
|
@ -389,6 +388,7 @@ func eventLoop() {
|
|||
w.Invalidate()
|
||||
page = idPage
|
||||
default:
|
||||
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
|
||||
lst.Layout(gtx, len(passBtns), func(i int) {
|
||||
btn := passBtns[i]
|
||||
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
|
||||
|
@ -827,10 +827,11 @@ func eventLoop() {
|
|||
return
|
||||
case system.StageEvent:
|
||||
if e.Stage == system.StageRunning {
|
||||
go func() {
|
||||
updateIdBtns()
|
||||
}()
|
||||
initPgp(w)
|
||||
}
|
||||
go func() {
|
||||
updateIdBtns()
|
||||
}()
|
||||
case system.FrameEvent:
|
||||
gtx.Reset(e.Config, e.Size)
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ func (b *Overlay) Layout(gtx *layout.Context) {
|
|||
ins.Layout(gtx, func() {
|
||||
l.Layout(gtx)
|
||||
})
|
||||
pointer.Rect(image.Rect(0, 0, gtx.Dimensions.Size.X, gtx.Dimensions.Size.Y)).Add(gtx.Ops)
|
||||
pointer.RectAreaOp{image.Rect(0, 0, gtx.Dimensions.Size.X, gtx.Dimensions.Size.Y)}.Add(gtx.Ops)
|
||||
})
|
||||
c1 := st.Expand(gtx, func() {
|
||||
layoutRRect(b.Background, gtx)
|
||||
|
@ -74,15 +74,13 @@ func layoutRRect(col color.RGBA, gtx *layout.Context) {
|
|||
f32.Point{0, 0},
|
||||
f32.Point{w, h},
|
||||
}
|
||||
//clip.RoundRect(gtx.Ops, rect, r, r, r, r)
|
||||
clip.Rect{Rect: rect, NE: r, NW: r, SE: r, SW: r}.Op(gtx.Ops).Add(gtx.Ops)
|
||||
clip.RoundRect(gtx.Ops, rect, r, r, r, r)
|
||||
paint.ColorOp{Color: col}.Add(gtx.Ops)
|
||||
paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{X: w, Y: h}}}.Add(gtx.Ops)
|
||||
gtx.Dimensions = layout.Dimensions{Size: sz}
|
||||
}
|
||||
|
||||
func (b *Button) Layout(gtx *layout.Context) {
|
||||
mwidth := gtx.Constraints.Width.Min
|
||||
b.clicked = false
|
||||
for _, ev := range b.Click.Events(gtx) {
|
||||
if ev.Type == gesture.TypeClick {
|
||||
|
@ -99,11 +97,10 @@ func (b *Button) Layout(gtx *layout.Context) {
|
|||
ins.Layout(gtx, func() {
|
||||
l.Layout(gtx)
|
||||
})
|
||||
pointer.Rect(image.Rect(0, 0, gtx.Dimensions.Size.X, gtx.Dimensions.Size.Y)).Add(gtx.Ops)
|
||||
pointer.RectAreaOp{image.Rect(0, 0, gtx.Dimensions.Size.X, gtx.Dimensions.Size.Y)}.Add(gtx.Ops)
|
||||
b.Click.Add(gtx.Ops)
|
||||
})
|
||||
c1 := st.Expand(gtx, func() {
|
||||
gtx.Constraints.Width.Min = mwidth
|
||||
layoutRRect(b.Background, gtx)
|
||||
})
|
||||
st.Layout(gtx, c1, c2)
|
||||
|
|
13
go.mod
13
go.mod
|
@ -1,13 +0,0 @@
|
|||
module git.wow.st/gmp/passgo
|
||||
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
gioui.org v0.0.0-20191126175243-2ca2e5462f16
|
||||
git.wow.st/gmp/clip v0.0.0-20191001134149-1458ba6a7cf5
|
||||
git.wow.st/gmp/rand v0.0.0-20191001220155-a81bebfaf8b0
|
||||
github.com/fsnotify/fsnotify v1.4.7
|
||||
github.com/jcmdev0/gpgagent v0.0.0-20180509014935-5601b32d936c
|
||||
golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c
|
||||
gopkg.in/yaml.v2 v2.2.7
|
||||
)
|
40
go.sum
40
go.sum
|
@ -1,40 +0,0 @@
|
|||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
gioui.org v0.0.0-20191126175243-2ca2e5462f16 h1:p31rtmKm51xpj2QtqGNlljAyHEP1oStU8MDRl2Dv7Gs=
|
||||
gioui.org v0.0.0-20191126175243-2ca2e5462f16/go.mod h1:KqFFi2Dq5gYA3FJ0sDOt8OBXoMsuxMtE8v2f0JExXAY=
|
||||
git.wow.st/gmp/clip v0.0.0-20191001134149-1458ba6a7cf5 h1:OKeTjZST+/TKvtdA258NXJH+/gIx/xwyZxKrAezNFvk=
|
||||
git.wow.st/gmp/clip v0.0.0-20191001134149-1458ba6a7cf5/go.mod h1:NLdpaBoMQNFqncwP8OVRNWUDw1Kt9XWm3snfT7cXu24=
|
||||
git.wow.st/gmp/rand v0.0.0-20191001220155-a81bebfaf8b0 h1:08wP00wvbDINsct1fzKV1xGGLvvtNsSb2X4CtIdpBzM=
|
||||
git.wow.st/gmp/rand v0.0.0-20191001220155-a81bebfaf8b0/go.mod h1:8+2Gwnrpc5yuk8Wp6cBhxvGcNLumYiPbQ7n0SQ8h29A=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||
github.com/jcmdev0/gpgagent v0.0.0-20180509014935-5601b32d936c h1:DCnjNrPDSEslcqqBgcZBxlLUIhk2elQVyf2V+HkyxJI=
|
||||
github.com/jcmdev0/gpgagent v0.0.0-20180509014935-5601b32d936c/go.mod h1:vdJ2op9pzpbH8CbpYKYBD6zjURqDY13PmnVn2I/uYBs=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c h1:/nJuwDLoL/zrqY6gf57vxC+Pi+pZ8bfhpPkicO5H7W4=
|
||||
golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3 h1:n9HxLrNxWWtEb1cA950nuEEj3QnKbtsCJ6KjcgisNUs=
|
||||
golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3/go.mod h1:NOZ3BPKG0ec/BKJQgnvsSFpcKLM5xXVWnvZS97DWHgE=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4=
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
||||
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ=
|
||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
|
||||
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
@ -27,33 +27,38 @@ import (
|
|||
var (
|
||||
h *app.Handle
|
||||
waitch chan struct{}
|
||||
//w *app.Window
|
||||
w *app.Window
|
||||
pgp PGP
|
||||
installCompleteOnce sync.Once
|
||||
InitPgpOnce sync.Once
|
||||
)
|
||||
|
||||
func init() {
|
||||
waitch = make(chan struct{})
|
||||
}
|
||||
|
||||
//export Java_st_wow_git_passgo_PgpConnect_installComplete
|
||||
func Java_st_wow_git_passgo_PgpConnect_installComplete(env *C.JNIEnv, class C.jclass, p C.jobject) {
|
||||
//export installComplete
|
||||
func installComplete(env *C.JNIEnv, class C.jclass, p C.jobject) {
|
||||
log.Printf("InstallComplete()")
|
||||
pgp = PGP(C.NewGlobalRef(env, p))
|
||||
h = app.PlatformHandle()
|
||||
SetJVM(h.JVM)
|
||||
installCompleteOnce.Do(func() {
|
||||
close(waitch)
|
||||
})
|
||||
close(waitch)
|
||||
}
|
||||
|
||||
func InitPgp(w *app.Window) {
|
||||
log.Printf("InitPgp()")
|
||||
w.RegisterFragment("st/wow/git/passgo/PgpConnect")
|
||||
func InitPgp(x *app.Window) {
|
||||
InitPgpOnce.Do(func() {
|
||||
log.Printf("InitPgp()")
|
||||
w = x
|
||||
h = app.PlatformHandle()
|
||||
SetJVM(h.JVM, h.Context)
|
||||
RunInJVM(func(env *JNIEnv) {
|
||||
C.InitPgpConnect(env)
|
||||
})
|
||||
w.RegisterDelegate("st/wow/git/passgo/PgpConnect")
|
||||
})
|
||||
}
|
||||
|
||||
func stopPgp() {
|
||||
waitch = make(chan struct{})
|
||||
w = nil
|
||||
}
|
||||
|
||||
func connect() {
|
||||
|
|
|
@ -2,9 +2,61 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
#include "jni_android.h"
|
||||
#include "_cgo_export.h"
|
||||
|
||||
static jobject gClassLoader;
|
||||
static jmethodID gFindClassMethod;
|
||||
|
||||
void
|
||||
SetLoader(JNIEnv* env, jobject context) {
|
||||
jclass cclass = (*env)->GetObjectClass(env, context);
|
||||
jmethodID gcl_id = (*env)->GetMethodID(env, cclass, "getClassLoader", "()Ljava/lang/ClassLoader;");
|
||||
jobject loader = (*env)->CallObjectMethod(env, context, gcl_id);
|
||||
gClassLoader = (*env)->NewGlobalRef(env, loader);
|
||||
jclass lclass = (*env)->GetObjectClass(env, loader);
|
||||
gFindClassMethod = (*env)->GetMethodID(env, lclass, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;");
|
||||
}
|
||||
|
||||
jclass
|
||||
FindClass(JNIEnv* env, char* name) {
|
||||
jstring strClassName = (*env)->NewStringUTF(env, name);
|
||||
return (*env)->CallObjectMethod(env, gClassLoader, gFindClassMethod, strClassName);
|
||||
}
|
||||
|
||||
jobject
|
||||
CreateObject(JNIEnv* env, jclass cls) {
|
||||
jmethodID init = (*env)->GetMethodID(env, cls, "<init>", "()V");
|
||||
return (*env)->NewObject(env, cls, init);
|
||||
}
|
||||
|
||||
void
|
||||
InitPgpConnect(JNIEnv* env) {
|
||||
jclass cls = FindClass(env, "st/wow/git/passgo/PgpConnect");
|
||||
printf("class = %p", cls);
|
||||
|
||||
static const JNINativeMethod actMethods[] = {
|
||||
{
|
||||
.name = "activityResult",
|
||||
.signature = "(II)V",
|
||||
.fnPtr = activityResult
|
||||
},
|
||||
{
|
||||
.name = "stringResult",
|
||||
.signature = "(ILjava/lang/String;)V",
|
||||
.fnPtr = stringResult
|
||||
},
|
||||
{
|
||||
.name = "installComplete",
|
||||
.signature = "(Lst/wow/git/passgo/PgpConnect;)V",
|
||||
.fnPtr = installComplete
|
||||
},
|
||||
};
|
||||
|
||||
(*env)->RegisterNatives(env, cls, actMethods, sizeof(actMethods)/sizeof(actMethods[0]));
|
||||
}
|
||||
|
||||
void
|
||||
GetId(JNIEnv* env, jobject p, int chint) {
|
||||
jclass cls = (*env)->GetObjectClass(env, p);
|
||||
|
@ -25,7 +77,7 @@ Decrypt(JNIEnv* env, jobject p, char* cdata, int datalen, int chint) {
|
|||
(*env)->CallVoidMethod(env, p, mid, data, chint);
|
||||
}
|
||||
|
||||
void Java_st_wow_git_passgo_PgpConnect_stringResult(JNIEnv* env, jclass cls, jint requestCode, jobject response) {
|
||||
void stringResult(JNIEnv* env, jclass cls, jint requestCode, jobject response) {
|
||||
if (response == 0) {
|
||||
goStringResult(env, cls, requestCode, 0);
|
||||
} else {
|
||||
|
@ -64,6 +116,18 @@ void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID) {
|
|||
(*env)->CallVoidMethod(env, obj, methodID);
|
||||
}
|
||||
|
||||
void CallVoidMethod1(JNIEnv *env, jobject obj, jmethodID methodID, jobject arg) {
|
||||
(*env)->CallVoidMethod(env, obj, methodID, arg);
|
||||
}
|
||||
|
||||
jint CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID) {
|
||||
return (*env)->CallIntMethod(env, obj, methodID);
|
||||
}
|
||||
|
||||
jmethodID GetMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig) {
|
||||
return (*env)->GetMethodID(env, clazz, name, sig);
|
||||
}
|
||||
|
||||
jint GetEnv(JavaVM *vm, JNIEnv **env, jint version) {
|
||||
return (*vm)->GetEnv(vm, (void **)env, version);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package passgo
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: -landroid
|
||||
#cgo LDFLAGS: -landroid -llog
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "jni_android.h"
|
||||
|
@ -20,17 +20,54 @@ import (
|
|||
var theJVM *C.JavaVM
|
||||
type JNIEnv = C.JNIEnv
|
||||
|
||||
func SetJVM(jvm uintptr) {
|
||||
func SetJVM(jvm, context uintptr) {
|
||||
log.Print("set theJVM")
|
||||
theJVM = (*C.JavaVM)(unsafe.Pointer(jvm))
|
||||
RunInJVM(func(env *C.JNIEnv) {
|
||||
C.SetLoader(env, (C.jobject)(context))
|
||||
})
|
||||
}
|
||||
|
||||
func FindClass(env *C.JNIEnv, name string) C.jclass {
|
||||
cname := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cname))
|
||||
return C.FindClass((*C.JNIEnv)(env), cname)
|
||||
}
|
||||
|
||||
func JniCallVoidMethod(env *C.JNIEnv, obj C.jobject, methodID C.jmethodID) {
|
||||
C.CallVoidMethod(env, obj, methodID)
|
||||
}
|
||||
|
||||
func JniCallVoidMethod1(env *C.JNIEnv, obj C.jobject, methodID C.jmethodID, arg uintptr) {
|
||||
C.CallVoidMethod1(env, obj, methodID, C.jobject(unsafe.Pointer(arg)))
|
||||
}
|
||||
|
||||
func JniCallIntMethod(env *C.JNIEnv, obj C.jobject, methodID C.jmethodID) int {
|
||||
return (int)(C.CallIntMethod(env, obj, methodID))
|
||||
}
|
||||
|
||||
func JniGetMethodID(env *C.JNIEnv, cls C.jclass, name, sig string) C.jmethodID {
|
||||
cname := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cname))
|
||||
csig := C.CString(sig)
|
||||
defer C.free(unsafe.Pointer(csig))
|
||||
return C.GetMethodID(env, cls, cname, csig)
|
||||
}
|
||||
|
||||
func CreateObject(env *C.JNIEnv, cls C.jclass) C.jobject {
|
||||
return C.CreateObject(env, (C.jclass)(cls))
|
||||
}
|
||||
|
||||
type PGP C.jobject
|
||||
|
||||
func InitPgpConnect(env uintptr) {
|
||||
C.InitPgpConnect((*C.JNIEnv)(unsafe.Pointer(env)))
|
||||
}
|
||||
|
||||
//func NewPgpConnect(env uintptr, act uintptr) PGP {
|
||||
// return (PGP)(C.NewPgpConnect((*C.JNIEnv)(unsafe.Pointer(env)), (C.jobject)(unsafe.Pointer(act))))
|
||||
//}
|
||||
|
||||
var (
|
||||
fragChans map[int]chan string
|
||||
chmux sync.Mutex
|
||||
|
@ -143,6 +180,11 @@ func RunInJVM(f func(env *C.JNIEnv)) {
|
|||
f(env)
|
||||
}
|
||||
|
||||
//export activityResult
|
||||
func activityResult(env *C.JNIEnv, class C.jclass, request, result C.jint) {
|
||||
log.Printf("activityResult (%d): %d", request, result)
|
||||
}
|
||||
|
||||
//export goStringResult
|
||||
func goStringResult(env *C.JNIEnv, class C.jclass, request C.jint, str *C.char) {
|
||||
fragChans[int(request)] <- C.GoString(str)
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
#include <jni.h>
|
||||
|
||||
void SetLoader(JNIEnv* env, jobject context);
|
||||
jclass FindClass(JNIEnv* env, char* name);
|
||||
jobject CreateObject(JNIEnv* env, jclass cls);
|
||||
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);
|
||||
jint CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID);
|
||||
jmethodID GetMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig);
|
||||
jint GetEnv(JavaVM *vm, JNIEnv **env, jint version);
|
||||
jint AttachCurrentThread(JavaVM *vm, JNIEnv **p_env, void *thr_args);
|
||||
jint DetachCurrentThread(JavaVM *vm);
|
||||
|
|
Loading…
Reference in New Issue
Block a user