Loading core/java/android/os/ZygoteProcess.java +24 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.os; import android.net.LocalSocket; import android.net.LocalSocketAddress; import android.util.Log; import android.util.Slog; import com.android.internal.annotations.GuardedBy; import com.android.internal.os.Zygote; import com.android.internal.util.Preconditions; Loading Loading @@ -529,4 +530,27 @@ public class ZygoteProcess { return (state.inputStream.readInt() == 0); } } /** * Try connecting to the Zygote over and over again until we hit a time-out. * @param socketName The name of the socket to connect to. */ public static void waitForConnectionToZygote(String socketName) { for (int n = 20; n >= 0; n--) { try { final ZygoteState zs = ZygoteState.connect(socketName); zs.close(); return; } catch (IOException ioe) { Log.w(LOG_TAG, "Got error connecting to zygote, retrying. msg= " + ioe.getMessage()); } try { Thread.sleep(1000); } catch (InterruptedException ie) { } } Slog.wtf(LOG_TAG, "Failed to connect to Zygote through socket " + socketName); } } core/java/android/webkit/WebViewZygote.java +1 −22 Original line number Diff line number Diff line Loading @@ -218,7 +218,7 @@ public class WebViewZygote { final String zip = (zipPaths.size() == 1) ? zipPaths.get(0) : TextUtils.join(File.pathSeparator, zipPaths); waitForZygote(); ZygoteProcess.waitForConnectionToZygote(WEBVIEW_ZYGOTE_SOCKET); Log.d(LOGTAG, "Preloading package " + zip + " " + librarySearchPath); sZygote.preloadPackageForAbi(zip, librarySearchPath, sPackageCacheKey, Loading @@ -228,25 +228,4 @@ public class WebViewZygote { sZygote = null; } } /** * Wait until a connection to the Zygote can be established. */ private static void waitForZygote() { while (true) { try { final ZygoteProcess.ZygoteState zs = ZygoteProcess.ZygoteState.connect(WEBVIEW_ZYGOTE_SOCKET); zs.close(); break; } catch (IOException ioe) { Log.w(LOGTAG, "Got error connecting to zygote, retrying. msg= " + ioe.getMessage()); } try { Thread.sleep(1000); } catch (InterruptedException ie) { } } } } core/java/com/android/internal/os/ZygoteInit.java +1 −15 Original line number Diff line number Diff line Loading @@ -786,21 +786,7 @@ public class ZygoteInit { private static void waitForSecondaryZygote(String socketName) { String otherZygoteName = Process.ZYGOTE_SOCKET.equals(socketName) ? Process.SECONDARY_ZYGOTE_SOCKET : Process.ZYGOTE_SOCKET; while (true) { try { final ZygoteProcess.ZygoteState zs = ZygoteProcess.ZygoteState.connect(otherZygoteName); zs.close(); break; } catch (IOException ioe) { Log.w(TAG, "Got error connecting to zygote, retrying. msg= " + ioe.getMessage()); } try { Thread.sleep(1000); } catch (InterruptedException ie) { } } ZygoteProcess.waitForConnectionToZygote(otherZygoteName); } static boolean isPreloadComplete() { Loading Loading
core/java/android/os/ZygoteProcess.java +24 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.os; import android.net.LocalSocket; import android.net.LocalSocketAddress; import android.util.Log; import android.util.Slog; import com.android.internal.annotations.GuardedBy; import com.android.internal.os.Zygote; import com.android.internal.util.Preconditions; Loading Loading @@ -529,4 +530,27 @@ public class ZygoteProcess { return (state.inputStream.readInt() == 0); } } /** * Try connecting to the Zygote over and over again until we hit a time-out. * @param socketName The name of the socket to connect to. */ public static void waitForConnectionToZygote(String socketName) { for (int n = 20; n >= 0; n--) { try { final ZygoteState zs = ZygoteState.connect(socketName); zs.close(); return; } catch (IOException ioe) { Log.w(LOG_TAG, "Got error connecting to zygote, retrying. msg= " + ioe.getMessage()); } try { Thread.sleep(1000); } catch (InterruptedException ie) { } } Slog.wtf(LOG_TAG, "Failed to connect to Zygote through socket " + socketName); } }
core/java/android/webkit/WebViewZygote.java +1 −22 Original line number Diff line number Diff line Loading @@ -218,7 +218,7 @@ public class WebViewZygote { final String zip = (zipPaths.size() == 1) ? zipPaths.get(0) : TextUtils.join(File.pathSeparator, zipPaths); waitForZygote(); ZygoteProcess.waitForConnectionToZygote(WEBVIEW_ZYGOTE_SOCKET); Log.d(LOGTAG, "Preloading package " + zip + " " + librarySearchPath); sZygote.preloadPackageForAbi(zip, librarySearchPath, sPackageCacheKey, Loading @@ -228,25 +228,4 @@ public class WebViewZygote { sZygote = null; } } /** * Wait until a connection to the Zygote can be established. */ private static void waitForZygote() { while (true) { try { final ZygoteProcess.ZygoteState zs = ZygoteProcess.ZygoteState.connect(WEBVIEW_ZYGOTE_SOCKET); zs.close(); break; } catch (IOException ioe) { Log.w(LOGTAG, "Got error connecting to zygote, retrying. msg= " + ioe.getMessage()); } try { Thread.sleep(1000); } catch (InterruptedException ie) { } } } }
core/java/com/android/internal/os/ZygoteInit.java +1 −15 Original line number Diff line number Diff line Loading @@ -786,21 +786,7 @@ public class ZygoteInit { private static void waitForSecondaryZygote(String socketName) { String otherZygoteName = Process.ZYGOTE_SOCKET.equals(socketName) ? Process.SECONDARY_ZYGOTE_SOCKET : Process.ZYGOTE_SOCKET; while (true) { try { final ZygoteProcess.ZygoteState zs = ZygoteProcess.ZygoteState.connect(otherZygoteName); zs.close(); break; } catch (IOException ioe) { Log.w(TAG, "Got error connecting to zygote, retrying. msg= " + ioe.getMessage()); } try { Thread.sleep(1000); } catch (InterruptedException ie) { } } ZygoteProcess.waitForConnectionToZygote(otherZygoteName); } static boolean isPreloadComplete() { Loading