Skip to content

Commit

Permalink
Fixed an issue that could cause a crash when opening an Activity in I…
Browse files Browse the repository at this point in the history
…ntent-Filter mode
  • Loading branch information
jiongxuan committed Jul 20, 2017
1 parent 71dbe41 commit 610ddf5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 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 @@ -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

0 comments on commit 610ddf5

Please sign in to comment.