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

Commit e6bcbdca authored by Rhed Jao's avatar Rhed Jao
Browse files

Fix a crash when starting a service in the isolated split

A ClassNotFoundException is thrown when an application starts a
service defined in the isolated split. This cl uses the class loader
of the split to load the class of the service. It also updates the
correct split context to the service.

Bug: 169196314
Test: atest ClassloaderSplitsTest
Change-Id: If52ecb6065cdc6b0e3f2c163996df90c85a00958
parent 01f110bf
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import android.annotation.Nullable;
import android.app.assist.AssistContent;
import android.app.assist.AssistStructure;
import android.app.backup.BackupAgent;
import android.app.backup.BackupManager;
import android.app.servertransaction.ActivityLifecycleItem;
import android.app.servertransaction.ActivityLifecycleItem.LifecycleState;
import android.app.servertransaction.ActivityRelaunchItem;
@@ -4391,11 +4390,20 @@ public final class ActivityThread extends ClientTransactionHandler
            if (localLOGV) Slog.v(TAG, "Creating service " + data.info.name);

            Application app = packageInfo.makeApplication(false, mInstrumentation);
            java.lang.ClassLoader cl = packageInfo.getClassLoader();

            final java.lang.ClassLoader cl;
            if (data.info.splitName != null) {
                cl = packageInfo.getSplitClassLoader(data.info.splitName);
            } else {
                cl = packageInfo.getClassLoader();
            }
            service = packageInfo.getAppFactory()
                    .instantiateService(cl, data.info.name, data.intent);
            final ContextImpl context = ContextImpl.getImpl(service
            ContextImpl context = ContextImpl.getImpl(service
                    .createServiceBaseContext(this, packageInfo));
            if (data.info.splitName != null) {
                context = (ContextImpl) context.createContextForSplit(data.info.splitName);
            }
            // Service resources must be initialized with the same loaders as the application
            // context.
            context.getResources().addLoaders(