Support "UI process" as a plug-in management process (rather than only support the "persistent process")

This is the second part, mainly to optimize performance,
This commit is contained in:
zhangjiongxuan 2017-08-11 18:11:28 +08:00
parent bf75346648
commit 2d07650b2d
3 changed files with 29 additions and 14 deletions

View File

@ -283,7 +283,7 @@ public class PluginProcessMain {
/**
* 非常驻进程调用获取常驻进程的 IPluginHost
*/
static final void installHost() {
static final void connectToHostSvc() {
Context context = PMF.getApplicationContext();
//
@ -352,6 +352,7 @@ public class PluginProcessMain {
System.exit(1);
}
// 注册该进程信息到插件管理进程
PMF.sPluginMgr.attach();
}
@ -369,7 +370,7 @@ public class PluginProcessMain {
}
}
// 再次唤起常驻进程
installHost();
connectToHostSvc();
}
return sPluginHostRemote;
}

View File

@ -25,13 +25,13 @@ import android.os.IBinder.DeathRecipient;
import android.os.RemoteException;
import android.text.TextUtils;
import com.qihoo360.replugin.utils.CloseableUtils;
import com.qihoo360.loader2.sp.IPref;
import com.qihoo360.loader2.sp.PrefImpl;
import com.qihoo360.replugin.base.IPC;
import com.qihoo360.replugin.component.process.ProcessPitProviderBase;
import com.qihoo360.replugin.component.process.ProcessPitProviderPersist;
import com.qihoo360.replugin.helper.LogDebug;
import com.qihoo360.replugin.utils.CloseableUtils;
import java.util.Arrays;
@ -127,7 +127,7 @@ public class PluginProviderStub {
//
PMF.sPluginMgr.mLocalCookie = cookie;
//
PluginProcessMain.installHost();
PluginProcessMain.connectToHostSvc();
}
}

View File

@ -230,19 +230,26 @@ class PmBase {
void init() {
if (HostConfigHelper.PERSISTENT_ENABLE) {
// 默认常驻进程作为插件管理进程区分进程对待
// 默认常驻进程作为插件管理进程常驻进程作为Server其余进程作为Client
if (IPC.isPersistentProcess()) {
initForPersistent();
// 初始化Server所做工作
initForServer();
} else {
// 连接到Server
initForClient();
}
} else {
// UI进程作为插件管理进程唯一进程此进程既可以作为Persistent也可以作为Client
// UI进程作为插件管理进程唯一进程UI进程既可以作为Server也可以作为Client
if (IPC.isUIProcess()) {
initForPersistent();
initForClient();
// 1. 尝试初始化Server所做工作
initForServer();
// 2. 注册该进程信息到插件管理进程
// 注意这里无需再做 initForClient因为不需要再走一次Binder
PMF.sPluginMgr.attach();
} else {
// 其它进程直接走Client即可
// 其它进程直接连接到Server即可
initForClient();
}
}
@ -262,7 +269,7 @@ class PmBase {
* Persistent(常驻)进程的初始化
*
*/
private final void initForPersistent() {
private final void initForServer() {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "search plugins from file system");
}
@ -290,8 +297,6 @@ class PmBase {
LogRelease.e(PLUGIN_TAG, "lst.p: " + e.getMessage(), e);
}
}
}
/**
@ -303,8 +308,17 @@ class PmBase {
LogDebug.d(PLUGIN_TAG, "list plugins from persistent process");
}
PluginProcessMain.installHost();
// 1. 先尝试连接
PluginProcessMain.connectToHostSvc();
// 2. 然后从常驻进程获取插件列表
refreshPluginsFromHostSvc();
}
/**
* 从HostSvc插件管理所在进程获取所有的插件信息
*/
private void refreshPluginsFromHostSvc() {
List<PluginInfo> plugins = null;
try {
plugins = PluginProcessMain.getPluginHost().listPlugins();