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 first part, mainly the core of the realization
  • Loading branch information
jiongxuan committed Aug 11, 2017
1 parent 6bc5b01 commit bf75346
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.qihoo360.replugin.component.dummy.DummyService;
import com.qihoo360.replugin.component.process.PluginProcessHost;
import com.qihoo360.replugin.component.service.server.PluginPitService;
import com.qihoo360.replugin.helper.HostConfigHelper;
import com.qihoo360.replugin.helper.LogDebug;
import com.qihoo360.replugin.helper.LogRelease;
import com.qihoo360.replugin.model.PluginInfo;
Expand Down Expand Up @@ -228,19 +229,22 @@ static final void cleanIntentPluginParams(Intent intent) {
}

void init() {
if (IPC.isPersistentProcess()) {
mHostSvc = new PmHostSvc(mContext, this);
PluginProcessMain.installHost(mHostSvc);
PluginProcessMain.schedulePluginProcessLoop(PluginProcessMain.CHECK_STAGE1_DELAY);

} else {
PluginProcessMain.installHost();
}

if (IPC.isPersistentProcess()) {
initForPersistent();
if (HostConfigHelper.PERSISTENT_ENABLE) {
// (默认)“常驻进程”作为插件管理进程,则区分进程对待
if (IPC.isPersistentProcess()) {
initForPersistent();
} else {
initForClient();
}
} else {
initForClient();
// “UI进程”作为插件管理进程(唯一进程),则此进程既可以作为Persistent也可以作为Client
if (IPC.isUIProcess()) {
initForPersistent();
initForClient();
} else {
// 其它进程?直接走Client即可
initForClient();
}
}

// 最新快照
Expand All @@ -263,6 +267,10 @@ private final void initForPersistent() {
LogDebug.d(PLUGIN_TAG, "search plugins from file system");
}

mHostSvc = new PmHostSvc(mContext, this);
PluginProcessMain.installHost(mHostSvc);
PluginProcessMain.schedulePluginProcessLoop(PluginProcessMain.CHECK_STAGE1_DELAY);

// 兼容即将废弃的p-n方案 by Jiongxuan Zhang
mAll = new Builder.PxAll();
Builder.builder(mContext, mAll);
Expand Down Expand Up @@ -295,6 +303,8 @@ private final void initForClient() {
LogDebug.d(PLUGIN_TAG, "list plugins from persistent process");
}

PluginProcessMain.installHost();

List<PluginInfo> plugins = null;
try {
plugins = PluginProcessMain.getPluginHost().listPlugins();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,6 @@ public RePluginConfig setVerifySign(boolean verifySign) {
return this;
}

/**
* 是否开启"双进程"模式?
*
* @return 是否开启
*/
public boolean isPersistentEnable() {
return persistentEnable;
}

/**
* 设置是否允许开启"双进程"模式,开启后会极大的提升插件加载和获取的性能 <p>
* TODO 尚不支持单进程模式,在以后会开发
*
* @param persistentEnable 是否开启
* @return RePluginConfig自己。这样可以连环调用set方法
*/
public RePluginConfig setPersistentEnable(boolean persistentEnable) {
if (!checkAllowModify()) {
return this;
}
this.persistentEnable = persistentEnable;
return this;
}

/**
* 是否当插件没有指定类时,使用宿主的类? <p>
* 有关该开关的具体说明,请参见setUseHostClass方法
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import com.qihoo360.loader.utils.SysUtils;
import com.qihoo360.loader2.PluginProcessMain;
import com.qihoo360.replugin.RePlugin;
import com.qihoo360.replugin.helper.HostConfigHelper;
import com.qihoo360.replugin.helper.LogDebug;

Expand Down Expand Up @@ -58,13 +57,17 @@ public static void init(Context context) {
sPackageName = context.getApplicationInfo().packageName;

// 设置最终的常驻进程名
String cppn = HostConfigHelper.PERSISTENT_NAME;
if (!TextUtils.isEmpty(cppn)) {
if (cppn.startsWith(":")) {
sPersistentProcessName = sPackageName + cppn;
} else {
sPersistentProcessName = cppn;
if (HostConfigHelper.PERSISTENT_ENABLE) {
String cppn = HostConfigHelper.PERSISTENT_NAME;
if (!TextUtils.isEmpty(cppn)) {
if (cppn.startsWith(":")) {
sPersistentProcessName = sPackageName + cppn;
} else {
sPersistentProcessName = cppn;
}
}
} else {
sPersistentProcessName = sPackageName;
}

sIsUIProcess = sCurrentProcess.equals(sPackageName);
Expand Down Expand Up @@ -105,11 +108,7 @@ public static String getPersistentProcessName() {
* @return 插件处理逻辑所在进程名
*/
public static String getPluginHostProcessName() {
if (isPersistentEnable()) {
return getPersistentProcessName();
} else {
return getCurrentProcessName();
}
return sPersistentProcessName;
}

/**
Expand Down Expand Up @@ -148,7 +147,7 @@ public static boolean isPersistentProcess() {
* @return 是否支持?
*/
public static boolean isPersistentEnable() {
return RePlugin.getConfig().isPersistentEnable();
return HostConfigHelper.PERSISTENT_ENABLE;
}

/**
Expand Down

0 comments on commit bf75346

Please sign in to comment.