Skip to content

Commit 3ad217a

Browse files
committed
ANDROID: update handling with permission denied errors
1 parent 096f277 commit 3ad217a

File tree

5 files changed

+33
-26
lines changed

5 files changed

+33
-26
lines changed

src/platform/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ android {
99
applicationId 'net.sourceforge.smallbasic'
1010
minSdkVersion 16
1111
targetSdkVersion 33
12-
versionCode 54
12+
versionCode 55
1313
versionName '12.25'
1414
resConfigs 'en'
1515
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import java.util.Map;
7373
import java.util.Properties;
7474
import java.util.Queue;
75+
import java.util.concurrent.ConcurrentHashMap;
7576
import java.util.concurrent.ConcurrentLinkedQueue;
7677
import java.util.concurrent.ExecutorService;
7778
import java.util.concurrent.Executors;
@@ -103,7 +104,7 @@ public class MainActivity extends NativeActivity {
103104
private final ExecutorService _audioExecutor = Executors.newSingleThreadExecutor();
104105
private final Queue<Sound> _sounds = new ConcurrentLinkedQueue<>();
105106
private final Handler _keypadHandler = new Handler(Looper.getMainLooper());
106-
private final Map<String, Boolean> permittedHost = new HashMap<>();
107+
private final Map<String, Boolean> permittedHost = new ConcurrentHashMap<>();
107108
private String[] _options = null;
108109
private MediaPlayer _mediaPlayer = null;
109110
private LocationAdapter _locationAdapter = null;
@@ -776,7 +777,7 @@ private boolean isHostDenied(String remoteHost) {
776777
return (remoteHost != null && permittedHost.get(remoteHost) != null && Boolean.FALSE.equals(permittedHost.get(remoteHost)));
777778
}
778779

779-
private boolean isHostNonPermitted(String remoteHost) {
780+
private boolean isHostNotPermitted(String remoteHost) {
780781
return (remoteHost == null || permittedHost.get(remoteHost) == null || !Boolean.TRUE.equals(permittedHost.get(remoteHost)));
781782
}
782783

@@ -894,7 +895,7 @@ private void setupStorageEnvironment() {
894895
}
895896

896897
private void validateAccess(String remoteHost) throws IOException {
897-
if (isHostNonPermitted(remoteHost)) {
898+
if (isHostNotPermitted(remoteHost)) {
898899
throw new IOException(getString(R.string.PORTAL_DENIED));
899900
}
900901
}
@@ -999,7 +1000,7 @@ protected void execStream(String remoteHost, InputStream inputStream) throws IOE
9991000
if (isHostDenied(remoteHost)) {
10001001
throw new IOException(getString(R.string.PORTAL_DENIED));
10011002
}
1002-
if (isHostNonPermitted(remoteHost)) {
1003+
if (isHostNotPermitted(remoteHost)) {
10031004
requestHostPermission(remoteHost);
10041005
} else {
10051006
MainActivity.this.execStream(inputStream);
@@ -1014,7 +1015,7 @@ protected Response getFile(String remoteHost, String path, boolean asset) throws
10141015
long length = getFileLength(name);
10151016
log("Opened " + name + " " + length + " bytes");
10161017
result = new Response(getAssets().open(name), length);
1017-
if ("index.html".equals(path) && isHostNonPermitted(remoteHost)) {
1018+
if ("index.html".equals(path) && isHostNotPermitted(remoteHost)) {
10181019
requestHostPermission(remoteHost);
10191020
}
10201021
} else {

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -447,19 +447,25 @@ private Response handleFileList() throws IOException {
447447
builder.append('[');
448448
long id = 0;
449449
char comma = 0;
450-
for (FileData nextFile : getFileData(remoteHost)) {
451-
builder.append(comma);
452-
builder.append('{');
453-
builder.append("id", id++, true);
454-
builder.append("fileName", nextFile.fileName, true);
455-
builder.append("size", nextFile.size, true);
456-
builder.append("date", nextFile.date, false);
457-
builder.append('}');
458-
comma = ',';
450+
Response result;
451+
try {
452+
for (FileData nextFile : getFileData(remoteHost)) {
453+
builder.append(comma);
454+
builder.append('{');
455+
builder.append("id", id++, true);
456+
builder.append("fileName", nextFile.fileName, true);
457+
builder.append("size", nextFile.size, true);
458+
builder.append("date", nextFile.date, false);
459+
builder.append('}');
460+
comma = ',';
461+
}
462+
builder.append(']');
463+
byte[] json = builder.getBytes();
464+
result = new Response(new ByteArrayInputStream(json), json.length);
465+
} catch (Exception e) {
466+
result = handleStatus(false, e.getMessage());
459467
}
460-
builder.append(']');
461-
byte[] json = builder.getBytes();
462-
return new Response(new ByteArrayInputStream(json), json.length);
468+
return result;
463469
}
464470

465471
/**
@@ -522,7 +528,7 @@ private Response handleDelete(Map<String, FormField> data) throws IOException {
522528
deleteFile(remoteHost, fileName);
523529
log("Deleted " + fileName);
524530
result = handleFileList();
525-
} catch (IOException e) {
531+
} catch (Exception e) {
526532
result = handleStatus(false, e.getMessage());
527533
}
528534
return result;
@@ -538,7 +544,7 @@ private Response handleRename(Map<String, FormField> data) throws IOException {
538544
try {
539545
renameFile(remoteHost, from, to);
540546
result = handleStatus(true, "File renamed");
541-
} catch (IOException e) {
547+
} catch (Exception e) {
542548
result = handleStatus(false, e.getMessage());
543549
}
544550
return result;

src/platform/android/webui/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"dependencies": {
77
"@emotion/react": "^11.10.5",
88
"@emotion/styled": "^11.10.5",
9-
"@mui/icons-material": "^5.10.9",
10-
"@mui/material": "^5.10.12",
11-
"@mui/x-data-grid": "^5.17.10",
12-
"npm-check-updates": "^16.3.16",
9+
"@mui/icons-material": "^5.10.15",
10+
"@mui/material": "^5.10.15",
11+
"@mui/x-data-grid": "^5.17.12",
12+
"npm-check-updates": "^16.4.3",
1313
"react": "^18.2.0",
1414
"react-dom": "^18.2.0",
1515
"react-scripts": "5.0.1"

src/platform/android/webui/src/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import {
23
Fragment,
34
useState
@@ -173,7 +174,6 @@ function GridToolbarDelete(props) {
173174
props.setSelections([]);
174175
}, (error) => {
175176
setError(error);
176-
setError(true);
177177
});
178178
};
179179

@@ -314,7 +314,7 @@ function FileList(props) {
314314

315315
return (
316316
<Fragment>
317-
<ErrorMessage error={error} setError={setError} />
317+
<ErrorMessage error={error} setError={setError} severity="error"/>
318318
<DataGrid rows={props.rows}
319319
initialState={sorting}
320320
columns={columns}

0 commit comments

Comments
 (0)