Loading core/java/android/webkit/WebViewZygote.java +40 −12 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.os.Build; import android.os.SystemService; import android.os.ZygoteProcess; import android.text.TextUtils; import android.util.AndroidRuntimeException; import android.util.Log; import com.android.internal.annotations.GuardedBy; Loading Loading @@ -52,6 +53,13 @@ public class WebViewZygote { @GuardedBy("sLock") private static ZygoteProcess sZygote; /** * Variable that allows us to determine whether the WebView zygote Service has already been * started. */ @GuardedBy("sLock") private static boolean sStartedService = false; /** * Information about the selected WebView package. This is set from #onWebViewProviderChanged(). */ Loading @@ -67,7 +75,9 @@ public class WebViewZygote { public static ZygoteProcess getProcess() { synchronized (sLock) { connectToZygoteIfNeededLocked(); if (sZygote != null) return sZygote; waitForServiceStartAndConnect(); return sZygote; } } Loading Loading @@ -95,17 +105,20 @@ public class WebViewZygote { final String serviceName = getServiceNameLocked(); if (serviceName == null) return; if (enabled && sZygote == null) { if (enabled) { if (!sStartedService) { SystemService.start(serviceName); sStartedService = true; } } else { SystemService.stop(serviceName); sStartedService = false; sZygote = null; } } } public static void onWebViewProviderChanged(PackageInfo packageInfo) { String serviceName; synchronized (sLock) { sPackage = packageInfo; Loading @@ -114,7 +127,7 @@ public class WebViewZygote { return; } serviceName = getServiceNameLocked(); final String serviceName = getServiceNameLocked(); sZygote = null; // The service may enter the RUNNING state before it opens the socket, Loading @@ -124,7 +137,20 @@ public class WebViewZygote { } else { SystemService.restart(serviceName); } sStartedService = true; } } private static void waitForServiceStartAndConnect() { if (!sStartedService) { throw new AndroidRuntimeException("Tried waiting for the WebView Zygote Service to " + "start running without first starting the service."); } String serviceName; synchronized (sLock) { serviceName = getServiceNameLocked(); } try { SystemService.waitForState(serviceName, SystemService.State.RUNNING, 5000); } catch (TimeoutException e) { Loading @@ -132,6 +158,7 @@ public class WebViewZygote { return; } synchronized (sLock) { connectToZygoteIfNeededLocked(); } } Loading @@ -151,8 +178,9 @@ public class WebViewZygote { @GuardedBy("sLock") private static void connectToZygoteIfNeededLocked() { if (sZygote != null) if (sZygote != null) { return; } if (sPackage == null) { Log.e(LOGTAG, "Cannot connect to zygote, no package specified"); Loading Loading
core/java/android/webkit/WebViewZygote.java +40 −12 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.os.Build; import android.os.SystemService; import android.os.ZygoteProcess; import android.text.TextUtils; import android.util.AndroidRuntimeException; import android.util.Log; import com.android.internal.annotations.GuardedBy; Loading Loading @@ -52,6 +53,13 @@ public class WebViewZygote { @GuardedBy("sLock") private static ZygoteProcess sZygote; /** * Variable that allows us to determine whether the WebView zygote Service has already been * started. */ @GuardedBy("sLock") private static boolean sStartedService = false; /** * Information about the selected WebView package. This is set from #onWebViewProviderChanged(). */ Loading @@ -67,7 +75,9 @@ public class WebViewZygote { public static ZygoteProcess getProcess() { synchronized (sLock) { connectToZygoteIfNeededLocked(); if (sZygote != null) return sZygote; waitForServiceStartAndConnect(); return sZygote; } } Loading Loading @@ -95,17 +105,20 @@ public class WebViewZygote { final String serviceName = getServiceNameLocked(); if (serviceName == null) return; if (enabled && sZygote == null) { if (enabled) { if (!sStartedService) { SystemService.start(serviceName); sStartedService = true; } } else { SystemService.stop(serviceName); sStartedService = false; sZygote = null; } } } public static void onWebViewProviderChanged(PackageInfo packageInfo) { String serviceName; synchronized (sLock) { sPackage = packageInfo; Loading @@ -114,7 +127,7 @@ public class WebViewZygote { return; } serviceName = getServiceNameLocked(); final String serviceName = getServiceNameLocked(); sZygote = null; // The service may enter the RUNNING state before it opens the socket, Loading @@ -124,7 +137,20 @@ public class WebViewZygote { } else { SystemService.restart(serviceName); } sStartedService = true; } } private static void waitForServiceStartAndConnect() { if (!sStartedService) { throw new AndroidRuntimeException("Tried waiting for the WebView Zygote Service to " + "start running without first starting the service."); } String serviceName; synchronized (sLock) { serviceName = getServiceNameLocked(); } try { SystemService.waitForState(serviceName, SystemService.State.RUNNING, 5000); } catch (TimeoutException e) { Loading @@ -132,6 +158,7 @@ public class WebViewZygote { return; } synchronized (sLock) { connectToZygoteIfNeededLocked(); } } Loading @@ -151,8 +178,9 @@ public class WebViewZygote { @GuardedBy("sLock") private static void connectToZygoteIfNeededLocked() { if (sZygote != null) if (sZygote != null) { return; } if (sPackage == null) { Log.e(LOGTAG, "Cannot connect to zygote, no package specified"); Loading