StrictMode: set sIsIdlerRegistered to false, and don't register if no penalties
Change-Id: I1b2531b66d09c850519af17918aed8be9853ef3b
diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java
index a53818e..1375a29 100644
--- a/core/java/android/os/StrictMode.java
+++ b/core/java/android/os/StrictMode.java
@@ -244,13 +244,20 @@
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<Class, Integer> EMPTY_CLASS_LIMIT_MAP = new HashMap<Class, Integer>();
@@ -1117,7 +1124,7 @@
// 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 @@
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 @@
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;