Replicate "adb tcpip" copy / restart adbd without root - android

I've researched a lot about adbd and adb. I'd like to replicate the "adb tcpip 5555" command by doing the following:
I open up the adb shell via cmd (I'm using Windows 10 and a Samsung S5 Android 6.0 for testing purposes) and then I enter:
setprop service.adb.tcp.port 5555
stop adbd
start adbd
Whenever I enter one of those commands, the output (in the next line) is just the command that I just entered and does not give any further information. Checking with
getprop service.adb.tcp.port
returns 5555 though. The adbd service does not seem to restart however, as entering
adb connect ip-of-S5
results in
unable to connect to ip-of-S5:5555
Pinging works though, so the ip/connection is not a problem. (Just like adb tcpip 5555 works as well.)
In case this helps, here is some further information:
getprop | grep adb
[init.svc.adbd]: [running]
[persist.sys.usb.config]: [mtp,adb]
[ro.adb.secure]: [1]
[service.adb.root]: [0]
[service.adb.tcp.port]: [5555]
[sys.usb.config]: [mtp,adb]
[sys.usb.state]: [mtp,adb]
Is there any way to get to know how the orginal adb tcpip command works internally? It doesn't need root, so it should be possible to do it manually as well, right?
Thank you very much!
Best regards

Related

Trying to setup ADB wireless, stuck at "adb tcpip 5555"

I used to be able to setup wireless ADB no problem (plug in, adb tcpip 5555, adb connect ), now it gets stuck indefinitely during the "adb tcpip 5555" command. Wired adb still works fine, so does setting up wireless ADB through apps in play store, just not via cmd. Between wireless working and now not working, I did a bunch of things so any of them may or may not be the problem:
1) Reformatted computer (Same OS)
2) Redownloaded the SDK needed for Android Development
3) Went from ParanoidAndroid to GPE on my HTC One.
Anyone have any idea what the problem is?
You can emulate what apps do with these steps on your device with root and android terminal emulator:
$ adbd stop
$ setprop service.adb.tcp.port 5555
$ adbd start
Then use adb connect XXX.XXX.XXX.XXX where XXX.XXX.XXX.XXX is your ip address found from:
$ ifconfig wlan0 | awk '/inet addr/ {print $2}' | cut -d: -f2
You can check if your connection is establed using netstat | grep 5555. You should see a tcp entry with your ip address and port for adb connectivity.
If your device is rooted then it is very simple to establish a wireless connection, you don't even need a USB cable. Download this app from Google Play https://play.google.com/store/apps/details?id=com.ttxapps.wifiadb&hl=en
It worked for me at least, and as can be seen from the app rating it works for almost all.
-----Enter the command adb kill-server at command prompt-----
C:>adb kill-server
-----Enter the command adb devices-----
C:>adb devices
List of devices attached
daemon not running; starting now at tcp:5037
daemon started successfully
DeviceID device
-----DeviceID is the unique ID of connected device-----
-----Enter the command adb tcpip 5555-----
C:>adb tcpip 5555
restarting in TCP mode port: 5555
-----will see the response as given above -----
-----Enter the command adb connect 1.1.2.2-----
-----1.1.2.2 is the mobile device IP-----
C:>adb connect 1.1.2.2
connected to 1.1.2.2:5555
-----will see the response as given above -----
-----Now u can use 1.1.2.2:5555 ID as wireless to connect device-----

Rebooting a device when adb is connected over tcpip

I have connected an android device over tcpip using adb connect <ipaddress>. I am able perfrom all operations of adb on this devices.
However when I issues a command adb -s <ip>:5555 reboot, I see that prompt simply hangs and reboot is not being performed on the devices.
Is this a known limitation of adb over tcpip?
Are there any other ways to issue reboot commands in such cases?
Thanks in advance
Command adb -s :5555 reboot is incorrect, adb -s <IP Address>:<5555> reboot is correct.
If your device IP is 172.16.7.123, use the following.
$ adb connect 172.16.7.123
Lets say your list of devices show the following
$ adb devices
List of devices attached
172.16.7.123:5555 device
0554e0700a67240d device
The correct way to reboot the device using adb is
$ adb -s 172.16.7.123:5555 reboot
After issuing the above command, your prompt will hang since the adbd daemon is killed on the device.
To return it to normal, use adb disconnect 172.16.7.123 on another prompt and it will return to normal.

How to restart adb from root to user mode?

Basic question on ADB.
adb root restarts adb as root. But what i want is to restart it back to user after some time.
I tried the following :
adb kill-server
adb start-server
doesnt work..
ps -A -> noted the process number of adb and killed it.. even this did not work. Finally i am restarting my device. Is there any way i can come back from root adb to general adb?
Thank you.
If you used adb root, you would have got the following message:
C:\>adb root
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
restarting adbd as root
To get out of the root mode, you can use:
C:\>adb unroot
restarting adbd as non root
adb kill-server and adb start-server only control the adb daemon on the PC side. You need to restart adbd daemon on the device itself after reverting the service.adb.root property change done by adb root:
~$ adb shell id
uid=2000(shell) gid=2000(shell)
~$ adb root
restarting adbd as root
~$ adb shell id
uid=0(root) gid=0(root)
~$ adb shell 'setprop service.adb.root 0; setprop ctl.restart adbd'
~$ adb shell id
uid=2000(shell) gid=2000(shell)
Try this to make sure you get your shell back:
enter adb shell (root). Then type below comamnd.
stop adbd && setprop service.adb.root 0 && start adbd &
This command will stop adbd, then setprop service.adb.root 0 if adbd has been successfully stopped, and finally restart adbd should the .root property have successfully been set to 0. And all this will be done in the background thanks to the last &.
I would like to add a little more explanation to #user837048's answer. on my OSX Yosemite and Galaxy S3 which is rooted and using firmware CyanogenMod 11 and KitKat I have done the below proceedings to Enable and Disable root prompt.
Please make ensure below
On your system
Make sure you have installed Android SDK and you have set paths to binary files. type which adb on your shell. It must give you somewhat result.
$ which adb
/Applications/Android Studio.app/sdk/platform-tools/adb
On your Mobile
Settings > Developer Options> Android Debugging = ON
Settings > Developer Options> Root Access = Apps and ADB
If you don't see Developer Options in your settings, Goto Settings > About Phone. Scroll down to Build number and tap there 7 times. I know its crazy. But believe me it works :D
Connect your phone via USB Cable.
type on your computer's terminal
$ adb shell
you will see a prompt similiar, If any prompt has been shown on your mobile, to trust the connection, tap 'Always Trust' and 'OK'
shell#m0:/ $
now type
shell#m0:/ $ id
uid=2000(shell) gid=2000(shell) groups=1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats) context=u:r:shell:s0
See you are not root
Now exit from shell, which will fall back to computer's prompt
shell#m0:/ $ exit
Now activate root
$adb shell
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
root#m0:/ #
Wow.. you are root
root#m0:/ # id
uid=0(root) gid=0(root) context=u:r:shell:s0
I tried many solutions to go back to normal non root prompt. But didn't worked except #user837048's solution.
root#m0:/ # stop adbd && setprop service.adb.root 0 && start adbd &
[1] 32137
root#m0:/ #
$
This might exit you from Adb prompt to normal prompt. Now connect again.
$ adb shell
shell#m0:/ $
Well.. You are Non root
For quick steps just check summary. If interested to know details, go on to read below.
adb is a daemon. Doing ps adb we can see its process.
shell#grouper:/ $ ps adb
USER PID PPID VSIZE RSS WCHAN PC NAME
shell 133 1 4636 212 ffffffff 00000000 S /sbin/adbd
I just checked what additional property variables it is using when adb is running as root and user.
adb user mode :
shell#grouper:/ $ getprop | grep adb
[init.svc.adbd]: [running]
[persist.sys.usb.config]: [mtp,adb]
[ro.adb.secure]: [1]
[sys.usb.config]: [mtp,adb]
[sys.usb.state]: [mtp,adb]
adb root mode :
shell#grouper:/ # getprop | grep adb
[init.svc.adbd]: [running]
[persist.sys.usb.config]: [mtp,adb]
[ro.adb.secure]: [1]
[service.adb.root]: [1]
[sys.usb.config]: [mtp,adb]
[sys.usb.state]: [mtp,adb]
We can see that service.adb.root is a new prop variable that came up when we did adb root.
So, to change back adb to user from root, I went ahead and made this 0
setprop service.adb.root 0
But this did not change anything.
Then I went ahead and killed the process (with an intention to restart the process). The pid of adbd process in my device is 133
kill -9 133
I exited from shell automatically after I had killed the process.
I did adb shell again it was in user mode.
SUMMARY :
So, we have 3 very simple steps.
Enter adb shell as a root.
setprop service.adb.root 0
kill -9 (pid of adbd)
After these steps just re-enter the shell with adb shell and you are back on your device as a user.
This is a very common issue.
One solution is to kill adb server and restart it through command prompt. Sometimes this may not help out.
Just go to Window Task Manager to kill adb process and restart Eclipse.
Will work perfect :)
i've been with this issue using elementary OS loki. For like one day and i solved it restarting the adb using this command:
./adb kill-server
and
./adb start-server
You need to be in the Sdk folder >Platform Tools
Now, restart your phone this will restart all the process in your phone.
And that's how i fixed it.
if you cannot access data folder on Android Device Monitor
cmd
C:\Users\bscis\AppData\Local\Android\sdk\platform-tools
(Where you located sdk folder)
C:\Users\bscis\AppData\Local\Android\sdk\platform-tools>adb shell
generic_x86:/ $
C:\Users\bscis\AppData\Local\Android\sdk\platform-tools>adb kill-server
C:\Users\bscis\AppData\Local\Android\sdk\platform-tools>adb start-server
* daemon not running. starting it now at tcp:5037 *
* daemon started successfully *
C:\Users\bscis\AppData\Local\Android\sdk\platform-tools>adb root
C:\Users\bscis\AppData\Local\Android\sdk\platform-tools>
working fine.....

Android - adb tcpip error

I want to connect to the Android device using adb over the network. I am familiar with How can I connect to Android with ADB over TCP? and with https://developer.android.com/guide/topics/usb/index.html and follow the guidelines. Specifically, I did the following:
# adb kill-server
# adb tcpip 5555
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
restarting in TCP mode port: 5555
# adb connect 192.168.1.101:5555
unable to connect to 192.168.1.101:5555:5555
Due to the last error, I also tried
# adb connect 192.168.1.101
unable to connect to 192.168.1.101:5555
I also tried to restart the device itself, but it did not help.
Any reason why it does not work?
Update: To clear any doubts, I am sure that this is my device internal IP address.
I've been having the same issue with my unrooted device. And contrary to popular belief it seems that adb tcpip <port> requires either an emulator or a debug build or root privileges; at least according to the source code.
master branch: https://github.com/android/platform_system_core/blob/master/adb/adb.c#L898 look at should_drop_privileges which prevents https://github.com/android/platform_system_core/blob/master/adb/adb.c#L966 adb_main to open a TCP/IP socket connection.
In older branches the logic for identifying the privileges of adbd were in adb_main itself. See: https://github.com/android/platform_system_core/blob/froyo-release/adb/adb.c#L860
So, to further prove that adbd won't enter TCP/IP mode (even though adb tcpip gives out no errors), look at the following:
adb shell getprop | grep 'ro.secure\|debuggable\|qemu', output for my device:
[ro.secure]: [1]
[ro.debuggable]: [0]
This does not meet the conditions of being able to get a secure value of 0 in adbd, since I'm not running an emulator (which needs TCP/IP by default), I'm not running a debuggable build of Android, and I'm not root.
Furthermore if you issue an adb shell netstat command you'll see that there's nobody listening on port 5037 or 5555 or whatever else you supplied to the tcpip command as expected from an adbd running in TCP/IP mode.
Hope this helps, good luck!
The ability to restart adbd using tcpip transport can vary from device to device. Without knowing exactly which device you're using it's very difficult to know the exact cause.
I tested "adb tcpip 5555" on a Galaxy Nexus (takju) running 4.2.1 and found it to work. I also tested on a couple other devices and those did not work.
I managed to get it to work using root access on a Motorola Droid 3. Note that ro.secure=1 and ro.debuggable=0 still. I simply by manually set service.adb.tcp.port" to "5555" as such:
devbox:~/droid3$ adb shell
shell#cdma_solana:/$ getprop | grep 'ro.secure\|debuggable\|qemu'
[ro.secure]: [1]
[ro.debuggable]: [0]
shell#cdma_solana:/$ su -c 'setprop service.adb.tcp.port 5555'
shell#cdma_solana:/$ exit
devbox:~/droid3$ adb tcpip 5555
restarting in TCP mode port: 5555
devbox:~/droid3$ adb connect 172.16.0.14
connected to 172.16.0.14:5555
devbox:~/droid3$ adb -s 172.16.0.14:5555 shell
shell#cdma_solana:/$
Although I specified 5555 when running "adb tcpip" it gets ignored by the device. It seems that this particular device does not have the required access to set the "service.adb.tcp.port" property without root.
Similarly, you can go back to USB as such:
shell#cdma_solana:/$ getprop | grep adb
[persist.service.adb.enable]: [1]
[ro.sys.atvc_allow_all_adb]: [0]
[persist.adb.tcp.port]: []
[init.svc.adbd]: [running]
[service.adb.tcp.port]: [5555]
shell#cdma_solana:/$ su -c 'setprop service.adb.tcp.port ""'
shell#cdma_solana:/$ exit
devbox:~/droid3$ adb -s 172.16.0.14:5555 usb
restarting in USB mode
devbox:~/droid3$ adb shell
shell#cdma_solana:/$
The reasons that this might not work on other devices vary.
On the Galaxy Nexus I tested, the shell user is able to set the "service.adb.tcp.port" property. It's not clear why this differs at this time.
Interestingly it seems the droid3 will not continue to listen on USB if you enable TCPIP. However, the Galaxy Nexus will.
Hope this helps..
PS. See also: How can I connect to Android with ADB over TCP?
I also met same scenario as your, TCPIP setup succeseed, but adb connet failed. I finally found it's my network problem, the ping also failed under that scenairo.
After i made the ping works, the adb connect works as well. So, my suggestion is to check your network environment.
Hi there I know this is an old question but I was having the same problem. I am not sure it is the same case for you but the problem for me was that I was connecting my Android device through a USB expansion, as soon as I connected the Android device directly to the USB port in my MAC it worked.
Just to clarify try to connect the Android device directly to the computer or try switching the USB port.

Getting Error while configuring ADB

Trying to configure ADB so that I can debug it via wifi, I have checked on Google but not getting proper resolution.
Tell me what to enter in port address, device ip.
Moreover setprop service.adb.tcp.port command is running when i give space between set and prop, bit confuse...
Seeking for help
I got the following article, and wanted help in the same context.
disconnect device from usb then tell it to listen on 4455
adb tcpip 4455
restarting in TCP mode port: 4455
connect to the device using a specified ip:port. my device is using wifi
adb connect 192.168.1.103:4455
connected to 192.168.1.103:4455
now do normal adb commands over tcp
adb shell
when your done, you can put it back in USB mode
adb usb
restarting in USB mode
Help me
These are commands for the shell of the android device, not for the host system.
Type adb shell to get the device's shell and then enter them. If you get back to the windows shell prompt you are in the wrong place.
However those commands may not be effective on a secured device anyway.
setprop is an Android command and is meant to be used in a terminal after su on the device (you can do adb shell setprop ... but when you adb shell stop adbd you'll loose your device connection). The easier way if already connected via USB is adb tcpip 8600 and then adb connect IP_OF_PHONE:8600 -- but this will only work if adb shell will get you a root prompt (starts with # and not $). Be aware that anyone on your wifi network can access your device!

Categories

Resources