package com.novoda.notils.logger.analyse;

import android.os.StrictMode;

/**
 * Enables StrictMode with defaults to detect all wrong doing.
 * <p/>
 * See http://developer.android.com/reference/android/os/StrictMode.html for more
 */
public final class StrictModeManager {
    
    /**
     * Flag to enable or disable StrictMode
     * Recommended you set this to BuildConfig.DEBUG in your class that extends Application
     */
    public static boolean ON = true;

    private StrictModeManager() {
        throw new IllegalStateException("This class should not be instantiated");
    }

    /**
     * Initializes StrictMode to close activity and log to console when a violation occurs.
     */
    public static void initializeStrictMode() {
        if (ON) {
            StrictMode.setThreadPolicy(newThreadPolicyBuilderWithDefaults().penaltyDeath().build());
            StrictMode.setVmPolicy(newVmPolicyBuilderWithDefaults().penaltyDeath().build());
        }
    }

    /**
     * Initializes StrictMode to log to console when a violation occurs.
     */
    public static void initializeStrictModeLogOnly() {
        if (ON) {
            StrictMode.setThreadPolicy(newThreadPolicyBuilderWithDefaults().build());
            StrictMode.setVmPolicy(newVmPolicyBuilderWithDefaults().build());
        }
    }

    private static StrictMode.VmPolicy.Builder newVmPolicyBuilderWithDefaults() {
        return new StrictMode.VmPolicy.Builder().detectAll().penaltyLog();
    }

    private static StrictMode.ThreadPolicy.Builder newThreadPolicyBuilderWithDefaults() {
        return new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog();
    }

}

@@ -267,20 +267,16 @@
 nager %7B%0A
-    
 %0A    /**
@@ -750,43 +750,405 @@
    i
-f (ON) %7B
+nitializeStrictMode(newThreadPolicyBuilderWithDefaultViolations(), newVmPolicyBuilderWithDefaultViolations());
 %0A    
+%7D%0A%0A
     
-    StrictMode.set
+/**%0A     * Initializes StrictMode to close activity and log to console when a violation occurs.%0A     *%0A     * Allows specification of violations via parameters. Note, penaltyLog and penaltyDeath will be applied.%0A     */%0A    public static void initializeStrictMode(StrictMode.
 Thre
@@ -1147,37 +1147,42 @@
 ode.ThreadPolicy
-(newT
+.Builder t
 hreadPolicyBuild
@@ -1179,36 +1179,160 @@
 olicyBuilder
-WithDefaults
+, StrictMode.VmPolicy.Builder vmPolicyBuilder) %7B%0A        if (ON) %7B%0A            StrictMode.setThreadPolicy(threadPolicyBuilder.penaltyLog
 ().penaltyDe
@@ -1374,36 +1374,33 @@
 ode.setVmPolicy(
-newV
+v
 mPolicyBuilderWi
@@ -1397,28 +1397,27 @@
 yBuilder
-WithDefaults
+.penaltyLog
 ().penal
@@ -1593,24 +1593,516 @@
 LogOnly() %7B%0A
+        initializeStrictModeWithPenaltyLog(newThreadPolicyBuilderWithDefaultViolations(), newVmPolicyBuilderWithDefaultViolations());%0A    %7D%0A%0A    /**%0A     * Initializes StrictMode to log to console when a violation occurs.%0A     * %3Cp/%3E%0A     * Allows specification of violations via parameters. Note, penaltyLog will be applied.%0A     */%0A    public static void initializeStrictModeWithPenaltyLog(StrictMode.ThreadPolicy.Builder threadPolicyBuilder, StrictMode.VmPolicy.Builder vmPolicyBuilder) %7B%0A
         if (
@@ -2146,20 +2146,17 @@
 dPolicy(
-newT
+t
 hreadPol
@@ -2161,36 +2161,35 @@
 olicyBuilder
-WithDefaults
+.penaltyLog
 ().build());
@@ -2224,20 +2224,17 @@
 mPolicy(
-newV
+v
 mPolicyB
@@ -2239,28 +2239,27 @@
 yBuilder
-WithDefaults
+.penaltyLog
 ().build
@@ -2348,32 +2348,41 @@
 ilderWithDefault
+Violation
 s() %7B%0A        re
@@ -2427,37 +2427,24 @@
 .detectAll()
-.penaltyLog()
 ;%0A    %7D%0A%0A   
@@ -2524,16 +2524,25 @@
 hDefault
+Violation
 s() %7B%0A  
@@ -2603,29 +2603,16 @@
 ectAll()
-.penaltyLog()
 ;%0A    %7D%0A

Update StrictModeManager to allow custom rule violations