本文整理汇总了Java中android.os.StrictMode.allowThreadDiskReads方法的典型用法代码示例。如果您正苦于以下问题:Java StrictMode.allowThreadDiskReads方法的具体用法?Java StrictMode.allowThreadDiskReads怎么用?Java StrictMode.allowThreadDiskReads使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.StrictMode
的用法示例。
在下文中一共展示了StrictMode.allowThreadDiskReads方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCoreCountPre17
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* Determines the number of cores available on the device (pre-v17).
*
* <p>Before Jellybean, {@link Runtime#availableProcessors()} returned the number of awake cores,
* which may not be the number of available cores depending on the device's current state. See
* https://stackoverflow.com/a/30150409.
*
* @return the maximum number of processors available to the VM; never smaller than one
*/
@SuppressWarnings("PMD")
private static int getCoreCountPre17() {
// We override the current ThreadPolicy to allow disk reads.
// This shouldn't actually do disk-IO and accesses a device file.
// See: https://github.com/bumptech/glide/issues/1170
File[] cpus = null;
ThreadPolicy originalPolicy = StrictMode.allowThreadDiskReads();
try {
File cpuInfo = new File(CPU_LOCATION);
final Pattern cpuNamePattern = Pattern.compile(CPU_NAME_REGEX);
cpus = cpuInfo.listFiles(new FilenameFilter() {
@Override
public boolean accept(File file, String s) {
return cpuNamePattern.matcher(s).matches();
}
});
} catch (Throwable t) {
if (Log.isLoggable(TAG, Log.ERROR)) {
Log.e(TAG, "Failed to calculate accurate cpu count", t);
}
} finally {
StrictMode.setThreadPolicy(originalPolicy);
}
return Math.max(1, cpus != null ? cpus.length : 0);
}
示例2: getPackageLabel
import android.os.StrictMode; //导入方法依赖的package包/类
@CalledByNative
public static String getPackageLabel(Context context) {
// Third-party code does disk read on the getApplicationInfo call. http://crbug.com/614343
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
PackageManager packageManager = context.getPackageManager();
ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(),
PackageManager.GET_META_DATA);
CharSequence label = packageManager.getApplicationLabel(appInfo);
return label != null ? label.toString() : "";
} catch (NameNotFoundException e) {
return "";
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
示例3: preInflationStartup
import android.os.StrictMode; //导入方法依赖的package包/类
@Override
public void preInflationStartup() {
WebappInfo info = createWebappInfo(getIntent());
String id = "";
if (info != null) {
mWebappInfo = info;
id = info.id();
}
// Initialize the WebappRegistry and warm up the shared preferences for this web app. No-ops
// if the registry and this web app are already initialized. Must override Strict Mode to
// avoid a violation.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
WebappRegistry.getInstance();
WebappRegistry.warmUpSharedPrefsForId(id);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
ScreenOrientationProvider.lockOrientation(getWindowAndroid(),
(byte) mWebappInfo.orientation(), this);
super.preInflationStartup();
}
示例4: startChromeBrowserProcessesSync
import android.os.StrictMode; //导入方法依赖的package包/类
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();
StrictMode.setThreadPolicy(oldPolicy);
libraryLoader.asyncPrefetchLibrariesToMemory();
BrowserStartupController.get(mApplication, LibraryProcessType.PROCESS_BROWSER)
.startBrowserProcessesSync(false);
GoogleServicesManager.get(mApplication);
} finally {
TraceEvent.end("ChromeBrowserInitializer.startChromeBrowserProcessesSync");
}
}
示例5: getWebappDirectory
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* 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);
}
}
示例6: getUriForItem
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* 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;
// #getContentUriFromFile 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();
try {
// Try to obtain a content:// URI, which is preferred to a file:// URI so that
// receiving apps don't attempt to determine the file's mime type (which often fails).
uri = ContentUriUtils.getContentUriFromFile(ContextUtils.getApplicationContext(), file);
} catch (IllegalArgumentException e) {
Log.e(TAG, "Could not create content uri: " + e);
}
StrictMode.setThreadPolicy(oldPolicy);
if (uri == null) uri = Uri.fromFile(file);
return uri;
}
示例7: hasOAuth2RefreshToken
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* 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);
}
}
示例8: onInitializeAccessibilityNodeInfo
import android.os.StrictMode; //导入方法依赖的package包/类
@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);
}
if (mAccessibilityTextOverride != null) {
info.setText(mAccessibilityTextOverride);
}
}
示例9: isEnabled
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* Check the cached value to figure out if the feature is enabled. We have to use the cached
* value because native library hasn't yet been loaded.
* @param context The application context.
* @return Whether the feature is enabled.
*/
protected boolean isEnabled(Context context) {
// Will go away once the feature is enabled for everyone by default.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
return ChromePreferenceManager.getInstance(context).getCachedInstantAppsEnabled();
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
示例10: dispatchIntentOnUIThread
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* 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);
}
}
示例11: checkGooglePlayServicesAvailable
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* 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);
}
}
示例12: waitForPendingStateChangeTask
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* Waits for any pending state change operations to be completed.
*
* This will avoid timing issues described here: crbug.com/649453.
*/
private static void waitForPendingStateChangeTask() {
ThreadUtils.assertOnUiThread();
if (sStateChangeTask == null) return;
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
sStateChangeTask.get();
sStateChangeTask = null;
} catch (InterruptedException | ExecutionException e) {
Log.e(TAG, "Print state change task did not complete as expected");
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
示例13: isOptedOutOfDocumentMode
import android.os.StrictMode; //导入方法依赖的package包/类
/** @return True if the user is not in document mode. */
public static boolean isOptedOutOfDocumentMode() {
// The OPT_OUT_STATE preference was introduced sometime after document mode was rolled out.
// It may not be set for all users, even if they are in document mode. In order to correctly
// detect whether the user is in document mode, if OPT_OUT_STATE is not state we must check
// whether MIGRATION_ON_UPGRADE_ATTEMPTED is set.
int optOutState = ContextUtils.getAppSharedPreferences().getInt(OPT_OUT_STATE,
OPT_OUT_STATE_UNSET);
if (optOutState == OPT_OUT_STATE_UNSET) {
boolean hasMigratedToDocumentMode = ContextUtils.getAppSharedPreferences().getBoolean(
MIGRATION_ON_UPGRADE_ATTEMPTED, false);
if (!hasMigratedToDocumentMode) {
optOutState = OPTED_OUT_OF_DOCUMENT_MODE;
} else {
// Check if a migration has already happened by looking for tab_state0 file.
// See crbug.com/646146.
boolean newMetadataFileExists = false;
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
File newMetadataFile = new File(
TabbedModeTabPersistencePolicy.getOrCreateTabbedModeStateDirectory(),
TabbedModeTabPersistencePolicy.getStateFileName(TAB_MODEL_INDEX));
newMetadataFileExists = newMetadataFile.exists();
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
if (newMetadataFileExists) {
optOutState = OPTED_OUT_OF_DOCUMENT_MODE;
} else {
optOutState = OPT_IN_TO_DOCUMENT_MODE;
}
}
setOptedOutState(optOutState);
}
return optOutState == OPTED_OUT_OF_DOCUMENT_MODE;
}
示例14: getNativeGvrContext
import android.os.StrictMode; //导入方法依赖的package包/类
@Override
public long getNativeGvrContext() {
long nativeGvrContext = 0;
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
nativeGvrContext = mGvrLayout.getGvrApi().getNativeGvrContext();
} catch (Exception ex) {
Log.e(TAG, "Unable to instantiate GvrApi", ex);
return 0;
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
return nativeGvrContext;
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:15,代码来源:NonPresentingGvrContextImpl.java
示例15: onCreate
import android.os.StrictMode; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String intentAction = getIntent().getAction();
// Exit early if the original intent action isn't for opening a new tab.
if (!intentAction.equals(ACTION_OPEN_NEW_TAB)
&& !intentAction.equals(ACTION_OPEN_NEW_INCOGNITO_TAB)) {
finish();
return;
}
Intent newIntent = new Intent();
newIntent.setAction(Intent.ACTION_VIEW);
newIntent.setData(Uri.parse(UrlConstants.NTP_URL));
newIntent.setClass(this, ChromeLauncherActivity.class);
newIntent.putExtra(IntentHandler.EXTRA_INVOKED_FROM_SHORTCUT, true);
newIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
newIntent.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
IntentHandler.addTrustedIntentExtras(newIntent, this);
if (intentAction.equals(ACTION_OPEN_NEW_INCOGNITO_TAB)) {
newIntent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
}
// 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);
}
finish();
}