ThreadPolicy originalPolicy = StrictMode.allowThreadDiskReads(); try { File cpuInfo = new File(CPU_LOCATION);
@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); } }
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); } }
ThreadPolicy originalPolicy = StrictMode.allowThreadDiskReads(); File[] cpus = null; try {
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { FileReader fileReader = new FileReader(cgroupFilename);
/** * 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; }
/** * Returns the directory for a web app, creating it if necessary. * @param webappId ID for the web app. Used as a subdirectory name. * @return File for storing information about the web app. */ File getWebappDirectory(Context context, String webappId) { // Temporarily allowing disk access while fixing. TODO: http://crbug.com/525781 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.allowThreadDiskWrites(); try { long time = SystemClock.elapsedRealtime(); File webappDirectory = new File(getBaseWebappDirectory(context), webappId); if (!webappDirectory.exists() && !webappDirectory.mkdir()) { Log.e(TAG, "Failed to create web app directory."); } RecordHistogram.recordTimesHistogram("Android.StrictMode.WebappDir", SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS); return webappDirectory; } finally { StrictMode.setThreadPolicy(oldPolicy); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { addPreferencesFromResource(R.xml.prefs_paired_devices); } finally { StrictMode.setThreadPolicy(oldPolicy); } Context context = getContext(); bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); hidDataSender = HidDataSender.getInstance(); hidDeviceProfile = hidDataSender.register(context, profileListener); context.registerReceiver( bluetoothStateReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)); }
private static boolean removeScheduledTasks(GcmNetworkManager scheduler) { // Third-party code causes broadcast to touch disk. http://crbug.com/614679 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { scheduler.cancelTask(TASK_TAG, ChromeBackgroundService.class); } catch (IllegalArgumentException e) { // This occurs when BackgroundSyncLauncherService is not found in the application // manifest. This should not happen in code that reaches here, but has been seen in // the past. See https://crbug.com/548314 // Disable GCM for the remainder of this session. setGCMEnabled(false); // Return false so that the failure will be logged. return false; } finally { StrictMode.setThreadPolicy(oldPolicy); } return true; }
@SuppressLint("InlinedApi") private void launchTabbedMode() { maybePrefetchDnsInBackground(); Intent newIntent = new Intent(getIntent()); String className = MultiWindowUtils.getInstance().getTabbedActivityForIntent( newIntent, this).getName(); newIntent.setClassName(getApplicationContext().getPackageName(), className); newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { newIntent.addFlags(Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS); } Uri uri = newIntent.getData(); if (uri != null && "content".equals(uri.getScheme())) { newIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } if (mIsInLegacyMultiInstanceMode) { MultiWindowUtils.getInstance().makeLegacyMultiInstanceIntent(this, newIntent); } // This system call is often modified by OEMs and not actionable. http://crbug.com/619646. StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.allowThreadDiskWrites(); try { startActivity(newIntent); } finally { StrictMode.setThreadPolicy(oldPolicy); } }
/** * @see #getMacForUrl * * @param url The URL to validate. * @param mac The bytes of a previously-calculated MAC. * * @return true if the MAC is a valid MAC for the URL, false otherwise. */ public static boolean isUrlValid(Context context, String url, byte[] mac) { byte[] goodMac = null; // Temporarily allowing disk access while fixing. TODO: http://crbug.com/525785 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { long time = SystemClock.elapsedRealtime(); goodMac = getMacForUrl(context, url); sWebappValidationTimes.record(SystemClock.elapsedRealtime() - time); } finally { StrictMode.setThreadPolicy(oldPolicy); } if (goodMac == null) { return false; } return constantTimeAreArraysEqual(goodMac, mac); }
/** * 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); } }
/** * Called by native to check wether the account has an OAuth2 refresh token. */ @CalledByNative public static boolean hasOAuth2RefreshToken(Context context, String accountName) { // Temporarily allowing disk read while fixing. TODO: http://crbug.com/618096. // This function is called in RefreshTokenIsAvailable of OAuth2TokenService which is // expected to be called in the UI thread synchronously. StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { return AccountManagerHelper.get(context).hasAccountForName(accountName); } finally { StrictMode.setThreadPolicy(oldPolicy); } }
private void restoreTab(TabRestoreDetails tabToRestore, boolean setAsActive) { // As we do this in startup, and restoring the active tab's state is critical, we permit // this read in the event that the prefetch task is not available. Either: // 1. The user just upgraded, has not yet set the new active tab id pref yet. Or // 2. restoreTab is used to preempt async queue and restore immediately on the UI thread. StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { long time = SystemClock.uptimeMillis(); TabState state; int restoredTabId = mPreferences.getInt(PREF_ACTIVE_TAB_ID, Tab.INVALID_TAB_ID); if (restoredTabId == tabToRestore.id && mPrefetchActiveTabTask != null) { long timeWaitingForPrefetch = SystemClock.uptimeMillis(); state = mPrefetchActiveTabTask.get(); logExecutionTime("RestoreTabPrefetchTime", timeWaitingForPrefetch); } else { // Necessary to do on the UI thread as a last resort. state = TabState.restoreTabState(getStateDirectory(), tabToRestore.id); } logExecutionTime("RestoreTabTime", time); restoreTab(tabToRestore, state, setAsActive); } catch (Exception e) { // Catch generic exception to prevent a corrupted state from crashing the app // at startup. Log.d(TAG, "loadTabs exception: " + e.toString(), e); } finally { StrictMode.setThreadPolicy(oldPolicy); } }
/** * Saves the tab data out to a file. */ void saveState(File activityDirectory) { String tabFileName = TabState.getTabStateFilename(getActivityTab().getId(), false); File tabFile = new File(activityDirectory, tabFileName); FileOutputStream foutput = null; // Temporarily allowing disk access while fixing. TODO: http://crbug.com/525781 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.allowThreadDiskWrites(); try { long time = SystemClock.elapsedRealtime(); foutput = new FileOutputStream(tabFile); TabState.saveState(foutput, getActivityTab().getState(), false); RecordHistogram.recordTimesHistogram("Android.StrictMode.WebappSaveState", SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS); } catch (FileNotFoundException exception) { Log.e(TAG, "Failed to save out tab state.", exception); } catch (IOException exception) { Log.e(TAG, "Failed to save out tab state.", exception); } finally { StreamUtil.closeQuietly(foutput); StrictMode.setThreadPolicy(oldPolicy); } }
/** * @return Which flavor of Herb is being tested. See {@link ChromeSwitches#HERB_FLAVOR_ANISE} * and its related switches. */ public static String getHerbFlavor() { Context context = ContextUtils.getApplicationContext(); if (isHerbDisallowed(context)) return ChromeSwitches.HERB_FLAVOR_DISABLED; if (!sIsHerbFlavorCached) { sCachedHerbFlavor = null; // Allowing disk access for preferences while prototyping. StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { sCachedHerbFlavor = ChromePreferenceManager.getInstance(context).getCachedHerbFlavor(); } finally { StrictMode.setThreadPolicy(oldPolicy); } sIsHerbFlavorCached = true; Log.d(TAG, "Retrieved cached Herb flavor: " + sCachedHerbFlavor); } return sCachedHerbFlavor; }
@Override public boolean startActivityIfNeeded(Intent intent) { boolean activityWasLaunched; // Only touches disk on Kitkat. See http://crbug.com/617725 for more context. StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); StrictMode.allowThreadDiskReads(); try { forcePdfViewerAsIntentHandlerIfNeeded(mApplicationContext, intent); Context context = getAvailableContext(); if (context instanceof Activity) { activityWasLaunched = ((Activity) context).startActivityIfNeeded(intent, -1); } else { activityWasLaunched = false; } if (activityWasLaunched) recordExternalNavigationDispatched(intent); return activityWasLaunched; } catch (RuntimeException e) { logTransactionTooLargeOrRethrow(e, intent); return false; } finally { StrictMode.setThreadPolicy(oldPolicy); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { addPreferencesFromResource(R.xml.prefs_available_devices); } finally { StrictMode.setThreadPolicy(oldPolicy); } Context context = getContext(); bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); hidDataSender = HidDataSender.getInstance(); hidDeviceProfile = hidDataSender.register(context, profileListener); initiateScanDevices = findPreference(KEY_PREF_BLUETOOTH_SCAN); availableDevices = (PreferenceGroup) findPreference(KEY_PREF_BLUETOOTH_AVAILABLE); availableDevices.setLayoutResource(R.layout.preference_group_no_title); initScanDevices(initiateScanDevices); initAvailableDevices(); registerStateReceiver(); if (context.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { requestPermissions( new String[] {Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { addPreferencesFromResource(R.xml.prefs_input_settings); } finally { StrictMode.setThreadPolicy(oldPolicy); } settings = new SettingsUtil(getActivity()); initBooleanPref(SettingsUtil.STABILIZE); initBooleanPref(SettingsUtil.CURSOR_8_WAY); initBooleanPref(SettingsUtil.REDUCED_RATE); OnboardingController onboardingController = new OnboardingController(getActivity()); Preference onboardingPref = findPreference(ONBOARDING_PREF); onboardingPref.setEnabled(onboardingController.isAnyComplete()); onboardingPref.setOnPreferenceClickListener( preference -> { if (preference.isEnabled()) { onboardingController.resetAll(); preference.setEnabled(false); } return true; }); }
private void startChromeBrowserProcessesSync() throws ProcessInitException { try { TraceEvent.begin("ChromeBrowserInitializer.startChromeBrowserProcessesSync"); ThreadUtils.assertOnUiThread(); mApplication.initCommandLine(); LibraryLoader libraryLoader = LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); libraryLoader.ensureInitialized(mApplication); StrictMode.setThreadPolicy(oldPolicy); libraryLoader.asyncPrefetchLibrariesToMemory(); // The policies are used by browser startup, so we need to register the policy providers // before starting the browser process. mApplication.registerPolicyProviders(CombinedPolicyProvider.get()); BrowserStartupController.get(mApplication, LibraryProcessType.PROCESS_BROWSER) .startBrowserProcessesSync(false); GoogleServicesManager.get(mApplication); } finally { TraceEvent.end("ChromeBrowserInitializer.startChromeBrowserProcessesSync"); } }