Java Code Examples for android.content.pm.PackageManager#GET_PROVIDERS
The following examples show how to use
android.content.pm.PackageManager#GET_PROVIDERS .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DevicePluginManager.java From DeviceConnect-Android with MIT License | 6 votes |
/** * 指定されたパッケージの中にデバイスプラグインが存在するかチェックし追加する. * パッケージの中にデバイスプラグインがない場合には何もしない。 * * @param packageName パッケージ名 */ private void checkAndAddDevicePlugin(final String packageName) { if (packageName == null) { throw new IllegalArgumentException("packageName is null."); } PackageManager pkgMgr = mContext.getPackageManager(); try { int flag = PackageManager.GET_SERVICES | PackageManager.GET_RECEIVERS | PackageManager.GET_PROVIDERS; PackageInfo pkg = pkgMgr.getPackageInfo(packageName, flag); mLogger.info("PluginManager: get package info: " + pkg); if (pkg != null) { List<DevicePlugin> plugins = getInstalledPluginsForPackage(pkgMgr, pkg); mLogger.info("PluginManager: installed plugins: size=" + plugins.size()); for (DevicePlugin plugin : filterPlugin(plugins)) { addDevicePlugin(plugin); } } } catch (NameNotFoundException e) { // NOP. } }
Example 2
Source File: ApkTargetMapping.java From GPT with Apache License 2.0 | 5 votes |
/** * generateProviderInfo * * @param p PackageParser.Package * @param pi PackageInfo * @param flags flags */ private void generateProviderInfo(PackageParser.Package p, PackageInfo pi, int flags) { PackageUserState state = new PackageUserState(); if ((flags & PackageManager.GET_PROVIDERS) != 0) { int N = p.providers.size(); if (N > 0) { if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.providers = new ProviderInfo[N]; } else { int num = 0; for (int i = 0; i < N; i++) { if (p.providers.get(i).info.enabled) num++; } pi.providers = new ProviderInfo[num]; } for (int i = 0, j = 0; i < N; i++) { final Provider provider = p.providers.get(i); if (provider.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.providers[j++] = PackageParser.generateProviderInfo(p.providers.get(i), flags, state, 0); // try { // pi.providers[j++] = JavaCalls.callStaticMethodOrThrow(PackageParser.class, "generateProviderInfo", // p.providers.get(i), flags, state, 0); // } catch (Exception e) { // e.printStackTrace(); // } } } } } }
Example 3
Source File: RefreshInstalledListTask.java From apkextractor with GNU General Public License v3.0 | 4 votes |
@Override public void run(){ PackageManager manager=context.getApplicationContext().getPackageManager(); SharedPreferences settings= SPUtil.getGlobalSharedPreferences(context); int flag=0; if(settings.getBoolean(Constants.PREFERENCE_LOAD_PERMISSIONS,Constants.PREFERENCE_LOAD_PERMISSIONS_DEFAULT))flag|=PackageManager.GET_PERMISSIONS; if(settings.getBoolean(Constants.PREFERENCE_LOAD_ACTIVITIES,Constants.PREFERENCE_LOAD_ACTIVITIES_DEFAULT))flag|=PackageManager.GET_ACTIVITIES; if(settings.getBoolean(Constants.PREFERENCE_LOAD_RECEIVERS,Constants.PREFERENCE_LOAD_RECEIVERS_DEFAULT))flag|=PackageManager.GET_RECEIVERS; if(settings.getBoolean(Constants.PREFERENCE_LOAD_APK_SIGNATURE,Constants.PREFERENCE_LOAD_APK_SIGNATURE_DEFAULT))flag|=PackageManager.GET_SIGNATURES; if(settings.getBoolean(Constants.PREFERENCE_LOAD_SERVICES,Constants.PREFERENCE_LOAD_SERVICES_DEFAULT))flag|=PackageManager.GET_SERVICES; if(settings.getBoolean(Constants.PREFERENCE_LOAD_PROVIDERS,Constants.PREFERENCE_LOAD_PROVIDERS_DEFAULT))flag|=PackageManager.GET_PROVIDERS; final List<PackageInfo> list = new ArrayList<>(); synchronized (RefreshInstalledListTask.class){//加锁是在多线程请求已安装列表时PackageManager可能会抛异常 ParceledListSlice: Failure retrieving array; list.clear(); list.addAll(manager.getInstalledPackages(flag)); } Global.handler.post(new Runnable() { @Override public void run() { if(listener!=null)listener.onRefreshProgressStarted(list.size()); } }); for(int i=0;i<list.size();i++){ if(isInterrupted)return; PackageInfo info=list.get(i); boolean info_is_system_app=((info.applicationInfo.flags& ApplicationInfo.FLAG_SYSTEM)>0); final int current=i+1; Global.handler.post(new Runnable() { @Override public void run() { if(listener!=null)listener.onRefreshProgressUpdated(current,list.size()); } }); if(!flag_system&&info_is_system_app)continue; list_sum.add(new AppItem(context,info)); } if(isInterrupted)return; AppItem.sort_config=settings.getInt(Constants.PREFERENCE_SORT_CONFIG,0); Collections.sort(list_sum); synchronized (Global.app_list){ Global.app_list.clear(); Global.app_list.addAll(list_sum);//向全局list保存一个引用 } GetSignatureInfoTask.clearCache(); Global.handler.post(new Runnable() { @Override public void run() { if(listener!=null)listener.onRefreshCompleted(list_sum); } }); }
Example 4
Source File: ImportItem.java From apkextractor with GNU General Public License v3.0 | 4 votes |
public ImportItem(@NonNull Context context,@NonNull FileItem fileItem){ this.fileItem=fileItem; this.context=context; version_name=context.getResources().getString(R.string.word_unknown); version_code=context.getResources().getString(R.string.word_unknown); minSdkVersion=context.getResources().getString(R.string.word_unknown); targetSdkVersion=context.getResources().getString(R.string.word_unknown); drawable=context.getResources().getDrawable(R.drawable.icon_file); if(fileItem.getName().trim().toLowerCase().endsWith(".zip") ||fileItem.getName().trim().toLowerCase().endsWith(SPUtil.getCompressingExtensionName(context).toLowerCase())){ importType=ImportType.ZIP; drawable=context.getResources().getDrawable(R.drawable.icon_zip); } if(fileItem.getName().trim().toLowerCase().endsWith(".xapk")){ importType=ImportType.ZIP; drawable=context.getResources().getDrawable(R.drawable.icon_xapk); } if(fileItem.getName().trim().toLowerCase().endsWith(".apk")){ importType=ImportType.APK; PackageManager packageManager=context.getApplicationContext().getPackageManager(); if(fileItem.isFileInstance()){ try{ int flag=0; final SharedPreferences settings=SPUtil.getGlobalSharedPreferences(context); if(settings.getBoolean(Constants.PREFERENCE_LOAD_PERMISSIONS,Constants.PREFERENCE_LOAD_PERMISSIONS_DEFAULT))flag|=PackageManager.GET_PERMISSIONS; if(settings.getBoolean(Constants.PREFERENCE_LOAD_ACTIVITIES,Constants.PREFERENCE_LOAD_ACTIVITIES_DEFAULT))flag|=PackageManager.GET_ACTIVITIES; if(settings.getBoolean(Constants.PREFERENCE_LOAD_RECEIVERS,Constants.PREFERENCE_LOAD_RECEIVERS_DEFAULT))flag|=PackageManager.GET_RECEIVERS; if(settings.getBoolean(Constants.PREFERENCE_LOAD_APK_SIGNATURE,Constants.PREFERENCE_LOAD_APK_SIGNATURE_DEFAULT))flag|=PackageManager.GET_SIGNATURES; if(settings.getBoolean(Constants.PREFERENCE_LOAD_SERVICES,Constants.PREFERENCE_LOAD_SERVICES_DEFAULT))flag|=PackageManager.GET_SERVICES; if(settings.getBoolean(Constants.PREFERENCE_LOAD_PROVIDERS,Constants.PREFERENCE_LOAD_PROVIDERS_DEFAULT))flag|=PackageManager.GET_PROVIDERS; packageInfo=packageManager.getPackageArchiveInfo(fileItem.getPath(),flag); }catch (Exception e){e.printStackTrace();} if(packageInfo!=null){ packageInfo.applicationInfo.sourceDir=fileItem.getPath(); packageInfo.applicationInfo.publicSourceDir=fileItem.getPath(); drawable=packageInfo.applicationInfo.loadIcon(packageManager); version_name=packageInfo.versionName; version_code=String.valueOf(packageInfo.versionCode); if(Build.VERSION.SDK_INT>23){ minSdkVersion=String.valueOf(packageInfo.applicationInfo.minSdkVersion); } targetSdkVersion=String.valueOf(packageInfo.applicationInfo.targetSdkVersion); }else{ drawable=context.getResources().getDrawable(R.drawable.icon_apk); } }else{ drawable=context.getResources().getDrawable(R.drawable.icon_apk); } } length=fileItem.length(); lastModified =fileItem.lastModified(); }
Example 5
Source File: PluginClientManager.java From AndroidPlugin with MIT License | 4 votes |
/** * add a apk client. Before start a plugin Activity, we should do this * first.<br/> * NOTE : will only be called by host apk. * * @param dexPath */ public PluginClientInfo addPluginClient(String dexPath) { // when loadApk is called by host apk, we assume that plugin is invoked // by host. PackageManager packageManager = mContext.getPackageManager(); int flags = PackageManager.GET_ACTIVITIES | PackageManager.GET_CONFIGURATIONS | PackageManager.GET_INSTRUMENTATION | PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES | PackageManager.GET_SIGNATURES; PackageInfo packageInfo = packageManager.getPackageArchiveInfo(dexPath, flags); if (packageInfo == null) { return null; } final String packageName = packageInfo.packageName; PluginClientInfo pluginPackage = mPluginClientPackages.get(packageName); if (pluginPackage == null) { DexClassLoader dexClassLoader = null; if (mPluginClientDexClassLoaders.containsKey(packageName)) { dexClassLoader = mPluginClientDexClassLoaders.get(packageName); } else { dexClassLoader = createDexClassLoader(dexPath, packageInfo.packageName, packageInfo.versionName); mPluginClientDexClassLoaders.put(packageName, dexClassLoader); } AssetManager assetManager = createAssetManager(dexPath); Resources resources = createResources(assetManager); pluginPackage = new PluginClientInfo(packageName, dexPath, dexClassLoader, assetManager, resources, packageInfo); mPluginClientPackages.put(packageName, pluginPackage); } if (!mPluginClientDexPaths.containsKey(packageName)) { mPluginClientDexPaths.put(packageName, dexPath); } return pluginPackage; }
Example 6
Source File: PluginManagerImpl.java From koala--Android-Plugin-Runtime- with Apache License 2.0 | 4 votes |
/** * 解析APK的manifest * * @param info * 插件信息 */ private void getPackageInfo(PluginInfo info) { int flags = PackageManager.GET_ACTIVITIES | PackageManager.GET_CONFIGURATIONS | PackageManager.GET_INSTRUMENTATION | PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES | PackageManager.GET_SIGNATURES; // 需要获取Package对象,主要是处理隐式启动插件中的activity PackageParser parser = new PackageParser(info.apkPath); DisplayMetrics metrics = new DisplayMetrics(); metrics.setToDefaults(); File sourceFile = new File(info.apkPath); PackageParser.Package pack = parser.parsePackage(sourceFile, info.apkPath, metrics, 0); // 因为PackagePaser的generatePackageInfo方法不同版本参数相差太多,所以还是用packagemanager的api // 但这样导致APK被解析了两次,上面获取Package是一次 PackageInfo packageInfo = mContext.getPackageManager().getPackageArchiveInfo(info.apkPath, flags); info.packageName = packageInfo.packageName; info.mPackageObj = pack; info.mPackageInfo = packageInfo; ArrayList<PackageParser.Activity> activitys = pack.activities; int size = activitys.size(); for (int i = 0; i < size; i++) { mActivitys.addActivity(activitys.get(i)); } ArrayList<PackageParser.Service> services = pack.services; size = services.size(); for (int i = 0; i < size; i++) { mServices.addService(services.get(i)); } ArrayList<PackageParser.Provider> providers = pack.providers; size = providers.size(); for (int i = 0; i < size; i++) { Provider p = providers.get(i); String names[] = PATTERN_SEMICOLON.split(p.info.authority); for (int j = 0; j < names.length; j++) { mProviderInfoMap.put(names[i], p); } } }