How to access adb directly from Android app? - android

Is it possible to communicate with the Android Debug Bridge (ADB) from inside an app if the service has been loaded through USB?
Here is the use case: I can take a screenshot of the framebuffer through ADB on an unrooted phone with no problem, but it is a little slow to transmit the entire raw buffer over USB, especially if I want to take more than a frame every 2 seconds. What I would like to do is access the framebuffer from inside an app on the phone which can then either transmit it over Wifi or do some compression first. ASL doesn't work on Jellybean (they shut down the loophole to install native services on /data/local), so I would just like to connect to the ADB service via some socket or whatever and issue the framebuffer request that way.
I am ok with having to connect via USB to load the ADB service, but once connected, I would like to do processing on the phone itself before transmission. And it must work on unrooted phones.
Is this possible?

Oneliner:
$ adb shell screencap -p \| gzip -c \> /mnt/sdcard/s.png.gz; adb pull /mnt/sdcard/s.png.gz;

Related

Adnroid-TV tcp ADB & USB-ports unusable

I want to use ADB on my Adnroid-TV over Wifi. It works like a charm, but there is main downside: although just using ADB over TCP/Wifi, the USB-Ports seem to get unusable. This especially means, that time-shift on the TV is not usable, as no USB-storage is detected anymore.
Is there a way to use ADB over Wifi and have the USB ports still functional? Can I configure the ADB server? Is there another way/app to control the TV via Wifi without loosing USB-functionality?
Regards
SEB

What's the best way to capture packets sent and received by my own android app?

I'm a developer of a VOIP calling app who's trying to troubleshoot connectivity issues.
I'd like to ship something in production that uploads pcap traces of it's own calls - particularly ones that drop, have high amounts of noise, or other nastiness.
There seem to be external apps (some of which require root) for capturing the network traffic of all apps - but no library that I can embed in my app and ship to help me debug.
Is there an easy to use solution for this?
I reccomend you to use Charles (especially when you use https): https://jaanus.com/debugging-http-on-an-android-phone-or-tablet-with-charles-proxy-for-fun-and-profit/
1. Wireshark
Run Wireshark on your laptop and setup your laptop as a hotspot. Connect your device to your laptop's hotspot, then run. Wireshark will capture all packets.
2. ADB
adb root > remount > shell
$su > tcpdump -w /sdcard/tcp > [CTRL-C] to stop > exit
adb pull /sdcard/tcp

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.

24/7 packet capture in Android using tcpdump

I would like to get packet level data traffic captures (.pcap) in Android during a week (in several files if possible).
I thought that I could use tcpdump via Shark, however I find that the capture stops after some time. The biggest packet capture I got is around 40MB. I found out that tcpdump stops/crashes when changing the network interface. For example, when the phone is connected to 3G, when I run tcpdump from Shark I can see the process of tcpdump running until I switch on WiFi.
In the Galaxy S2, when connected via WiFi I have the following interfaces (got by using netcfg in adb shell): lo, svnet0, usb0, sit0, eth0. When I connect via 3G, I get pdp0 instead of eth0.
Is there any way that I can run tcpdump 24/7? Or any way to check when it is running and if it stops make it run again from a Java app? Checking the process of tcpdump or something like this maybe? Or monitoring the status of the network and running tcpdump every time the network is changed?
I had a look to: ReadLine on TCPDump-Buffer sometimes blocks until kill tcpdump , but it does not completely solve my problem.
I am using rooted devices.
How about trying tPacketCapture application ( works with non-rooted devices)
Android OS 4.0
Free
https://play.google.com/store/apps/details?id=jp.co.taosoftware.android.packetcapture
If you have rooted device then use SimplePacketCapture instead of tPacketCapture.
tPacketCapture creates a vpn that can break your voip application.
I'v tried as follow to see what's going on about tcpdump after alternating network interface.
1.open wifi run tcpdump-arm
2.run ps|grep tcpdump-arm
3.close wifi and open mobile interface
4.run ps|grep tcpdump-arm
I've found that when alternating the network interface on the mobile phone, the tcpdump-arm process is still working, but it captures no packets.
I think you need tcpdump to keep capturing even when the network interface changed.
You can catch the connectivity change broadcast as the tutorial of google says at first.
Then, you should run "killall" to kill the tcpdump processl
At last, restart the tcpdump process, if you don not specify an interface, it will listen on the newly opened interface.If you would like the tcpdump to return quickly, you can add "-l" option as the answer in TCPDump-Buffer sometimes blocks until kill tcpdump implies.

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