[Plugin] Remote Adb Shell

Search This thread

ttydy

Senior Member
Mar 30, 2012
110
9
run "pm grant com.google.android.gms android.permission.ACCESS_COARSE_LOCATION". invalid, why?
 

gps3dx

Senior Member
Jan 24, 2010
792
401
HTC Desire
Samsung Galaxy Tab 10.1
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'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 ).
@Humpie - can you please check this addon on nougat with latest tasker ?
P.S - I guess the relevant logcat is:
Code:
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 ----------

This doesn't work outside my Plugin either. I'm not sure what you're trying to do

"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.
 
Last edited:

Humpie

Recognized Developer
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 ).
@Humpie - can you please check this addon on nougat with latest tasker ?
P.S - I guess the relevant logcat is:

---------- 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.

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.
 
Last edited:

digitalpig82

Senior Member
Oct 20, 2014
214
118
Berlin
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"
(...)

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 @Humpie 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...
 

gps3dx

Senior Member
Jan 24, 2010
792
401
HTC Desire
Samsung Galaxy Tab 10.1
But actually, since you're rooted, it seems kind of pointless to use this plugin instead of just using the shell with root enabled...

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

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 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.
 
Last edited:

digitalpig82

Senior Member
Oct 20, 2014
214
118
Berlin
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.

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.
@Humpie ?
 
  • Like
Reactions: gps3dx

Humpie

Recognized Developer
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.

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?
 

gps3dx

Senior Member
Jan 24, 2010
792
401
HTC Desire
Samsung Galaxy Tab 10.1
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?
Hi @Humpie - 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
 
Last edited:

Humpie

Recognized Developer
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.
 

ttydy

Senior Member
Mar 30, 2012
110
9
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.

When can you update? Just ask, not reminder.
 

yc_richard

New member
Jun 9, 2017
3
0
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.
 

Humpie

Recognized Developer
When can you update? Just ask, not reminder.

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.

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.

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
 

yc_richard

New member
Jun 9, 2017
3
0
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

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.
 

ttydy

Senior Member
Mar 30, 2012
110
9
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.

Me too. Command does not to really quit.
 

ttydy

Senior Member
Mar 30, 2012
110
9
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

Can you share your source code on github?
 

finck125

Member
Jun 26, 2014
6
0
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 ).
@Humpie - can you please check this addon on nougat with latest tasker ?
P.S - I guess the relevant logcat is:
Code:
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 ----------


.

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 $.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 12
    Hi everyone!

    I just created my first Tasker plug-in. This plug-in enables you to send an adb shell command to any other device on the network that has adb over wifi enabled. I for example use it to turn my androidtv on or off by sending it the command "input keyevent POWER". You can also open specific activities in apps for example or simulate touch input.

    Please read the description before using it and don't hesitate to leave feedback/bug reports/tips! This is my first app ever published so I still have a lot to learn.

    You can download it for free from the play store:
    https://play.google.com/store/apps/details?id=com.ADBPlugin

    Edit: It's now also available on XDA Labs! You can find it here
    10
    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. :)
    3
    Second update! The Plugin now has Tasker variable support!

    (enjoy @MartelKombat ;) btw I'm still thinking about how to implement your other request!)
    2
    Any news on the output variable? I have high hopes since you mentioned you already see the output in the logs...

    Thanks a lot for this plugin! It makes an unrooted phone much easier to control! :)

    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
    2
    So...is it possible to create a version of the plugin that runs locally and doesn't disappear on a reboot?
    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!