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;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.StrictMode;
import android.provider.Settings;
import android.view.View;
import android.view.ViewGroup;
......@@ -1245,8 +1246,13 @@ public class VrShellDelegate
assert (VrCoreInstallUtils.getVrSupportLevel() == VrSupportLevel.VR_DAYDREAM
|| !mStartedFromVrIntent);
if (mNativeVrShellDelegate != 0) {
VrShellDelegateJni.get().onResume(mNativeVrShellDelegate, VrShellDelegate.this);
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
if (mNativeVrShellDelegate != 0) {
VrShellDelegateJni.get().onResume(mNativeVrShellDelegate, VrShellDelegate.this);
}
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
// Perform slow initialization asynchronously.
......@@ -1569,11 +1575,13 @@ public class VrShellDelegate
if (mActivity.getCompositorViewHolder() == null) return false;
TabModelSelector tabModelSelector = mActivity.getTabModelSelector();
if (tabModelSelector == null) return false;
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
mVrShell = new VrShell(mActivity, this, tabModelSelector);
} catch (VrUnsupportedException e) {
return false;
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
return true;
}
......
......@@ -13,6 +13,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.StrictMode;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
......@@ -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.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
Bundle options = mIsVrIntent
? VrModuleProvider.getIntentDelegate().getVrIntentOptions(mActivity)
......@@ -423,6 +425,8 @@ public class LaunchIntentDispatcher implements IntentHandler.IntentHandlerDelega
} else {
throw ex;
}
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
return Action.FINISH_ACTIVITY;
......
......@@ -13,6 +13,7 @@ import android.content.pm.ShortcutManager;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import androidx.annotation.VisibleForTesting;
......@@ -51,7 +52,15 @@ public class LauncherShortcutActivity extends Activity {
}
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();
}
......
......@@ -11,6 +11,7 @@ import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.StrictMode;
import android.text.TextUtils;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;
......@@ -83,8 +84,13 @@ public class BookmarkWidgetService extends RemoteViewsService {
}
static SharedPreferences getWidgetState(int widgetId) {
return ContextUtils.getApplicationContext().getSharedPreferences(
String.format(Locale.US, "widgetState-%d", widgetId), Context.MODE_PRIVATE);
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
return ContextUtils.getApplicationContext().getSharedPreferences(
String.format(Locale.US, "widgetState-%d", widgetId), Context.MODE_PRIVATE);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
static void deleteWidgetState(int widgetId) {
......
......@@ -12,6 +12,7 @@ import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.StrictMode;
import android.os.SystemClock;
import android.text.TextUtils;
......@@ -240,8 +241,13 @@ public class CustomTabActivityNavigationController implements StartStopWithNativ
boolean willChromeHandleIntent =
mIntentDataProvider.isOpenedByChrome() || mIntentDataProvider.isIncognito();
willChromeHandleIntent |=
ExternalNavigationDelegateImpl.willChromeHandleIntent(intent, true);
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
willChromeHandleIntent |=
ExternalNavigationDelegateImpl.willChromeHandleIntent(intent, true);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
Bundle startActivityOptions = ActivityOptionsCompat.makeCustomAnimation(
mActivity, R.anim.abc_fade_in, R.anim.abc_fade_out).toBundle();
......@@ -252,10 +258,16 @@ public class CustomTabActivityNavigationController implements StartStopWithNativ
mTabController.detachAndStartReparenting(intent, startActivityOptions,
() -> finish(REPARENTING));
} else {
if (mIntentDataProvider.isInfoPage()) {
IntentHandler.startChromeLauncherActivityForTrustedIntent(intent);
} else {
mActivity.startActivity(intent, startActivityOptions);
// Temporarily allowing disk access while fixing. TODO: http://crbug.com/581860
StrictMode.allowThreadDiskWrites();
try {
if (mIntentDataProvider.isInfoPage()) {
IntentHandler.startChromeLauncherActivityForTrustedIntent(intent);
} else {
mActivity.startActivity(intent, startActivityOptions);
}
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
return true;
......
......@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.document;
import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.TraceEvent;
......@@ -20,30 +21,35 @@ public class ChromeLauncherActivity extends Activity {
@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");
super.onCreate(savedInstanceState);
try {
super.onCreate(savedInstanceState);
if (VrModuleProvider.getIntentDelegate().isVrIntent(getIntent())) {
// We need to turn VR mode on as early as possible in the intent handling flow to
// avoid brightness flickering when handling VR intents.
VrModuleProvider.getDelegate().setVrModeEnabled(this, true);
}
if (VrModuleProvider.getIntentDelegate().isVrIntent(getIntent())) {
// We need to turn VR mode on as early as possible in the intent handling flow to
// avoid brightness flickering when handling VR intents.
VrModuleProvider.getDelegate().setVrModeEnabled(this, true);
}
@LaunchIntentDispatcher.Action
int dispatchAction = LaunchIntentDispatcher.dispatch(this, getIntent());
switch (dispatchAction) {
case LaunchIntentDispatcher.Action.FINISH_ACTIVITY:
finish();
break;
case LaunchIntentDispatcher.Action.FINISH_ACTIVITY_REMOVE_TASK:
ApiCompatibilityUtils.finishAndRemoveTask(this);
break;
default:
assert false : "Intent dispatcher finished with action " + dispatchAction
+ ", finishing anyway";
finish();
break;
@LaunchIntentDispatcher.Action
int dispatchAction = LaunchIntentDispatcher.dispatch(this, getIntent());
switch (dispatchAction) {
case LaunchIntentDispatcher.Action.FINISH_ACTIVITY:
finish();
break;
case LaunchIntentDispatcher.Action.FINISH_ACTIVITY_REMOVE_TASK:
ApiCompatibilityUtils.finishAndRemoveTask(this);
break;
default:
assert false : "Intent dispatcher finished with action " + dispatchAction
+ ", finishing anyway";
finish();
break;
}
} finally {
StrictMode.setThreadPolicy(oldPolicy);
TraceEvent.end("ChromeLauncherActivity.onCreate");
}
TraceEvent.end("ChromeLauncherActivity.onCreate");
}
}
......@@ -13,6 +13,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.StrictMode;
import android.text.TextUtils;
import androidx.annotation.MainThread;
......@@ -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
// share the file to other apps.
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.
return DownloadFileProvider.createContentUri(filePath);
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
Uri uri = null;
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 FileUtils.getUriForFile(new File(filePath));
return uri;
}
/**
......@@ -387,8 +398,10 @@ public class DownloadUtils {
// Check if any apps can open the file.
try {
// 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)
: getUriForOtherApps(filePath);
StrictMode.setThreadPolicy(oldPolicy);
Intent viewIntent =
MediaViewerUtils.createViewIntentForUri(uri, mimeType, originalUrl, referrer);
context.startActivity(viewIntent);
......
......@@ -15,6 +15,7 @@ import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.os.StrictMode;
import android.util.Log;
import org.chromium.base.Callback;
......@@ -106,8 +107,15 @@ public class GSAServiceClient {
if (mService != null) Log.e(TAG, "Already connected.");
Intent intent = new Intent(GSA_SERVICE).setPackage(GSAState.SEARCH_INTENT_PACKAGE);
return mContext.bindService(
intent, mConnection, Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND);
// Third-party modifications to the framework lead to StrictMode violations in
// 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;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.StrictMode;
import androidx.annotation.DrawableRes;
......@@ -74,32 +75,38 @@ public class DataReductionPromoInfoBar extends ConfirmInfoBar {
String freOrSecondRunVersion =
DataReductionPromoUtils.getDisplayedFreOrSecondRunPromoVersion();
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 (!freOrSecondRunVersion.isEmpty()
&& currentMilestone
< VersionNumberGetter.getMilestoneFromVersionNumber(freOrSecondRunVersion)
+ 2) {
return false;
// 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 (!freOrSecondRunVersion.isEmpty()
&& 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;
import android.app.Activity;
import android.os.Build;
import android.os.Process;
import android.os.StrictMode;
import org.chromium.base.ActivityState;
import org.chromium.base.ApplicationStatus;
......@@ -348,7 +349,9 @@ public class ChromeBrowserInitializer {
try {
TraceEvent.begin("ChromeBrowserInitializer.startChromeBrowserProcessesSync");
ThreadUtils.assertOnUiThread();
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
LibraryLoader.getInstance().ensureInitialized();
StrictMode.setThreadPolicy(oldPolicy);
LibraryPrefetcher.asyncPrefetchLibrariesToMemory();
getBrowserStartupController().startBrowserProcessesSync(
LibraryProcessType.PROCESS_BROWSER, /*singleProcess=*/false);
......
......@@ -14,6 +14,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.PersistableBundle;
import android.os.StrictMode;
import android.os.SystemClock;
import android.util.Log;
......@@ -103,9 +104,16 @@ public class NotificationService extends IntentService {
ChromeBrowserInitializer.getInstance().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.
WebappRegistry.getInstance();
WebappRegistry.warmUpSharedPrefs();
// 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.
......
......@@ -9,6 +9,7 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.os.StrictMode;
import android.provider.Settings;
import android.text.Editable;
import android.text.InputType;
......@@ -23,6 +24,7 @@ import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.widget.TextView;
......@@ -872,6 +874,18 @@ public abstract class UrlBar extends AutocompleteEditText {
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
public Editable getText() {
if (mRequestingAutofillStructure) {
......
......@@ -13,6 +13,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.os.SystemClock;
import android.text.TextUtils;
import android.text.format.Formatter;
......@@ -121,21 +122,28 @@ public class ManageSpaceActivity extends AppCompatActivity implements View.OnCli
}
};
String productVersion = AboutChromeSettings.getApplicationVersion(
this, ChromeVersionInfo.getProductVersion());
String failedVersion = SharedPreferencesManager.getInstance().readString(
ChromePreferenceKeys.SETTINGS_WEBSITE_FAILED_BUILD_VERSION, null);
if (TextUtils.equals(failedVersion, productVersion)) {
parts.onStartupFailure(null);
return;
}
// Allow reading/writing to disk to check whether the last attempt was successful before
// kicking off the browser process initialization.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
String productVersion = AboutChromeSettings.getApplicationVersion(
this, ChromeVersionInfo.getProductVersion());
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
// 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
// used to clear data for the chrome app, so it must be particularly error resistant.
SharedPreferencesManager.getInstance().writeStringSync(
ChromePreferenceKeys.SETTINGS_WEBSITE_FAILED_BUILD_VERSION, productVersion);
// 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
// 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.
SharedPreferencesManager.getInstance().writeStringSync(
ChromePreferenceKeys.SETTINGS_WEBSITE_FAILED_BUILD_VERSION, productVersion);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
try {
ChromeBrowserInitializer.getInstance().handlePreNativeStartup(parts);
......
......@@ -228,7 +228,9 @@ public class AndroidSyncSettings {
if (value == mChromeSyncEnabled || mAccount == null) return;
mChromeSyncEnabled = value;
mSyncContentResolverDelegate.setSyncAutomatically(mAccount, mContractAuthority, value);
try (StrictModeContext ignored = StrictModeContext.allowDiskWrites()) {
mSyncContentResolverDelegate.setSyncAutomatically(mAccount, mContractAuthority, value);
}
notifyObservers();
}
......@@ -281,17 +283,19 @@ public class AndroidSyncSettings {
boolean oldChromeSyncEnabled = mChromeSyncEnabled;
boolean oldMasterSyncEnabled = mMasterSyncEnabled;
if (mAccount != null) {
mIsSyncable =
mSyncContentResolverDelegate.getIsSyncable(mAccount, mContractAuthority)
> 0;
mChromeSyncEnabled = mSyncContentResolverDelegate.getSyncAutomatically(
mAccount, mContractAuthority);
} else {
mIsSyncable = false;
mChromeSyncEnabled = false;
try (StrictModeContext ignored = StrictModeContext.allowDiskWrites()) {
if (mAccount != null) {
mIsSyncable =
mSyncContentResolverDelegate.getIsSyncable(mAccount, mContractAuthority)
> 0;
mChromeSyncEnabled = mSyncContentResolverDelegate.getSyncAutomatically(
mAccount, mContractAuthority);
} else {
mIsSyncable = false;
mChromeSyncEnabled = false;
}
mMasterSyncEnabled = mSyncContentResolverDelegate.getMasterSyncAutomatically();
}
mMasterSyncEnabled = mSyncContentResolverDelegate.getMasterSyncAutomatically();
return oldChromeSyncEnabled != mChromeSyncEnabled
|| oldMasterSyncEnabled != mMasterSyncEnabled;
......
......@@ -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 android.app.Dialog;
import android.os.StrictMode;
import android.support.test.InstrumentationRegistry;
import android.view.View;
......@@ -81,17 +82,24 @@ public class MediaRouterIntegrationTest {
private static final int SCRIPT_TIMEOUT_MS = 10000;
private static final int SCRIPT_RETRY_MS = 50;
private StrictMode.ThreadPolicy mOldPolicy;
private EmbeddedTestServer mTestServer;
@Before
public void setUp() throws Exception {
BrowserMediaRouter.setRouteProviderFactoryForTest(new MockMediaRouteProvider.Factory());
mActivityTestRule.startMainActivityOnBlankPage();
// Temporary until support library is updated, see http://crbug.com/576393.
TestThreadUtils.runOnUiThreadBlocking(
() -> { mOldPolicy = StrictMode.allowThreadDiskWrites(); });
mTestServer = EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
}
@After
public void tearDown() {
// Temporary until support library is updated, see http://crbug.com/576393.
TestThreadUtils.runOnUiThreadBlocking(() -> { StrictMode.setThreadPolicy(mOldPolicy); });
mTestServer.stopAndDestroyServer();
}
......
......@@ -4,10 +4,12 @@
package org.chromium.chrome.browser.shape_detection;
import android.os.StrictMode;
import android.support.test.InstrumentationRegistry;
import androidx.test.filters.LargeTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
......@@ -25,6 +27,7 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ChromeRestriction;
import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.browser.TabTitleObserver;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServer;
import java.util.concurrent.TimeoutException;
......@@ -45,6 +48,7 @@ public class ShapeDetectionTest {
private static final String BARCODE_TEST_EXPECTED_TAB_TITLE = "https://chromium.org";
private static final String TEXT_TEST_EXPECTED_TAB_TITLE =
"The quick brown fox jumped over the lazy dog. Helvetica Neue 36.";
private StrictMode.ThreadPolicy mOldPolicy;
/**
* Verifies that QR codes are detected correctly.
......@@ -102,5 +106,12 @@ public class ShapeDetectionTest {
@Before
public void setUp() throws Exception {
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;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.StrictMode;
import org.chromium.webapk.lib.common.identity_service.IIdentityService;
......@@ -15,8 +16,13 @@ public class IdentityService extends Service {
private final IIdentityService.Stub mBinder = new IIdentityService.Stub() {
@Override
public String getRuntimeHostBrowserPackageName() {
return HostBrowserUtils.computeHostBrowserPackageClearCachedDataOnChange(
getApplicationContext());
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
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