Fixed an issue that could cause a crash when opening an Activity in Intent-Filter mode

This commit is contained in:
zhangjiongxuan 2017-07-20 22:23:31 +08:00
parent 71dbe4159e
commit 610ddf5f0d
3 changed files with 19 additions and 12 deletions

View File

@ -229,7 +229,7 @@ class Loader {
mComponents = Plugin.queryCachedComponentList(mPath);
if (mComponents == null) {
// ComponentList
mComponents = new ComponentList(mPackageInfo, mPath, mPluginName);
mComponents = new ComponentList(mPackageInfo, mPath, mPluginObj.mInfo);
// 动态注册插件中声明的 receiver
regReceivers();

View File

@ -21,6 +21,7 @@ import android.os.PatternMatcher;
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;
@ -67,23 +68,23 @@ 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) {
@ -91,6 +92,11 @@ public enum ManifestParser {
}
}
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
*

View File

@ -34,6 +34,7 @@ import com.qihoo360.replugin.component.utils.ApkCommentReader;
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;
@ -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) {
@ -157,11 +158,11 @@ public class ComponentList {
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;