Android, Native OpenGL/OpenMAX, Screen capture - android

Use-case
Mirror Android Screen to PC using USB
Potential (Native) Implementation Approaches
Using Android Open-Source, modify screenrecord for your needs and re-install on your Android device using ADB
Use well known native API such as OpenGL/OpenMAX to capture screen
Discussion
Approach #1 will certainly work ( under the shell account ), however, each time the Android OS is updated, the custom code will need to get updated to keep up with OS changes, with approach #2 the API stay fixed and there is no need to worry about OS changes, the question is whether it is possible to implement Mirroring solely using OpenGL/OpenMAX ?
Questions
Having the above said, what would be the best approach to mirror the android screen via USB ?

The screenrecord that ships with Android 5.0 "Lollipop" can send raw H.264 over ADB. The command line looks like:
adb shell screenrecord --output-format=h264 - | <player>
A few details are on the bigflake page. I've used it to mirror the screen onto a Linux workstation, but unfortunately I didn't save the VLC/mplayer command lines. Some player suggestions are here.
You can try to do uncompressed frames (--output-format=raw-frames), but at decent frame rates that easily overwhelms the ADB connection, even if the screen is tiny.
Source code is here.

As suggested by fadden, I have ended up patching through sreeenrecord disabling the time limitation and adding some code of my own ( enabling ADB over USB routing ), it works, BUT, req maintanance each time the OS is updated, I wish there would have been a way for using the Android Java framework as an ADB Shell Tool as this would considerably reduce the amount of un-documented buttons I am pressing...

Related

Unlock patterns using adb sendevent in Android

After checking some answers:
Is there a way to unlock android phone via adb, if I KNOW the pattern and
Unlock Screen Galaxy Nexus ADB
Im trying to unlock a pattern using adb commands using this script https://github.com/mattwilson1024/android-pattern-unlock/blob/master/unlock.sh (for automation purpose).
Unfortunately the events arent working but I noticed that if I turn on the screen by myself (without using adb shell input keyevent 26) while the script is running, the events work and the pattern unlock.
Could someone explain me why this is happening and if there is another way to unlock patterns? maybe without using events (like I wrote before is for automation purpose, not for a phone that was locked).
Can you please try following capabilities in your code?
We can use capabilities, where we can directly set the unlockType and unlockKey..
unlockType: ['pin', 'password', 'pattern', 'fingerprint']
unlockKey; If you want to draw suppose 'L', then it would be 1478 in key section.
Let me know if this doesn't work.
Appium version - 1.6.4
Reference - https://github.com/appium/appium-android-driver/blob/master/docs/UNLOCK.md
This feature is available in latest appium release.
If you, for some reason, need to use Matt Wilson's script, this is not going to help you, but if your goal is to unlock your phone with a pattern lock via your computer, try Vysor, a Chrome extension that displays your phone's screen (including the lock screen) on your computer, allowing you to enter your lock pattern using the mouse or (if you have a touch display) your finger. For me, it worked fine, as I explain in more detail here.

Running systrace directly from target device

On our boards, USB is not yet up. We are experiencing some frame drop issues while doing video playback and we would like to see whats happening using systrace. Now, I have used systrace, but, with adb and related functionality working.
Is it possible to run systrace directly from the target device so that adb is not used at all? In my opinion it should be, but am not able to find anything useful over web!
Thank you!

Android device mirrored PC

I would like to know if there is any possibility to mirror my android device in real time using android studio? Or anything else that may be used just with an usb or hdmi cable with no required registration?
I tried a couple of little software apps so far but there is a delay consinsting in more than 10 seconds until the action is mirrored on the pc.
Thank you in advance.
I am using Vysor which doesn't need registration, but free version limits the resolution, so it may not be optimal for certain purposes
Edit, I just discovered scrcpy which seems to work way better and even supports copy-pasting from PC to device
Now you can do it with Android Studio https://developer.android.com/studio/preview/features#device-mirroring
Now this feature is available in Android Studio Electric Eel Yay!
Preference > Experimental > Device Mirroring
You can try AllCast. http://www.omgchrome.com/cast-android-mirror-chrome-desktop-pc/
or may be, you can first record your screen and play it back later by using adb shell screenrecord /sdcard/demo.mp4 and pull the file back using adb pull /sdcard/demo.mp4

Is there any command in adb that can damage android phone (without root)?

My question is that is there any chance that any command in adb can damage (both hardware and software) my android phone (my phone is not rooted) and if software can it be recovered by factory reset? It is Micromax A120 and runs on android 4.4.2.
Yes, you can easily mess up your phone if you mess with ADB and don't know what you are doing. This is particularly true if you are using the 'Recovery' options (flashing new software to your device) in particular, if don't do this correctly, there are opportunities to mess things up (particularly if you are not patient, and don't wait for all operations to complete).
For the most part ADB is just a communication mechanism, and if you are careful to do only things you are confident are safe, there is minimal risk.
Bottom line, there is nothing specific about ADB that is risky, but it is a tool, and if mis-used could cause issues. Use it carefully, and you should be fine.
With adb you can delete and copy data on your mobile phone. So you can loose data or damage the Android System. However you have every time the chance to go into fastboot mode and flash a new Android ROM using the fastboot tools. You only can damage your Android device if you flash a corrupted bootloader using fastboot.
So in short form:
ADB: You can delete data but you have everytime the chance to recover your system. (However you can loose all your data!)
Fastboot: You can destroy your Android device if you flash a corrupted bootloader. It's irreparable.

Android: Kernel Debugging with KGDB

I'm trying to do kernel debugging for my Nexus One, and have been following instructions from http://bootloader.wikidot.com/android:kgdb. I was wondering if someone has actually got this to work? And has anyone done a more up to date solution for using KGDB to debug the kernel?
I found this post when I was looking for information of KGDB on Android so, despite it being a few years old, I thought it worth posting a link to some work I did to get this up and running on the Nexus 6.
http://www.contextis.com/resources/blog/kgdb-android-debugging-kernel-boss/
I hope this helps anyone else looking for similar answers.
Edited following feedback (thanks all):
To get this working I had to make a UART debug cable based on this Accuvant blog. This is quite a simple circuit which consists of a FTDI 3.3v basic breakout (available from SparkFun at the time of writing), as well as 4 resistors (2 x 1K Ohm, 1 x 1.2K Ohm and 1 x 100Ohm), and a 4-element Tip-Ring-Ring-Sleeve (TRRS) headphone jack. The resistors are essentially providing a voltage divider to reduce the 3.3v down to something a little safer for your phone. By inserting the audio jack with the other end connected to your circuit board, the audio subsystem recognises that a voltage (~2.8V) on the one of the pins and it knows to provide a UART interface via that cable. The FTDI breakout plugs into your PC via USB and from here you can access console messages via a terminal emulator like minicom. However, you now have a serial interface through the same mechanism and that's what we can use for a KGDB connection.
So at this point some relatively minor changes are required to the Nexus 6's serial driver (msm_serial_hs_lite.c) to support KGDB (specifically, the ability to perform atomic character I/O operations). I just ported these changes from the Linux Kernel mainline code as a chap called Stephen Boyd had done the hard work to the full MSM (Qualcomm) serial driver msm_serial.c. His changes can be found here or just search for "msm_serial: add support for poll_" on Google. The port wasn't difficult and my code can be found on github.
Aside from that you need to be able to build a custom kernel for your N6 which google provides lots of information on. You then need to create a boot image which contains the KGDB modifications in the github repo. I took the stock kernel from https://developers.google.com/android/nexus/images, extracted it (using abootimg -x) and then used the following command to repack it with my custom kernel (zImage-dtb) and additional command line params to ensure KGDB would be loaded and point to my serial port like so:
abootimg -u boot.img -k zImage-dtb -c 'cmdline=console=ttyHSL0,115200,n8 kgdboc=ttyHSL0,115200 kgdbretry=4'
With my boot.img created I could boot into it using the command fastboot boot boot.img, open an adb shell and then trigger a breakpoint in the Android kernel using the command:
echo -n g > /proc/sysrq-trigger
It is worth mentioning for completeness that you need superuser privileges to access /proc/sysrq-trigger so you need to have root.
With the phone halted, and your debug cable connected, launch a version of GDB for ARM on your host PC with your uncompressed kernel as an argument (e.g. arm-eabi-gdb ./vmlinux). Note: I'm running Ubuntu 14.04 and using arm-eabi-gdb from the 'prebuilts' directory in my AOSP source repository. Finally, enter the following commands:
set remoteflow off
set remotebaud 115200
target remote /dev/ttyUSB0
All being well this should immediately break into the kgdb breakpoint (that your write to /proc/sysrq-trigger produced) and you can start debugging.
I know that you've already asked a question at the Android Kernel Dev list and got no answers, but did you search through the archives for posts about kgdb and debugging?: http://groups.google.com/group/android-kernel/search?group=android-kernel&q=kgdb&qt_g=Search+this+group
In particular, you might want to look at this post: http://groups.google.com/group/android-kernel/browse_thread/thread/5233e03391867c98/320beef11e737a62
Here's a few other random links that might be helpful:
http://www.cs.gmu.edu/~astavrou/courses/ISA_673/Android_Debugging/Android_GDB.pdf
http://www.cs.columbia.edu/~nieh/teaching/w4118/ubb/Forum6/HTML/000122.html
http://wiki.ncl.cs.columbia.edu/wiki/AndroidVirt:Guides:Kernel_Debugging
http://source.android.com/porting/debugging_gdb.html
Anyhow, this is an interesting question, and I'm really having a hard time finding anything on it. You might want want to try hopping on IRC sometime (#android-dev or #android-root on freenode) and asking some people there for pointers (please post up what you find here), or maybe asking on the xda-developers Android forums.

Categories

Resources