From e6bcbdcafa839f32c83395f88e4e1042278f2e64 Mon Sep 17 00:00:00 2001 From: Rhed Jao Date: Wed, 21 Apr 2021 16:42:37 +0800 Subject: [PATCH] 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 --- core/java/android/app/ActivityThread.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 0acc4b3b61106..0ae13d79f06ba 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -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(