DroidPluginTeam / DroidPluginTeam/DroidPlugin

宿主调用插件的service: 首次失败, 贴上解决办法

Open
#76 0 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
Java
Stars
7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

宿主里要启动插件的service, 在类ServcesManager的onStart()里没有判断PluginManager.getInstance().isConnected(), 需要同步这个状态. 因为在宿主里[判断这个值智能代表宿主进程的这个值, 一旦插件进程启动, 需要在新的进程里判断这个值, 否则此次调用startService不会被传递下去
修改前:
public int onStart(Context context, Intent intent, int flags, int startId) throws Exception {
new Throwable().printStackTrace();
Intent targetIntent = intent.getParcelableExtra(Env.EXTRA_TARGET_INTENT);
if (targetIntent != null) {
ServiceInfo targetInfo = PluginManager.getInstance().resolveServiceInfo(targetIntent, 0);
if (targetInfo != null) {
Service service = mNameService.get(targetInfo.name);
if (service == null) {
handleCreateServiceOne(context, intent, targetInfo);
}
handleOnStartOne(targetIntent, flags, startId);
}
}
return -1;
}

修改后
public int onStart(Context context, Intent intent, int flags, int startId) throws Exception {
Log.i(TAG, "onStart()");
Intent targetIntent = intent.getParcelableExtra(Env.EXTRA_TARGET_INTENT);
if (targetIntent != null) {
if (PluginManager.getInstance().isConnected()) {
Log.i(TAG, "onStart(), PluginManager isConnected!");
forwardStartService(context, intent, flags, startId, targetIntent);
} else {
Log.i(TAG, "onStart(), PluginManager is NOT connected!");
waitAndStart(context, intent, flags, startId, targetIntent);
}
}
return -1;
}

private void forwardStartService(Context context, Intent intent, int flags, int startId, Intent targetIntent) throws Exception {
Log.i(TAG, "forwardStartService()");
ServiceInfo targetInfo = PluginManager.getInstance().resolveServiceInfo(targetIntent, 0);
if (targetInfo != null) {
Service service = mNameService.get(targetInfo.name);
if (service == null) {
handleCreateServiceOne(context, intent, targetInfo);
}
handleOnStartOne(targetIntent, flags, startId);
} else {
Log.i(TAG, "onStart(), ============ServiceInfo is NULL, cannot startService!!!");
}
}

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.