diff options
| author | 2016-03-15 18:23:01 +0000 | |
|---|---|---|
| committer | 2016-03-15 18:23:03 +0000 | |
| commit | 53ea5a2f071909e10e21b53ca974d2016c400173 (patch) | |
| tree | 98ebda965029d17291646711a5789efe0e5d1d93 | |
| parent | 68b36ee07b6f8c184e0b9f297ae672b5685a978c (diff) | |
| parent | 43b28b17d2af269f58a7b0b8d8714444ac9bbd76 (diff) | |
Merge "Restore fix for native activity without a java-code" into nyc-dev
| -rw-r--r-- | core/java/android/app/LoadedApk.java | 154 |
1 files changed, 76 insertions, 78 deletions
diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java index b8fc32308961..a03fd7236694 100644 --- a/core/java/android/app/LoadedApk.java +++ b/core/java/android/app/LoadedApk.java @@ -281,7 +281,7 @@ public final class LoadedApk { addedPaths.addAll(newPaths); } synchronized (this) { - mClassLoader = createOrUpdateClassLoaderLocked(addedPaths); + createOrUpdateClassLoaderLocked(addedPaths); if (mResources != null) { mResources = mActivityThread.getTopLevelResources(mResDir, mSplitResDirs, mOverlayDirs, mApplicationInfo.sharedLibraryFiles, Display.DEFAULT_DISPLAY, @@ -402,101 +402,99 @@ public final class LoadedApk { } } } - - final String zip = TextUtils.join(File.pathSeparator, outZipPaths); } - private ClassLoader createOrUpdateClassLoaderLocked(List<String> addedPaths) { - final ClassLoader classLoader; - if (mIncludeCode && !mPackageName.equals("android")) { - // 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. - if (!Objects.equals(mPackageName, ActivityThread.currentPackageName())) { - VMRuntime.getRuntime().vmInstructionSet(); - try { - ActivityThread.getPackageManager().notifyPackageUse(mPackageName); - } catch (RemoteException re) { - throw re.rethrowFromSystemServer(); - } + private void createOrUpdateClassLoaderLocked(List<String> addedPaths) { + if (mPackageName.equals("android")) { + if (mClassLoader != null) { + // nothing to update + return; } - final List<String> zipPaths = new ArrayList<>(); - final List<String> libPaths = new ArrayList<>(); - - if (mRegisterPackage) { - try { - ActivityManagerNative.getDefault().addPackageDependency(mPackageName); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } + if (mBaseClassLoader != null) { + mClassLoader = mBaseClassLoader; + } else { + mClassLoader = ClassLoader.getSystemClassLoader(); } - makePaths(mActivityThread, mApplicationInfo, zipPaths, libPaths); - final String zip = TextUtils.join(File.pathSeparator, zipPaths); - final boolean isBundledApp = mApplicationInfo.isSystemApp() - && !mApplicationInfo.isUpdatedSystemApp(); - String libraryPermittedPath = mDataDir; - if (isBundledApp) { - // This is necessary to grant bundled apps access to - // libraries located in subdirectories of /system/lib - libraryPermittedPath += File.pathSeparator + - System.getProperty("java.library.path"); + return; + } + + // 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. + if (!Objects.equals(mPackageName, ActivityThread.currentPackageName())) { + VMRuntime.getRuntime().vmInstructionSet(); + try { + ActivityThread.getPackageManager().notifyPackageUse(mPackageName); + } catch (RemoteException re) { + throw re.rethrowFromSystemServer(); } - // DO NOT SHIP: this is a workaround for apps loading native libraries - // provided by 3rd party apps using absolute path instead of corresponding - // classloader; see http://b/26954419 for example. - if (mApplicationInfo.targetSdkVersion <= 23) { - libraryPermittedPath += File.pathSeparator + "/data/app"; + } + + final List<String> zipPaths = new ArrayList<>(); + final List<String> libPaths = new ArrayList<>(); + + if (mRegisterPackage) { + try { + ActivityManagerNative.getDefault().addPackageDependency(mPackageName); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); } - // ----------------------------------------------------------------------------- + } - final String librarySearchPath = TextUtils.join(File.pathSeparator, libPaths); + makePaths(mActivityThread, mApplicationInfo, zipPaths, libPaths); + final String zip = mIncludeCode ? TextUtils.join(File.pathSeparator, zipPaths) : ""; + final boolean isBundledApp = mApplicationInfo.isSystemApp() + && !mApplicationInfo.isUpdatedSystemApp(); + String libraryPermittedPath = mDataDir; + if (isBundledApp) { + // This is necessary to grant bundled apps access to + // libraries located in subdirectories of /system/lib + libraryPermittedPath += File.pathSeparator + + System.getProperty("java.library.path"); + } + // DO NOT SHIP: this is a workaround for apps loading native libraries + // provided by 3rd party apps using absolute path instead of corresponding + // classloader; see http://b/26954419 for example. + if (mApplicationInfo.targetSdkVersion <= 23) { + libraryPermittedPath += File.pathSeparator + "/data/app"; + } + // ----------------------------------------------------------------------------- - /* - * With all the combination done (if necessary, actually - * create the class loader. - */ + final String librarySearchPath = TextUtils.join(File.pathSeparator, libPaths); - if (ActivityThread.localLOGV) - Slog.v(ActivityThread.TAG, "Class path: " + zip + - ", JNI path: " + librarySearchPath); + /* + * With all the combination done (if necessary, actually + * create the class loader. + */ - if (mClassLoader == null) { - // Temporarily disable logging of disk reads on the Looper thread - // as this is early and necessary. - StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); - - classLoader = ApplicationLoaders.getDefault().getClassLoader(zip, - mApplicationInfo.targetSdkVersion, isBundledApp, librarySearchPath, - libraryPermittedPath, mBaseClassLoader); - - StrictMode.setThreadPolicy(oldPolicy); - } else if (addedPaths != null && addedPaths.size() > 0) { - final String add = TextUtils.join(File.pathSeparator, addedPaths); - ApplicationLoaders.getDefault().addPath(mClassLoader, add); - classLoader = mClassLoader; - } else { - classLoader = mClassLoader; - } - } else { - if (mClassLoader == null) { - if (mBaseClassLoader == null) { - classLoader = ClassLoader.getSystemClassLoader(); - } else { - classLoader = mBaseClassLoader; - } - } else { - classLoader = mClassLoader; - } + if (ActivityThread.localLOGV) + Slog.v(ActivityThread.TAG, "Class path: " + zip + + ", JNI path: " + librarySearchPath); + + if (mClassLoader == null) { + // Temporarily disable logging of disk reads on the Looper thread + // as this is early and necessary. + StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); + + mClassLoader = ApplicationLoaders.getDefault().getClassLoader(zip, + mApplicationInfo.targetSdkVersion, isBundledApp, librarySearchPath, + libraryPermittedPath, mBaseClassLoader); + + StrictMode.setThreadPolicy(oldPolicy); + } + + if (addedPaths != null && addedPaths.size() > 0) { + final String add = TextUtils.join(File.pathSeparator, addedPaths); + ApplicationLoaders.getDefault().addPath(mClassLoader, add); } - return classLoader; } public ClassLoader getClassLoader() { synchronized (this) { if (mClassLoader == null) { - mClassLoader = createOrUpdateClassLoaderLocked(null /*addedPaths*/); + createOrUpdateClassLoaderLocked(null /*addedPaths*/); } return mClassLoader; } |