这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e597ece
Added: ArgumentTokenizer to com.termux.shared.shell
tareksander Dec 4, 2021
4aca163
Added: termux-am-library to integrate am with Termux.
tareksander Dec 4, 2021
f366db0
Added: LocalFilesystemSocket as an Interface to UNIX sockets in the f…
tareksander Dec 6, 2021
33b88b5
Changed: Set termux-am-library to a tag instead of following the main…
tareksander Dec 6, 2021
3dee2eb
Changed: Allow connections from root o sockets.
tareksander Dec 8, 2021
2851175
Changed: Moved the am socket to PREFIX/var/run/am-socket
tareksander Dec 8, 2021
b025872
Changed: Updated the termux-am-library dependency, because the repo i…
tareksander Dec 8, 2021
007f9cd
Changed: Set socket dir to /data/data/com.termux/files/api/
tareksander Dec 9, 2021
cc981d8
Changed: Move `com.termux.app.utils.PluginUtils` to `com.termux.share…
agnostic-apollo Apr 8, 2022
c095a61
Changed: Rename `TermuxCrashUtils` `sendPluginCrashReportNotification…
agnostic-apollo Apr 8, 2022
02ab832
Changed|Fixed: Do not add empty stacktraces entry to Error log and ma…
agnostic-apollo Apr 17, 2022
5116d88
Changed: Add label parameter to `ExecutionCommand` `getArgumentsLogSt…
agnostic-apollo Apr 17, 2022
6b60adc
Fixed: Do not stop the app if `UncaughtExceptionHandler` implemented …
agnostic-apollo Apr 17, 2022
9c7ec0c
Added: Add functions that can be used by non main threads to set `Cra…
agnostic-apollo Apr 17, 2022
1b9ca91
Added: Add functions to `DataUtils` to get generic, space and tab ind…
agnostic-apollo Apr 17, 2022
58c3d42
Fixed: Log and add to Error the current file type in `FileUtils.delet…
agnostic-apollo Apr 17, 2022
c81d9c3
Added: Add `FileType.SOCKET` support and add `FileUtils.deleteSocketF…
agnostic-apollo Apr 17, 2022
89a08ff
Fixed: Allow `Object` class object to be passed to `ReflectionUtils.i…
agnostic-apollo Apr 17, 2022
6bda7c4
Added|Changed: Add `Logger.logErrorPrivate*()` functions which do not…
agnostic-apollo Apr 17, 2022
bcd8f4c
Added: Add `TERMUX_APPS_DIR_PATH` and `TERMUX_APP.APPS_DIR_PATH` and …
agnostic-apollo Apr 17, 2022
69cc65c
Added: Add functions to `UserUtils` to get user name for user id from…
agnostic-apollo Apr 17, 2022
9a71074
Added: Add function to `ProcessUtils` to get app process name for a p…
agnostic-apollo Apr 17, 2022
5f8a922
Added: Allow users to disable `termux-am` server
agnostic-apollo Apr 17, 2022
2aa7f43
Added|Changed|Fixed: Refactor local socket server implementation and …
agnostic-apollo Apr 17, 2022
53f26c9
Changed: Refactor am socket server
agnostic-apollo Apr 17, 2022
7f7d889
Fixed: Fix proguard removing JNI used methods for release builds
agnostic-apollo Apr 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions app/src/main/java/com/termux/app/RunCommandService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.termux.R;
import com.termux.shared.data.DataUtils;
import com.termux.shared.data.IntentUtils;
import com.termux.shared.termux.plugins.TermuxPluginUtils;
import com.termux.shared.termux.file.TermuxFileUtils;
import com.termux.shared.file.filesystem.FileType;
import com.termux.shared.errors.Errno;
Expand All @@ -22,7 +23,6 @@
import com.termux.shared.file.FileUtils;
import com.termux.shared.logger.Logger;
import com.termux.shared.notification.NotificationUtils;
import com.termux.app.utils.PluginUtils;
import com.termux.shared.shell.command.ExecutionCommand;
import com.termux.shared.shell.command.ExecutionCommand.Runner;

Expand Down Expand Up @@ -75,7 +75,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
if (!RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND.equals(intent.getAction())) {
errmsg = this.getString(R.string.error_run_command_service_invalid_intent_action, intent.getAction());
executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg);
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
return stopService();
}

Expand Down Expand Up @@ -110,7 +110,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
if (Runner.runnerOf(executionCommand.runner) == null) {
errmsg = this.getString(R.string.error_run_command_service_invalid_execution_command_runner, executionCommand.runner);
executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg);
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
return stopService();
}

Expand All @@ -137,10 +137,10 @@ public int onStartCommand(Intent intent, int flags, int startId) {
// user knows someone tried to run a command in termux context, since it may be malicious
// app or imported (tasker) plugin project and not the user himself. If a pending intent is
// also sent, then its creator is also logged and shown.
errmsg = PluginUtils.checkIfAllowExternalAppsPolicyIsViolated(this, LOG_TAG);
errmsg = TermuxPluginUtils.checkIfAllowExternalAppsPolicyIsViolated(this, LOG_TAG);
if (errmsg != null) {
executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg);
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, true);
TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, true);
return stopService();
}

Expand All @@ -150,7 +150,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
if (executionCommand.executable == null || executionCommand.executable.isEmpty()) {
errmsg = this.getString(R.string.error_run_command_service_mandatory_extra_missing, RUN_COMMAND_SERVICE.EXTRA_COMMAND_PATH);
executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg);
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
return stopService();
}

Expand All @@ -164,7 +164,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
false);
if (error != null) {
executionCommand.setStateFailed(error);
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
return stopService();
}

Expand All @@ -185,7 +185,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
false, true);
if (error != null) {
executionCommand.setStateFailed(error);
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
return stopService();
}
}
Expand Down
28 changes: 24 additions & 4 deletions app/src/main/java/com/termux/app/TermuxApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
import android.app.Application;
import android.content.Context;

import com.termux.shared.errors.Error;
import com.termux.shared.logger.Logger;
import com.termux.shared.termux.TermuxConstants;
import com.termux.shared.termux.crash.TermuxCrashUtils;
import com.termux.shared.termux.file.TermuxFileUtils;
import com.termux.shared.termux.settings.preferences.TermuxAppSharedPreferences;
import com.termux.shared.logger.Logger;
import com.termux.shared.termux.settings.properties.TermuxAppSharedProperties;
import com.termux.shared.termux.shell.am.TermuxAmSocketServer;
import com.termux.shared.termux.theme.TermuxThemeUtils;


public class TermuxApplication extends Application {

private static final String LOG_TAG = "TermuxApplication";

public void onCreate() {
super.onCreate();

Context context = getApplicationContext();

// Set crash handler for the app
TermuxCrashUtils.setCrashHandler(this);
TermuxCrashUtils.setDefaultCrashHandler(this);

// Set log config for the app
setLogConfig(context);
Expand All @@ -31,6 +35,23 @@ public void onCreate() {

// Set NightMode.APP_NIGHT_MODE
TermuxThemeUtils.setAppNightMode(properties.getNightMode());

// Check and create termux files directory. If failed to access it like in case of secondary
// user or external sd card installation, then don't run files directory related code
Error error = TermuxFileUtils.isTermuxFilesDirectoryAccessible(this, true, true);
if (error != null) {
Logger.logErrorExtended(LOG_TAG, "Termux files directory is not accessible\n" + error);
} else {
Logger.logInfo(LOG_TAG, "Termux files directory is accessible");

error = TermuxFileUtils.isAppsTermuxAppDirectoryAccessible(true, true);
if (error != null) {
Logger.logErrorExtended(LOG_TAG, "Create apps/termux-app directory failed\n" + error);
return;
}

TermuxAmSocketServer.setupTermuxAmSocketServer(context);
}
}

public static void setLogConfig(Context context) {
Expand All @@ -43,4 +64,3 @@ public static void setLogConfig(Context context) {
}

}

4 changes: 2 additions & 2 deletions app/src/main/java/com/termux/app/TermuxOpenReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import android.provider.MediaStore;
import android.webkit.MimeTypeMap;

import com.termux.app.utils.PluginUtils;
import com.termux.shared.termux.plugins.TermuxPluginUtils;
import com.termux.shared.data.DataUtils;
import com.termux.shared.data.IntentUtils;
import com.termux.shared.net.uri.UriUtils;
Expand Down Expand Up @@ -204,7 +204,7 @@ public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) thr
}

// If TermuxConstants.PROP_ALLOW_EXTERNAL_APPS property to not set to "true", then throw exception
String errmsg = PluginUtils.checkIfAllowExternalAppsPolicyIsViolated(getContext(), LOG_TAG);
String errmsg = TermuxPluginUtils.checkIfAllowExternalAppsPolicyIsViolated(getContext(), LOG_TAG);
if (errmsg != null) {
throw new IllegalArgumentException(errmsg);
}
Expand Down
32 changes: 18 additions & 14 deletions app/src/main/java/com/termux/app/TermuxService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import com.termux.R;
import com.termux.app.terminal.TermuxTerminalSessionClient;
import com.termux.app.utils.PluginUtils;
import com.termux.shared.termux.plugins.TermuxPluginUtils;
import com.termux.shared.data.IntentUtils;
import com.termux.shared.net.uri.UriUtils;
import com.termux.shared.errors.Errno;
Expand Down Expand Up @@ -286,7 +286,7 @@ private synchronized void killAllTermuxExecutionCommands() {
ExecutionCommand executionCommand = pendingPluginExecutionCommands.get(i);
if (!executionCommand.shouldNotProcessResults() && executionCommand.isPluginExecutionCommandWithPendingResult()) {
if (executionCommand.setStateFailed(Errno.ERRNO_CANCELLED.getCode(), this.getString(com.termux.shared.R.string.error_execution_cancelled))) {
PluginUtils.processPluginExecutionCommandResult(this, LOG_TAG, executionCommand);
TermuxPluginUtils.processPluginExecutionCommandResult(this, LOG_TAG, executionCommand);
}
}
}
Expand Down Expand Up @@ -367,7 +367,7 @@ private void actionServiceExecute(Intent intent) {
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);
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
return;
}

Expand Down Expand Up @@ -411,7 +411,7 @@ else if (Runner.TERMINAL_SESSION.equalsRunner(executionCommand.runner))
else {
String errmsg = getString(R.string.error_termux_service_unsupported_execution_command_runner, executionCommand.runner);
executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg);
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
}
}

Expand Down Expand Up @@ -454,9 +454,11 @@ public synchronized AppShell createTermuxTask(ExecutionCommand executionCommand)
Logger.logError(LOG_TAG, "Failed to execute new TermuxTask command for:\n" + executionCommand.getCommandIdAndLabelLogString());
// If the execution command was started for a plugin, then process the error
if (executionCommand.isPluginExecutionCommand)
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
else
Logger.logErrorExtended(LOG_TAG, executionCommand.toString());
TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
else {
Logger.logError(LOG_TAG, "Set log level to debug or higher to see error in logs");
Logger.logErrorPrivateExtended(LOG_TAG, executionCommand.toString());
}
return null;
}

Expand All @@ -483,7 +485,7 @@ public void onAppShellExited(final AppShell termuxTask) {

// If the execution command was started for a plugin, then process the results
if (executionCommand != null && executionCommand.isPluginExecutionCommand)
PluginUtils.processPluginExecutionCommandResult(this, LOG_TAG, executionCommand);
TermuxPluginUtils.processPluginExecutionCommandResult(this, LOG_TAG, executionCommand);

mTermuxTasks.remove(termuxTask);
}
Expand Down Expand Up @@ -517,7 +519,7 @@ else if (SessionCreateMode.NO_SESSION_WITH_NAME.equalsMode(executionCommand.sess
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);
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
return;
} else {
newTermuxSession = getTermuxSessionForName(executionCommand.sessionName);
Expand All @@ -527,7 +529,7 @@ else if (SessionCreateMode.NO_SESSION_WITH_NAME.equalsMode(executionCommand.sess
else {
String errmsg = getString(R.string.error_termux_service_unsupported_execution_command_session_create_mode, executionCommand.sessionCreateMode);
executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg);
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
return;
}

Expand Down Expand Up @@ -575,9 +577,11 @@ public synchronized TermuxSession createTermuxSession(ExecutionCommand execution
Logger.logError(LOG_TAG, "Failed to execute new TermuxSession command for:\n" + executionCommand.getCommandIdAndLabelLogString());
// If the execution command was started for a plugin, then process the error
if (executionCommand.isPluginExecutionCommand)
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
else
Logger.logErrorExtended(LOG_TAG, executionCommand.toString());
TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
else {
Logger.logError(LOG_TAG, "Set log level to debug or higher to see error in logs");
Logger.logErrorPrivateExtended(LOG_TAG, executionCommand.toString());
}
return null;
}

Expand Down Expand Up @@ -621,7 +625,7 @@ public void onTermuxSessionExited(final TermuxSession termuxSession) {

// If the execution command was started for a plugin, then process the results
if (executionCommand != null && executionCommand.isPluginExecutionCommand)
PluginUtils.processPluginExecutionCommandResult(this, LOG_TAG, executionCommand);
TermuxPluginUtils.processPluginExecutionCommandResult(this, LOG_TAG, executionCommand);

mTermuxSessions.remove(termuxSession);

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/termux/app/models/UserAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
public enum UserAction {

ABOUT("about"),
PLUGIN_EXECUTION_COMMAND("plugin execution command"),
REPORT_ISSUE_FROM_TRANSCRIPT("report issue from transcript");

private final String name;
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@


<!-- Miscellaneous -->
<string name="error_allow_external_apps_ungranted">%1$s requires `allow-external-apps`
property to be set to `true` in `%2$s` file.</string>
<string name="error_termux_service_start_failed_general">Failed to start TermuxService. Check logcat for exception message.</string>
<string name="error_termux_service_start_failed_bg">Failed to start TermuxService while app is in background due to android bg restrictions.</string>

Expand Down
12 changes: 12 additions & 0 deletions termux-shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@ android {
implementation "commons-io:commons-io:2.5"

implementation project(":terminal-view")

implementation 'com.github.termux:termux-am-library:1.0'
}

defaultConfig {
minSdkVersion project.properties.minSdkVersion.toInteger()
targetSdkVersion project.properties.targetSdkVersion.toInteger()
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
ndkBuild {
cppFlags ''
}
}
}

buildTypes {
Expand All @@ -45,6 +52,11 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
ndkBuild {
path file('src/main/cpp/Android.mk')
}
}
}

dependencies {
Expand Down
6 changes: 6 additions & 0 deletions termux-shared/src/main/cpp/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := local-socket
LOCAL_SRC_FILES := local-socket.cpp
include $(BUILD_SHARED_LIBRARY)
1 change: 1 addition & 0 deletions termux-shared/src/main/cpp/Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APP_STL := c++_static
Loading