Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANDROID: additional error checking on JNI an more #386

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

0-8-15
Copy link
Contributor

@0-8-15 0-8-15 commented Nov 2, 2020

Preface: I have not been able to break this in meaningful smaller patches. All changes where required to pass a meaningful test case.

1.) Android 9/10 restricts access to JNI and Jave reflection API's.

This adds additional checks.

Commented out an possible optimization, which could be assumed to
works, but does not for me so far. Please leave this comment in, so
we recall before we wonder why and try over and over again. Once in a
while we should ponder if it still does not work or why.

2.) Clear Java exceptions.

This enables to continue to run when an exception ocured during a JNI
call. (Future versions shall forward this as an exception in Gambit.)

3.) Avoid some JNI calls and provide more information about the
Java/Android environment to Scheme.

This is required for (upcoming) tricks to still call embedded dynamic
libraries as subprocesses.

It also enables to figure out a sane path to store app-private data
instead of the deprecated hard coding of the publicly accessible path
/sdcard.

4.) Add support to switch the apps content view to Java and back.

An upcoming module webview will need this.

1.) Android 9/10 restricts access to JNI and Jave reflection API's.

This adds additional checks.

Commented out an possible optimization, which could be assumed to
works, but does not for me so far.  Please leave this comment in, so
we recall before we wonder why and try over and over again.  Once in a
while we should ponder if it still does not work or why.

2.) Clear Java exceptions.

This enables to continue to run when an exception occured during a JNI
call.  (Future versions shall forward this as an exception in Gambit.)

3.) Avoid some JNI calls and provide more information about the
Java/Android environment to Scheme.

This is required for (upcoming) tricks to still call embedded dynamic
libraries as subprocesses.

It also enables to figure out a sane path to store app-private data
instead of the deprecated hard coding of the publicly accessible path
`/sdcard`.

4.) Add support to switch the apps content view to Java and back.

An upcoming module `webview` will need this.
@0-8-15 0-8-15 mentioned this pull request Nov 2, 2020
@mgorges
Copy link
Contributor

mgorges commented Nov 5, 2020

I might break this into three commit when I push it into master, just to clearly identify what does what. Not sure yet though.

#if 1
sprintf(path,"/sdcard/%s", SYS_APPNAME);
sys_dir=strdup(path);
sys_appdir=android_getFilesDir();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A potential concern to confirm during testing is what we do with apps that get upgraded and that have files in the previous location, which is no longer accessible if we do this? The approach in #380 might be an interesting (or complementary) change.

@@ -126,42 +126,65 @@ public class @SYS_APPNAME@ extends Activity implements @ANDROID_JAVA_IMPLEMENTS@
}
}

private android.view.View current_ContentView = null;
@Override
public void setContentView(android.view.View view) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self - move to separate commit - unrelated to everything else

}

class xGLSurfaceView extends GLSurfaceView {
public xGLSurfaceView(Context context) {
super(context);
setFocusable(true);
setFocusable(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes from here on out in this file are cosmetic (space at end of line). I guess the vimrc from #135 was never included anywhere?

extern char* android_getPackageCodePath();
EOF
)
(define (android-PackageCodePath) ((c-lambda () char-string "android_getPackageCodePath"))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a strange naming conversion for a scheme function, more like Java with CamelCase?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this function is not defined on non-android platforms, which may be a problem as how do we prevent users from including this in their code? Wouldn't it be safer to always declare it and simply not do anything on non-android platforms?

@0-8-15
Copy link
Contributor Author

0-8-15 commented Nov 6, 2020 via email

char* android_getFilesDir() { return (char*) app_directory_files; }
char* android_getPackageCodePath() { return (char*) app_code_path; }

char* android_getFilesDir_info_get() { return android_getFilesDir(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry why is this needed - it does the exact same thing as android_getFilesDir(), which is defined 2 lines above?

(android
(c-declare #<<EOF
extern char* android_getFilesDir_info_get();
char* android_getFilesDir_info()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are now making a third way of calling android_getFilesDir() - am I missing something that makes this one different? as otherwise only the extern char* android_getPackageCodePath() needs to stay here?

int JNI_forward_exception_to_gambit(JNIEnv*env) {
// TBD: actually forward, not only clear!
if((*env)->ExceptionCheck(env)) {
(*env)->ExceptionClear(env);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0-8-15
Copy link
Contributor Author

0-8-15 commented Nov 7, 2020 via email

@0-8-15
Copy link
Contributor Author

0-8-15 commented Nov 7, 2020 via email

@0-8-15
Copy link
Contributor Author

0-8-15 commented Nov 7, 2020 via email

mgorges pushed a commit that referenced this pull request Nov 9, 2020
An upcoming module webview will need this.
mgorges added a commit that referenced this pull request Nov 9, 2020
Avoid some JNI calls and provide more information about the Java/Android environment to Scheme.

Co-authored-by: Matthias Görges <[email protected]>
mgorges pushed a commit that referenced this pull request Nov 9, 2020
1) Android 9/10 restricts access to JNI and Jave reflection API's. This adds additional checks. Commented out an possible optimization, which could be assumed to works, but does not for me so far.  Please leave this comment in, so we recall before we wonder why and try over and over again.  Once in a while we should ponder if it still does not work or why.
2) Clear Java exceptions. This enables to continue to run when an exception occured during a JNI call.  (Future versions shall forward this as an exception in Gambit.)
@mgorges
Copy link
Contributor

mgorges commented Nov 9, 2020

Alright, I hope I have faithfully committed this as three separate commits. I then had to fix (*env)->ReleaseStringUTFChars(env, codePath, NULL); as I get a JNI exception with NULL not being allowed? Will need to do a bit more testing but the simple apps I tried in the simulator seem to run.

@mgorges
Copy link
Contributor

mgorges commented Nov 20, 2020

Short of the dealing of JNI exceptions, has this been merged in functionally equivalent three changes so we can close this one?

@0-8-15
Copy link
Contributor Author

0-8-15 commented Nov 20, 2020

let's see.

give me some to reconcile my differences here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants