mouldybread/adb-auto-enable
حول
Automatically enable wireless ADB and switch to port 5555 on Android device boot - no root required. Seamless wireless debugging on Chromecast with Google TV and other Android devices.
أدوات التطويرالنمو المقاس للنجوم
- خلال 24 ساعة
- +٧
- خلال 7 أيام
- +١١
- خلال 15 يومًا
- +٢٣
- خلال شهر
- جارٍ جمع السجل
تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.
README.md
الأصلAutomatically enable wireless ADB debugging and switch to your chosen port (default 5555) on every boot, no root required!
Android 14 introduces enhanced ADB security which disables and randomises the port used after sleep/reboot, breaking automation setups. Auto ADB Enable automatically re-enables wireless ADB, maintaining remote access for non-interactive devices.
[!WARNING] This application enables Android Debug Bridge (ADB) on your configured port (default 5555), which provides remote access to your device with full system privileges. While ADB connections require RSA key authentication (users must accept the connection on first pairing), once a computer is authorized, it has permanent unrestricted access to install applications, access all data, execute shell commands, and take complete control of your device without further prompts. Additionally, the RSA authentication prompt is vulnerable to overlay attacks where malicious apps can trick users into authorizing connections. This app should ONLY be used on isolated or trusted networks (such as a home network behind a firewall with no port forwarding) and NEVER on public WiFi, guest networks, or any network you do not fully control. Exposing ADB to the internet or untrusted networks can result in complete device compromise if an attacker gains authorization, either through social engineering, overlay attacks, or physical access to previously paired computers. Use this tool only on devices you own and ensure your network is properly secured with a firewall blocking external access. The web interface on port 9093 is protected by a 6-digit access code but is served over plain HTTP, so use it only on a network you trust (see Web Interface and API).
Quick Start
Requirements:
- Android 14+ (tested on Chromecast with Google TV and modern Android builds)
- A Wi-Fi connection: It may be possible to use a dummy wifi connection to start the service, see issue #24
- WRITE_SECURE_SETTINGS: The app asks for this permission itself after pairing. Some OEM builds block the request, so it fails or doesn't persist. Without it the app can still set up ADB at boot if wireless debugging is already on. See Secure Settings Permission and issue #25.
- Users must approve Android's "allow wireless debugging on this network" prompt once, with "Always allow on this network". Without it, the boot-time enable is reverted.
1. Installation
Download and install the APK from Releases, or build from source:
git clone [https://github.com/mouldybread/adb-auto-enable.git](https://github.com/mouldybread/adb-auto-enable.git)
cd adb-auto-enable
./gradlew assembleRelease
adb install app/build/outputs/apk/release/app-release.apk
[!IMPORTANT] After installing the APK, you must open the app on your device once (via Settings → Apps → See All Apps → ADB Auto-Enable) to start the background web server before you can access
http://your-device-ip:9093. The app's main screen also shows the 6-digit access code that the web interface asks for.
2. Initial Pairing
- Navigate to
http://your-device-ip:9093in a browser and enter the 6-digit access code shown on the app's main screen on the device. - On your Android device:
- Go to Settings → Developer Options → Wireless Debugging
- Tap "Pair device with pairing code"
- Keep the "Pair device with pairing code" screen open on your device. Enter the pairing code and pairing port into the web interface.
- Click "Pair Device".
3. Verify Setup
- (Optional) Click "Switch Target Port Now" in the web interface to test the configuration manually.
- (Optional) Wait 30 seconds and check status — should show "✓ Available".
- Reboot your device and wait 30-60 seconds (service initialization + 30s system stabilization delay), then connect to your configured port:
adb connect your-device-ip:5555
Secure Settings Permission
The app uses Android's Secure Settings permission (WRITE_SECURE_SETTINGS) to turn Wireless Debugging on at boot and to stop Android from expiring its ADB authorization. After pairing, the app asks for the permission itself, through its own local ADB connection.
Some device makers refuse that request unless an extra developer-security control is allowed first. On Xiaomi/HyperOS, for example, Settings → Developer options → USB debugging (Security settings) may have to be on before the grant is accepted. That is Xiaomi's label, not a universal Android setting: other devices use a different name or a different control, such as a permission-monitoring, enterprise-security or device-management setting.
What the app does without it
| Situation | What happens at boot |
|---|---|
| Permission granted | Wireless Debugging is turned on as usual |
| Permission missing, Wireless Debugging already on | The app skips turning it on and carries on with port discovery and the port switch |
| Permission missing, Wireless Debugging off | The app stops at once, without retries. Last Boot Status reads Failed - Secure Settings permission unavailable and wireless debugging is off |
Without the permission the app cannot turn Wireless Debugging on for you, and it cannot keep Android from revoking its authorization.
Asking again
Once the device is paired and the permission is missing, the web interface shows a Secure Settings Permission card with the Wireless Debugging state and a Request Permission Again button. After allowing the control your device needs, press it. The page reports the real result: granted, refused by the device, not paired, or Wireless Debugging port not found. From a script, use POST /api/permission (see API.md).
You can also request the permission from a trusted computer while the device is connected over USB debugging:
adb shell pm grant com.tpn.adbautoenable android.permission.WRITE_SECURE_SETTINGS
If the device rejects that command too, the restriction is enforced by the system and the app cannot get around it without root or system-level integration.
Port Switching (Optional)
By default the app switches ADB to a fixed TCP port (5555 unless you change it) after every boot, so adb connect your-device-ip:5555 always works. If you only want Wireless Debugging enabled at boot, and are happy to use its own port, you can turn port switching off.
| Port switching on (default) | Port switching off | |
|---|---|---|
| Wireless Debugging enabled at boot | Yes | Yes |
Port discovery and tcpip switch |
Yes | No |
| Connect with | adb connect your-device-ip:5555 (or your target port) |
adb connect your-device-ip:<port>, using the port shown under Settings → Developer Options → Wireless Debugging |
Android picks a new Wireless Debugging port at random, so with switching off you need to read the current port from the device. The web interface also shows it in the Last known port box (see The Last known port box).
Changing the setting
- On the device: use the Switch ADB to legacy TCP port on boot switch on the app's main screen.
- In the web interface: use the Legacy ADB Port Switching card.
- Over HTTP (send the access code with every request, see Web Interface and API):
# turn port switching off (use enabled=true to turn it back on)
curl -X POST -H 'X-Access-Code: 123456' -d 'enabled=false' http://your-device-ip:9093/api/switchport
GET /api/status includes switchPortEnabled.
What changes when it is off
- After boot the app enables Wireless Debugging and checks that Android kept it enabled. It then looks up the Wireless Debugging port, for display only, and stops. The status line reads
Success - wireless debugging enabled (port switch off). The lookup never changes the port and never changes whether the boot counts as successful. - Save & Switch and Switch Target Port Now are disabled in the web interface, and
/api/switchreturnssuccess: falsewithout doing anything. Save Port still stores the target port for when switching is turned back on. - Turning the setting off does not undo a switch that has already happened. ADB stays on the target port until
adbdrestarts, for example on reboot. - On TCL devices, the step that applies the
AUTO_STARTpermission when the service starts connects to the target port, so it may not complete while port switching is off.
The Last known port box
The Last known port box in the web interface shows the port ADB is on, or the last port the app knew about:
| The box shows | Meaning |
|---|---|
Discovery in progress |
The boot configuration, or a manual switch, is running and no port answers yet |
| A port number | That port accepts connections now. With port switching on this is normally your target port; with it off it is the Wireless Debugging port |
<port> (not responding) |
The app knows this port, but nothing is answering on it now. The number is kept so you can see what it was |
Not found |
The last run could not find a port |
Not discovered yet |
Nothing has run since install |
The page checks every 5 seconds, so it can take a few seconds to catch up. The same information is in GET /api/status as currentPort, portState and lastKnownPort (see API.md).
Web Interface and API
The web interface (http://your-device-ip:9093) and the HTTP API need a 6-digit access code. The device generates it and shows it on the app's main screen. Generate new code on that screen replaces it and logs out every browser and script.
- Browser: enter the code on the login page. The browser stays logged in for a year, or until you log out or generate a new code.
- Scripts: send the code in an
X-Access-Codeheader, or log in once withPOST /api/loginand reuse the session cookie.
curl -H 'X-Access-Code: 123456' http://your-device-ip:9093/api/status
Wrong codes are rate limited. Five wrong codes from one address lock that address out for a minute, and each further lockout doubles the wait, up to an hour. Every endpoint, with examples, is documented in API.md.
Good to know:
- Use the device's IP address in the URL. Requests that use another hostname, or that come through a reverse proxy, are refused.
- The server uses plain HTTP, so someone who can watch your network can read the code. Use it on a network you trust.
- To keep the web server off, turn off Enable Web Interface on Boot on the app's main screen.
Light and dark theme
The web interface follows your browser's light or dark setting. The button at the top right of the page switches between Auto (follow the browser), Light and Dark. The browser remembers the choice for this address, and it applies to the login page too. The choice is stored in the browser only, not on the device.
Upgrading from a version without the access code
- Open the app once and note the access code on its main screen.
- Add the code to every script, Home Assistant setup or other tool that calls the API (the
X-Access-Codeheader). /api/switchand/api/testnow requirePOST. They used to acceptGET./api/webservernow requiresenabled=trueorenabled=false. It used to treat a missing value astrue.- Call the device by its IP address, not by a hostname.
Troubleshooting
Pairing fails
If pairing fails please open an issue and include your device, version, logs from the web-based gui and/or ADB logs:
adb logcat "adbd:V ADBAutoEnable:V *:S"
Boot Configuration Not Running
Check logs in the web UI at http://device-ip:9093 or via ADB:
adb logcat "adbd:V ADBAutoEnable:V *:S"
Look for:
"Boot event detected, starting ADB configuration service immediately...""Step 0: Immediately enabling wireless debugging setting...""Waiting for WiFi connection...""Successfully configured ADB on port 5555!"
Without the Secure Settings permission, step 0 is skipped and the log says so instead (see Secure Settings Permission).
Port 5555 Unreachable After the Device Sleeps
If adb connect your-device-ip:5555 works after a reboot but fails after the device has been asleep or in standby for a few hours, the device is most likely powering down its network stack. The app only configures ADB at boot, it does not change the device's power policy.
Wake the device (for example with the remote), then try again:
adb connect your-device-ip:5555
If it connects after waking, try these:
- Disable any battery, energy-saving or background-restriction setting for the system network components and this app (on some Android TV builds this is under Settings → Apps or Settings → Device Preferences → Power/Energy).
- Disable any Wi-Fi power-saving or "turn off Wi-Fi in standby" option if your device has one.
- If your device supports it, use wired Ethernet for the connection you use to reach 5555, and keep Wi-Fi connected so wireless debugging can still start at boot.
Web Server Not Accessible
The web server runs on port 9093 in a foreground service. If you can't access it:
- Check that the service is running:
adb shell dumpsys activity services | grep AdbConfigService - Verify the device IP address on the main app screen.
- Ensure you are accessing from the same network subnet:
http://device-ip:9093. 403 Unrecognized Host headermeans the URL uses a hostname or an IP that is not the device's current IP. Use the IP address shown on the main app screen.401means the access code is missing or wrong. The code is on the app's main screen. After a429, wait the number of seconds in the message or theRetry-Afterheader.
How It Works
- One-Time Pairing: App pairs with itself via localhost, storing authentication keys.
- Permission Request: After pairing, the app asks for
WRITE_SECURE_SETTINGSthrough local ADB. Whether the device grants it is shown in the web interface (see Secure Settings Permission). - Boot Activation: On device boot,
BootReceiverinstantly launchesAdbConfigServiceto satisfy Android 14+ foreground service launch rules. - Early Setting Enforcement: With the permission, writes
adb_wifi_enabled = 1toSettings.Globalbefore any network or sleep delays. Without it, this step is skipped. - Stabilization & Network Wait: Service waits for an active Wi-Fi/Ethernet IP and allows a 30-second system stabilization period.
- Port Discovery: Discovers the randomized ADB port using mDNS or a 64-thread parallel socket sweep (
32768–60999). Skipped when port switching is turned off, except for an mDNS lookup that only feeds the Last known port box. - Self-Connection & Switch: Connects to the local ADB daemon (127.0.0.1 loopback -> device LAN IP fallback) and sends the tcpip:<target_port> command. Skipped when port switching is turned off.
- Done!: ADB is available on your target port for external connections!
Technical Details
Project Structure
adb-auto-enable/
├── app/src/main/java/com/tpn/adbautoenable/
│ ├── MainActivity.java # Shows the web UI address, access code and on-device switches
│ ├── AdbConfigService.java # Foreground service executing boot sequence
│ ├── BootReceiver.java # Instant boot broadcast receiver
│ ├── AdbHelper.java # Wire protocol implementation & port switcher
│ ├── NetworkUtils.java # Live IP resolution & connectivity checks
│ ├── AccessControl.java # Access code, sessions and brute-force limits
│ ├── PrefsAccessStore.java # Stores the access code and session hashes
│ ├── RequestGuard.java # Host, Origin and request size checks
│ └── WebServer.java # NanoHTTPD web server, API and live logs
├── app/src/main/assets/web/ # Web UI served by WebServer (index.html, login.html, style.css, app.js, login.js, session.js)
├── app/src/main/AndroidManifest.xml
├── API.md # HTTP API reference
└── README.md
Authentication keys are generated locally and stored in /data/data/com.tpn.adbautoenable/files/.
Boot Process Flow
LOCKED_BOOT_COMPLETED / BOOT_COMPLETED → BootReceiver
↓
Start AdbConfigService Foreground Service (Immediate)
↓
Start Web Server (port 9093)
↓
Step 0: Write adb_wifi_enabled = 1 immediately (only with the Secure Settings permission)
↓
Step 1: Wait for WiFi connection (up to 60s)
↓
Step 2: Wait for system stabilization (30s)
↓
No permission and Wireless Debugging off? Stop with a clear status, no retries
↓
Port switching off? Confirm Wireless Debugging stayed enabled, look up its port for display, then stop
↓
Step 3: Discover randomized ADB port (mDNS → 64-thread socket sweep fallback)
↓
Step 4: Connect to ADB daemon (127.0.0.1 loopback → Device LAN IP fallback)
↓
Send tcpip:<target_port> command
↓
Success! (with 3 retry attempts if needed)
Acknowledgments
- Google, for forcing my hardware to update consequently creating this mess
- This Home Assistant Issue
- Uses NanoHTTPD for embedded web server
- Uses libadb-android for ADB protocol implementation
استكشف مشاريع مشابهة ومرتبطة
جارٍ التحميل…
