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

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

Merge "Zygote: Fix race condition on package preloads." into oc-dr1-dev

parents cf694ade bae484ad
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -488,7 +488,7 @@ public class ZygoteProcess {
     * Instructs the zygote to pre-load the classes and native libraries at the given paths
     * Instructs the zygote to pre-load the classes and native libraries at the given paths
     * for the specified abi. Not all zygotes support this function.
     * for the specified abi. Not all zygotes support this function.
     */
     */
    public void preloadPackageForAbi(String packagePath, String libsPath, String cacheKey,
    public boolean preloadPackageForAbi(String packagePath, String libsPath, String cacheKey,
                                        String abi) throws ZygoteStartFailedEx, IOException {
                                        String abi) throws ZygoteStartFailedEx, IOException {
        synchronized(mLock) {
        synchronized(mLock) {
            ZygoteState state = openZygoteSocketIfNeeded(abi);
            ZygoteState state = openZygoteSocketIfNeeded(abi);
@@ -508,6 +508,8 @@ public class ZygoteProcess {
            state.writer.newLine();
            state.writer.newLine();


            state.writer.flush();
            state.writer.flush();

            return (state.inputStream.readInt() == 0);
        }
        }
    }
    }


+13 −1
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import android.util.Log;
import android.webkit.WebViewFactory;
import android.webkit.WebViewFactory;
import android.webkit.WebViewFactoryProvider;
import android.webkit.WebViewFactoryProvider;


import java.io.DataOutputStream;
import java.io.File;
import java.io.File;
import java.io.IOException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.InvocationTargetException;
@@ -87,17 +88,28 @@ class WebViewZygoteInit {
            // Once we have the classloader, look up the WebViewFactoryProvider implementation and
            // Once we have the classloader, look up the WebViewFactoryProvider implementation and
            // call preloadInZygote() on it to give it the opportunity to preload the native library
            // call preloadInZygote() on it to give it the opportunity to preload the native library
            // and perform any other initialisation work that should be shared among the children.
            // and perform any other initialisation work that should be shared among the children.
            boolean preloadSucceeded = false;
            try {
            try {
                Class<WebViewFactoryProvider> providerClass =
                Class<WebViewFactoryProvider> providerClass =
                        WebViewFactory.getWebViewProviderClass(loader);
                        WebViewFactory.getWebViewProviderClass(loader);
                Object result = providerClass.getMethod("preloadInZygote").invoke(null);
                Object result = providerClass.getMethod("preloadInZygote").invoke(null);
                if (!((Boolean)result).booleanValue()) {
                preloadSucceeded = ((Boolean) result).booleanValue();
                if (!preloadSucceeded) {
                    Log.e(TAG, "preloadInZygote returned false");
                    Log.e(TAG, "preloadInZygote returned false");
                }
                }
            } catch (ClassNotFoundException | NoSuchMethodException | SecurityException |
            } catch (ClassNotFoundException | NoSuchMethodException | SecurityException |
                     IllegalAccessException | InvocationTargetException e) {
                     IllegalAccessException | InvocationTargetException e) {
                Log.e(TAG, "Exception while preloading package", e);
                Log.e(TAG, "Exception while preloading package", e);
            }
            }

            try {
                DataOutputStream socketOut = getSocketOutputStream();
                socketOut.writeInt(preloadSucceeded ? 1 : 0);
            } catch (IOException ioe) {
                Log.e(TAG, "Error writing to command socket", ioe);
                return true;
            }

            Log.i(TAG, "Package preload done");
            Log.i(TAG, "Package preload done");
            return false;
            return false;
        }
        }
+4 −0
Original line number Original line Diff line number Diff line
@@ -314,6 +314,10 @@ class ZygoteConnection {
        return ZygoteInit.isPreloadComplete();
        return ZygoteInit.isPreloadComplete();
    }
    }


    protected DataOutputStream getSocketOutputStream() {
        return mSocketOutStream;
    }

    protected boolean handlePreloadPackage(String packagePath, String libsPath, String cacheKey) {
    protected boolean handlePreloadPackage(String packagePath, String libsPath, String cacheKey) {
        throw new RuntimeException("Zyogte does not support package preloading");
        throw new RuntimeException("Zyogte does not support package preloading");
    }
    }