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

Commit 13868acd authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix compat issue with apps directly calling...

Merge "Fix compat issue with apps directly calling LoadedApk.makeApplication()." into tm-dev am: 3403fc7f

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17144652

Change-Id: I3effdd62bef9866687995511ca94f1c61143cb9b
parents a03c5fdd 3403fc7f
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -3587,7 +3587,7 @@ public final class ActivityThread extends ClientTransactionHandler
        }
        }


        try {
        try {
            Application app = r.packageInfo.makeApplication(false, mInstrumentation);
            Application app = r.packageInfo.makeApplicationInner(false, mInstrumentation);


            if (localLOGV) Slog.v(TAG, "Performing launch of " + r);
            if (localLOGV) Slog.v(TAG, "Performing launch of " + r);
            if (localLOGV) Slog.v(
            if (localLOGV) Slog.v(
@@ -4286,7 +4286,7 @@ public final class ActivityThread extends ClientTransactionHandler
        BroadcastReceiver receiver;
        BroadcastReceiver receiver;
        ContextImpl context;
        ContextImpl context;
        try {
        try {
            app = packageInfo.makeApplication(false, mInstrumentation);
            app = packageInfo.makeApplicationInner(false, mInstrumentation);
            context = (ContextImpl) app.getBaseContext();
            context = (ContextImpl) app.getBaseContext();
            if (data.info.splitName != null) {
            if (data.info.splitName != null) {
                context = (ContextImpl) context.createContextForSplit(data.info.splitName);
                context = (ContextImpl) context.createContextForSplit(data.info.splitName);
@@ -4475,7 +4475,7 @@ public final class ActivityThread extends ClientTransactionHandler
        try {
        try {
            if (localLOGV) Slog.v(TAG, "Creating service " + data.info.name);
            if (localLOGV) Slog.v(TAG, "Creating service " + data.info.name);


            Application app = packageInfo.makeApplication(false, mInstrumentation);
            Application app = packageInfo.makeApplicationInner(false, mInstrumentation);


            final java.lang.ClassLoader cl;
            final java.lang.ClassLoader cl;
            if (data.info.splitName != null) {
            if (data.info.splitName != null) {
@@ -6695,7 +6695,7 @@ public final class ActivityThread extends ClientTransactionHandler
        try {
        try {
            // If the app is being launched for full backup or restore, bring it up in
            // If the app is being launched for full backup or restore, bring it up in
            // a restricted environment with the base application class.
            // a restricted environment with the base application class.
            app = data.info.makeApplication(data.restrictedBackupMode, null);
            app = data.info.makeApplicationInner(data.restrictedBackupMode, null);


            // Propagate autofill compat state
            // Propagate autofill compat state
            app.setAutofillOptions(data.autofillOptions);
            app.setAutofillOptions(data.autofillOptions);
@@ -7565,7 +7565,7 @@ public final class ActivityThread extends ClientTransactionHandler
                mInstrumentation.basicInit(this);
                mInstrumentation.basicInit(this);
                ContextImpl context = ContextImpl.createAppContext(
                ContextImpl context = ContextImpl.createAppContext(
                        this, getSystemContext().mPackageInfo);
                        this, getSystemContext().mPackageInfo);
                mInitialApplication = context.mPackageInfo.makeApplication(true, null);
                mInitialApplication = context.mPackageInfo.makeApplicationInner(true, null);
                mInitialApplication.onCreate();
                mInitialApplication.onCreate();
            } catch (Exception e) {
            } catch (Exception e) {
                throw new RuntimeException(
                throw new RuntimeException(
+30 −5
Original line number Original line Diff line number Diff line
@@ -1352,9 +1352,28 @@ public final class LoadedApk {
        return mResources;
        return mResources;
    }
    }


    /**
     * This is for 3p apps accessing this hidden API directly... in which case, we don't return
     * the cached Application instance.
     */
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    public Application makeApplication(boolean forceDefaultAppClass,
    public Application makeApplication(boolean forceDefaultAppClass,
            Instrumentation instrumentation) {
            Instrumentation instrumentation) {
        return makeApplicationInner(forceDefaultAppClass, instrumentation,
                /* allowDuplicateInstances= */ true);
    }

    /**
     * This is for all the (internal) callers, for which we do return the cached instance.
     */
    public Application makeApplicationInner(boolean forceDefaultAppClass,
            Instrumentation instrumentation) {
        return makeApplicationInner(forceDefaultAppClass, instrumentation,
                /* allowDuplicateInstances= */ false);
    }

    private Application makeApplicationInner(boolean forceDefaultAppClass,
            Instrumentation instrumentation, boolean allowDuplicateInstances) {
        if (mApplication != null) {
        if (mApplication != null) {
            return mApplication;
            return mApplication;
        }
        }
@@ -1366,12 +1385,16 @@ public final class LoadedApk {
                // Looks like this is always happening for the system server, because
                // Looks like this is always happening for the system server, because
                // the LoadedApk created in systemMain() -> attach() isn't cached properly?
                // the LoadedApk created in systemMain() -> attach() isn't cached properly?
                if (!"android".equals(mPackageName)) {
                if (!"android".equals(mPackageName)) {
                    Slog.wtf(TAG, "App instance already created for package=" + mPackageName
                    Slog.wtfStack(TAG, "App instance already created for package=" + mPackageName
                            + " instance=" + cached);
                            + " instance=" + cached);
                }
                }
                if (!allowDuplicateInstances) {
                    mApplication = cached;
                    mApplication = cached;
                    return cached;
                    return cached;
                }
                }
                // Some apps intentionally call makeApplication() to create a new Application
                // instance... Sigh...
            }
        }
        }


        Application app = null;
        Application app = null;
@@ -1421,9 +1444,11 @@ public final class LoadedApk {
        }
        }
        mActivityThread.mAllApplications.add(app);
        mActivityThread.mAllApplications.add(app);
        mApplication = app;
        mApplication = app;
        if (!allowDuplicateInstances) {
            synchronized (sApplications) {
            synchronized (sApplications) {
                sApplications.put(mPackageName, app);
                sApplications.put(mPackageName, app);
            }
            }
        }


        if (instrumentation != null) {
        if (instrumentation != null) {
            try {
            try {