Guard the JNI fragment registration against the null detach view.
Gio's GioView.onDestroyView signals detach with ViewEvent{View: 0};
handleEvent already filters these, but add defense in depth so any
caller forwarding the event unfiltered cannot drive the JNI path
(GetObjectClass on a null ref aborts the process, the recents-wipe
SIGABRT). Completes the intent of PR #1, whose handleEvent guard is
already in master from the migration commit.
Fixes: recents-wipe crash defense (PR #1 superseded).
This commit is contained in:
parent
dc7661e226
commit
4c337ff06d
|
|
@ -51,6 +51,9 @@ func Java_st_wow_git_passgo_PgpConnect_installComplete(env *C.JNIEnv, class C.jc
|
||||||
|
|
||||||
func InitPgp(view uintptr) {
|
func InitPgp(view uintptr) {
|
||||||
log.Printf("InitPgp()")
|
log.Printf("InitPgp()")
|
||||||
|
if view == 0 {
|
||||||
|
return // detach signal; nothing to register
|
||||||
|
}
|
||||||
jvm = app.JavaVM()
|
jvm = app.JavaVM()
|
||||||
SetJVM(jvm) // why?
|
SetJVM(jvm) // why?
|
||||||
RunInJVM(func(env *JNIEnv) {
|
RunInJVM(func(env *JNIEnv) {
|
||||||
|
|
@ -63,6 +66,9 @@ func InitPgp(view uintptr) {
|
||||||
// screen on Android 11+) so the app can read the store in shared storage.
|
// screen on Android 11+) so the app can read the store in shared storage.
|
||||||
func InitPermissions(view uintptr) {
|
func InitPermissions(view uintptr) {
|
||||||
log.Printf("InitPermissions()")
|
log.Printf("InitPermissions()")
|
||||||
|
if view == 0 {
|
||||||
|
return // detach signal; nothing to register
|
||||||
|
}
|
||||||
RunInJVM(func(env *JNIEnv) {
|
RunInJVM(func(env *JNIEnv) {
|
||||||
C.registerPermissionsFragment(env, (C.jobject)(unsafe.Pointer(view)))
|
C.registerPermissionsFragment(env, (C.jobject)(unsafe.Pointer(view)))
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,12 @@
|
||||||
|
|
||||||
void
|
void
|
||||||
registerFragment(JNIEnv *env, jobject view) {
|
registerFragment(JNIEnv *env, jobject view) {
|
||||||
|
if (view == NULL) {
|
||||||
|
// Detach signal (Gio sends ViewEvent{View: 0} when the view is
|
||||||
|
// destroyed, e.g. on a recents-wipe); the Go side already
|
||||||
|
// filters these, but GetObjectClass(null) aborts the process.
|
||||||
|
return;
|
||||||
|
}
|
||||||
jclass cls = (*env)->GetObjectClass(env, view);
|
jclass cls = (*env)->GetObjectClass(env, view);
|
||||||
jmethodID mid = (*env)->GetMethodID(env, cls, "getContext", "()Landroid/content/Context;");
|
jmethodID mid = (*env)->GetMethodID(env, cls, "getContext", "()Landroid/content/Context;");
|
||||||
jobject ctx = (*env)->CallObjectMethod(env, view, mid);
|
jobject ctx = (*env)->CallObjectMethod(env, view, mid);
|
||||||
|
|
@ -23,6 +29,9 @@ registerFragment(JNIEnv *env, jobject view) {
|
||||||
|
|
||||||
void
|
void
|
||||||
registerPermissionsFragment(JNIEnv *env, jobject view) {
|
registerPermissionsFragment(JNIEnv *env, jobject view) {
|
||||||
|
if (view == NULL) {
|
||||||
|
return; // detach signal; see registerFragment
|
||||||
|
}
|
||||||
jclass cls = (*env)->GetObjectClass(env, view);
|
jclass cls = (*env)->GetObjectClass(env, view);
|
||||||
jmethodID mid = (*env)->GetMethodID(env, cls, "getContext", "()Landroid/content/Context;");
|
jmethodID mid = (*env)->GetMethodID(env, cls, "getContext", "()Landroid/content/Context;");
|
||||||
jobject ctx = (*env)->CallObjectMethod(env, view, mid);
|
jobject ctx = (*env)->CallObjectMethod(env, view, mid);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user