Commit 0ce26a3b authored by Haiyang Pan's avatar Haiyang Pan Committed by Commit Bot

Revert "Android: Remove StrictMode usage from //chrome"

This reverts commit 1de470a5.

Reason for revert: Likely caused a lot of test failure due to StrictMode.
An example build is https://ci.chromium.org/p/chromium/builders/ci/Lollipop%20Phone%20Tester/27067

Original change's description:
> Android: Remove StrictMode usage from //chrome
> 
> Removes direct usage (StrictModeContext left for follow-up)
> 
> These suppressions are safe to remove now that StrictMode handling in
> chrome has been switched to a filter-based approach.
> 
> Bug: 1038384
> Change-Id: I59ee33bd1e34249c6be7973e5d759007ec0b2533
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410537
> Commit-Queue: Andrew Grieve <agrieve@chromium.org>
> Reviewed-by: Peter Kotwicz <pkotwicz@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#809402}

TBR=agrieve@chromium.org,pkotwicz@chromium.org

Change-Id: I6277029a7154c53d2ea1bc0f4d7cc6b9aacb0e62
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1038384
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2424989Reviewed-by: default avatarHaiyang Pan <hypan@google.com>
Commit-Queue: Haiyang Pan <hypan@google.com>
Cr-Commit-Position: refs/heads/master@{#809584}
parent 8b4e8944
...@@ -18,6 +18,7 @@ import android.net.Uri; ...@@ -18,6 +18,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.StrictMode;
import android.provider.Settings; import android.provider.Settings;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -1245,8 +1246,13 @@ public class VrShellDelegate ...@@ -1245,8 +1246,13 @@ public class VrShellDelegate
assert (VrCoreInstallUtils.getVrSupportLevel() == VrSupportLevel.VR_DAYDREAM assert (VrCoreInstallUtils.getVrSupportLevel() == VrSupportLevel.VR_DAYDREAM
|| !mStartedFromVrIntent); || !mStartedFromVrIntent);
if (mNativeVrShellDelegate != 0) { StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
VrShellDelegateJni.get().onResume(mNativeVrShellDelegate, VrShellDelegate.this); try {
if (mNativeVrShellDelegate != 0) {
VrShellDelegateJni.get().onResume(mNativeVrShellDelegate, VrShellDelegate.this);
}
} finally {
StrictMode.setThreadPolicy(oldPolicy);
} }
// Perform slow initialization asynchronously. // Perform slow initialization asynchronously.
...@@ -1569,11 +1575,13 @@ public class VrShellDelegate ...@@ -1569,11 +1575,13 @@ public class VrShellDelegate
if (mActivity.getCompositorViewHolder() == null) return false; if (mActivity.getCompositorViewHolder() == null) return false;
TabModelSelector tabModelSelector = mActivity.getTabModelSelector(); TabModelSelector tabModelSelector = mActivity.getTabModelSelector();
if (tabModelSelector == null) return false; if (tabModelSelector == null) return false;
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try { try {
mVrShell = new VrShell(mActivity, this, tabModelSelector); mVrShell = new VrShell(mActivity, this, tabModelSelector);
} catch (VrUnsupportedException e) { } catch (VrUnsupportedException e) {
return false; return false;
} finally { } finally {
StrictMode.setThreadPolicy(oldPolicy);
} }
return true; return true;
} }
......
...@@ -13,6 +13,7 @@ import android.content.Intent; ...@@ -13,6 +13,7 @@ import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.StrictMode;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
...@@ -409,6 +410,7 @@ public class LaunchIntentDispatcher implements IntentHandler.IntentHandlerDelega ...@@ -409,6 +410,7 @@ public class LaunchIntentDispatcher implements IntentHandler.IntentHandlerDelega
} }
// 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.allowThreadDiskWrites();
try { try {
Bundle options = mIsVrIntent Bundle options = mIsVrIntent
? VrModuleProvider.getIntentDelegate().getVrIntentOptions(mActivity) ? VrModuleProvider.getIntentDelegate().getVrIntentOptions(mActivity)
...@@ -423,6 +425,8 @@ public class LaunchIntentDispatcher implements IntentHandler.IntentHandlerDelega ...@@ -423,6 +425,8 @@ public class LaunchIntentDispatcher implements IntentHandler.IntentHandlerDelega
} else { } else {
throw ex; throw ex;
} }
} finally {
StrictMode.setThreadPolicy(oldPolicy);
} }
return Action.FINISH_ACTIVITY; return Action.FINISH_ACTIVITY;
......
...@@ -13,6 +13,7 @@ import android.content.pm.ShortcutManager; ...@@ -13,6 +13,7 @@ import android.content.pm.ShortcutManager;
import android.graphics.drawable.Icon; import android.graphics.drawable.Icon;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.StrictMode;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
...@@ -51,7 +52,15 @@ public class LauncherShortcutActivity extends Activity { ...@@ -51,7 +52,15 @@ public class LauncherShortcutActivity extends Activity {
} }
Intent newIntent = getChromeLauncherActivityIntent(this, intentAction); Intent newIntent = getChromeLauncherActivityIntent(this, intentAction);
startActivity(newIntent);
// This system call is often modified by OEMs and not actionable. http://crbug.com/619646.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
startActivity(newIntent);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
finish(); finish();
} }
......
...@@ -11,6 +11,7 @@ import android.content.SharedPreferences; ...@@ -11,6 +11,7 @@ import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.StrictMode;
import android.text.TextUtils; import android.text.TextUtils;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import android.widget.RemoteViewsService; import android.widget.RemoteViewsService;
...@@ -83,8 +84,13 @@ public class BookmarkWidgetService extends RemoteViewsService { ...@@ -83,8 +84,13 @@ public class BookmarkWidgetService extends RemoteViewsService {
} }
static SharedPreferences getWidgetState(int widgetId) { static SharedPreferences getWidgetState(int widgetId) {
return ContextUtils.getApplicationContext().getSharedPreferences( StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
String.format(Locale.US, "widgetState-%d", widgetId), Context.MODE_PRIVATE); try {
return ContextUtils.getApplicationContext().getSharedPreferences(
String.format(Locale.US, "widgetState-%d", widgetId), Context.MODE_PRIVATE);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
} }
static void deleteWidgetState(int widgetId) { static void deleteWidgetState(int widgetId) {
......
...@@ -12,6 +12,7 @@ import android.app.Activity; ...@@ -12,6 +12,7 @@ import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.StrictMode;
import android.os.SystemClock; import android.os.SystemClock;
import android.text.TextUtils; import android.text.TextUtils;
...@@ -240,8 +241,13 @@ public class CustomTabActivityNavigationController implements StartStopWithNativ ...@@ -240,8 +241,13 @@ public class CustomTabActivityNavigationController implements StartStopWithNativ
boolean willChromeHandleIntent = boolean willChromeHandleIntent =
mIntentDataProvider.isOpenedByChrome() || mIntentDataProvider.isIncognito(); mIntentDataProvider.isOpenedByChrome() || mIntentDataProvider.isIncognito();
willChromeHandleIntent |= StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
ExternalNavigationDelegateImpl.willChromeHandleIntent(intent, true); try {
willChromeHandleIntent |=
ExternalNavigationDelegateImpl.willChromeHandleIntent(intent, true);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
Bundle startActivityOptions = ActivityOptionsCompat.makeCustomAnimation( Bundle startActivityOptions = ActivityOptionsCompat.makeCustomAnimation(
mActivity, R.anim.abc_fade_in, R.anim.abc_fade_out).toBundle(); mActivity, R.anim.abc_fade_in, R.anim.abc_fade_out).toBundle();
...@@ -252,10 +258,16 @@ public class CustomTabActivityNavigationController implements StartStopWithNativ ...@@ -252,10 +258,16 @@ public class CustomTabActivityNavigationController implements StartStopWithNativ
mTabController.detachAndStartReparenting(intent, startActivityOptions, mTabController.detachAndStartReparenting(intent, startActivityOptions,
() -> finish(REPARENTING)); () -> finish(REPARENTING));
} else { } else {
if (mIntentDataProvider.isInfoPage()) { // Temporarily allowing disk access while fixing. TODO: http://crbug.com/581860
IntentHandler.startChromeLauncherActivityForTrustedIntent(intent); StrictMode.allowThreadDiskWrites();
} else { try {
mActivity.startActivity(intent, startActivityOptions); if (mIntentDataProvider.isInfoPage()) {
IntentHandler.startChromeLauncherActivityForTrustedIntent(intent);
} else {
mActivity.startActivity(intent, startActivityOptions);
}
} finally {
StrictMode.setThreadPolicy(oldPolicy);
} }
} }
return true; return true;
......
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.document; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.document;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.os.StrictMode;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.TraceEvent; import org.chromium.base.TraceEvent;
...@@ -20,30 +21,35 @@ public class ChromeLauncherActivity extends Activity { ...@@ -20,30 +21,35 @@ public class ChromeLauncherActivity extends Activity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
// Third-party code adds disk access to Activity.onCreate. http://crbug.com/619824 // Third-party code adds disk access to Activity.onCreate. http://crbug.com/619824
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
TraceEvent.begin("ChromeLauncherActivity.onCreate"); TraceEvent.begin("ChromeLauncherActivity.onCreate");
super.onCreate(savedInstanceState); try {
super.onCreate(savedInstanceState);
if (VrModuleProvider.getIntentDelegate().isVrIntent(getIntent())) { if (VrModuleProvider.getIntentDelegate().isVrIntent(getIntent())) {
// We need to turn VR mode on as early as possible in the intent handling flow to // We need to turn VR mode on as early as possible in the intent handling flow to
// avoid brightness flickering when handling VR intents. // avoid brightness flickering when handling VR intents.
VrModuleProvider.getDelegate().setVrModeEnabled(this, true); VrModuleProvider.getDelegate().setVrModeEnabled(this, true);
} }
@LaunchIntentDispatcher.Action @LaunchIntentDispatcher.Action
int dispatchAction = LaunchIntentDispatcher.dispatch(this, getIntent()); int dispatchAction = LaunchIntentDispatcher.dispatch(this, getIntent());
switch (dispatchAction) { switch (dispatchAction) {
case LaunchIntentDispatcher.Action.FINISH_ACTIVITY: case LaunchIntentDispatcher.Action.FINISH_ACTIVITY:
finish(); finish();
break; break;
case LaunchIntentDispatcher.Action.FINISH_ACTIVITY_REMOVE_TASK: case LaunchIntentDispatcher.Action.FINISH_ACTIVITY_REMOVE_TASK:
ApiCompatibilityUtils.finishAndRemoveTask(this); ApiCompatibilityUtils.finishAndRemoveTask(this);
break; break;
default: default:
assert false : "Intent dispatcher finished with action " + dispatchAction assert false : "Intent dispatcher finished with action " + dispatchAction
+ ", finishing anyway"; + ", finishing anyway";
finish(); finish();
break; break;
}
} finally {
StrictMode.setThreadPolicy(oldPolicy);
TraceEvent.end("ChromeLauncherActivity.onCreate");
} }
TraceEvent.end("ChromeLauncherActivity.onCreate");
} }
} }
...@@ -13,6 +13,7 @@ import android.content.pm.PackageInfo; ...@@ -13,6 +13,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.StrictMode;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.MainThread; import androidx.annotation.MainThread;
...@@ -295,13 +296,23 @@ public class DownloadUtils { ...@@ -295,13 +296,23 @@ public class DownloadUtils {
// It's ok to use blocking calls on main thread here, since the user is waiting to open or // It's ok to use blocking calls on main thread here, since the user is waiting to open or
// share the file to other apps. // share the file to other apps.
boolean isOnSDCard = DownloadDirectoryProvider.isDownloadOnSDCard(filePath); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
if (ChromeFeatureList.isEnabled(ChromeFeatureList.DOWNLOAD_FILE_PROVIDER) && isOnSDCard) { Uri uri = null;
// Use custom file provider to generate content URI for download on SD card.
return DownloadFileProvider.createContentUri(filePath); try {
boolean isOnSDCard = DownloadDirectoryProvider.isDownloadOnSDCard(filePath);
if (ChromeFeatureList.isEnabled(ChromeFeatureList.DOWNLOAD_FILE_PROVIDER)
&& isOnSDCard) {
// Use custom file provider to generate content URI for download on SD card.
uri = DownloadFileProvider.createContentUri(filePath);
} else {
// Use FileProvider to generate content URI or file URI.
uri = FileUtils.getUriForFile(new File(filePath));
}
} finally {
StrictMode.setThreadPolicy(oldPolicy);
} }
// Use FileProvider to generate content URI or file URI. return uri;
return FileUtils.getUriForFile(new File(filePath));
} }
/** /**
...@@ -387,8 +398,10 @@ public class DownloadUtils { ...@@ -387,8 +398,10 @@ public class DownloadUtils {
// Check if any apps can open the file. // Check if any apps can open the file.
try { try {
// TODO(qinmin): Move this to an AsyncTask so we don't need to temper with strict mode. // TODO(qinmin): Move this to an AsyncTask so we don't need to temper with strict mode.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
Uri uri = ContentUriUtils.isContentUri(filePath) ? Uri.parse(filePath) Uri uri = ContentUriUtils.isContentUri(filePath) ? Uri.parse(filePath)
: getUriForOtherApps(filePath); : getUriForOtherApps(filePath);
StrictMode.setThreadPolicy(oldPolicy);
Intent viewIntent = Intent viewIntent =
MediaViewerUtils.createViewIntentForUri(uri, mimeType, originalUrl, referrer); MediaViewerUtils.createViewIntentForUri(uri, mimeType, originalUrl, referrer);
context.startActivity(viewIntent); context.startActivity(viewIntent);
......
...@@ -15,6 +15,7 @@ import android.os.IBinder; ...@@ -15,6 +15,7 @@ import android.os.IBinder;
import android.os.Message; import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.StrictMode;
import android.util.Log; import android.util.Log;
import org.chromium.base.Callback; import org.chromium.base.Callback;
...@@ -106,8 +107,15 @@ public class GSAServiceClient { ...@@ -106,8 +107,15 @@ public class GSAServiceClient {
if (mService != null) Log.e(TAG, "Already connected."); if (mService != null) Log.e(TAG, "Already connected.");
Intent intent = new Intent(GSA_SERVICE).setPackage(GSAState.SEARCH_INTENT_PACKAGE); Intent intent = new Intent(GSA_SERVICE).setPackage(GSAState.SEARCH_INTENT_PACKAGE);
return mContext.bindService( // Third-party modifications to the framework lead to StrictMode violations in
intent, mConnection, Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND); // Context#bindService(). See crbug.com/670195.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
return mContext.bindService(
intent, mConnection, Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
} }
/** /**
......
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.infobar; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.infobar;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.os.StrictMode;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
...@@ -74,32 +75,38 @@ public class DataReductionPromoInfoBar extends ConfirmInfoBar { ...@@ -74,32 +75,38 @@ public class DataReductionPromoInfoBar extends ConfirmInfoBar {
String freOrSecondRunVersion = String freOrSecondRunVersion =
DataReductionPromoUtils.getDisplayedFreOrSecondRunPromoVersion(); DataReductionPromoUtils.getDisplayedFreOrSecondRunPromoVersion();
Calendar releaseDateOfM48Stable = Calendar.getInstance(TimeZone.getTimeZone("UTC")); // Temporarily allowing disk access. TODO: Fix. See http://crbug.com/577185
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
releaseDateOfM48Stable.setTime(Date.valueOf(M48_STABLE_RELEASE_DATE)); try {
long packageInstallTime = getPackageInstallTime(context); Calendar releaseDateOfM48Stable = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
// The boolean pref that stores whether user opted out on the first run experience was releaseDateOfM48Stable.setTime(Date.valueOf(M48_STABLE_RELEASE_DATE));
// added in M51. If the last promo was shown before M51, then |freOrSecondRunVersion| long packageInstallTime = getPackageInstallTime(context);
// 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. // The boolean pref that stores whether user opted out on the first run experience was
if (freOrSecondRunVersion.isEmpty() // added in M51. If the last promo was shown before M51, then |freOrSecondRunVersion|
&& packageInstallTime > releaseDateOfM48Stable.getTimeInMillis()) { // will be empty. If Chrome was installed after the FRE promo was added in M48 and
return false; // beforeM51,assume the user opted out from the FRE and don't show the infobar.
} if (freOrSecondRunVersion.isEmpty()
&& packageInstallTime > releaseDateOfM48Stable.getTimeInMillis()) {
// Only show the promo if the current version is at least two milestones after the last return false;
// 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. // Only show the promo if the current version is at least two milestones after the last
if (!freOrSecondRunVersion.isEmpty() // promo was displayed or the command line switch is on. If the last promo was shown
&& currentMilestone // before M51 then |freOrSecondRunVersion| will be empty and it is safe to show the
< VersionNumberGetter.getMilestoneFromVersionNumber(freOrSecondRunVersion) // infobar promo.
+ 2) { if (!freOrSecondRunVersion.isEmpty()
return false; && currentMilestone < VersionNumberGetter.getMilestoneFromVersionNumber(
freOrSecondRunVersion)
+ 2) {
return false;
}
return true;
} finally {
StrictMode.setThreadPolicy(oldPolicy);
} }
return true;
} }
/** /**
......
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.init; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.init;
import android.app.Activity; import android.app.Activity;
import android.os.Build; import android.os.Build;
import android.os.Process; import android.os.Process;
import android.os.StrictMode;
import org.chromium.base.ActivityState; import org.chromium.base.ActivityState;
import org.chromium.base.ApplicationStatus; import org.chromium.base.ApplicationStatus;
...@@ -348,7 +349,9 @@ public class ChromeBrowserInitializer { ...@@ -348,7 +349,9 @@ public class ChromeBrowserInitializer {
try { try {
TraceEvent.begin("ChromeBrowserInitializer.startChromeBrowserProcessesSync"); TraceEvent.begin("ChromeBrowserInitializer.startChromeBrowserProcessesSync");
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
LibraryLoader.getInstance().ensureInitialized(); LibraryLoader.getInstance().ensureInitialized();
StrictMode.setThreadPolicy(oldPolicy);
LibraryPrefetcher.asyncPrefetchLibrariesToMemory(); LibraryPrefetcher.asyncPrefetchLibrariesToMemory();
getBrowserStartupController().startBrowserProcessesSync( getBrowserStartupController().startBrowserProcessesSync(
LibraryProcessType.PROCESS_BROWSER, /*singleProcess=*/false); LibraryProcessType.PROCESS_BROWSER, /*singleProcess=*/false);
......
...@@ -14,6 +14,7 @@ import android.content.Context; ...@@ -14,6 +14,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.os.StrictMode;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.Log; import android.util.Log;
...@@ -103,9 +104,16 @@ public class NotificationService extends IntentService { ...@@ -103,9 +104,16 @@ public class NotificationService extends IntentService {
ChromeBrowserInitializer.getInstance().handleSynchronousStartup(); ChromeBrowserInitializer.getInstance().handleSynchronousStartup();
// Warm up the WebappRegistry, as we need to check if this notification should launch a // 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. // standalone web app. This no-ops if the registry is already initialized and warmed,
WebappRegistry.getInstance(); // but triggers a strict mode violation otherwise (i.e. the browser isn't running).
WebappRegistry.warmUpSharedPrefs(); // 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 // Now that the browser process is initialized, we pass forward the call to the
// NotificationPlatformBridge which will take care of delivering the appropriate events. // NotificationPlatformBridge which will take care of delivering the appropriate events.
......
...@@ -9,6 +9,7 @@ import android.graphics.Canvas; ...@@ -9,6 +9,7 @@ import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Build; import android.os.Build;
import android.os.StrictMode;
import android.provider.Settings; import android.provider.Settings;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
...@@ -23,6 +24,7 @@ import android.view.GestureDetector; ...@@ -23,6 +24,7 @@ import android.view.GestureDetector;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputConnection;
import android.widget.TextView; import android.widget.TextView;
...@@ -872,6 +874,18 @@ public abstract class UrlBar extends AutocompleteEditText { ...@@ -872,6 +874,18 @@ public abstract class UrlBar extends AutocompleteEditText {
Editable.SPAN_INCLUSIVE_EXCLUSIVE); Editable.SPAN_INCLUSIVE_EXCLUSIVE);
} }
@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);
}
}
@Override @Override
public Editable getText() { public Editable getText() {
if (mRequestingAutofillStructure) { if (mRequestingAutofillStructure) {
......
...@@ -13,6 +13,7 @@ import android.content.pm.PackageManager.NameNotFoundException; ...@@ -13,6 +13,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.StrictMode;
import android.os.SystemClock; import android.os.SystemClock;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.format.Formatter; import android.text.format.Formatter;
...@@ -121,21 +122,28 @@ public class ManageSpaceActivity extends AppCompatActivity implements View.OnCli ...@@ -121,21 +122,28 @@ public class ManageSpaceActivity extends AppCompatActivity implements View.OnCli
} }
}; };
String productVersion = AboutChromeSettings.getApplicationVersion( // Allow reading/writing to disk to check whether the last attempt was successful before
this, ChromeVersionInfo.getProductVersion()); // kicking off the browser process initialization.
String failedVersion = SharedPreferencesManager.getInstance().readString( StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
ChromePreferenceKeys.SETTINGS_WEBSITE_FAILED_BUILD_VERSION, null); try {
if (TextUtils.equals(failedVersion, productVersion)) { String productVersion = AboutChromeSettings.getApplicationVersion(
parts.onStartupFailure(null); this, ChromeVersionInfo.getProductVersion());
return; String failedVersion = SharedPreferencesManager.getInstance().readString(
} ChromePreferenceKeys.SETTINGS_WEBSITE_FAILED_BUILD_VERSION, null);
if (TextUtils.equals(failedVersion, productVersion)) {
parts.onStartupFailure(null);
return;
}
// If the native library crashes and kills the browser process, there is no guarantee // If the native library crashes and kills the browser process, there is no guarantee
// java-side the pref will be written before the process dies. We want to make sure we // java-side the pref will be written before the process dies. We want to make sure we
// don't attempt to start the browser process and have it kill chrome. This activity is // don't attempt to start the browser process and have it kill chrome. This activity is
// used to clear data for the chrome app, so it must be particularly error resistant. // used to clear data for the chrome app, so it must be particularly error resistant.
SharedPreferencesManager.getInstance().writeStringSync( SharedPreferencesManager.getInstance().writeStringSync(
ChromePreferenceKeys.SETTINGS_WEBSITE_FAILED_BUILD_VERSION, productVersion); ChromePreferenceKeys.SETTINGS_WEBSITE_FAILED_BUILD_VERSION, productVersion);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
try { try {
ChromeBrowserInitializer.getInstance().handlePreNativeStartup(parts); ChromeBrowserInitializer.getInstance().handlePreNativeStartup(parts);
......
...@@ -228,7 +228,9 @@ public class AndroidSyncSettings { ...@@ -228,7 +228,9 @@ public class AndroidSyncSettings {
if (value == mChromeSyncEnabled || mAccount == null) return; if (value == mChromeSyncEnabled || mAccount == null) return;
mChromeSyncEnabled = value; mChromeSyncEnabled = value;
mSyncContentResolverDelegate.setSyncAutomatically(mAccount, mContractAuthority, value); try (StrictModeContext ignored = StrictModeContext.allowDiskWrites()) {
mSyncContentResolverDelegate.setSyncAutomatically(mAccount, mContractAuthority, value);
}
notifyObservers(); notifyObservers();
} }
...@@ -281,17 +283,19 @@ public class AndroidSyncSettings { ...@@ -281,17 +283,19 @@ public class AndroidSyncSettings {
boolean oldChromeSyncEnabled = mChromeSyncEnabled; boolean oldChromeSyncEnabled = mChromeSyncEnabled;
boolean oldMasterSyncEnabled = mMasterSyncEnabled; boolean oldMasterSyncEnabled = mMasterSyncEnabled;
if (mAccount != null) { try (StrictModeContext ignored = StrictModeContext.allowDiskWrites()) {
mIsSyncable = if (mAccount != null) {
mSyncContentResolverDelegate.getIsSyncable(mAccount, mContractAuthority) mIsSyncable =
> 0; mSyncContentResolverDelegate.getIsSyncable(mAccount, mContractAuthority)
mChromeSyncEnabled = mSyncContentResolverDelegate.getSyncAutomatically( > 0;
mAccount, mContractAuthority); mChromeSyncEnabled = mSyncContentResolverDelegate.getSyncAutomatically(
} else { mAccount, mContractAuthority);
mIsSyncable = false; } else {
mChromeSyncEnabled = false; mIsSyncable = false;
mChromeSyncEnabled = false;
}
mMasterSyncEnabled = mSyncContentResolverDelegate.getMasterSyncAutomatically();
} }
mMasterSyncEnabled = mSyncContentResolverDelegate.getMasterSyncAutomatically();
return oldChromeSyncEnabled != mChromeSyncEnabled return oldChromeSyncEnabled != mChromeSyncEnabled
|| oldMasterSyncEnabled != mMasterSyncEnabled; || oldMasterSyncEnabled != mMasterSyncEnabled;
......
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.media.router; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.media.router;
import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE; import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE;
import android.app.Dialog; import android.app.Dialog;
import android.os.StrictMode;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.view.View; import android.view.View;
...@@ -81,17 +82,24 @@ public class MediaRouterIntegrationTest { ...@@ -81,17 +82,24 @@ public class MediaRouterIntegrationTest {
private static final int SCRIPT_TIMEOUT_MS = 10000; private static final int SCRIPT_TIMEOUT_MS = 10000;
private static final int SCRIPT_RETRY_MS = 50; private static final int SCRIPT_RETRY_MS = 50;
private StrictMode.ThreadPolicy mOldPolicy;
private EmbeddedTestServer mTestServer; private EmbeddedTestServer mTestServer;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
BrowserMediaRouter.setRouteProviderFactoryForTest(new MockMediaRouteProvider.Factory()); BrowserMediaRouter.setRouteProviderFactoryForTest(new MockMediaRouteProvider.Factory());
mActivityTestRule.startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
// Temporary until support library is updated, see http://crbug.com/576393.
TestThreadUtils.runOnUiThreadBlocking(
() -> { mOldPolicy = StrictMode.allowThreadDiskWrites(); });
mTestServer = EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext()); mTestServer = EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
} }
@After @After
public void tearDown() { public void tearDown() {
// Temporary until support library is updated, see http://crbug.com/576393.
TestThreadUtils.runOnUiThreadBlocking(() -> { StrictMode.setThreadPolicy(mOldPolicy); });
mTestServer.stopAndDestroyServer(); mTestServer.stopAndDestroyServer();
} }
......
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
package org.chromium.chrome.browser.shape_detection; package org.chromium.chrome.browser.shape_detection;
import android.os.StrictMode;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import androidx.test.filters.LargeTest; import androidx.test.filters.LargeTest;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
...@@ -25,6 +27,7 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner; ...@@ -25,6 +27,7 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ChromeRestriction; import org.chromium.chrome.test.util.ChromeRestriction;
import org.chromium.chrome.test.util.ChromeTabUtils; import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.browser.TabTitleObserver; import org.chromium.chrome.test.util.browser.TabTitleObserver;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServer; import org.chromium.net.test.EmbeddedTestServer;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
...@@ -45,6 +48,7 @@ public class ShapeDetectionTest { ...@@ -45,6 +48,7 @@ public class ShapeDetectionTest {
private static final String BARCODE_TEST_EXPECTED_TAB_TITLE = "https://chromium.org"; private static final String BARCODE_TEST_EXPECTED_TAB_TITLE = "https://chromium.org";
private static final String TEXT_TEST_EXPECTED_TAB_TITLE = private static final String TEXT_TEST_EXPECTED_TAB_TITLE =
"The quick brown fox jumped over the lazy dog. Helvetica Neue 36."; "The quick brown fox jumped over the lazy dog. Helvetica Neue 36.";
private StrictMode.ThreadPolicy mOldPolicy;
/** /**
* Verifies that QR codes are detected correctly. * Verifies that QR codes are detected correctly.
...@@ -102,5 +106,12 @@ public class ShapeDetectionTest { ...@@ -102,5 +106,12 @@ public class ShapeDetectionTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mActivityTestRule.startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
TestThreadUtils.runOnUiThreadBlocking(
() -> { mOldPolicy = StrictMode.allowThreadDiskWrites(); });
}
@After
public void tearDown() {
TestThreadUtils.runOnUiThreadBlocking(() -> StrictMode.setThreadPolicy(mOldPolicy));
} }
} }
...@@ -7,6 +7,7 @@ package org.chromium.webapk.shell_apk; ...@@ -7,6 +7,7 @@ package org.chromium.webapk.shell_apk;
import android.app.Service; import android.app.Service;
import android.content.Intent; import android.content.Intent;
import android.os.IBinder; import android.os.IBinder;
import android.os.StrictMode;
import org.chromium.webapk.lib.common.identity_service.IIdentityService; import org.chromium.webapk.lib.common.identity_service.IIdentityService;
...@@ -15,8 +16,13 @@ public class IdentityService extends Service { ...@@ -15,8 +16,13 @@ public class IdentityService extends Service {
private final IIdentityService.Stub mBinder = new IIdentityService.Stub() { private final IIdentityService.Stub mBinder = new IIdentityService.Stub() {
@Override @Override
public String getRuntimeHostBrowserPackageName() { public String getRuntimeHostBrowserPackageName() {
return HostBrowserUtils.computeHostBrowserPackageClearCachedDataOnChange( StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
getApplicationContext()); try {
return HostBrowserUtils.computeHostBrowserPackageClearCachedDataOnChange(
getApplicationContext());
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
} }
}; };
......
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