I am investigating behavior of android's View traversals and measure cache,
using the AOSP source code and emulator.

I would like to emit debug log messages from each of the functions
View.measure(), View.layout(), View.draw(),
from all processes in which they are called.

Sounds straightforward, right? But I haven't found a mechanism that works reliably, yet.

What I tried:

1. The standard logging mechanism: java.util.Log (and view using logcat).

FAIL: Drops messages at random when there are too many of them.
2. Creating and appending to a file in directory
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY\_DOWNLOADS).

FAIL: This only works for some processes (those with WRITE\_EXTERNAL\_STORAGE
permission, presumably).
3. Creating and appending to a file in directory view.getContext().getCacheDir().

FAIL: The call to getCacheDir() fails in system\_process, with:
"java.lang.RuntimeException: No data directory found for package android".
4. Creating and appending to a file in directory view.getContext().getExternalCacheDir().

FAIL: This seems to work for all processes except system\_process,
in which getExternalCacheDir() returns /storage/emulated/0/Android/data/android/cache,
but attempting to write to a file in there gives AccessDeniedException.
5. Creating and appending to a file in directory view.getContext().getExternalFilesDir(null).

FAIL: Same result as (4), except the directory name ends with "files" instead of "cache".
6. Creating and appending to a file in /data/local/tmp.

FAIL: Gives AccessDeniedException in all processes.

How can I do this logging??

I'd be interested in concrete solutions along any of the following lines:

* Hack AOSP source to keep java.util.Log from dropping messages
* Write an alternative logging daemon, which doesn't drop messages
and must be made available during system startup (so that it will be available to processes such as system\_process and com.android.systemui).
* Just find a
directory/file that system\_process is allowed to write to
 (I think that's the only process for which I couldn't find such a file)
* Hack AOSP source to make it so system\_process has
permission to write to some file.