Commit dbc759a8 authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

Allow passing split name to SplitCompatJobService

This allows loading services which may be in other splits besides the
chrome split. This falls back to the chrome split to prevent breaking
if the enable_chrome_child_modules gn arg is turned off.

This will be used to fix a crash in the chime module in //clank.

Bug: 1151810
Change-Id: Icabaa21c63b492ec19dd30076c87f93477a59e52
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2553978Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830188}
parent a97a85f3
...@@ -8,21 +8,34 @@ import android.app.job.JobParameters; ...@@ -8,21 +8,34 @@ import android.app.job.JobParameters;
import android.app.job.JobService; import android.app.job.JobService;
import android.content.Context; import android.content.Context;
import org.chromium.base.BundleUtils;
/** /**
* JobService base class which will call through to the given {@link Impl}. This class must be * JobService base class which will call through to the given {@link Impl}. This class must be
* present in the base module, while the Impl can be in the chrome module. * present in the base module, while the Impl can be in the chrome module.
*/ */
public class SplitCompatJobService extends JobService { public class SplitCompatJobService extends JobService {
private String mServiceClassName; private String mServiceClassName;
private String mSplitName;
private Impl mImpl; private Impl mImpl;
public SplitCompatJobService(String serviceClassName) { public SplitCompatJobService(String serviceClassName) {
mServiceClassName = serviceClassName; mServiceClassName = serviceClassName;
} }
public SplitCompatJobService(String serviceClassName, String splitName) {
mServiceClassName = serviceClassName;
mSplitName = splitName;
}
@Override @Override
protected void attachBaseContext(Context context) { protected void attachBaseContext(Context context) {
context = SplitCompatUtils.createChromeContext(context); // Make sure specified split is installed, otherwise fall back to chrome split.
if (mSplitName != null && BundleUtils.isIsolatedSplitInstalled(context, mSplitName)) {
context = BundleUtils.createIsolatedSplitContext(context, mSplitName);
} else {
context = SplitCompatUtils.createChromeContext(context);
}
mImpl = (Impl) SplitCompatUtils.newInstance(context, mServiceClassName); mImpl = (Impl) SplitCompatUtils.newInstance(context, mServiceClassName);
mImpl.setService(this); mImpl.setService(this);
super.attachBaseContext(context); super.attachBaseContext(context);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment