Skip to content

Instantly share code, notes, and snippets.

@SuperKenVery
Last active March 23, 2025 14:09
Show Gist options
  • Save SuperKenVery/d2a37b5dfebe6acc2bd9ed92a3c89e04 to your computer and use it in GitHub Desktop.
Save SuperKenVery/d2a37b5dfebe6acc2bd9ed92a3c89e04 to your computer and use it in GitHub Desktop.
Enable wireless adb from shell

[GUIDE] How to enable wireless adb from shell

Why

If, like me, you've installed MagiskSSH and Magisk-Tailscald on your Android device, you might want to enable adb from commandline (ssh) so that you can scrcpy into it.

How

Enable

setprop service.adb.tcp.port 8897  # Specify your desired port here
setprop ctl.restart adbd

Disable

setprop service.adb.tcp.port -1
setprop ctl.restart adbd

Reference

https://github.com/RikkaApps/WADB/blob/7c988730f12fde373cde4bfeee7bf188ebcb2c46/app/src/main/java/moe/haruue/wadb/events/GlobalRequestHandler.java#L34-L37

https://github.com/RikkaApps/WADB/blob/7c988730f12fde373cde4bfeee7bf188ebcb2c46/app/src/main/java/moe/haruue/wadb/events/GlobalRequestHandler.java#L47-L50

How to switch user on Android from commandline

Why

Actually I once borrowed my phone to my girlfriend cuz her phone's battery died (she always forgets to charge it :( ) so I created an account for her, which isn't an administrator. According to Android policy, switching to another user requires the current user's password. She switched from her account to mine and told me that she couldn't use the phone anymore.

I had to gave her my password. Though I changed my password afterwards, I think this should be avoided in the future. Therefore, I installed MagiskSSH and Magisk-Tailscald on my phone, hoping that I could switch user from remote.

Actually I can!

How

# First, list user and obtain user ID
pm list users

# Then, switch to the desired account
am switch-user User_ID

When running pm list users, you may see output like this:

Users:
        UserInfo{0:机主:4c13} running
        UserInfo{10:工作资料:10b0}

Here, 0 and 10 are user IDs. I'm not sure what's 4c13 and 10b0.

This is from here. The answer is really old but I verified that it still works on Android 14. You won't need the current user's password, and you'll be on the lock screen of the target user.

@SuperKenVery
Copy link
Author

Fuck GitHub, I had to add numbers to my filenames to re-order the files 😡

@SuperKenVery
Copy link
Author

For the wireless adb commands, it sometimes may fail, for some unknown reasons... Maybe I just didn't sleep long enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment