11package com .plugin .core ;
22
33import java .util .ArrayList ;
4- import java .util .Collection ;
54import java .util .Iterator ;
65import java .util .List ;
76
1817import com .plugin .content .LoadedPlugin ;
1918import com .plugin .content .PluginDescriptor ;
2019import com .plugin .core .localservice .LocalServiceManager ;
21- import com .plugin .core .manager .PluginManagerProvider ;
20+ import com .plugin .core .manager .PluginManagerHelper ;
2221import com .plugin .core .systemservice .AndroidAppIActivityManager ;
2322import com .plugin .core .systemservice .AndroidAppINotificationManager ;
2423import com .plugin .core .systemservice .AndroidAppIPackageManager ;
@@ -38,6 +37,10 @@ public class PluginLoader {
3837 private PluginLoader () {
3938 }
4039
40+ public static Application getApplicatoin () {
41+ return sApplication ;
42+ }
43+
4144 /**
4245 * 初始化loader, 只可调用一次
4346 *
@@ -71,7 +74,7 @@ public void run() {
7174 PluginInjector .injectBaseContext (sApplication );
7275
7376 if (ProcessUtil .isPluginProcess ()) {
74- Iterator <PluginDescriptor > itr = getPlugins ().iterator ();
77+ Iterator <PluginDescriptor > itr = PluginManagerHelper . getPlugins ().iterator ();
7578 while (itr .hasNext ()) {
7679 PluginDescriptor plugin = itr .next ();
7780 LocalServiceManager .registerService (plugin );
@@ -121,24 +124,17 @@ public static Context fixBaseContextForReceiver(Context superApplicationContext)
121124 }
122125 }
123126
124- public static int installPlugin (String srcFile ) {
125- Bundle bundle = sApplication .getContentResolver ().call (PluginManagerProvider .CONTENT_URI ,
126- PluginManagerProvider .ACTION_INSTALL , srcFile , null );
127- return bundle .getInt (PluginManagerProvider .INSTALL_RESULT );
128- }
129127
130128 /**
131129 * 根据插件中的classId加载一个插件中的class
132130 *
133131 * @param clazzId
134132 * @return
135133 */
134+ @ TargetApi (Build .VERSION_CODES .HONEYCOMB )
136135 @ SuppressWarnings ("rawtypes" )
137136 public static Class loadPluginFragmentClassById (String clazzId ) {
138-
139- Bundle bundle = sApplication .getContentResolver ().call (PluginManagerProvider .CONTENT_URI , PluginManagerProvider .ACTION_QUERY_BY_FRAGMENT_ID , clazzId , null );
140- PluginDescriptor pluginDescriptor = (PluginDescriptor )bundle .getSerializable (PluginManagerProvider .QUERY_BY_FRAGMENT_ID_RESULT );
141-
137+ PluginDescriptor pluginDescriptor = PluginManagerHelper .getPluginDescriptorByFragmentId (clazzId );
142138 if (pluginDescriptor != null ) {
143139 //插件可能尚未初始化,确保使用前已经初始化
144140 LoadedPlugin plugin = PluginLauncher .instance ().startPlugin (pluginDescriptor .getPackageName ());
@@ -166,7 +162,7 @@ public static Class loadPluginFragmentClassById(String clazzId) {
166162 @ SuppressWarnings ("rawtypes" )
167163 public static Class loadPluginClassByName (String clazzName ) {
168164
169- PluginDescriptor pluginDescriptor = getPluginDescriptorByClassName (clazzName );
165+ PluginDescriptor pluginDescriptor = PluginManagerHelper . getPluginDescriptorByClassName (clazzName );
170166
171167 if (pluginDescriptor != null ) {
172168 //插件可能尚未初始化,确保使用前已经初始化
@@ -206,7 +202,7 @@ public static Class loadPluginClassByName(String clazzName) {
206202 public static Context getDefaultPluginContext (@ SuppressWarnings ("rawtypes" ) Class clazz ) {
207203
208204 Context pluginContext = null ;
209- PluginDescriptor pluginDescriptor = getPluginDescriptorByClassName (clazz .getName ());
205+ PluginDescriptor pluginDescriptor = PluginManagerHelper . getPluginDescriptorByClassName (clazz .getName ());
210206
211207 if (pluginDescriptor != null ) {
212208 pluginContext = PluginLauncher .instance ().getRunningPlugin (pluginDescriptor .getPackageName ()).pluginContext ;;
@@ -243,7 +239,7 @@ public static Context getDefaultPluginContext(@SuppressWarnings("rawtypes") Clas
243239 }
244240
245241 public static Context getNewPluginApplicationContext (String pluginId ) {
246- PluginDescriptor pluginDescriptor = getPluginDescriptorByPluginId (pluginId );
242+ PluginDescriptor pluginDescriptor = PluginManagerHelper . getPluginDescriptorByPluginId (pluginId );
247243
248244 //插件可能尚未初始化,确保使用前已经初始化
249245 LoadedPlugin plugin = PluginLauncher .instance ().startPlugin (pluginId );
@@ -265,53 +261,14 @@ public static Context getNewPluginApplicationContext(String pluginId) {
265261 }
266262
267263 public static boolean isInstalled (String pluginId , String pluginVersion ) {
268- PluginDescriptor pluginDescriptor = getPluginDescriptorByPluginId (pluginId );
264+ PluginDescriptor pluginDescriptor = PluginManagerHelper . getPluginDescriptorByPluginId (pluginId );
269265 if (pluginDescriptor != null ) {
270266 LogUtil .d (pluginId , pluginDescriptor .getVersion (), pluginVersion );
271267 return pluginDescriptor .getVersion ().equals (pluginVersion );
272268 }
273269 return false ;
274270 }
275271
276- public static Application getApplicatoin () {
277- return sApplication ;
278- }
279-
280- /**
281- * 清除列表并不能清除已经加载到内存当中的class,因为class一旦加载后后无法卸载
282- */
283- @ TargetApi (Build .VERSION_CODES .HONEYCOMB )
284- public static synchronized void removeAll () {
285- sApplication .getContentResolver ().call (PluginManagerProvider .CONTENT_URI ,
286- PluginManagerProvider .ACTION_REMOVE_ALL , null , null );
287- }
288-
289- @ TargetApi (Build .VERSION_CODES .HONEYCOMB )
290- public static synchronized void remove (String pluginId ) {
291- sApplication .getContentResolver ().call (PluginManagerProvider .CONTENT_URI ,
292- PluginManagerProvider .ACTION_REMOVE , pluginId , null );
293- }
294-
295- @ TargetApi (Build .VERSION_CODES .HONEYCOMB )
296- @ SuppressWarnings ("unchecked" )
297- public static Collection <PluginDescriptor > getPlugins () {
298- Bundle bundle = sApplication .getContentResolver ().call (PluginManagerProvider .CONTENT_URI ,
299- PluginManagerProvider .ACTION_QUERY_ALL , null , null );
300- return (Collection <PluginDescriptor >)bundle .getSerializable (PluginManagerProvider .QUERY_ALL_RESULT );
301- }
302-
303- @ TargetApi (Build .VERSION_CODES .HONEYCOMB )
304- public static PluginDescriptor getPluginDescriptorByPluginId (String pluginId ) {
305- Bundle bundle = sApplication .getContentResolver ().call (PluginManagerProvider .CONTENT_URI , PluginManagerProvider .ACTION_QUERY_BY_ID , pluginId , null );
306- return (PluginDescriptor )bundle .getSerializable (PluginManagerProvider .QUERY_BY_ID_RESULT );
307- }
308-
309- @ TargetApi (Build .VERSION_CODES .HONEYCOMB )
310- public static PluginDescriptor getPluginDescriptorByClassName (String clazzName ) {
311- Bundle bundle = sApplication .getContentResolver ().call (PluginManagerProvider .CONTENT_URI , PluginManagerProvider .ACTION_QUERY_BY_CLASS_NAME , clazzName , null );
312- return (PluginDescriptor )bundle .getSerializable (PluginManagerProvider .QUERY_BY_CLASS_NAME_RESULT );
313- }
314-
315272 /**
316273 */
317274 public static ArrayList <String > matchPlugin (Intent intent , int type ) {
@@ -322,7 +279,7 @@ public static ArrayList<String> matchPlugin(Intent intent, int type) {
322279 packageName = intent .getComponent ().getPackageName ();
323280 }
324281 if (packageName != null && !packageName .equals (PluginLoader .getApplicatoin ().getPackageName ())) {
325- PluginDescriptor dp = getPluginDescriptorByPluginId (packageName );
282+ PluginDescriptor dp = PluginManagerHelper . getPluginDescriptorByPluginId (packageName );
326283 if (dp != null ) {
327284 List <String > list = dp .matchPlugin (intent , type );
328285 if (list != null && list .size () > 0 ) {
@@ -333,7 +290,7 @@ public static ArrayList<String> matchPlugin(Intent intent, int type) {
333290 }
334291 }
335292 } else {
336- Iterator <PluginDescriptor > itr = getPlugins ().iterator ();
293+ Iterator <PluginDescriptor > itr = PluginManagerHelper . getPlugins ().iterator ();
337294 while (itr .hasNext ()) {
338295 List <String > list = itr .next ().matchPlugin (intent , type );
339296 if (list != null && list .size () > 0 ) {
0 commit comments