android.content.pm.PackageParser.Provider源码实例Demo

类android.content.pm.PackageParser.Provider源码实例Demo

下面列出了android.content.pm.PackageParser.Provider 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: GPT   文件: ApkTargetMapping.java
/**
     * 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();
//                        } 
                    }
                }
            }
        }


    }
 
源代码2 项目: container   文件: PackageParserCompat.java
public static ProviderInfo generateProviderInfo(Provider provider, int flags) {

		if (SDK >= M) {

			return PackageParserMarshmallow.generateProviderInfo.call(provider, flags, sUserState, myUserId);

		} else if (SDK >= LOLLIPOP_MR1) {

			return PackageParserLollipop22.generateProviderInfo.call(provider, flags, sUserState, myUserId);

		} else if (SDK >= LOLLIPOP) {

			return PackageParserLollipop.generateProviderInfo.call(provider, flags, sUserState, myUserId);

		} else if (SDK >= JELLY_BEAN_MR1) {

			return PackageParserJellyBean17.generateProviderInfo.call(provider, flags, sUserState, myUserId);

		} else if (SDK >= JELLY_BEAN) {

			return PackageParserJellyBean.generateProviderInfo.call(provider, flags, false, 1, myUserId);

		} else {
			return mirror.android.content.pm.PackageParser.generateProviderInfo.call(provider, flags);
		}
	}
 
/**
 * 解析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);
        }
    }
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包
 同包方法