-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Termux:Tasker Plugin Various Improvements #36
Merged
15 commits merged into
termux:master
from
agnostic-apollo:termux-tasker-plugin-various-improvements
Dec 6, 2020
Merged
Termux:Tasker Plugin Various Improvements #36
15 commits merged into
termux:master
from
agnostic-apollo:termux-tasker-plugin-various-improvements
Dec 6, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…s like normally done on shells like bourne shell
Make `PluginResultsService` a unified class and service to handle sending of plugin commands to the execution service, receiving the results of plugin commands back from the execution service and sending immediate or pending results back to the plugin host.
…er`. - Changed `ResultsService` service name to `PluginResultsService`.
- Moved `getVersionCode()` function to `PluginUtils` class.
… and `TermuxAppUtils` util classes.
…ger` util class. - Added support to store `log_level` persistently in android `QueryPreferences` using `QueryPreferences` util class.
…ory, provided that `allow-external-apps` property is set to `true` by the user in `~/.termux/termux.properties` file. - Added support for working directory. - Adding support for users to set plugin `logcat` log levels to help with debugging through the configuration activity options menu. - Added support to automatically clear `%errmsg`, `%stdout`, `%stderr` and `%result` variables when plugin action is run. - Adding support for showing warnings in configuration activity and returning error messages via `%errmsg` to plugin host app on invalid plugin configuration or missing permissions or access failures. - Updated `FireReceiver` to use `PluginResultsService` for sending commands to execution service and to send error messages to plugin host app if required. - Updated default action timeout value to `10s` regardless of `inTerminal` value. - Removed requirement for `TASKER_DIR` to exist for plugin configuration since absolute paths are allowed. - Fixed `isBundleValid()` function.
- Changed `case` statements to `if` since resource IDs are non-final from gradle plugin version `5`.
- Updated library versions and switched to `AndroidX`.
agnostic-apollo
force-pushed
the
termux-tasker-plugin-various-improvements
branch
from
December 6, 2020 14:22
37b97b0
to
aa13bb4
Compare
ghost
approved these changes
Dec 6, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
That was quick. Thanks! |
This was referenced Dec 16, 2020
Closed
This pull request was closed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey,
Here are a bunch of improvements for Termux:Tasker. Check the new
README.md
for more details, some things not detailed here to prevent duplication.json
. The argument splitting in code was done here.Without the java escaping, the regex is
([^"]\S*|".+?")\s*
.What that means in layman is that:
(non double quote character followed by zero or more non white space characters OR one or more characters surrounded by double quotes) followed by zero or more whitespace characters
Basically string splits on whitespaces unless enclosed in double quotes. But the second part of the OR does not check if double quotes are preceded by a backslash so to ignore them. So if you pass
"some string with \" double quote"
, i think it will likely become two argumentssome string with \
anddouble quote
After that it also replaces all double quotes with nothing in line
47
. So technically there was no way to pass double quotes from what I saw.I have fixed that by using ArgumentTokenizer which will parse the arguments as normally done on the shell, including surrounding with single quotes for sending literal strings, of course any single quotes inside the string that needs to be passed will have to be escaped.
Since termux can run dangerous commands, there should be better security. I have added
com.termux.permission.RUN_COMMAND
to theFireReceiver
that will be required to run ANY termux commands with the plugin from henceforth. TheTasker
app has requested the permission sincev5.9.3
so an update would not be required for it. Other plugin host apps will have to be updated for the plugin to continue working.Added support for absolute paths outside
~/.termux/tasker/
directory, provided thatallow-external-apps
property is set totrue
by the user in~/.termux/termux.properties
file. The permission combined with the property check provides reasonable security for apps to execute arbitrary commands. This is already done by theRUN_COMMAND
intent. The benefit would be that the result of commands can be received by the sender like Tasker as well. Note that this behaviour is a bit different fromRUN_COMMAND
intent, it requires both to run any commands, whereas the plugin will only require the permission to run scripts in tasker directory and both to run absolute paths. This will make it easier for users to just grant the permission for scripts and they can optionally not set the property totrue
if they don’t want plugin apps to run arbitrary commands. If you want this behaviour changed, let me know.Added support for working directory, specially since absolute paths are now supported. It will be automatically created if inside
~/
.Adding support for users to set plugin
logcat
log levels to help with debugging through the configuration activity options menu.The whole app is kinda refactored with safety checks everywhere, notifying the user of errors in every step, like if they are missing a permissions and if they have invalid values set or if
$PREFIX
can't be accessed by the plugin in case oftermux-app
not installed or mixing of install sources. The%errmsg
variable will also be used for reporting errors to tasker while running the plugin action that occurs before command execution.I have added the
PluginResultsService
class that is a unified class and service to handle sending of plugin commands to the execution service, receiving the results of plugin commands back from the execution service and sending immediate or pending results back to the plugin host. Thetermux-app
should consider importing the class and using thesendExecuteResultToResultsService()
function inBackgroundJob
to send exceptions in%errmsg
so that plugin host apps can be notified instead of users having to checklogcat
and also for sending back the final result in%stdout
etc.Template tasker task and scripts for running the plugin have been added in
templates/
.There is a kinda a related bug mentioned by @Grimler91 here which was being caused by
Termux:Tasker
plugin sendingTaskerPlugin.Setting.RESULT_CODE_PENDING
back to tasker for commands that had to be run in the terminal session and the tasker action had been set to a timeout of>0
. The issue was thatTermuxService
didn't send any result viaPendingIntent
back to the plugin ifEXTRA_EXECUTE_IN_BACKGROUND
wasfalse
, so the plugin also never sent any result back to tasker even though tasker was expecting it and hence action timed out. I have fixed that by sendingTaskerPlugin.Setting.RESULT_CODE_OK
directly from the plugin ifinTerminal
istrue
. Timeout will also default to10s
now regardless ofinTerminal
value so that%errmsg
can be returned to plugin host app, since otherwise if it were set to0s
, plugin host wouldn't wait for any errors and continued the task and user wouldn't know what happened, like ifallow-external-apps
is set tofalse
and absolute path out~/.termux/tasker/
directory is set asExecutable
. The users too should update their tasks and use the default10s
even withinTerminal
true
. The%errmsg
,%stdout
,%stderr
and%result
variables will also be cleared automatically whenever the action is run if timeout is greater than0
to solve the issue of if multiple actions are run in the same task, then variables from previous action may still be set and get mixed in with current ones.I have updated the code to
AndroidX
and made other changes so it can be compiled fortargetSdkVersion
29
when needed just by incrementing the number, it currently still targets28
sincetermux-app
isn't ready. Playstore uploads will not be possible sincenov 2
deadline has passed and uploads are not planned anyways untiltermux-app
is ready. The plugin works fine when targeting sdk29
with the currenttermux-app
targeting sdk28
and also withandroid-10
branch targeting sdk29
.If
termux-app
targets sdk28
andtermux-tasker
targets sdk29
on android 10 emulator.The
termux-tasker
givesavc: granted { execute }
warnings whencanExecute()
is called:The
termux-app
gives the following warnings on execution:These are likely due to
auditallow
rules and just security notifications and hopefully won't get changed to denial messages in future, but who knows. ;)If
termux-app
(android-10 branch) andtermux-tasker
both target sdk29
on android 11 emulator, the scripts and running bash commands do execute fine, although there are followingavc
warnings, not sure what's causing them. Thelib275.so
isbash
.Moreover, due to apparent proot usage to run scripts, the script shebangs need to be set to
#!/usr/bin/bash
instead of#!/data/data/com.termux/files/usr/bin/bash
, otherwise scripts fail. Is that behaviour likely to stay, since that may break current scripts of users. TheTermux Environment
section of theREADME.md
would require updating too. I have set the template scripts shebangs to#!/usr/bin/...
just in case.So basically, since no executions are directly done in
termux-tasker
, the app should work fine if it targets sdk29
. Changes just have to be made on thetermux-app
side. Shebangs will cause problems for existing scripts though. Although, pushing an update fortermux-tasker
to playstore for bug fixes can be done by targeting sdk29
and keepingtermux-app
at28
, since its working that way, but will requiretermux-app
to be installed before the plugin, otherwise due tosharedUserId
, sdk29
exec restrictions kick in, so that could be troublesome.The plugin version should ideally be incremented to
0.5
since that's referenced everywhere in theREADME.md
and templates.unrelated The
termux-app
BackgroundJob.BackgroundJob()
andTermuxService.createTermSession()
functions need to be updated for targeting sdk29
if (cwd == null) cwd = TermuxService.HOME_PATH;
needs to be changed toif (cwd == null || cwd.isEmpty()) cwd = TermuxService.HOME_PATH;
since otherwise if an empty working directory string extra is passed from theRUN_COMMAND
intent or the plugin, the following exception is raised due to an empty string being passed toRuntime.getRuntime().exec(progArray, env, new File(cwd));
. I have fixed that from the plugin side by not passing an empty directory but this should be fixed fromtermux-app
side as well, cause of issues withRUN_COMMAND
intent and possibly others.termux-app
RunCommandService.parsePath()
function needs to be fixed as perFileUtils.getExpandedTermuxPath()
function intermux-tasker
. The working directory should also be created automatically if inside termux home as pertermux-tasker
. There should also be a dedicated Wiki page added forRUN_COMMAND
intent so its easier to find for users and devs instead of its brief mention in FAQ, something that shows in search results easily likeRunning termux commands from other apps
.