Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eff8ed36 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add a time-out for connecting to SystemServer, and WebView, zygotes."

parents 547fd0d0 f0c52b5e
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -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);
    }
}
+1 −22
Original line number Diff line number Diff line
@@ -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) {
            }
        }
    }
}
+1 −15
Original line number Diff line number Diff line
@@ -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() {