MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / execute

Method execute

src/plugins/terminal/src/android/Executor.java:234–366  ·  view source on GitHub ↗
(String action, JSONArray args, CallbackContext callbackContext)

Source from the content-addressed store, hash-verified

232 }
233
234 @Override
235 public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
236 // For actions that don't need the service, handle them directly
237 if (action.equals("loadLibrary")) {
238 callbackContext.error("This feature is no longer supported. Loading native libraries directly from JavaScript is no longer allowed due to security reasons.");
239 /*
240 try {
241 System.load(args.getString(0));
242 callbackContext.success("Library loaded successfully.");
243 } catch (Exception e) {
244 callbackContext.error("Failed to load library: " + e.getMessage());
245 }
246 */
247 return true;
248 }
249
250 if (action.equals("stopService")) {
251 stopServiceNow();
252 callbackContext.success("Service stopped");
253 return true;
254 }
255
256 if (action.equals("moveToBackground")) {
257 Intent intent = new Intent(context, TerminalService.class);
258 intent.setAction(TerminalService.MOVE_TO_BACKGROUND);
259 context.startService(intent);
260 callbackContext.success("Service moved to background mode");
261 return true;
262 }
263
264 if (action.equals("moveToForeground")) {
265 Intent intent = new Intent(context, TerminalService.class);
266 intent.setAction(TerminalService.MOVE_TO_FOREGROUND);
267 context.startService(intent);
268 callbackContext.success("Service moved to foreground mode");
269 return true;
270 }
271
272 if (action.equals("spawn")) {
273 try {
274 JSONArray cmdArr = args.getJSONArray(0);
275 String[] cmd = new String[cmdArr.length()];
276 for (int i = 0; i < cmdArr.length(); i++) {
277 cmd[i] = cmdArr.getString(i);
278 }
279
280 int port;
281 try (ServerSocket socket = new ServerSocket(0)) {
282 port = socket.getLocalPort();
283 }
284
285 ProcessServer server = new ProcessServer(port, cmd);
286 server.startAndAwait(); // blocks until onStart() fires — server is listening before port is returned
287
288 callbackContext.success(port);
289 } catch (Exception e) {
290 e.printStackTrace();
291 callbackContext.error("Failed to spawn process: " + e.getMessage());

Callers 2

startProcessMethod · 0.45
execMethod · 0.45

Calls 15

stopServiceNowMethod · 0.95
startAndAwaitMethod · 0.95
getAllProcessesMethod · 0.95
killProcessMethod · 0.95
ensureServiceBoundMethod · 0.95
startProcessMethod · 0.95
writeToProcessMethod · 0.95
stopProcessMethod · 0.95
execMethod · 0.95
isProcessRunningMethod · 0.95
listProcessesMethod · 0.95
successMethod · 0.80

Tested by

no test coverage detected