Benjamin-Loison / termux-api

Termux add-on app which exposes device functionality as API to command line programs.
https://f-droid.org/en/packages/com.termux.api/
0 stars 0 forks source link

First `termux-notification` `--button1-action` overwrites following `termux-notification` `--button1-action` #23

Open Benjamin-Loison opened 2 months ago

Benjamin-Loison commented 2 months ago

See Benjamin_Loison/Food/issues/43.

pkg install -y termux-api

+5

Problem description

Steps to reproduce

Expected behavior

Additional information

Benjamin-Loison commented 1 month ago

Nothing seems clearly wrong, it might be subtle.

Benjamin-Loison commented 1 month ago

Could experimentally check that app/src/main/java/com/termux/api/apis/JobSchedulerAPI.java is not involved in the issue.

Benjamin-Loison commented 1 month ago
git reset --hard 3bea194249586a7dcb143e66b46c1694cb6ca21a

results in having the issue but

git checkout HEAD~ app/src/main/java/com/termux/api/apis/NotificationAPI.java

and adding back import java.util.Arrays; solves the issue.

So the issue seems app/src/main/java/com/termux/api/apis/NotificationAPI.java specific.

Benjamin-Loison commented 1 month ago

https://github.com/termux/termux-app/blob/8c1749ef9699e2953c7ca12a976c2fb70a6107e5/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java#L574-L590

Benjamin-Loison commented 1 month ago

Only last hunk of app/src/main/java/com/termux/api/apis/NotificationAPI.java seems to blame.

Benjamin-Loison commented 1 month ago

new String[]{"-c", action} is used in both.

Benjamin-Loison commented 1 month ago

Let us compare:

Intent executeIntent = new Intent(ACTION_EXECUTE, executeUri);

and

Intent executionIntent = new Intent(TERMUX_SERVICE.ACTION_SERVICE_EXECUTE, executionCommand.executableUri);
private static final String ACTION_EXECUTE = "com.termux.service_execute";

https://github.com/termux/termux-app/blob/8c1749ef9699e2953c7ca12a976c2fb70a6107e5/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java#L993-L994

So about the first argument, both are identical.

Benjamin-Loison commented 1 month ago
private static final String EXTRA_EXECUTE_IN_BACKGROUND = "com.termux.execute.background";

https://github.com/termux/termux-app/blob/8c1749ef9699e2953c7ca12a976c2fb70a6107e5/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java#L1004-L1006

so both are identical.

Benjamin-Loison commented 1 month ago

https://github.com/termux/termux-app/blob/8c1749ef9699e2953c7ca12a976c2fb70a6107e5/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java#L347-L348

        private static final String TERMUX_SERVICE = "com.termux.app.TermuxService";

https://github.com/termux/termux-app/blob/8c1749ef9699e2953c7ca12a976c2fb70a6107e5/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java#L973-L974

so both are identical.

Benjamin-Loison commented 1 month ago

So what is unclearly different:

executionIntent.putExtra(TERMUX_SERVICE.EXTRA_RUNNER, executionCommand.runner);

executionIntent second constructor argument.

Uri scriptUri = new Uri.Builder().scheme("com.termux.file").path(filePath).build();
Intent executeIntent = new Intent(ACTION_EXECUTE, scriptUri);
ExecutionCommand executionCommand = new ExecutionCommand();
executionCommand.executableUri = new Uri.Builder().scheme(TERMUX_SERVICE.URI_SCHEME_SERVICE_EXECUTE).path(filePath).build();
executionCommand.runner = ExecutionCommand.Runner.APP_SHELL.getName();
Benjamin-Loison commented 1 month ago

https://github.com/termux/termux-app/blob/8c1749ef9699e2953c7ca12a976c2fb70a6107e5/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java#L996-L997

So both Uri are identical.

Benjamin-Loison commented 1 month ago

In fact I was focusing by mistake on JobSchedulerAPI.java.

.appendQueryParameter("arguments", Arrays.toString(arguments))

Except runner only the above seems to differ.

Benjamin-Loison commented 1 month ago

https://github.com/termux/termux-app/blob/8c1749ef9699e2953c7ca12a976c2fb70a6107e5/termux-shared/src/main/java/com/termux/shared/shell/command/ExecutionCommand.java

git diff app/src/main/java/com/termux/api/apis/NotificationAPI.java
Output: ```diff diff --git a/app/src/main/java/com/termux/api/apis/NotificationAPI.java b/app/src/main/java/com/termux/api/apis/NotificationAPI.java index fedcd6f..6b3d54f 100644 --- a/app/src/main/java/com/termux/api/apis/NotificationAPI.java +++ b/app/src/main/java/com/termux/api/apis/NotificationAPI.java @@ -31,6 +31,7 @@ import com.termux.shared.termux.TermuxConstants.TERMUX_APP.TERMUX_SERVICE; import java.io.File; import java.io.PrintWriter; import java.lang.reflect.Field; +import java.util.Arrays; import java.util.Objects; import java.util.UUID; @@ -409,8 +410,8 @@ public class NotificationAPI { static Intent createExecuteIntent(String action){ ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.executableUri = new Uri.Builder().scheme(TERMUX_SERVICE.URI_SCHEME_SERVICE_EXECUTE).path(BIN_SH).build(); executionCommand.arguments = new String[]{"-c", action}; + executionCommand.executableUri = new Uri.Builder().scheme(TERMUX_SERVICE.URI_SCHEME_SERVICE_EXECUTE).path(BIN_SH).appendQueryParameter("arguments", Arrays.toString(executionCommand.arguments)).build(); executionCommand.runner = ExecutionCommand.Runner.APP_SHELL.getName(); // Create execution intent with the action TERMUX_SERVICE#ACTION_SERVICE_EXECUTE to be sent to the TERMUX_SERVICE ```

seems to solve the regression.

Let us try it on the latest commit.

Benjamin-Loison commented 1 month ago
git diff
Output: ```diff diff --git a/app/src/main/java/com/termux/api/apis/NotificationAPI.java b/app/src/main/java/com/termux/api/apis/NotificationAPI.java index caee093..59724ff 100644 --- a/app/src/main/java/com/termux/api/apis/NotificationAPI.java +++ b/app/src/main/java/com/termux/api/apis/NotificationAPI.java @@ -31,6 +31,7 @@ import com.termux.shared.termux.TermuxConstants.TERMUX_APP.TERMUX_SERVICE; import java.io.File; import java.io.PrintWriter; import java.lang.reflect.Field; +import java.util.Arrays; import java.util.Objects; import java.util.UUID; @@ -406,8 +407,8 @@ public class NotificationAPI { static Intent createExecuteIntent(String action){ ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.executableUri = new Uri.Builder().scheme(TERMUX_SERVICE.URI_SCHEME_SERVICE_EXECUTE).path(BIN_SH).build(); executionCommand.arguments = new String[]{"-c", action}; + executionCommand.executableUri = new Uri.Builder().scheme(TERMUX_SERVICE.URI_SCHEME_SERVICE_EXECUTE).path(BIN_SH).appendQueryParameter("arguments", Arrays.toString(executionCommand.arguments)).build(); executionCommand.runner = ExecutionCommand.Runner.APP_SHELL.getName(); // Create execution intent with the action TERMUX_SERVICE#ACTION_SERVICE_EXECUTE to be sent to the TERMUX_SERVICE ```

solves the issue on the last commit it seems:

git log | head -n 5
Output: ``` commit c553bc2ba7de37ad5c42df23d71e699d2785d7c5 Author: agnostic-apollo Date: Tue Jul 30 07:57:29 2024 +0500 Added: Add latest version name info to README.md ```
Benjamin-Loison commented 1 month ago

Have the same issue with button2? At least not with my patch.

GokerAnonymous commented 1 month ago

ترمكس

GokerAnonymous commented 1 month ago

اوامر اختراق wi fi

Benjamin-Loison commented 1 month ago

@GokerAnonymous Write in English.

Benjamin-Loison commented 3 weeks ago

termux-app termux-app/actions/runs/11146787425/job/30979551872

image

image

image

shows how ridiculous it is to distinguish connected from not connected users even if they do not have permissions.