From b357c651c3e2444ad0c3e82458d998acceefeb20 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Tue, 17 Nov 2020 18:04:35 +0900 Subject: [PATCH] Create linker namespace in startServiceFromJar Previously the classloader would have no initialized linker namespace, so JNI libraries associated with a JAR in an APEX would not be found. Use ClassLoaderFactory to ensure that the linker namespace is initialized. Bug: 172541385 Test: manual: boot device with system server JAR using JNI in APEX Change-Id: Icc94c70b3e3817aa637c32f1190faa41364e1604 --- .../core/java/com/android/server/SystemServiceManager.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/SystemServiceManager.java b/services/core/java/com/android/server/SystemServiceManager.java index 71a18218110e9..f5d6785c0621e 100644 --- a/services/core/java/com/android/server/SystemServiceManager.java +++ b/services/core/java/com/android/server/SystemServiceManager.java @@ -21,6 +21,7 @@ import android.annotation.Nullable; import android.annotation.UserIdInt; import android.content.Context; import android.content.pm.UserInfo; +import android.os.Build; import android.os.Environment; import android.os.SystemClock; import android.os.Trace; @@ -32,6 +33,7 @@ import android.util.Slog; import android.util.SparseArray; import com.android.internal.annotations.GuardedBy; +import com.android.internal.os.ClassLoaderFactory; import com.android.internal.util.Preconditions; import com.android.server.SystemService.TargetUser; import com.android.server.am.EventLogTags; @@ -121,7 +123,10 @@ public final class SystemServiceManager implements Dumpable { if (pathClassLoader == null) { // NB: the parent class loader should always be the system server class loader. // Changing it has implications that require discussion with the mainline team. - pathClassLoader = new PathClassLoader(path, this.getClass().getClassLoader()); + pathClassLoader = (PathClassLoader) ClassLoaderFactory.createClassLoader( + path, null /* librarySearchPath */, null /* libraryPermittedPath */, + this.getClass().getClassLoader(), Build.VERSION.SDK_INT, + true /* isNamespaceShared */, null /* classLoaderName */); mLoadedPaths.put(path, pathClassLoader); } final Class serviceClass = loadClassFromLoader(className, pathClassLoader);