android.content.pm.PackageParser.Provider Java Examples

The following examples show how to use android.content.pm.PackageParser.Provider. 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: ApkTargetMapping.java    From GPT with Apache License 2.0 5 votes vote down vote up
/**
     * 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 #2
Source File: PackageParserCompat.java    From container with GNU General Public License v3.0 4 votes vote down vote up
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);
		}
	}
 
Example #3
Source File: PluginManagerImpl.java    From koala--Android-Plugin-Runtime- with Apache License 2.0 4 votes vote down vote up
/**
 * 解析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);
        }
    }
}