Chrisの梳羽之礁

A look of quick intelligence and soft refinement
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Strict Mode

Posted on 2014-02-10 22:17  Chrisfang6  阅读(181)  评论(0编辑  收藏  举报

 

 

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.StrictMode;

/**
 * @author chris
 * 
 */
public class StrictModeWrapper {

    public static void start(Context context) {
        // Check if android:debuggable is set to true.
        int appFlags = context.getApplicationInfo().flags;
        if ((appFlags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                    .detectDiskReads() //
                    .detectDiskWrites() //
                    .detectNetwork() //
                    .penaltyLog() //
                    .penaltyDeathOnNetwork() //
                    .penaltyDeath() //
                    .build());
            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                    .detectLeakedSqlLiteObjects() //
                    .penaltyLog() //
                    .penaltyDeath() //
                    .build());
        }
    }
}