Merge "Move ApplicationInfo to params in AppComponentFactory" am: 96dd06a151

am: 13a48e1490

Change-Id: I2272a7f640a7ddde5002b7dd1bdf178d20db9ad3
This commit is contained in:
David Brazdil
2019-02-28 09:51:55 -08:00
committed by android-build-merger
3 changed files with 18 additions and 29 deletions

View File

@@ -4203,10 +4203,9 @@ package android.app {
public class AppComponentFactory { public class AppComponentFactory {
ctor public 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.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 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.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.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; 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;

View File

@@ -27,6 +27,7 @@ import android.content.pm.ApplicationInfo;
* *
* @see #instantiateApplication * @see #instantiateApplication
* @see #instantiateActivity * @see #instantiateActivity
* @see #instantiateClassLoader
* @see #instantiateService * @see #instantiateService
* @see #instantiateReceiver * @see #instantiateReceiver
* @see #instantiateProvider * @see #instantiateProvider
@@ -39,8 +40,10 @@ public class AppComponentFactory {
* a custom class loader hierarchy. * a custom class loader hierarchy.
* *
* @param cl The default classloader instantiated by platform. * @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; return cl;
} }
@@ -133,19 +136,6 @@ public class AppComponentFactory {
return (ContentProvider) cl.loadClass(className).newInstance(); 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 * @hide
*/ */

View File

@@ -232,7 +232,8 @@ public final class LoadedApk {
mResources = Resources.getSystem(); mResources = Resources.getSystem();
mDefaultClassLoader = ClassLoader.getSystemClassLoader(); mDefaultClassLoader = ClassLoader.getSystemClassLoader();
mAppComponentFactory = createAppFactory(mApplicationInfo, mDefaultClassLoader); 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; mApplicationInfo = info;
mDefaultClassLoader = classLoader; mDefaultClassLoader = classLoader;
mAppComponentFactory = createAppFactory(info, mDefaultClassLoader); mAppComponentFactory = createAppFactory(info, mDefaultClassLoader);
mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader); mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader,
new ApplicationInfo(mApplicationInfo));
} }
private AppComponentFactory createAppFactory(ApplicationInfo appInfo, ClassLoader cl) { private AppComponentFactory createAppFactory(ApplicationInfo appInfo, ClassLoader cl) {
if (appInfo.appComponentFactory != null && cl != null) { if (appInfo.appComponentFactory != null && cl != null) {
try { try {
AppComponentFactory factory = (AppComponentFactory) cl.loadClass( return (AppComponentFactory)
appInfo.appComponentFactory).newInstance(); 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;
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
Slog.e(TAG, "Unable to instantiate appComponentFactory", e); Slog.e(TAG, "Unable to instantiate appComponentFactory", e);
} }
@@ -712,8 +709,8 @@ public final class LoadedApk {
mDefaultClassLoader = ClassLoader.getSystemClassLoader(); mDefaultClassLoader = ClassLoader.getSystemClassLoader();
} }
mAppComponentFactory = createAppFactory(mApplicationInfo, mDefaultClassLoader); mAppComponentFactory = createAppFactory(mApplicationInfo, mDefaultClassLoader);
mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader); mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader,
new ApplicationInfo(mApplicationInfo));
return; return;
} }
@@ -801,7 +798,8 @@ public final class LoadedApk {
} }
if (mClassLoader == null) { if (mClassLoader == null) {
mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader); mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader,
new ApplicationInfo(mApplicationInfo));
} }
return; return;
@@ -915,8 +913,10 @@ public final class LoadedApk {
// Call AppComponentFactory to select/create the main class loader of this app. // 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 // Since this may call code in the app, mDefaultClassLoader must be fully set up
// before invoking the factory. // before invoking the factory.
// Invoke with a copy of ApplicationInfo to protect against the app changing it.
if (mClassLoader == null) { if (mClassLoader == null) {
mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader); mClassLoader = mAppComponentFactory.instantiateClassLoader(mDefaultClassLoader,
new ApplicationInfo(mApplicationInfo));
} }
} }