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

Commit 96dd06a1 authored by David Brazdil's avatar David Brazdil Committed by Gerrit Code Review
Browse files

Merge "Move ApplicationInfo to params in AppComponentFactory"

parents 222d1d04 c5a0a075
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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;
+4 −14
Original line number Diff line number Diff line
@@ -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
     */
+13 −13
Original line number Diff line number Diff line
@@ -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));
        }
    }