This is an automated archive made by the Lemmit Bot.
The original was posted on /r/tasker by /u/Lord_Sithek on 2023-12-18 08:38:52.
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!
DOWNLOAD THE PROJECT FROM TASKERNET
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: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:
-
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; fi
3. Create new folder for needed files
Create new folder on your sdcard to store files needed for extracting open wireless debugging port:
/sdcard/Documents/nmap
4. Create scripts
(a) create a directory for Tasker scripts
Open Termux and issue the following command:
mkdir -p .termux/tasker
(b) create a script for ADB pairing
In Termux, type the following command to create adb_pair.sh script:
nano .termux/tasker/adb_pair.sh
Copy and paste the text from the following link into terminal:
Save the script by selecting CTRL
(in Termux) and then pressing x
; confirm by pressing y
and Enter
.
© create a script for ADB connecting
In Termux, type the following command to create adb.sh script:
nano .termux/tasker/adb.sh
Copy and paste the text from the following link into terminal:
Save the script by pressing CTRL
(in Termux) and then pressing x
; confirm by pressing y
and Enter
.
(d) create a script for nmap 1st command
In Termux, type the following command to create nmap1.txt script:
nano .termux/tasker/nmap1.txt
Copy and paste the following text into terminal:
nmap -T4 $1 -p 30000-49999 | awk "/\/tcp open/" | cut -d/ -f1 > /sdcard/Documents/nmap/nmap.txt
Save the script by pressing CTRL
(in Termux) and then pressing x
; confirm by pressing y
and Enter
.
(e) create a script for nmap 2nd command
In Termux, type the following command to create nmap2.txt script:
nano .termux/tasker/nmap2.txt
Copy and paste the following text into terminal:
nmap -T4 $1 -p 30000-49999 | awk "/\/tcp open/" | cut -d/ -f1 >> /sdcard/Documents/nmap/nmap.txt
Save the script by pressing CTRL
(in Termux) and then pressing x
; confirm by pressing y
and Enter
.
(f) create a script for cat command
In Termux, type the following command to create cat.txt script:
nano .termux/tasker/cat.txt
Copy and paste the following text into terminal:
cat /sdcard/Documents/nmap/nmap.txt | sort | uniq -u > /sdcard/Documents/nmap/nmap1.txt
Save the script by pressing CTRL
(in Termux) and then pressing x
; confirm by pressing y
and Enter
.
5. Import the project into Tasker
Download link above
6. 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 Volume Up
button to make pairing. 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 (no. 41) in Enable ADB WiFi
task.
BOTTOM NOTE
Perhaps there is a way to achieve this more easily or even to simplify the flow I created. Also I could pack all things in one huge task, but I decided to split the flow to separate tasks in order to keep it more clear.
FYI, I’m not a programmer, just a Tasker user determined to achieve his goal and taking advantage of the work of others ;)) So 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/Alive_Tart3681, u/ihifidt250, u/The_IMPERIAL_One and u/plepleus for useful ideas I utilized here.