fix(termux): rename ExecutionCommand.Runner.name to 'runnerName' to avoid conflict with Enum.name

This commit is contained in:
Akash Yadav
2024-01-10 19:36:04 +05:30
parent 21d94526c9
commit 23819eef02
7 changed files with 15 additions and 19 deletions
@@ -4,7 +4,6 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.system.Os;
import android.util.Pair;
@@ -33,8 +32,6 @@ import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import static com.itsaky.androidide.utils.Environment.PREFIX;
import static com.itsaky.androidide.utils.Environment.SHELL;
import static com.termux.shared.termux.TermuxConstants.TERMUX_PREFIX_DIR;
import static com.termux.shared.termux.TermuxConstants.TERMUX_PREFIX_DIR_PATH;
import static com.termux.shared.termux.TermuxConstants.TERMUX_STAGING_PREFIX_DIR;
@@ -50,7 +50,6 @@ import com.termux.terminal.TerminalSession;
import com.termux.terminal.TerminalSessionClient;
import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -384,7 +383,7 @@ public final class TermuxService extends Service implements AppShell.AppShellCli
// If EXTRA_RUNNER is passed, use that, otherwise check EXTRA_BACKGROUND and default to Runner.TERMINAL_SESSION
executionCommand.runner = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_RUNNER,
(intent.getBooleanExtra(TERMUX_SERVICE.EXTRA_BACKGROUND, false) ? Runner.APP_SHELL.getName() : Runner.TERMINAL_SESSION.getName()));
(intent.getBooleanExtra(TERMUX_SERVICE.EXTRA_BACKGROUND, false) ? Runner.APP_SHELL.getRunnerName() : Runner.TERMINAL_SESSION.getRunnerName()));
if (Runner.runnerOf(executionCommand.runner) == null) {
String errmsg = this.getString(R.string.error_termux_service_invalid_execution_command_runner, executionCommand.runner);
executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg);
@@ -472,7 +471,7 @@ public final class TermuxService extends Service implements AppShell.AppShellCli
@Nullable
public AppShell createTermuxTask(String executablePath, String[] arguments, String stdin, String workingDirectory) {
return createTermuxTask(new ExecutionCommand(TermuxShellManager.getNextShellId(), executablePath,
arguments, stdin, workingDirectory, Runner.APP_SHELL.getName(), false));
arguments, stdin, workingDirectory, Runner.APP_SHELL.getRunnerName(), false));
}
/** Create a TermuxTask. */
@@ -580,7 +579,7 @@ public final class TermuxService extends Service implements AppShell.AppShellCli
public TermuxSession createTermuxSession(String executablePath, String[] arguments, String stdin,
String workingDirectory, boolean isFailSafe, String sessionName) {
ExecutionCommand executionCommand = new ExecutionCommand(TermuxShellManager.getNextShellId(),
executablePath, arguments, stdin, workingDirectory, Runner.TERMINAL_SESSION.getName(), isFailSafe);
executablePath, arguments, stdin, workingDirectory, Runner.TERMINAL_SESSION.getRunnerName(), isFailSafe);
executionCommand.shellName = sessionName;
return createTermuxSession(executionCommand);
}
@@ -80,7 +80,7 @@ public class PhantomProcessUtils {
// Dumpsys logs the currently enforced MAX_PHANTOM_PROCESSES value and not the device config setting.
String script = "/system/bin/dumpsys activity settings | /system/bin/grep -iE '^[\t ]+" + KEY_MAX_PHANTOM_PROCESSES + "=[0-9]+$' | /system/bin/cut -d = -f2";
ExecutionCommand executionCommand = new ExecutionCommand(-1, "/system/bin/sh", null,
script + "\n", "/", ExecutionCommand.Runner.APP_SHELL.getName(), true);
script + "\n", "/", ExecutionCommand.Runner.APP_SHELL.getRunnerName(), true);
executionCommand.commandLabel = " ActivityManager " + KEY_MAX_PHANTOM_PROCESSES + " Command";
executionCommand.backgroundCustomLogLevel = Logger.LOG_LEVEL_OFF;
AppShell appShell = AppShell.execute(context, executionCommand, null, new AndroidShellEnvironment(), null, true);
@@ -71,25 +71,25 @@ public class ExecutionCommand {
///** Run command in {@link RootShell}. */
//ROOT_SHELL("root-shell");
private final String name;
private final String runnerName;
Runner(final String name) {
this.name = name;
Runner(final String runnerName) {
this.runnerName = runnerName;
}
public String getName() {
return name;
public String getRunnerName() {
return runnerName;
}
public boolean equalsRunner(String runner) {
return runner != null && runner.equals(this.name);
return runner != null && runner.equals(this.runnerName);
}
/** Get {@link Runner} for {@code name} if found, otherwise {@code null}. */
@Nullable
public static Runner runnerOf(String name) {
for (Runner v : Runner.values()) {
if (v.name.equals(name)) {
if (v.runnerName.equals(name)) {
return v;
}
}
@@ -51,7 +51,7 @@ public class ShellCommandShellEnvironment {
ExecutionCommand.Runner runner = ExecutionCommand.Runner.runnerOf(executionCommand.runner);
if (runner == null) return environment;
ShellEnvironmentUtils.putToEnvIfSet(environment, ENV_SHELL_CMD__RUNNER_NAME, runner.getName());
ShellEnvironmentUtils.putToEnvIfSet(environment, ENV_SHELL_CMD__RUNNER_NAME, runner.getRunnerName());
ShellEnvironmentUtils.putToEnvIfSet(environment, ENV_SHELL_CMD__PACKAGE_NAME, currentPackageContext.getPackageName());
ShellEnvironmentUtils.putToEnvIfSet(environment, ENV_SHELL_CMD__SHELL_ID, String.valueOf(executionCommand.id));
ShellEnvironmentUtils.putToEnvIfSet(environment, ENV_SHELL_CMD__SHELL_NAME, executionCommand.shellName);
@@ -432,7 +432,7 @@ public class TermuxUtils {
ExecutionCommand executionCommand = new ExecutionCommand(-1,
TermuxConstants.TERMUX_BIN_PREFIX_DIR_PATH + "/bash", null, aptInfoScript,
null, ExecutionCommand.Runner.APP_SHELL.getName(), false);
null, ExecutionCommand.Runner.APP_SHELL.getRunnerName(), false);
executionCommand.commandLabel = "APT Info Command";
executionCommand.backgroundCustomLogLevel = Logger.LOG_LEVEL_OFF;
AppShell appShell = AppShell.execute(context, executionCommand, null, new TermuxShellEnvironment(), null, true);
@@ -491,7 +491,7 @@ public class TermuxUtils {
// Run script
// Logging must be disabled for output of logcat command itself in StreamGobbler
ExecutionCommand executionCommand = new ExecutionCommand(-1, "/system/bin/sh",
null, logcatScript + "\n", "/", ExecutionCommand.Runner.APP_SHELL.getName(), true);
null, logcatScript + "\n", "/", ExecutionCommand.Runner.APP_SHELL.getRunnerName(), true);
executionCommand.commandLabel = "Logcat dump command";
executionCommand.backgroundCustomLogLevel = Logger.LOG_LEVEL_OFF;
AppShell appShell = AppShell.execute(context, executionCommand, null, new TermuxShellEnvironment(), null, true);
@@ -378,7 +378,7 @@ public class TermuxFileUtils {
// Run script
ExecutionCommand executionCommand = new ExecutionCommand(-1, "/system/bin/sh", null,
statScript.toString() + "\n", "/", ExecutionCommand.Runner.APP_SHELL.getName(), true);
statScript.toString() + "\n", "/", ExecutionCommand.Runner.APP_SHELL.getRunnerName(), true);
executionCommand.commandLabel = TermuxConstants.TERMUX_APP_NAME + " Files Stat Command";
executionCommand.backgroundCustomLogLevel = Logger.LOG_LEVEL_OFF;
AppShell appShell = AppShell.execute(context, executionCommand, null, new TermuxShellEnvironment(), null, true);