summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Brian Carlstrom <bdc@google.com> 2010-11-08 10:30:40 -0800
committer Brian Carlstrom <bdc@google.com> 2010-11-08 10:58:20 -0800
commit4b9b7c38e8f52259f9d2f960072d35e8a1ab2129 (patch)
tree81c60303060fa2e7431b2113054e0c0fc6d482a9
parent3a3f24e37049de6714de64188b1814a6476dbebb (diff)
Add custom CloseGuard.Reporter for StrictMode
StrictMode now replaces the default CloseGuard.Reporter with one that calls onVmPolicyViolation, which is a renamed version of onSqliteObjectLeaked. Change-Id: Iea980662e2ee91939960c83b8768a8172379617a
-rw-r--r--core/java/android/os/StrictMode.java23
1 files changed, 22 insertions, 1 deletions
diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java
index ab5173e9524b..25d868f0860f 100644
--- a/core/java/android/os/StrictMode.java
+++ b/core/java/android/os/StrictMode.java
@@ -600,6 +600,14 @@ public final class StrictMode {
}
}
+ // Sets up CloseGuard in Dalvik/libcore
+ private static void setCloseGuardEnabled(boolean enabled) {
+ if (!(CloseGuard.getReporter() instanceof AndroidBlockGuardPolicy)) {
+ CloseGuard.setReporter(new AndroidCloseGuardReporter());
+ }
+ CloseGuard.setEnabled(enabled);
+ }
+
private static class StrictModeNetworkViolation extends BlockGuard.BlockGuardPolicyException {
public StrictModeNetworkViolation(int policyMask) {
super(policyMask, DETECT_NETWORK);
@@ -1026,6 +1034,12 @@ public final class StrictMode {
}
}
+ private static class AndroidCloseGuardReporter implements CloseGuard.Reporter {
+ public void report (String message, Throwable allocationSite) {
+ onVmPolicyViolation(message, allocationSite);
+ }
+ }
+
/**
* Called from Parcel.writeNoException()
*/
@@ -1051,7 +1065,7 @@ public final class StrictMode {
*/
public static void setVmPolicy(final VmPolicy policy) {
sVmPolicyMask = policy.mask;
- CloseGuard.setEnabled(vmClosableObjectLeaksEnabled());
+ setCloseGuardEnabled(vmClosableObjectLeaksEnabled());
}
/**
@@ -1099,6 +1113,13 @@ public final class StrictMode {
* @hide
*/
public static void onSqliteObjectLeaked(String message, Throwable originStack) {
+ onVmPolicyViolation(message, originStack);
+ }
+
+ /**
+ * @hide
+ */
+ public static void onVmPolicyViolation(String message, Throwable originStack) {
if ((sVmPolicyMask & PENALTY_LOG) != 0) {
Log.e(TAG, message, originStack);
}