Low level Android Debugging - android

Is there a way to trace through function calls at the lowest levels of the Android system? Right now when I debug in Eclipse, it goes through the source files that are located inside the frameworks folder, but is it possible to go even lower? For example show what functions are being called from the libcore folder. I am also interested to find how it communicates with the linux kernel at the bottom of the layers. Is there a way to do this?
Thanks

The lowest level you can go with eclipse debugger if you add all framework source folders is up to JNI calls (the layer that interfaces with native code).
If you want to go lower you need to use gnu gdb debugger, here you will find a guide on how to use it.

http://android.opensourceror.org/2010/01/18/android-source/
Try this :)

In all cases mentioned below, first you need to be root on the mobile phone.
At each process level, you can use "strace" (available from android SDK which u can copy into the phone).
http://tthtlc.wordpress.com/2011/02/06/analysing-the-softkeyboard-in-android/
http://tthtlc.wordpress.com/category/android/page/5/
At the kernel level, depending on the phone's ftrace config flag (but most phone's kernel config followed that of Google ASOP):
http://tthtlc.wordpress.com/2011/12/29/playing-with-ftrace-option-on-my-xperia-arc-s/

I guess the easy way would be compiling your own version of android from https://android.googlesource.com and making it debuggable.

Related

FUSE (Filesystem in Userspace) support on Android

I'm trying an app that require to enable a cloud based file system to my device. For this I've to have FUSE support in my Android device . I'm using Android version 4.4.2 on a Asus tablet. However I searched a lot but couldn't find some satisfactory answer to ensure that whether Android support Fuse. Thus I have few question as below ,
1.According to my search result When I run cat /proc/filesystems on an app (Terminal Emulator for Android) that provides Linux terminal I found the result of cat shows "Fuse" there . Is that mean my system support Fuse interface to allow install an user space file system ?
I also found in some forum either Fuse should come as built inside kernel or it should be as fuse.ko module under /system/lib/module . But my system doesn't contain fuse.ko hence does it mean I don't have fuse ?
In short, my question is how to ensure FUSE on android device ? I'm a beginner in Android programming so any help is much appreciated . Thanks in advance.
Modern versions of Android utilize Fuse internally, for example to implement the emulated External Storage.
However, Android is locked down and so neither 3rd party applications, not in most cases the human user, are allowed to add additional filesystems.
For stock Android the only choice will be to implement file-system-like operations within application code, creating a private API that replicates basic file operations, without actually using any files. Anywhere in the code you are writing or porting and need to access one of the remote "files", you would substitute your API for the actual file one. A good example of this would be Android assets - they look a lot like files and have many similar operations, but at runtime they actually are not files but an Android-unique storage mechanism.
Anything else would require modifying Android away from stock configuration (ie, root hacks, etc).
To check what your version of Android on your device supports, download a terminal emulator, and from the command line, run the following snippet of commands minus the parentheses...
"cat /proc/filesystems"
And scroll through the results looking for fuse. This will be a list of supported filesystems weather it be compiled into the kernel or loadable module.

I have sdk. Is ndk neccesarry for eclipse

I have eclipse Kepler and I am having "Android-Sdk-Windows" files. But I cannot able to make an android project in eclipse.. Do i need NDK necessary.
I already have experience with opening project with just "sdk" and eclipse.. But this times How can i enter the "sdk" path instead of "ndk".
Or Teach me what is "sdk" and "ndk"
i tried eclipse->preference->android-> But i can only see NDK location.
Native methods are platform-specific code. They are usually written in languages such as C or C++ and contained in libraries(dll's). It is possible to create a hybrid Java application that benefits from such libraries.
Reasons for Using Native Methods
Gaining access to special capabilities of your device or or Android
OS
Gaining extra speed
Gaining access to a large body of existing legacy code
Typically, good use cases for the NDK are CPU-intensive applications such as game engines, signal processing, and physics simulation
The major disadvantage of native methods is that you won't have cross-platform capability.
What is Android NDK
The Android NDK is a companion tool to the Android SDK that lets
you build performance-critical portions of your apps in native code.
It provides headers and libraries that allow you to build activities,
handle user input, use hardware sensors, access application resources,
and more, when programming in C or C++. If you write native code, your
applications are still packaged into an .apk file and they still run
inside of a virtual machine on the device. The fundamental Android
application model does not change.
Now if you don't know what native code is, then probably you don't need to use native code. Android NDK documentation explains this well:
..., you should understand that the NDK will not benefit most apps. As
a developer, you need to balance its benefits against its drawbacks.
Notably, using native code on Android generally does not result in a
noticable performance improvement, but it always increases your app
complexity. In general, you should only use the NDK if it is essential
to your app—never because you simply prefer to program in C/C++. When
examining whether or not you should develop in native code, think
about your requirements and see if the Android framework APIs provide
the functionality that you need.
Yo do not need the ndk, in order to build an android project. If you are having difficulties with eclipse, I would suggest using Android Studio unless you are dead set on eclipse. I use both, and strongly prefer to use Android Studio whenever I can.
If you decide to stay with eclipse, it is as easy as downloading the ADT plugin by putting the url in the input box under Help->Install New Software, launching and downloading the sdk from the Android sdk manager, restarting eclipse, and then starting a new Android project. Hopefully you do not have to do anything to configure java or anything else.
The ndk is a way of accessing things from a lower level, in order to bypass certain things, or squeeze more performance out of a phone for highly intense operations, or finally to be able to port c/c++ code from different project. i.e. You can write a Opengl ES game in c and reuse most the code for web, ios, and android this way. But that goes beyond the scope of the question, and this answer.
Firstly you should ensure you have installed ADT plugin .

Android API from Go

I know that Go programs can be compiled for Android.
How can I use Android specific API, like getting GPS coordinates or opening a URL with the default browser, from within a Go program?
I'm afraid it's hardly possible at the moment. In the "Meet the Go Team" I/O sessions, the guys from the Go team stated that they have no plans to add Android support to Go.
What we have now is just a compiler for ARM architecture. Unfortunately, this is pretty much useless for real Android apps, though such programs can be launched from the command line on Android devices.
Most of the Android framework is written in Java, so to interact with it your code should be compiled to a *.so libary, that will be loaded and called via the JNI interface. And it's not possible with the current Go compiler (gc, not sure about the gccgo).
Maybe you will be able to make bindings to the Android NDK API with cgo, that would allow you to create applications in Go since API level 9 (Android 2.3)
UPD: You can now use JNI from Go and create java bindings automatically with golang.org/x/mobile package. In Go 1.4 it's still experimental, but there are plans to include it into Go 1.5 release. The package also provides bindings for GL, audio and user input (hopefully they would also add iOS support and that would be compatible for Android and iOS one day). Anyway this package is mostly oriented at writing games in Go, rather than using Go as a replacement for Java on Android.
Take a look at my answer to Android App from Go programming language. The goandroid project allows you to create Android apps in Go through the NDK.
(Disclaimer: I'm the author of goandroid)
Edit: As mentioned in the comments, Go 1.5 adds official support for Android apps in pure Go or as a mix of Java and Go. iOS is also expected to arrive in time for the final 1.5 release. See https://github.com/golang/mobile for more details.
GO 1.4 doc says, "Go 1.4 can build binaries for ARM processors running the Android operating system. It can also build a .so library that can be loaded by an Android application using the supporting packages in the mobile subrepository"
There is package app option in "golang.org/x/mobile/app" library that lets you write Apps for Android (and eventually, iOS).
Step 1: Create a platform independent GUI library using Golang that uses OpenGL to draw and an intelligent event and data-binding system to write the apps in. Any software using OpenGL is going to be more-or-less portable. Essentially, re-write Kivy in Golang.
Step 2: Create introspection/reflection based wrapper for using Java classes similar to PyJNIus (also a Kivy project).
Step 3: Lots more hard work, because there is a lot to do to get to the level of Kivy
Step 4: Profit

OpenGL ES source files

I am trying to build the OpenGL SO lib from android sources (libGLESv2.so) and i would like a little bit more understanding of the internal mechanism of Android OpenGL ES and the flow.
Please correct me where i am wrong:
I know that in windows a developer includes gl.h and static link to OpenGL32(64).lib (which in turn dynamically link to OpenGL32.dll (probably there is a way to dynamic linke to OpenGL32.dll by the developer but that's not important).
The developer is exposed to the declaration of OpenGL API's but the implementation which i assume to be HW dependent.
The same scenario, Android: assuming developer import .opengl.GLES20 and calls the following method: GLES20.glTexEnvf(....
I would like to know what's going on behind the scenes in android (maybe Linux is better for an Android beginner).
the implementation which reside in opengl/java/android/opengl/GLES20.java source calls the native C function glTexEnvf which unlike windows we have it's implementation which reside in opengl/libagl.
Is it true?
In any case what is the GLES2_dbg library in /libs/GLES20_dbg? i can see there some kind of debug implementation with python scripts... are they to compile OpenGL debug version?
What are the .in files and gl2.cpp file in /libs/GLES20?
Where are the HW calls? does each GPU vendor sends his libGLESv2 implementation for HW calls as i saw the libGLESv2_adreno200.so in my xperia arc?
Please help me understand the flow. If you have a link which explain this structure even in Linux it will be great.
In Windows opengl32.dll contains both a software rasterizer fallback and so called trampolines into the OpenGL-ICD shipping with the GPU driver.
The opengl32.lib ist not really a library but a cross reference for the linker to add entries into the executable that make the OS dynamically link the program against the DLL at runtime.
On Linux in the current implementation the libGL.so ships with the graphics driver and contains the vendor specific implementations. The linkers used in *nix systems don't rely on an extra crossreferencing .lib but can take the information directly from the .so
On Android the libGLES you see is only a kind of placeholder to make linking possible. But ultimately the GPU vendor provides the proper library, which drops into the place where the phony libGLES resided.
The .in files are nothing special in particular. They are input files used by configure and build systems to build source files from a template (the .in file) with fields filled in by configuration values.
thanks for the quick answer, i did a little more digging and as i saw here:
Missing OpenGL drivers on Android emulator,
further explanation.
What i understand now is the libagl is pure SW implementation.
In that case the libhgl is actually the GPU vendor implementation.
I also understood that libEGL opens (found it in the code - Loader.cpp) the libGLESv2....
So i will ask 2 more question:
libGLESv2 only dynamically link to the HW lib or the libEGL does that? (found something on EGL - loader.cpp which seems like dynamically link OpenGL API's)
2.So when i call an OpenGL API i goes trough libEGL (since there is the dynamic binding)? and from there to libGLESv2 ?
thanks a lot for your help
it starting to make sense now

Android Linux system call List

Does anyone know where I can find the list of system call that can be used in Android Mobile phones? I guess that looking to the kernel should work, but I cannot find any *.h or *.c with the declaration of them.
Best regards
You primarily want section 2 of the linux kernel manual pages.
Very little is unique to Android, the few gotchas being in the android docs (no sys-V IPC, AF_INET sockets won't work unless you are in the network group, etc). Most of the android additions are drivers (Binder, etc) and novel usage patterns (for example of user IDs) rather than actual syscalls.
If you actually need the syscall numbers you can find them in bionic/libc/SYSCALLS.TXT within the sources
You may want to check the Bionic sources for the system call list. Since, Bionic is the C-Library, that Android works off.
Try here
It is located in SYSCALLS.TXT file inside of libc directory under certain Android version. Example above is system call on Android 11.

Categories

Resources