diff --git a/app/src/main/java/com/termux/app/RunCommandService.java b/app/src/main/java/com/termux/app/RunCommandService.java
index 26172915..635f2810 100644
--- a/app/src/main/java/com/termux/app/RunCommandService.java
+++ b/app/src/main/java/com/termux/app/RunCommandService.java
@@ -116,8 +116,8 @@ public class RunCommandService extends Service {
executionCommand.backgroundCustomLogLevel = IntentUtils.getIntegerExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL, null);
executionCommand.sessionAction = intent.getStringExtra(RUN_COMMAND_SERVICE.EXTRA_SESSION_ACTION);
- executionCommand.sessionName = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_SESSION_NAME, null);
- executionCommand.sessionCreateMode = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_SESSION_CREATE_MODE, null);
+ executionCommand.shellName = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_SHELL_NAME, null);
+ executionCommand.shellCreateMode = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_SHELL_CREATE_MODE, null);
executionCommand.commandLabel = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_COMMAND_LABEL, "RUN_COMMAND Execution Intent Command");
executionCommand.commandDescription = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_COMMAND_DESCRIPTION, null);
executionCommand.commandHelp = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_COMMAND_HELP, null);
@@ -213,8 +213,8 @@ public class RunCommandService extends Service {
execIntent.putExtra(TERMUX_SERVICE.EXTRA_RUNNER, executionCommand.runner);
execIntent.putExtra(TERMUX_SERVICE.EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL, DataUtils.getStringFromInteger(executionCommand.backgroundCustomLogLevel, null));
execIntent.putExtra(TERMUX_SERVICE.EXTRA_SESSION_ACTION, executionCommand.sessionAction);
- execIntent.putExtra(TERMUX_SERVICE.EXTRA_SESSION_NAME, executionCommand.sessionName);
- execIntent.putExtra(TERMUX_SERVICE.EXTRA_SESSION_CREATE_MODE, executionCommand.sessionCreateMode);
+ execIntent.putExtra(TERMUX_SERVICE.EXTRA_SHELL_NAME, executionCommand.shellName);
+ execIntent.putExtra(TERMUX_SERVICE.EXTRA_SHELL_CREATE_MODE, executionCommand.shellCreateMode);
execIntent.putExtra(TERMUX_SERVICE.EXTRA_COMMAND_LABEL, executionCommand.commandLabel);
execIntent.putExtra(TERMUX_SERVICE.EXTRA_COMMAND_DESCRIPTION, executionCommand.commandDescription);
execIntent.putExtra(TERMUX_SERVICE.EXTRA_COMMAND_HELP, executionCommand.commandHelp);
diff --git a/app/src/main/java/com/termux/app/TermuxService.java b/app/src/main/java/com/termux/app/TermuxService.java
index 59005c0a..7f10c6c8 100644
--- a/app/src/main/java/com/termux/app/TermuxService.java
+++ b/app/src/main/java/com/termux/app/TermuxService.java
@@ -16,6 +16,7 @@ import android.os.IBinder;
import android.os.PowerManager;
import android.widget.ArrayAdapter;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.termux.R;
@@ -41,7 +42,7 @@ import com.termux.shared.android.PermissionUtils;
import com.termux.shared.data.DataUtils;
import com.termux.shared.shell.command.ExecutionCommand;
import com.termux.shared.shell.command.ExecutionCommand.Runner;
-import com.termux.shared.shell.command.ExecutionCommand.SessionCreateMode;
+import com.termux.shared.shell.command.ExecutionCommand.ShellCreateMode;
import com.termux.terminal.TerminalEmulator;
import com.termux.terminal.TerminalSession;
import com.termux.terminal.TerminalSessionClient;
@@ -385,8 +386,8 @@ public final class TermuxService extends Service implements AppShell.AppShellCli
executionCommand.workingDirectory = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_WORKDIR, null);
executionCommand.isFailsafe = intent.getBooleanExtra(TERMUX_ACTIVITY.EXTRA_FAILSAFE_SESSION, false);
executionCommand.sessionAction = intent.getStringExtra(TERMUX_SERVICE.EXTRA_SESSION_ACTION);
- executionCommand.sessionName = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_SESSION_NAME, null);
- executionCommand.sessionCreateMode = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_SESSION_CREATE_MODE, null);
+ executionCommand.shellName = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_SHELL_NAME, null);
+ executionCommand.shellCreateMode = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_SHELL_CREATE_MODE, null);
executionCommand.commandLabel = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_COMMAND_LABEL, "Execution Intent Command");
executionCommand.commandDescription = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_COMMAND_DESCRIPTION, null);
executionCommand.commandHelp = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_COMMAND_HELP, null);
@@ -401,6 +402,9 @@ public final class TermuxService extends Service implements AppShell.AppShellCli
executionCommand.resultConfig.resultFilesSuffix = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_RESULT_FILES_SUFFIX, null);
}
+ if (executionCommand.shellCreateMode == null)
+ executionCommand.shellCreateMode = ShellCreateMode.ALWAYS.getMode();
+
// Add the execution command to pending plugin execution commands list
mPendingPluginExecutionCommands.add(executionCommand);
@@ -425,7 +429,23 @@ public final class TermuxService extends Service implements AppShell.AppShellCli
Logger.logDebug(LOG_TAG, "Executing background \"" + executionCommand.getCommandIdAndLabelLogString() + "\" TermuxTask command");
- AppShell newTermuxTask = createTermuxTask(executionCommand);
+ // Transform executable path to shell/session name, e.g. "/bin/do-something.sh" => "do-something.sh".
+ if (executionCommand.shellName == null && executionCommand.executable != null)
+ executionCommand.shellName = ShellUtils.getExecutableBasename(executionCommand.executable);
+
+ AppShell newTermuxTask = null;
+ ShellCreateMode shellCreateMode = processShellCreateMode(executionCommand);
+ if (shellCreateMode == null) return;
+ if (ShellCreateMode.NO_SHELL_WITH_NAME.equals(shellCreateMode)) {
+ newTermuxTask = getTermuxTaskForShellName(executionCommand.shellName);
+ if (newTermuxTask != null)
+ Logger.logVerbose(LOG_TAG, "Existing TermuxTask with \"" + executionCommand.shellName + "\" shell name found for shell create mode \"" + shellCreateMode.getMode() + "\"");
+ else
+ Logger.logVerbose(LOG_TAG, "No existing TermuxTask with \"" + executionCommand.shellName + "\" shell name found for shell create mode \"" + shellCreateMode.getMode() + "\"");
+ }
+
+ if (newTermuxTask == null)
+ newTermuxTask = createTermuxTask(executionCommand);
}
/** Create a TermuxTask. */
@@ -502,35 +522,21 @@ public final class TermuxService extends Service implements AppShell.AppShellCli
private void executeTermuxSessionCommand(ExecutionCommand executionCommand) {
if (executionCommand == null) return;
- if (executionCommand.sessionCreateMode == null)
- executionCommand.sessionCreateMode = SessionCreateMode.ALWAYS.getMode();
-
Logger.logDebug(LOG_TAG, "Executing foreground \"" + executionCommand.getCommandIdAndLabelLogString() + "\" TermuxSession command");
- // Transform executable path to session name, e.g. "/bin/do-something.sh" => "do-something.sh".
- if (executionCommand.sessionName == null && executionCommand.executable != null) {
- executionCommand.sessionName = ShellUtils.getExecutableBasename(executionCommand.executable);
- }
+ // Transform executable path to shell/session name, e.g. "/bin/do-something.sh" => "do-something.sh".
+ if (executionCommand.shellName == null && executionCommand.executable != null)
+ executionCommand.shellName = ShellUtils.getExecutableBasename(executionCommand.executable);
TermuxSession newTermuxSession = null;
- if (SessionCreateMode.ALWAYS.equalsMode(executionCommand.sessionCreateMode))
- ; // Default
- else if (SessionCreateMode.NO_SESSION_WITH_NAME.equalsMode(executionCommand.sessionCreateMode))
- if (DataUtils.isNullOrEmpty(executionCommand.sessionName)) {
- String errmsg = getString(R.string.error_termux_service_execution_command_session_name_unset, executionCommand.sessionCreateMode);
- executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg);
- TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
- return;
- } else {
- newTermuxSession = getTermuxSessionForName(executionCommand.sessionName);
- if (newTermuxSession != null)
- Logger.logInfo(LOG_TAG, "Existing session with \"" + executionCommand.sessionName + "\" session name found");
- }
- else {
- String errmsg = getString(R.string.error_termux_service_unsupported_execution_command_session_create_mode, executionCommand.sessionCreateMode);
- executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg);
- TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
- return;
+ ShellCreateMode shellCreateMode = processShellCreateMode(executionCommand);
+ if (shellCreateMode == null) return;
+ if (ShellCreateMode.NO_SHELL_WITH_NAME.equals(shellCreateMode)) {
+ newTermuxSession = getTermuxSessionForShellName(executionCommand.shellName);
+ if (newTermuxSession != null)
+ Logger.logVerbose(LOG_TAG, "Existing TermuxSession with \"" + executionCommand.shellName + "\" shell name found for shell create mode \"" + shellCreateMode.getMode() + "\"");
+ else
+ Logger.logVerbose(LOG_TAG, "No existing TermuxSession with \"" + executionCommand.shellName + "\" shell name found for shell create mode \"" + shellCreateMode.getMode() + "\"");
}
if (newTermuxSession == null)
@@ -549,7 +555,7 @@ public final class TermuxService extends Service implements AppShell.AppShellCli
@Nullable
public TermuxSession createTermuxSession(String executablePath, String[] arguments, String stdin, String workingDirectory, boolean isFailSafe, String sessionName) {
ExecutionCommand executionCommand = new ExecutionCommand(getNextExecutionId(), executablePath, arguments, stdin, workingDirectory, Runner.TERMINAL_SESSION.getName(), isFailSafe);
- executionCommand.sessionName = sessionName;
+ executionCommand.shellName = sessionName;
return createTermuxSession(executionCommand);
}
@@ -642,6 +648,24 @@ public final class TermuxService extends Service implements AppShell.AppShellCli
+ private ShellCreateMode processShellCreateMode(@NonNull ExecutionCommand executionCommand) {
+ if (ShellCreateMode.ALWAYS.equalsMode(executionCommand.shellCreateMode))
+ return ShellCreateMode.ALWAYS; // Default
+ else if (ShellCreateMode.NO_SHELL_WITH_NAME.equalsMode(executionCommand.shellCreateMode))
+ if (DataUtils.isNullOrEmpty(executionCommand.shellName)) {
+ TermuxPluginUtils.setAndProcessPluginExecutionCommandError(this, LOG_TAG, executionCommand, false,
+ getString(R.string.error_termux_service_execution_command_shell_name_unset, executionCommand.shellCreateMode));
+ return null;
+ } else {
+ return ShellCreateMode.NO_SHELL_WITH_NAME;
+ }
+ else {
+ TermuxPluginUtils.setAndProcessPluginExecutionCommandError(this, LOG_TAG, executionCommand, false,
+ getString(R.string.error_termux_service_unsupported_execution_command_shell_create_mode, executionCommand.shellCreateMode));
+ return null;
+ }
+ }
+
/** Process session action for new session. */
private void handleSessionAction(int sessionAction, TerminalSession newTerminalSession) {
Logger.logDebug(LOG_TAG, "Processing sessionAction \"" + sessionAction + "\" for session \"" + newTerminalSession.mSessionName + "\"");
@@ -888,13 +912,25 @@ public final class TermuxService extends Service implements AppShell.AppShellCli
return null;
}
- public synchronized TermuxSession getTermuxSessionForName(String name) {
+ public synchronized AppShell getTermuxTaskForShellName(String name) {
+ if (DataUtils.isNullOrEmpty(name)) return null;
+ AppShell appShell;
+ for (int i = 0, len = mTermuxTasks.size(); i < len; i++) {
+ appShell = mTermuxTasks.get(i);
+ String shellName = appShell.getExecutionCommand().shellName;
+ if (shellName != null && shellName.equals(name))
+ return appShell;
+ }
+ return null;
+ }
+
+ public synchronized TermuxSession getTermuxSessionForShellName(String name) {
if (DataUtils.isNullOrEmpty(name)) return null;
TermuxSession termuxSession;
for (int i = 0, len = mTermuxSessions.size(); i < len; i++) {
termuxSession = mTermuxSessions.get(i);
- TerminalSession terminalSession = termuxSession.getTerminalSession();
- if (terminalSession.mSessionName != null && terminalSession.mSessionName.equals(name))
+ String shellName = termuxSession.getExecutionCommand().shellName;
+ if (shellName != null && shellName.equals(name))
return termuxSession;
}
return null;
diff --git a/app/src/main/java/com/termux/app/terminal/TermuxTerminalSessionClient.java b/app/src/main/java/com/termux/app/terminal/TermuxTerminalSessionClient.java
index 070872d7..1054d91f 100644
--- a/app/src/main/java/com/termux/app/terminal/TermuxTerminalSessionClient.java
+++ b/app/src/main/java/com/termux/app/terminal/TermuxTerminalSessionClient.java
@@ -357,7 +357,7 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
if (service != null) {
TermuxSession termuxSession = service.getTermuxSessionForTerminalSession(sessionToRename);
if (termuxSession != null)
- termuxSession.getExecutionCommand().sessionName = text;
+ termuxSession.getExecutionCommand().shellName = text;
}
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e7e0da60..ca4c83a5 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -104,8 +104,8 @@
Grants it from Settings -> Apps -> &TERMUX_APP_NAME; -> Advanced
Invalid execution command runner to TermuxService: `%1$s`
Unsupported execution command runner to TermuxService: `%1$s`
- Unsupported execution command session create mode to TermuxService: `%1$s`
- Session name not set but `%1$s` session create mode passed
+ Unsupported execution command shell create mode to TermuxService: `%1$s`
+ Shell name not set but `%1$s` shell create mode passed
diff --git a/termux-shared/src/main/java/com/termux/shared/shell/command/ExecutionCommand.java b/termux-shared/src/main/java/com/termux/shared/shell/command/ExecutionCommand.java
index a579b313..7876ddac 100644
--- a/termux-shared/src/main/java/com/termux/shared/shell/command/ExecutionCommand.java
+++ b/termux-shared/src/main/java/com/termux/shared/shell/command/ExecutionCommand.java
@@ -105,17 +105,17 @@ public class ExecutionCommand {
}
- public enum SessionCreateMode {
+ public enum ShellCreateMode {
/** Always create {@link TerminalSession}. */
ALWAYS("always"),
- /** Create session only if no session with {@link #sessionName} found. */
- NO_SESSION_WITH_NAME("no-session-with-name");
+ /** Create shell only if no shell with {@link #shellName} found. */
+ NO_SHELL_WITH_NAME("no-shell-with-name");
private final String mode;
- SessionCreateMode(final String mode) {
+ ShellCreateMode(final String mode) {
this.mode = mode;
}
@@ -127,10 +127,10 @@ public class ExecutionCommand {
return sessionCreateMode != null && sessionCreateMode.equals(this.mode);
}
- /** Get {@link SessionCreateMode} for {@code mode} if found, otherwise {@code null}. */
+ /** Get {@link ShellCreateMode} for {@code mode} if found, otherwise {@code null}. */
@Nullable
- public static SessionCreateMode modeOf(String mode) {
- for (SessionCreateMode v : SessionCreateMode.values()) {
+ public static ShellCreateMode modeOf(String mode) {
+ for (ShellCreateMode v : ShellCreateMode.values()) {
if (v.mode.equals(mode)) {
return v;
}
@@ -187,11 +187,12 @@ public class ExecutionCommand {
/** The session action of {@link Runner#TERMINAL_SESSION} commands. */
public String sessionAction;
- /** The session name of {@link Runner#TERMINAL_SESSION} commands. */
- public String sessionName;
- /** The {@link SessionCreateMode} of session for {@link Runner#TERMINAL_SESSION} commands. */
- public String sessionCreateMode;
+ /** The shell name of commands. */
+ public String shellName;
+
+ /** The {@link ShellCreateMode} of commands. */
+ public String shellCreateMode;
@@ -386,12 +387,12 @@ public class ExecutionCommand {
if (!ignoreNull || executionCommand.sessionAction != null)
logString.append("\n").append(executionCommand.getSessionActionLogString());
- if (!ignoreNull || executionCommand.sessionName != null) {
- logString.append("\n").append(executionCommand.getSessionNameLogString());
+ if (!ignoreNull || executionCommand.shellName != null) {
+ logString.append("\n").append(executionCommand.getShellNameLogString());
}
- if (!ignoreNull || executionCommand.sessionCreateMode != null) {
- logString.append("\n").append(executionCommand.getSessionCreateModeLogString());
+ if (!ignoreNull || executionCommand.shellCreateMode != null) {
+ logString.append("\n").append(executionCommand.getShellCreateModeLogString());
}
if (!ignoreNull || executionCommand.commandIntent != null)
@@ -485,8 +486,9 @@ public class ExecutionCommand {
}
markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Session Action", executionCommand.sessionAction, "-"));
- markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Session Name", executionCommand.sessionName, "-"));
- markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Session Create Mode", executionCommand.sessionCreateMode, "-"));
+
+ markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Shell Name", executionCommand.shellName, "-"));
+ markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Shell Create Mode", executionCommand.shellCreateMode, "-"));
markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("isPluginExecutionCommand", executionCommand.isPluginExecutionCommand, "-"));
@@ -577,12 +579,12 @@ public class ExecutionCommand {
return Logger.getSingleLineLogStringEntry("Session Action", sessionAction, "-");
}
- public String getSessionNameLogString() {
- return Logger.getSingleLineLogStringEntry("Session Name", sessionName, "-");
+ public String getShellNameLogString() {
+ return Logger.getSingleLineLogStringEntry("Shell Name", shellName, "-");
}
- public String getSessionCreateModeLogString() {
- return Logger.getSingleLineLogStringEntry("Session Create Mode", sessionCreateMode, "-");
+ public String getShellCreateModeLogString() {
+ return Logger.getSingleLineLogStringEntry("Shell Create Mode", shellCreateMode, "-");
}
public String getCommandDescriptionLogString() {
diff --git a/termux-shared/src/main/java/com/termux/shared/shell/command/runner/app/AppShell.java b/termux-shared/src/main/java/com/termux/shared/shell/command/runner/app/AppShell.java
index d740a7e3..8eb3b899 100644
--- a/termux-shared/src/main/java/com/termux/shared/shell/command/runner/app/AppShell.java
+++ b/termux-shared/src/main/java/com/termux/shared/shell/command/runner/app/AppShell.java
@@ -75,8 +75,15 @@ public final class AppShell {
executionCommand.workingDirectory = "/";
String[] env = shellEnvironmentClient.buildEnvironment(context, executionCommand.isFailsafe, executionCommand.workingDirectory);
+ // Transform executable path to shell/session name, e.g. "/bin/do-something.sh" => "do-something.sh".
+ String executableBasename = ShellUtils.getExecutableBasename(executionCommand.executable);
+
+ if (executionCommand.shellName == null)
+ executionCommand.shellName = executableBasename;
final String[] commandArray = shellEnvironmentClient.setupProcessArgs(executionCommand.executable, executionCommand.arguments);
+ if (executionCommand.commandLabel == null)
+ executionCommand.commandLabel = executableBasename;
if (!executionCommand.setState(ExecutionState.EXECUTING)) {
executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), context.getString(R.string.error_failed_to_execute_app_shell_command, executionCommand.getCommandIdAndLabelLogString()));
@@ -88,11 +95,6 @@ public final class AppShell {
Logger.logDebugExtended(LOG_TAG, ExecutionCommand.getExecutionInputLogString(executionCommand,
true, Logger.shouldEnableLoggingForCustomLogLevel(executionCommand.backgroundCustomLogLevel)));
- String taskName = ShellUtils.getExecutableBasename(executionCommand.executable);
-
- if (executionCommand.commandLabel == null)
- executionCommand.commandLabel = taskName;
-
// Exec the process
final Process process;
try {
diff --git a/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java b/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java
index ab142bf7..6e95c5b1 100644
--- a/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java
+++ b/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java
@@ -11,7 +11,7 @@ import java.util.Formatter;
import java.util.List;
/*
- * Version: v0.45.0
+ * Version: v0.46.0
* SPDX-License-Identifier: MIT
*
* Changelog
@@ -251,6 +251,12 @@ import java.util.List;
*
* - 0.45.0 (2022-06-01)
* - Added `TERMUX_APP.BUILD_CONFIG_CLASS_NAME`.
+ *
+ * - 0.46.0 (2022-06-03)
+ * - Rename `TERMUX_APP.TERMUX_SERVICE.EXTRA_SESSION_NAME` to `*.EXTRA_SHELL_NAME`,
+ * `TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_SESSION_NAME` to `*.EXTRA_SHELL_NAME`,
+ * `TERMUX_APP.TERMUX_SERVICE.EXTRA_SESSION_CREATE_MODE` to `*.EXTRA_SHELL_CREATE_MODE` and
+ * `TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_SESSION_CREATE_MODE` to `*.EXTRA_SHELL_CREATE_MODE`.
*/
/**
@@ -992,10 +998,10 @@ public final class TermuxConstants {
public static final String EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL = TERMUX_PACKAGE_NAME + ".execute.background_custom_log_level"; // Default: "com.termux.execute.background_custom_log_level"
/** Intent {@code String} extra for session action for {@link Runner#TERMINAL_SESSION} commands for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
public static final String EXTRA_SESSION_ACTION = TERMUX_PACKAGE_NAME + ".execute.session_action"; // Default: "com.termux.execute.session_action"
- /** Intent {@code String} extra for session name for {@link Runner#TERMINAL_SESSION} commands for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
- public static final String EXTRA_SESSION_NAME = TERMUX_PACKAGE_NAME + ".execute.session_name"; // Default: "com.termux.execute.session_name"
- /** Intent {@code String} extra for the {@link ExecutionCommand.SessionCreateMode} for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent. */
- public static final String EXTRA_SESSION_CREATE_MODE = TERMUX_PACKAGE_NAME + ".execute.session_create_mode"; // Default: "com.termux.execute.session_create_mode"
+ /** Intent {@code String} extra for shell name for commands for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
+ public static final String EXTRA_SHELL_NAME = TERMUX_PACKAGE_NAME + ".execute.shell_name"; // Default: "com.termux.execute.shell_name"
+ /** Intent {@code String} extra for the {@link ExecutionCommand.ShellCreateMode} for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent. */
+ public static final String EXTRA_SHELL_CREATE_MODE = TERMUX_PACKAGE_NAME + ".execute.shell_create_mode"; // Default: "com.termux.execute.shell_create_mode"
/** Intent {@code String} extra for label of the command for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
public static final String EXTRA_COMMAND_LABEL = TERMUX_PACKAGE_NAME + ".execute.command_label"; // Default: "com.termux.execute.command_label"
/** Intent markdown {@code String} extra for description of the command for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */
@@ -1133,10 +1139,10 @@ public final class TermuxConstants {
public static final String EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_BACKGROUND_CUSTOM_LOG_LEVEL"; // Default: "com.termux.RUN_COMMAND_BACKGROUND_CUSTOM_LOG_LEVEL"
/** Intent {@code String} extra for session action of {@link Runner#TERMINAL_SESSION} commands for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
public static final String EXTRA_SESSION_ACTION = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_SESSION_ACTION"; // Default: "com.termux.RUN_COMMAND_SESSION_ACTION"
- /** Intent {@code String} extra for session name of {@link Runner#TERMINAL_SESSION} commands for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
- public static final String EXTRA_SESSION_NAME = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_SESSION_NAME"; // Default: "com.termux.RUN_COMMAND_SESSION_NAME"
- /** Intent {@code String} extra for the {@link ExecutionCommand.SessionCreateMode} for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent. */
- public static final String EXTRA_SESSION_CREATE_MODE = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_SESSION_CREATE_MODE"; // Default: "com.termux.RUN_COMMAND_SESSION_CREATE_MODE"
+ /** Intent {@code String} extra for shell name of commands for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
+ public static final String EXTRA_SHELL_NAME = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_SHELL_NAME"; // Default: "com.termux.RUN_COMMAND_SHELL_NAME"
+ /** Intent {@code String} extra for the {@link ExecutionCommand.ShellCreateMode} for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent. */
+ public static final String EXTRA_SHELL_CREATE_MODE = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_SHELL_CREATE_MODE"; // Default: "com.termux.RUN_COMMAND_SHELL_CREATE_MODE"
/** Intent {@code String} extra for label of the command for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
public static final String EXTRA_COMMAND_LABEL = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_COMMAND_LABEL"; // Default: "com.termux.RUN_COMMAND_COMMAND_LABEL"
/** Intent markdown {@code String} extra for description of the command for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */
diff --git a/termux-shared/src/main/java/com/termux/shared/termux/plugins/TermuxPluginUtils.java b/termux-shared/src/main/java/com/termux/shared/termux/plugins/TermuxPluginUtils.java
index 6be7c050..8d83dc0f 100644
--- a/termux-shared/src/main/java/com/termux/shared/termux/plugins/TermuxPluginUtils.java
+++ b/termux-shared/src/main/java/com/termux/shared/termux/plugins/TermuxPluginUtils.java
@@ -7,6 +7,7 @@ import android.content.Context;
import android.os.Build;
import android.os.Environment;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.termux.shared.R;
@@ -103,6 +104,28 @@ public class TermuxPluginUtils {
executionCommand.setState(ExecutionCommand.ExecutionState.SUCCESS);
}
+ /**
+ * Set {@link ExecutionCommand} state to {@link Errno#ERRNO_FAILED} with {@code errmsg} and
+ * process error with {@link #processPluginExecutionCommandError(Context, String, ExecutionCommand, boolean)}.
+ *
+ *
+ * @param context The {@link Context} for operations.
+ * @param logTag The log tag to use for logging.
+ * @param executionCommand The {@link ExecutionCommand} that failed.
+ * @param forceNotification If set to {@code true}, then a flash and notification will be shown
+ * regardless of if pending intent is {@code null} or
+ * {@link TERMUX_APP#KEY_PLUGIN_ERROR_NOTIFICATIONS_ENABLED}
+ * is {@code false}.
+ * @param errmsg The error message to set.
+ */
+ public static void setAndProcessPluginExecutionCommandError(final Context context, String logTag,
+ final ExecutionCommand executionCommand,
+ boolean forceNotification,
+ @NonNull String errmsg) {
+ executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg);
+ processPluginExecutionCommandError(context, logTag, executionCommand, forceNotification);
+ }
+
/**
* Process {@link ExecutionCommand} error.
*
@@ -128,7 +151,9 @@ public class TermuxPluginUtils {
* {@link TERMUX_APP#KEY_PLUGIN_ERROR_NOTIFICATIONS_ENABLED}
* is {@code false}.
*/
- public static void processPluginExecutionCommandError(final Context context, String logTag, final ExecutionCommand executionCommand, boolean forceNotification) {
+ public static void processPluginExecutionCommandError(final Context context, String logTag,
+ final ExecutionCommand executionCommand,
+ boolean forceNotification) {
if (context == null || executionCommand == null) return;
logTag = DataUtils.getDefaultIfNull(logTag, LOG_TAG);
diff --git a/termux-shared/src/main/java/com/termux/shared/termux/shell/command/runner/terminal/TermuxSession.java b/termux-shared/src/main/java/com/termux/shared/termux/shell/command/runner/terminal/TermuxSession.java
index 7f365c99..93e32f49 100644
--- a/termux-shared/src/main/java/com/termux/shared/termux/shell/command/runner/terminal/TermuxSession.java
+++ b/termux-shared/src/main/java/com/termux/shared/termux/shell/command/runner/terminal/TermuxSession.java
@@ -131,8 +131,8 @@ public class TermuxSession {
Logger.logDebug(LOG_TAG, "Running \"" + executionCommand.getCommandIdAndLabelLogString() + "\" TermuxSession");
TerminalSession terminalSession = new TerminalSession(executionCommand.executable, executionCommand.workingDirectory, executionCommand.arguments, environment, executionCommand.terminalTranscriptRows, terminalSessionClient);
- if (executionCommand.sessionName != null) {
- terminalSession.mSessionName = executionCommand.sessionName;
+ if (executionCommand.shellName != null) {
+ terminalSession.mSessionName = executionCommand.shellName;
}
return new TermuxSession(terminalSession, executionCommand, termuxSessionClient, setStdoutOnExit);