From bc8fbe40d2fc2ee350d23d45610d5e65b24707d5 Mon Sep 17 00:00:00 2001 From: "Torne (Richard Coles)" Date: Thu, 19 Mar 2020 12:11:18 -0400 Subject: [PATCH] Restart the WebView zygote after a WebView update. The zygote is stopped when a WebView update occurs, and will be automatically restarted the first time an app tries to use it, but this means the first app to use WebView after an update pays a fairly large startup time penalty. Instead, queue a background task to wait for RELRO creation to be finished and then start the zygote immediately afterward, as we do at boot time, saving the app from paying this cost. Fixes: 112485729 Test: atest WebViewUpdateServiceTest Change-Id: I14159980851f423675b6a4ec0905cecda63e0e54 --- .../server/webkit/WebViewUpdateServiceImpl.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/webkit/WebViewUpdateServiceImpl.java b/services/core/java/com/android/server/webkit/WebViewUpdateServiceImpl.java index 4d670f1eb59cd..dd0ec948aa3aa 100644 --- a/services/core/java/com/android/server/webkit/WebViewUpdateServiceImpl.java +++ b/services/core/java/com/android/server/webkit/WebViewUpdateServiceImpl.java @@ -163,6 +163,7 @@ class WebViewUpdateServiceImpl { } void prepareWebViewInSystemServer() { + mSystemInterface.notifyZygote(isMultiProcessEnabled()); try { synchronized (mLock) { mCurrentWebViewPackage = findPreferredWebViewPackage(); @@ -199,12 +200,6 @@ class WebViewUpdateServiceImpl { Slog.e(TAG, "No valid provider and no fallback available."); } } - - boolean multiProcessEnabled = isMultiProcessEnabled(); - mSystemInterface.notifyZygote(multiProcessEnabled); - if (multiProcessEnabled) { - AsyncTask.THREAD_POOL_EXECUTOR.execute(this::startZygoteWhenReady); - } } private void startZygoteWhenReady() { @@ -358,6 +353,12 @@ class WebViewUpdateServiceImpl { mWebViewPackageDirty = true; } } + + // Once we've notified the system that the provider has changed and started RELRO creation, + // try to restart the zygote so that it will be ready when apps use it. + if (isMultiProcessEnabled()) { + AsyncTask.THREAD_POOL_EXECUTOR.execute(this::startZygoteWhenReady); + } } /**