Commit Graph

1425 Commits

Author SHA1 Message Date
agnostic-apollo f9e9193c4e Added: Add package `APK_PATH`, `SE_PROCESS_CONTEXT`, `SE_FILE_CONTEXT` and `SE_INFO` when generating app info markdown string 2022-06-11 14:15:33 +05:00
agnostic-apollo 790481b802 Added: Add functions to `PackageUtils` to get base APK path of package 2022-06-11 14:12:58 +05:00
agnostic-apollo 1788013c80 Added: Add functions to `PackageUtils` to get `seInfo` and `seInfoUser` of package 2022-06-11 14:11:58 +05:00
agnostic-apollo 5759411109 Added: Add `SELinuxUtils` to get process and file paths security contexts 2022-06-11 14:10:34 +05:00
agnostic-apollo 0fd354a469 Changed: Ensure `TermuxSession` executable is `null` if its empty so that `login` shell can start 2022-06-11 13:55:49 +05:00
agnostic-apollo 042487c2b4 Changed: Ensure `AppShell` executable is not `null` before trying to execute it 2022-06-11 13:52:10 +05:00
agnostic-apollo b96fcb78fd Changed: Update termux twitter to https://twitter.com/termuxdevs 2022-06-11 02:41:09 +05:00
agnostic-apollo 9547869a52 Changed: Update funding link to https://termux.dev/donate 2022-06-11 02:41:09 +05:00
agnostic-apollo d29e20b0d0 Removed: Remove Termux game, root, science, unstable and x11 repo links since they have all been merged with https://github.com/termux/termux-packages 2022-06-11 02:41:09 +05:00
agnostic-apollo 0c22067b5e Added|Changed: Add termux site url and change donate url to https://termux.dev/donate 2022-06-11 02:41:09 +05:00
agnostic-apollo d287734aba Added|Changed!: Rename `SESSION_NAME` and `SESSION_CREATE_MODE` to `SHELL_NAME` and `SHELL_CREATE_MODE` and add support for `ShellCreateMode` to `AppShells`
Renamed extras `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`.

Renamed `enum` class `SessionCreateMode` to `ShellCreateMode`, `sessionName` field to `shellName`, `sessionCreateMode` to `shellCreateMode` in `ExecutionCommand`.

The `TermuxService` `AppShells`/`TermuxTasks` will now consider `ShellCreateMode` as well before starting tasks as done for `TermuxSessions` via 5794ab9a

New task command to not create new foreground session and switch to existing session if one already exits with `shellName` is

```
am startservice --user 0 -n com.termux/com.termux.app.RunCommandService \
-a com.termux.RUN_COMMAND \
--es com.termux.RUN_COMMAND_PATH '/data/data/com.termux/files/usr/bin/bash' \
--es com.termux.RUN_COMMAND_SHELL_CREATE_MODE 'no-shell-with-name' \
--es com.termux.RUN_COMMAND_SHELL_NAME "custom-name"
```

New task command to not create new background task if one already exits with `shellName` is

```
am startservice --user 0 -n com.termux/com.termux.app.RunCommandService \
-a com.termux.RUN_COMMAND \
--es com.termux.RUN_COMMAND_PATH '/data/data/com.termux/files/usr/bin/top' \
--esa com.termux.RUN_COMMAND_ARGUMENTS '-n,5' \
--es com.termux.RUN_COMMAND_SHELL_CREATE_MODE 'no-shell-with-name' \
--es com.termux.RUN_COMMAND_SHELL_NAME "custom-name" \
--es com.termux.RUN_COMMAND_RUNNER "app-shell"
```
2022-06-11 02:41:09 +05:00
agnostic-apollo 46cfea09ec Added: Add support for plugin apps to set TERMUX_APP_PACKAGE_VARIANT and TERMUX_APP_PACKAGE_MANAGER from Termux app APK BuildConfig.TERMUX_PACKAGE_VARIANT 2022-06-03 00:09:18 +05:00
agnostic-apollo 980bf8f0ae Added: Add support to get termux app package context with code classloader for plugin usage 2022-06-01 00:06:05 +05:00
agnostic-apollo 231ecff5f0 Changed: Do not modify code points for virtual or soft keyboard events
Closes #2799
2022-05-29 22:44:57 +05:00
agnostic-apollo c1c46dfcfc Changed: Change `TERMUX_APP.APPS_DIR_PATH` basename from `termux-app` to `com.termux`
The apps directory will now use the unique package name of apps for basename that can be automatically generated instead of having to be hardcoded.

`termux-am-socket` will be upgraded to `v1.4.0` for respective change.
2022-05-29 08:28:20 +05:00
agnostic-apollo 37f08c4fcc Fixed: Fix `Settings.ACTION_*` permission requests for non-activity contexts
This was caused by ce12b8ad

Closes #2769
2022-05-29 07:42:53 +05:00
agnostic-apollo a50387b553 Changed: Change termux support email from termuxreports@groups.io to support@termux.dev 2022-05-29 07:42:53 +05:00
agnostic-apollo 30cb848639 Fixed: Do not setup plugin and crash notification channel on API `< 24` since NotificationManager.IMPORTANCE_HIGH requires API 24 2022-05-29 06:54:01 +05:00
agnostic-apollo b04f209f17 Added: Add TERMUX_DEVS key SHA-256 digest to official signing keys list 2022-05-24 01:20:44 +05:00
agnostic-apollo 7b222ba392 Changed: Export correct PATH and also export LD_LIBRARY_PATH for `apt-android-5` variant instead of on Android 5/6
Overrides 4e08f76f
2022-05-24 01:20:43 +05:00
Henrik Grimler 899ef71e17 Changed: Bump android-7 bootstraps to v2022.04.28-r5 2022-05-24 01:19:45 +05:00
Henrik Grimler 4d084c02e7 Changed: Bump android-5 bootstraps to v2022.04.28-r6 2022-05-24 01:19:45 +05:00
agnostic-apollo 18a1a33e83 Added: Enable `TERMUX_PACKAGE_VARIANT` `apt-android-5` builds 2022-05-24 01:19:45 +05:00
agnostic-apollo 7677633e8f Fixed: Catch `UnsatisfiedLinkError` for `local-socket` library 2022-05-24 01:19:45 +05:00
agnostic-apollo 007bef8132 Added: Add message to bootstrap error if user installed termux on portable/external/removable sd card since its not supported on some devices 2022-05-24 01:19:45 +05:00
agnostic-apollo 5290ce1f77 Added|Fixed: Add `TermuxNotificationUtils.getTermuxOrPluginAppNotificationBuilder()` helper function and fix notification icon drawable resource id issue on Android 5 2022-05-24 01:19:45 +05:00
agnostic-apollo ab9b620c88 Added: Add ResourceUtils to get resource ids from names
This will mainly be used later when MediaViewer gets added.
2022-05-24 01:19:45 +05:00
agnostic-apollo 4e08f76fd2 Changed: Export correct PATH and also export LD_LIBRARY_PATH for Android 5/6 since packages won't use DT_RUNPATH 2022-05-24 01:19:45 +05:00
agnostic-apollo c549988434 Fixed: Fix broken javadocs links 2022-05-24 01:19:45 +05:00
agnostic-apollo 55dcd09a09 Fixed: Fixed extra keys not showing properly on Android 5
Related issue #739
2022-05-24 01:19:45 +05:00
agnostic-apollo 677a580042 Changed: Add general compatibility fixes for `minSdkVerion` `21` 2022-05-24 01:19:45 +05:00
agnostic-apollo fa829623a8 Added: Add `ViewUtils.pxToDp()` 2022-05-24 01:19:45 +05:00
agnostic-apollo 14e9a8b6fc Changed: Use float dp parameter instead of int for `ViewUtils.dpToPx()` to not lose precision 2022-05-24 01:19:45 +05:00
agnostic-apollo a1719d91b3 Changed: Bump `termux-am-library` to 2.0.0 that uses `minSdkVersion` `21` 2022-05-24 01:19:45 +05:00
agnostic-apollo 9143ebdc22 Changed: Enable desugaring support to enable support for new language APIs like Java 8 on old android versions
https://developer.android.com/studio/write/java8-support
2022-05-24 01:19:45 +05:00
agnostic-apollo 623aaebb4a Changed: Bump down `minSdkVersion` from `24` to `21` to restart supporting android 5/6 for the time being
Compatibility fixes will come in later commits.
2022-05-24 01:19:45 +05:00
agnostic-apollo 6213b7f782 Changed: Use double quotes instead of single quotes for all gradle dependencies 2022-05-24 01:19:45 +05:00
Henrik Grimler 0b4f456132
Changed: Write only our open collective to FUNDING.yml
Promote https://opencollective.com/termux instead of the old donation
channels that we have no control over.
2022-05-23 22:03:41 +02:00
agnostic-apollo b950efec27 Added: Add support for `TERMUX_APP_PACKAGE_MANAGER` and `TERMUX_APP_PACKAGE_VARIANT` to build APKs with different package manager configurations
The `TermuxBootstrap` class has been added that defines the `PackageManager` and `PackageVariant` classes for the supported package manager configurations for the app. The variant is defined by the `project.ext.packageVariant` value in the `app/build.gradle` and its value is used by the `build.gradle` to pack its respective bootstrap zips in the app APK at build time and the value is used to set `TermuxBootstrap.TERMUX_APP_PACKAGE_MANAGER` and `TermuxBootstrap.TERMUX_APP_PACKAGE_VARIANT` static values that are used at runtime by the app to run variant specific code. The manager is automatically extracted from the variant as the substring before first dash `-`.

The default variant is `apt-android-7` and it can either be replaced in `app/build.gradle` manually or the `TERMUX_PACKAGE_VARIANT` env variable can be exported in which the build command is run.

The `TERMUX_APP_PACKAGE_MANAGER` and `TERMUX_APP_PACKAGE_VARIANT` environmental variables will be exported by the app and they will also be added in Termux app info in about page and reports, allowing users and devs to know which variant is currently installed.

Bootstrap of a different variant must not be manually installed by the user after app installation by replacing `$PREFIX` since app code is dependant on the variant used to build the APK.

Currently, `apt-android-7` and `apt-android-5` variants will be built for by the workflows but they will fail for `apt-android-5` since `build.gradle` support is currently not enabled and will be enabled by a pull request that adds support for Android 5. The workflow needs to try to build the `apt-android-5` variant so that pull request builds are generated.
2022-04-28 09:33:20 +05:00
agnostic-apollo 4b3b1a5b6a Changed: Bump bootstrap to v2022.04.22-r1 2022-04-23 01:49:36 +05:00
agnostic-apollo 7f7d889dd0 Fixed: Fix proguard removing JNI used methods for release builds
```
Exception in createServerSocketNative():
java.lang.NoSuchMethodError: no non-static method "Lcom/termux/shared/jni/models/JniResult;.<init>(IILjava/lang/String;I)V"
	at com.termux.shared.net.socket.local.LocalSocketManager.createServerSocketNative(Native Method)
	at com.termux.shared.net.socket.local.LocalSocketManager.createServerSocket(LocalSocketManager.java:125)
	at com.termux.shared.net.socket.local.LocalServerSocket.start(LocalServerSocket.java:100)
	at com.termux.shared.net.socket.local.LocalSocketManager.start(LocalSocketManager.java:84)
	at com.termux.shared.shell.am.AmSocketServer.start(AmSocketServer.java:68)
	at com.termux.shared.termux.shell.am.TermuxAmSocketServer.start(TermuxAmSocketServer.java:101)
	at com.termux.shared.termux.shell.am.TermuxAmSocketServer.setupTermuxAmSocketServer(TermuxAmSocketServer.java:77)
	at com.termux.app.TermuxApplication.onCreate(TermuxApplication.java:53)
	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6719)
	at android.app.ActivityThread.access$1300(ActivityThread.java:237)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loop(Looper.java:223)
	at android.app.ActivityThread.main(ActivityThread.java:7664)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
```
2022-04-23 00:39:00 +05:00
agnostic-apollo 53f26c9659 Changed: Refactor am socket server
The `AmSocketServer` now handles the entire logic for processing of am commands sent by clients and its results. This can be used by other apps as well to run their own am servers. The server started by `termux-app` will be managed by `TermuxAmSocketServer`. Read their javadocs for details.

The extended implementation `TermuxAmSocketServerClient` of `AmSocketServer.AmSocketServerClient`/`ILocalSocketManager` will also send a plugin error notification for all errors to the user instead of just logging to logcat since users are not very good at checking those, this should save dev time debugging problems. We may need to ignore notifications for some errors like broken pipe, based on their `Error` objects if they are normally expected, this requires further investigation.

The `TERMUX_APP_AM_SOCKET_SERVER_ENABLED` env variable will also be exported for all shell sessions and tasks for whether the server was successfully started on app startup. The user can disable the server by adding "run-termux-am-socket-server=false" to the "~/.termux/termux.properties" as implemented in 5f8a9222. The env variable will be checked by `$PREFIX/bin/termux-am` before attempting to connect.

The new path for the server socket is `/data/data/com.termux/files/apps/termux-app/termux-am/am.sock` as per `TERMUX_APP.APPS_DIR_PATH` added in bcd8f4c4.
2022-04-23 00:39:00 +05:00
agnostic-apollo 2aa7f43d1c Added|Changed|Fixed: Refactor local socket server implementation and make client handling abstract
- Added `LocalSocketManager` to manage the server, `LocalServerSocket` to represent server socket, `LocalClientSocket` to represent client socket, `LocalSocketRunConfig` to store server run config and `ILocalSocketManager` as interface for the `LocalSocketManager` to handle callbacks from the server to handle clients.
- Added support to get full `PeerCred` for client socket, including `pid`, `pname`, `uid`, `uname`, `gid`, `gname` and `cmdline` instead of just `uid`. This should provide more info for error logs about which client failed or tried to connect in case of disallowed clients. Some data is filled in native code and some in java. Native support for added to get process name and `cmdline` of a process with a specific pid.
- Added `JniResult` to get results for JNI calls. Previously only an int was returned and incomplete errors logged. With `JniResult`, both `retval` and `errno` will be returned and full error messages in `errmsg`, including all `strerror()` output for `errno`s. This would provide more helpful info on errors.
- Added `Error` support via `LocalSocketErrno` which contains full error messages and stacktraces for all native and java calls, allowing much better error reporting to users and devs. The errors will be logged by `LocalSocketManagerClientBase` if log level is debug or higher since `PeerCred` `cmdline` may contain private info of users.
- Added support in java to check if socket path was an absolute path and not greater than `108` bytes, after canonicalizing it since otherwise it would result in creation of useless parent directories on failure.
- Added `readDataOnInputStream()` and `sendDataToOutputStream()` functions to `LocalClientSocket` so that server manager client can easily read and send data.

- Renamed the variables and functions as per convention, specially one letter variables. https://source.android.com/setup/contribute/code-style#follow-field-naming-conventions
- Rename `local-filesystem-socket` to `local-filesystem` since abstract namespace sockets can also be created.
- Previously, it was assumed that all local server would expect a shell command string that should be converted to command args with `ArgumentTokenizer` and then should be passed to `LocalSocketHandler.handle()` and then result sent back to client with exit code, stdout and stderr, but there could be any kind of servers in which behaviour is different. Such client handling should not be hard coded and the server manager client should handle the client themselves however they like, including closing the client socket. This will now be done with `ILocalSocketManager. onClientAccepted(LocalSocketManager, LocalClientSocket)`.

- Ensure app does not crash if `local-socket` library is not found or for any other exceptions in the server since anything running in the `Application` class is critical that it does not fail since user would not be able to recover from it, specially non rooted users without SAF support to disable the server with a prop.
- Make sure all reasonable JNI exceptions are caught instead of crashing the app.
- Fixed issue where client logic (`LocalSocketHandler.handle()` was being run in the same thread as the new client acceptable thread, basically blocking new clients until previous client's am command was fully processed. Now all client interface callbacks are started in new threads by `LocalSocketManager`.
- Fix bug where timeout would not be greater than `1000ms` due to only using `tv_usec` which caps at `999,999`.
2022-04-23 00:36:12 +05:00
agnostic-apollo 5f8a922201 Added: Allow users to disable `termux-am` server
The user can add `run-termux-am-socket-server=false` entry to `termux.properties` file to disable the `termux-am` server to run at app startup which is connected to by `$PREFIX/bin/termux-am` from the `termux-am-socket` package. The default value is `true`. Changes require `termux-app` to be force stopped and restarted to provide consistent state for all termux sessions and tasks.

The prop will be used in a later commit.
2022-04-23 00:36:12 +05:00
agnostic-apollo 9a71074c7d Added: Add function to `ProcessUtils` to get app process name for a pid from `ActivityManager` 2022-04-23 00:36:12 +05:00
agnostic-apollo 69cc65c3ac Added: Add functions to `UserUtils` to get user name for user id from `PackageManager` and `Libcore` 2022-04-23 00:36:12 +05:00
agnostic-apollo bcd8f4c419 Added: Add `TERMUX_APPS_DIR_PATH` and `TERMUX_APP.APPS_DIR_PATH` and create them at application startup.
The termux files directory will also be checked and created if required at startup and code related to it will only be run if it is accessible. This can later also be used for init execution commands.

The `TERMUX_APP.APPS_DIR_PATH` will act as app specific directory for `termux-app` app related files. Other plugin apps will have their own directories under `TERMUX_APPS_DIR_PATH` if required.
2022-04-23 00:36:12 +05:00
agnostic-apollo 6bda7c4fc4 Added|Changed: Add `Logger.logErrorPrivate*()` functions which do not log errors that may contain potentially private info unless log level is debug or higher
Execution commands and other errors that may contain potentially private info should not be logged unless user has explicitly allowed it since apps with `READ_LOGS` permission would be able to read the data. A notification for failed executions commands would still be shown if enabled and required.
2022-04-23 00:36:12 +05:00
agnostic-apollo 89a08ff01a Fixed: Allow `Object` class object to be passed to `ReflectionUtils.invokeField()` 2022-04-23 00:36:12 +05:00
agnostic-apollo c81d9c3346 Added: Add `FileType.SOCKET` support and add `FileUtils.deleteSocketFile()` function 2022-04-23 00:36:12 +05:00