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

Commit f2953dad authored by Gustav Sennton's avatar Gustav Sennton Committed by Android (Google) Code Review
Browse files

Merge "Add system API method for loading webview library from another package."

parents e7d575d8 85edb6c6
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -41589,10 +41589,19 @@ package android.webkit {
    ctor public WebViewFactory();
    method public static android.content.pm.PackageInfo getLoadedPackageInfo();
    method public static java.lang.String getWebViewPackageName();
    method public static int loadWebViewNativeLibraryFromPackage(java.lang.String);
    method public static void onWebViewUpdateInstalled();
    method public static void prepareWebViewInSystemServer();
    method public static void prepareWebViewInZygote();
    field public static final java.lang.String CHROMIUM_WEBVIEW_VMSIZE_SIZE_PROPERTY = "persist.sys.webview.vmsize";
    field public static final int LIBLOAD_ADDRESS_SPACE_NOT_RESERVED = 2; // 0x2
    field public static final int LIBLOAD_FAILED_JNI_CALL = 7; // 0x7
    field public static final int LIBLOAD_FAILED_LISTING_WEBVIEW_PACKAGES = 4; // 0x4
    field public static final int LIBLOAD_FAILED_TO_LOAD_LIBRARY = 6; // 0x6
    field public static final int LIBLOAD_FAILED_TO_OPEN_RELRO_FILE = 5; // 0x5
    field public static final int LIBLOAD_FAILED_WAITING_FOR_RELRO = 3; // 0x3
    field public static final int LIBLOAD_SUCCESS = 0; // 0x0
    field public static final int LIBLOAD_WRONG_PACKAGE_NAME = 1; // 0x1
  }
  public abstract interface WebViewFactoryProvider {
+32 −6
Original line number Diff line number Diff line
@@ -76,6 +76,18 @@ public final class WebViewFactory {
    private static boolean sAddressSpaceReserved = false;
    private static PackageInfo sPackageInfo;

    // Error codes for loadWebViewNativeLibraryFromPackage
    public static final int LIBLOAD_SUCCESS = 0;
    public static final int LIBLOAD_WRONG_PACKAGE_NAME = 1;
    public static final int LIBLOAD_ADDRESS_SPACE_NOT_RESERVED = 2;
    public static final int LIBLOAD_FAILED_WAITING_FOR_RELRO = 3;
    public static final int LIBLOAD_FAILED_LISTING_WEBVIEW_PACKAGES = 4;

    // native relro loading error codes
    public static final int LIBLOAD_FAILED_TO_OPEN_RELRO_FILE = 5;
    public static final int LIBLOAD_FAILED_TO_LOAD_LIBRARY = 6;
    public static final int LIBLOAD_FAILED_JNI_CALL = 7;

    private static class MissingWebViewPackageException extends AndroidRuntimeException {
        public MissingWebViewPackageException(String message) { super(message); }
        public MissingWebViewPackageException(Exception e) { super(e); }
@@ -136,6 +148,18 @@ public final class WebViewFactory {
        return sPackageInfo;
    }

    /**
     * Load the native library for the given package name iff that package
     * name is the same as the one providing the current webview.
     */
    public static int loadWebViewNativeLibraryFromPackage(String packageName) {
        sPackageInfo = findPreferredWebViewPackage();
        if (packageName != null && packageName.equals(sPackageInfo.packageName)) {
            return loadNativeLibrary();
        }
        return LIBLOAD_WRONG_PACKAGE_NAME;
    }

    static WebViewFactoryProvider getProvider() {
        synchronized (sProviderLock) {
            // For now the main purpose of this function (and the factory abstraction) is to keep
@@ -434,32 +458,34 @@ public final class WebViewFactory {
        }
    }

    private static void loadNativeLibrary() {
    private static int loadNativeLibrary() {
        if (!sAddressSpaceReserved) {
            Log.e(LOGTAG, "can't load with relro file; address space not reserved");
            return;
            return LIBLOAD_ADDRESS_SPACE_NOT_RESERVED;
        }

        try {
            getUpdateService().waitForRelroCreationCompleted(VMRuntime.getRuntime().is64Bit());
        } catch (RemoteException e) {
            Log.e(LOGTAG, "error waiting for relro creation, proceeding without", e);
            return;
            return LIBLOAD_FAILED_WAITING_FOR_RELRO;
        }

        try {
            String[] args = getWebViewNativeLibraryPaths();
            boolean result = nativeLoadWithRelroFile(args[0] /* path32 */,
            int result = nativeLoadWithRelroFile(args[0] /* path32 */,
                                                     args[1] /* path64 */,
                                                     CHROMIUM_WEBVIEW_NATIVE_RELRO_32,
                                                     CHROMIUM_WEBVIEW_NATIVE_RELRO_64);
            if (!result) {
            if (result != LIBLOAD_SUCCESS) {
                Log.w(LOGTAG, "failed to load with relro file, proceeding without");
            } else if (DEBUG) {
                Log.v(LOGTAG, "loaded with relro file");
            }
            return result;
        } catch (MissingWebViewPackageException e) {
            Log.e(LOGTAG, "Failed to list WebView package libraries for loadNativeLibrary", e);
            return LIBLOAD_FAILED_LISTING_WEBVIEW_PACKAGES;
        }
    }

@@ -470,6 +496,6 @@ public final class WebViewFactory {
    private static native boolean nativeReserveAddressSpace(long addressSpaceToReserve);
    private static native boolean nativeCreateRelroFile(String lib32, String lib64,
                                                        String relro32, String relro64);
    private static native boolean nativeLoadWithRelroFile(String lib32, String lib64,
    private static native int nativeLoadWithRelroFile(String lib32, String lib64,
                                                          String relro32, String relro64);
}