Example usage for android.os StrictMode setVmPolicy

List of usage examples for android.os StrictMode setVmPolicy

Introduction

In this page you can find the example usage for android.os StrictMode setVmPolicy.

Prototype

public static void setVmPolicy(final VmPolicy policy) 

Source Link

Document

Sets the policy for what actions in the VM process (on any thread) should be detected, as well as the penalty if such actions occur.

Usage

From source file:Main.java

public static void enableStrictMode() {
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
            .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
}

From source file:Main.java

public static void setStrictModeOn() {
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectNetwork().penaltyLog()
            .penaltyDialog().permitDiskWrites().permitDiskReads().build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
}

From source file:Main.java

public static void openStrictMode() {
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
            .penaltyLog().detectNetwork().penaltyDeath().build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().penaltyDeath().build());

}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void enableStrictMode(Class... cls) {
    if (hasGingerbread()) {
        StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll()
                .penaltyLog();//  w w w.java 2s  .  c o  m
        StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll()
                .penaltyLog();

        if (hasHoneycomb()) {
            threadPolicyBuilder.penaltyFlashScreen();

            if (cls != null) {
                for (Class cl : cls) {
                    vmPolicyBuilder.setClassInstanceLimit(cl, 1);
                }
            }
        }
        StrictMode.setThreadPolicy(threadPolicyBuilder.build());
        StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }
}

From source file:Main.java

@TargetApi(11)
public static void enableStrictMode(Class classs) {
    if (hasGingerbread()) {
        StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll()
                .penaltyLog();/* www.j av  a  2 s  .  c om*/
        StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll()
                .penaltyLog();
        if (hasHoneycomb()) {
            threadPolicyBuilder.penaltyFlashScreen();
            vmPolicyBuilder.setClassInstanceLimit(classs, 1);
        }
        StrictMode.setThreadPolicy(threadPolicyBuilder.build());
        StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }
}

From source file:com.android.project.imagefetcher.Utils.java

@TargetApi(11)
public static void enableStrictMode(Class<?> strictClass) {
    if (Utils.hasGingerbread()) {
        StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll()
                .penaltyLog();//from   w ww .  ja v  a 2 s  .  c  om
        StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll()
                .penaltyLog();

        if (Utils.hasHoneycomb()) {
            threadPolicyBuilder.penaltyFlashScreen();
            vmPolicyBuilder.setClassInstanceLimit(strictClass, 1).setClassInstanceLimit(strictClass, 1);
        }
        StrictMode.setThreadPolicy(threadPolicyBuilder.build());
        StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }
}

From source file:com.elkriefy.android.apps.authenticationexample.cleartextnetworkusage.ClearTextNetworkUsageActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (BuildConfig.APPLY_STRICT_MODE) {
        StrictMode.VmPolicy.Builder b = new StrictMode.VmPolicy.Builder();
        b.detectCleartextNetwork().penaltyLog();
        StrictMode.setVmPolicy(b.build());
    }// ww  w.j  a v  a 2 s. com
    setContentView(R.layout.clear_text_network_activity_main);
    mImageView = (ImageView) findViewById(R.id.imageViewOutCome);

    mWebview = (WebView) findViewById(R.id.WebView_Network_test);
    mWebview.loadUrl(BuildConfig.URL);

    try {
        Picasso.with(this).load(BuildConfig.URL).fit().into(mImageView);

    } catch (Throwable e) {
        e.printStackTrace();
    }

}

From source file:air.com.snagfilms.utils.Utils.java

@TargetApi(VERSION_CODES.HONEYCOMB)
public static void enableStrictMode() {
    if (Utils.hasGingerbread()) {
        StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll()
                .penaltyLog();//  w  w w.  j  a v a2 s  . co m
        StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll()
                .penaltyLog();

        if (Utils.hasHoneycomb()) {
            threadPolicyBuilder.penaltyFlashScreen();
            /*
             * vmPolicyBuilder
             * .setClassInstanceLimit(ImageGridActivity.class, 1)
             * .setClassInstanceLimit(ImageDetailActivity.class, 1);
             */
        }
        StrictMode.setThreadPolicy(threadPolicyBuilder.build());
        StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }
}

From source file:com.commonsware.cwac.loaderex.demo.ConstantsBrowserACL.java

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

    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
            .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());

    setContentView(R.layout.main);//  w w w  . j  a  v a  2s .  c  o  m

    db = new DatabaseHelper(this);

    adapter = new SimpleCursorAdapter(this, R.layout.row, null,
            new String[] { DatabaseHelper.TITLE, DatabaseHelper.VALUE }, new int[] { R.id.title, R.id.value });

    ListView lv = (ListView) findViewById(R.id.constants);

    lv.setAdapter(adapter);
    registerForContextMenu(lv);
    getSupportLoaderManager().initLoader(0, null, this);
}

From source file:com.android.mail.ui.AbstractMailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (STRICT_MODE) {
        StrictMode.setThreadPolicy(/*from w  w w. j a v a 2s. c  o m*/
                new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems
                        .penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects().penaltyLog().build());
    }

    super.onCreate(savedInstanceState);
    mUiHandler.setEnabled(true);
}