@Override public void onCreate() { super.onCreate(); setThreadPolicy(new ThreadPolicy.Builder().detectAll().penaltyLog().build()); setVmPolicy(new VmPolicy.Builder().detectAll().penaltyLog().build()); } }
@Override public void run() { StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy(); StrictMode.setThreadPolicy(THREAD_POLICY); try { command.run(); } finally { StrictMode.setThreadPolicy(oldPolicy); } } });
ThreadPolicy originalPolicy = StrictMode.allowThreadDiskReads(); try { File cpuInfo = new File(CPU_LOCATION); StrictMode.setThreadPolicy(originalPolicy);
@Override public void onReady(Bundle savedInstanceState) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectNetwork() .penaltyDeath() .build()); if (getSupportFragmentManager().findFragmentById(android.R.id.content)==null) { getSupportFragmentManager().beginTransaction() .add(android.R.id.content, new DownloadFragment()).commit(); } }
static SharedPreferences getWidgetState(Context context, int widgetId) { StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.allowThreadDiskWrites(); try { return context.getSharedPreferences( String.format("widgetState-%d", widgetId), Context.MODE_PRIVATE); } finally { StrictMode.setThreadPolicy(oldPolicy); } }
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.setVmPolicy(builder.build()); final int columnIndex = cursor.getColumnIndexOrThrow(column); return cursor.getString(columnIndex); } } finally { if (cursor != null) { cursor.close(); } } return null; }
new StrictMode.ThreadPolicy.Builder(StrictMode.getThreadPolicy()); StrictMode.VmPolicy.Builder vmPolicy = new StrictMode.VmPolicy.Builder(StrictMode.getVmPolicy()); StrictMode.setThreadPolicy(threadPolicy.build()); StrictMode.setVmPolicy(vmPolicy.build());
StrictMode.ThreadPolicy originalPolicy = StrictMode.getThreadPolicy(); try { StrictMode.allowThreadDiskReads(); StrictMode.allowThreadDiskWrites(); switch (method) { case "getHooks": throw new RemoteException(ex.getMessage()); } finally { StrictMode.setThreadPolicy(originalPolicy);
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); final File reportFile = getReportFileName(crashReportData); saveCrashReportFile(reportFile, crashReportData); StrictMode.setThreadPolicy(oldPolicy); } else { if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Not sending crash report because of ReportingAdministrator " + blockingAdministrator.getClass().getName());
public void setHostname(String hostname, int port){ mHostname = hostname; mPort = port; mType = Type.REMOTE; try{ // This is needed to avoid NetworkOnMainThreadException StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); mAddress = InetAddress.getByName(mHostname); } catch(Exception e){ Logger.debug(e.toString()); } }
/** * The folder where the state should be saved to. * @return A file representing the directory that contains TabModelSelector states. */ public static File getOrCreateStateDirectory() { synchronized (DIR_CREATION_LOCK) { if (sStateDirectory == null) { sStateDirectory = new File( BaseStateDirectoryHolder.sDirectory, SAVED_STATE_DIRECTORY); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.allowThreadDiskWrites(); try { if (!sStateDirectory.exists() && !sStateDirectory.mkdirs()) { Log.e(TAG, "Failed to create state folder: " + sStateDirectory); } } finally { StrictMode.setThreadPolicy(oldPolicy); } } } return sStateDirectory; }
@Test public void setVmPolicyTest() { StrictMode.VmPolicy policy = new StrictMode.VmPolicy.Builder().build(); StrictMode.setVmPolicy(policy); // should not result in an exception } }
StrictMode.ThreadPolicy originalPolicy = StrictMode.getThreadPolicy(); try { StrictMode.allowThreadDiskReads(); StrictMode.allowThreadDiskWrites(); switch (method) { case "getVersion": throw new RemoteException(ex.getMessage()); } finally { StrictMode.setThreadPolicy(originalPolicy);
@Override public boolean onCreate() { final Context context = getContext(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); mOpenHelper = new DatabaseHelper(context); StrictMode.setThreadPolicy(oldPolicy); LauncherAppState.setLauncherProvider(this); return true; }
@Override protected void onCreate(Bundle savedInstanceState) { if (BuildConfig.DEBUG) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog() .penaltyDeath() .build()); } super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); GetOrComputeYearClass findYearClass = new GetOrComputeYearClass(); findYearClass.execute(); mYearClass = (TextView) findViewById(R.id.year_class); }
@Override public List<ResolveInfo> queryIntentActivities(Intent intent) { // White-list for Samsung. See http://crbug.com/613977 for more context. StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { return mApplicationContext.getPackageManager().queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); } finally { StrictMode.setThreadPolicy(oldPolicy); } }
private static void enabledStrictMode() { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() // .detectAll() // .penaltyLog() // .penaltyDeath() // .build()); } }
/** * Invokes whatever external code is necessary to check if Google Play Services is available * and returns the code produced by the attempt. Subclasses can override to force the behavior * one way or another, or to change the way that the check is performed. * @param context The current context. * @return The code produced by calling the external code */ protected int checkGooglePlayServicesAvailable(final Context context) { // Temporarily allowing disk access. TODO: Fix. See http://crbug.com/577190 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.allowThreadDiskWrites(); try { long time = SystemClock.elapsedRealtime(); int isAvailable = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context); mRegistrationTimeHistogramSample.record(SystemClock.elapsedRealtime() - time); return isAvailable; } finally { StrictMode.setThreadPolicy(oldPolicy); } }
@BeforeClass public static void init() { if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.P) { if (LOG_DIR.listFiles()!=null) { for (File file : LOG_DIR.listFiles()) { if (!file.isDirectory()) { file.delete(); } } } StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectNonSdkApiUsage() .penaltyListener(LISTENER_EXECUTOR, GREYLISTENER) .build()); } }
@Override public void run() { StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy(); StrictMode.setThreadPolicy(THREAD_POLICY); try { command.run(); } finally { StrictMode.setThreadPolicy(oldPolicy); } } });