Merge "Wait for RELRO before starting WebViewZygote at boot." into qt-dev

am: 49e9f80efd

Change-Id: I01a7479ad437dddd1723606a083442238cef6671
This commit is contained in:
Torne (Richard Coles)
2019-04-11 10:45:54 -07:00
committed by android-build-merger
5 changed files with 22 additions and 12 deletions

View File

@@ -17,7 +17,6 @@
package android.webkit; package android.webkit;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.ChildZygoteProcess; import android.os.ChildZygoteProcess;
import android.os.Process; import android.os.Process;
@@ -81,17 +80,9 @@ public class WebViewZygote {
synchronized (sLock) { synchronized (sLock) {
sMultiprocessEnabled = enabled; sMultiprocessEnabled = enabled;
// When toggling between multi-process being on/off, start or stop the // When multi-process is disabled, kill the zygote. When it is enabled,
// zygote. If it is enabled and the zygote is not yet started, launch it. // the zygote will be started when it is first needed in getProcess().
// Otherwise, kill it. The name may be null if the package information has if (!enabled) {
// not yet been resolved.
if (enabled) {
// Run on a background thread as this waits for the zygote to start and we don't
// want to block the caller on this. It's okay if this is delayed as anyone trying
// to use the zygote will call it first anyway.
AsyncTask.THREAD_POOL_EXECUTOR.execute(WebViewZygote::getProcess);
} else {
// No need to run this in the background, it's very brief.
stopZygoteLocked(); stopZygoteLocked();
} }
} }

View File

@@ -265,6 +265,11 @@ public class SystemImpl implements SystemInterface {
WebViewZygote.setMultiprocessEnabled(enableMultiProcess); WebViewZygote.setMultiprocessEnabled(enableMultiProcess);
} }
@Override
public void ensureZygoteStarted() {
WebViewZygote.getProcess();
}
@Override @Override
public boolean isMultiProcessDefaultEnabled() { public boolean isMultiProcessDefaultEnabled() {
// Multiprocess is enabled for all 64-bit devices, since the ability to run the renderer // Multiprocess is enabled for all 64-bit devices, since the ability to run the renderer

View File

@@ -61,5 +61,7 @@ public interface SystemInterface {
public int getMultiProcessSetting(Context context); public int getMultiProcessSetting(Context context);
public void setMultiProcessSetting(Context context, int value); public void setMultiProcessSetting(Context context, int value);
public void notifyZygote(boolean enableMultiProcess); public void notifyZygote(boolean enableMultiProcess);
/** Start the zygote if it's not already running. */
public void ensureZygoteStarted();
public boolean isMultiProcessDefaultEnabled(); public boolean isMultiProcessDefaultEnabled();
} }

View File

@@ -17,6 +17,7 @@ package com.android.server.webkit;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.os.AsyncTask;
import android.os.UserHandle; import android.os.UserHandle;
import android.webkit.WebViewProviderInfo; import android.webkit.WebViewProviderInfo;
import android.webkit.WebViewProviderResponse; import android.webkit.WebViewProviderResponse;
@@ -81,6 +82,14 @@ public class WebViewUpdateServiceImpl {
migrateFallbackStateOnBoot(); migrateFallbackStateOnBoot();
mWebViewUpdater.prepareWebViewInSystemServer(); mWebViewUpdater.prepareWebViewInSystemServer();
mSystemInterface.notifyZygote(isMultiProcessEnabled()); mSystemInterface.notifyZygote(isMultiProcessEnabled());
AsyncTask.THREAD_POOL_EXECUTOR.execute(this::startZygoteWhenReady);
}
void startZygoteWhenReady() {
// Wait on a background thread for RELRO creation to be done. We ignore the return value
// because even if RELRO creation failed we still want to start the zygote.
waitForAndGetProvider();
mSystemInterface.ensureZygoteStarted();
} }
void handleNewUser(int userId) { void handleNewUser(int userId) {

View File

@@ -184,6 +184,9 @@ public class TestSystemImpl implements SystemInterface {
@Override @Override
public void notifyZygote(boolean enableMultiProcess) {} public void notifyZygote(boolean enableMultiProcess) {}
@Override
public void ensureZygoteStarted() {}
@Override @Override
public boolean isMultiProcessDefaultEnabled() { public boolean isMultiProcessDefaultEnabled() {
return mMultiProcessDefault; return mMultiProcessDefault;