yashsingh1/xdaforums huggingface dataset:
[Tasker Tips & Tricks] digitalpig82:
How to run root commands on an unrooted device with this plugin

I just wanted to share how I use this plugin, just to give others an example of what this nice plugin is capable of.

Recently, I bought a new device and for now, I have no intention of rooting it. Coming from a rooted OnePlus One, this means some of my Tasker profiles do not work as expected anymore and I have to find workarounds.

On LineageOS (and CyanogenMod before that), we have the option to display left/right cursor arrows in the navigation bar when typing text. I always loved this feature, since placing the cursor in the right position by tapping will always be a hit&miss game. Since my new device (S7 Edge) has no onscreen navigation bar, I was searching for a replacement solution to move the cursor. I came up with the idea that it would be quite handy to use the volume buttons for this. So, the idea was the following:

IF the keyboard is shown THEN use the volume keys to move the cursor (and suppress any volume changes, if possible).

It took me a while to figure out how to determine whether the keyboard is out (solution: install another keyboard and intercept the "change input method" notification as a trigger). Suppressing the volume keys' usual behaviour was easy (AutoInput -> Key Suppress) but the final step turned out to be quite difficult: How to move the cursor?

After doing some extensive research, I always came to the same point: "not possible without root". Damn.

But then, this plugin came in. The keyword "remote" in its name might suggest that you can use this plugin only to act from one device to another, but that's not true. Actually, you can use this plugin to run adb commands on the same device.

What does that mean? It means that you can run an adb shell command like "adb shell input keyevent xy" on your phone WITHOUT ROOT. In my case, I can run "input keyevent 21" and "input keyevent 22" to move the cursor. So, how can we do that?

Prerequisites:

Connect your device via ADB to a PC (google it if you don't know how) and run the command "adb tcpip 5555". That's it, you can disconnect your device now.

Then in Tasker, create an action with this plugin and type in the following:

IP Address: localhost

Port: 5555

ADB Shell Command: input keyevent POWER

Hit the play button to test this action. If you've done everything right, your screen will turn off. :cool:

Congrats, you just executed a command on an unrooted device which usually requires root privileges!

Important:

The only downside is, the tcpip setting does not survive a reboot, so you have to set the port 5555 again via PC after rebooting the device.

I hope I explained the important part well enough. If that's not the case, don't hesitate to quote me and I'll answer here. :)
[Tasker Tips & Tricks] Humpie:
I'm sorry for my absence, really busy with school etc. (honestly, I also completely forgot, I hope you can forgive me). I'll try to look into it soon (this week or the next) and see how far I get. I really like that you like my plugin! I just found out myself last week that I can let unrooted phones send shell commands to themselves using my plugin, so I'm glad to see you found it out as well! (I used it for snapchat to simulate volume key presses, which is also possible without root indeed: https://www.reddit.com/r/tasker/comments/699sav/project_share_handsfree_snapchat_picture_and/ It also works for other camera apps that require you to hold the button to film, like whatsapp etc)

Edit: I hope it pleases you to hear that today I started working on it again. I already have the responses bundled in a list in Java, now I just need to parse them to Tasker
[Tasker Tips & Tricks] Humpie:
Yes, you have to remove the "adb shell" part since all my plugin does is access the adb shell part. This means commands like adb pull etc won't work, that requires a different type of connection, that for now I can't achieve with Tasker. But running any remote shell command should be fine (like how you would run it if you were directly running the commands from a terminal on your phone)
[Tasker Tips & Tricks] kenkiller:
So...is it possible to create a version of the plugin that runs locally and doesn't disappear on a reboot?
[Tasker Tips & Tricks] Humpie:
I would like to be able to create such a think but I don't think Google would allow it since it's a big security flaw to have adb opened to the world at all time without notifying the user. Some devices however have a debug over wifi function hidden in the developer options (like the nvidia shield android tv), there you can just enable it and it will probably survive a reboot.

However what I would advise to do if this option is not available, is to create a .bat file on your desktop containing "adb tcpip 5555". That way after a reboot you can just plug in your phone, click the bat file and be done!
[Tasker Tips & Tricks] kenkiller:
Hmm....But there's this custom nav bar app where it allows users to grant it adb shell permissions, and the permission survives over reboots. Auto tools and Securetask relies on the same process as well.

I guess what we're asking for is something that's not as encompassing as your plugin. Me, I just want to execute the power command without root in a way that respects smart lock, which is possible now with your app but doesn't survive a reboot, or with the custom nav bar app, which survives a reboot, but restricts me to using it in a tiny button on the nav bar, as the dev doesn't seem interested in exposing the commands to external usage. :(

---------- Post added at 07:30 AM ---------- Previous post was at 07:28 AM ----------

We discussed it in this part here....

https://xdaforums.com/android/apps-games/app-custom-navigation-bar-customize-t3590967/post72212488
[Tasker Tips & Tricks] Humpie:
It seems this app uses specific android permissions to be able to send events etc. However my plugin has no direct access to the android system (only by using the adb bridge), so granting my plugin these permissions won't help. What however would help is if I could find a way to enable adb over wifi using only some permissions... I have no clue whether this is possible though as the app would have to call service.adb.tcp.port 5555 for itself and that needs root or an adb connection (so it still requires a laptop XD). I'm still trying though.
[Tasker Tips & Tricks] kenkiller:
No worries. It's just that it's so close yet so far, heheh.... :D I guess I'll have to reboot only when home. :D
[Tasker Tips & Tricks] Humpie:
I found out it is in fact possible to have wireless adb survive a reboot! However it requires a build.prop edit.

in \system\build.prop "service.adb.tcp.port=5555" needs to be added at the end of the file and then after a reboot adb over wifi will still be enabled (at least it was in my case).

The downside is that this modification can't be done via adb without root unless you have a custom recovery like TWRP and run adb while having that opened and /System/ mounted.

I'm trying to create a zip that modifies the build.prop how it should be modified, but I don't think it's possible to run it through a non-custom recovery...

Edit: I added my .bat file for modifying the build.prop adding that line. It uses an adb connection that requires more rights than what android allows when booted, but should probably work if you are able to access adb from recovery and you are of course booted in recovery mode (using recoveries like TWRP or even some stock manufacturer ones).
[Tasker Tips & Tricks] Humpie:
Update 4.3 is live!

As requested you can now access the output from the console directly in Tasker.

I tried to order everything neatly in a list, with each line in the console being an item in the list, but this does mean that the initial "device\sdcard $" et cetera get added as an item as well.

But since I didn't want to cut off anything important I just kept it that way. You can just modify the list in any way you want (AutoTools has some handy Array handling tools built in).

I also added some hints in the main screen just for fun.

If you run into any strange behaviour, bugs or have tips, please tell me!

Enjoy ;)
[Tasker Tips & Tricks] Humpie:
Since most people are using my Plugin locally instead of remotely, I'm thinking of renaming it to just 'ADB Shell [Tasker]'. It would make it simpler when googling it. What do you think?
[Tasker Tips & Tricks] ttydy:
run "pm grant com.google.android.gms android.permission.ACCESS_COARSE_LOCATION". invalid, why?
[Tasker Tips & Tricks] Humpie:
This doesn't work outside my Plugin either. I'm not sure what you're trying to do
[Tasker Tips & Tricks] gps3dx:
I've enabled wireless ADB on phone.

then, I connected my phone to PC, ran "adb tcpip 5555", opened tasker, tried to use the addon, BUT

NO

COMMAND whatsoever works.

( tried localhost, 5555, and commands:

A. "input keyevent POWER"

B. "pm uninstall -k --user 0 PACKAGE_NAME"

)

I use Tasker v5.0b9 on android 7.1.2 ( WITH root... so that's weird... I would expect it not to work on non-rooted phone... by mine is rooted, although the addon does not request any root perm ).

[MENTION=3372705]Humpie[/MENTION] - can you please check this addon on nougat with latest tasker ?

P.S - I guess the relevant logcat is:

07-20 19:07:17.730 32401 32648 I com.ADBPlugin: Loaded existing keypair
07-20 19:07:17.730 32401 32648 I com.ADBPlugin: Socket connecting...
07-20 19:07:17.732 32401 32648 I com.ADBPlugin: Socket connected, creating AdbConnection...
07-20 19:07:17.732 32401 32648 D com.ADBPlugin: Created, ADB connecting...
07-20 19:07:17.738 32401 32648 D com.ADBPlugin: ADB connected, opening shell stream...
07-20 19:07:17.746 32401 32648 D com.ADBPlugin: Opened, writing command: pm uninstall --user 0 -k com.whatsapp
07-20 19:07:17.747 32401 32648 D com.ADBPlugin: Command sent, getting responses
07-20 19:07:17.771 29007 29007 D checkDoubleClick: click
07-20 19:07:17.792 32401 32648 D com.ADBPlugin: response: pm uninstall --user 0 -k com.whatsapp
07-20 19:07:17.792 32401 32648 D com.ADBPlugin: response: ^@
07-20 19:07:17.792 32401 32648 D com.ADBPlugin: response: 7[r[999;999H[6n8
07-20 19:07:17.792 32401 32648 D com.ADBPlugin: response: OnePlus3:/ $
07-20 19:07:17.792 32401 32648 D com.ADBPlugin: Sending exit command and waiting for stream to close
07-20 19:07:17.796 32401 32648 W System.err: java.io.IOException: Stream closed
07-20 19:07:17.796 32401 32648 W System.err: at com.cgutman.adblib.AdbStream.read(AdbStream.java:124)
07-20 19:07:17.796 32401 32648 W System.err: at com.ADBPlugin.SendSingleCommand.SendSingleCommand(SendSingleCommand.java:251)
07-20 19:07:17.796 32401 32648 W System.err: at com.ADBPlugin.receiver.FireReceiver$1.run(FireReceiver.java:89)
07-20 19:07:17.796 32401 32648 W System.err: at java.lang.Thread.run(Thread.java:761)
07-20 19:07:17.796 32401 32648 D com.ADBPlugin: Stream closed, closing Adb...
07-20 19:07:17.796 32401 32648 D com.ADBPlugin: ADB Closed
07-20 19:07:17.796 32401 32648 D com.ADBPlugin: Executed single command

---------- Post added at 04:46 PM ---------- Previous post was at 04:30 PM ----------

"pm" command can only work through ADB without root perm on phone.

if you tried running it using terminal emulator ( again, without any root ), it won't work.

try connecting to a PC, open ADB then run it -> it will probably work.
[Tasker Tips & Tricks] Humpie:
Thanks for trying and posting the logcat!

Did you enable adb over wifi and try that tcpip command? You only need to do one of the two, since that command enables adb over wifi itself, but if you're rooted, using an app to enable adb over wifi is also possible of course.

The keyevent command should work, I'm not sure why it doesn't for you. Did you get a popup the first time your tried containing "do you trust this computer"?

My plugin works also completely without root and expects to execute commands without root. Can you however try altering the command to "su pm uninstall..." that way it will request root permission first and then execute the command as su. (you can also do it like "su; pm uninstall..." if you want to run more commands as su afterwards).

I'll update Tasker to the latest version and check out the functioning of the Plugin btw!

Edit: can confirm my Plugin to be working just fine on Tasker 5.0b9, will try to mess with the pm command.

I just checked the "pm" command btw in terminal emulator and it just worked with and without root, without root however setting permissions to certain apps does not work as expected. I'm not sure why, I don't have that much knowledge of all android commands.
[Tasker Tips & Tricks] digitalpig82:
After you connected your device to the pc, did you type "adb devices" at first to make sure you've got a connection to the device? Did you get any console output when you were typing the commands from the pc? Any additional info will help.

I did not get the latest tasker play store update yet, unfortunately :( but since [MENTION=3372705]Humpie[/MENTION] tried it with the latest beta, it seems like it will work with the 5.0 release of tasker.

But actually, since you're rooted, it seems kind of pointless to use this plugin instead of just using the shell with root enabled...
[Tasker Tips & Tricks] gps3dx:
I stated i'm rooted to clarify that it doesn't work.

I do want to run in on devices without root though... what's why i'm interested in that plugin

I can enter "adb shell" on PC without problem, using either USB or wireless ADB.

I do get "approve this device" and I select approve.

I can run "adb devices" and get my device info ON A PC, without problem.

Nontheless, any adb shell command ("ls -ls", "pwd", the command in my last post) I run using the plugin, I get %output that repeats my command with another "$" empty line after it.

I also made sure that appOps gave the plugin ALL the permissions and that my firewall (afwall) is disabled.
[Tasker Tips & Tricks] digitalpig82:
I'm afraid I can't help you with that... It seems like you did everything right. :( It works fine on my device, so I cannot investigate any more from my side.

[MENTION=3372705]Humpie[/MENTION] ?
[Tasker Tips & Tricks] Humpie:
If you get that as output, it means the command you executed worked. Just like when you would type it from a console. I think the problem thus is somewhere else. My Plugin uses the same adb library as the following (free) app https://play.google.com/store/apps/details?id=com.cgutman.androidremotedebugger. It's the same code as my Plugin uses, just without Tasker support. Can you try if it works with this app?
[Tasker Tips & Tricks] gps3dx:
Hi [MENTION=3372705]Humpie[/MENTION] - thanks for the reply.

using the app you linked, I can indeed send to "localhost:5555" commands, and they exec and work just fine.

that is indeed weird...

I do the same with your tasker plugin, but the commands I send simply do not work.

I attack screenvideo that shows that
[Tasker Tips & Tricks] ttydy:
Me too. [MENTION=3372705]Humpie[/MENTION]
[Tasker Tips & Tricks] Humpie:
I'll investigate after my holiday, but I still find it strange since it does work with that other app and I have the same code. The only difference is the Tasker part and I just followed their official guidelines and templates for that.
[Tasker Tips & Tricks] ttydy:
Waiting...
[Tasker Tips & Tricks] ttydy:
When can you update? Just ask, not reminder.
[Tasker Tips & Tricks] yc_richard:
In my case, the command sent to the localhost can only be excuted once.

For example, after the first use of: input keyevent POWER. The phone went into sleep. Unlock and run again, it got time out error.

The only way to make it work again is to toggle the USB Debugging.
[Tasker Tips & Tricks] Humpie:
Well first I need to be able to recreate the problem as it doesn't occur for me. If I find it, then I'll have to look for a way to rebuild the entire app I guess.. So it will probably take a while. I'm sorry.

I've had this problem in the very beginning of building the plugin, but the problem disappeared after the command was executed. It's like there can only be a single instance of the Plugin running (which seems reasonable since the receiver can only have one adb device connected to it) and sometimes when Tasker sends an intent to the plugin it takes ages for it to arrive, so this (or for this reason receiving multiple intents) causes the running plugin to not properly end the previous connection and then thus block the connection from all others on the receiving device.

I'd have to look into if I can detect from the plugin that the connection needs to be closed whether or not the command was executed because another command needs to be sent... But this will be hard for me
[Tasker Tips & Tricks] yc_richard:
True, it has to be a problem of multiple instances. I had tried to add "exit" after each command. But it seems it is not something can be done with the current plugin.

Hope you can find a way around it. It is a very useful plugin. Cheers.
[Tasker Tips & Tricks] ttydy:
Me too. Command does not to really quit.
[Tasker Tips & Tricks] ttydy:
Can you share your source code on github?
[Tasker Tips & Tricks] finck125:
I also have Nougat and cannot get this to work with Tasker either. I am able to get the Remote ADB Shell app to work, but the first command doesn't do anything. Any commands I enter after the first one will work though. It seems like we need an option to send a throwaway command before the actual command (a space works). The logcat seems to confirm this, with the command showing up before the $.
[Tasker Tips & Tricks] ttydy:
Does anyone know when the new version is released? [MENTION=3372705]Humpie[/MENTION]
[Tasker Tips & Tricks] Humpie:
Good idea! I certainly will, look forward to it

However, the truth is, my project is a mess, currently it won't even compile (due to old Tasker plugin templates combined with new android studio stuff). When I get it up and running again I can upload it
[Tasker Tips & Tricks] Humpie:
The "exit" command is actually always executed already at the end of each command so to gracefully close the connection. I'll do my best! thanks
[Tasker Tips & Tricks] Humpie:
Okay finally after converting the project to Gradle and making it work again, I made it open source on GitHub: https://github.com/Jolanrensen/ADBPlugin

The version on there I call 5.0 since it's a rebuilt of the app on the play store, but not much is changed (only slightly improved the responses), so I won't publish it yet on the play store. Of course I'm still looking for the bugs and the multiple instance mess, but now you can help and make a pull request if you know how to fix something I don't (again, I'm far from a professional programmer).

Btw I don't seem to be having any problems on my Shield tablet on android 7.0
[Tasker Tips & Tricks] Humpie:
you can check out the debug version for 5.0 at my github. The responses are improved already, so that will result in better logs hopefully (and of course better use of %output() in tasker itself)

I'm eager to see what it looks like for people with the jibberish-response-bug
[Tasker Tips & Tricks] ttydy:
Repeatedly run several task tasks, display timeout. you must manually stop app(com.adbplugin) for the job.

Edit: It seems that the last command did not exit properly. I'm using version 5.0

logcat:

08-29 21:39:16.869 I/com.ADBPlugin(6132): Loaded existing keypair

08-29 21:39:16.869 I/com.ADBPlugin(6132): Socket connecting at localhost:5555

08-29 21:39:16.886 I/com.ADBPlugin(6132): Socket connected, creating AdbConnection...

08-29 21:39:16.887 D/com.ADBPlugin(6132): Created, ADB connecting...
[Tasker Tips & Tricks] Humpie:
Could you check out the latest apk on github? (you need to uninstall the original as it's a debug version)

I changed the exiting of the connection.

(it's still called 5.0 but I did change some things)
[Tasker Tips & Tricks] ttydy:
So far out of the normal. thx.

Edit: The software does not work for LineageOS 14.1. Run "input keyevent POWER" does not respond.
[Tasker Tips & Tricks] Humpie:
do you have the logs?
[Tasker Tips & Tricks] Humpie:
Released version 5.0 to the play store! now everyone can try if it's improved, you can see all the changes on the google play store
[Tasker Tips & Tricks] finck125:
I am running lineage os 14.1 also. So it could be a problem with that rather than Nougat itself. Just tried the new version from the play store and it still doesn't work.
[Tasker Tips & Tricks] ttydy:
Logcat:

08-31 09:31:50.044 I/com.ADBPlugin(7522): Loaded existing keypair

08-31 09:31:50.044 I/com.ADBPlugin(7522): Socket connecting at localhost:5555

08-31 09:31:50.047 I/com.ADBPlugin(7522): Socket connected, creating AdbConnection...

08-31 09:31:50.047 D/com.ADBPlugin(7522): Created, ADB connecting...

08-31 09:31:50.056 D/com.ADBPlugin(7522): ADB connected, opening shell stream...

08-31 09:31:50.061 D/com.ADBPlugin(7522): Opened, writing command: input keyevent POWER

08-31 09:31:50.062 D/com.ADBPlugin(7522): Command sent, getting responses

08-31 09:31:50.088 D/com.ADBPlugin(7522): response: input keyevent POWER

08-31 09:31:50.088 D/com.ADBPlugin(7522): ^@7[r[999;999H[6n8oneplus3:/ $

08-31 09:31:50.089 D/com.ADBPlugin(7522): Sending close command and waiting for stream to close

08-31 09:31:50.089 D/com.ADBPlugin(7522): Stream closed, closing Adb...

08-31 09:31:50.090 D/com.ADBPlugin(7522): ADB Closed

08-31 09:31:50.090 D/com.ADBPlugin(7522): Executed single command
[Tasker Tips & Tricks] Humpie:
Thanks! It seems there's something special in the way the shell works on lineage Os, perhaps a different encoding or something... I wonder why they changed it from aosp though... I'll try to find out what this difference is.

Edit: I actually have an old tablet running cyanogenmod and it seems to have the same problem as you have! I'll see what I can do to fix it

Status update: ADB on these devices is a mess. I have to verify every time if the plugin is actually writing its command on the receiving device and the receiving device is actually responsive, but still trying!
[Tasker Tips & Tricks] ttydy:
Looking forward to your solution.
[Tasker Tips & Tricks] ttydy:
The result of the loop is not right, see the attachment. The correct result you can use the last command alone.

Edit: It seems to get the output of the previous one.
[Tasker Tips & Tricks] ttydy:
Hi: Humpie

Did the results get the wrong solution? [MENTION=3372705]Humpie[/MENTION]
[Tasker Tips & Tricks] Humpie:
I haven't been able to make it work yet on my tablet, as it's adb is fairly inconsistent with the responses. However, I'm not sure anymore if it acts the same way as with your phone. It seems my tablet ends some lines with a unknown character which messes up the ability to type the command... I'll have to find another (newer) cyanogenmod/lineage device to test with
[Tasker Tips & Tricks] ttydy:
I installed the LOS system. You can send me.
[Tasker Tips & Tricks] ttydy:
Re-explain, I get an error the result is not on the LOS, but OnePlus3 OOS. LOS get no results.
[Tasker Tips & Tricks] Humpie:
You can see what happens with that other adb app I linked here before. If you try to connect with adb to such a device you can't immediately type the command. You'll need to send an Enter before you can start to type. This seems pretty consider with all LOS/CM devices. However the CM device I own also has another problem (something with line endings or) so I can't test if I fixed the first problem with that device.

I do have a 3t with oos, however no problems there, it works fine.
[Tasker Tips & Tricks] ttydy:
When a single command, the result is correct, the loop is wrong. I made the last tasker xml the last one to "dumpsysy audio" results are correct. Loop as if the next number of characters to obtain less or empty, the result will be on a result.

Edit: other adb app (remote ADB shell) in the LOS system also get no results, show garbled. [MENTION=3372705]Humpie[/MENTION]
[Tasker Tips & Tricks] finck125:
I have been trying out some things to fix this but haven't had any luck. I could see if your fix works for me.
[Tasker Tips & Tricks] haksancan:
Great app, keep up the good work!