Skip to content

Commit 24cbf69

Browse files
committed
添加对外部app唤起插件组件的支持:例如微信sdk
1 parent 2532f8f commit 24cbf69

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

PluginCore/src/com/plugin/core/HostClassLoader.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ protected Class<?> loadClass(String className, boolean resolve) throws ClassNotF
4242
if (clazz != null) {
4343
return clazz;
4444
}
45+
} else if (PluginStubBinding.isExact(className)) {
46+
LogUtil.d("className ", className, "target", className);
47+
Class clazz = PluginLoader.loadPluginClassByName(className);
48+
if (clazz != null) {
49+
return clazz;
50+
}
4551
}
4652
return super.loadClass(className, resolve);
4753
}

PluginCore/src/com/plugin/core/PluginStubBinding.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
import java.io.ObjectInputStream;
1919
import java.io.ObjectOutputStream;
2020
import java.io.Serializable;
21+
import java.util.ArrayList;
2122
import java.util.HashMap;
23+
import java.util.HashSet;
2224
import java.util.Iterator;
2325
import java.util.List;
2426
import java.util.Map;
27+
import java.util.Set;
2528

2629
/**
2730
* 插件组件动态绑定到宿主的虚拟stub组件
@@ -34,6 +37,8 @@ public class PluginStubBinding {
3437

3538
private static final String ACTION_STUB_SERVICE = "com.plugin.core.STUB_SERVICE";
3639

40+
private static final String STUB_EXACT = "com.plugin.core.STUB_EXACT";
41+
3742
/**
3843
* key:stub Activity Name
3944
* value:plugin Activity Name
@@ -47,6 +52,8 @@ public class PluginStubBinding {
4752
*/
4853
private static HashMap<String, String> serviceMapping = new HashMap<String, String>();
4954

55+
private static Set<String> mExcatStubSet;
56+
5057
private static boolean isPoolInited = false;
5158

5259
public static String bindLaunchModeStubActivity(String pluginActivityClassName, int launchMode) {
@@ -108,6 +115,8 @@ private static void initPool() {
108115

109116
loadStubService();
110117

118+
loadExact();
119+
111120
isPoolInited = true;
112121
}
113122

@@ -162,6 +171,47 @@ private static void loadStubService() {
162171
}
163172
}
164173

174+
private static void loadExact() {
175+
Intent exactStub = new Intent();
176+
exactStub.setAction(STUB_EXACT);
177+
exactStub.setPackage(PluginLoader.getApplicatoin().getPackageName());
178+
179+
//精确匹配的activity
180+
List<ResolveInfo> resolveInfos = PluginLoader.getApplicatoin().getPackageManager().queryIntentActivities(exactStub, PackageManager.MATCH_DEFAULT_ONLY);
181+
182+
if (resolveInfos != null && resolveInfos.size() > 0) {
183+
if (mExcatStubSet == null) {
184+
mExcatStubSet = new HashSet<String>();
185+
}
186+
for(ResolveInfo info:resolveInfos) {
187+
mExcatStubSet.add(info.activityInfo.name);
188+
}
189+
}
190+
191+
//精确匹配的service
192+
resolveInfos = PluginLoader.getApplicatoin().getPackageManager().queryIntentServices(exactStub, PackageManager.MATCH_DEFAULT_ONLY);
193+
194+
if (resolveInfos != null && resolveInfos.size() > 0) {
195+
if (mExcatStubSet == null) {
196+
mExcatStubSet = new HashSet<String>();
197+
}
198+
for(ResolveInfo info:resolveInfos) {
199+
mExcatStubSet.add(info.serviceInfo.name);
200+
}
201+
}
202+
203+
}
204+
205+
public static boolean isExact(String name) {
206+
initPool();
207+
208+
if (mExcatStubSet != null && mExcatStubSet.size() > 0) {
209+
return mExcatStubSet.contains(name);
210+
}
211+
212+
return false;
213+
}
214+
165215
public static void unBindLaunchModeStubActivity(String activityName, Intent intent) {
166216
if (activityName.startsWith(PluginStubBinding.STUB_ACTIVITY_PRE)) {
167217
if (intent != null) {

0 commit comments

Comments
 (0)