From 2cd0b537649af902424e4df53a42bde86b24162f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20F=2E=20Wittenberger?= Date: Thu, 29 Aug 2019 17:02:18 +0200 Subject: [PATCH 1/3] Handle compilation and permissions for ANDROIDAPI>22. Since Marshmallow permissions are not automatically granted as specified in the Manifest. As a consequence LN apps die when accessing the SDCard, e.g. when unpacking embedded files. This patch adds a fragile hack to enable an ifdef-alike trick to exclude code portions when targeting older APIs and uses it to request the permission at startup. Plus create the system-directory if it does not already exists. --- loaders/android/bootstrap.java.in | 12 +++++++++++- make.sh | 1 + modules/ln_core/packtool.scm | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/loaders/android/bootstrap.java.in b/loaders/android/bootstrap.java.in index 7a27b643..73963b90 100644 --- a/loaders/android/bootstrap.java.in +++ b/loaders/android/bootstrap.java.in @@ -75,6 +75,7 @@ public class @SYS_APPNAME@ extends Activity implements @ANDROID_JAVA_IMPLEMENTS@ //Variable declarations needed for modules, e.g. gps @ANDROID_JAVA_VARIABLES@ + int idle_tmScheduleRate = 250; Timer idle_tm = new Timer(); TimerTask idle_task = new TimerTask() { public void run() { @@ -109,11 +110,20 @@ public class @SYS_APPNAME@ extends Activity implements @ANDROID_JAVA_IMPLEMENTS@ mGLView = new xGLSurfaceView(this); setContentView(mGLView); mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE); + + /* Included @IF_ANDROIDAPI_GT_22@ + if (getApplicationContext().checkCallingOrSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) + != android.content.pm.PackageManager.PERMISSION_GRANTED) { + requestPermissions(new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1); + // startActivity(new Intent(android.provider.Settings.ACTION_MEMORY_CARD_SETTINGS).setData(Uri.parse("package:"+"@SYS_PACKAGE_DOT@"))); + } + /* end of IF_ANDROIDAPI_GT_22 */ + // Additions needed by modules, e.g. gps @ANDROID_JAVA_ONCREATE@ // start EVENT_IDLE - idle_tm.scheduleAtFixedRate(idle_task, 0, 250); + if(idle_tmScheduleRate > 0) idle_tm.scheduleAtFixedRate(idle_task, 0, idle_tmScheduleRate); nativeInstanceInit(); } diff --git a/make.sh b/make.sh index 4226df4f..e3f31641 100755 --- a/make.sh +++ b/make.sh @@ -1032,6 +1032,7 @@ make_setup_target() ac_subst SYS_APPVERSION ac_subst SYS_APPVERSIONCODE ac_subst SYS_ANDROIDAPI + ac_subst IF_ANDROIDAPI_GT_22 "`if [ $SYS_ANDROIDAPI -lt 23 ]; then echo 'commented out:'; else echo 'active here:*/'; fi`" ac_subst SYS_ANDROIDSDK ac_subst SYS_ANDROIDNDK ac_subst SYS_ANDROIDARCH diff --git a/modules/ln_core/packtool.scm b/modules/ln_core/packtool.scm index 2952c3e4..8b6f8dff 100644 --- a/modules/ln_core/packtool.scm +++ b/modules/ln_core/packtool.scm @@ -56,6 +56,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;; extract an embedded file (define (packtool-unpack file cdata overwrite) + (let ((rootpath (system-directory))) + (if (not (file-exists? rootpath)) (create-directory rootpath))) (let ((path (packtool:prep file))) (if (or overwrite (not (file-exists? path))) (let ((data (u8vector-decompress cdata))) From 6fc0e7a93fcb86f3b5db7763e0089c1b66d4c7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20F=2E=20Wittenberger?= Date: Thu, 29 Aug 2019 21:13:16 +0200 Subject: [PATCH 2/3] Do not break syntax highlighting by `ifdef` alike trick. --- loaders/android/bootstrap.java.in | 2 +- make.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/loaders/android/bootstrap.java.in b/loaders/android/bootstrap.java.in index 73963b90..fe55ef6e 100644 --- a/loaders/android/bootstrap.java.in +++ b/loaders/android/bootstrap.java.in @@ -111,7 +111,7 @@ public class @SYS_APPNAME@ extends Activity implements @ANDROID_JAVA_IMPLEMENTS@ setContentView(mGLView); mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE); - /* Included @IF_ANDROIDAPI_GT_22@ + @IF_ANDROIDAPI_GT_22@ if (getApplicationContext().checkCallingOrSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != android.content.pm.PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1); diff --git a/make.sh b/make.sh index e3f31641..f95b4386 100755 --- a/make.sh +++ b/make.sh @@ -1032,7 +1032,7 @@ make_setup_target() ac_subst SYS_APPVERSION ac_subst SYS_APPVERSIONCODE ac_subst SYS_ANDROIDAPI - ac_subst IF_ANDROIDAPI_GT_22 "`if [ $SYS_ANDROIDAPI -lt 23 ]; then echo 'commented out:'; else echo 'active here:*/'; fi`" + ac_subst IF_ANDROIDAPI_GT_22 "`if [ $SYS_ANDROIDAPI -lt 23 ]; then echo '/* commented out:'; else echo '/* active here:*/'; fi`" ac_subst SYS_ANDROIDSDK ac_subst SYS_ANDROIDNDK ac_subst SYS_ANDROIDARCH From e53a75602c2d5632891c578de99cedb70d3a4b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20F=2E=20Wittenberger?= Date: Thu, 29 Aug 2019 21:35:01 +0200 Subject: [PATCH 3/3] Slightly improve the generated comments. --- make.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make.sh b/make.sh index f95b4386..27c3f7c7 100755 --- a/make.sh +++ b/make.sh @@ -1032,7 +1032,7 @@ make_setup_target() ac_subst SYS_APPVERSION ac_subst SYS_APPVERSIONCODE ac_subst SYS_ANDROIDAPI - ac_subst IF_ANDROIDAPI_GT_22 "`if [ $SYS_ANDROIDAPI -lt 23 ]; then echo '/* commented out:'; else echo '/* active here:*/'; fi`" + ac_subst IF_ANDROIDAPI_GT_22 "`if [ $SYS_ANDROIDAPI -lt 23 ]; then echo '/* IF_ANDROIDAPI_GT_22 commented out:'; else echo '/* IF_ANDROIDAPI_GT_22 active here:*/'; fi`" ac_subst SYS_ANDROIDSDK ac_subst SYS_ANDROIDNDK ac_subst SYS_ANDROIDARCH