Guard against Gio's null-view detach event (recents-wipe SIGABRT) #1

Closed
gmp wants to merge 1 commits from fix/recents-wipe-jni-null-view into master
3 changed files with 23 additions and 0 deletions

View File

@ -23,6 +23,15 @@ func init() {
func handleEvent(e event.Event) {
switch e := e.(type) {
case app.ViewEvent:
// View == 0 is Gio's detach signal: GioView.onDestroyView sends
// ViewEvent{View: 0} when the view is destroyed (e.g. the activity
// going away on a recents-wipe). There is nothing to register for a
// detached view; passing the null ref on would abort in JNI
// (GetObjectClass on null). A re-attach arrives as a fresh event
// with a live view.
if e.View == 0 {
return
}
initPgp(e.View)
}
}

View File

@ -49,6 +49,12 @@ func Java_st_wow_git_passgo_PgpConnect_installComplete(env *C.JNIEnv, class C.jc
func InitPgp(view uintptr) {
log.Printf("InitPgp()")
// view == 0 is Gio's detach signal (GioView.onDestroyView); nothing to
// register. Guard here as well so callers that forward the event
// unfiltered cannot drive registerFragment with a null ref (JNI abort).
if view == 0 {
return
}
jvm = app.JavaVM()
SetJVM(jvm) // why?
RunInJVM(func(env *JNIEnv) {

View File

@ -7,6 +7,14 @@
void
registerFragment(JNIEnv *env, jobject view) {
if (view == NULL) {
// Detach signal (Gio sends ViewEvent{View: 0} when the view is
// destroyed, e.g. the activity going away on a recents-wipe).
// The Go side already filters these; this guard keeps the JNI
// calls safe if one ever slips through (GetObjectClass on null
// aborts the process).
return;
}
jclass cls = (*env)->GetObjectClass(env, view);
jmethodID mid = (*env)->GetMethodID(env, cls, "getContext", "()Landroid/content/Context;");
jobject ctx = (*env)->CallObjectMethod(env, view, mid);