diff options
| -rw-r--r-- | core/java/android/os/ZygoteProcess.java | 24 | ||||
| -rw-r--r-- | core/java/android/webkit/WebViewZygote.java | 23 | ||||
| -rw-r--r-- | core/java/com/android/internal/os/ZygoteInit.java | 16 |
3 files changed, 26 insertions, 37 deletions
diff --git a/core/java/android/os/ZygoteProcess.java b/core/java/android/os/ZygoteProcess.java index 8208438dc62a..0d81bd9c74dc 100644 --- a/core/java/android/os/ZygoteProcess.java +++ b/core/java/android/os/ZygoteProcess.java @@ -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; @@ -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); + } } diff --git a/core/java/android/webkit/WebViewZygote.java b/core/java/android/webkit/WebViewZygote.java index b519ec9c42a2..0204dff9bf9d 100644 --- a/core/java/android/webkit/WebViewZygote.java +++ b/core/java/android/webkit/WebViewZygote.java @@ -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, @@ -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) { - } - } - } } diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java index 142effbbf0c7..4ce6ec5520ca 100644 --- a/core/java/com/android/internal/os/ZygoteInit.java +++ b/core/java/com/android/internal/os/ZygoteInit.java @@ -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() { |