Skip to content

Commit

Permalink
Merge pull request #243 from jiongxuan/fix_plugin_loader
Browse files Browse the repository at this point in the history
Fixed a crash when opening an Activity in Intent-Filter
  • Loading branch information
cundong authored Jul 20, 2017
2 parents bc2bfd8 + 610ddf5 commit c0edede
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ final boolean loadDex(ClassLoader parent, int load) {
mComponents = Plugin.queryCachedComponentList(mPath);
if (mComponents == null) {
// ComponentList
mComponents = new ComponentList(mPackageInfo, mPath, mPluginName);
mComponents = new ComponentList(mPackageInfo, mPath, mPluginObj.mInfo);

// 动态注册插件中声明的 receiver
regReceivers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,11 +739,11 @@ private final boolean doLoad(String tag, Context context, ClassLoader parent, Pl
return false;
}
File file = new File(dir, dstName);
info = PluginInfo.build(file);
if (info == null) {
return false;
}
// 不会改变
info = (PluginInfo) mInfo.clone();
info.setPath(file.getPath());

// FIXME 不应该是P-N,即便目录相同,未来会优化这里
info.setType(PluginInfo.TYPE_PN_INSTALLED);

} else if (mInfo.getType() == PluginInfo.TYPE_PN_JAR) {
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.qihoo360.mobilesafe.parser.manifest.bean.ComponentBean;
import com.qihoo360.replugin.helper.LogDebug;
import com.qihoo360.replugin.model.PluginInfo;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
Expand Down Expand Up @@ -67,30 +68,35 @@ public enum ManifestParser {
/**
* 解析 AndroidManifest
*
* @param plugin 插件名称
* @param pli 插件信息
* @param manifestStr AndroidManifest.xml 字符串
*/
public void parse(String plugin, String manifestStr) {
public void parse(PluginInfo pli, String manifestStr) {
XmlHandler handler = parseManifest(manifestStr);

Map<String, List<IntentFilter>> activityFilterMap = new HashMap<>();
mPluginActivityInfoMap.put(plugin, activityFilterMap);
parseComponent(plugin, activityFilterMap, handler.getActivities(), mActivityActionPluginsMap);
putToMap(mPluginActivityInfoMap, activityFilterMap, pli);
parseComponent(pli.getName(), activityFilterMap, handler.getActivities(), mActivityActionPluginsMap);

Map<String, List<IntentFilter>> serviceFilterMap = new HashMap<>();
mPluginServiceInfoMap.put(plugin, serviceFilterMap);
parseComponent(plugin, serviceFilterMap, handler.getServices(), mServiceActionPluginsMap);
putToMap(mPluginServiceInfoMap, serviceFilterMap, pli);
parseComponent(pli.getName(), serviceFilterMap, handler.getServices(), mServiceActionPluginsMap);

Map<String, List<IntentFilter>> receiverFilterMap = new HashMap<>();
mPluginReceiverInfoMap.put(plugin, receiverFilterMap);
parseComponent(plugin, receiverFilterMap, handler.getReceivers(), null);
putToMap(mPluginReceiverInfoMap, receiverFilterMap, pli);
parseComponent(pli.getName(), receiverFilterMap, handler.getReceivers(), null);

/* 打印日志 */
if (LOG) {
printFilters(activityFilterMap, serviceFilterMap, receiverFilterMap);
}
}

private void putToMap(Map<String, Map<String, List<IntentFilter>>> infoMap, Map<String, List<IntentFilter>> filterMap, PluginInfo pi) {
infoMap.put(pi.getPackageName(), filterMap);
infoMap.put(pi.getAlias(), filterMap);
}

/**
* parseComponent
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.qihoo360.replugin.component.utils.IntentMatcherHelper;
import com.qihoo360.replugin.ext.parser.ApkParser;
import com.qihoo360.replugin.helper.LogDebug;
import com.qihoo360.replugin.model.PluginInfo;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -92,7 +93,7 @@ public class ComponentList {
* 初始化ComponentList对象 <p>
* 注意:仅框架内部使用
*/
public ComponentList(PackageInfo pi, String path, String plugin) {
public ComponentList(PackageInfo pi, String path, PluginInfo pli) {
if (pi.activities != null) {
for (ActivityInfo ai : pi.activities) {
if (LOG) {
Expand Down Expand Up @@ -157,11 +158,11 @@ public ComponentList(PackageInfo pi, String path, String plugin) {
String manifest = getManifestFromApk(path);

if (LOG) {
LogDebug.d(PLUGIN_TAG, "\n解析插件 " + plugin + " : " + path + "\nAndroidManifest: \n" + manifest);
LogDebug.d(PLUGIN_TAG, "\n解析插件 " + pli.getName() + " : " + path + "\nAndroidManifest: \n" + manifest);
}

// 生成组件与 IntentFilter 的对应关系
ManifestParser.INS.parse(plugin, manifest);
ManifestParser.INS.parse(pli, manifest);

mApplication = pi.applicationInfo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ public class PluginInfo implements Parcelable, Cloneable {
public static final int TYPE_PN_INSTALLED = 1;

/**
* 内建插件
*
* @deprecated 只用于旧的P-n插件,可能会废弃
* 内置插件
*/
public static final int TYPE_BUILTIN = 2;

Expand Down

0 comments on commit c0edede

Please sign in to comment.