66 lines
1.2 KiB
Go
66 lines
1.2 KiB
Go
//go:generate mkdir -p classes
|
|
//go:generate javac -bootclasspath $ANDROID_HOME/platforms/android-29/android.jar -classpath openpgp-api.jar -d classes PgpConnect.java
|
|
//go:generate jar cf PgpConnect.jar -C classes .
|
|
//go:generate rm -rf classes
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
|
|
"gioui.org/app"
|
|
)
|
|
|
|
var (
|
|
h *app.Handle
|
|
connected bool
|
|
pgp PGP
|
|
)
|
|
|
|
|
|
func connect() {
|
|
if !connected {
|
|
log.Print("PlatformHandle()")
|
|
h = app.PlatformHandle()
|
|
log.Print("SetJVM()")
|
|
SetJVM(h.JVM, h.Activity)
|
|
log.Print("SetJVM() returned")
|
|
RunInJVM(func(env *JNIEnv) {
|
|
log.Print("NewPgpConnect()")
|
|
pgp = NewPgpConnect(env, h.Activity)
|
|
})
|
|
connected = true
|
|
}
|
|
}
|
|
|
|
func checkPermission() bool {
|
|
connect()
|
|
//return pgp.CheckPermission(env)
|
|
return false
|
|
}
|
|
|
|
func callJni() {
|
|
connect()
|
|
labchan <- fmt.Sprintf("JVM = %d", h.JVM)
|
|
labchan <- fmt.Sprintf("Activity = %d", h.Activity)
|
|
time.Sleep(time.Second / 5)
|
|
|
|
val, err := pgp.Encrypt("greg_pomerantz@yahoo.com", "hi there")
|
|
if err != nil {
|
|
fmt.Printf("Encryption error: %s", err)
|
|
labchan <- err.Error()
|
|
return
|
|
}
|
|
log.Print("val = ", val)
|
|
val2, err := pgp.Decrypt(val)
|
|
if err != nil {
|
|
fmt.Printf("Decryption error: %s", err)
|
|
labchan <- err.Error()
|
|
return
|
|
}
|
|
labchan <- "result = " + val2
|
|
}
|
|
|