How to make multi-devices dump with AndroidViewClient/dump command? - android

I'd like to compare the screen of my devices (many) so I'm using AndroidViewClient tool to get the hierarchy of my screens with the dump command in a terminal.
However, my devices are all linked with my computer at the same time, and the dump command seem to work on only one device. So when I use the command, I get the dump of the first device in the device list when I use adb devices.
My goal is to compare screens. So what I want is to specify which device I want to use for my dump in the terminal (and then doing it for all my devices to compare).
Is there a solution of this ? because the only solution I found yet is to make an adb -s [device serial_number] shell uiautomator dump, which offer the possibility to chose which device we want to use among those who are attached, but it produce an xml file (and this is why I need AndroidViewClient's dump, because I don't want the xml file).
In other words, is there a way to specify a device with the dump command in a terminal without disconnecting my USBs successively (keep only one device connected at the same time) ?
Thank you very much in advance !

If I understand correctly, you want to dump different devices that are already available through adb.
Getting help you can see that dump accepts an optional command line parameter which is the serialno
$ dump --help
usage: dump [OPTION]... [serialno]
...
You can also take a look at --multi-device option for culebra that can generate tests that run on many devices at the same time.

Related

How to Compare output of a command dynamically in batch program

I want to poll the state of my android device dynamically using adb in a batch file.
I know that the command "adb devices" or "fastboot devices" gives me the the device id of the device in the respective state and are mutually exclusive. I want to put one of these commands in an if, so that I can judge by comparing the output which state my device is in.
I have seen some if usage in batch file in other posts here, but they weren't helpful as I wasn't able to get the desired output.
Linux has a command called watch, which is perfect for what you want to do. You can simply:
watch adb devices
This will refresh the command every 2 seconds (I think?) by default, but the delay is configurable using a command switch.
In Windows, I would probably use something like this answer: https://stackoverflow.com/a/5483958/1003560

ADB Command Weird Behavior

I have a question regarding ADB.
I'm sorry about the title of this question as I really don't know how to put a good title to this.
I'm working with many android devices at the moment, and I noticed that on some devices, the following problem occurs.
Say I want to run a shell script (my_script.sh) that is located in the /data/local/tmp/ folder of the phone.
If I do this:
adb shell 'sh /data/local/tmp/my_script.sh &'
nothing happens on the phone.
If I just go into adb shell (by entering adb shell on a terminal) and when I get this prompt:
shell#android:/ $
and then I type in the following:
sh /data/local/tmp/my_script.sh &
everything works just fine.
This happens on only a few of the devices I have. So I'm not able to figure out what exactly I'm doing wrong.
Here is another piece of information that might help someone. If I don't use the "&" at the end (which means I don't run the script in a background process), everything works as well.
The following code gives the correct behavior:
adb shell 'sh /data/local/tmp/my_script.sh'
I'm completely lost, and I'm hoping someone here can help me out.
Thanks in advance!
UPDATE: So this issue has puzzled me for a while, and I spent quite a bit of time investigating this issue. I've noticed another behavior, say I lock the screen (by pressing the power key) and then issue the command:
adb shell 'sh /data/local/tmp/my_script.sh &'
And then unlock the screen, the script will run fine.
This is really the weirdest thing I've encountered in a long time.
I really hope someone can lend a hand here.
I guess you want to daemonize some program to run in the background. But normally the child process will got killed while the parent is gone. In this case, your adb shell is the parent process.
And this behavior is really different from device to device. I just tried it on my phone and found that "&" didn't take any effect, the shell command is still blocked.
I think a better way to handle it is to use standard daemonize approach of linux. Please refer to:
Write a daemonize native program
How to daemonize a script on a generic linux os

how to manage multiple android emulators in windows?

i'm writing an app on android which will read data from DB or just textfiles, and i'll run it on multiple emulators, each of them has different data.
the question for me is, how can i manage the data in each android emulator programmatically on windows?
you may say that DDMS may help, but it's not programmatically(or something i don't know about DDMS?).
so if i write a management program running on windows to handle my question, what tech. should i use, telnet, ddms or somethingelse? any advise will be appreciated. thank you.
You can address different emulator / device independently by its serial number. The easiest way is to use command line adb.
To see all of your devices and their serial number
adb devices
To send command to specific device
adb -s <serial> <command>
For example to push a file to a specific device sdcard
adb -s <serial> push <file> /sdcard/
More info here
http://developer.android.com/tools/help/adb.html

screenshot via adb in Amazon Kindle Fire HD

Actually, there is no screencap utility out of box in Amazon Kindle Fire HD. Id'like to install it to /system/bin/ via adb to call from the command line (still via adb) at the moments when I need to have a screenshot and logcat is not enough to attach the to bug description.
There are some descriptions how to use screencap utility for such purpose: http://habrahabr.ru/company/intel/blog/152122/
(see
adb shell screencap /sdcard/screen.png
adb pull /sdcard/screen.png screen.png
adb shell rm /sdcard/screen.png
)
However, it seems that my device uses Android 2.3 Gingerbread, so there is no screencap utility out of box. So, the question are 1) Is there a way to push screencap of other Android versions to /system/bin/ 2) where I can download it online?
Other approaches working with adb shell are welcome.
I don't know exactly if this will help you, but I once happened to find out several other ways of capturing a screenshot. From what I know, they do not depend on the screencap but rather on the ADB daemon. All of them require your device to have USB debugging turned on.
I would really suggest trying this simple utility out: http://www.roman10.net/a-program-for-taking-screenshot-for-android-device-from-command-line/ which essentially reimplements the DDMS screenshot functionality without the whole GUI. It automatically writes it on your computer so there's no need for push/pull. It's pure Java so it's a great bonus.
Scroll down to the download section where you can download just the binary and test it out.
Another method would be to use MonkeyRunner described here: http://developer.android.com/tools/help/monkeyrunner_concepts.html. All you need to do is write a simple script which captures the screen, which is shown on the page from the link.
Unfortunately I don't know if android-tools-adb provides MonkeyRunner.
Another tool is Android Screenshots and Screen Capture: http://sourceforge.net/projects/ashot/
It just needs the Android SDK installed and I suspect it runs on the same principle as DDMS or the first program - from Roman10.
Hope that helps!

Android command list

I have many questions about Android command. I do not know where I should start But, anyway, I have put all question related Android commands. Here ;
Is subset of Linux commands come in Android by default ? Or, Are we installing something ?
In system/bin, there are lots of commands. Where can I find their meaning ? I have tried man, but man is not built in.
Can I start and stop application via start and stop command ?
Why cannot I run the reboot from terminal emulator ? The error permission is denied.
NOTE : feel free to reedit the question, if you see meaningless part.
Is subset of Linux commands come in Android by default ? Or, Are we installing something ?
A subset exists by default within the system. Things like ls, cd, mkdir, cat etc... are present. You can gain access to a wider range by installing Busy Box on a rooted device, as stated by Zac.
In system/bin, there are lots of commands. Where can I find their meaning ? I have tried man, but man is not built in.
The ADB Page is a good place to start. That covers many of the basic ADB and shell commands. It states near the bottom:
"For a complete list of commands and programs, start an emulator instance and use the adb -help command."
So you can use adb -help on an emualator or device to see a full list of the ADB and shell commands (note I think this list will be android specific commands only, it won't include things like cd,ls and other basic unix commands).
Can I start and stop application via start and stop command ?
No, it states on the ADB dev page:
start ........ Starts (restarts) an emulator/device instance.
stop ........ Stops execution of an emulator/device instance.
To start an application you'll use the am utility iirc it will look something like am start com.your.packagename It's been a while though, I might have syntax wrong. The instructions are listend if you issue the am command by itself with no params in a shell.
Why cannot I run the reboot from terminal emulator ? The error permission is denied.
The system prevents applications from rebooting the device unless they are signed with the same key as the OS. When you use the terminal emulator you are restricted to whatever permissions that application has declared. The reboot permission is not granted to any third party applications, so it won't work correctly from any terminals. You could probably do it if your device was rooted and you used su though
EDIT:
Here is another good resource that lists more of the shell commands
There are not many Linux commands included in android, however if you are rooted you can easily install busybox which has a large range of linux commands.
You need to have root access to reboot your device via the command line (to prevent any old app being able to do it)

Categories

Resources