How to Compare output of a command dynamically in batch program - android

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

Related

How to use Android dumpsys framestats

I want to measure the FPS of my Android Augmented Reality app. I am trying to follow the documentation for using dumpsys framestats.
This is my procedure:
connect device (Galaxy Tab S5e) via USB to computer (MacBook Pro)
Launch application
Open terminal and enter adb shell dumpsys gfxinfo <PACKAGE_NAME> framestats
I get results. The documentation says that I should get some CSV data (which I do). Here it is:
Flags,IntendedVsync,Vsync,OldestInputEvent,NewestInputEvent,HandleInputStart,AnimationStart,PerformTraversalsStart,DrawStart,SyncQueued,SyncStart,IssueDrawCommandsStart,SwapBuffers,FrameCompleted,DequeueBufferDuration,QueueBufferDuration,
1,270900288236110,270901404902732,9223372036854775807,0,270901406732543,270901407052751,270901407062751,270901480932022,270901488003689,270901488511137,270901489180876,270901502575459,270901504554157,1520000,1026000,
1,270901416955482,270901500288812,9223372036854775807,0,270901507061241,270901507131709,270901507732074,270901524054574,270901524125251,270901524430720,270901524804834,270901531068480,270901534144522,3249000,1831000,
Firstly, why is there only two rows, if:
"Each line of this output represents a frame produced by the app"
If I wait and then rerun the command, I again only get 2 rows. Sometimes the values have updated, but other times they have not...
The documentation says that I can calculate frame time with:
(FRAME_COMPLETED - INTENDED_VSYNC)
So, I thought I could run the ADB command after say, 1 minute, get out a load of frame times and then graph it, but if I only get out 2 frames at a time... and if rerunning the ADB command does not update the data... how can I measure Frametimes? What am I missing here?
I am writing my bachelor thesis and using this adb command to get framerate. In my experience, the framerate data is updated only when the screen is changed. For example, you have a long list. If you don't scroll it, you only see limited framerate data, but if you scroll it, there will be more framerate data (but the maximum number of frames is 122 )

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

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.

adb shell: can't use the ESCAPE key

I want to use vi when running adb shell. Starting "vi" is easy. However, I found that the ESC key doesn't seem to get through to it, so I can't exit insert mode.
More broadly, it doesn't appear that I'm able to send an ESC character to the adb shell at all. I've scanned the web pretty thoroughly and haven't been able to find anyone with a similar problem (much less an answer).
I'm running VRUFNK1 on a Samsung S4. On the PC end I'm running the "adb shell" command from Cygwin under Windows.
Ideas???
UPDATE: Here's are some possible clues.
The adb shell doesn't seem to be the problem. I can capture ESC in a file running
od -cb > file, so ESC seems to be getting to the program being run under the adb shell.
All commands get echoed in my "adb shell" (as if set -v was on, but it isn't).
I notice that input doesn't seem to get sent to adb shell from my cygwin shell in "raw mode" -- i.e., any text I type gets buffered locally until I hit carriage return -- then the entire line gets sent. I'm not sure why that would make ESC ineffective, but certainly vi doesn't expect to be receiving input in quite that manner and perhaps its an indication of something unusual in my environment.
Similar to #1, bash (Bash X) seems to receive it, although echoing from bash is very strange. I can use ESC to enter "edit mode" in my bash shell (Bash X) to scroll through my history (I've run set -o vi), but the experience is very strange. When I hit ESC,k, nothing changes on the screen but my location in the command history goes up one rung (as it should); subsequent presses of 'k' cause a 'k' to be echoed to the screen (instead of the relevant command from my history list). When I finally hit carriage return, the correct command from my history list is executed (!).
UPDATE 2: Progress…
I tried setting the stty value in the "adb shell" to the same as the ones in my cygwin bash shell and that didn't have any effect.
I also tried this: Avoiding escape timeout issues in vim but it didn't help.
I tried this (by reading in from a file using :so <filename>).
Unfortunately, the commands weren't recognized by "vi" (they are actually "vim" commands).
Partial Solution:
Typing a <cr> immediately after the ESC when in "vi" works -- the ESC is accepted and I can exit the editor. It's awkward, and the editing window is still unusable (as if TERM was set to the wrong value), but this is progress.
Also, things work fine when I ssh in. That shell gets started by the telnet server; similar situation as Terminal Emulator directly on the device. Ssh has its own server which then forks off the shell. In the case of the "adb shell", the shell is forked off by /sbin/adbd -- as far as I can tell, there is simply something unusual about that environment. This is a huge step for me -- at least now I have a way to do full screen editing on the device using my PC (rather than editing directly on the S4's tiny screen). Thanks to Jack Palevich for that suggestion.
I can only think of two things to try at this point:
Try running adb shell against someone's device (but the device must be running root, so that I can run Busybox's "vi") (BTW, the version of "vi" is not the problem -- it runs fine from ssh.)
As someone else to run "vi" in "adb shell" on my device, from their host (preferably someone who has succeeded in running "adb shell" and vi somewhere previously.
I'm starting to think that It Simply Doesn't Work.
UPDATE 3: Info from XDA Developers
I found some relevant posts on the XDA Developers forum. It seems to be the case that people have had problems with this for a long time (since at least 2010). I didn't find any solutions.
XDA Link 1
XDA Link 2
XDA Link 3
There is also a paragraph listing various perceived/proposed adb shell bugs that match my experience, here:
Proposed ADB Shell Bugs
You're right - it simply doesn't work under Windows or Cygwin shell. I found that the simplest way to make it work is to use PuTTYTray.
Check my answer in the linked thread for instructions and additional details.
Another solution: Use Windows PowerShell instead of cygwin. Commands like 'o', 'esc', and ':wq' work nicely here.

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)

How to manually set file or directory timestamp using adb shell? Does anything like unix's touch exist in adb shell?

aafm is a small Python GUI utility that copies files between a computer and an Android device with MTP, using adb as the underneath layer. But as it is right now, the files get the timestamp of when they have been copied, instead of their original timestamp.
It would be great if we could set the last modified date in the device to match the last modified time in the computer.
I've been going through the list of adb shell commands in http://developer.android.com/tools/help/adb.html but so far I'm unable to find anything remotely similar to the classic unix touch command.
Does anything like that exist in this shell?
You can use busybox on android for that purpose. This is one binary acting as replacement (mainly with limited options) of small linux standard programs, e.g. touch. Read this and this
Now I found it is a part of android toolbox binary, but if you can't find it on a phone you can used own built touch binary and use it, source file is here. You just need to upload it on the phone, chmod and delete after using.
If you are talking about copying from host to the Android using ADB, it should use the original modify timestamp. The current code in adbd does a utime(). On some devices the utime() fails (see below). Copying from Android to host over ADB does not even attempt to set any timestamps. I do not know the reason for this omission. On my two devices (2.1 & 4.0) modify timestamp is set on write to Android but not on write to host. On 4.2 devices there is an issue with the FUSE filesystem and not allowing utime();
On devices without a real sdcard (that is, using FUSE) there will be problems doing utime() on a file unless you are root. This gets into the anomalous situation where you can create a file but not alter the timestamps. The only real solution is to make sure that ro.secure=0 or that you are running an insecure version of adbd.

Categories

Resources