Java Code Examples for android.os.StrictMode#allowThreadDiskReads()
The following examples show how to use
android.os.StrictMode#allowThreadDiskReads() .
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: PackageManagerDelegate.java From 365browser with Apache License 2.0 | 6 votes |
/** * Retrieves the list of activities that can respond to the given intent. And returns the * activites' meta data in ResolveInfo. * * @param intent The intent to query. * @return The list of activities that can respond to the intent. */ public List<ResolveInfo> getActivitiesThatCanRespondToIntentWithMetaData(Intent intent) { ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { return ContextUtils.getApplicationContext().getPackageManager().queryIntentActivities( intent, PackageManager.GET_META_DATA); } finally { StrictMode.setThreadPolicy(oldPolicy); } }
Example 2
Source File: WebappDirectoryManager.java From delion with Apache License 2.0 | 6 votes |
/** * 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); } }
Example 3
Source File: PathUtils.java From 365browser with Apache License 2.0 | 6 votes |
/** * @return the public downloads directory. */ @SuppressWarnings("unused") @CalledByNative private static String getDownloadsDirectory() { // Temporarily allowing disk access while fixing. TODO: http://crbug.com/508615 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); String downloadsPath; try { long time = SystemClock.elapsedRealtime(); downloadsPath = Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_DOWNLOADS).getPath(); RecordHistogram.recordTimesHistogram("Android.StrictMode.DownloadsDir", SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS); } finally { StrictMode.setThreadPolicy(oldPolicy); } return downloadsPath; }
Example 4
Source File: ChromeBrowserInitializer.java From delion with Apache License 2.0 | 6 votes |
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"); } }
Example 5
Source File: BackgroundSyncLauncher.java From AndroidChromium with Apache License 2.0 | 6 votes |
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; }
Example 6
Source File: OAuth2TokenService.java From delion with Apache License 2.0 | 5 votes |
/** * 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); } }
Example 7
Source File: VrClassesWrapperImpl.java From 365browser with Apache License 2.0 | 5 votes |
@Override public NonPresentingGvrContext createNonPresentingGvrContext(ChromeActivity activity) { StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { return new NonPresentingGvrContextImpl(activity); } catch (Exception ex) { Log.e(TAG, "Unable to instantiate NonPresentingGvrContextImpl", ex); return null; } finally { StrictMode.setThreadPolicy(oldPolicy); } }
Example 8
Source File: AutocompleteEditText.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { // Certain OEM implementations of onInitializeAccessibilityNodeInfo trigger disk reads // to access the clipboard. crbug.com/640993 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { super.onInitializeAccessibilityNodeInfo(info); } finally { StrictMode.setThreadPolicy(oldPolicy); } }
Example 9
Source File: NotificationService.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Initializes Chrome and starts the browser process if it's not running as of yet, and * dispatch |intent| to the NotificationPlatformBridge once this is done. * * @param intent The intent containing the notification's information. */ @SuppressFBWarnings("DM_EXIT") private void dispatchIntentOnUIThread(Intent intent) { try { ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup(); // Warm up the WebappRegistry, as we need to check if this notification should launch a // standalone web app. This no-ops if the registry is already initialized and warmed, // but triggers a strict mode violation otherwise (i.e. the browser isn't running). // Temporarily disable strict mode to work around the violation. StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { WebappRegistry.getInstance(); WebappRegistry.warmUpSharedPrefs(); } finally { StrictMode.setThreadPolicy(oldPolicy); } // Now that the browser process is initialized, we pass forward the call to the // NotificationPlatformBridge which will take care of delivering the appropriate events. if (!NotificationPlatformBridge.dispatchNotificationEvent(intent)) { Log.w(TAG, "Unable to dispatch the notification event to Chrome."); } // TODO(peter): Verify that the lifetime of the NotificationService is sufficient // when a notification event could be dispatched successfully. } catch (ProcessInitException e) { Log.e(TAG, "Unable to start the browser process.", e); System.exit(-1); } }
Example 10
Source File: OAuth2TokenService.java From 365browser with Apache License 2.0 | 5 votes |
/** * Called by native to check wether the account has an OAuth2 refresh token. */ @CalledByNative public static boolean hasOAuth2RefreshToken(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().hasAccountForName(accountName); } finally { StrictMode.setThreadPolicy(oldPolicy); } }
Example 11
Source File: DownloadUtils.java From 365browser with Apache License 2.0 | 5 votes |
/** * Returns a URI that points at the file. * @param file File to get a URI for. * @return URI that points at that file, either as a content:// URI or a file:// URI. */ public static Uri getUriForItem(File file) { Uri uri = null; // FileUtils.getUriForFile() causes a disk read when it calls into // FileProvider#getUriForFile. Obtaining a content URI is on the critical path for creating // a share intent after the user taps on the share button, so even if we were to run this // method on a background thread we would have to wait. As it depends on user-selected // items, we cannot know/preload which URIs we need until the user presses share. StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); uri = FileUtils.getUriForFile(file); StrictMode.setThreadPolicy(oldPolicy); return uri; }
Example 12
Source File: CrashServiceImpl.java From Cangol-appcore with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.GINGERBREAD) @Override public void onCreate(Application context) { mApplication = (CoreApplication) context; mDefaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(this); mSessionService = (SessionService) mApplication.getAppService(AppService.SESSION_SERVICE); final ConfigService configService = (ConfigService) mApplication.getAppService(AppService.CONFIG_SERVICE); mCrashDir = configService.getFileDir("crash").getAbsolutePath(); final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); FileUtils.newFolder(mCrashDir); StrictMode.setThreadPolicy(oldPolicy); }
Example 13
Source File: EarlyTraceEvent.java From cronet with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** @see TraceEvent#MaybeEnableEarlyTracing(). */ static void maybeEnable() { ThreadUtils.assertOnUiThread(); if (sState != STATE_DISABLED) return; boolean shouldEnable = false; // Checking for the trace config filename touches the disk. StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { if (CommandLine.getInstance().hasSwitch("trace-startup")) { shouldEnable = true; } else { try { shouldEnable = (new File(TRACE_CONFIG_FILENAME)).exists(); } catch (SecurityException e) { // Access denied, not enabled. } } if (ContextUtils.getAppSharedPreferences().getBoolean( BACKGROUND_STARTUP_TRACING_ENABLED_KEY, false)) { if (shouldEnable) { // If user has enabled tracing, then force disable background tracing for this // session. setBackgroundStartupTracingFlag(false); sCachedBackgroundStartupTracingFlag = false; } else { sCachedBackgroundStartupTracingFlag = true; shouldEnable = true; } } } finally { StrictMode.setThreadPolicy(oldPolicy); } if (shouldEnable) enable(); }
Example 14
Source File: ChromeWebApkHost.java From 365browser with Apache License 2.0 | 5 votes |
/** * Check the cached value to figure out if the feature is enabled. We have to use the cached * value because native library may not yet been loaded. * @return Whether the feature is enabled. */ private static boolean isEnabledInPrefs() { // Will go away once the feature is enabled for everyone by default. StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { return ChromePreferenceManager.getInstance().getCachedWebApkRuntimeEnabled(); } finally { StrictMode.setThreadPolicy(oldPolicy); } }
Example 15
Source File: ExternalAuthUtils.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * 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); } }
Example 16
Source File: ChromeLauncherActivity.java From 365browser with Apache License 2.0 | 5 votes |
/** * Figure out how to route the Intent. Because this is on the critical path to startup, please * avoid making the pathway any more complicated than it already is. Make sure that anything * you add _absolutely has_ to be here. */ @Override public void onCreate(Bundle savedInstanceState) { // Third-party code adds disk access to Activity.onCreate. http://crbug.com/619824 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); TraceEvent.begin("ChromeLauncherActivity.onCreate"); try { super.onCreate(savedInstanceState); doOnCreate(savedInstanceState); } finally { StrictMode.setThreadPolicy(oldPolicy); TraceEvent.end("ChromeLauncherActivity.onCreate"); } }
Example 17
Source File: Locales.java From firefox-echo-show with Mozilla Public License 2.0 | 5 votes |
/** * Is only required by locale aware activities, AND Application. In most cases you should be * using LocaleAwareAppCompatActivity or friends. * @param context */ public static void initializeLocale(Context context) { final LocaleManager localeManager = LocaleManager.getInstance(); final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads(); StrictMode.allowThreadDiskWrites(); try { localeManager.getAndApplyPersistedLocale(context); } finally { StrictMode.setThreadPolicy(savedPolicy); } }
Example 18
Source File: SettingsStore.java From FirefoxReality with Mozilla Public License 2.0 | 5 votes |
public boolean isTelemetryEnabled() { // The first access to shared preferences will require a disk read. final StrictMode.ThreadPolicy threadPolicy = StrictMode.allowThreadDiskReads(); try { return mPrefs.getBoolean( mContext.getString(R.string.settings_key_telemetry), TELEMETRY_DEFAULT); } finally { StrictMode.setThreadPolicy(threadPolicy); } }
Example 19
Source File: InstantAppsHandler.java From 365browser with Apache License 2.0 | 5 votes |
/** @return Whether Chrome is the default browser on the device. */ private boolean isChromeDefaultHandler(Context context) { StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { return ChromePreferenceManager.getInstance().getCachedChromeDefaultBrowser(); } finally { StrictMode.setThreadPolicy(oldPolicy); } }
Example 20
Source File: DataReductionPromoInfoBar.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** * Launch the data reduction infobar promo, if it needs to be displayed. * * @param context An Android context. * @param webContents The WebContents of the tab on which the infobar should show. * @param url The URL of the page on which the infobar should show. * @param isFragmentNavigation Whether the main frame navigation did not cause changes to the * document (for example scrolling to a named anchor PopState). * @param statusCode The HTTP status code of the navigation. * @return boolean Whether the promo was launched. */ public static boolean maybeLaunchPromoInfoBar(Context context, WebContents webContents, String url, boolean isErrorPage, boolean isFragmentNavigation, int statusCode) { ThreadUtils.assertOnUiThread(); if (webContents.isIncognito()) return false; if (isErrorPage) return false; if (isFragmentNavigation) return false; if (statusCode != HttpURLConnection.HTTP_OK) return false; if (!DataReductionPromoUtils.canShowPromos()) return false; // Don't show the infobar promo if neither the first run experience or second run promo has // been shown. if (!DataReductionPromoUtils.getDisplayedFreOrSecondRunPromo()) return false; // Don't show the promo if the user opted out on the first run experience promo. if (DataReductionPromoUtils.getOptedOutOnFrePromo()) return false; // Don't show the promo if the user has seen this infobar promo before. if (DataReductionPromoUtils.getDisplayedInfoBarPromo()) return false; // Only show the promo on HTTP pages. if (!GURLUtils.getScheme(url).concat("://").equals(UrlConstants.HTTP_SCHEME)) return false; int currentMilestone = VersionNumberGetter.getMilestoneFromVersionNumber( PrefServiceBridge.getInstance().getAboutVersionStrings().getApplicationVersion()); String freOrSecondRunVersion = DataReductionPromoUtils.getDisplayedFreOrSecondRunPromoVersion(); // Temporarily allowing disk access. TODO: Fix. See http://crbug.com/577185 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { Calendar releaseDateOfM48Stable = Calendar.getInstance(TimeZone.getTimeZone("UTC")); releaseDateOfM48Stable.setTime(Date.valueOf(M48_STABLE_RELEASE_DATE)); long packageInstallTime = getPackageInstallTime(context); // The boolean pref that stores whether user opted out on the first run experience was // added in M51. If the last promo was shown before M51, then |freOrSecondRunVersion| // will be empty. If Chrome was installed after the FRE promo was added in M48 and // beforeM51,assume the user opted out from the FRE and don't show the infobar. if (freOrSecondRunVersion.isEmpty() && packageInstallTime > releaseDateOfM48Stable.getTimeInMillis()) { return false; } // Only show the promo if the current version is at least two milestones after the last // promo was displayed or the command line switch is on. If the last promo was shown // before M51 then |freOrSecondRunVersion| will be empty and it is safe to show the // infobar promo. if (!CommandLine.getInstance().hasSwitch(ENABLE_INFOBAR_SWITCH) && !freOrSecondRunVersion.isEmpty() && currentMilestone < VersionNumberGetter .getMilestoneFromVersionNumber(freOrSecondRunVersion) + 2) { return false; } DataReductionPromoInfoBar.launch(webContents, BitmapFactory.decodeResource(context.getResources(), R.drawable.infobar_chrome), context.getString(R.string.data_reduction_promo_infobar_title), context.getString(R.string.data_reduction_promo_infobar_text), context.getString(R.string.data_reduction_promo_infobar_button), context.getString(R.string.no_thanks)); return true; } finally { StrictMode.setThreadPolicy(oldPolicy); } }