diff options
author | Brad Fitzpatrick <bradfitz@android.com> | 2010-10-28 15:08:33 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-10-28 15:08:33 -0700 |
commit | ed82725f0ee4c8a06b03828d5855bda245828d20 (patch) | |
tree | bb7a9c6b099adbe27ffb9f8c51f2d3504f61bf2d | |
parent | 673ce4e2a65146eb1fc11b77c30e6d4624c275fd (diff) | |
parent | 71678ddcc45d9cd4557f3bed8bba5382bf36b68b (diff) | |
download | frameworks_base-ed82725f0ee4c8a06b03828d5855bda245828d20.zip frameworks_base-ed82725f0ee4c8a06b03828d5855bda245828d20.tar.gz frameworks_base-ed82725f0ee4c8a06b03828d5855bda245828d20.tar.bz2 |
Merge "StrictMode: optimize common case (just dropboxing)"
-rw-r--r-- | core/java/android/os/StrictMode.java | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java index 9786959..40aceb3 100644 --- a/core/java/android/os/StrictMode.java +++ b/core/java/android/os/StrictMode.java @@ -173,6 +173,12 @@ public final class StrictMode { public static final int PENALTY_GATHER = 0x100; /** + * Mask of all the penalty bits. + */ + private static final int PENALTY_MASK = + PENALTY_LOG | PENALTY_DIALOG | PENALTY_DEATH | PENALTY_DROPBOX | PENALTY_GATHER; + + /** * The current VmPolicy in effect. */ private static volatile int sVmPolicyMask = 0; @@ -882,7 +888,7 @@ public final class StrictMode { } } - // The violationMask, passed to ActivityManager, is a + // The violationMaskSubset, passed to ActivityManager, is a // subset of the original StrictMode policy bitmask, with // only the bit violated and penalty bits to be executed // by the ActivityManagerService remaining set. @@ -900,7 +906,35 @@ public final class StrictMode { if (violationMaskSubset != 0) { int violationBit = parseViolationFromMessage(info.crashInfo.exceptionMessage); violationMaskSubset |= violationBit; + final int violationMaskSubsetFinal = violationMaskSubset; final int savedPolicyMask = getThreadPolicyMask(); + + final boolean justDropBox = (info.policy & PENALTY_MASK) == PENALTY_DROPBOX; + if (justDropBox) { + // If all we're going to ask the activity manager + // to do is dropbox it (the common case during + // platform development), we can avoid doing this + // call synchronously which Binder data suggests + // isn't always super fast, despite the implementation + // in the ActivityManager trying to be mostly async. + new Thread("callActivityManagerForStrictModeDropbox") { + public void run() { + Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); + try { + ActivityManagerNative.getDefault(). + handleApplicationStrictModeViolation( + RuntimeInit.getApplicationObject(), + violationMaskSubsetFinal, + info); + } catch (RemoteException e) { + Log.e(TAG, "RemoteException handling StrictMode violation", e); + } + } + }.start(); + return; + } + + // Normal synchronous call to the ActivityManager. try { // First, remove any policy before we call into the Activity Manager, // otherwise we'll infinite recurse as we try to log policy violations |