18
18
import java .io .ObjectInputStream ;
19
19
import java .io .ObjectOutputStream ;
20
20
import java .io .Serializable ;
21
+ import java .util .ArrayList ;
21
22
import java .util .HashMap ;
23
+ import java .util .HashSet ;
22
24
import java .util .Iterator ;
23
25
import java .util .List ;
24
26
import java .util .Map ;
27
+ import java .util .Set ;
25
28
26
29
/**
27
30
* 插件组件动态绑定到宿主的虚拟stub组件
@@ -34,6 +37,8 @@ public class PluginStubBinding {
34
37
35
38
private static final String ACTION_STUB_SERVICE = "com.plugin.core.STUB_SERVICE" ;
36
39
40
+ private static final String STUB_EXACT = "com.plugin.core.STUB_EXACT" ;
41
+
37
42
/**
38
43
* key:stub Activity Name
39
44
* value:plugin Activity Name
@@ -47,6 +52,8 @@ public class PluginStubBinding {
47
52
*/
48
53
private static HashMap <String , String > serviceMapping = new HashMap <String , String >();
49
54
55
+ private static Set <String > mExcatStubSet ;
56
+
50
57
private static boolean isPoolInited = false ;
51
58
52
59
public static String bindLaunchModeStubActivity (String pluginActivityClassName , int launchMode ) {
@@ -108,6 +115,8 @@ private static void initPool() {
108
115
109
116
loadStubService ();
110
117
118
+ loadExact ();
119
+
111
120
isPoolInited = true ;
112
121
}
113
122
@@ -162,6 +171,47 @@ private static void loadStubService() {
162
171
}
163
172
}
164
173
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
+
165
215
public static void unBindLaunchModeStubActivity (String activityName , Intent intent ) {
166
216
if (activityName .startsWith (PluginStubBinding .STUB_ACTIVITY_PRE )) {
167
217
if (intent != null ) {
0 commit comments