Wifi ADB debug mode lost on restart?

tanutanu

Well-known member
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?
Just FYI. It seems to be working for me.

And you don't catch "adb shell settings put global adb_wifi_enable 1" means. I don't turn on Wifi itself. Before connecting ADB wifi debugging, I'm trying to turn on the developer option because it turned off while rebooting as you wrote.

EDITED: Too large video :oops: i uploaded on Youtube and linked it.
Actually, the implementation of ADB command on Turmux and another app would have the difference of behaviors. I prefer to test it because it is more flexible.
 
Last edited:

chaoscreater

Active member
If you dont use Tasker, how does it work then ?

Dude......I literally gave you a step by step instruction in the previous post. You do realize that Tasker plugins is not the same as Tasker itself? And you realize that MacroDroid supports plugins, including Tasker plugins? Go back and read the instructions mate.




Just FYI. It seems to be working for me.

And you don't catch "adb shell settings put global adb_wifi_enable 1" means. I don't turn on Wifi itself. Before connecting ADB wifi debugging, I'm trying to turn on the developer option because it turned off while rebooting as you wrote.

EDITED: Too large video :oops: i uploaded on Youtube and linked it.
Actually, the implementation of ADB command on Turmux and another app would have the difference of behaviors. I prefer to test it because it is more flexible.

I know exactly what "adb_wifi_enable 1" does and it's to toggle wireless debugging setting in developer option. Like I said, I toggle it without needing root. You need to turn on wifi first before you can toggle that setting in developer option. That setting RELIES on wifi being on. If you turn on wireless debugging and you turn off wifi, then wireless debugging gets turned off as well.

Just use Snurre's macro to autoamte the process of turning on wifi + wireless debugging at boot. It works fine for me without root.
http://www.macrodroidforum.com/inde...ply-adb-hacks-to-xiaomi-devices.862/post-7381

And it's good that you can run ADB svc data enable in Termux without issues. Does Termux support plugin for MacroDroid? I don't want to type ADB commands manually or manually load a .sh script into Termux manually...


UPDATE:

OK, I just tried Termux and I can confirm that it works with all the ADB commands that would normally require me to use adb tcpip 5555, so that's great. There is also a Termux Tasker Plugin that I found from FDroid and I got it installed. Unfortunately, MacroDroid cannot find the Termux Tasker Plugin. The only ADB plugin that I can use in MacroDroid is ADB Shell Command Tasker Plugin.

I need to make MacroDroid send commands to Termux somehow. Any ideas?


UPDATE 2:

Unlike LADB, which will somehow automatically get the wireless debugging IP and port automatically and connect to it, Termux doesn't do that. You have to manually connect Termux to the IP:port generated by wireless debugging. This Reddit thread automates this process, but I have no idea how to get this working in MacroDroid, as there isn't a way for MacroDroid to talk to Termux from what I can see....
https://www.reddit.com/r/tasker/comments/mjc4wx


@MacroDroidDev - Could you please confirm whether MacroDroid supports Termux-Tasker plugin? I can find Termux in the Plugins store but MacroDroid doesn't seem to be able to talk to Termux. In the Reedit link above, you can see that Tasker is able to call a Termux script and pass in variables as parameters to the script.

BTW, Termux on Google Play is being deprecated. They no longer support the Google Play version. The one I'm using is from FDROID (both Termux app and the Termux-Tasker plugin).
 
Last edited:

tanutanu

Well-known member
Dude......I literally gave you a step by step instruction in the previous post. You do realize that Tasker plugins is not the same as Tasker itself? And you realize that MacroDroid supports plugins, including Tasker plugins? Go back and read the instructions mate.






I know exactly what "adb_wifi_enable 1" does and it's to toggle wireless debugging setting in developer option. Like I said, I toggle it without needing root. You need to turn on wifi first before you can toggle that setting in developer option. That setting RELIES on wifi being on. If you turn on wireless debugging and you turn off wifi, then wireless debugging gets turned off as well.

Just use Snurre's macro to autoamte the process of turning on wifi + wireless debugging at boot. It works fine for me without root.
http://www.macrodroidforum.com/inde...ply-adb-hacks-to-xiaomi-devices.862/post-7381

And it's good that you can run ADB svc data enable in Termux without issues. Does Termux support plugin for MacroDroid? I don't want to type ADB commands manually or manually load a .sh script into Termux manually...


UPDATE:

OK, I just tried Termux and I can confirm that it works with all the ADB commands that would normally require me to use adb tcpip 5555, so that's great. There is also a Termux Tasker Plugin that I found from FDroid and I got it installed. Unfortunately, MacroDroid cannot find the Termux Tasker Plugin. The only ADB plugin that I can use in MacroDroid is ADB Shell Command Tasker Plugin.

I need to make MacroDroid send commands to Termux somehow. Any ideas?


UPDATE 2:

Unlike LADB, which will somehow automatically get the wireless debugging IP and port automatically and connect to it, Termux doesn't do that. You have to manually connect Termux to the IP:port generated by wireless debugging. This Reddit thread automates this process, but I have no idea how to get this working in MacroDroid, as there isn't a way for MacroDroid to talk to Termux from what I can see....
https://www.reddit.com/r/tasker/comments/mjc4wx


@MacroDroidDev - Could you please confirm whether MacroDroid supports Termux-Tasker plugin? I can find Termux in the Plugins store but MacroDroid doesn't seem to be able to talk to Termux. In the Reedit link above, you can see that Tasker is able to call a Termux script and pass in variables as parameters to the script.

BTW, Termux on Google Play is being deprecated. They no longer support the Google Play version. The one I'm using is from FDROID (both Termux app and the Termux-Tasker plugin).
The port number is dynamic, not fixed as you know, so need to get a specific port as I do(but becomes not reliable while connect and disconnect, so looping the several ports are better). The quoted Tasker code is just the first time to be pairing, so I don't think it need to do automatically because it is just one time procedure.
Termux itself works as Tasker/MD plugin, so it could progress the connecting sequence easily, I encountered exception while setting global value though. I'm not sure the reason of the problem, I got an error while m2crypto building but could just ignore it, built it individuality, and I didn't turn the usb debugging(security setting) on coz I don't want to give my private info to Xiaomi;) I have not so much interests to ADB hack or rooted and I did it on the other device when I needed it.
So, I don't have any questions about that, just tried as an research and evaluation as my interest.

If you got something and Jamie can be focusing on more popular features and/or issues, I think it's better for everyone and also me. I believe you have enough skills and abilities to get to your goal by yourself:)
@chaoscreator, I always read your comments with interest because you are always working passionately and almost all your comments are absolutely accurate:)

EDITED: Termux:Tasker plugin is working with MD as well. I always set variables like %val Tasker style, but MD style might be working as same as another plugin. I don't have good example but one of my macro use it.
 
Last edited:

chaoscreater

Active member
The port number is dynamic, not fixed as you know, so need to get a specific port as I do(but becomes not reliable while connect and disconnect, so looping the several ports are better). The quoted Tasker code is just the first time to be pairing, so I don't think it need to do automatically because it is just one time procedure.
Termux itself works as Tasker/MD plugin, so it could progress the connecting sequence easily, I encountered exception while setting global value though. I'm not sure the reason of the problem, I got an error while m2crypto building but could just ignore it, built it individuality, and I didn't turn the usb debugging(security setting) on coz I don't want to give my private info to Xiaomi;) I have not so much interests to ADB hack or rooted and I did it on the other device when I needed it.
So, I don't have any questions about that, just tried as an research and evaluation as my interest.

If you got something and Jamie can be focusing on more popular features and/or issues, I think it's better for everyone and also me. I believe you have enough skills and abilities to get to your goal by yourself:)
@chaoscreator, I always read your comments with interest because you are always working passionately and almost all your comments are absolutely accurate:)

EDITED: Termux:Tasker plugin is working with MD as well. I always set variables like %val Tasker style, but MD style might be working as same as another plugin. I don't have good example but one of my macro use it.

Yes, pairing with wireless debugging is a one time procedure and it needs to be done for each app (e.g. LADB or Termux). However, you still need to run "adb connect IP:port" from within Termux, in order to connect ADB wirelessly. If you reboot phone and simply try to run e.g. "adb svc data enable" in Termux, it won't work. You have to connect to ADB first.

The Reddit link I posted can be modified to "connect" instead of pairing. If I understand how it works correctly, you first create a .sh script in Termux:

~/.termux/tasker/adb.sh

Next, it uses Tasker's AutoInput plugin to get the IP address and the port from wireless debugging. It stores the IP and port values into a variable and Tasker then passes those variables as parameters to the adb.sh script.

Here is the improved version written by the same guy from Reddit:
https://www.reddit.com/r/tasker/comments/mk8zqd
The way this new version works is you can use either a quick tile (like MacroDroid's quick tile), or you can use a widget, which will trigger Tasker to run some actions in the background. I think it uses logcat to capture the IP & port from wireless debugging and then pass them as variables to Termux.



I checked out your macro (it is quite complex) and I noticed that you are using the Termux plugin in MacroDroid. But when I tried to edit it, it doesn't show me Termux in the list of plugins available to choose from. Are you using Termux + Termux Tasker Plugin from Google Play, or are you using Termux + Termux Tasker Plugin from FDROID? Google Play store version is old and obsolete and the developer said he will only support FDROID version now. Unfortunately, the FDROID version doesn't seem to be recognized by MacroDroid......


BTW, I own Xiaomi devices as well and you just need to disable/uninstall Xiaomi services like MAB and other Xiaomi related services. Enabling USB debugging shouldn't have anything to do with Xiaomi collecting your data. Another recommendation is to use NextDNS in your Android Private DNS setting. You can block system ads and ads in apps using NextDNS and this is all done without root. I don't use Blockada or AdAway or any other ad blocking solutions. Private DNS works a charm. Furthermore, you can go into your NextDNS account and check what is blocked. I used to see traffic going to Xiaomi servers and I don't anymore, partly because I uninstalled unnecessary Xiaomi services and partly because I'm using Private DNS to filter out those server connections.


Also, you're right, I think Termux's ADB binary is different to the ADB binary used in other apps (like LADB). I noticed that if I run "adb tcpip 5555" in Termux, I can kill Termux and my phone is still connected via adb tcpip 5555 without any issues. However, if I do the same thing in LADB, I have ot make sure that I keep LADB alive and running in background. If it gets killed, then I lose adb tcpip 5555. I don't know why there's a difference, I think perhaps the adb server running within the apps are slightly different, not sure.




UPDATE 2:

OK, figured out the issue for why Termux plugin not showing up in MacroDroid. I had to go into MacroDroid permission setting -> Additional Permission and allow "Run commands in Termux environment". This doesn't get prompted automatically, probably because it's not a typical Android permission....after I granted this permission, I can see the Termux plugin in MacroDroid itself. Now I just gotta figure out how to use it.....
 
Last edited:

tanutanu

Well-known member
Next, it uses Tasker's AutoInput plugin to get the IP address and the port from wireless debugging. It stores the IP and port values into a variable and Tasker then passes those variables as parameters to the adb.sh script.

Here is the improved version written by the same guy from Reddit:
https://www.reddit.com/r/tasker/comments/mk8zqd
The way this new version works is you can use either a quick tile (like MacroDroid's quick tile), or you can use a widget, which will trigger Tasker to run some actions in the background. I think it uses logcat to capture the IP & port from wireless debugging and then pass them as variables to Termux.
That's way I scanned the ports.
I usually use TouchTask to scan the screen contents but I don't want it when the device just boot up.

I checked out your macro (it is quite complex) and I noticed that you are using the Termux plugin in MacroDroid. But when I tried to edit it, it doesn't show me Termux in the list of plugins available to choose from. Are you using Termux + Termux Tasker Plugin from Google Play, or are you using Termux + Termux Tasker Plugin from FDROID? Google Play store version is old and obsolete and the developer said he will only support FDROID version now. Unfortunately, the FDROID version doesn't seem to be recognized by MacroDroid......
Google Play Store version is outdated and I head it couldn't merge to F-droid's simply. So, its better to use F-droid's. Once, installed, you can update it via pkg(apt-get) command.

OK, figured out the issue for why Termux plugin not showing up in MacroDroid. I had to go into MacroDroid permission setting -> Additional Permission and allow "Run commands in Termux environment". This doesn't get prompted automatically, probably because it's not a typical Android permission....after I granted this permission, I can see the Termux plugin in MacroDroid itself. Now I just gotta figure out how to use it.....

sounds good:)
I forgot when it added but maybe this year. Tasker supports the same permission. I tried alternative method, via Intent, but I couldn't do, Termux just opens its console same as you ticked on the plugin dialog. I guess the background run flag doesn't seem to be working correctly.
Anyway All you have to do is just pass some variables as arguments of your wrapper script. The bash, GNU tools and any scripting languages if needed are much better than mksh and very limited BSD commands of Toybox.
 
Last edited:

chaoscreater

Active member
That's way I scanned the ports.
I usually use TouchTask to scan the screen contents but I don't want it when the device just boot up.


Google Play Store version is outdated and I head it couldn't merge to F-droid's simply. So, its better to use F-droid's. Once, installed, you can update it via pkg(apt-get) command.



sounds good:)
I forgot when it added but maybe this year. Tasker supports the same permission. I tried alternative method, via Intent, but I couldn't do, Termux just opens its console same as you ticked on the plugin dialog. I guess the background run flag doesn't seem to be working correctly.
Anyway All you have to do is just pass some variables as arguments of your wrapper script. The bash, GNU tools and any scripting languages if needed are much better than mksh and very limited BSD commands of Toybox.

So are you using MacroDroid to run some nmap command to scan the port from wireless debugging, then pass the port as a variable to Termus for "adb connect ip:port"? Would you mind sharing your macro
 

tanutanu

Well-known member
So are you using MacroDroid to run some nmap command to scan the port from wireless debugging, then pass the port as a variable to Termus for "adb connect ip:port"? Would you mind sharing your macro
Exactly. It's simple one liner commands. I think it good enough when OS starts up only, but need to modify if use it frequently coz ADB Wifi debugging seems open another port when a pairing failed.

PORT=`nmap -sT -p30000-45000 localhost | tail -n 3 | head -n 1 | sed -r 's/([1-9][0-9]+)(\/tcp.+)/\1/'`; adb connect localhost:"$PORT"

Modify the port range as you want. It is not reasonable. I just put it on empirically.

EDITED: I think it better that MD macro will catch on boot event and manage with another macro. It works as the most outside wrapper. And it calls the connecting sequence on the shell script on Termux, including ADB shell commands. Then returns a value what I need for post process such as notifications.
Of course, it could be possible to do everything on Termux, but MD notifications looks better than Termux's.
 
Last edited:

chaoscreater

Active member
Exactly. It's simple one liner commands. I think it good enough when OS starts up only, but need to modify if use it frequently coz ADB Wifi debugging seems open another port when a pairing failed.

PORT=`nmap -sT -p30000-45000 localhost | tail -n 3 | head -n 1 | sed -r 's/([1-9][0-9]+)(\/tcp.+)/\1/'`; adb connect localhost:"$PORT"

Modify the port range as you want. It is not reasonable. I just put it on empirically.
Yeah, the port changes whenever you disable wireless debugging and enable it again.

Is that run within Termux or MacroDroid? It looks like you're using that command as a .sh script in Termux, then using MacroDroid to call that .sh script on phone startup?

I'm not really good with Linux and so I barely understand how .sh scripts work. If you don't mind, could you share the entire setup (if you could upload your MacroDroid template in the store, that would be nice) and some basic instructions on where to put the .sh script in Termux?
 

tanutanu

Well-known member
Yeah, the port changes whenever you disable wireless debugging and enable it again.

Is that run within Termux or MacroDroid? It looks like you're using that command as a .sh script in Termux, then using MacroDroid to call that .sh script on phone startup?

I'm not really good with Linux and so I barely understand how .sh scripts work. If you don't mind, could you share the entire setup (if you could upload your MacroDroid template in the store, that would be nice) and some basic instructions on where to put the .sh script in Termux?
OK, give me an hour. I didn't do that yet. I'm doing with the other things at the same time coz it is just a small research.
 

tanutanu

Well-known member
@chaoscreater,

Thanks for waiting. I need double to check it up 🙃
Probably it contains all what you want. The return value to MD writes to STDOUT, so you can catch it via MD variable, and manipulate it by MD Text manipulate action.

umm... text .sh file was gone away...uploaded it again.
 

Attachments

  • IMG_20211030_211049.jpg
    IMG_20211030_211049.jpg
    139.2 KB · Views: 27

chaoscreater

Active member
@chaoscreater,

Thanks for waiting. I need double to check it up 🙃
Probably it contains all what you want. The return value to MD writes to STDOUT, so you can catch it via MD variable, and manipulate it by MD Text manipulate action.

umm... text .sh file was gone away...uploaded it again.

Thanks for sharing that. I just have 2 questions:

1. How can I make the script run automatically on Termux app startup?
2. Can you include the MacroDroid macro as well for use with Termux?



Also, I have a suggestion. When you enable wireless debugging, it should register something in logcat. In fact, if you take a look at the Reddit link for Tasker, it uses logcat to capture the events. Based on this, we can capture the port used by wireless debugging and then store that as a variable. Then, pass this variable into Termux. It'll be a lot quicker compared to using nmap to scan.

I just did a test and it showed this in my logcat:

"adb wifi started on port 45391"

Make sure to kill any existing ADB server first before you run logcat. I was using adb tcpip 5555 on my phone and so I wasn't getting any logcat data at all.


UPDATE:

OK, I just tested and got my macro working. I can now just use logcat to capture the port used by wireless debugging! Now I just need to figure out how to pass this port to Termux....

Search "id=10632" in the store for my macro.


UPDATE 2:

OK, I've created my own solution and I think I got it working!

First of all, download Termux and Termux-Tasker plugin from F-DROID. Don't download from Play Store. If you're using a Xiaomi device, make sure that AFTER you've installed Termux and Termux-Tasker plugin, go into your MacroDroid setting -> Permission and allow the Termux-Plugin. If you don't do this, MacroDroid won't be able to see Termux-Plugin when you configure it in the Actions.


Run Termux and type adb. It should say that you don't have adb install and will give you a command to install it. I can't remember exactly what the command is, but I think it's something like "pkg install android-tools". This step is very important, because there are different ways to install adb in Termux and without getting into details, this is the one you need.

Once installed, run "adb pair" and it should give you an example of how the command should be structured. If you get an error about how "adb pair" is not a valid command, then you did not install the correct adb package.

Next, run Termux in a floating window. Now, browse to Developer Options -> Wireless Debugging and click to generate a pairing code. This pairing code will disappear and change to a new one whenever you swap to another app, which is why we need to run Termux in a floating window.

Next, simply run:

adb pair localhost:port pair_code

where the port and pair code are from the wireless debugging. Once done, you should see a new entry added to wireless debugging.

You can then run:

adb connect localhost:port

where the port is shown in the top in the wireless debugging menu.



Now, browse to the ~/.Termux directory:
cd ~/.Termux

List the contents of the directory:

You should find a "termux.properties" file. Edit this file:
nano termux.properties

Go to the very bottom and add exactly as it shows below:
allow-external-apps=true

Press CTRL+O to write and CTRL+X to exit. This will allow other apps to be able to issue commands to Termux (which we'll be doing using MacroDroid).

Next, while still in the same ~/.Termux directory, create a folder called Tasker:
mkdir Tasker

Go into the folder:
cd Tasker

Create a new file called connadb3.sh:
nano connadb3.sh

And paste the following in there:
#!/data/data/com.termux/files/usr/bin/bash

host="localhost"
WirelessDebugging_Port="$1"
adb=$PREFIX/bin/adb
echo "Connecting to" ${host} "on" ${WirelessDebugging_Port}
$adb connect ${host}:${WirelessDebugging_Port}

$adb tcpip 5555

As far as I know, you can call a Termux .sh script from another app by using the name of the script and the variable as parameter. In our case, we can call it like this:

connadb3.sh 43002 - where 43002 is just a random port for the purpose of this example.

The script will receive the port "43002" and use it in the variable "$1", which is in the 4th line of the script. The important part is the 2nd to last line, where it basically connects to the wireless debugging via:

adb connect localhost:port

The final line is optional. I'm using it to run adb tcpip 5555. You don't need to if you don't need it. OK, so that's the setup done in Termux. Now over to MacroDroid.

Go to the Templates store and search and add the following macros:


and


The first macro runs on device boot. It will enable your wifi, wait about 10s for wifi to be connected and then run "adb_wifi_enabled = 1". This turns on the setting "Wireless Debugging" under Developer Settings. On my phone (Xiaomi), I'll get a popup asking to "Always allow on this network" and even if you tick "Always allow", you'll get this prompt on every startup. This is a known Android bug and it seems that other people on other phone brands have the same issue.

The popup can take a few seconds to show up, so here we wait a few seconds. I then use UI Interaction to tick "Always allow on this network" (this part is optional because of the bug as mentioned above, so you can disable this step if you want). The important part is that it ticks allow, so that it starts wireless debugging in the background.

Now, because Android logcat captures adbd events, we can capture exactly what port is generated by wireless debugging. This is what the 2nd macro does. The trigger is that if abd message is found, specifically the "wifi started on port" message (from wireless debugging), then the trigger will be invoked. The tricky and annoying thing here is I can't make it run AFTER the first macro has run. Obviously, we only want to start capturing logcat AFTER we have turned on wireless debugging. I have tried using the constraint "macro 1 invoked within x minutes", but this doesn't really control the order for which macro 2 is invoked.

Therefore, my current workaround is to set macro 2 to be disabled. We run macro 1 first, then at the end of it we enable macro 2. The assumption here is that at this point, macro 1 would have turned on wireless debugging and macro 2 will immediately start capturing logcat events.

Back to macro 2. We save the logcat entry into a variable, then we extract just the port number from the variable. We then pass this port into the Termux .sh script that we created earlier, which is used in the $1 variable (i.e the first parameter) in the Termux script.

You may also need to grant MacroDroid the read_logs permission via ADB. You'll get a message about it if you haven't.

You should also double check the Termux Tasker plugin action in MacroDroid. Make sure it's not complaining about your script not being found. If yes, then you didn't add the "allow-external-apps=true" in Termux properly. Go back and re-do it, or Google it. I had to Google all of this myself.



That's it! If you got it working properly, then what should happen is everytime you boot up your phone, your wifi will connect and MacroDroid will automatically turn on wireless debugging, then use logcat to check the port and pass the port to Termux, which will then run adb connect localhost:port and finally adb tcpip 5555 (optional). No need to use nmap or anything else to scan ports, this is much more accurate and way quicker.

Of course, you can set the trigger for the logcat event to something else, such as a MacroDroid quick tile or whatever. Just make sure you know that logcat event capture runs continually (it seems that way) and so it'll slow down your phone if you misconfigure this particular trigger.



NOTEs:

- Because I don't know of a good way to click "Allow" for wireless debugging, so the MacroDroid UI interaction is what I'm using and obviously there should be a better way to do this. Sometimes, the click taps the same spot twice and so it's annoying.

- If you have previously run adb tcpip 5555 and you're trying to test this whole thing, then you won't get any logcat events. You need to kill adb server first, or just restart phone.

- If you're rooted, you can simply backup your Termux files/data from here --> /data/data/com.termux/files/home. Then, when you need to restore, just copy all files/data back to the same directory and make sure to set the permission on the files and folders. I use Root Explorer to do this and I just set permissions to 777 (yes, I know it's a bad idea but hey it works).
 
Last edited:

tanutanu

Well-known member
1. How can I make the script run automatically on Termux app startup?
Write a wrapper MD macro as you did. I told you it's better to manage all together when boot up in a MD macro.

2. Can you include the MacroDroid macro as well for use with Termux?
So, it's up to you.
My backup macro has the way how to get variables from MD even though array, and how to return variables to MD in 2 different methods. You don't need to read the macro entirely, just a part of the few line statements calling Termux:Tasker plugin.
It is also showcasing how to distribute a Termux file including in a MD macro and where it would be by default.
Check them up if you have an interest.

You should find a "termux.properties" file. Edit this file:
nano termux.properties

Go to the very bottom and add exactly as it shows below:

Press CTRL+O to write and CTRL+X to exit. This will allow other apps to be able to issue commands to Termux (which we'll be doing using MacroDroid).

Next, while still in the same ~/.Termux directory, create a folder called Tasker:


Go into the folder:


Create a new file called connadb3.sh:


And paste the following in there:


As far as I know, you can call a Termux .sh script from another app by using the name of the script and the variable as parameter. In our case, we can call it like this:

connadb3.sh 43002 - where 43002 is just a random port for the purpose of this example.

The script will receive the port "43002" and use it in the variable "$1", which is in the 4th line of the script. The important part is the 2nd to last line, where it basically connects to the wireless debugging via:
You don't need to add anything by default, just run termux-setup-storage command to access OS defined sharing directory easier.
If you want to be executable on anywhere, set a property as "allow-external-apps = true", but it doesn't need because the plugin always works on the default directory, ~/.termux/tasker, without the flag setting.

The arguments from MD is following the standard handling manner of the shell, nothing different. You can pass not only the logcat search port result but also another values, i.e. if you want to change the shell script behavior between as onBoot and as onDisconnected, you can pass the status as an argument to switch, otherwise the bash script itself could be written liike a daemon to monitor the ADB port and reconnect by itself on its interval loop and return the port as an intent.

The Logcat output is available through ADB shell, or Termux built in logcat command even before connecting ADB, so maybe you don't need to paas it from MD, sorry I don't notice the fact that the ADB Wifi connecting is logged because I had no interest crawling the log;)
Anyway, everything is up to you. Termux has its own APIs and commands for Android platform, so somethig you want to do might be possible directly. One import thing is that Termux is NOT just a frontend to access ADB shell console.

adb connect localhost:port

The final line is optional. I'm using it to run adb tcpip 5555. You don't need to if you don't need it. OK, so that's the setup done in Termux. Now over to MacroDroid.
So I told you at my very first comment, why you need to connect both. Simply continue to use the WiFi debugging port, I supposed you don't need to reconnect to switch to the over Wifi method, but you need it strongly, so I wrote the example as you want.
That's it! If you got it working properly, then what should happen is everytime you boot up your phone, your wifi will connect and MacroDroid will automatically turn on wireless debugging, then use logcat to check the port and pass the port to Termux, which will then run adb connect localhost:port and finally adb tcpip 5555 (optional). No need to use nmap or anything else to scan ports, this is much more accurate and way quicker.

Of course, you can set the trigger for the logcat event to something else, such as a MacroDroid quick tile or whatever. Just make sure you know that logcat event capture runs continually (it seems that way) and so it'll slow down your phone if you misconfigure this particular trigger.
Well, you always wrote like you...you...you...you...excuse me, I don't need any lecture. I don't know who needs the long long story, you just a little excited your great success for you, or keep it as a working log though.
Everything is just for you. You are the OP who had the issue of the topic. Even if this is the first experience for you, I don't think only few people know whole the method.

Of course, I'm glad to hear you did it well, but sorry, I have not so much interest because I know it should be possible and you would do it successfully by yourself, so I just want to hear a brief report as the result and a summary of the updates what you did. I understand it as the difference of culture, native language and/or characteristics though.
You would better to talk them when you get the questions from somebody who ask you on another opportunity:) Enjoy your macro life😄
 
Last edited:

chaoscreater

Active member
@tanutanu - The reason I'm still using adb tcpip 5555 is because I have macros that turn off wifi in specific scenarios. When wifi is turned off, wireless debugging is turned off as well. If you turn on wireless debugging again, you'll get a new port and you'll have to do another "adb connect ip:port" again, which is a waste of time. If I set "adb tcpip 5555" just once (per phone restart), then I can turn off wifi and turn on as many times as I want and I will still be able to use certain adb shell commands.

As for writing "you, you, you" a lot, that wasn't a message for you specifically. It's perfectly normal to write "you" to address everyone. I wrote that guide to share with others. It wasn't a guide written for you specifically, so I'm not sure why you're taking it so personally.

Regarding using "allow-external-apps = true", I had to put that in there, otherwise MacroDroid complains about not able to find the .sh file, even though it is there. I only put the name of the script in MacroDroid, I did not have to specify any path.

I don't know enough about Termux, because obviously I only heard about this recommendation from you just a few days ago. For now, the solution I have now is good enough for me.

Anyway, thanks for all your help, I appreciate it.
 

tanutanu

Well-known member
As for writing "you, you, you" a lot, that wasn't a message for you specifically. It's perfectly normal to write "you" to address everyone. I wrote that guide to share with others. It wasn't a guide written for you specifically, so I'm not sure why you're taking it so personally.
Yep, I know that and I understand. That's a difference of culture or grammatical usage because English is not my first language.
I'd like to suggest you to write the guide in a different topic or your blog post.
The mixed up, complexed documentation is called as チラ裏 in Japanese slang. It seems to be losing value of your achievement. Again, I'm always read your comments as highly valued ones in the chaotic forum. The only thing is that you tend to write too many extra information even if a little went off.

Regarding using "allow-external-apps = true", I had to put that in there, otherwise MacroDroid complains about not able to find the .sh file, even though it is there. I only put the name of the script in MacroDroid, I did not have to specify any path.
I guess it might be the reason.
Next, while still in the same ~/.Termux directory, create a folder called Tasker:
mkdir Tasker
"Tasker" is different than "tasker." It's case sensitive, recognize as upper and lower is different.
The correct directory, ~/.termux/tasker should be working for a long time. Actually, I don't add the flag.

EDITED: I noticed another possibility. If you filled your script name in the plugin dialog box just after you put it in the default directory, it might warn you.
Normally, a newly created file has +rw permission(600, 640 or 644) following the parental directory permission on standard UNIX platforms, an executable should have +x attribute(700, 750 or 755) though.
As the Termux exception, it is changed to executable automatically. So you have a possibility to leave the script as is, and assign it. If so, the plugin complained to you.

Anyway, thanks for all your help, I appreciate it.
You're welcome:)
 
Last edited:

chaoscreater

Active member
Just. Install that app : https://play.google.com/store/apps/details?id=com.github.standardadb
Then macrodroid import the macro
And pair the adb app to your phone then every time press local shell and done
Some devices will need more delay for the macro

I've just tested this out of curiosity and I fail to see how this helps.

Whenever you restart the phone, you have to manually pair the "ADB Local&Remote ADB Shell" app to your phone. Every time you turn on the wireless debugging setting, the port and pairing code is always different. It's randomly generated. This means you have to always manually do the pairing process yourself.

2ndly, after you get the "ADB Local&Remote ADB Shell" paired to your phone, you can't just run any ADB shell command inside Local Shell. For example, try running "adb tcpip 5555" in the Local Shell. It doesn't work. You can verify this by downloading this app and look at the status - https://play.google.com/store/apps/details?id=com.origiq.wirelessadb&hl=en_NZ&gl=US

As I mentioned in my previous posts, if you do not ROOT your phone, then there are certain MacroDroid actions and features that will not work. The alternative is to run ADB commands and this requires you to use "adb tcpip 5555".

With my method, I can automate all of this using Termux. I don't have to do a single thing every time I reboot my phone. It does all of ADB pairing (using Termux) automatically and also enables "adb tcpip 5555" automatically.
 
Top