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

Commit 34738174 authored by tony.ys_liu's avatar tony.ys_liu Committed by Andreas Gampe
Browse files

Set system server's class loader for wrap.system_server

Root Cause: systemServer's class path is not set
  after set wrap.system_server property, and restart system_server,
  it shows a java.lang.RuntimeException:
    Missing class when invoking static main com.android.server.SystemServer

Solution: Correctly pass and parse a passed classpath.

Bug: 34692265
Test: adb root && adb shell stop && adb shell setprop wrap.system_server logwrapper && adb shell start
Change-Id: Ia6707dc05fa627af6cc28360d26b894487a6eff1
parent 40aa5ee5
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -139,6 +139,21 @@ public class WrapperInit {
            Slog.d(RuntimeInit.TAG, "RuntimeInit: Starting application from wrapper");
        }

        RuntimeInit.applicationInit(targetSdkVersion, argv, null);
        // Check whether the first argument is a "-cp" in argv, and assume the next argument is the
        // classpath. If found, create a PathClassLoader and use it for applicationInit.
        ClassLoader classLoader = null;
        if (argv != null && argv.length > 2 && argv[0].equals("-cp")) {
            classLoader = ZygoteInit.createPathClassLoader(argv[1], targetSdkVersion);

            // Install this classloader as the context classloader, too.
            Thread.currentThread().setContextClassLoader(classLoader);

            // Remove the classpath from the arguments.
            String removedArgs[] = new String[argv.length - 2];
            System.arraycopy(argv, 2, removedArgs, 0, argv.length - 2);
            argv = removedArgs;
        }

        RuntimeInit.applicationInit(targetSdkVersion, argv, classLoader);
    }
}
+8 −9
Original line number Diff line number Diff line
@@ -449,7 +449,8 @@ public class ZygoteInit {
                String[] amendedArgs = new String[args.length + 2];
                amendedArgs[0] = "-cp";
                amendedArgs[1] = systemServerClasspath;
                System.arraycopy(parsedArgs.remainingArgs, 0, amendedArgs, 2, parsedArgs.remainingArgs.length);
                System.arraycopy(args, 0, amendedArgs, 2, args.length);
                args = amendedArgs;
            }

            WrapperInit.execApplication(parsedArgs.invokeWith,
@@ -458,8 +459,7 @@ public class ZygoteInit {
        } else {
            ClassLoader cl = null;
            if (systemServerClasspath != null) {
                cl = createSystemServerClassLoader(systemServerClasspath,
                                                   parsedArgs.targetSdkVersion);
                cl = createPathClassLoader(systemServerClasspath, parsedArgs.targetSdkVersion);

                Thread.currentThread().setContextClassLoader(cl);
            }
@@ -474,15 +474,14 @@ public class ZygoteInit {
    }

    /**
     * Creates a PathClassLoader for the system server. It also creates
     * a shared namespace associated with the classloader to let it access
     * platform-private native libraries.
     * Creates a PathClassLoader for the given class path that is associated with a shared
     * namespace, i.e., this classloader can access platform-private native libraries. The
     * classloader will use java.library.path as the native library path.
     */
    private static PathClassLoader createSystemServerClassLoader(String systemServerClasspath,
                                                                 int targetSdkVersion) {
    static PathClassLoader createPathClassLoader(String classPath, int targetSdkVersion) {
      String libraryPath = System.getProperty("java.library.path");

      return PathClassLoaderFactory.createClassLoader(systemServerClasspath,
      return PathClassLoaderFactory.createClassLoader(classPath,
                                                      libraryPath,
                                                      libraryPath,
                                                      ClassLoader.getSystemClassLoader(),