Skip to content

Commit dfa0547

Browse files
0-8-15mgorges
authored andcommitted
Compilation and permissions for ANDROIDAPI>22. (#257)
Since Marshmallow permissions are not automatically granted as specified in the Manifest. As a consequence LN apps crash 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. It also creates the system-directory if it does not already exists.
1 parent 37b2cde commit dfa0547

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

loaders/android/bootstrap.java.in

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public class @SYS_APPNAME@ extends Activity implements @ANDROID_JAVA_IMPLEMENTS@
7575
//Variable declarations needed for modules, e.g. gps
7676
@ANDROID_JAVA_VARIABLES@
7777

78+
int idle_tmScheduleRate = 250;
7879
Timer idle_tm = new Timer();
7980
TimerTask idle_task = new TimerTask() {
8081
public void run() {
@@ -109,11 +110,20 @@ public class @SYS_APPNAME@ extends Activity implements @ANDROID_JAVA_IMPLEMENTS@
109110
mGLView = new xGLSurfaceView(this);
110111
setContentView(mGLView);
111112
mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
113+
114+
@IF_ANDROIDAPI_GT_22@
115+
if (getApplicationContext().checkCallingOrSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
116+
!= android.content.pm.PackageManager.PERMISSION_GRANTED) {
117+
requestPermissions(new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1);
118+
// startActivity(new Intent(android.provider.Settings.ACTION_MEMORY_CARD_SETTINGS).setData(Uri.parse("package:"+"@SYS_PACKAGE_DOT@")));
119+
}
120+
/* end of IF_ANDROIDAPI_GT_22 */
121+
112122
// Additions needed by modules, e.g. gps
113123
@ANDROID_JAVA_ONCREATE@
114124

115125
// start EVENT_IDLE
116-
idle_tm.scheduleAtFixedRate(idle_task, 0, 250);
126+
if(idle_tmScheduleRate > 0) idle_tm.scheduleAtFixedRate(idle_task, 0, idle_tmScheduleRate);
117127

118128
nativeInstanceInit();
119129
}

make.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ make_setup_target()
10321032
ac_subst SYS_APPVERSION
10331033
ac_subst SYS_APPVERSIONCODE
10341034
ac_subst SYS_ANDROIDAPI
1035+
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`"
10351036
ac_subst SYS_ANDROIDSDK
10361037
ac_subst SYS_ANDROIDNDK
10371038
ac_subst SYS_ANDROIDARCH

modules/ln_core/packtool.scm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5656

5757
;; extract an embedded file
5858
(define (packtool-unpack file cdata overwrite)
59+
(let ((rootpath (system-directory)))
60+
(if (not (file-exists? rootpath)) (create-directory rootpath)))
5961
(let ((path (packtool:prep file)))
6062
(if (or overwrite (not (file-exists? path)))
6163
(let ((data (u8vector-decompress cdata)))

0 commit comments

Comments
 (0)