本文整理汇总了Java中android.os.StrictMode.allowThreadDiskWrites方法的典型用法代码示例。如果您正苦于以下问题:Java StrictMode.allowThreadDiskWrites方法的具体用法?Java StrictMode.allowThreadDiskWrites怎么用?Java StrictMode.allowThreadDiskWrites使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.StrictMode
的用法示例。
在下文中一共展示了StrictMode.allowThreadDiskWrites方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveState
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* 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);
// Temporarily allowing disk access while fixing. TODO: http://crbug.com/525781
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
StrictMode.allowThreadDiskWrites();
try {
long time = SystemClock.elapsedRealtime();
TabState.saveState(tabFile, getActivityTab().getState(), false);
RecordHistogram.recordTimesHistogram("Android.StrictMode.WebappSaveState",
SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
示例2: 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);
}
}
示例3: startActivityIfNeeded
import android.os.StrictMode; //导入方法依赖的package包/类
@Override
public boolean startActivityIfNeeded(Intent intent, boolean proxy) {
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);
if (proxy) {
dispatchAuthenticatedIntent(intent);
activityWasLaunched = true;
} else {
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) {
IntentUtils.logTransactionTooLargeOrRethrow(e, intent);
return false;
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:29,代码来源:ExternalNavigationDelegateImpl.java
示例4: 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);
}
}
示例5: getWidgetState
import android.os.StrictMode; //导入方法依赖的package包/类
@SuppressLint("DefaultLocale")
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);
}
}
示例6: createVrShell
import android.os.StrictMode; //导入方法依赖的package包/类
private boolean createVrShell() {
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
StrictMode.allowThreadDiskWrites();
try {
Constructor<?> vrShellConstructor = mVrShellClass.getConstructor(Activity.class);
mVrShell = (VrShell) vrShellConstructor.newInstance(mActivity);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException e) {
Log.e(TAG, "Unable to instantiate VrShell", e);
return false;
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
return true;
}
示例7: 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();
}
示例8: initializeLocale
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* 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);
}
}
示例9: openCurrentUrlInBrowser
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* Opens the URL currently being displayed in the Custom Tab in the regular browser.
* @param forceReparenting Whether tab reparenting should be forced for testing.
*
* @return Whether or not the tab was sent over successfully.
*/
boolean openCurrentUrlInBrowser(boolean forceReparenting) {
Tab tab = getActivityTab();
if (tab == null) return false;
String url = tab.getUrl();
if (DomDistillerUrlUtils.isDistilledPage(url)) {
url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url);
}
if (TextUtils.isEmpty(url)) url = getUrlToLoad();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false);
boolean willChromeHandleIntent = getIntentDataProvider().isOpenedByChrome();
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
StrictMode.allowThreadDiskWrites();
try {
willChromeHandleIntent |= ExternalNavigationDelegateImpl
.willChromeHandleIntent(this, intent, true);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
Bundle startActivityOptions = ActivityOptionsCompat.makeCustomAnimation(
this, R.anim.abc_fade_in, R.anim.abc_fade_out).toBundle();
if (willChromeHandleIntent || forceReparenting) {
Runnable finalizeCallback = new Runnable() {
@Override
public void run() {
finishAndClose(true);
}
};
mMainTab = null;
tab.detachAndStartReparenting(intent, startActivityOptions, finalizeCallback);
} else {
// Temporarily allowing disk access while fixing. TODO: http://crbug.com/581860
StrictMode.allowThreadDiskReads();
StrictMode.allowThreadDiskWrites();
try {
startActivity(intent, startActivityOptions);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
return true;
}
示例10: setContentView
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* This function builds the {@link CompositorViewHolder}. Subclasses *must* call
* super.setContentView() before using {@link #getTabModelSelector()} or
* {@link #getCompositorViewHolder()}.
*/
@Override
protected final void setContentView() {
final long begin = SystemClock.elapsedRealtime();
TraceEvent.begin("onCreate->setContentView()");
enableHardwareAcceleration();
setLowEndTheme();
int controlContainerLayoutId = getControlContainerLayoutId();
WarmupManager warmupManager = WarmupManager.getInstance();
if (warmupManager.hasViewHierarchyWithToolbar(controlContainerLayoutId)) {
View placeHolderView = new View(this);
setContentView(placeHolderView);
ViewGroup contentParent = (ViewGroup) placeHolderView.getParent();
warmupManager.transferViewHierarchyTo(contentParent);
contentParent.removeView(placeHolderView);
} else {
warmupManager.clearViewHierarchy();
// Allow disk access for the content view and toolbar container setup.
// On certain android devices this setup sequence results in disk writes outside
// of our control, so we have to disable StrictMode to work. See crbug.com/639352.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
setContentView(R.layout.main);
if (controlContainerLayoutId != NO_CONTROL_CONTAINER) {
ViewStub toolbarContainerStub =
((ViewStub) findViewById(R.id.control_container_stub));
toolbarContainerStub.setLayoutResource(controlContainerLayoutId);
toolbarContainerStub.inflate();
}
// It cannot be assumed that the result of toolbarContainerStub.inflate() will be
// the control container since it may be wrapped in another view.
ControlContainer controlContainer =
(ControlContainer) findViewById(R.id.control_container);
// Inflate the correct toolbar layout for the device.
int toolbarLayoutId = getToolbarLayoutId();
if (toolbarLayoutId != NO_TOOLBAR_LAYOUT && controlContainer != null) {
controlContainer.initWithToolbar(toolbarLayoutId);
}
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
TraceEvent.end("onCreate->setContentView()");
mInflateInitialLayoutDurationMs = SystemClock.elapsedRealtime() - begin;
// Set the status bar color to black by default. This is an optimization for
// Chrome not to draw under status and navigation bars when we use the default
// black status bar
ApiCompatibilityUtils.setStatusBarColor(getWindow(), Color.BLACK);
ViewGroup rootView = (ViewGroup) getWindow().getDecorView().getRootView();
mCompositorViewHolder = (CompositorViewHolder) findViewById(R.id.compositor_view_holder);
mCompositorViewHolder.setRootView(rootView);
// Setting fitsSystemWindows to false ensures that the root view doesn't consume the insets.
rootView.setFitsSystemWindows(false);
// Add a custom view right after the root view that stores the insets to access later.
// ContentViewCore needs the insets to determine the portion of the screen obscured by
// non-content displaying things such as the OSK.
mInsetObserverView = InsetObserverView.create(this);
rootView.addView(mInsetObserverView, 0);
}
示例11: launchTabbedMode
import android.os.StrictMode; //导入方法依赖的package包/类
/**
* Handles launching a {@link ChromeTabbedActivity}.
* @param skipFre Whether skip the First Run Experience in ChromeTabbedActivity.
*/
@SuppressLint("InlinedApi")
private void launchTabbedMode(boolean skipFre) {
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();
boolean isContentScheme = false;
if (uri != null && "content".equals(uri.getScheme())) {
isContentScheme = true;
newIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
if (mIsInLegacyMultiInstanceMode) {
MultiWindowUtils.getInstance().makeLegacyMultiInstanceIntent(this, newIntent);
}
if (skipFre) {
newIntent.putExtra(FirstRunFlowSequencer.SKIP_FIRST_RUN_EXPERIENCE, 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);
} catch (SecurityException ex) {
if (isContentScheme) {
Toast.makeText(
this, R.string.external_app_restricted_access_error,
Toast.LENGTH_LONG).show();
} else {
throw ex;
}
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
示例12: allowThreadDiskWrites
import android.os.StrictMode; //导入方法依赖的package包/类
@Override
public StrictMode.ThreadPolicy allowThreadDiskWrites() {
return StrictMode.allowThreadDiskWrites();
}