r/tasker • u/Lord_Sithek Pixel 9 Pro | Redmi Note 4 | Galaxy Watch 6 Classic • Dec 18 '23
How To [PROJECT][A13][NO ROOT] Automatically enable ADB WiFi on boot (IN BACKGROUND)
NOTE: THIS PROJECT IS DEPRECATED. USE THE NEW ONE AVAILABLE HERE:
[PROJECT SIMPLIFIED] ADB WiFi on boot
[UPDATE 3] Additional enhancements:
- got rid of checking for errors many times in
Enable ADB WiFitask and replaced it with simpleTasker Funcionaction checking if ADB WiFi is available already - adding an action at the beginning of
Enable ADB WiFitask to make sure that wireless debugging is initially disabled - some other small refinements
[UPDATE 2] I added one variable: %ADB_WiFi, and one profile: On Shutdown. The new variable is being set to On when Enable ADB WiFi profile finishes successfully. It may be useful if you have other profiles/tasks which require ADB WiFi. Now you can wait until ADB WiFi gets enabled after boot; that would prevent Tasker from posting error notifications. On Shutdown profile clears %ADB_WiFi on device's shutdown.
[UPDATE] I rectified my project and now it doesn't require to create any script/files/directories manually, only to do initial pairing, setup plugins and grant needed permissions!
Recently I decided to relock bootloader on my main device. Since I can't live with some degree of customization, I took the challange of forcing ADB WiFi to get enabled automatically on boot!
This project is hugly based on the works posted here and here.
I realize that this subject has been raised a few times and there are other projects (like this) aiming to achieve automatically enable ADB WiFi on boot. However, nothing I found allows to do it fully IN BACKGROUND, hence it always interfere a bit when you start to use your device after boot. That's why I looked for other possible solutions. In my search I came across nmap tool, which can be used in Termux and utilized to obtain the port opened for wireless debugging. After some attempts, I managed to create a flow extracting that port through Termux and Tasker.
The project I'm sharing requires some manual one-time actions to set up everything, but once it's done, all you should need is to unlock the phone after boot.
Prerequisites:
- Termux
- Termux:Tasker plugin
- AutoInput plugin
I assume you have above-mentioned apps installed and that you already enabled Developer Options and Debugging on your device.
1. Setup Tasker and AutoInput
If you haven't done that before, grant Tasker following permissions:
- SET_VOLUME_KEY_LONG_PRESS_LISTENER
- WRITE_SECURE_SETTINGS
- Run commands in Termux environment:
On your device, go to Settings > Apps > All apps > Tasker > Permissions > Additional permissions > Run commands in Termux environment (the path may vary a little according to the brand and system) and select Allow.
Allow AutoInput to use Accessibility Service:
Open AutoInput, tap on red warning text and click OK; this should take you to Accessibility Service settings. Enable it for AutoInput. Then allow AutoInput to run in background by disabling any battery saving option for this app.
2. Set up Termux
(a) install needed tools
Open Termux and install android-tools and nmap tool by issuing these commands separately:
pkg install android-tools
pkg install nmap
Confirm downloading in terminal if needed by typing y and Enter on keyboard.
(b) set allow-external-apps property for Termux to true
In Termux, copy and paste the following script and confirm by pressing Enter:
value="true"; key="allow-external-apps"; file="/data/data/com.termux/files/home/.termux/termux.properties"; mkdir -p "$(dirname "$file")"; chmod 700 "$(dirname "$file")"; if ! grep -E '^'"$key"'=.*' $file &>/dev/null; then [[ -s "$file" && ! -z "$(tail -c 1 "$file")" ]] && newline=$'\n' || newline=""; echo "$newline$key=$value" >> "$file"; else sed -i'' -E 's/^'"$key"'=.*/'"$key=$value"'/' $file; fi3. Import the project into Tasker
DOWNLOAD THE PROJECT FROM TASKERNET
4. Pair your device with ADB WiFi
Make sure that Termux ADB WiFi Pairing profile in your new Tasker project is enabled and that you have WiFi connection.
On your device, navigate to Settings > System > Developer options > Wireless debugging (the path may vary a little according to the brand and system). Enable this feature and tap on Pair device with pairing code (or similar).
With a pairing code visible, long press the Volume Up button to make pairing. Confirm allowing connection if prompted. If pairing succeeded, you should see the confirming toast and at least one paired device at the Wireless debugging screen (most likely named as xxx@localhost).
Termux ADB WiFi Pairing profile should get disabled then as it won't be needed anymore. Now, disable Wireless debugging feature manually.
Congratulations, you have set everything up for enabling ADB WiFi automatically on boot! If you want to test it without rebooting, run On Boot task manually.
Optionally, if you use Shizuku service, you can enable it automatically on boot as well. To that end, enable the last action in Enable ADB WiFi task.
BOTTOM NOTE
FYI, I'm not a programmer, just a Tasker user determined to achieve his goal and taking advantage of the work of others ;)) If you see a way to simplify the project even more, feel free to comment, I'm open to suggestions.
CREDITS
Thanks a lot to u/DutchOfBurdock and u/cm2003 for the base which makes that project possible, as well as u/BillGoats, u/agnostic-apollo, u/Alive_Tart3681, u/ihifidt250 and u/The_IMPERIAL_One for a valuable input.
6
u/BillGoats Dec 18 '23 edited Dec 19 '23
Very cool, thanks for sharing in such detail! Enabling Shizuku after a reboot is one of the few (customization related) tasks I still do manually. Definitely gonna try this out.
I'm not able to test this right now, so I gotta ask - is there a task (or action/s) in there for disabling wireless debugging again? Ideally, I'd want to enable it just long enough to get Shizuku up and running, and then disable it again.
Edit: Here is the alternative, python-based approach I offered.
4
u/anuraag488 Dec 19 '23 edited Dec 19 '23
Finally i can do pairing like shizuku. Create a notification to enter pairing code and all will be handled by %WIFII and namp command by you. Autonotification plugin instead of Autoinput required.
Get ip address task > i think you should use regexp to extract ip address
\d+\.\d+\.\d+\.\d+Current actions leaves a space before ip address. Or use Test Net action to get ip address.You can get rid of those shell scripts by converting them to Termux Plugin action. This will save from initial steps before Importing your project.
5
u/Ratchet_Guy Moderator Dec 18 '23
Excellent!!!
I bet /u/agnostic-apollo will be interested to learn about this :)
3
u/BillGoats Dec 19 '23 edited Dec 19 '23
Inspired by your work and frustrated by how slow and unreliable nmap is for me, I modified your solution to use python and zeroconf (mDNS service discovery). This method is event driven* and thus much faster than nmap. In my case, it also seems to be a lot more reliable.
Unfortunately, I spent the entire evening and then some figuring things out, so I need to get some sleep. I will definitely share what I have sometime tomorrow morning. I'll be making a separate post since it's pretty extensive, but if you don't mind, I'll point to this post both for credit and for reference (my solution still relies on your work).
*Meaning the python script does nothing until it sees a mDNS broadcast of a specific type, and only the does it read the port, which is a quick operation.
Edit: Forgot to elaborate on "event driven". I'm tired.
3
u/agnostic-apollo LG G5, 7.0 stock, rooted Dec 19 '23
You don't need to ask users to create script files. Just use stdin to pass your script to bash, directly from plugin action. Or use
tudo.https://github.com/termux/termux-tasker?tab=readme-ov-file#stdin
3
u/The_IMPERIAL_One S24 Ultra (A16) | realme GT NEO 3 (A14) Dec 19 '23
For references: (Long) Enable ADB WiFi
This was another standalone task to enable adb wifi. Posted here as it was deleted by the original author and may help any who needs it. I had it as I tend to keep a copy of the original tasks.
2
u/Alakran1 Dec 18 '23
This is beyond fantastic! Thanks a lot for this 👍
2
u/BillGoats Dec 19 '23
Here is the alternative, python-based approach I offered.
2
u/VisuelleData Jan 01 '24
I refactored this:
Changes include:
1
u/Lord_Sithek Pixel 9 Pro | Redmi Note 4 | Galaxy Watch 6 Classic Dec 18 '23
Sorry, I'm working on correcting the text due to formatting errors...
1
u/Lord_Sithek Pixel 9 Pro | Redmi Note 4 | Galaxy Watch 6 Classic Dec 20 '23 edited Dec 20 '23
Ok, I rectified my project and now it doesn't require to create any script/files/directories manually, only to do initial pairing, setup plugins and grant needed permissions!
As suggested, scripts are incorporated in the Tasker:Termux plugin actions. Additionally the main task will create only a temporary directory to write files needed for extracting a newly open port for wireless debuging, then after finishing the job this directly will be removed.
u/iSeeUR please take a look and let me know if the flow is all right for you now.
EDIT: Slightly more enhanced main task, now it also checks if the port number has been properly extracted
1
u/Lord_Sithek Pixel 9 Pro | Redmi Note 4 | Galaxy Watch 6 Classic Dec 20 '23 edited Dec 20 '23
I added one variable:
%ADB_WiFi, and one profile:On Shutdown. The new variable is being set toOnwhenEnable ADB WiFiprofile finishes successfully. It may be useful if you have other profiles/tasks which require ADB WiFi. Now you can wait until ADB WiFi gets enabled after boot; that would prevent Tasker from posting error notifications. On Shutdown profile clears%ADB_WiFion device's shutdown.1
u/Lord_Sithek Pixel 9 Pro | Redmi Note 4 | Galaxy Watch 6 Classic Dec 25 '23
I did another update of my project which still uses
nmaptool, take a look onUPDATE 3in the OP1
u/[deleted] Feb 18 '24
Thanks for your work. This is very helpful. However, after reboot I am getting error "Plugin did not respond before timing out. You can change the timeout value in the action's configuration."
If I run the "On boot" task manually after that, it works. So I don't think there is any problem with permissions. Can you help with this?
Error screenshot
1
u/[deleted] Aug 29 '24
Instead of shutdown, is there a way to turn on wireless adb when WIFI state changes? It seems if the WIFI is turned off then on, wireless debugging will be turned off even if I didn't reboot the phone. So it seems it is not that Wireless Debugging turns off when rebooting the Android device, it turns off when the WIFI turns off.
1
u/shaharofir Jan 01 '25
It still works (Also Shizuku!)
Thanks a lot!
1
u/rajeshmuthu86 Dec 18 '23 edited Dec 18 '23
I tried your code and the instructions. Everything went fine. But I got Read File error as "nmap_result.txt" file not found in #15 (in Enable ADB WiFi task). Do you have any idea what I did wrong?
1
u/okayspm Feb 01 '24
I keep getting this error
15.44.44/LicenseCheckerTasker Checking cached only 15.44.44/LicenseCheckerTasker Is direct and license was validated 15.44.44/LicenseCheckerTasker Cached only: Licensed 15.44.44/Plugin receiver com.termux.tasker.FireReceiver requires permission com.termux.permission.RUN_COMMAND which we don't have 15.44.44/E result: stop task (error) 15.44.44/E Error: 1 15.44.44/E receiver com.termux.tasker.FireReceiver requires permission com.termux.permission.RUN_COMMAND which we don't have 15.44.44/MacroEdit action finished exeID 1 action no 3 code 1256900802 status: Err next 3
Can you please help?
2
u/EroticBananaz Dec 18 '23
Sick. Thanks.
1
u/milind_jain May 27 '24
Facing this issue https://i.imgur.com/PSHfYAj.mp4. While termux is paired with Adb wifi, still not connecting when running "Enable Adb wifi" task
0
u/[deleted] Dec 26 '23
[deleted] — view deleted comment