Skip to content

Commit 3106845

Browse files
committed
ANDROID: remove hardcoded references to /sdcard path
1 parent 3c074d6 commit 3106845

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

src/platform/android/app/src/main/assets/main.bas

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ end
232232

233233
sub loadFileList(path, byref basList)
234234
erase basList
235-
local emptyNode, storage
235+
local emptyNode, ext_storage, int_storage
236236

237237
func walker(node)
238238
if (node.depth==0) then
@@ -249,9 +249,17 @@ sub loadFileList(path, byref basList)
249249
dirwalk path, "", use walker(x)
250250

251251
if (path = "/" && len(basList) == 0 && !is_sdl) then
252-
storage = env("EXTERNAL_STORAGE")
253-
if (len(storage) > 0) then
254-
emptyNode.name = mid(storage, 2)
252+
ext_storage = env("EXTERNAL_STORAGE")
253+
if (len(ext_storage) > 0) then
254+
emptyNode.name = mid(ext_storage, 2)
255+
emptyNode.dir = true
256+
emptyNode.size = ""
257+
emptyNode.mtime = 0
258+
basList << emptyNode
259+
endif
260+
int_storage = env("INTERNAL_STORAGE")
261+
if (len(int_storage) > 0 && int_storage != ext_storage) then
262+
emptyNode.name = mid(int_storage, 2)
255263
emptyNode.dir = true
256264
emptyNode.size = ""
257265
emptyNode.mtime = 0

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,16 @@ public String getExternalStorage() {
257257
result = path;
258258
}
259259
} else {
260-
result = getFilesDir().getAbsolutePath();
260+
result = getInternalStorage();
261261
}
262262
return result;
263263
}
264264

265-
public String getIPAddress() {
265+
public String getInternalStorage() {
266+
return getFilesDir().getAbsolutePath();
267+
}
268+
269+
public String getIpAddress() {
266270
String result = "";
267271
try {
268272
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
@@ -385,16 +389,6 @@ public boolean onPrepareOptionsMenu(Menu menu) {
385389
return super.onPrepareOptionsMenu(menu);
386390
}
387391

388-
@Override
389-
public void onRequestPermissionsResult(int requestCode,
390-
@NonNull String[] permissions,
391-
@NonNull int[] grantResults) {
392-
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
393-
if (requestCode == REQUEST_STORAGE_PERMISSION && grantResults[0] == PackageManager.PERMISSION_DENIED) {
394-
exit();
395-
}
396-
}
397-
398392
public void optionsBox(final String[] items) {
399393
this._options = items;
400394
runOnUiThread(new Runnable() {
@@ -702,12 +696,6 @@ private void execStream(final String line, DataInputStream inputStream) throws I
702696
runFile(outputFile.getAbsolutePath());
703697
}
704698

705-
private void exit() {
706-
moveTaskToBack(true);
707-
android.os.Process.killProcess(android.os.Process.myPid());
708-
System.exit(1);
709-
}
710-
711699
private Map<String, String> getPostData(DataInputStream inputStream, final String line) throws IOException {
712700
int length = 0;
713701
final String lengthHeader = "content-length: ";

src/platform/android/jni/runtime.cpp

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

461-
String ipAddress = getString("getIPAddress");
461+
String ipAddress = getString("getIpAddress");
462462
if (!ipAddress.empty()) {
463463
setenv("IP_ADDR", ipAddress.c_str(), 1);
464464
}
@@ -487,7 +487,11 @@ void Runtime::loadConfig() {
487487
_output->setFontSize(fontSize);
488488
_initialFontSize = _output->getFontSize();
489489

490-
String storage = getString("getExternalStorage");
490+
String storage = getString("getInternalStorage");
491+
if (!storage.empty()) {
492+
setenv("INTERNAL_STORAGE", storage.c_str(), 1);
493+
}
494+
storage = getString("getExternalStorage");
491495
if (!storage.empty()) {
492496
setenv("EXTERNAL_STORAGE", storage.c_str(), 1);
493497
chdir(storage.c_str());

0 commit comments

Comments
 (0)