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

Commit a6ef052f authored by Jason Monk's avatar Jason Monk Committed by android-build-merger
Browse files

Merge "Fix crash in monodroid apps" into oc-dr1-dev

am: 3d80a733

Change-Id: If80299af64fac8138e4cf9b681ebed13e09b8ccf
parents 7ab87b35 3d80a733
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -6450,9 +6450,9 @@ public final class ActivityThread {
    private <T> T instantiate(ClassLoader cl, String className, Context c,
            Instantiator<T> instantiator)
            throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        if (c.getApplicationContext() instanceof Application) {
            T a = instantiator.instantiate((Application) c.getApplicationContext(),
                    cl, className);
        Application app = getApp(c);
        if (app != null) {
            T a = instantiator.instantiate(app, cl, className);
            if (a != null) return a;
        }
        return (T) cl.loadClass(className).newInstance();
@@ -6461,14 +6461,25 @@ public final class ActivityThread {
    private <T> T instantiate(ClassLoader cl, String className, Intent intent, Context c,
            IntentInstantiator<T> instantiator)
            throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        if (c.getApplicationContext() instanceof Application) {
            T a = instantiator.instantiate((Application) c.getApplicationContext(),
                    cl, className, intent);
        Application app = getApp(c);
        if (app != null) {
            T a = instantiator.instantiate(app, cl, className, intent);
            if (a != null) return a;
        }
        return (T) cl.loadClass(className).newInstance();
    }

    private Application getApp(Context c) {
        // We need this shortcut to avoid actually calling getApplicationContext() on an Application
        // because the Application may not return itself for getApplicationContext() because the
        // API doesn't enforce it.
        if (c instanceof Application) return (Application) c;
        if (c.getApplicationContext() instanceof Application) {
            return (Application) c.getApplicationContext();
        }
        return null;
    }

    private interface Instantiator<T> {
        T instantiate(Application app, ClassLoader cl, String className)
                throws ClassNotFoundException, IllegalAccessException, InstantiationException;