diff options
| -rwxr-xr-x | api/current.txt | 3 | ||||
| -rw-r--r-- | core/java/android/app/AppComponentFactory.java | 18 | ||||
| -rw-r--r-- | core/java/android/app/LoadedApk.java | 26 |
3 files changed, 18 insertions, 29 deletions
diff --git a/api/current.txt b/api/current.txt index e789d5b3f6b0..288a8a0a60c3 100755 --- a/api/current.txt +++ b/api/current.txt @@ -4203,10 +4203,9 @@ package android.app { public class AppComponentFactory { ctor public AppComponentFactory(); - method public android.content.pm.ApplicationInfo getApplicationInfo(); method @NonNull public android.app.Activity instantiateActivity(@NonNull ClassLoader, @NonNull String, @Nullable android.content.Intent) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException; method @NonNull public android.app.Application instantiateApplication(@NonNull ClassLoader, @NonNull String) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException; - method @NonNull public ClassLoader instantiateClassLoader(@NonNull ClassLoader); + method @NonNull public ClassLoader instantiateClassLoader(@NonNull ClassLoader, @NonNull android.content.pm.ApplicationInfo); method @NonNull public android.content.ContentProvider instantiateProvider(@NonNull ClassLoader, @NonNull String) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException; method @NonNull public android.content.BroadcastReceiver instantiateReceiver(@NonNull ClassLoader, @NonNull String, @Nullable android.content.Intent) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException; method @NonNull public android.app.Service instantiateService(@NonNull ClassLoader, @NonNull String, @Nullable android.content.Intent) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException; diff --git a/core/java/android/app/AppComponentFactory.java b/core/java/android/app/AppComponentFactory.java index ae632915dd2d..2cec7f0fc323 100644 --- a/core/java/android/app/AppComponentFactory.java +++ b/core/java/android/app/AppComponentFactory.java @@ -27,6 +27,7 @@ import android.content.pm.ApplicationInfo; * * @see #instantiateApplication * @see #instantiateActivity + * @see #instantiateClassLoader * @see #instantiateService * @see #instantiateReceiver * @see #instantiateProvider @@ -39,8 +40,10 @@ public class AppComponentFactory { * a custom class loader hierarchy. * * @param cl The default classloader instantiated by platform. + * @param aInfo Information about the application being loaded. */ - public @NonNull ClassLoader instantiateClassLoader(@NonNull ClassLoader cl) { + public @NonNull ClassLoader instantiateClassLoader(@NonNull ClassLoader cl, + @NonNull ApplicationInfo aInfo) { return cl; } @@ -133,19 +136,6 @@ public class AppComponentFactory { return (ContentProvider) cl.loadClass(className).newInstance(); } - private ApplicationInfo mApplicationInfo = null; - - void setApplicationInfo(ApplicationInfo info) { - mApplicationInfo = info; - } - - /** - * Returns the ApplicationInfo associated with this package. - */ - public ApplicationInfo getApplicationInfo() { - return mApplicationInfo; - } - /** * @hide */ diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java index ac33c169288b..3a76de442777 100644 --- a/core/java/android/app/LoadedApk.java +++ b/core/java/android/app/LoadedApk.java @@ -232,7 +232,8 @@ public final class LoadedApk { mResources = Resources.getSystem(); mDefaultClassLoader = ClassLoader.getSystemClassLoader(); mAppComponentFactory = createAppFactory(mApplicationInfo, mDefaultClassLoader); - mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader); + mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader, + new ApplicationInfo(mApplicationInfo)); } /** @@ -243,19 +244,15 @@ public final class LoadedApk { mApplicationInfo = info; mDefaultClassLoader = classLoader; mAppComponentFactory = createAppFactory(info, mDefaultClassLoader); - mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader); + mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader, + new ApplicationInfo(mApplicationInfo)); } private AppComponentFactory createAppFactory(ApplicationInfo appInfo, ClassLoader cl) { if (appInfo.appComponentFactory != null && cl != null) { try { - AppComponentFactory factory = (AppComponentFactory) cl.loadClass( - appInfo.appComponentFactory).newInstance(); - // Pass a copy of ApplicationInfo to the factory. Copying protects the framework - // from apps which would override the factory and change ApplicationInfo contents. - // ApplicationInfo is used to set up the default class loader. - factory.setApplicationInfo(new ApplicationInfo(appInfo)); - return factory; + return (AppComponentFactory) + cl.loadClass(appInfo.appComponentFactory).newInstance(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { Slog.e(TAG, "Unable to instantiate appComponentFactory", e); } @@ -712,8 +709,8 @@ public final class LoadedApk { mDefaultClassLoader = ClassLoader.getSystemClassLoader(); } mAppComponentFactory = createAppFactory(mApplicationInfo, mDefaultClassLoader); - mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader); - + mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader, + new ApplicationInfo(mApplicationInfo)); return; } @@ -801,7 +798,8 @@ public final class LoadedApk { } if (mClassLoader == null) { - mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader); + mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader, + new ApplicationInfo(mApplicationInfo)); } return; @@ -915,8 +913,10 @@ public final class LoadedApk { // Call AppComponentFactory to select/create the main class loader of this app. // Since this may call code in the app, mDefaultClassLoader must be fully set up // before invoking the factory. + // Invoke with a copy of ApplicationInfo to protect against the app changing it. if (mClassLoader == null) { - mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader); + mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader, + new ApplicationInfo(mApplicationInfo)); } } |