StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy(); StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder(old) .permitDiskReads() .permitDiskWrites() .build());
new StrictMode.ThreadPolicy.Builder().detectAll().permitDiskReads().permitDiskWrites().penaltyLog().build());
new StrictMode.ThreadPolicy.Builder().detectAll().permitDiskReads().permitDiskWrites().penaltyLog().build());
/** * Load all preferences, such as keywords, commands, etc. */ private static Set<String> loadSetFromPrefs(Common.PrefSet type) { StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy(); StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder(old) .permitDiskReads() .permitDiskWrites() .build()); final Set<String> newSet = new HashSet<>(); try { final XSharedPreferences loadedPrefs = new XSharedPreferences(Common.PACKAGE_NAME, type.getPrefKey()); loadedPrefs.makeWorldReadable(); final boolean isFirstRun = loadedPrefs.getBoolean(Common.FIRST_RUN_KEY, true); // Load boolean that determines if this is the first run since being installed. // Loaded set is IMMUTABLE. We need to copy the values out of it. final Set<String> loadedSet = loadedPrefs.getStringSet(type.getSetKey(), null); if (loadedSet != null) { newSet.addAll(loadedSet); } else if (isFirstRun) { newSet.addAll(type.getDefaultSet()); } } finally { StrictMode.setThreadPolicy(old); } return newSet; }
protected void setupStrictMode() { if (BuildConfig.DEBUG) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectAll() .permitDiskReads() // those is mainly caused by shared preferences and room. probably enable .permitDiskWrites() // this as soon as we don't call allowMainThreadQueries() in TcaDb .penaltyLog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectActivityLeaks() //.detectLeakedClosableObjects() // seems like room / DAOs leak .detectLeakedRegistrationObjects() .detectFileUriExposure() //.detectCleartextNetwork() // not available at the current minSdk //.detectContentUriWithoutPermission() //.detectUntaggedSockets() .penaltyLog() .build()); } }
@Override public void run() { StrictMode.ThreadPolicy threadPolicy = new StrictMode.ThreadPolicy.Builder().detectAll() .permitDiskReads() .permitDiskWrites() .penaltyLog() .build(); StrictMode.setThreadPolicy(threadPolicy); StrictMode.VmPolicy vmPolicy = new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build(); StrictMode.setVmPolicy(vmPolicy); } });