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

Commit 92f9bfae authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Rework WebView startup timestamp system API." into sc-dev am: 99e37aca am: 3a1b86f4

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14602033

Change-Id: Icdedd6a67ebde91e39b810e4157cf90676e61b54
parents 41e7f81d 3a1b86f4
Loading
Loading
Loading
Loading
+15 −12
Original line number Diff line number Diff line
@@ -14735,7 +14735,7 @@ package android.webkit {
    method public String getDataDirectorySuffix();
    method public String getErrorString(android.content.Context, int);
    method public int getPackageId(android.content.res.Resources, String);
    method @NonNull public long[] getTimestamps();
    method @NonNull public android.webkit.WebViewFactory.StartupTimestamps getStartupTimestamps();
    method @Deprecated public void invokeDrawGlFunctor(android.view.View, long, boolean);
    method public boolean isMultiProcessEnabled();
    method public boolean isTraceTagEnabled();
@@ -14751,12 +14751,6 @@ package android.webkit {
    method public static android.content.pm.PackageInfo getLoadedPackageInfo();
    method public static int loadWebViewNativeLibraryFromPackage(String, ClassLoader);
    method public static void prepareWebViewInZygote();
    field public static final int ADD_ASSETS_END = 4; // 0x4
    field public static final int ADD_ASSETS_START = 3; // 0x3
    field public static final int CREATE_CONTEXT_END = 2; // 0x2
    field public static final int CREATE_CONTEXT_START = 1; // 0x1
    field public static final int GET_CLASS_LOADER_END = 6; // 0x6
    field public static final int GET_CLASS_LOADER_START = 5; // 0x5
    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
@@ -14767,11 +14761,20 @@ package android.webkit {
    field public static final int LIBLOAD_FAILED_WAITING_FOR_WEBVIEW_REASON_UNKNOWN = 8; // 0x8
    field public static final int LIBLOAD_SUCCESS = 0; // 0x0
    field public static final int LIBLOAD_WRONG_PACKAGE_NAME = 1; // 0x1
    field public static final int NATIVE_LOAD_END = 8; // 0x8
    field public static final int NATIVE_LOAD_START = 7; // 0x7
    field public static final int PROVIDER_CLASS_FOR_NAME_END = 10; // 0xa
    field public static final int PROVIDER_CLASS_FOR_NAME_START = 9; // 0x9
    field public static final int WEBVIEW_LOAD_START = 0; // 0x0
  }
  public static class WebViewFactory.StartupTimestamps {
    method public long getAddAssetsEnd();
    method public long getAddAssetsStart();
    method public long getCreateContextEnd();
    method public long getCreateContextStart();
    method public long getGetClassLoaderEnd();
    method public long getGetClassLoaderStart();
    method public long getNativeLoadEnd();
    method public long getNativeLoadStart();
    method public long getProviderClassForNameEnd();
    method public long getProviderClassForNameStart();
    method public long getWebViewLoadStart();
  }
  public interface WebViewFactoryProvider {
+3 −6
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package android.webkit;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.UptimeMillisLong;
import android.app.ActivityThread;
import android.app.Application;
import android.app.ResourcesManager;
@@ -221,14 +220,12 @@ public final class WebViewDelegate {
    }

    /**
     * Returns an array of startup timestamps. For the specification of array
     * see {@link WebViewFactory.Timestamp}.
     * Get the timestamps at which various WebView startup events occurred in this process.
     * This method must be called on the same thread where the
     * WebViewChromiumFactoryProvider#create method was invoked.
     */
    @NonNull
    @UptimeMillisLong
    public long[] getTimestamps() {
        return WebViewFactory.getTimestamps();
    public WebViewFactory.StartupTimestamps getStartupTimestamps() {
        return WebViewFactory.getStartupTimestamps();
    }
}
+100 −54
Original line number Diff line number Diff line
@@ -16,9 +16,9 @@

package android.webkit;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.annotation.UptimeMillisLong;
import android.app.ActivityManager;
import android.app.AppGlobals;
import android.app.Application;
@@ -38,8 +38,6 @@ import android.util.ArraySet;
import android.util.Log;

import java.io.File;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;

/**
@@ -72,44 +70,6 @@ public final class WebViewFactory {
    private static boolean sWebViewDisabled;
    private static String sDataDirectorySuffix; // stored here so it can be set without loading WV

    // Indices in sTimestamps array.
    /** @hide */
    @IntDef(value = {
            WEBVIEW_LOAD_START, CREATE_CONTEXT_START, CREATE_CONTEXT_END,
            ADD_ASSETS_START, ADD_ASSETS_END, GET_CLASS_LOADER_START, GET_CLASS_LOADER_END,
            NATIVE_LOAD_START, NATIVE_LOAD_END,
            PROVIDER_CLASS_FOR_NAME_START, PROVIDER_CLASS_FOR_NAME_END})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Timestamp {
    }

    /** When the overall WebView provider load began. */
    public static final int WEBVIEW_LOAD_START = 0;
    /** Before creating the WebView APK Context. */
    public static final int CREATE_CONTEXT_START = 1;
    /** After creating the WebView APK Context. */
    public static final int CREATE_CONTEXT_END = 2;
    /** Before adding WebView assets to AssetManager. */
    public static final int ADD_ASSETS_START = 3;
    /** After adding WebView assets to AssetManager. */
    public static final int ADD_ASSETS_END = 4;
    /** Before creating the WebView ClassLoader. */
    public static final int GET_CLASS_LOADER_START = 5;
    /** After creating the WebView ClassLoader. */
    public static final int GET_CLASS_LOADER_END = 6;
    /** Before preloading the WebView native library. */
    public static final int NATIVE_LOAD_START = 7;
    /** After preloading the WebView native library. */
    public static final int NATIVE_LOAD_END = 8;
    /** Before looking up the WebView provider class. */
    public static final int PROVIDER_CLASS_FOR_NAME_START = 9;
    /** After looking up the WebView provider class. */
    public static final int PROVIDER_CLASS_FOR_NAME_END = 10;
    private static final int TIMESTAMPS_SIZE = 11;

    // WebView startup timestamps. To access elements use {@link Timestamp}.
    private static long[] sTimestamps = new long[TIMESTAMPS_SIZE];

    // Error codes for loadWebViewNativeLibraryFromPackage
    public static final int LIBLOAD_SUCCESS = 0;
    public static final int LIBLOAD_WRONG_PACKAGE_NAME = 1;
@@ -130,6 +90,97 @@ public final class WebViewFactory {
    // error for namespace lookup
    public static final int LIBLOAD_FAILED_TO_FIND_NAMESPACE = 10;

    /**
     * Stores the timestamps at which various WebView startup events occurred in this process.
     */
    public static class StartupTimestamps {
        long mWebViewLoadStart;
        long mCreateContextStart;
        long mCreateContextEnd;
        long mAddAssetsStart;
        long mAddAssetsEnd;
        long mGetClassLoaderStart;
        long mGetClassLoaderEnd;
        long mNativeLoadStart;
        long mNativeLoadEnd;
        long mProviderClassForNameStart;
        long mProviderClassForNameEnd;

        StartupTimestamps() {}

        /** When the overall WebView provider load began. */
        @UptimeMillisLong
        public long getWebViewLoadStart() {
            return mWebViewLoadStart;
        }

        /** Before creating the WebView APK Context. */
        @UptimeMillisLong
        public long getCreateContextStart() {
            return mCreateContextStart;
        }

        /** After creating the WebView APK Context. */
        @UptimeMillisLong
        public long getCreateContextEnd() {
            return mCreateContextEnd;
        }

        /** Before adding WebView assets to AssetManager. */
        @UptimeMillisLong
        public long getAddAssetsStart() {
            return mAddAssetsStart;
        }

        /** After adding WebView assets to AssetManager. */
        @UptimeMillisLong
        public long getAddAssetsEnd() {
            return mAddAssetsEnd;
        }

        /** Before creating the WebView ClassLoader. */
        @UptimeMillisLong
        public long getGetClassLoaderStart() {
            return mGetClassLoaderStart;
        }

        /** After creating the WebView ClassLoader. */
        @UptimeMillisLong
        public long getGetClassLoaderEnd() {
            return mGetClassLoaderEnd;
        }

        /** Before preloading the WebView native library. */
        @UptimeMillisLong
        public long getNativeLoadStart() {
            return mNativeLoadStart;
        }

        /** After preloading the WebView native library. */
        @UptimeMillisLong
        public long getNativeLoadEnd() {
            return mNativeLoadEnd;
        }

        /** Before looking up the WebView provider class. */
        @UptimeMillisLong
        public long getProviderClassForNameStart() {
            return mProviderClassForNameStart;
        }

        /** After looking up the WebView provider class. */
        @UptimeMillisLong
        public long getProviderClassForNameEnd() {
            return mProviderClassForNameEnd;
        }
    }

    static final StartupTimestamps sTimestamps = new StartupTimestamps();

    @NonNull
    static StartupTimestamps getStartupTimestamps() {
        return sTimestamps;
    }

    private static String getWebViewPreparationErrorReason(int error) {
        switch (error) {
@@ -273,7 +324,7 @@ public final class WebViewFactory {
            // us honest and minimize usage of WebView internals when binding the proxy.
            if (sProviderInstance != null) return sProviderInstance;

            sTimestamps[WEBVIEW_LOAD_START] = SystemClock.uptimeMillis();
            sTimestamps.mWebViewLoadStart = SystemClock.uptimeMillis();
            final int uid = android.os.Process.myUid();
            if (uid == android.os.Process.ROOT_UID || uid == android.os.Process.SYSTEM_UID
                    || uid == android.os.Process.PHONE_UID || uid == android.os.Process.NFC_UID
@@ -413,7 +464,7 @@ public final class WebViewFactory {

            Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW,
                    "initialApplication.createApplicationContext");
            sTimestamps[CREATE_CONTEXT_START] = SystemClock.uptimeMillis();
            sTimestamps.mCreateContextStart = SystemClock.uptimeMillis();
            try {
                // Construct an app context to load the Java code into the current app.
                Context webViewContext = initialApplication.createApplicationContext(
@@ -422,7 +473,7 @@ public final class WebViewFactory {
                sPackageInfo = newPackageInfo;
                return webViewContext;
            } finally {
                sTimestamps[CREATE_CONTEXT_END] = SystemClock.uptimeMillis();
                sTimestamps.mCreateContextEnd = SystemClock.uptimeMillis();
                Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
            }
        } catch (RemoteException | PackageManager.NameNotFoundException e) {
@@ -448,26 +499,26 @@ public final class WebViewFactory {

            Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.getChromiumProviderClass()");
            try {
                sTimestamps[ADD_ASSETS_START] = SystemClock.uptimeMillis();
                sTimestamps.mAddAssetsStart = SystemClock.uptimeMillis();
                for (String newAssetPath : webViewContext.getApplicationInfo().getAllApkPaths()) {
                    initialApplication.getAssets().addAssetPathAsSharedLibrary(newAssetPath);
                }
                sTimestamps[ADD_ASSETS_END] = sTimestamps[GET_CLASS_LOADER_START] =
                sTimestamps.mAddAssetsEnd = sTimestamps.mGetClassLoaderStart =
                        SystemClock.uptimeMillis();
                ClassLoader clazzLoader = webViewContext.getClassLoader();
                Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.loadNativeLibrary()");
                sTimestamps[GET_CLASS_LOADER_END] = sTimestamps[NATIVE_LOAD_START] =
                sTimestamps.mGetClassLoaderEnd = sTimestamps.mNativeLoadStart =
                        SystemClock.uptimeMillis();
                WebViewLibraryLoader.loadNativeLibrary(clazzLoader,
                        getWebViewLibrary(sPackageInfo.applicationInfo));
                Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
                Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "Class.forName()");
                sTimestamps[NATIVE_LOAD_END] = sTimestamps[PROVIDER_CLASS_FOR_NAME_START] =
                sTimestamps.mNativeLoadEnd = sTimestamps.mProviderClassForNameStart =
                        SystemClock.uptimeMillis();
                try {
                    return getWebViewProviderClass(clazzLoader);
                } finally {
                    sTimestamps[PROVIDER_CLASS_FOR_NAME_END] = SystemClock.uptimeMillis();
                    sTimestamps.mProviderClassForNameEnd = SystemClock.uptimeMillis();
                    Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
                }
            } catch (ClassNotFoundException e) {
@@ -529,9 +580,4 @@ public final class WebViewFactory {
        return IWebViewUpdateService.Stub.asInterface(
                ServiceManager.getService(WEBVIEW_UPDATE_SERVICE_NAME));
    }

    @NonNull
    static long[] getTimestamps() {
        return sTimestamps;
    }
}