Java Code Examples for android.os.StrictMode#setVmPolicy()

The following examples show how to use android.os.StrictMode#setVmPolicy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PopularMoviesApplication.java    From udacity-p1-p2-popular-movies with MIT License 6 votes vote down vote up
/**
 * 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());
}
 
Example 2
Source File: App.java    From sms-ticket with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 3
Source File: CathodeInitProvider.java    From cathode with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 4
Source File: ApplicationManager.java    From buddycloud-android with Apache License 2.0 6 votes vote down vote up
@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());
     }
}
 
Example 5
Source File: StrictModeUtil.java    From JianDan_OkHttpWithVolley with Apache License 2.0 6 votes vote down vote up
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());
    }
}
 
Example 6
Source File: IMUISampleApplication.java    From aurora-imui with MIT License 6 votes vote down vote up
@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());
        }
    }
 
Example 7
Source File: DemoActivity.java    From actual-number-picker with GNU General Public License v3.0 6 votes vote down vote up
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
}
 
Example 8
Source File: StrictModeUtil.java    From JianDan_OkHttp with Apache License 2.0 6 votes vote down vote up
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());
    }
}
 
Example 9
Source File: Utils.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 10
Source File: MyApplication.java    From tinydnssd with MIT License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
            .detectAll()
            .penaltyDeath()
            .build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
            .detectAll()
            .penaltyDeath()
            .build());
}
 
Example 11
Source File: MiscUtils.java    From android-utils with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example 12
Source File: VoicePlayerView.java    From ChatVoicePlayer with MIT License 5 votes vote down vote up
@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);

}
 
Example 13
Source File: MApplication.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 14
Source File: Api9Adapter.java    From mytracks with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 15
Source File: YoukuBasePlayerActivity.java    From SimplifyReader with Apache License 2.0 4 votes vote down vote up
/**
     * 加密视频处理的回调,如果客户端没有调用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);
    }
 
Example 16
Source File: DailyApplication.java    From ZhihuDaily with Apache License 2.0 4 votes vote down vote up
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());
    }
}
 
Example 17
Source File: SampleApplication.java    From SafeContentResolver with Apache License 2.0 4 votes vote down vote up
private void disableFileUriExposedException() {
    // We're lazy and just disable all StrictMode.VmPolicy checks
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().build());
}
 
Example 18
Source File: App.java    From LLApp with Apache License 2.0 4 votes vote down vote up
@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();//启动检测
    }
 
Example 19
Source File: StrictModeManager.java    From yahnac with Apache License 2.0 4 votes vote down vote up
public static void initializeStrictMode(StrictMode.VmPolicy.Builder vmPolicyBuilder, StrictMode.ThreadPolicy.Builder threadPolicyBuilder) {
    StrictMode.setThreadPolicy(threadPolicyBuilder.penaltyDeath().build());
    StrictMode.setVmPolicy(vmPolicyBuilder.penaltyDeath().build());
}
 
Example 20
Source File: AppAnalyzer.java    From BadIntent with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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();
    }
}