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

Commit 70b6130d 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
(cherry picked from commit b9c9026b)
parent de384452
Loading
Loading
Loading
Loading
+116 −115
Original line number Diff line number Diff line
@@ -261,7 +261,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.
@@ -350,7 +358,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) {
@@ -395,13 +403,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
@@ -158,7 +158,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