Java Code Examples for android.content.pm.PackageManager#GET_INSTRUMENTATION

The following examples show how to use android.content.pm.PackageManager#GET_INSTRUMENTATION . 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: PluginClientManager.java    From AndroidPlugin with MIT License 4 votes vote down vote up
/**
 * 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 2
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);
        }
    }
}