diff --git a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PmBase.java b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PmBase.java index 733085a..8e436b4 100644 --- a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PmBase.java +++ b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PmBase.java @@ -44,6 +44,7 @@ import com.qihoo360.replugin.component.dummy.DummyProvider; 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; @@ -228,19 +229,22 @@ class PmBase { } void init() { - if (IPC.isPersistentProcess()) { - mHostSvc = new PmHostSvc(mContext, this); - PluginProcessMain.installHost(mHostSvc); - PluginProcessMain.schedulePluginProcessLoop(PluginProcessMain.CHECK_STAGE1_DELAY); - + if (HostConfigHelper.PERSISTENT_ENABLE) { + // (默认)“常驻进程”作为插件管理进程,则区分进程对待 + if (IPC.isPersistentProcess()) { + initForPersistent(); + } else { + initForClient(); + } } else { - PluginProcessMain.installHost(); - } - - if (IPC.isPersistentProcess()) { - initForPersistent(); - } else { - initForClient(); + // “UI进程”作为插件管理进程(唯一进程),则此进程既可以作为Persistent也可以作为Client + if (IPC.isUIProcess()) { + initForPersistent(); + initForClient(); + } else { + // 其它进程?直接走Client即可 + initForClient(); + } } // 最新快照 @@ -263,6 +267,10 @@ class PmBase { 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); @@ -295,6 +303,8 @@ class PmBase { LogDebug.d(PLUGIN_TAG, "list plugins from persistent process"); } + PluginProcessMain.installHost(); + List plugins = null; try { plugins = PluginProcessMain.getPluginHost().listPlugins(); diff --git a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/RePluginConfig.java b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/RePluginConfig.java index c178c0e..1ded4ac 100644 --- a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/RePluginConfig.java +++ b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/RePluginConfig.java @@ -143,30 +143,6 @@ public final class RePluginConfig { return this; } - /** - * 是否开启"双进程"模式? - * - * @return 是否开启 - */ - public boolean isPersistentEnable() { - return persistentEnable; - } - - /** - * 设置是否允许开启"双进程"模式,开启后会极大的提升插件加载和获取的性能

- * TODO 尚不支持单进程模式,在以后会开发 - * - * @param persistentEnable 是否开启 - * @return RePluginConfig自己。这样可以连环调用set方法 - */ - public RePluginConfig setPersistentEnable(boolean persistentEnable) { - if (!checkAllowModify()) { - return this; - } - this.persistentEnable = persistentEnable; - return this; - } - /** * 是否当插件没有指定类时,使用宿主的类?

* 有关该开关的具体说明,请参见setUseHostClass方法 diff --git a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/base/IPC.java b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/base/IPC.java index 4ba9a03..b03cd94 100644 --- a/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/base/IPC.java +++ b/replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/replugin/base/IPC.java @@ -24,7 +24,6 @@ import android.text.TextUtils; 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; @@ -58,13 +57,17 @@ public class IPC { 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); @@ -105,11 +108,7 @@ public class IPC { * @return 插件处理逻辑所在进程名 */ public static String getPluginHostProcessName() { - if (isPersistentEnable()) { - return getPersistentProcessName(); - } else { - return getCurrentProcessName(); - } + return sPersistentProcessName; } /** @@ -148,7 +147,7 @@ public class IPC { * @return 是否支持? */ public static boolean isPersistentEnable() { - return RePlugin.getConfig().isPersistentEnable(); + return HostConfigHelper.PERSISTENT_ENABLE; } /**