Wifi ADB debug mode lost on restart?

chaoscreater

Active member
I remember a while ago on my old phone (non-rooted), that I was able to use "adb tcpip 5555" and MacroDroid would continue working using ADB debug mode, even when the phone was restarted.

On my new phone, it seems that I lose ADB debug mode after a restart, which is annoying. Is there a way around this?
 

MacroDroidDev

Administrator
Staff member
Sorry but I'm not entirely sure what you mean by this. What exact feature in MacroDroid are you referring to because there are features that require an ADB hack but this should not ever reset on device reboot.
 

chaoscreater

Active member
Just to clarify, I have no issues with the ADB permissions using ADB hack. I was referring to "ADB over wifi" (adb tcpip 5555) not persisting after a phone reboot.


ADB Wifi is a method of allowing Tasker to run commands it used to need root for. You have normal permissions, and above that you have ADB, and at the top you have root permissions. Before this update, Tasker could only access regular and root. The addition of ADB wifi opens some of the root level commands to regular users.

Normally, ADB is only used when you plug your phone into a computer, but ADB wifi allows the same thing, just without using a PC. Tasker is exploiting this. Instead of a computer sending (through USB) a command to Android, Tasker can send that command instead.

Unfortunately, Tasker isn't allowed to send that command by default. So we have to plug the phone into the computer and give Tasker permission to send it. This only has to happen once per phone reboot. After you run 'adb tcpip 5555' (the command that gives Tasker permission to run ADB commands) you can unplug the phone and use it as normal. If you reboot the phone, ADB Wifi commands will not work until you re-grant Tasker the permissions to run ADB commands (by plugging it in and running 'adb tcpip 5555' again.

The WiFi part of it is just a way to trick Android into thinking the ADB command came from another device over Wifi. It doesn't really care that Tasker on the device is sending it, because Tasker is spoofing itself using the tcpip.

TLDR:
when a user runs “adb tcpip 5555”, it causes the device to listen for a TCP/IP connection on port 5555, which allows Tasker to send commands “remotely” to the ADB client. Normally this process is used to let you send ADB commands from a PC to your phone while it’s untethered, but in this case, Tasker is using it to keep the adb client alive so it can send shell commands to it.

Normally, on every phone reboot, you'd have to type "adb tcpip 5555" in order to allow either Tasker or MacroDroid to have run ADB shell commands that would normally require root (such as adb svc data enable). However, you don't need to do this anymore. Tasker will automatically spoof the "adb tcpip 5555" command by itself, meaning that you only have to run "adb tcpip 5555" just once and Tasker will still be able to execute commands using ADB, even after your phone is rebooted. I remember MacroDroid used to do the same, but it doesn't anymore.
 

MacroDroidDev

Administrator
Staff member
MacroDroid has never been able to do this I'm afraid, but maybe you were running Tasker and MacroDroid together and it was Tasker that was doing this for you. I wasn't aware that Tasker had overcome the need to do the adb wifi every time you reboot, this is certainly interesting. I will have to look into this and see if I can figure out to do the same because adding a similar ABD wifi functionality becomes viable.
 

MacroDroidDev

Administrator
Staff member
@chaoscreater the Tasker site still says "IMPORTANT NOTE:The ADB command below will have to be ran every time you reboot your device. There's no known way to run it on boot automatically."

Can you point me at a source that details the workaround that prevents this being required any more.
 

tanutanu

Well-known member
It might depend on OS developer options.
I think MD and Tasker are irrelevant.
 

Attachments

  • IMG_20211029_030429.jpg
    IMG_20211029_030429.jpg
    258.3 KB · Views: 46

chaoscreater

Active member
It might depend on OS developer options.
I think MD and Tasker are irrelevant.

No, that's not it. Wireless Debugging is NOT the same as ADB over Wifi (or ADB over Network). Wireless Debugging is an Android 11 feature and ADB over Wifi has pre-existed before Wireless Debugging.

When you run "adb tcpip 5555", that's ADB over Wifi. Here's an example screenshot from Google:

1635465285658.png

Anyway, I use both wireless debugging and adb over wifi and I already have that ticked as per your screenshot. The problem is that "always allow on this network" is only remembered for the current session. If you restart your phone, you'll have to tick that again. If you turn off wifi or restart phone, you'll have to manually enable wireless debugging.

I use wireless debugging with LADB (look it up on Google Play Store). Once you get LADB working with wireless debugging, you can then run "adb tcpip 5555" from within LADB itself. Basically, you can achieve ADB over Wifi on a non-rooted device, without using a PC or another device.

Snurre has shared a macro that automates turning on wireless debugging:
http://www.macrodroidforum.com/inde...ply-adb-hacks-to-xiaomi-devices.862/post-7381


@chaoscreater the Tasker site still says "IMPORTANT NOTE:The ADB command below will have to be ran every time you reboot your device. There's no known way to run it on boot automatically."

Can you point me at a source that details the workaround that prevents this being required any more.

I don't use Tasker anymore because I much prefer MacroDroid. I can't find the source to this either, but it's definitely possible, just not very well known.

Atm, I'm using an app called LADB to run ADB over Wifi. In a nutshell:

- Turn on wireless debugging (Android 11 feature)
- Pair LADB with wireless debugging using the generated port and pin code.
- Once LADB is paired, it will automatically connect to wireless debugging (equivalent of adb connect IP:Port I believe). From within LADB, run "adb tcpip 5555". ADB over Wifi is now enabled and now MacroDroid should be able to run ADB commands (using ADB Shell Plugin), such as "adb svc data enable". These type of commands require ADB over Wifi to work.

When you restart your phone, you'll just need to:
- Turn on wireless debugging
- Run LADB. It should automatically connect to wireless debugging again, as long as you haven't revoked ADB authorization.
- Once LADB is connected, then run "adb tcpip 5555" again.

So I think MacroDroid just needs to replace the steps done above, as much as possible. LADB can obviously invoke ADB over Wifi once it is connected to wireless debugging. So when MacroDroid runs, it just needs to automatically turn on wireless debugging (or we can do this manually), it'll connect to wireless debugging and then issue "adb tcpip 5555" in the background, without the user doing any of this.
 

Jacob L

Moderator (Lawsonator)
Have a look at the system setting action and Setedit app to see settings tables, you can turn ADB on there
 

Snurre

Well-known member
No, that's not it. Wireless Debugging is NOT the same as ADB over Wifi (or ADB over Network). Wireless Debugging is an Android 11 feature and ADB over Wifi has pre-existed before Wireless Debugging.

When you run "adb tcpip 5555", that's ADB over Wifi. Here's an example screenshot from Google:

View attachment 1346

Anyway, I use both wireless debugging and adb over wifi and I already have that ticked as per your screenshot. The problem is that "always allow on this network" is only remembered for the current session. If you restart your phone, you'll have to tick that again. If you turn off wifi or restart phone, you'll have to manually enable wireless debugging.

I use wireless debugging with LADB (look it up on Google Play Store). Once you get LADB working with wireless debugging, you can then run "adb tcpip 5555" from within LADB itself. Basically, you can achieve ADB over Wifi on a non-rooted device, without using a PC or another device.

Snurre has shared a macro that automates turning on wireless debugging:
http://www.macrodroidforum.com/inde...ply-adb-hacks-to-xiaomi-devices.862/post-7381




I don't use Tasker anymore because I much prefer MacroDroid. I can't find the source to this either, but it's definitely possible, just not very well known.

Atm, I'm using an app called LADB to run ADB over Wifi. In a nutshell:

- Turn on wireless debugging (Android 11 feature)
- Pair LADB with wireless debugging using the generated port and pin code.
- Once LADB is paired, it will automatically connect to wireless debugging (equivalent of adb connect IP:port I believe). From within LADB, run "adb tcpip 5555". ADB over Wifi is now enabled and now MacroDroid should be able to run ADB commands (using ADB Shell Plugin), such as "adb svc data enable". These type of commands require ADB over Wifi to work.

When you restart your phone, you'll just need to:
- Turn on wireless debugging
- Run LADB. It should automatically connect to wireless debugging again, as long as you haven't revoked ADB authorization.
- Once LADB is connected, then run "adb tcpip 5555" again.

So I think MacroDroid just needs to replace the steps done above, as much as possible. LADB can obviously invoke ADB over Wifi once it is connected to wireless debugging. So when MacroDroid runs, it just needs to automatically turn on wireless debugging (or we can do this manually), it'll connect to wireless debugging and then issue "adb tcpip 5555" in the background, without the user doing any of this.
I'm a "little" bit confused about all this 🤔
I'm also using LADB wich works really nice for me, what I don't understand is that I can just run "adb svc data enable" without using "adb tcpip 5555" so is it really necessary?
Or is it device Specific?
 

chaoscreater

Active member
I'm a "little" bit confused about all this 🤔
I'm also using LADB wich works really nice for me, what I don't understand is that I can just run "adb svc data enable" without using "adb tcpip 5555" so is it really necessary?
Or is it device Specific?

Pretty sure it's not device specific and I think the way you're using ADB commands is not the same as how I use it. If you have to type in commands into LADB manually everytime, then that's not automation (which is the point of MacroDroid and Tasker). In order to automate the commands, I use the Tasker plugin "ADB Shell Plugin", which is also supported in MacroDroid.

First, download "ADB Shell Plugin" from Play Store.

Next, search in the MacroDroid template store "id=10617" (Disable mobile data). There should be an action for "ADB Shell Command" that you can use directly for testing. When you use commands in ADB Shell Command, you'll have to exclude the keyword "adb". So instead of "adb svc data disable", just use "svc data disable".

Now, go into LADB and run "adb devices -l" and it should show you your ADB connected devices. It should give you the IP and port. Note down the port number.

Go back to MacroDroid and edit the macro. Edit the port in ADB Shell Command and use the same port number that you wrote down. Try to run the macro and see if it works. Obviously, the macro disables mobile data, so make sure to toggle mobile data on before you run the macro in order to verify that it works.

If it doesn't work, then go back to LADB and run "adb tcpip 5555" (make sure it shows it's connected) and you can check this by running adb devices -l again. Go back to ADB Shell Command and change the port back to 5555 and run it again and see if it works.
 

tanutanu

Well-known member
No, that's not it. Wireless Debugging is NOT the same as ADB over Wifi (or ADB over Network). Wireless Debugging is an Android 11 feature and ADB over Wifi has pre-existed before Wireless Debugging.

When you run "adb tcpip 5555", that's ADB over Wifi. Here's an example screenshot from Google:

View attachment 1346

Anyway, I use both wireless debugging and adb over wifi and I already have that ticked as per your screenshot. The problem is that "always allow on this network" is only remembered for the current session. If you restart your phone, you'll have to tick that again. If you turn off wifi or restart phone, you'll have to manually enable wireless debugging.

I use wireless debugging with LADB (look it up on Google Play Store). Once you get LADB working with wireless debugging, you can then run "adb tcpip 5555" from within LADB itself. Basically, you can achieve ADB over Wifi on a non-rooted device, without using a PC or another device.

Snurre has shared a macro that automates turning on wireless debugging:
http://www.macrodroidforum.com/inde...ply-adb-hacks-to-xiaomi-devices.862/post-7381




I don't use Tasker anymore because I much prefer MacroDroid. I can't find the source to this either, but it's definitely possible, just not very well known.

Atm, I'm using an app called LADB to run ADB over Wifi. In a nutshell:

- Turn on wireless debugging (Android 11 feature)
- Pair LADB with wireless debugging using the generated port and pin code.
- Once LADB is paired, it will automatically connect to wireless debugging (equivalent of adb connect IP:port I believe). From within LADB, run "adb tcpip 5555". ADB over Wifi is now enabled and now MacroDroid should be able to run ADB commands (using ADB Shell Plugin), such as "adb svc data enable". These type of commands require ADB over Wifi to work.

When you restart your phone, you'll just need to:
- Turn on wireless debugging
- Run LADB. It should automatically connect to wireless debugging again, as long as you haven't revoked ADB authorization.
- Once LADB is connected, then run "adb tcpip 5555" again.

So I think MacroDroid just needs to replace the steps done above, as much as possible. LADB can obviously invoke ADB over Wifi once it is connected to wireless debugging. So when MacroDroid runs, it just needs to automatically turn on wireless debugging (or we can do this manually), it'll connect to wireless debugging and then issue "adb tcpip 5555" in the background, without the user doing any of this.
OK, gotcha:) Wifi debugging abd ADB over Wifi are different.
So, I wonder why you have to use both of them? Scan the port by nmap first, then connect via ADB on Termux doesn't satisfy you? Normally, I like to use remote debugger, so I just tried to do. It would be working.
Even if ADB on Termux is something wrong, I think you can pass the port to MD once, then send to another ADB embedded app to automate the connection sequence.
 

Attachments

  • IMG_20211029_170732.jpg
    IMG_20211029_170732.jpg
    141.7 KB · Views: 27

Snurre

Well-known member
Yeah I know it's not automation but I'm not using adb that much, mainly just to grant permissions to different apps
And I'm not using Tasker, trying to do as much as possible in MD
Instead of what you are suggesting why not just use MD like this:

Screenshot_20211029-110735_MacroDroid.jpg

Works for me
 

chaoscreater

Active member
OK, gotcha:) Wifi debugging abd ADB over Wifi are different.
So, I wonder why you have to use both of them? Scan the port by nmap first, then connect via ADB on Termux doesn't satisfy you? Normally, I like to use remote debugger, so I just tried to do. It would be working.
Even if ADB on Termux is something wrong, I think you can pass the port to MD once, then send to another ADB embedded app to automate the connection sequence.
You don't have to scan the port using nmap. You can just run "adb devices -l" to get the connected port. But I see that you're using a script, which loads the nmap port into a variable and then use it (I'm guessing adb connect IP:Port), so yeah I guess that's fine.

I've tried doing what you did and logically it should work, but it doesn't for certain ADB commands. For example, let's say the port I get from wireless debugging is 43202. I'll then run "svc data enable" in ADB Command Shell via localhost on port 43202. But this doesn't work. I have to run adb tcpip 5555 first and make ADB Command Shell listen on localhost 5555. I don't know why it doesn't work for the port generated via wireless debugging.....

Anyway, try what I wrote in #11 and see if it works for you without using adb tcpip 5555.
 

chaoscreater

Active member
Yeah I know it's not automation but I'm not using adb that much, mainly just to grant permissions to different apps
And I'm not using Tasker, trying to do as much as possible in MD
Instead of what you are suggesting why not just use MD like this:

View attachment 1348

Works for me

I know about that and have tried it. It doesn't work on all devices unfortunately. While it works on my device, there are some weird behaviours with it (I have mentioned this in another MacroDroid post, cbf finding it). And not all phones have those Global/System variables (e.g. mobile_data) in the database. Also, "adb svc data enable/disable" is just an example. It's one of those commands that require elevated ADB (i.e using adb tcpip 5555). There are plenty of other ones that don't work without adb tcpip 5555.

Have you actually tried what I suggested in #11?
 

tanutanu

Well-known member
You don't have to scan the port using nmap. You can just run "adb devices -l" to get the connected port. But I see that you're using a script, which loads the nmap port into a variable and then use it (I'm guessing adb connect IP:port), so yeah I guess that's fine.

I've tried doing what you did and logically it should work, but it doesn't for certain ADB commands. For example, let's say the port I get from wireless debugging is 43202. I'll then run "svc data enable" in ADB Command Shell via localhost on port 43202. But this doesn't work. I have to run adb tcpip 5555 first and make ADB Command Shell listen on localhost 5555. I don't know why it doesn't work for the port generated via wireless debugging.....

Anyway, try what I wrote in #11 and see if it works for you without using adb tcpip 5555.
Yeah, you told me it is a big problem Android OS turn off the Wifi debugging option after rebooting. So, I tried to automate it as many as possible.
Unfortunately, the option couldn't turn on because my mobile is not rooted and setting "adb shell settings put global adb_wifi_enable 1" is impossible before connecting ADB even if rooted. I'm still looking for a good way, but in the worst case UI interaction action can do it.
Anyway, once connected through the randomized Wifi debugging port, it could switch to 5555 standard over Wifi port. And it could pass to any apps:)
 

chaoscreater

Active member
Nope, don't use Tasker
I wasn't talking about Tasker.....I'm using MacroDroid this entire time and the steps I highlighted are all done within MacroDroid.

Yeah, you told me it is a big problem Android OS turn off the Wifi debugging option after rebooting. So, I tried to automate it as many as possible.
Unfortunately, the option couldn't turn on because my mobile is not rooted and setting "adb shell settings put global adb_wifi_enable 1" is impossible before connecting ADB even if rooted. I'm still looking for a good way, but in the worst case UI interaction action can do it.
Anyway, once connected through the randomized Wifi debugging port, it could switch to 5555 standard over Wifi port. And it could pass to any apps:)
You don't need root to set adb_wifi_enable...

http://www.macrodroidforum.com/inde...ply-adb-hacks-to-xiaomi-devices.862/post-7381
 
Top