11package com .plugin .core ;
22
33import java .io .Serializable ;
4+ import java .util .ArrayList ;
45import java .util .HashMap ;
56
7+ import android .app .Application ;
68import android .content .Context ;
9+ import android .content .IntentFilter ;
10+ import android .content .pm .PackageInfo ;
711import android .util .Log ;
812import dalvik .system .DexClassLoader ;
913
1014/**
1115 * <Pre>
12- * {
13- * "id":123,
14- * "version":"1.0.1",
15- * "description":"插件介绍",
16- * "application":"com.example.plugintest.PluginApplication",
17- * "fragments":{
18- * "test1":"com.example.plugintest.PluginMustRunInSpec",
19- * "test2":"com.example.plugintest.PluginRunEasy"
20- * },
21- * "activities":{
22- * "test3":"com.example.plugintest.PluginTextActivity",
23- * },
24- * "services":{
25- * "test4":"com.example.plugintest.PluginTextService"
26- * }
27- * }
2816 * @author cailiming
2917 * </Pre>
3018 */
3119public class PluginDescriptor implements Serializable {
3220
3321 private static final long serialVersionUID = -7545734825911798344L ;
3422
35- private String id ;
23+ private String packageName ;
3624
3725 private String version ;
3826
3927 private String description ;
4028
4129 private boolean isEnabled ;
4230
43- private String application ;
31+ private String applicationName ;
4432
45- private HashMap <String , String > fragments ;
33+ private HashMap <String , String > fragments = new HashMap < String , String >() ;
4634
47- private HashMap <String , String > activities ;
35+ private HashMap <String , ArrayList < IntentFilter >> components ;
4836
49- private HashMap <String , String > services ;
50-
5137 private String installedPath ;
5238
39+ private transient Application pluginApplication ;
40+
5341 private transient DexClassLoader pluginClassLoader ;
5442
5543 private transient Context pluginContext ;
@@ -70,12 +58,12 @@ public void setPluginClassLoader(DexClassLoader pluginLoader) {
7058 this .pluginClassLoader = pluginLoader ;
7159 }
7260
73- public String getId () {
74- return id ;
61+ public String getPackageName () {
62+ return packageName ;
7563 }
7664
77- public void setId (String id ) {
78- this .id = id ;
65+ public void setPackageName (String packageName ) {
66+ this .packageName = packageName ;
7967 }
8068
8169 public String getVersion () {
@@ -102,12 +90,12 @@ public void setInstalledPath(String installedPath) {
10290 this .installedPath = installedPath ;
10391 }
10492
105- public HashMap <String , String > getActivities () {
106- return activities ;
93+ public HashMap <String , ArrayList < IntentFilter >> getComponents () {
94+ return components ;
10795 }
10896
109- public void setActivities (HashMap <String , String > activities ) {
110- this .activities = activities ;
97+ public void setComponents (HashMap <String , ArrayList < IntentFilter > > activities ) {
98+ this .components = activities ;
11199 }
112100
113101 public String getDescription () {
@@ -118,20 +106,12 @@ public void setDescription(String description) {
118106 this .description = description ;
119107 }
120108
121- public String getApplication () {
122- return application ;
109+ public String getApplicationName () {
110+ return applicationName ;
123111 }
124112
125- public void setApplication (String application ) {
126- this .application = application ;
127- }
128-
129- public HashMap <String , String > getServices () {
130- return services ;
131- }
132-
133- public void setServices (HashMap <String , String > services ) {
134- this .services = services ;
113+ public void setApplicationName (String applicationName ) {
114+ this .applicationName = applicationName ;
135115 }
136116
137117 public boolean isEnabled () {
@@ -142,15 +122,14 @@ public void setEnabled(boolean isEnabled) {
142122 this .isEnabled = isEnabled ;
143123 }
144124
125+ /**
126+ * 需要根据id查询的只有fragment
127+ * @param clazzId
128+ * @return
129+ */
145130 public String getPluginClassNameById (String clazzId ) {
146131 String clazzName = getFragments ().get (clazzId );
147- if (clazzName == null ) {
148- clazzName = getActivities ().get (clazzId );
149- }
150- if (clazzName == null ) {
151- clazzName = getServices ().get (clazzId );
152- }
153-
132+
154133 if (clazzName == null ) {
155134 Log .d ("PluginDescriptor" , "clazzName not found for classId " + clazzId );
156135 } else {
@@ -159,23 +138,35 @@ public String getPluginClassNameById(String clazzId) {
159138 return clazzName ;
160139 }
161140
162- public boolean containsId (String clazzId ) {
141+ public Application getPluginApplication () {
142+ return pluginApplication ;
143+ }
144+
145+ public void setPluginApplication (Application pluginApplication ) {
146+ this .pluginApplication = pluginApplication ;
147+ }
148+
149+ /**
150+ * 需要根据Id查询的只有fragment
151+ * @param clazzId
152+ * @return
153+ */
154+ public boolean containsFragment (String clazzId ) {
163155 if (getFragments ().containsKey (clazzId ) && isEnabled ()) {
164156 return true ;
165- } else if (getActivities ().containsKey (clazzId ) && isEnabled ()) {
166- return true ;
167- } else if (getServices ().containsKey (clazzId ) && isEnabled ()) {
168- return true ;
169157 }
170158 return false ;
171159 }
172160
161+ /**
162+ * 根据className查询
163+ * @param clazzName
164+ * @return
165+ */
173166 public boolean containsName (String clazzName ) {
174167 if (getFragments ().containsValue (clazzName ) && isEnabled ()) {
175168 return true ;
176- } else if (getActivities ().containsValue (clazzName ) && isEnabled ()) {
177- return true ;
178- } else if (getServices ().containsValue (clazzName ) && isEnabled ()) {
169+ } else if (getComponents ().containsKey (clazzName ) && isEnabled ()) {
179170 return true ;
180171 }
181172 return false ;
0 commit comments