import android.webkit.WebViewProviderResponse;
import java.io.PrintWriter;
+import java.lang.Integer;
import java.util.List;
/**
private WebViewUpdater mWebViewUpdater;
final private Context mContext;
+ private final static int MULTIPROCESS_SETTING_ON_VALUE = Integer.MAX_VALUE;
+ private final static int MULTIPROCESS_SETTING_OFF_VALUE = Integer.MIN_VALUE;
+
public WebViewUpdateServiceImpl(Context context, SystemInterface systemInterface) {
mContext = context;
mSystemInterface = systemInterface;
}
boolean isMultiProcessEnabled() {
- PackageInfo current = getCurrentWebViewPackage();
- if (current == null) return false;
- int currentVersion = current.versionCode;
int settingValue = mSystemInterface.getMultiProcessSetting(mContext);
if (mSystemInterface.isMultiProcessDefaultEnabled()) {
- // Multiprocess should be enabled unless the user has turned it off manually for this
- // version or newer, as we want to re-enable it when it's updated to get fresh
- // bug reports.
- return settingValue > -currentVersion;
+ // Multiprocess should be enabled unless the user has turned it off manually.
+ return settingValue > MULTIPROCESS_SETTING_OFF_VALUE;
} else {
- // Multiprocess should not be enabled, unless the user has turned it on manually for
- // any version.
- return settingValue > 0;
+ // Multiprocess should not be enabled, unless the user has turned it on manually.
+ return settingValue >= MULTIPROCESS_SETTING_ON_VALUE;
}
}
void enableMultiProcess(boolean enable) {
- // The value we store for the setting is the version code of the current package, if it's
- // enabled, or the negation of the version code of the current package, if it's disabled.
- // Users who have a setting from before this scheme was implemented will have it set to 0 or
- // 1 instead.
PackageInfo current = getCurrentWebViewPackage();
- int currentVersion = current != null ? current.versionCode : 1;
mSystemInterface.setMultiProcessSetting(mContext,
- enable ? currentVersion : -currentVersion);
+ enable ? MULTIPROCESS_SETTING_ON_VALUE : MULTIPROCESS_SETTING_OFF_VALUE);
mSystemInterface.notifyZygote(enable);
if (current != null) {
mSystemInterface.killPackageDependents(current.packageName);
import org.mockito.Matchers;
import org.mockito.compat.ArgumentMatcher;
+import java.lang.Integer;
import java.util.concurrent.CountDownLatch;
@Test
public void testMultiProcessEnabledByDefault() {
+ testMultiProcessByDefault(true /* enabledByDefault */);
+ }
+
+ @Test
+ public void testMultiProcessDisabledByDefault() {
+ testMultiProcessByDefault(false /* enabledByDefault */);
+ }
+
+ private void testMultiProcessByDefault(boolean enabledByDefault) {
String primaryPackage = "primary";
WebViewProviderInfo[] packages = new WebViewProviderInfo[] {
new WebViewProviderInfo(
primaryPackage, "", true /* default available */, false /* fallback */, null)};
setupWithPackages(packages, true /* fallback logic enabled */, 1 /* numRelros */,
- true /* debuggable */, true /* multiprocess by default */);
+ true /* debuggable */,
+ enabledByDefault /* not multiprocess by default */);
mTestSystemImpl.setPackageInfo(createPackageInfo(primaryPackage, true /* enabled */,
true /* valid */, true /* installed */, null /* signatures */,
10 /* lastUpdateTime*/, false /* not hidden */, 1000 /* versionCode */,
runWebViewBootPreparationOnMainSync();
checkPreparationPhasesForPackage(primaryPackage, 1 /* first preparation phase */);
- // Check it's on by default
- assertTrue(mWebViewUpdateServiceImpl.isMultiProcessEnabled());
+ // Check it's off by default
+ assertEquals(enabledByDefault, mWebViewUpdateServiceImpl.isMultiProcessEnabled());
// Test toggling it
- mWebViewUpdateServiceImpl.enableMultiProcess(false);
- assertFalse(mWebViewUpdateServiceImpl.isMultiProcessEnabled());
- mWebViewUpdateServiceImpl.enableMultiProcess(true);
- assertTrue(mWebViewUpdateServiceImpl.isMultiProcessEnabled());
+ mWebViewUpdateServiceImpl.enableMultiProcess(!enabledByDefault);
+ assertEquals(!enabledByDefault, mWebViewUpdateServiceImpl.isMultiProcessEnabled());
+ mWebViewUpdateServiceImpl.enableMultiProcess(enabledByDefault);
+ assertEquals(enabledByDefault, mWebViewUpdateServiceImpl.isMultiProcessEnabled());
+ }
- // Disable, then upgrade provider, which should re-enable it
- mWebViewUpdateServiceImpl.enableMultiProcess(false);
- mTestSystemImpl.setPackageInfo(createPackageInfo(primaryPackage, true /* enabled */,
- true /* valid */, true /* installed */, null /* signatures */,
- 20 /* lastUpdateTime*/, false /* not hidden */, 2000 /* versionCode */,
- false /* isSystemApp */));
- mWebViewUpdateServiceImpl.packageStateChanged(primaryPackage,
- WebViewUpdateService.PACKAGE_ADDED_REPLACED, 0);
- checkPreparationPhasesForPackage(primaryPackage, 2);
- assertTrue(mWebViewUpdateServiceImpl.isMultiProcessEnabled());
+ @Test
+ public void testMultiProcessEnabledByDefaultWithSettingsValue() {
+ testMultiProcessByDefaultWithSettingsValue(
+ true /* enabledByDefault */, Integer.MIN_VALUE, false /* expectEnabled */);
+ testMultiProcessByDefaultWithSettingsValue(
+ true /* enabledByDefault */, -999999, true /* expectEnabled */);
+ testMultiProcessByDefaultWithSettingsValue(
+ true /* enabledByDefault */, 0, true /* expectEnabled */);
+ testMultiProcessByDefaultWithSettingsValue(
+ true /* enabledByDefault */, 999999, true /* expectEnabled */);
}
@Test
- public void testMultiProcessDisabledByDefault() {
+ public void testMultiProcessDisabledByDefaultWithSettingsValue() {
+ testMultiProcessByDefaultWithSettingsValue(
+ false /* enabledByDefault */, Integer.MIN_VALUE, false /* expectEnabled */);
+ testMultiProcessByDefaultWithSettingsValue(
+ false /* enabledByDefault */, 0, false /* expectEnabled */);
+ testMultiProcessByDefaultWithSettingsValue(
+ false /* enabledByDefault */, 999999, false /* expectEnabled */);
+ testMultiProcessByDefaultWithSettingsValue(
+ false /* enabledByDefault */, Integer.MAX_VALUE, true /* expectEnabled */);
+ }
+
+ /**
+ * Test the logic of the multiprocess setting depending on whether multiprocess is enabled by
+ * default, and what the setting is set to.
+ * @param enabledByDefault whether multiprocess is enabled by default.
+ * @param settingValue value of the multiprocess setting.
+ */
+ private void testMultiProcessByDefaultWithSettingsValue(
+ boolean enabledByDefault, int settingValue, boolean expectEnabled) {
String primaryPackage = "primary";
WebViewProviderInfo[] packages = new WebViewProviderInfo[] {
new WebViewProviderInfo(
primaryPackage, "", true /* default available */, false /* fallback */, null)};
setupWithPackages(packages, true /* fallback logic enabled */, 1 /* numRelros */,
- true /* debuggable */, false /* not multiprocess by default */);
+ true /* debuggable */, enabledByDefault /* multiprocess by default */);
mTestSystemImpl.setPackageInfo(createPackageInfo(primaryPackage, true /* enabled */,
true /* valid */, true /* installed */, null /* signatures */,
10 /* lastUpdateTime*/, false /* not hidden */, 1000 /* versionCode */,
runWebViewBootPreparationOnMainSync();
checkPreparationPhasesForPackage(primaryPackage, 1 /* first preparation phase */);
- // Check it's off by default
- assertFalse(mWebViewUpdateServiceImpl.isMultiProcessEnabled());
-
- // Test toggling it
- mWebViewUpdateServiceImpl.enableMultiProcess(true);
- assertTrue(mWebViewUpdateServiceImpl.isMultiProcessEnabled());
- mWebViewUpdateServiceImpl.enableMultiProcess(false);
- assertFalse(mWebViewUpdateServiceImpl.isMultiProcessEnabled());
-
- // Disable, then upgrade provider, which should not re-enable it
- mWebViewUpdateServiceImpl.enableMultiProcess(false);
- mTestSystemImpl.setPackageInfo(createPackageInfo(primaryPackage, true /* enabled */,
- true /* valid */, true /* installed */, null /* signatures */,
- 20 /* lastUpdateTime*/, false /* not hidden */, 2000 /* versionCode */,
- false /* isSystemApp */));
- mWebViewUpdateServiceImpl.packageStateChanged(primaryPackage,
- WebViewUpdateService.PACKAGE_ADDED_REPLACED, 0);
- checkPreparationPhasesForPackage(primaryPackage, 2);
- assertFalse(mWebViewUpdateServiceImpl.isMultiProcessEnabled());
+ mTestSystemImpl.setMultiProcessSetting(null /* context */, settingValue);
- // Enable, then upgrade provider, which should leave it on
- mWebViewUpdateServiceImpl.enableMultiProcess(true);
- mTestSystemImpl.setPackageInfo(createPackageInfo(primaryPackage, true /* enabled */,
- true /* valid */, true /* installed */, null /* signatures */,
- 30 /* lastUpdateTime*/, false /* not hidden */, 3000 /* versionCode */,
- false /* isSystemApp */));
- mWebViewUpdateServiceImpl.packageStateChanged(primaryPackage,
- WebViewUpdateService.PACKAGE_ADDED_REPLACED, 0);
- checkPreparationPhasesForPackage(primaryPackage, 3);
- assertTrue(mWebViewUpdateServiceImpl.isMultiProcessEnabled());
+ assertEquals(expectEnabled, mWebViewUpdateServiceImpl.isMultiProcessEnabled());
}
+
/**
* Ensure that packages with a targetSdkVersion targeting the current platform are valid, and
* that packages targeting an older version are not valid.