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

Commit b9c9026b authored by Dimitry Ivanov's avatar Dimitry Ivanov
Browse files

Construct classloader for apps with no java code

The commit 6f06ad7d
fixed a way to load native library for NativeActivity
by using classloader logic to find the library; which
also fixed the problem of native activity not working
when library is supposed to be opened directly from
the apk.

As a side effect it introduced regression - apps without
java code did not have correctly initialized classloader.
This change fixes this by constructing classloader with
empty dexpath but valid nativeLibrarySearchPath.

Bug: http://b/26015561
Bug: http://b/27250344
Change-Id: I50f1119f0976a95edd75d88efb9fcdedc57efbc3
parent ea168d22
Loading
Loading
Loading
Loading
+123 −122
Original line number Diff line number Diff line
@@ -268,7 +268,15 @@ public final class LoadedApk {
                return mClassLoader;
            }

            if (mIncludeCode && !mPackageName.equals("android")) {
            if (mPackageName.equals("android")) {
                if (mBaseClassLoader == null) {
                    mClassLoader = ClassLoader.getSystemClassLoader();
                } else {
                    mClassLoader = mBaseClassLoader;
                }
                return mClassLoader;
            }

            // Avoid the binder call when the package is the current application package.
            // The activity manager will perform ensure that dexopt is performed before
            // spinning up the process.
@@ -357,7 +365,7 @@ public final class LoadedApk {
                }
            }

                final String zip = TextUtils.join(File.pathSeparator, zipPaths);
            final String zip = mIncludeCode ? TextUtils.join(File.pathSeparator, zipPaths) : "";

            // Add path to libraries in apk for current abi
            if (mApplicationInfo.primaryCpuAbi != null) {
@@ -409,13 +417,6 @@ public final class LoadedApk {
                    librarySearchPath, libraryPermittedPath, mBaseClassLoader);

            StrictMode.setThreadPolicy(oldPolicy);
            } else {
                if (mBaseClassLoader == null) {
                    mClassLoader = ClassLoader.getSystemClassLoader();
                } else {
                    mClassLoader = mBaseClassLoader;
                }
            }
            return mClassLoader;
        }
    }
+2 −1
Original line number Diff line number Diff line
@@ -166,7 +166,8 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback2,
        String path = classLoader.findLibrary(libname);

        if (path == null) {
            throw new IllegalArgumentException("Unable to find native library: " + libname);
            throw new IllegalArgumentException("Unable to find native library " + libname +
                                               " using classloader: " + classLoader.toString());
        }
        
        byte[] nativeSavedState = savedInstanceState != null