diff options
| author | Rhed Jao <rhedjao@google.com> | 2021-04-21 16:42:37 +0800 |
|---|---|---|
| committer | Rhed Jao <rhedjao@google.com> | 2021-04-21 16:44:37 +0800 |
| commit | e6bcbdcafa839f32c83395f88e4e1042278f2e64 (patch) | |
| tree | e0b6393091952d28e702b7fc7ec21ea8b6de76f7 /core/java/android | |
| parent | 01f110bfd4663e3bf07fcbed93f0b573ba1efb62 (diff) | |
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
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/ActivityThread.java | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 0acc4b3b6110..0ae13d79f06b 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( |
