2011年5月17日 星期二

[Android] StrictMode

New Gingerbread API: StrictMode

StrictMode is a new API in Gingerbread which primarily lets you set a policy on a thread declaring what you’re not allowed to do on that thread, and what the penalty is if you violate the policy. Implementation-wise, this policy is simply a thread-local integer bitmask.

By default everything is allowed and it won’t get in your way unless you want it to. The flags you can enable in the thread policy include:

detect disk writes
detect disk reads
detect network usage

on a violation: log
on a violation: crash
on a violation: dropbox
on a violation: show an annoying dialog

Watching StrictMode


If you’re using penaltyLog(), the default, just run adb logcat and watch the terminal output. Any violations will be logged to your console, slightly rate-limited for duplicate elimination.

If you want to get fancier, turn on penaltyDropbox() and they’ll be written to the DropBoxManager, where you can extract them later with

adb shell dumpsys dropbox data_app_strictmode --print

SystemServer Thread

When boot up, SystemServer Thread will enable StrictMode for debug purpose (if it is not a user build).
And any violations will be logged to dropbox.

沒有留言:

張貼留言