Skip to content

Commit 406f7ea

Browse files
first working implementation
1 parent 0398225 commit 406f7ea

File tree

9 files changed

+327
-43
lines changed

9 files changed

+327
-43
lines changed

package-lock.json

Lines changed: 65 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@
3131
"cordova-plugin-sdcard": {},
3232
"cordova-plugin-browser": {},
3333
"cordova-plugin-iap": {},
34-
"cordova-plugin-advanced-http": {
35-
"ANDROIDBLACKLISTSECURESOCKETPROTOCOLS": "SSLv3,TLSv1"
36-
},
34+
"cordova-plugin-advanced-http": {},
3735
"cordova-plugin-websocket": {},
38-
"com.foxdebug.acode.rk.exec.terminal": {},
3936
"cordova-plugin-buildinfo": {},
40-
"cordova-plugin-system": {}
37+
"cordova-plugin-system": {},
38+
"com.foxdebug.acode.rk.exec.terminal": {}
4139
},
4240
"platforms": [
4341
"android"
@@ -64,7 +62,7 @@
6462
"autoprefixer": "^10.4.19",
6563
"babel-loader": "^9.1.3",
6664
"com.foxdebug.acode.rk.exec.terminal": "file:src/plugins/terminal",
67-
"cordova-android": "^13.0.0",
65+
"cordova-android": "^14.0.1",
6866
"cordova-clipboard": "^1.3.0",
6967
"cordova-plugin-advanced-http": "^3.3.1",
7068
"cordova-plugin-browser": "file:src/plugins/browser",
@@ -88,6 +86,7 @@
8886
"sass": "^1.77.2",
8987
"sass-loader": "^14.2.1",
9088
"style-loader": "^4.0.0",
89+
"terminal": "^0.1.4",
9190
"webpack": "^5.94.0",
9291
"webpack-cli": "^5.1.4"
9392
},

src/lib/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ async function onDeviceReady() {
325325
);
326326
})
327327
.catch(console.error);
328+
329+
Terminal.initSandbox();
328330
}
329331

330332
async function loadApp() {

src/plugins/system/android/com/foxdebug/system/System.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
import org.json.JSONArray;
4848
import org.json.JSONException;
4949
import org.json.JSONObject;
50+
import java.nio.file.Files;
51+
import java.nio.file.LinkOption;
52+
import java.nio.file.Path;
53+
5054

5155
public class System extends CordovaPlugin {
5256

@@ -157,7 +161,7 @@ public void run() {
157161
);
158162
return true;
159163
case "fileExists":
160-
callbackContext.success(fileExists(args.getString(0)) ? 1 : 0);
164+
callbackContext.success(fileExists(args.getString(0),args.getString(1)) ? 1 : 0);
161165
return true;
162166

163167
case "createSymlink":
@@ -180,6 +184,25 @@ public void run() {
180184
case "listChildren":
181185
callbackContext.success(listChildren(args.getString(0)));
182186
return true;
187+
case "getArch":
188+
String arch;
189+
190+
if (android.os.Build.VERSION.SDK_INT >= 21) {
191+
arch = android.os.Build.SUPPORTED_ABIS[0];
192+
} else {
193+
arch = android.os.Build.CPU_ABI;
194+
}
195+
196+
callbackContext.success(arch);
197+
return true;
198+
case "mkdirs":
199+
File file = new File(args.getString(0));
200+
if(file.mkdirs()){
201+
callbackContext.success();
202+
}else{
203+
callbackContext.error("mkdirs failed");
204+
}
205+
return true;
183206
default:
184207
return false;
185208
}
@@ -423,9 +446,20 @@ private void hasPermission(String permission, CallbackContext callback) {
423446
callback.error("No permission passed to check.");
424447
}
425448

426-
public boolean fileExists(String path) {
427-
return new File(path).exists();
449+
public boolean fileExists(String path, String countSymlinks) {
450+
Path p = new File(path).toPath();
451+
try {
452+
if (Boolean.parseBoolean(countSymlinks)) {
453+
// This will return true even for broken symlinks
454+
return Files.exists(p, LinkOption.NOFOLLOW_LINKS);
455+
} else {
456+
// Check target file, not symlink itself
457+
return Files.exists(p) && !Files.isSymbolicLink(p);
458+
}
459+
} catch (Exception e) {
460+
return false;
428461
}
462+
}
429463

430464
public boolean createSymlink(String target, String linkPath) {
431465
try {

src/plugins/system/www/plugin.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
2-
fileExists: function (path, success, error) {
3-
cordova.exec(success, error, 'System', 'fileExists', [path]);
2+
fileExists: function (path,countSymlinks, success, error) {
3+
cordova.exec(success, error, 'System', 'fileExists', [path,String(countSymlinks)]);
44
},
55

66
createSymlink: function (target, linkPath, success, error) {
@@ -22,6 +22,13 @@ module.exports = {
2222
listChildren: function (path, success, error) {
2323
cordova.exec(success, error, 'System', 'listChildren', [path]);
2424
},
25+
mkdirs: function (path, success, error) {
26+
cordova.exec(success, error, 'System', 'mkdirs', [path]);
27+
},
28+
getArch: function (success, error) {
29+
cordova.exec(success, error, 'System', 'getArch', []);
30+
},
31+
2532
clearCache: function (success, fail) {
2633
return cordova.exec(success, fail, "System", "clearCache", []);
2734
},

src/plugins/terminal/plugin.xml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,32 @@
1414
<platform name="android">
1515
<config-file parent="/*" target="res/xml/config.xml">
1616
<feature name="Executor">
17-
<param name="android-package" value="com.foxdebug.acode.rk.exec.terminal" />
18-
</feature>
19-
<feature name="Terminal">
20-
<param name="android-package" value="com.foxdebug.acode.rk.exec.terminal" />
17+
<param name="android-package" value="com.foxdebug.acode.rk.exec.terminal.Executor" />
2118
</feature>
2219
</config-file>
2320
<config-file parent="/*" target="AndroidManifest.xml" />
2421
<source-file src="src/android/Executor.java" target-dir="src/com/foxdebug/acode/rk/exec/terminal" />
2522

2623
<!-- Use flavors if F-Droid complains about native libs -->
24+
25+
<!-- x86_64 / x64 only (32bit is not supported) -->
2726
<source-file src="libs/x64/libproot.so" target-dir="libs/x86_64" />
2827
<source-file src="libs/x64/libproot32.so" target-dir="libs/x86_64" />
2928
<source-file src="libs/x64/libproot-xed.so" target-dir="libs/x86_64" />
3029
<source-file src="libs/x64/libtalloc.so" target-dir="libs/x86_64" />
3130

31+
<!-- arm64 / arm-v8a -->
3232
<source-file src="libs/arm64/libproot.so" target-dir="libs/arm64-v8a" />
3333
<source-file src="libs/arm64/libproot32.so" target-dir="libs/arm64-v8a" />
3434
<source-file src="libs/arm64/libproot-xed.so" target-dir="libs/arm64-v8a" />
3535
<source-file src="libs/arm64/libtalloc.so" target-dir="libs/arm64-v8a" />
3636

37+
38+
<!-- armhf / armeabi-v7a (armeabi / armeabi-v6a not supported)-->
3739
<source-file src="libs/arm32/libproot.so" target-dir="libs/armeabi-v7a" />
3840
<source-file src="libs/arm32/libproot-xed.so" target-dir="libs/armeabi-v7a" />
3941
<source-file src="libs/arm32/libtalloc.so" target-dir="libs/armeabi-v7a" />
40-
42+
43+
4144
</platform>
4245
</plugin>

src/plugins/terminal/src/android/Executor.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
3434
String cmdExec = args.getString(0);
3535
exec(cmdExec, callbackContext);
3636
return true;
37+
case "isRunning":
38+
String pid = args.getString(0);
39+
isProcessRunning(pid, callbackContext);
40+
return true;
3741
default:
3842
callbackContext.error("Unknown action: " + action);
3943
return false;
@@ -133,6 +137,22 @@ private void stopProcess(String pid, CallbackContext callbackContext) {
133137
}
134138
}
135139

140+
private void isProcessRunning(String pid, CallbackContext callbackContext) {
141+
Process process = processes.get(pid);
142+
143+
if (process != null) {
144+
if (process.isAlive()) {
145+
callbackContext.success("running");
146+
} else {
147+
cleanup(pid);
148+
callbackContext.success("exited");
149+
}
150+
} else {
151+
callbackContext.success("not_found");
152+
}
153+
}
154+
155+
136156
private void streamOutput(InputStream inputStream, String pid, String streamType) {
137157
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
138158
String line;

src/plugins/terminal/www/Executor.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const Executor = {
2828
* Executor.stop(pid);
2929
* });
3030
*/
31-
start(command, onData,alpine = false) {
31+
start(command, onData) {
3232
return new Promise((resolve, reject) => {
3333
exec(
3434
(message) => {
@@ -76,6 +76,19 @@ const Executor = {
7676
exec(resolve, reject, "Executor", "stop", [pid]);
7777
});
7878
},
79+
isRunning(pid) {
80+
return new Promise((resolve, reject) => {
81+
exec((result)=>{
82+
if(result === "running"){
83+
resolve(true)
84+
}else if(result === "exited"){
85+
resolve(false)
86+
}else{
87+
resolve(false)
88+
}
89+
}, reject, "Executor", "isRunning", [pid]);
90+
});
91+
},
7992

8093
/**
8194
* Executes a shell command and waits for it to finish.
@@ -91,7 +104,7 @@ const Executor = {
91104
* console.error(error);
92105
* });
93106
*/
94-
execute(command,alpine = false) {
107+
execute(command) {
95108
return new Promise((resolve, reject) => {
96109
exec(resolve, reject, "Executor", "exec", [command]);
97110
});

0 commit comments

Comments
 (0)