package com.braintreepayments.demo;

import android.app.Application;
import android.content.Context;

import com.braintreepayments.demo.internal.ApiClient;
import com.braintreepayments.demo.internal.ApiClientRequestInterceptor;
import com.lukekorth.mailable_log.MailableLog;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.Thread.UncaughtExceptionHandler;

import retrofit.RestAdapter;

public class DemoApplication extends Application implements UncaughtExceptionHandler {

    private static ApiClient sApiClient;

    private Thread.UncaughtExceptionHandler mDefaultExceptionHandler;

    @Override
    public void onCreate() {
        super.onCreate();

        if (Settings.getVersion(this) != BuildConfig.VERSION_CODE) {
            Settings.setVersion(this);
            MailableLog.clearLog(this);
        }
        MailableLog.init(this, BuildConfig.DEBUG);

        DeveloperTools.setup(this);

        mDefaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
        Thread.setDefaultUncaughtExceptionHandler(this);
    }

    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
        Logger logger = LoggerFactory.getLogger("Exception");

        logger.error("thread.toString(): " + thread.toString());
        logger.error("Exception: " + ex.toString());
        logger.error("Exception stacktrace:");
        for (StackTraceElement trace : ex.getStackTrace()) {
            logger.error(trace.toString());
        }

        logger.error("");

        logger.error("cause.toString(): " + ex.getCause().toString());
        logger.error("Cause: " + ex.getCause().toString());
        logger.error("Cause stacktrace:");
        for (StackTraceElement trace : ex.getCause().getStackTrace()) {
            logger.error(trace.toString());
        }

        mDefaultExceptionHandler.uncaughtException(thread, ex);
    }

    static ApiClient getApiClient(Context context) {
        if (sApiClient == null) {
            sApiClient = new RestAdapter.Builder()
                    .setEndpoint(Settings.getEnvironmentUrl(context))
                    .setRequestInterceptor(new ApiClientRequestInterceptor())
                    .build()
                    .create(ApiClient.class);
        }

        return sApiClient;
    }

    static void resetApiClient() {
        sApiClient = null;
    }
}

@@ -93,16 +93,46 @@
 Context;
+%0Aimport android.os.StrictMode;
 %0A%0Aimport
@@ -678,24 +678,531 @@
 nCreate() %7B%0A
+        if (BuildConfig.DEBUG) %7B%0A            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()%0A                    .detectCustomSlowCalls()%0A                    .detectNetwork()%0A                    .penaltyLog()%0A                    .penaltyDeath()%0A                    .build());%0A            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()%0A                    .detectAll()%0A                    .penaltyLog()%0A                    .penaltyDeath()%0A                    .build());%0A        %7D%0A%0A
         supe

Add StrictMode to demo app in debug