[Wear OS General] gusano38:
Hey folks,

Just wanted to share something I found that might be useful from time to time: how to send adb commands to android wear directly from your phone without any cables nor an extra PC.

This is a combination from different tutorials, made for different goals, so almost all credit goes to them ;)

This worked from my Nexus 5 (4.4.4 stock, rooted) to a LG G Watch R (5.0.1)... but it should work with any combination as long as, your smartphone is rooted (but this is XDA so it has to be rooted :p)

First thing first, start bluetooth debugging in your android wear device (from the developer menu)

Now from your smartphone, start USB debugging (developer menu too)

At the bottom of the settings in the android wear app you should see a new option "Debugging over bluetooth", turn it on. You should get a message just below:

Host: disconnected

Target: connected

You will also get a permanent notification to remind you that debugging over bluetooth is active.

Disclaimer: su commands are powerful and with great powers comes great responsibility... so pay attention to what you do. In any case, I'm not responsable for any damage incurred to your phone, your android wear device, your cat, your home, your neighborhood, etc...

Open a terminal emulator in the smartphone paired to your wear device, where you can do "su" stuff, and run the following commands:

> su

> export HOME=/sdcard

> setprop service.adb.tcp.port 5555

> stop adbd

> start adbd

> adb devices <--- this should show you your own smartphone (with a emulator-5554, in my case)... you can actually shell into it if you like recursions ;).

SECURITY NOTE: This will allow the adb daemon to listen for tcp/ip connections from other machines connected to your wifi hotspot... I guess it will also allow machines sharing the same 4G cellular network you are using to connect, but what are the odds... In any case, and if I'm not wrong, any android version since 4.3 should give you a message telling you to accept the connection or not.... maybe in airplane mode with just bluetooth activated it would work and it would also be safer.

Continuing in terminal (the typical stuff we know already):

> adb forward tcp:4444 localabstract:/adb-hub

> adb connect localhost:4444

At this point your smartphone should buzz and ask you to allow a connection from your own phone. This time is the real deal, but just in case read carefully the message. It should say "Allow Wear Debugging?", so accept the connection and optionally mark the always accept option.

You will now have two emulated devices:

> adb devices

emulator-5554 device <--- the smartphone

localhost:4444 device <--- the android wear device

you need to specify for now on the target of your adb commands. For instance if you want to have a shell in the android wear device:

> adb -s localhost:4444 shell

That's it. Hope it works for everyone.

Ah! just one thing the value service.adb.tcp.port we set before disappears with a reboot (you can replace the word service with persist if you prefer to have it surviving the reboot... but I do not recommend it).

If you do not want to reboot but you want to disable it, run, as root:

> setprop service.adb.tcp.port -1

> stop adbd

> start adbd

to clean-up, from the terminal and as root:

> adb kill-server

You can also disable the adb debugging from the developer menu.

N.B. 1 . I guess the easiest thing to do would be to put all those commands in a script file and then just run as root:

> sh script_to_adb_wear.sh

N.B.2. I have not tried with fastboot... but that would surprise me if it works.... In any case, and IMHO, fastboot should only be used with the device connected to a computer via usb.