Can I dump logs from an android phone over wifi (using tcp/ip) using adb? adb connect can be used, but it needs some server to be running on the phone (at 5555 port). How do I start this server?
Or the only way to get logs from a phone is by connecting it as a USB device?
Install adbWireless on your phone. Run the application and click on the big button (you cannot miss it!). It will activate ADB over Wifi and display the URL to use to connect to it with the adb command.
On your computer, run the adb command with the connect parameter. The usage for adb says:
connect <host>[:<port>] - connect to a device via TCP/IP
Port 5555 is used by default if no port number is specified.
Obviously the computer and the smartphone must be on the same Wifi network.
zero4
All you are trying to do is drop adb logcat command on the device & send output stream to a remote location. I would suggest, read this post about how to run shell commands in your app.
The summary is
Run "adb logcat"
Collect Output Stream of the command in a file on device
& Finally post that file to your local server OR Manually pull that file from device
The post contains link to everything you are looking for.
Android is very paranoid when it comes to network access. Without root access, you can't really run any servers, just clients. In short, without root, look at the answer from 100rabh.
If you do have root, you could either open up your network stack for incoming connections on port 5555, or you could hack adb to do the inverse connection (that is, connect to your client). The latter is way more secure and shouldn't really be to hard to do. (I haven't looked at the code for a while, though.) The communication bits for all parts of adb is handled in one and the same library, for all three parts of adb (server, daemon and client).
By the way, what you refer to as a server on the phone is really the adb daemon.
Related
I'm attempting to connect to multiple devices in the run up to a live event using the ADB connect command after setting them all to run the daemon on the default TCPIP port (5555). This was working absolutely fine back in our main office and ADB retained a connection to every device, allowing us to push commands to individual devices by IP address and create Python scripts to semi-automate everything. As soon as we got set up on-site, however, I've been getting a weird error when attempting to connect to some devices:
> adb connect 10.20.30.400:5555
Connected to 10.20.30.400:5555
> adb connect 10.20.30.401:5555
Already connected to 10.20.30.401:5555 (as 10.20.30.400:5555)
This only seems to occur on the PC I'm using, not others, and no amount of adb kill/start-server or adb disconnect seems to resolve it. I also weirdly get the same error when attempting to use different ports for each device, so that's not a viable solution.
I guess my question is: why does this issue occur and is there something cached on the PC that might cause this type of problem to persist (since it's only occurring on the PC we're using).
I am debugging an Android app that usually crashes when I plug into an Arduino it is supposed to be communicating with. Consequently, I need to get a wireless connection to the device's logcat, which is what brought me to ADB over TPC as seen on the Android developers webpage.
The recommended process is:
C:\Users\User> cd AppData\Local\Android\sdk\platform-tools
C:\Users\User\AppData\Local\Android\sdk\platform-tools> adb kill-server
C:\Users\User\AppData\Local\Android\sdk\platform-tools> adb start-server
* daemon not running; starting now at tcp:5037
* daemon started successfully
C:\Users\User\AppData\Local\Android\sdk\platform-tools> adb tcpip 5555
restarting in TCP mode port: 5555
C:\Users\User\AppData\Local\Android\sdk\platform-tools> adb connect 10.20.5.160:5555
However, the typical response is:
unable to connect to 10.20.5.160:5555: cannot connect to 10.20.5.160:5555: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)
I could not consistently get a connection between a PC and mobile device. Over the course of three weeks using several networks and devices, I could only connect two times out of an agonizing many attempts.
I have dug deep into the posted questions on stackoverflow and tried literally every recommended alteration to getting an adb connection, from using an Android Studio plugin to forwarding ports to trying several other ports to toggling my device's internet. I still could not get a connection more than a fraction of a percent of the time.
When I look at the network state of my device after adb tpip <port>, I find no evidence of the device trying to look for a connection:
C:\Users\User\AppData\Local\Android\sdk\platform-tools> adb shell
j3ltevzw:/ $ netstat -n
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 ::ffff:10.20.5.160:4214 ::ffff:173.194.196.188: ESTABLISHED
udp 4288 0 adb shell ip -f inet addr show wlan0:68 10.20.5.1:67 ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
... ... ... ... ... ...
... ... ... ... ... ...
Also, when I try to ping my device, I usually get:
C:\Users\Benjamin\AppData\Local\Android\sdk\platform-tools> ping 10.20.5.160
Pinging 10.20.5.160 with 32 bytes of data:
Reply from 10.20.5.232: Destination host unreachable.
Reply from 10.20.5.232: Destination host unreachable.
Reply from 10.20.5.232: Destination host unreachable.
Reply from 10.20.5.232: Destination host unreachable.
Ping statistics for 10.20.5.160:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)
What I am looking for is a process or file that can be run and consistently open a tcp adb connection, or at least explain what about my setup is invalid. Ideas?
Update 1:
I have started a bounty on this question. I feel like the problem with the ADB software used to make connection for debugging is two fold:
adb tcpip <port> does not always invoke the mobile device to listen on the specified port
adb connect <ip>:<port>, I am assuming, is not given permission by the network to connect; I am not a networking expert, but the fact that pinging a device returns "destination host unreachable" seems a little off
I will award the first person to find a successful solution. Seeing that having an ADB USB connection gives a user access to both the mobile device's and host's terminal, there really is no excuse for a connection not to be able to be made between the two.
Update 2:
I have recently had more success in connecting to the ADB as well as receiving successful pings at my school network. Note at this network connects are insecure and the host and mobile devices where on separate subnetworks. Any idea why these conditions would work over my secure network at home that uses only one subnet?
Try starting from scratch and setup ADB-over-tcp following steps below:
Turn off USB debugging on your device and turn it on again (just to reset).
Kill the ADB server on your PC using adb kill-server
Connect your device to the PC using the USB cable and type adb devices. This will automatically restart the ABD server again.
Enter adb tcpip 5555 on your PC terminal. This will switch the adbd daemon on your device to tcp-ip mode.
Disconnect your device from USB. Now connect your device to the same wireless network as your PC, either the same wi-fi or use your phone as a hotspot.
Determine your phone's ip. You can do this in the wi-fi settings on your phone. If you are using your phone as hotspot, then generally your ip should be 192.168.43.1 (not required but most of the time it's the same).
Connect to ADB via tcp using adb connect <IP>
This should hopefully connect your device to your pc via tcp-ip.
I found a solution that works for me, but I feel it shouldn't necessary and it may not applicable for everybody else with these issues, so its still not quite what I was aiming for.
Anyways, after seeing riyaz-ali suggest what an IP address I should be for using a mobile hotstop through a phone, I realized any network complications would be solved if I was the network, so I connected my mobile device to the mobile hotspot on my laptop.
Instant ping responses and immediate ADB connection with the popularly suggested commands.
Just found myself in the same situation. Had no problem yesterday but today couldn't connect.
Solution was simple, I realized that today I'm connected to VPN which obviously makes me belonging to a different network.
So, disconnecting and connection to the same Wi-Fi solved the trouble.
I'm using Android tablet communicating with a USB device through USB port, the tablet only has one usb port, so I use adb wifi as my debug tool. However, when I connect adb through WIFI, the connection won't keep long(only a few minutes us usually), how to keep the adb wifi connection online all the time?
Another question, is it possible to use USB HUB to connect the tablet with both USB flash-drive and my computer, and keep adb running?
Many thanks!!!
After lots of unsuccessful attempts,I have noticed that turning Allow ADB debugging in charge only mode specification on , solved the problem . It makes the device online and accessable over wifi to ADB.
You can find it under Developer options section.
Here is what I found out from researching everywhere and developing on my own for more than a week.
Q1. adb service often crashes if it is not doing any executions for a long long time.
A1. calling adb commands time to time keeps adb server online.
Q2. wifi connected device sometimes disconnect.
A2. Before you check your wifi on the connected device, check the wifi that your ADB server is running on. Ping to google and if it is well connected, ping to the device.
Wireless can disconnect on its own and even wired connection is sometimes disconnected. so calling "adb connect ..." when the device is not already connected is necessary. You could do this easily by saving "adb devices > device.txt" and query out whether your expected wifi is on the list. If not, connect again..(do this in another thread).
Q3. wifi connected device is sometimes offline.
A3. This is because by TCP/IP connection your ADB server is now on Time_Wait stance. The last connection was interrupted that the next connection is now offline because the last connection is not completely shut down. You can either manually disconnect/connect your device's wifi or restart TCPIP connection by ex) "adb tcpip 5555"
If you want to do this automatically, you are going to have to disconnect/connect your device's wifi programmatically.
Leave any other questions and I can answer on the comments.
When connection is lost and adb devices shows device is offline, like this:
prompt> adb devices
List of devices attached
192.168.1.1:5555 offline
then adb disconnect IP followed by adb connect IP will often work:
prompt> adb disconnect 192.168.1.1
disconnected 192.168.1.1
prompt> adb devices
List of devices attached
prompt> adb connect 192.168.1.1
connected to 192.168.1.1
prompt> adb devices
List of devices attached
192.168.1.1:5555 device
Use adb over wi-fi without any third-party apps. Follow the steps.
Connect device via USB
Open your terminal and check your device is listed with adb devices command
Type adb tcpip 5555 and enter (or use another port instead of 5555)
Plug out your USB cable. You don't need it anymore.
Take your Android phone and go Settings/About/Status
Check the IP address part. Let's say your IP address is 192.168.x.y
In your terminal, write the command adb connect 192.168.x.y
Now, you have connected your device via wi-fi.
You can see your device in adb devices
Enjoy it! :)
This seems like an issue with your wifi. As a precaution, just keep the terminal open and whenever you need to test just press the 'UP arrow' key to get to previously ran adb connect "<ip>" command.
I tried many ways but this one worked out for me:
force the display on and of in a loop would keep the device online
adb shell input keyevent 224
timeout 2
adb shell input keyevent 26
timeout 58
this turns the display on every minute for 2 seconds
So, I'm using Scrcpy and Adb to wirelessly connect to my Phone(for developing Flutter Apps) and since the screen wasn't staying awake even by Scrcpy --stay-awake command.
I had to change Lock Settings=>Lock Screen => Sleep, and settings to Never Sleep.
I am writing a bash script to connect to a device via adb and then manipulate files. I prompt the user for an IP address to connect to, and then connect using adb connect $IP. However, I want to verify that the device was successfully connected, and abort the script if it was not.
I am thinking I would accomplish this with something like adb connect $IP | cat, and then check the output for the words "unable to connect" (I am fairly new to bash scripting, so this might be pretty basic). How would I write this in my script?
Another way to do this would be using the command "adb devices", which only lists connected devices and outputs nothing when there's no device connected. So you can take advantage of that. If you're not sure how to do it, read this.
Of course, if there are other devices connected, that would be problematic. But I'm assuming you take for granted that there are no other devices. In case you'd want to take this into account, you can just check "adb devices" output before and after..
We have test suite where adb clients connect to multiple android devices.
Our test suite raises these requests to connect, get device state and run applications in it.
I would like to simulate a scenario where adb server hangs.
I tried issuing "adb kill-server" but any adb request from client starts the adb server.
Is there anyway we can stop the adb server from listening to adb client requests ?
Of course there is a long way of compiling adb service and changing the code our self.
But any easy way to get this done?
Do you need to still have a connection (that doesn't respond to commands), or is it fine to kill the connection altogether? Sounds to me like killing the connection would be fine since you say that you tried adb kill-server.
In that case, how about trying to connect to the device in TCP/IP mode without having set up the adb server to listen on a network port? I.e. something like:
adb tcpip 12345
Another suggestion would be to actually disable adb interface totally in the device. While this may or may not stop the adb server, you would still get your desired result i.e no connection for adb clients.
The way this could be done is that on a ROOTED device, do
adb shell
su
echo 1 > /sys/class/android_usb/f_adb/on
This one is what I could do on an HTC Vivid which I have on hand. For other devices, the paths might be different but they should all be similar. Once your reboot the phone, adb starts working again.