-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
make TermuxService (com.termux.service_execute) available to other apps #804
Comments
can you please clarify this? I am interested in executing streamlink which I have running in termux. I want to start the streamlink command from an android app |
All similar issues have been closed in favour of this one, yes, but has there been any progress or concidering since the opening of this particular issue, 6 months ago? |
Currently no, as we need to implement proper permission management so commands may be executed only by programs allowed by user. Another thing that should be implemented is a way to access Termux files by third-party apps, again this will require implementing permissions. |
Hi, I took a look on how to do this. My usecase was to be able to use the <service
android:name="com.termux.app.TermuxService"
android:exported="true"
android:permission="com.termux.permission.TERMUX_SERVICE">
<intent-filter>
<action android:name="com.termux.service_execute" />
</intent-filter>
</service> It seems that the intent-filter is important because without it, there is no dialog to ask the user on Easer to allow the custom permission. I also need to define my custom permission: <permission android:name="com.termux.permission.TERMUX_SERVICE"
android:label="@string/termux_permission_label"
android:description="@string/termux_permission_description"
android:icon="@drawable/ic_launcher"
android:protectionLevel="dangerous"/> Then I modify Easer to be able to access Termux. <uses-permission android:name="com.termux.permission.TERMUX_SERVICE" /> in @Override
public boolean checkPermissions(@NonNull Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return PluginHelper.checkPermission(context, "com.termux.permission.TERMUX_SERVICE");
} else {
return true;
}
// return true;
}
@Override
public void requestPermissions(@NonNull Activity activity, int requestCode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PluginHelper.requestPermission(activity, requestCode, "com.termux.permission.TERMUX_SERVICE");
}
} Finally using am startservice --user 0 -a com.termux.service_execute -n com.termux/com.termux.app.TermuxService -d com.termux.file:/data/data/com.termux/files/home/.shortcuts/test The test script should be available on .shortcuts directory. What do you think about this approach ? Changes are both available on https://github.com/edaubert/termux-app and https://github.com/edaubert/Easer if you want to try it. I can also provide a pull request if you are interested in. The changes in Termux are only about the |
@edaubert Seems okay. Can you open a PR ? |
I really think that Idea in #302 is better and more secure. I.e. embed termux core or environment in another android app and then allow that Android App to execute Termux shell command. It is cleaner and less security concern than what is attempted by #804. It is also better to have this "embedded" Termux to operate as different environment than an installed Termux. Just my $0.02. In case it is still possible to pivot to an "embeded termux" vs the idea in this thread! |
@HarisHashim Note that Termux environment requires specific executable path ( |
Ping. Any news? |
Wait, isn't this already possible? There are bunch of apps here that call termux scripts, e.g. Calls a script during boot. I haven't been able to redo that in my own app yet though. My use case would be to call certain script from my app, one would think this is basic thing for termux. I'm trying with this code at the moment: fun runTermuxScriptBackground(filePath: String, ctx: Context) {
val scriptUri = Uri.Builder().scheme("com.termux.file").path(filePath).build()
val intent = Intent("com.termux.service_execute", scriptUri)
intent.setClassName("com.termux", "com.termux.app.TermuxService")
intent.putExtra("com.termux.execute.background", true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ctx.startForegroundService(intent)
} else {
ctx.startService(intent)
}
} Not yet working though. |
From third-party apps no. |
@Ciantic, the README says:
|
Oh bummer, have to wait for the PR. I've made a nice job service myself I want to run with a script, really dying to use it :) |
Ping. Any development going on this? If not can you let me know what all I need to integrate from the core to be used in my own app. |
I'm aware that the main reason there is no "real progress" on this is due to permissions. Maybe this could be simplified by taking a similar approach as the termux-tasker add-on: Let third-party apps call scripts only in There could even be a list of directories to check, so that there could be an termux-side-package for any third-party app that wants to integrate + the possibility to add custom scripts for users. The calling APK would just specify the script's name (e.g. "myscript.sh") and TermuxService (or any other receiver) would check for:
The first file to be found would be executed. And there would be not much to worry about permissions, since the scripts could not be dropped in the correct location without the user actually doing that. |
Guys while you're at it, there is temporary workaround for this, as for my case I needed to run ipfs(it's an application) commands in my Android app and found that there is an ipfs package available on termux, I wanted to use termux to run the commands and return the results to my app, as it may seem complex, there is a simple solution for this, termux has nodejs package using it we can run a server in termux, which in turn can execute commands on termux using node-cmd package, put it all together and you get a server to which we can send commands from our Android app to execute on termux and the server returns the response back, which fulfills the requirement for the need of integrating the core in the first place,. I've seen that I can even open ports on Android using termux and use the ports in my Android app for communication (ipfs communication stuff which is my requirement, I haven't attached that part in the sample code below). I used this for my project. You can see a sample code here for reference |
The changelog for v0.95 links here, but there's no actual info about how to do it here. This line of a commit sheds some light on the matter |
Thank you so much! :)
Get Outlook for Android<https://aka.ms/ghei36>
…________________________________
From: sudomain <notifications@github.com>
Sent: Friday, July 3, 2020 9:45:33 PM
To: termux/termux-app <termux-app@noreply.github.com>
Cc: Gopikrishnan Rajeev <gopikrishnan.rmg@live.in>; Comment <comment@noreply.github.com>
Subject: Re: [termux/termux-app] make TermuxService (com.termux.service_execute) available to other apps (#804)
The changelog for v0.95 links here, but there's no actual info about how to do it here. This line of a commit sheds some light on the matter<db3ff7b#diff-ce2c83bede81bdf3c44d9adc68f68975R18>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#804 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AFBABI3OZDMF5OESYZTD6X3RZX72LANCNFSM4FO6ALRQ>.
|
On Termux side: set On Your App side:
Closing issue as feature is already implemented and v0.95 is released. |
If someone needs to do this without using intention, for any strange reason or just "_because I can", you can install node.js (pkg install nodejs), start a local server that receives the script and executes it. (exec) Remember, this isn't secure. |
@iagows yeah, that's what I posted above |
Thanks for the example, that works great. My script is executable and has the shebang #!$PREFIX/bin/bash |
Do you literally have $PREFIX in the shebang? environmental variables are (at least generally) not supported in shebangs (https://unix.stackexchange.com/questions/20880/how-can-i-use-environment-variables-in-my-shebang) |
@Grimler91 Hum, you're right. I used to test with the full path but i switched to $PREFIX for whatever reason... Can confirm that it's working with the full shebang but i'm wondering :
Maybe i'm missing something simple but is there a way to make termux open when i start the intent and view the result of my script ? |
There is a pending PR that will open the session automatically, there is a suggested workaround until it is merged and released in the first post of that PR ( |
Oh nice, i'll be waiting for the next release then. |
Doing the support for this through a more generic intent caller makes it possible to add support for calling intents from emacs or QML. It'll also allow us to easily start emacs if needed, now that support for calling external commands is merged in termux: termux/termux-app#804 Currently the implementation is split between GUI and server parts - it probably makes sense to split that off into an android crap helper class eventually, callable from both sides.
So, any app can use the TermuxService execute.
Only minor changes in AndroidManifest.xml are needed:
```
< permission android:name="com.termux.app.TermuxService">
< /permission>
The text was updated successfully, but these errors were encountered: