Change PmInternalImpl to PluginLibraryProxy and remove IPluginActivityManager

This commit is contained in:
zhangjiongxuan 2017-07-19 16:16:00 +08:00
parent e8c9724e0a
commit 54bcf3e783
5 changed files with 115 additions and 194 deletions

View File

@ -22,10 +22,13 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.qihoo360.loader2.PluginLibraryInternalProxy;
import org.json.JSONArray;
/**
* @hide 内部框架使用
* plugin-library中通过反射调用的内部逻辑如PluginActivity类的调用等均在此处 <p>
* 注意务必要Keep住此类否则插件调用将失败
*
* @author RePlugin Team
*/
@ -34,7 +37,7 @@ public final class Factory2 {
/**
* @hide 内部框架使用
*/
public static IPluginActivityManager sPluginManager;
public static PluginLibraryInternalProxy sPLProxy;
/**
* @hide 内部方法插件框架使用
@ -44,7 +47,7 @@ public final class Factory2 {
* @return 为Activity构造一个base Context
*/
public static final Context createActivityContext(Activity activity, Context newBase) {
return sPluginManager.createActivityContext(activity, newBase);
return sPLProxy.createActivityContext(activity, newBase);
}
/**
@ -54,7 +57,7 @@ public final class Factory2 {
* @param savedInstanceState
*/
public static final void handleActivityCreateBefore(Activity activity, Bundle savedInstanceState) {
sPluginManager.handleActivityCreateBefore(activity, savedInstanceState);
sPLProxy.handleActivityCreateBefore(activity, savedInstanceState);
}
/**
@ -64,7 +67,7 @@ public final class Factory2 {
* @param savedInstanceState
*/
public static final void handleActivityCreate(Activity activity, Bundle savedInstanceState) {
sPluginManager.handleActivityCreate(activity, savedInstanceState);
sPLProxy.handleActivityCreate(activity, savedInstanceState);
}
/**
@ -73,7 +76,7 @@ public final class Factory2 {
* @param activity
*/
public static final void handleActivityDestroy(Activity activity) {
sPluginManager.handleActivityDestroy(activity);
sPLProxy.handleActivityDestroy(activity);
}
/**
@ -83,7 +86,7 @@ public final class Factory2 {
* @param savedInstanceState
*/
public static final void handleRestoreInstanceState(Activity activity, Bundle savedInstanceState) {
sPluginManager.handleRestoreInstanceState(activity, savedInstanceState);
sPLProxy.handleRestoreInstanceState(activity, savedInstanceState);
}
/**
@ -92,7 +95,7 @@ public final class Factory2 {
* @param service
*/
public static final void handleServiceCreate(Service service) {
sPluginManager.handleServiceCreate(service);
sPLProxy.handleServiceCreate(service);
}
/**
@ -101,7 +104,7 @@ public final class Factory2 {
* @param service
*/
public static final void handleServiceDestroy(Service service) {
sPluginManager.handleServiceDestroy(service);
sPLProxy.handleServiceDestroy(service);
}
/**
@ -113,7 +116,7 @@ public final class Factory2 {
* @return 插件机制层是否成功例如没有插件存在没有合适的Activity坑
*/
public static final boolean startActivity(Activity activity, Intent intent) {
return sPluginManager.startActivity(activity, intent);
return sPLProxy.startActivity(activity, intent);
}
/**
@ -128,7 +131,7 @@ public final class Factory2 {
* @return 插件机制层是否成功例如没有插件存在没有合适的Activity坑
*/
public static final boolean startActivity(Context context, Intent intent, String plugin, String activity, int process, boolean download) {
return sPluginManager.startActivity(context, intent, plugin, activity, process, download);
return sPLProxy.startActivity(context, intent, plugin, activity, process, download);
}
/**
@ -141,7 +144,7 @@ public final class Factory2 {
* @see #startActivityForResult(Activity, Intent, int, Bundle)
*/
public static final boolean startActivityForResult(Activity activity, Intent intent, int requestCode, Bundle options) {
return sPluginManager.startActivityForResult(activity, intent, requestCode, options);
return sPLProxy.startActivityForResult(activity, intent, requestCode, options);
}
/**
@ -151,7 +154,7 @@ public final class Factory2 {
* @return
*/
public static final JSONArray fetchPlugins(String name) {
return sPluginManager.fetchPlugins(name);
return sPLProxy.fetchPlugins(name);
}
/**
@ -164,7 +167,7 @@ public final class Factory2 {
* @return
*/
public static final boolean registerDynamicClass(String className, String plugin, String type, String target) {
return sPluginManager.registerDynamicClass(className, plugin, type, target);
return sPLProxy.registerDynamicClass(className, plugin, type, target);
}
/**
@ -176,7 +179,7 @@ public final class Factory2 {
* @return
*/
public static final boolean registerDynamicClass(String className, String plugin, String target, Class defClass) {
return sPluginManager.registerDynamicClass(className, plugin, target, defClass);
return sPLProxy.registerDynamicClass(className, plugin, target, defClass);
}
/**
@ -187,7 +190,7 @@ public final class Factory2 {
* @return
*/
public static final boolean isDynamicClass(String plugin, String className) {
return sPluginManager.isDynamicClass(plugin, className);
return sPLProxy.isDynamicClass(plugin, className);
}
/**
@ -198,6 +201,6 @@ public final class Factory2 {
* @return 插件名称
*/
public static final String getPluginByDynamicClass(String className) {
return sPluginManager.getPluginByDynamicClass(className);
return sPLProxy.getPluginByDynamicClass(className);
}
}

View File

@ -1,152 +0,0 @@
/*
* Copyright (C) 2005-2017 Qihoo 360 Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.qihoo360.i;
import android.app.Activity;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import org.json.JSONArray;
/**
* @hide 内部框架使用
*
* @author RePlugin Team
*/
public interface IPluginActivityManager {
/**
* @hide 内部方法插件框架使用
* 插件的Activity创建成功后通过此方法获取其base context
* @param activity
* @param newBase
* @return 为Activity构造一个base Context
*/
Context createActivityContext(Activity activity, Context newBase);
/**
* @hide 内部方法插件框架使用
* 插件的Activity的onCreate调用前调用此方法
* @param activity
* @param savedInstanceState
*/
void handleActivityCreateBefore(Activity activity, Bundle savedInstanceState);
/**
* @hide 内部方法插件框架使用
* 插件的Activity的onCreate调用后调用此方法
* @param activity
* @param savedInstanceState
*/
void handleActivityCreate(Activity activity, Bundle savedInstanceState);
/**
* @hide 内部方法插件框架使用
* 插件的Activity的onDestroy调用后调用此方法
* @param activity
*/
void handleActivityDestroy(Activity activity);
/**
* @hide 内部方法插件框架使用
* 插件的Activity的onRestoreInstanceState调用后调用此方法
* @param activity
* @param savedInstanceState
*/
void handleRestoreInstanceState(Activity activity, Bundle savedInstanceState);
/**
* @hide 内部方法插件框架使用
* 插件的Service的onCreate调用后调用此方法
* @param service
*/
void handleServiceCreate(Service service);
/**
* @hide 内部方法插件框架使用
* 插件的Service的onDestroy调用后调用此方法
* @param service
*/
void handleServiceDestroy(Service service);
/**
* @hide 内部方法插件框架使用
* 启动一个插件中的activity
* 通过Extra参数IPluginManager.KEY_COMPATIBLEIPluginManager.KEY_PLUGINIPluginManager.KEY_ACTIVITYIPluginManager.KEY_PROCESS控制
* @param activity Activity上下文
* @param intent
* @return 插件机制层是否成功例如没有插件存在没有合适的Activity坑
*/
boolean startActivity(Activity activity, Intent intent);
/**
* @hide 内部方法插件框架使用
* 启动一个插件中的activity如果插件不存在会触发下载界面
* @param context 应用上下文或者Activity上下文
* @param intent
* @param plugin 插件名
* @param activity 待启动的activity类名
* @param process 是否在指定进程中启动
* @param download 下载
* @return 插件机制层是否成功例如没有插件存在没有合适的Activity坑
*/
boolean startActivity(Context context, Intent intent, String plugin, String activity, int process, boolean download);
/**
* @hide 内部方法插件框架使用
* 返回所有插件的json串格式见plugins-builtin.json文件
* @param name 插件名传null或者空串表示获取全部
* @return
*/
JSONArray fetchPlugins(String name);
/**
* @hide 内部方法插件框架使用
* 登记动态映射的类(6.5.0 later)
* @param className 壳类名
* @param plugin 目标插件名
* @param type 目标类的类型: activity, service, provider
* @param target 目标类名
* @return
*/
boolean registerDynamicClass(String className, String plugin, String type, String target);
/**
* @hide 内部方法插件框架使用
* 登记动态映射的类(7.7.0 later)
*/
boolean registerDynamicClass(String className, String plugin, String target, Class defClass);
/**
* @hide 内部方法插件框架使用
* 查询某个类是否是动态映射的类(7.7.0 later)
*/
boolean isDynamicClass(String plugin, String className);
/**
* @hide 内部方法插件框架使用
* 查询某个动态映射的类对应的插件(7.7.0 later)
*/
String getPluginByDynamicClass(String className);
/**
* @hide 内部方法插件框架使用
*/
boolean startActivityForResult(Activity activity, Intent intent, int requestCode, Bundle options);
}

View File

@ -26,7 +26,6 @@ import android.text.TextUtils;
import com.qihoo360.i.Factory;
import com.qihoo360.i.Factory2;
import com.qihoo360.i.IModule;
import com.qihoo360.i.IPluginActivityManager;
import com.qihoo360.i.IPluginManager;
import com.qihoo360.loader.utils.PatchClassLoaderUtils;
import com.qihoo360.replugin.helper.LogRelease;
@ -74,7 +73,7 @@ public class PMF {
sPluginMgr.init();
Factory.sPluginManager = PMF.getLocal();
Factory2.sPluginManager = PMF.getInternal();
Factory2.sPLProxy = PMF.getInternal();
PatchClassLoaderUtils.patch(application);
}
@ -112,7 +111,7 @@ public class PMF {
/**
* @return
*/
public static final IPluginActivityManager getInternal() {
public static final PluginLibraryInternalProxy getInternal() {
return sPluginMgr.mInternal;
}

View File

@ -27,7 +27,6 @@ import android.text.TextUtils;
import com.qihoo360.i.Factory;
import com.qihoo360.i.Factory2;
import com.qihoo360.i.IPluginActivityManager;
import com.qihoo360.i.IPluginManager;
import com.qihoo360.replugin.utils.ReflectUtils;
import com.qihoo360.replugin.RePlugin;
@ -50,20 +49,29 @@ import static com.qihoo360.replugin.helper.LogDebug.PLUGIN_TAG;
import static com.qihoo360.replugin.helper.LogRelease.LOGR;
/**
* plugin-library中通过反射调用的内部逻辑如PluginActivity类的调用Factory2等均在此处
*
* @author RePlugin Team
*/
class PmInternalImpl implements IPluginActivityManager {
public class PluginLibraryInternalProxy {
/**
*
*/
PmBase mPluginMgr;
PmInternalImpl(PmBase pm) {
PluginLibraryInternalProxy(PmBase pm) {
mPluginMgr = pm;
}
@Override
/**
* @hide 内部方法插件框架使用
* 启动一个插件中的activity
* 通过Extra参数IPluginManager.KEY_COMPATIBLEIPluginManager.KEY_PLUGINIPluginManager.KEY_ACTIVITYIPluginManager.KEY_PROCESS控制
* @param activity Activity上下文
* @param intent
* @return 插件机制层是否成功例如没有插件存在没有合适的Activity坑
*/
public boolean startActivity(Activity activity, Intent intent) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "start activity: intent=" + intent);
@ -157,7 +165,17 @@ class PmInternalImpl implements IPluginActivityManager {
}
// FIXME 建议去掉plugin和activity参数直接用intent代替
@Override
/**
* @hide 内部方法插件框架使用
* 启动一个插件中的activity如果插件不存在会触发下载界面
* @param context 应用上下文或者Activity上下文
* @param intent
* @param plugin 插件名
* @param activity 待启动的activity类名
* @param process 是否在指定进程中启动
* @param download 下载
* @return 插件机制层是否成功例如没有插件存在没有合适的Activity坑
*/
public boolean startActivity(Context context, Intent intent, String plugin, String activity, int process, boolean download) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "start activity: intent=" + intent + " plugin=" + plugin + " activity=" + activity + " process=" + process + " download=" + download);
@ -198,7 +216,7 @@ class PmInternalImpl implements IPluginActivityManager {
// Added by Jiongxuan Zhang
if (PluginStatusController.getStatus(plugin) < PluginStatusController.STATUS_OK) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "PmInternalImpl.startActivity(): Plugin Disabled. pn=" + plugin);
LogDebug.d(PLUGIN_TAG, "PluginLibraryInternalProxy.startActivity(): Plugin Disabled. pn=" + plugin);
}
return RePlugin.getConfig().getCallbacks().onPluginNotExistsForActivity(context, plugin, intent, process);
}
@ -273,7 +291,6 @@ class PmInternalImpl implements IPluginActivityManager {
* @param requestCode 请求码
* @param options 附加的数据
*/
@Override
public boolean startActivityForResult(Activity activity, Intent intent, int requestCode, Bundle options) {
String plugin = getPluginName(activity, intent);
@ -353,7 +370,13 @@ class PmInternalImpl implements IPluginActivityManager {
return false;
}
@Override
/**
* @hide 内部方法插件框架使用
* 插件的Activity创建成功后通过此方法获取其base context
* @param activity
* @param newBase
* @return 为Activity构造一个base Context
*/
public Context createActivityContext(Activity activity, Context newBase) {
// PluginContainers.ActivityState state = mPluginMgr.mClient.mACM.lookupLastLoading(activity.getClass().getName());
// if (state == null) {
@ -376,7 +399,12 @@ class PmInternalImpl implements IPluginActivityManager {
return plugin.mLoader.createBaseContext(newBase);
}
@Override
/**
* @hide 内部方法插件框架使用
* 插件的Activity的onCreate调用前调用此方法
* @param activity
* @param savedInstanceState
*/
public void handleActivityCreateBefore(Activity activity, Bundle savedInstanceState) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "activity create before: " + activity.getClass().getName() + " this=" + activity.hashCode() + " taskid=" + activity.getTaskId());
@ -404,7 +432,12 @@ class PmInternalImpl implements IPluginActivityManager {
}
}
@Override
/**
* @hide 内部方法插件框架使用
* 插件的Activity的onCreate调用后调用此方法
* @param activity
* @param savedInstanceState
*/
public void handleActivityCreate(Activity activity, Bundle savedInstanceState) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "activity create: " + activity.getClass().getName() + " this=" + activity.hashCode() + " taskid=" + activity.getTaskId());
@ -490,7 +523,12 @@ class PmInternalImpl implements IPluginActivityManager {
ActivityInjector.inject(activity, state.plugin, state.activity);
}
@Override
/**
* @hide 内部方法插件框架使用
* 插件的Activity的onRestoreInstanceState调用后调用此方法
* @param activity
* @param savedInstanceState
*/
public void handleRestoreInstanceState(Activity activity, Bundle savedInstanceState) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "activity restore instance state: " + activity.getClass().getName());
@ -512,7 +550,11 @@ class PmInternalImpl implements IPluginActivityManager {
}
}
@Override
/**
* @hide 内部方法插件框架使用
* 插件的Activity的onDestroy调用后调用此方法
* @param activity
*/
public void handleActivityDestroy(Activity activity) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "activity destroy: " + activity.getClass().getName() + " this=" + activity.hashCode() + " taskid=" + activity.getTaskId());
@ -550,17 +592,30 @@ class PmInternalImpl implements IPluginActivityManager {
RePlugin.getConfig().getEventCallbacks().onActivityDestroyed(activity);
}
@Override
/**
* @hide 内部方法插件框架使用
* 插件的Service的onCreate调用后调用此方法
* @param service
*/
public void handleServiceCreate(Service service) {
mPluginMgr.handleServiceCreated(service);
}
@Override
/**
* @hide 内部方法插件框架使用
* 插件的Service的onDestroy调用后调用此方法
* @param service
*/
public void handleServiceDestroy(Service service) {
mPluginMgr.handleServiceDestroyed(service);
}
@Override
/**
* @hide 内部方法插件框架使用
* 返回所有插件的json串格式见plugins-builtin.json文件
* @param name 插件名传null或者空串表示获取全部
* @return
*/
public JSONArray fetchPlugins(String name) {
JSONArray ja = new JSONArray();
synchronized (PluginTable.PLUGINS) {
@ -574,22 +629,39 @@ class PmInternalImpl implements IPluginActivityManager {
return ja;
}
@Override
/**
* @hide 内部方法插件框架使用
* 登记动态映射的类(6.5.0 later)
* @param className 壳类名
* @param plugin 目标插件名
* @param type 目标类的类型: activity, service, provider
* @param target 目标类名
* @return
*/
public boolean registerDynamicClass(String className, String plugin, String type, String target) {
return mPluginMgr.addDynamicClass(className, plugin, type, target, null);
}
@Override
/**
* @hide 内部方法插件框架使用
* 登记动态映射的类(7.7.0 later)
*/
public boolean registerDynamicClass(String className, String plugin, String target, Class defClass) {
return mPluginMgr.addDynamicClass(className, plugin, "", target, defClass);
}
@Override
/**
* @hide 内部方法插件框架使用
* 查询某个类是否是动态映射的类(7.7.0 later)
*/
public boolean isDynamicClass(String plugin, String className) {
return mPluginMgr.isDynamicClass(plugin, className);
}
@Override
/**
* @hide 内部方法插件框架使用
* 查询某个动态映射的类对应的插件(7.7.0 later)
*/
public String getPluginByDynamicClass(String className) {
return mPluginMgr.getPluginByDynamicClass(className);
}

View File

@ -31,7 +31,6 @@ import android.text.TextUtils;
import com.qihoo360.i.Factory;
import com.qihoo360.i.IModule;
import com.qihoo360.i.IPluginActivityManager;
import com.qihoo360.i.IPluginManager;
import com.qihoo360.replugin.utils.ReflectUtils;
import com.qihoo360.mobilesafe.api.Tasks;
@ -165,7 +164,7 @@ class PmBase {
/**
*
*/
IPluginActivityManager mInternal;
PluginLibraryInternalProxy mInternal;
/**
* insertNewPlugin 时使用的线程锁
@ -225,7 +224,7 @@ class PmBase {
mLocal = new PmLocalImpl(context, this);
//
mInternal = new PmInternalImpl(this);
mInternal = new PluginLibraryInternalProxy(this);
}
void init() {