android.os.StrictMode#setVmPolicy ( )源码实例Demo

下面列出了android.os.StrictMode#setVmPolicy ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: JianDan_OkHttp   文件: StrictModeUtil.java
public static void init() {
    if (false && BuildConfig.DEBUG && Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {

        //线程监控,会弹框哦
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .penaltyDialog()
                .build());

        //VM监控
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .build());
    }
}
 
源代码2 项目: cathode   文件: CathodeInitProvider.java
@Override public boolean onCreate() {
  if (BuildConfig.DEBUG) {
    Timber.plant(new Timber.DebugTree());

    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
    StrictMode.setThreadPolicy(
        new StrictMode.ThreadPolicy.Builder().detectAll().permitDiskReads().penaltyLog().build());
  } else {
    Fabric.with(getContext(), new Crashlytics());
    Timber.plant(new CrashlyticsTree());
  }

  ((CathodeApp) getContext().getApplicationContext()).ensureInjection();
  AndroidInjection.inject(this);

  UpcomingSortByPreference.init(getContext());
  UpcomingTimePreference.init(getContext());
  FirstAiredOffsetPreference.init(getContext());

  Upgrader.upgrade(getContext());

  Accounts.setupAccount(getContext());

  return true;
}
 
源代码3 项目: JianDan_OkHttpWithVolley   文件: StrictModeUtil.java
public static void init() {
    if (false && BuildConfig.DEBUG && Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {

        //线程监控,会弹框哦
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .penaltyDialog()
                .build());

        //VM监控
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .build());
    }
}
 
源代码4 项目: aurora-imui   文件: IMUISampleApplication.java
@Override
    public void onCreate() {
        super.onCreate();
//        if (LeakCanary.isInAnalyzerProcess(this)) {
//            return;
//        }
//        LeakCanary.install(this);

        if (BuildConfig.DEBUG) {
            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                    .detectAll()
                    .penaltyLog()
                    .build());

            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                    .detectAll()
                    .penaltyLog()
                    .build());
        }
    }
 
源代码5 项目: actual-number-picker   文件: DemoActivity.java
private void enableStrictMode() {
    // @formatter:off
    StrictMode.setThreadPolicy(
        new StrictMode.ThreadPolicy.
            Builder().
            detectAll().
            penaltyLog().
            build());
    StrictMode.setVmPolicy(
        new StrictMode.VmPolicy.
            Builder().
            detectAll().
            penaltyLog().
            penaltyDeath().
            build());
    // @formatter:on
}
 
源代码6 项目: buddycloud-android   文件: ApplicationManager.java
@SuppressLint("NewApi")
private void applicationDebuggingMode() {
	if (DEVELOPER_MODE) {
         StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                 .detectDiskReads()
                 .detectDiskWrites()
                 .detectNetwork()   // or .detectAll() for all detectable problems
                 .penaltyLog()
                 .build());
         StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                 .detectLeakedSqlLiteObjects()
                 .detectLeakedClosableObjects()
                 .penaltyLog()
                 .penaltyDeath()
                 .build());
     }
}
 
源代码7 项目: sms-ticket   文件: App.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
protected void initStrictMode() {
    StrictMode.ThreadPolicy.Builder tpb = new StrictMode.ThreadPolicy.Builder();
    tpb.detectAll();
    tpb.penaltyLog();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        tpb.penaltyFlashScreen();
    }
    StrictMode.setThreadPolicy(tpb.build());

    StrictMode.VmPolicy.Builder vmpb = new StrictMode.VmPolicy.Builder();
    /* vmpb.detectActivityLeaks() - it doesn't work: http://stackoverflow.com/questions/5956132/android-strictmode-instancecountviolation */
    vmpb.detectLeakedSqlLiteObjects();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        vmpb.detectLeakedClosableObjects();
    }
    vmpb.penaltyLog();
    StrictMode.setVmPolicy(vmpb.build());
}
 
/**
 * Used to enable {@link android.os.StrictMode} during development
 */
public static void enableStrictMode() {
    if (!BuildConfig.DEBUG) {
        return;
    }
    // thread violations
    final StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder();
    threadPolicyBuilder.detectAll();
    threadPolicyBuilder.penaltyLog();
    threadPolicyBuilder.penaltyDialog();
    StrictMode.setThreadPolicy(threadPolicyBuilder.build());

    // activity leaks, unclosed resources, etc
    final StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder();
    vmPolicyBuilder.detectAll();
    vmPolicyBuilder.penaltyLog();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        vmPolicyBuilder.detectLeakedRegistrationObjects();
    }
    StrictMode.setVmPolicy(vmPolicyBuilder.build());
}
 
源代码9 项目: mytracks   文件: Api9Adapter.java
@Override
public void enableStrictMode() {
  Log.d(TAG, "Enabling strict mode");
  StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
      .detectAll()
      .penaltyLog()
      .build());
  StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
      .detectAll()
      .penaltyLog()
      .build());
}
 
源代码10 项目: AndroidComponentPlugin   文件: MApplication.java
private void startStrictMode() {
    if (!BuildConfig.DEBUG || Build.VERSION.SDK_INT <= 15) return;
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
            .detectAll()
            .penaltyDialog()
            .penaltyLog()
            .build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
            .detectAll()
            .penaltyDeath()
            .penaltyLog()
            .build());
}
 
源代码11 项目: ChatVoicePlayer   文件: VoicePlayerView.java
@Override
public void onClick(View view) {
    ((Activity) context).runOnUiThread(new Runnable() {
        @Override
        public void run() {
            imgShare.setVisibility(GONE);
            progressBar.setVisibility(VISIBLE);
        }
    });
    File file = new File(path);
    if (file.exists()){
        Intent intentShareFile = new Intent(Intent.ACTION_SEND);
        intentShareFile.setType(URLConnection.guessContentTypeFromName(file.getName()));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
        }
            intentShareFile.putExtra(Intent.EXTRA_STREAM,
                    Uri.parse("file://"+file.getAbsolutePath()));

        context.startActivity(Intent.createChooser(intentShareFile, shareTitle));
    }
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            ((Activity) context).runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    progressBar.setVisibility(GONE);
                    imgShare.setVisibility(VISIBLE);
                }
            });

        }
    }, 500);

}
 
源代码12 项目: mimi-reader   文件: Utils.java
@TargetApi(11)
public static void enableStrictMode() {
    StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog();
    StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll().penaltyLog();

    threadPolicyBuilder.penaltyFlashScreen();
    StrictMode.setThreadPolicy(threadPolicyBuilder.build());
    StrictMode.setVmPolicy(vmPolicyBuilder.build());
}
 
源代码13 项目: android-utils   文件: MiscUtils.java
/**
 * Enable strict mode.
 *
 * @param enable the enable flag
 */
public static void enableStrictMode(boolean enable) {
    if (enable) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads()
                .detectDiskWrites()
                .detectNetwork()   // or .detectAll() for all detectable problems
                .penaltyLog()
                .build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects()
                .penaltyLog()
                .penaltyDeath()
                .build());
    }
}
 
源代码14 项目: tinydnssd   文件: MyApplication.java
@Override
public void onCreate() {
    super.onCreate();
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
            .detectAll()
            .penaltyDeath()
            .build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
            .detectAll()
            .penaltyDeath()
            .build());
}
 
源代码15 项目: BadIntent   文件: AppAnalyzer.java
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
    sPrefs = new XSharedPreferences(new File(PREFERENCE_PATH));
    sPrefs.reload();

    String target = lpparam.packageName;

    //bypass various apps depending on preferences
    String[] bypass = getBypassList();
    String packageNameFilter = sPrefs.getString("package_filter", "");
    for (String bypassElement : bypass) {
        /* check if package filter does not equal this package
        NOTE: this is a special condition in order to overwrite the hook_system_switch;
        However, the packageNameFilter has to exactly match exactly the target package.
         */
        if (target.matches(bypassElement) && !target.equals(packageNameFilter)){
            return;
        }
    }

    //disable strict mode in order to prevent unclosed connections file usage
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().build());

    HookingManager hookingManager = new HookingManager(lpparam, target);

    int port = getRandomPort();

    //updating current app's meta data
    AppInformation.Instance.packageName = lpparam.packageName;
    AppInformation.Instance.port = port;
    Log.d(TAG, "Hooking package:" + target + " port: " + port);
    if (hookingManager.continueHooking()) {
        BaseHook base = hookingManager.getBaseHook();
        ParcelProxyHooks parcelProxyHooks = new ParcelProxyHooks(base, port);
        parcelProxyHooks.hookParcel();
        TransactionHooks transactionHooks = new TransactionHooks(base, sPrefs, port);
        transactionHooks.hookBinder();
        LogHooks logHooks = new LogHooks(base, sPrefs, port);
        logHooks.hookLogs();
    }
}
 
源代码16 项目: ZhihuDaily   文件: DailyApplication.java
private void setStrictMode() {
    if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
    }
}
 
源代码17 项目: SimplifyReader   文件: YoukuBasePlayerActivity.java
/**
     * 加密视频处理的回调,如果客户端没有调用YoukuPlayer的setIEncryptVideoCallBack设置�?
     * YoukuBasePlayerActivity默认提供一个call调用,用于处理加密视频的回调信息�?
     */
//	public boolean isApiServiceAvailable = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Logger.d("PlayFlow", "YoukuBasePlayerActivity->onCreate");
        if (DEVELOPER_MODE) {
            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                    .detectDiskReads().detectDiskWrites().detectNetwork() // 这里可以替换为detectAll()
                            // 就包括了磁盘读写和网络I/O
                    .penaltyLog() // 打印logcat,当然也可以定位到dropbox,通过文件保存相应的log
                    .build());
            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                    .detectLeakedSqlLiteObjects() // 探测SQLite数据库操�?
                    .penaltyLog() // 打印logcat
                    .penaltyDeath().build());
        }

        super.onCreate(savedInstanceState);
/*		isApiServiceAvailable = PlayerUiUtile.isYoukuPlayerServiceAvailable(this);
        if(!isApiServiceAvailable){
			return;
		}

		PlayerUiUtile.initialYoukuPlayerService(this);
		mediaPlayerDelegate = RemoteInterface.mediaPlayerDelegate;*/


        if (mCreateTime == 0) {
            // 优酷进入播放器需要重新获取设置的清晰�?
            Profile.getVideoQualityFromSharedPreferences(getApplicationContext());
        }
        ++mCreateTime;
        youkuContext = this;
        mImageWorker = (ImageResizer) getImageWorker(this);

        setVolumeControlStream(AudioManager.STREAM_MUSIC);

        OfflineStatistics offline = new OfflineStatistics();
        offline.sendVV(this);

        ACTIVE_TIME = PreferenceUtil.getPreference(this, "active_time");
        if (ACTIVE_TIME == null || ACTIVE_TIME.length() == 0) {
            ACTIVE_TIME = String.valueOf(System.currentTimeMillis());
            PreferenceUtil.savePreference(this, "active_time", ACTIVE_TIME);
        }

        // 初始化设备信�?
        Profile.GUID = Device.guid;
        try {
            YoukuBasePlayerActivity.versionName = getPackageManager()
                    .getPackageInfo(getPackageName(),
                            PackageManager.GET_META_DATA).versionName;
        } catch (NameNotFoundException e) {
            YoukuBasePlayerActivity.versionName = "3.1";
            Logger.e(TAG_GLOBAL, e);
        }

        if (TextUtils.isEmpty(com.baseproject.utils.Profile.User_Agent)) {
            String plant = UIUtils.isTablet(this) ? "Youku HD;" : "Youku;";
            com.baseproject.utils.Profile.initProfile("player", plant
                    + versionName + ";Android;"
                    + android.os.Build.VERSION.RELEASE + ";"
                    + android.os.Build.MODEL, getApplicationContext());
        }

//		mApplication = PlayerApplication.getPlayerApplicationInstance();
        flags = getApplicationInfo().flags;
        com.baseproject.utils.Profile.mContext = getApplicationContext();
        if (MediaPlayerProxyUtil.isUplayerSupported()) {                                //-------------------->
            YoukuBasePlayerActivity.isHighEnd = true;
            // 使用软解
            PreferenceUtil.savePreference(this, "isSoftwareDecode", true);
            com.youku.player.goplay.Profile.setVideoType_and_PlayerType(
                    com.youku.player.goplay.Profile.FORMAT_FLV_HD, this);
        } else {
            YoukuBasePlayerActivity.isHighEnd = false;
            com.youku.player.goplay.Profile.setVideoType_and_PlayerType(
                    com.youku.player.goplay.Profile.FORMAT_3GPHD, this);
        }

        IMediaPlayerDelegate.is = getResources().openRawResource(R.raw.aes);        //-------------------------------------->
        orientationHelper = new DeviceOrientationHelper(this, this);
    }
 
源代码18 项目: SafeContentResolver   文件: SampleApplication.java
private void disableFileUriExposedException() {
    // We're lazy and just disable all StrictMode.VmPolicy checks
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().build());
}
 
源代码19 项目: LLApp   文件: App.java
@Override
    public void onCreate() {
        super.onCreate();

        //解决7.0  FileUriExposedException
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
        }

        instance = this;
        //创建全局的路由
        routerService = new Router(this).create(RouterService.class);
        StaticValue.color = ThemeUtils.getThemeColor(this);
        //开启debug模式,方便定位错误,具体错误检查方式可以查看http://dev.umeng.com/social/android/quick-integration的报错必看,正式发布,请关闭该模式
        BuildConfig.DEBUG = false;
        // 初始化友盟组件
        UMShareAPI.get(this);
        //初始化LiuleiUtils
        LLUtils.init(this);
        //初始化加载文章缩略图配置
        ConfigManage.INSTANCE.initConfig(this);
        //litepal的配置
        LitePalApplication.initialize(this);
        //崩溃日志
        //注册crashHandler
        CrashHandler crashHandler = CrashHandler.getInstance();
        crashHandler.init(this);
        //Android crash 上传服务器回掉  暂时注释
//        HttpReportCallback report = new HttpReportCallback() {
//            @Override
//            public void uploadException2remote(File file) {
//                //可以直接上传文件
//            }
//        };
//        AndroidCrash.getInstance().setCrashReporter(report).init(this);
        if (BuildConfig.DEBUG) {
            Logcat.init("com.android.racofix").hideThreadInfo().methodCount(3);
        }
        //检查程序哪里出现ANR异常
//        BlockLooper.initialize(new BlockLooper.Builder(this)
//        .setIgnoreDebugger(true)
//        .setReportAllThreadInfo(true)
//        .setSaveLog(true)
//        .setOnBlockListener(new BlockLooper.OnBlockListener() {
//            @Override
//            public void onBlock(BlockError blockError) {
//                blockError.printStackTrace();
//            }
//        })
//        .build());
//        BlockLooper.getBlockLooper().start();//启动检测
    }
 
源代码20 项目: yahnac   文件: StrictModeManager.java
public static void initializeStrictMode(StrictMode.VmPolicy.Builder vmPolicyBuilder, StrictMode.ThreadPolicy.Builder threadPolicyBuilder) {
    StrictMode.setThreadPolicy(threadPolicyBuilder.penaltyDeath().build());
    StrictMode.setVmPolicy(vmPolicyBuilder.penaltyDeath().build());
}