Skip to content

Commit c75299d

Browse files
committed
ANDROID: avoid check permission race
1 parent 168ab92 commit c75299d

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/platform/android/app/src/main/java/net/sourceforge/smallbasic/MainActivity.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.net.Uri;
2323
import android.os.Bundle;
2424
import android.os.Environment;
25+
import android.os.Handler;
2526
import android.support.v4.app.ActivityCompat;
2627
import android.support.v4.content.ContextCompat;
2728
import android.util.Base64;
@@ -186,17 +187,6 @@ public void browseFile(final byte[] pathBytes) {
186187
}
187188
}
188189

189-
public int checkFilePermission() {
190-
int result;
191-
if (!permitted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
192-
checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, REQUEST_STORAGE_PERMISSION);
193-
result = 1;
194-
} else {
195-
result = 0;
196-
}
197-
return result;
198-
}
199-
200190
public void clearSoundQueue() {
201191
Log.i(TAG, "clearSoundQueue");
202192
for (Sound sound : _sounds) {
@@ -606,6 +596,7 @@ protected void onCreate(Bundle savedInstanceState) {
606596
super.onCreate(savedInstanceState);
607597
processIntent();
608598
processSettings();
599+
checkFilePermission();
609600
}
610601

611602
@Override
@@ -635,6 +626,18 @@ private String buildTokenForm() {
635626
"<input value=OK name=okay type=submit style='vertical-align:top'></form>";
636627
}
637628

629+
private void checkFilePermission() {
630+
if (!permitted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
631+
Runnable handler = new Runnable() {
632+
@Override
633+
public void run() {
634+
checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, REQUEST_STORAGE_PERMISSION);
635+
}
636+
};
637+
new Handler().postDelayed(handler, 250);
638+
}
639+
}
640+
638641
private void checkPermission(final String permission, final int result) {
639642
runOnUiThread(new Runnable() {
640643
@Override

src/platform/android/jni/runtime.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,6 @@ void Runtime::runShell() {
458458
_app->activity->callbacks->onContentRectChanged = onContentRectChanged;
459459
loadConfig();
460460

461-
getInteger("checkFilePermission");
462-
463461
String ipAddress = getString("getIpAddress");
464462
if (!ipAddress.empty()) {
465463
setenv("IP_ADDR", ipAddress.c_str(), 1);

0 commit comments

Comments
 (0)