Skip to content

Commit 6ea9be6

Browse files
improvements
1 parent b6e8661 commit 6ea9be6

File tree

9 files changed

+203
-98
lines changed

9 files changed

+203
-98
lines changed

package-lock.json

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

src/lib/main.js

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

332330
async function loadApp() {

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.foxdebug.system;
22

3+
4+
import java.nio.file.Files;
5+
import java.nio.file.Paths;
6+
import java.nio.file.StandardOpenOption;
7+
import java.io.IOException;
38
import android.app.Activity;
49
import android.app.PendingIntent;
510
import android.content.ClipData;
@@ -184,6 +189,23 @@ public void run() {
184189
case "listChildren":
185190
callbackContext.success(listChildren(args.getString(0)));
186191
return true;
192+
case "writeText": {
193+
try {
194+
String filePath = args.getString(0);
195+
String content = args.getString(1);
196+
197+
Files.write(Paths.get(filePath),
198+
Collections.singleton(content),
199+
StandardOpenOption.CREATE,
200+
StandardOpenOption.TRUNCATE_EXISTING);
201+
202+
callbackContext.success("File written successfully");
203+
} catch (Exception e) {
204+
callbackContext.error("Failed to write file: " + e.getMessage());
205+
}
206+
return true;
207+
}
208+
187209
case "getArch":
188210
String arch;
189211

src/plugins/system/www/plugin.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ module.exports = {
66
createSymlink: function (target, linkPath, success, error) {
77
cordova.exec(success, error, 'System', 'createSymlink', [target, linkPath]);
88
},
9+
writeText: function (path, content, success, error) {
10+
cordova.exec(success, error, 'System', 'writeText', [path, content]);
11+
},
912

1013
getNativeLibraryPath: function (success, error) {
1114
cordova.exec(success, error, 'System', 'getNativeLibraryPath', []);

src/plugins/terminal/plugin.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
</config-file>
2020
<config-file parent="/*" target="AndroidManifest.xml" />
2121
<source-file src="src/android/Executor.java" target-dir="src/com/foxdebug/acode/rk/exec/terminal" />
22+
23+
24+
<source-file src="scripts/init-sandbox.sh" target-dir="assets"/>
25+
<source-file src="scripts/init-alpine.sh" target-dir="assets"/>
2226

2327
<!-- Use flavors if F-Droid complains about native libs -->
2428

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
set -e # Exit immediately on Failure
2+
3+
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/share/bin:/usr/share/sbin:/usr/local/bin:/usr/local/sbin:/system/bin:/system/xbin:$PREFIX/local/bin
4+
export PS1="\[\e[38;5;46m\]\u\[\033[39m\]@localhost \[\033[39m\]\w \[\033[0m\]\\$ "
5+
export PIP_BREAK_SYSTEM_PACKAGES=1
6+
required_packages="bash"
7+
8+
missing_packages=""
9+
for pkg in $required_packages; do
10+
if ! apk info -e $pkg >/dev/null 2>&1; then
11+
missing_packages="$missing_packages $pkg"
12+
fi
13+
done
14+
if [ -n "$missing_packages" ]; then
15+
echo -e "\e[34;1m[*] \e[0mInstalling Important packages\e[0m"
16+
apk update && apk upgrade
17+
apk add $missing_packages
18+
if [ $? -eq 0 ]; then
19+
echo -e "\e[32;1m[+] \e[0mSuccessfully Installed\e[0m"
20+
fi
21+
echo -e "\e[34m[*] \e[0mUse \e[32mapk\e[0m to install new packages\e[0m"
22+
fi
23+
24+
25+
if [[ ! -f /linkerconfig/ld.config.txt ]];then
26+
mkdir -p /linkerconfig
27+
touch /linkerconfig/ld.config.txt
28+
fi
29+
30+
[ ! -L /bin/login ] && mv /bin/login /bin/real_login
31+
ln -sf /bin/bash /bin/login
32+
33+
if [ "$#" -eq 0 ]; then
34+
$PREFIX/axs
35+
else
36+
exec "$@"
37+
fi
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export LD_LIBRARY_PATH=$PREFIX
2+
export PROOT_TMP_DIR=$PREFIX/tmp
3+
export PROOT_LOADER=$NATIVE_DIR/libproot.so
4+
export PROOT_LOADER32=$NATIVE_DIR/libproot32.so
5+
6+
mkdir -p "$PREFIX/tmp"
7+
8+
if [ -e "$PREFIX/libtalloc.so.2" ] || [ -L "$PREFIX/libtalloc.so.2" ]; then
9+
rm "$PREFIX/libtalloc.so.2"
10+
fi
11+
12+
ln -s "$NATIVE_DIR/libtalloc.so" "$PREFIX/libtalloc.so.2"
13+
14+
15+
$NATIVE_DIR/libproot-xed.so -b $PREFIX:$PREFIX -b /data:/data -b /system:/system -b /vendor:/vendor -R $PREFIX/alpine sh $PREFIX/init-alpine.sh "$@"

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,28 @@
66
import java.io.*;
77
import java.util.*;
88
import java.util.concurrent.*;
9+
import android.content.Context;
10+
import android.app.Activity;
911

1012
public class Executor extends CordovaPlugin {
1113

1214
private final Map<String, Process> processes = new ConcurrentHashMap<>();
1315
private final Map<String, OutputStream> processInputs = new ConcurrentHashMap<>();
1416
private final Map<String, CallbackContext> processCallbacks = new ConcurrentHashMap<>();
1517

18+
private Context context;
19+
20+
21+
@Override
22+
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
23+
super.initialize(cordova, webView);
24+
this.context = cordova.getContext();
25+
26+
}
27+
28+
29+
30+
1631
@Override
1732
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
1833
switch (action) {
@@ -35,8 +50,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
3550
exec(cmdExec, callbackContext);
3651
return true;
3752
case "isRunning":
38-
String pid = args.getString(0);
39-
isProcessRunning(pid, callbackContext);
53+
isProcessRunning(args.getString(0), callbackContext);
4054
return true;
4155
default:
4256
callbackContext.error("Unknown action: " + action);
@@ -47,7 +61,14 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
4761
private void exec(String cmd, CallbackContext callbackContext) {
4862
try {
4963
if (cmd != null && !cmd.isEmpty()) {
50-
Process process = Runtime.getRuntime().exec(cmd);
64+
ProcessBuilder builder = new ProcessBuilder("sh", "-c", cmd);
65+
66+
// Set environment variables
67+
Map<String, String> env = builder.environment();
68+
env.put("PREFIX", context.getFilesDir().getAbsolutePath());
69+
env.put("NATIVE_DIR", context.getApplicationInfo().nativeLibraryDir);
70+
71+
Process process = builder.start();
5172

5273
// Capture stdout
5374
BufferedReader stdOutReader = new BufferedReader(
@@ -88,7 +109,15 @@ private void exec(String cmd, CallbackContext callbackContext) {
88109
private void startProcess(String pid, String cmd, CallbackContext callbackContext) {
89110
cordova.getThreadPool().execute(() -> {
90111
try {
91-
Process process = Runtime.getRuntime().exec(cmd);
112+
ProcessBuilder builder = new ProcessBuilder("sh", "-c", cmd);
113+
114+
// Set environment variables
115+
Map<String, String> env = builder.environment();
116+
env.put("PREFIX", context.getFilesDir().getAbsolutePath());
117+
env.put("NATIVE_DIR", context.getApplicationInfo().nativeLibraryDir);
118+
119+
Process process = builder.start();
120+
92121
processes.put(pid, process);
93122
processInputs.put(pid, process.getOutputStream());
94123
processCallbacks.put(pid, callbackContext);

0 commit comments

Comments
 (0)