diff options
| author | Orion Hodson <oth@google.com> | 2021-06-23 17:33:43 +0100 |
|---|---|---|
| committer | Orion Hodson <oth@google.com> | 2021-06-24 20:09:56 +0000 |
| commit | d0d23f5a2be1b24cd707ae2fc27288fe00674269 (patch) | |
| tree | c66f8fc596b5ece7819e9d10c613d9f5485cd8d3 /core/java | |
| parent | f9eb7b947a88b905a1cd4bb3e0b22582cae26055 (diff) | |
Revert^2 "Zygote: Load system server code early"
This reverts commit 6be3b0e117903c6aa696f91829012e74df8a4581.
Bug: 180949581
Test: atest odsign_e2e_tests
Change-Id: I7a7dd5b475af4502dc9671d2dce02ee3673ddf81
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/com/android/internal/os/ZygoteInit.java | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java index cb6008bfa961..a2b51ed7c80b 100644 --- a/core/java/com/android/internal/os/ZygoteInit.java +++ b/core/java/com/android/internal/os/ZygoteInit.java @@ -127,6 +127,12 @@ public class ZygoteInit { private static boolean sPreloadComplete; + /** + * Cached classloader to use for the system server. Will only be populated in the system + * server process. + */ + private static ClassLoader sCachedSystemServerClassLoader = null; + static void preload(TimingsTraceLog bootTimingsTraceLog) { Log.d(TAG, "begin preload"); bootTimingsTraceLog.traceBegin("BeginPreload"); @@ -543,10 +549,8 @@ public class ZygoteInit { throw new IllegalStateException("Unexpected return from WrapperInit.execApplication"); } else { - ClassLoader cl = null; - if (systemServerClasspath != null) { - cl = createPathClassLoader(systemServerClasspath, parsedArgs.mTargetSdkVersion); - + ClassLoader cl = getOrCreateSystemServerClassLoader(); + if (cl != null) { Thread.currentThread().setContextClassLoader(cl); } @@ -562,6 +566,23 @@ public class ZygoteInit { } /** + * Create the classloader for the system server and store it in + * {@link sCachedSystemServerClassLoader}. This function may be called through JNI in + * system server startup, when the runtime is in a critically low state. Do not do + * extended computation etc here. + */ + private static ClassLoader getOrCreateSystemServerClassLoader() { + if (sCachedSystemServerClassLoader == null) { + final String systemServerClasspath = Os.getenv("SYSTEMSERVERCLASSPATH"); + if (systemServerClasspath != null) { + sCachedSystemServerClassLoader = createPathClassLoader(systemServerClasspath, + VMRuntime.SDK_VERSION_CUR_DEVELOPMENT); + } + } + return sCachedSystemServerClassLoader; + } + + /** * Note that preparing the profiles for system server does not require special selinux * permissions. From the installer perspective the system server is a regular package which can * capture profile information. |
