From c0bb0bb5e3425b77b6e7820ebe25fe72bdd07782 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 20 Jan 2011 16:29:52 -0800 Subject: [PATCH] StrictMode: set sIsIdlerRegistered to false, and don't register if no penalties Change-Id: I1b2531b66d09c850519af17918aed8be9853ef3b --- core/java/android/os/StrictMode.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java index a53818efca1ab..1375a29b1ddd7 100644 --- a/core/java/android/os/StrictMode.java +++ b/core/java/android/os/StrictMode.java @@ -244,13 +244,20 @@ public final class StrictMode { public static final int PENALTY_GATHER = 0x100; /** - * Mask of all the penalty bits. + * Mask of all the penalty bits valid for thread policies. */ - private static final int PENALTY_MASK = + private static final int THREAD_PENALTY_MASK = PENALTY_LOG | PENALTY_DIALOG | PENALTY_DEATH | PENALTY_DROPBOX | PENALTY_GATHER | PENALTY_DEATH_ON_NETWORK | PENALTY_FLASH; + /** + * Mask of all the penalty bits valid for VM policies. + */ + private static final int VM_PENALTY_MASK = + PENALTY_LOG | PENALTY_DEATH | PENALTY_DROPBOX; + + // TODO: wrap in some ImmutableHashMap thing. // Note: must be before static initialization of sVmPolicy. private static final HashMap EMPTY_CLASS_LIMIT_MAP = new HashMap(); @@ -1117,7 +1124,7 @@ public final class StrictMode { // TODO: if in gather mode, ignore Looper.myLooper() and always // go into this immediate mode? if (looper == null || - (info.policy & PENALTY_MASK) == PENALTY_DEATH) { + (info.policy & THREAD_PENALTY_MASK) == PENALTY_DEATH) { info.durationMillis = -1; // unknown (redundant, already set) handleViolation(info); return; @@ -1254,7 +1261,7 @@ public final class StrictMode { violationMaskSubset |= violationBit; final int savedPolicyMask = getThreadPolicyMask(); - final boolean justDropBox = (info.policy & PENALTY_MASK) == PENALTY_DROPBOX; + final boolean justDropBox = (info.policy & THREAD_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 @@ -1413,8 +1420,10 @@ public final class StrictMode { Looper looper = Looper.getMainLooper(); if (looper != null) { MessageQueue mq = looper.mQueue; - if (policy.classInstanceLimit.size() == 0) { + if (policy.classInstanceLimit.size() == 0 || + (sVmPolicyMask & VM_PENALTY_MASK) == 0) { mq.removeIdleHandler(sProcessIdleHandler); + sIsIdlerRegistered = false; } else if (!sIsIdlerRegistered) { mq.addIdleHandler(sProcessIdleHandler); sIsIdlerRegistered = true;