How to verify adb connect was successful? - android

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..

Related

ADB auto detect port for adb connect

Everytime I want to connect my adb server to my device, I need to explicitly give the port.
adb connect localhost:<port>
On my case, the port is randomly defined so I have to find it on the interface.
I try to netstat my computer but the port does not appear, except if I adb connect, and just a moment after I adb disconnect. But then it disapear again.
An other thing I thought was to brut force all ports but it takes like an ethernity..
If you have a suggestion I would be glad to read and test it.
Thanks

Android ADB can't ALWAYS see the phone device

I have read all the relative threads about ADB not recognizing devices. My case though is different: ADB sometimes "sees" my phone (Samsung Galaxy) and other times NOT. No matter how many times I kill and restart the ADB service or I disconnect and reconnect the device from/to the PC. Quite an unstable situation here. You know, it's one of these things that drives you crazy. That's why I resorted to your help.
Has anyone had this exact problem and resolved it once for all?
More info:
The PC has never a problem recognizing the device.
I try with both the standard SDK adb.exe and the Universal ADB driver adb.exe.
Either of the above have no problem recognizing the emulator.
Couple things.
1) it's a dumb suggestion but sometimes its as simple as this. Did you try more than one cable?
2) If yes, then try this. try as many times as you have to get it connected since u said "ALWAYS" so it does work sometimes. When it does work, open terminal or command line and run the following commands.
(make sure device is connected when you do this AND you are on the same wifi network)
adb tcpip 5555
then disconnect your phone and run the following command:
adb connect YOUR_LOCAL_IP
do this many times, this is wireless adb connection and if this works, its something with ADB or your computer and not the phone.
Let me know if it works. I might have more ideas depending on what result you get
============ EDIT ============
I believe it's offline because it says 8080. I just did the same with my phone and I get the following:
Try this: disconnect phone physically (if connected) and all other devices and make sure by doing: adb disconnect.
then, do adb kill-server
then, on your phone, go to Developer Options and uncheck USB debugging.
then, right underneath that options, there is Revoke USB debugging authorizations options. select and revoke all devices
then, check USB debugging
then, back on your computer, run adb start-server
then, try reconnecting with the steps I said before. make sure port is 5555
when you run the adb connect command, make sure to add the port at the end.
example: adb connect 10.0.0.15:5555
Hope this works.

ADB - Using adb CONNECT command

I'm trying to make a tool that connects to your android phone wirelessly with the connect command.
I know the command and how to set up the ports, the problem is that you have to enter your ip manually. If i want it to be a tool, it should automatically connect to the right ip for the user's phone.
I've tried using localhost to connect
adb connect localhost:5555
But that does not work. If this is possible, please write a comment!
I'm sorry if i didnt explain it properly. English is not my main language.
You're not entering the command correctly. You should be connecting to the device's ip. adb connect [deviceIP]:5555.

How to make adb server not respond?

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.

adb logcat on a real phone using tcp/ip

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.

Categories

Resources