Skip to content

Commit

Permalink
Support "UI process" as a plug-in management process (rather than onl…
Browse files Browse the repository at this point in the history
…y support the "persistent process")

This is the second part, mainly to optimize performance,
  • Loading branch information
jiongxuan committed Aug 11, 2017
1 parent bf75346 commit 2d07650
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ static final void installHost(IPluginHost host) {
/**
* 非常驻进程调用,获取常驻进程的 IPluginHost
*/
static final void installHost() {
static final void connectToHostSvc() {
Context context = PMF.getApplicationContext();

//
Expand Down Expand Up @@ -352,6 +352,7 @@ public void binderDied() {
System.exit(1);
}

// 注册该进程信息到“插件管理进程”中
PMF.sPluginMgr.attach();
}

Expand All @@ -369,7 +370,7 @@ public static final IPluginHost getPluginHost() {
}
}
// 再次唤起常驻进程
installHost();
connectToHostSvc();
}
return sPluginHostRemote;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
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;

Expand Down Expand Up @@ -127,7 +127,7 @@ public static final Uri stubPlugin(Uri uri, ContentValues values) {
//
PMF.sPluginMgr.mLocalCookie = cookie;
//
PluginProcessMain.installHost();
PluginProcessMain.connectToHostSvc();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,26 @@ static final void cleanIntentPluginParams(Intent intent) {

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();
}
}
Expand All @@ -262,7 +269,7 @@ void init() {
* Persistent(常驻)进程的初始化
*
*/
private final void initForPersistent() {
private final void initForServer() {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "search plugins from file system");
}
Expand Down Expand Up @@ -290,8 +297,6 @@ private final void initForPersistent() {
LogRelease.e(PLUGIN_TAG, "lst.p: " + e.getMessage(), e);
}
}


}

/**
Expand All @@ -303,8 +308,17 @@ private final void initForClient() {
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();
Expand Down

0 comments on commit 2d07650

Please sign in to comment.