Commit 043f5431 authored by torne's avatar torne Committed by Commit bot

Clean up StrictMode.allowThreadDiskReads calls.

allowThreadDiskWrites also allows reads, so it's not necessary to call
both together. Remove all the redundant allowThreadDiskReads calls.

BUG=

Review-Url: https://codereview.chromium.org/2851473007
Cr-Commit-Position: refs/heads/master@{#468050}
parent 4e899699
...@@ -68,8 +68,7 @@ public abstract class PathUtils { ...@@ -68,8 +68,7 @@ public abstract class PathUtils {
// already finished. // already finished.
if (sDirPathFetchTask.cancel(false)) { if (sDirPathFetchTask.cancel(false)) {
// Allow disk access here because we have no other choice. // Allow disk access here because we have no other choice.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
try { try {
// sDirPathFetchTask did not complete. We have to run the code it was supposed // sDirPathFetchTask did not complete. We have to run the code it was supposed
// to be responsible for synchronously on the UI thread. // to be responsible for synchronously on the UI thread.
......
...@@ -65,8 +65,7 @@ public class LauncherShortcutActivity extends Activity { ...@@ -65,8 +65,7 @@ public class LauncherShortcutActivity extends Activity {
} }
// This system call is often modified by OEMs and not actionable. http://crbug.com/619646. // This system call is often modified by OEMs and not actionable. http://crbug.com/619646.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
try { try {
startActivity(newIntent); startActivity(newIntent);
} finally { } finally {
......
...@@ -84,8 +84,7 @@ public class BookmarkWidgetService extends RemoteViewsService { ...@@ -84,8 +84,7 @@ public class BookmarkWidgetService extends RemoteViewsService {
// TODO(crbug.com/635567): Fix this properly. // TODO(crbug.com/635567): Fix this properly.
@SuppressLint("DefaultLocale") @SuppressLint("DefaultLocale")
static SharedPreferences getWidgetState(Context context, int widgetId) { static SharedPreferences getWidgetState(Context context, int widgetId) {
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
try { try {
return context.getSharedPreferences( return context.getSharedPreferences(
String.format("widgetState-%d", widgetId), String.format("widgetState-%d", widgetId),
......
...@@ -215,8 +215,7 @@ public class ContextualSearchQuickActionControl extends ViewResourceInflater { ...@@ -215,8 +215,7 @@ public class ContextualSearchQuickActionControl extends ViewResourceInflater {
// On KitKat, calling PackageManager#resolveActivity() causes disk reads and writes. // On KitKat, calling PackageManager#resolveActivity() causes disk reads and writes.
// Temporarily allow this while resolving the intent. // Temporarily allow this while resolving the intent.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
try { try {
possibleDefaultActivity = packageManager.resolveActivity(mIntent, 0); possibleDefaultActivity = packageManager.resolveActivity(mIntent, 0);
} finally { } finally {
......
...@@ -1019,8 +1019,7 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -1019,8 +1019,7 @@ public class CustomTabActivity extends ChromeActivity {
intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false); intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false);
boolean willChromeHandleIntent = getIntentDataProvider().isOpenedByChrome(); boolean willChromeHandleIntent = getIntentDataProvider().isOpenedByChrome();
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
try { try {
willChromeHandleIntent |= ExternalNavigationDelegateImpl willChromeHandleIntent |= ExternalNavigationDelegateImpl
.willChromeHandleIntent(intent, true); .willChromeHandleIntent(intent, true);
...@@ -1046,7 +1045,6 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -1046,7 +1045,6 @@ public class CustomTabActivity extends ChromeActivity {
tab.detachAndStartReparenting(intent, startActivityOptions, finalizeCallback); tab.detachAndStartReparenting(intent, startActivityOptions, finalizeCallback);
} else { } else {
// Temporarily allowing disk access while fixing. TODO: http://crbug.com/581860 // Temporarily allowing disk access while fixing. TODO: http://crbug.com/581860
StrictMode.allowThreadDiskReads();
StrictMode.allowThreadDiskWrites(); StrictMode.allowThreadDiskWrites();
try { try {
if (mIntentDataProvider.isInfoPage()) { if (mIntentDataProvider.isInfoPage()) {
......
...@@ -77,8 +77,7 @@ public class CustomTabTabPersistencePolicy implements TabPersistencePolicy { ...@@ -77,8 +77,7 @@ public class CustomTabTabPersistencePolicy implements TabPersistencePolicy {
if (sStateDirectory == null) { if (sStateDirectory == null) {
sStateDirectory = new File( sStateDirectory = new File(
TabPersistentStore.getOrCreateBaseStateDirectory(), SAVED_STATE_DIRECTORY); TabPersistentStore.getOrCreateBaseStateDirectory(), SAVED_STATE_DIRECTORY);
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
try { try {
if (!sStateDirectory.exists() && !sStateDirectory.mkdirs()) { if (!sStateDirectory.exists() && !sStateDirectory.mkdirs()) {
Log.e(TAG, "Failed to create state folder: " + sStateDirectory); Log.e(TAG, "Failed to create state folder: " + sStateDirectory);
......
...@@ -418,8 +418,7 @@ public class ChromeLauncherActivity extends Activity ...@@ -418,8 +418,7 @@ public class ChromeLauncherActivity extends Activity
} }
// This system call is often modified by OEMs and not actionable. http://crbug.com/619646. // This system call is often modified by OEMs and not actionable. http://crbug.com/619646.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
try { try {
startActivity(newIntent); startActivity(newIntent);
} catch (SecurityException ex) { } catch (SecurityException ex) {
......
...@@ -262,8 +262,7 @@ public class ExternalAuthUtils { ...@@ -262,8 +262,7 @@ public class ExternalAuthUtils {
*/ */
protected int checkGooglePlayServicesAvailable(final Context context) { protected int checkGooglePlayServicesAvailable(final Context context) {
// Temporarily allowing disk access. TODO: Fix. See http://crbug.com/577190 // Temporarily allowing disk access. TODO: Fix. See http://crbug.com/577190
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
try { try {
long time = SystemClock.elapsedRealtime(); long time = SystemClock.elapsedRealtime();
int isAvailable = int isAvailable =
......
...@@ -343,7 +343,6 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat ...@@ -343,7 +343,6 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat
boolean activityWasLaunched; boolean activityWasLaunched;
// Only touches disk on Kitkat. See http://crbug.com/617725 for more context. // Only touches disk on Kitkat. See http://crbug.com/617725 for more context.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskReads();
try { try {
forcePdfViewerAsIntentHandlerIfNeeded(intent); forcePdfViewerAsIntentHandlerIfNeeded(intent);
if (proxy) { if (proxy) {
......
...@@ -105,8 +105,7 @@ public class CustomNotificationBuilder extends NotificationBuilderBase { ...@@ -105,8 +105,7 @@ public class CustomNotificationBuilder extends NotificationBuilderBase {
String formattedTime = ""; String formattedTime = "";
// Temporarily allowing disk access. TODO: Fix. See http://crbug.com/577185 // Temporarily allowing disk access. TODO: Fix. See http://crbug.com/577185
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
try { try {
long time = SystemClock.elapsedRealtime(); long time = SystemClock.elapsedRealtime();
formattedTime = DateFormat.getTimeFormat(mContext).format(new Date()); formattedTime = DateFormat.getTimeFormat(mContext).format(new Date());
......
...@@ -120,8 +120,7 @@ public class ManageSpaceActivity extends AppCompatActivity implements View.OnCli ...@@ -120,8 +120,7 @@ public class ManageSpaceActivity extends AppCompatActivity implements View.OnCli
// Allow reading/writing to disk to check whether the last attempt was successful before // Allow reading/writing to disk to check whether the last attempt was successful before
// kicking off the browser process initialization. // kicking off the browser process initialization.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
try { try {
String productVersion = AboutChromePreferences.getApplicationVersion( String productVersion = AboutChromePreferences.getApplicationVersion(
this, ChromeVersionInfo.getProductVersion()); this, ChromeVersionInfo.getProductVersion());
......
...@@ -134,8 +134,7 @@ public class TabbedModeTabPersistencePolicy implements TabPersistencePolicy { ...@@ -134,8 +134,7 @@ public class TabbedModeTabPersistencePolicy implements TabPersistencePolicy {
if (sStateDirectory == null) { if (sStateDirectory == null) {
sStateDirectory = new File( sStateDirectory = new File(
TabPersistentStore.getOrCreateBaseStateDirectory(), SAVED_STATE_DIRECTORY); TabPersistentStore.getOrCreateBaseStateDirectory(), SAVED_STATE_DIRECTORY);
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
try { try {
if (!sStateDirectory.exists() && !sStateDirectory.mkdirs()) { if (!sStateDirectory.exists() && !sStateDirectory.mkdirs()) {
Log.e(TAG, "Failed to create state folder: " + sStateDirectory); Log.e(TAG, "Failed to create state folder: " + sStateDirectory);
......
...@@ -82,10 +82,9 @@ public class VrDaydreamApiImpl implements VrDaydreamApi { ...@@ -82,10 +82,9 @@ public class VrDaydreamApiImpl implements VrDaydreamApi {
public Boolean isDaydreamCurrentViewer() { public Boolean isDaydreamCurrentViewer() {
DaydreamApi daydreamApi = DaydreamApi.create(mContext); DaydreamApi daydreamApi = DaydreamApi.create(mContext);
if (daydreamApi == null) return false; if (daydreamApi == null) return false;
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
// If this is the first time any app reads the daydream config file, daydream may create its // If this is the first time any app reads the daydream config file, daydream may create its
// config directory... crbug.com/686104 // config directory... crbug.com/686104
StrictMode.allowThreadDiskWrites(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
int type = GvrApi.ViewerType.CARDBOARD; int type = GvrApi.ViewerType.CARDBOARD;
try { try {
type = daydreamApi.getCurrentViewerType(); type = daydreamApi.getCurrentViewerType();
......
...@@ -208,8 +208,7 @@ public class WebappActivity extends FullScreenActivity { ...@@ -208,8 +208,7 @@ public class WebappActivity extends FullScreenActivity {
File tabFile = new File(activityDirectory, tabFileName); File tabFile = new File(activityDirectory, tabFileName);
// Temporarily allowing disk access while fixing. TODO: http://crbug.com/525781 // Temporarily allowing disk access while fixing. TODO: http://crbug.com/525781
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
try { try {
long time = SystemClock.elapsedRealtime(); long time = SystemClock.elapsedRealtime();
TabState.saveState(tabFile, getActivityTab().getState(), false); TabState.saveState(tabFile, getActivityTab().getState(), false);
......
...@@ -160,8 +160,7 @@ public class WebappDirectoryManager { ...@@ -160,8 +160,7 @@ public class WebappDirectoryManager {
*/ */
File getWebappDirectory(Context context, String webappId) { File getWebappDirectory(Context context, String webappId) {
// Temporarily allowing disk access while fixing. TODO: http://crbug.com/525781 // Temporarily allowing disk access while fixing. TODO: http://crbug.com/525781
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
try { try {
long time = SystemClock.elapsedRealtime(); long time = SystemClock.elapsedRealtime();
File webappDirectory = new File(getBaseWebappDirectory(context), webappId); File webappDirectory = new File(getBaseWebappDirectory(context), webappId);
......
...@@ -134,8 +134,7 @@ public abstract class CastTestBase extends ChromeActivityTestCaseBase<ChromeActi ...@@ -134,8 +134,7 @@ public abstract class CastTestBase extends ChromeActivityTestCaseBase<ChromeActi
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
mOldPolicy = StrictMode.allowThreadDiskReads(); mOldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
} }
}); });
mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext()); mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
......
...@@ -81,8 +81,7 @@ public class MediaRouterIntegrationTest extends ChromeActivityTestCaseBase<Chrom ...@@ -81,8 +81,7 @@ public class MediaRouterIntegrationTest extends ChromeActivityTestCaseBase<Chrom
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
mOldPolicy = StrictMode.allowThreadDiskReads(); mOldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
} }
}); });
mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext()); mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
......
...@@ -91,8 +91,7 @@ public class ShapeDetectionTest extends ChromeActivityTestCaseBase<ChromeActivit ...@@ -91,8 +91,7 @@ public class ShapeDetectionTest extends ChromeActivityTestCaseBase<ChromeActivit
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
mOldPolicy = StrictMode.allowThreadDiskReads(); mOldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
} }
}); });
} }
......
...@@ -52,8 +52,7 @@ public class MockStorageDelegate extends StorageDelegate { ...@@ -52,8 +52,7 @@ public class MockStorageDelegate extends StorageDelegate {
@Override @Override
public File getStateDirectory() { public File getStateDirectory() {
// This is a test class, allowing StrictMode violations. // This is a test class, allowing StrictMode violations.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
try { try {
if (!mStateDirectory.exists() && !mStateDirectory.mkdirs()) { if (!mStateDirectory.exists() && !mStateDirectory.mkdirs()) {
Assert.fail("Failed to create state directory. Tests should fail."); Assert.fail("Failed to create state directory. Tests should fail.");
......
...@@ -151,8 +151,7 @@ public class UiUtils { ...@@ -151,8 +151,7 @@ public class UiUtils {
Context.INPUT_METHOD_SERVICE); Context.INPUT_METHOD_SERVICE);
// Third-party touches disk on showSoftInput call. http://crbug.com/619824, // Third-party touches disk on showSoftInput call. http://crbug.com/619824,
// http://crbug.com/635118 // http://crbug.com/635118
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.allowThreadDiskWrites();
try { try {
imm.showSoftInput(view, 0); imm.showSoftInput(view, 0);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment