0

i need to follow Android IO call from very beginning down to near hardware layer.

  1. What I need is actually nice stack of links to responsible source like in below's example, so a person could easily follow.

It is very simmilar in idea to this StackOverflow unfamous C/C++ function definitions without assembly question.

Let's look at example:

FileOutputStream fos = OpenFileOutput(„filename”, Contex.MODE_PRIVATE)
fos.write(somemeaninglessstring.getBytes());

let's imagine we are more intrested in write, but want to traverse several steps of opening file first. We start at /frameworks/base/core/java/android/content/Context.java + ContextWrapper.java to see that we have

@Override
public FileInputStream openFileInput(String name)

Ok. So moving on to /frameworks/base/core/java/android/app/ContextImpl.java:705/ where we have java.io.FileOutputStream.write(), next - it's base class java.io.OutputStream.write()

public void write(byte[] buffer) throws IOException {
    write(buffer, 0, buffer.length);
}

... and here is where I've stuck.

java.io.* is top level package, OutputStream inherits only after Object, so - how could one find good algorithm to check what JVM does with write() in java.io.OutputStream ?

  1. I was wondering also, if there is anything simmilar to ctags that could speed up process if I'll need to repeat this process, preferably not requiring importing whole branch to Eclipse and so on.
Community
  • 1
  • 1
brainovergrow
  • 458
  • 4
  • 13

1 Answers1

0

Android is open source (http://source.android.com/) so you could just download the source and carry on digging into to the system.

Henry
  • 42,982
  • 7
  • 68
  • 84
  • I'm not sure how this could be helpful Henry. As a matter of fact, I do dig, and it does not really matter if i download Android source or browse online repository. And btw question concerns Java's IO part. I'm guessing there should be a connection between inside of JVM, through JNI write(?) and then, Dalvik like any other linux application would utilise Linux write, which in turn ends up with syscall. – brainovergrow Aug 14 '13 at 07:09
  • OutputStream.write(int) is an abstract method, thus implemented in a derived class, for example FileOutputStream ultimately uses `IoBridge.write(fd, buffer, byteOffset, byteCount);` to write bytes. To follow that further look up the sources for `libcore.io.IoBridge` ... Eventually you will reach the linux syscall. – Henry Aug 14 '13 at 07:24
  • Yes,streams are used by libcore's io subsystem. The problem is - perhaps i'm missing something or my explanation was unclear - how can i think of an algorithm, to allow someone go backwards in those calls, just by browsing code. Perhaps clearer is this: -person looks at java function let's say System.out.println. -can move backwards to observe what compositing layers take part in executing this command, like PrintStream's "out" object, and System (and how exactly data are modified and parsed there). Obvious problem is, that moving back, it's not always trivial to find "super" class IoBridge. – brainovergrow Aug 14 '13 at 07:41
  • As long as you are in Java, the IDE can help a lot. When crossing implementation layer boundaries (Java -> native code -> kernel) it becomes more difficult. Sometimes a debugger can help to find out the stack of function calls. I still don't quite get what kind of algorithm you are after. – Henry Aug 14 '13 at 07:56
  • Algorithm or perhaps better phrased "methodology of looking" for source files that should be shown to user by each next layer, moving backwards from any function call in Android, through Java, JNI, *libc and up to HW specifics. Something like backtracking callstack but in source, and backwards...now that i've written this as such i feel like it sounds crazy :) – brainovergrow Aug 14 '13 at 08:15