# adb-auto-enable
**Repository Path**: chmdev/adb-auto-enable
## Basic Information
- **Project Name**: adb-auto-enable
- **Description**: No description available
- **Primary Language**: Kotlin
- **License**: MIT
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2026-02-25
- **Last Updated**: 2026-02-25
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# ๐ง adb-auto-enable
**Automatically enable wireless ADB debugging and switch to port 5555 on every boot - completely autonomous, no root required!**
Perfect for Chromecast with Google TV, Android TV boxes, and any Android device where you want persistent wireless ADB access without manual intervention.
## Foreword
Android 14 introduces enhanced ADB security which disables and randomises the port used after sleep/reboot, breaking my automation setup. Auto ADB Enable automatically re-enables wireless ADB, maintaining remote access for non-interactive devices.
**However, this is likely a temporary workaround.** This app is part of a three-app ecosystem designed to progressively eliminate my ADB dependency:
- **[Auto ADB Enable](https://github.com/mouldybread/adb-auto-enable)** (this app) - Stopgap to maintain ADB access
- **[Display Launcher](https://github.com/mouldybread/DisplayLauncher)** - ADB-free app control via REST API
- **[Android Stream Viewer](https://github.com/mouldybread/android-stream-viewer)** - ADB-free camera display with web configuration
Used together, Display Launcher and Stream Viewer eliminate the need for ADB entirely. Display Launcher handles app launching (including Stream Viewer with specific cameras), while Stream Viewer provides fully web-configurable camera displays. Auto ADB Enable remains available for edge cases, but the long-term goal is complete ADB-free operation.
> [!WARNING]
> **SECURITY WARNING:** This application enables Android Debug Bridge (ADB) on port 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 to port 5555.
## ๐ซ Limitations
- Tested only on CCwGTV. May not work at all on wired devices.
## โจ Features
- ๐ **Fully Autonomous**: Automatically enables wireless debugging and switches to port 5555 on every boot
- ๐ฑ **No Root Required**: Works on non-rooted devices with a one-time pairing via the web UI
- ๐ **Web UI**: Clean web interface at `http://device-ip:9093` for status, pairing, and live logs
- ๐ **Smart Retry**: Implements retry logic with WiFi connection monitoring for reliability
- ๐ **Auto-Permission Grant**: Automatically grants itself WRITE_SECURE_SETTINGS after pairing (no PC required!)
- ๐ **Live Logs**: View real-time logs directly in the web interface with copy-to-clipboard functionality
- ๐ก๏ธ **Background Persistence**: Web server runs in a foreground service, survives app backgrounding
## ๐ฌ How It Works
1. **One-Time Pairing**: App pairs with itself via localhost, storing authentication keys
2. **Auto-Grant Permission**: After pairing, app automatically grants itself WRITE_SECURE_SETTINGS permission via ADB
3. **Boot Detection**: On device boot, service starts automatically (with WiFi monitoring and 60s stabilization delay)
4. **Enable Wireless Debugging**: Enables wireless debugging via `Settings.Global`
5. **Port Discovery**: Discovers the random ADB port using mDNS or port scanning
6. **Self-Connection**: Connects to local ADB daemon using stored authentication keys
7. **Port Switch**: Sends `tcpip:5555` command to ADB daemon to switch to fixed port
8. **Done!**: ADB is now available on port 5555 for external connections - completely autonomous!
## ๐ Requirements
- Android 13+ (tested on Chromecast with Google TV)
- WiFi connection
- No PC or ADB required after initial APK installation!
## ๐ Quick Start
### 1. Installation
Download and install the APK from [Releases](https://github.com/mouldybread/adb-auto-enable/releases), or build from source:
```bash
git clone https://github.com/mouldybread/adb-auto-enable.git
cd adb-auto-enable
./gradlew assembleRelease
adb install app/build/outputs/apk/release/app-release.apk
```
### 2. Initial Pairing (No PC Required!)
1. Open the app or navigate to `http://your-device-ip:9093` in a browser
2. On your Android device:
- Go to **Settings โ Developer Options โ Wireless Debugging**
- Tap **"Pair device with pairing code"**
3. Enter the **pairing code** and **pairing port** into the web interface
4. Click **"Pair Device"**
5. The app will automatically attempt to grant itself permissions!
### 3. Verify Setup
1. Check the web UI status - Permission should show "โ Granted"
2. Click **"Switch to Port 5555 Now"** to test the configuration
3. Check "ADB Port 5555" status - should show "โ Available"
### 4. Test Auto-Boot
Reboot your device:
```bash
adb reboot
```
Wait about 90 seconds (60s boot delay + 30s for configuration), then connect:
```bash
adb connect your-device-ip:5555
```
## ๐ Web Interface
Access the web interface at `http://device-ip:9093` to:
- โ
View system status (permissions, pairing, port availability)
- ๐ Perform one-time pairing (no PC required!)
- ๐ Manually trigger port switch
- ๐งช Test the boot configuration sequence
- ๐ View live logs with auto-refresh and copy-to-clipboard
- ๐ Monitor last boot status and discovered ports
## ๐ ๏ธ Configuration
### Adjust Boot Delay
Edit `AdbConfigService.java`:
```java
private static final int INITIAL_BOOT_DELAY_SECONDS = 60; // Adjust as needed
```
### Adjust Retry Settings
```java
private static final int MAX_RETRY_ATTEMPTS = 3;
private static final int RETRY_DELAY_SECONDS = 15;
```
### Change Web Server Port
Edit `AdbConfigService.java` and `MainActivity.java`:
```java
private static final int WEB_SERVER_PORT = 9093; // Change port
```
## ๐ Troubleshooting
### Permission Not Granted / Auto-Grant Failed
If auto-grant fails, you can manually grant the permission from a computer:
**1. Verify Permission Status:**
```bash
adb shell dumpsys package com.tpn.adbautoenable | grep WRITE_SECURE_SETTINGS
```
You should see:
```
android.permission.WRITE_SECURE_SETTINGS: granted=true
```
**2. Manual Permission Grant:**
If permission is not granted, connect via USB and run:
```bash
adb shell pm grant com.tpn.adbautoenable android.permission.WRITE_SECURE_SETTINGS
```
**3. Common Issues:**
**Issue: Permission Monitoring Blocked the Grant** (OnePlus, ColorOS, Xiaomi devices)
On your Android device:
1. Go to **Settings โ Developer Options**
2. Find **"Disable Permission Monitoring"** and enable it
3. Toggle **USB Debugging OFF and back ON**
4. Try pairing again in the web UI
**Issue: App Was Running When Permission Was Granted**
```bash
adb shell am force-stop com.tpn.adbautoenable
adb shell pm grant com.tpn.adbautoenable android.permission.WRITE_SECURE_SETTINGS
```
**Issue: Permission State Is "Stuck"**
```bash
adb shell cmd appops reset com.tpn.adbautoenable
adb shell pm grant com.tpn.adbautoenable android.permission.WRITE_SECURE_SETTINGS
```
### Boot Configuration Not Running
Check logs in the web UI at `http://device-ip:9093` or via ADB:
```bash
adb logcat -s ADBAutoEnable
```
Look for:
- `"Boot event detected, starting ADB configuration service..."`
- `"Waiting for WiFi connection..."`
- `"Successfully configured ADB on port 5555!"`
### Port Switch Fails
1. Verify permission is granted (see above)
2. Check pairing status in web UI - must show "โ Paired"
3. Try manual trigger via web UI button
4. Check live logs in web UI for detailed error messages
### WiFi Takes Too Long to Connect
Increase the WiFi wait timeout in `AdbConfigService.java`:
```java
int maxWaitSeconds = 120; // Increase to 180 or more
```
### Service Crashes on Boot
Check for foreground service permission errors:
```bash
adb logcat | grep -i "foreground"
```
Ensure `AndroidManifest.xml` has:
```xml
```
### Web Server Not Accessible
The web server runs on port 9093 in a foreground service. If you can't access it:
1. Check that the service is running:
```bash
adb shell dumpsys activity services | grep AdbConfigService
```
2. Verify the device IP address in the app's main screen
3. Try accessing from the same network: `http://device-ip:9093`
## ๐ Project Structure
```
adb-auto-enable/
โโโ app/src/main/java/com/tpn/adbautoenable/
โ โโโ MainActivity.java # Main activity that starts the service
โ โโโ AdbConfigService.java # Foreground service with web server
โ โโโ BootReceiver.java # Boot broadcast receiver
โ โโโ AdbHelper.java # ADB protocol implementation
โ โโโ WebServer.java # NanoHTTPD web interface with live logs
โโโ app/src/main/AndroidManifest.xml
โโโ README.md
```
## ๐ง Technical Details
### ADB Protocol Implementation
The app implements the ADB wire protocol:
- **CONNECT** message with `host::features` service
- **AUTH** signature/token exchange for authentication
- **OPEN** service channel to ADB daemon
- **WRITE** commands like `tcpip:5555` and `pm grant`
Authentication keys are stored in `/data/data/com.tpn.adbautoenable/files/adb_keys/`.
### Boot Process Flow
```
LOCKED_BOOT_COMPLETED โ BootReceiver โ AdbConfigService (Foreground)
โ
Start Web Server (port 9093)
โ
Wait for WiFi (up to 2 min)
โ
Wait for system stabilization (60s)
โ
Enable wireless debugging
โ
Wait 10s for ADB daemon
โ
Discover port (mDNS โ fallback to scan)
โ
Connect to local ADB
โ
Send tcpip:5555 command
โ
Success! (with 3 retry attempts if needed)
```
### Self-Grant Process
```
User Pairs via Web UI (localhost:random-port)
โ
Pairing successful, keys stored
โ
App discovers current ADB port (mDNS/scan)
โ
App connects to localhost:discovered-port
โ
App executes: shell:pm grant com.tpn.adbautoenable android.permission.WRITE_SECURE_SETTINGS
โ
Permission granted autonomously!
```
## ๐ Acknowledgments
- Google, for forcing my hardware to update consequently creating this mess
- [This Home Assistant Issue](https://github.com/home-assistant/core/issues/148359)
- Inspired by various Tasker projects and Magisk modules
- Uses [NanoHTTPD](https://github.com/NanoHttpd/nanohttpd) for embedded web server
- Uses [libadb-android](https://github.com/MuntashirAkon/libadb-android) for ADB protocol implementation