Java Code Examples for android.content.pm.PackageParser#Service

The following examples show how to use android.content.pm.PackageParser#Service . 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: ComponentResolver.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@GuardedBy("mLock")
private void addServicesLocked(PackageParser.Package pkg, boolean chatty) {
    final int servicesSize = pkg.services.size();
    StringBuilder r = null;
    for (int i = 0; i < servicesSize; i++) {
        PackageParser.Service s = pkg.services.get(i);
        s.info.processName = fixProcessName(pkg.applicationInfo.processName,
                s.info.processName);
        mServices.addService(s);
        if (DEBUG_PACKAGE_SCANNING && chatty) {
            if (r == null) {
                r = new StringBuilder(256);
            } else {
                r.append(' ');
            }
            r.append(s.info.name);
        }
    }
    if (DEBUG_PACKAGE_SCANNING && chatty) {
        Log.d(TAG, "  Services: " + (r == null ? "<NONE>" : r));
    }
}
 
Example 2
Source File: ComponentResolver.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
List<ResolveInfo> queryIntentForPackage(Intent intent, String resolvedType,
        int flags, List<PackageParser.Service> packageServices, int userId) {
    if (!sUserManager.exists(userId)) return null;
    if (packageServices == null) {
        return null;
    }
    mFlags = flags;
    final boolean defaultOnly = (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0;
    final int servicesSize = packageServices.size();
    ArrayList<PackageParser.ServiceIntentInfo[]> listCut = new ArrayList<>(servicesSize);

    ArrayList<PackageParser.ServiceIntentInfo> intentFilters;
    for (int i = 0; i < servicesSize; ++i) {
        intentFilters = packageServices.get(i).intents;
        if (intentFilters != null && intentFilters.size() > 0) {
            PackageParser.ServiceIntentInfo[] array =
                    new PackageParser.ServiceIntentInfo[intentFilters.size()];
            intentFilters.toArray(array);
            listCut.add(array);
        }
    }
    return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut, userId);
}
 
Example 3
Source File: ComponentResolver.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
void addService(PackageParser.Service s) {
    mServices.put(s.getComponentName(), s);
    if (DEBUG_SHOW_INFO) {
        Log.v(TAG, "  "
                + (s.info.nonLocalizedLabel != null
                ? s.info.nonLocalizedLabel : s.info.name) + ":");
        Log.v(TAG, "    Class=" + s.info.name);
    }
    final int intentsSize = s.intents.size();
    int j;
    for (j = 0; j < intentsSize; j++) {
        PackageParser.ServiceIntentInfo intent = s.intents.get(j);
        if (DEBUG_SHOW_INFO) {
            Log.v(TAG, "    IntentFilter:");
            intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
        }
        if (!intent.debugCheck()) {
            Log.w(TAG, "==> For Service " + s.info.name);
        }
        addFilter(intent);
    }
}
 
Example 4
Source File: ComponentResolver.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
void removeService(PackageParser.Service s) {
    mServices.remove(s.getComponentName());
    if (DEBUG_SHOW_INFO) {
        Log.v(TAG, "  " + (s.info.nonLocalizedLabel != null
                ? s.info.nonLocalizedLabel : s.info.name) + ":");
        Log.v(TAG, "    Class=" + s.info.name);
    }
    final int intentsSize = s.intents.size();
    int j;
    for (j = 0; j < intentsSize; j++) {
        PackageParser.ServiceIntentInfo intent = s.intents.get(j);
        if (DEBUG_SHOW_INFO) {
            Log.v(TAG, "    IntentFilter:");
            intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
        }
        removeFilter(intent);
    }
}
 
Example 5
Source File: ServiceIntentResolver.java    From koala--Android-Plugin-Runtime- with Apache License 2.0 6 votes vote down vote up
public List queryIntentForPackage(Intent intent, String resolvedType,
		int flags, ArrayList<PackageParser.Service> packageServices) {
	if (packageServices == null) {
		return null;
	}
	mFlags = flags;
	final boolean defaultOnly = (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0;
	int N = packageServices.size();
	ArrayList<ArrayList<PackageParser.ServiceIntentInfo>> listCut = new ArrayList<ArrayList<PackageParser.ServiceIntentInfo>>(
			N);

	ArrayList<PackageParser.ServiceIntentInfo> intentFilters;
	for (int i = 0; i < N; ++i) {
		intentFilters = packageServices.get(i).intents;
		if (intentFilters != null && intentFilters.size() > 0) {
			listCut.add(intentFilters);
		}
	}
	return super.queryIntentFromList(intent, resolvedType, defaultOnly,
			listCut);
}
 
Example 6
Source File: VPackageManagerService.java    From container with GNU General Public License v3.0 6 votes vote down vote up
public List<ResolveInfo> queryIntentForPackage(Intent intent, String resolvedType, int flags,
		ArrayList<PackageParser.Service> packageServices) {
	if (packageServices == null) {
		return null;
	}
	mFlags = flags;
	final boolean defaultOnly = (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0;
	final int N = packageServices.size();
	ArrayList<PackageParser.ServiceIntentInfo[]> listCut = new ArrayList<PackageParser.ServiceIntentInfo[]>(N);

	ArrayList<PackageParser.ServiceIntentInfo> intentFilters;
	for (int i = 0; i < N; ++i) {
		intentFilters = packageServices.get(i).intents;
		if (intentFilters != null && intentFilters.size() > 0) {
			PackageParser.ServiceIntentInfo[] array = new PackageParser.ServiceIntentInfo[intentFilters.size()];
			intentFilters.toArray(array);
			listCut.add(array);
		}
	}
	return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut);
}
 
Example 7
Source File: VPackageManagerService.java    From container with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected ResolveInfo newResult(PackageParser.ServiceIntentInfo filter, int match) {
	final PackageParser.Service service = filter.service;
	ServiceInfo si = PackageParserCompat.generateServiceInfo(service, mFlags);
	if (si == null) {
		return null;
	}
	final ResolveInfo res = new ResolveInfo();
	res.serviceInfo = si;
	if ((mFlags & PackageManager.GET_RESOLVED_FILTER) != 0) {
		res.filter = filter;
	}
	res.priority = filter.getPriority();
	res.preferredOrder = service.owner.mPreferredOrder;
	res.match = match;
	res.isDefault = filter.hasDefault;
	res.labelRes = filter.labelRes;
	res.nonLocalizedLabel = filter.nonLocalizedLabel;
	res.icon = filter.icon;
	return res;
}
 
Example 8
Source File: VPackageManagerService.java    From container with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ServiceInfo getServiceInfo(ComponentName component, int flags, int userId) {
	checkUserId(userId);
	synchronized (mPackages) {
		PackageParser.Service s = mServices.mServices.get(component);
		if (s != null) {
			ServiceInfo serviceInfo = PackageParserCompat.generateServiceInfo(s, flags);
			PackageParser.Package p = mPackages.get(serviceInfo.packageName);
			AppSetting settings = (AppSetting) p.mExtras;
			ComponentFixer.fixComponentInfo(settings, serviceInfo, userId);
			return serviceInfo;
		}
	}
	return null;
}
 
Example 9
Source File: ServiceIntentResolver.java    From koala--Android-Plugin-Runtime- with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean allowFilterResult(
		PackageParser.ServiceIntentInfo filter, List<PackageParser.Service> dest) {
	for (int i = dest.size() - 1; i >= 0; i--) {
		PackageParser.Service destAi = dest.get(i);
		if (destAi == filter.service) {
			return false;
		}
	}
	return true;
}
 
Example 10
Source File: ServiceIntentResolver.java    From koala--Android-Plugin-Runtime- with Apache License 2.0 5 votes vote down vote up
public final void removeService(PackageParser.Service s) {
	mServices.remove(s.getComponentName());
	int NI = s.intents.size();
	for (int j = 0; j < NI; j++) {
		PackageParser.ServiceIntentInfo intent = s.intents.get(j);
		removeFilter(intent);
	}
}
 
Example 11
Source File: ServiceIntentResolver.java    From koala--Android-Plugin-Runtime- with Apache License 2.0 5 votes vote down vote up
public final void addService(PackageParser.Service s) {
	mServices.put(s.getComponentName(), s);
	int NI = s.intents.size();
	for (int j = 0; j < NI; j++) {
		PackageParser.ServiceIntentInfo intent = s.intents.get(j);
		addFilter(intent);
	}
}
 
Example 12
Source File: VPackageManagerService.java    From container with GNU General Public License v3.0 5 votes vote down vote up
public final void removeService(PackageParser.Service s) {
	mServices.remove(s.getComponentName());
	if (DEBUG_SHOW_INFO) {
		Log.v(TAG, "  " + (s.info.nonLocalizedLabel != null ? s.info.nonLocalizedLabel : s.info.name) + ":");
		Log.v(TAG, "    Class=" + s.info.name);
	}
	final int NI = s.intents.size();
	int j;
	for (j = 0; j < NI; j++) {
		PackageParser.ServiceIntentInfo intent = s.intents.get(j);
		removeFilter(intent);
	}
}
 
Example 13
Source File: VPackageManagerService.java    From container with GNU General Public License v3.0 5 votes vote down vote up
public final void addService(PackageParser.Service s) {
	mServices.put(s.getComponentName(), s);
	if (DEBUG_SHOW_INFO) {
		Log.v(TAG, "  " + (s.info.nonLocalizedLabel != null ? s.info.nonLocalizedLabel : s.info.name) + ":");
		Log.v(TAG, "    Class=" + s.info.name);
	}
	final int NI = s.intents.size();
	int j;
	for (j = 0; j < NI; j++) {
		PackageParser.ServiceIntentInfo intent = s.intents.get(j);
		addFilter(intent);
	}
}
 
Example 14
Source File: ComponentResolver.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
protected void dumpFilterLabel(PrintWriter out, String prefix, Object label, int count) {
    final PackageParser.Service service = (PackageParser.Service) label;
    out.print(prefix);
    out.print(Integer.toHexString(System.identityHashCode(service)));
    out.print(' ');
    service.printComponentShortName(out);
    if (count > 1) {
        out.print(" ("); out.print(count); out.print(" filters)");
    }
    out.println();
}
 
Example 15
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);
        }
    }
}
 
Example 16
Source File: ServiceIntentResolver.java    From koala--Android-Plugin-Runtime- with Apache License 2.0 4 votes vote down vote up
@Override
protected void sortResults(List<PackageParser.Service> results) {
}
 
Example 17
Source File: ComponentResolver.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
/** Returns the given service */
PackageParser.Service getService(ComponentName component) {
    synchronized (mLock) {
        return mServices.mServices.get(component);
    }
}
 
Example 18
Source File: ServiceIntentResolver.java    From koala--Android-Plugin-Runtime- with Apache License 2.0 4 votes vote down vote up
@Override
protected PackageParser.Service newResult(PackageParser.ServiceIntentInfo info,
		int match) {
	return info.service;
}
 
Example 19
Source File: LoadedPlugin.java    From VirtualAPK with Apache License 2.0 4 votes vote down vote up
public LoadedPlugin(PluginManager pluginManager, Context context, File apk) throws Exception {
    this.mPluginManager = pluginManager;
    this.mHostContext = context;
    this.mLocation = apk.getAbsolutePath();
    this.mPackage = PackageParserCompat.parsePackage(context, apk, PackageParser.PARSE_MUST_BE_APK);
    this.mPackage.applicationInfo.metaData = this.mPackage.mAppMetaData;
    this.mPackageInfo = new PackageInfo();
    this.mPackageInfo.applicationInfo = this.mPackage.applicationInfo;
    this.mPackageInfo.applicationInfo.sourceDir = apk.getAbsolutePath();

    if (Build.VERSION.SDK_INT >= 28
        || (Build.VERSION.SDK_INT == 27 && Build.VERSION.PREVIEW_SDK_INT != 0)) { // Android P Preview
        try {
            this.mPackageInfo.signatures = this.mPackage.mSigningDetails.signatures;
        } catch (Throwable e) {
            PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
            this.mPackageInfo.signatures = info.signatures;
        }
    } else {
        this.mPackageInfo.signatures = this.mPackage.mSignatures;
    }
    
    this.mPackageInfo.packageName = this.mPackage.packageName;
    if (pluginManager.getLoadedPlugin(mPackageInfo.packageName) != null) {
        throw new RuntimeException("plugin has already been loaded : " + mPackageInfo.packageName);
    }
    this.mPackageInfo.versionCode = this.mPackage.mVersionCode;
    this.mPackageInfo.versionName = this.mPackage.mVersionName;
    this.mPackageInfo.permissions = new PermissionInfo[0];
    this.mPackageManager = createPluginPackageManager();
    this.mPluginContext = createPluginContext(null);
    this.mNativeLibDir = getDir(context, Constants.NATIVE_DIR);
    this.mPackage.applicationInfo.nativeLibraryDir = this.mNativeLibDir.getAbsolutePath();
    this.mResources = createResources(context, getPackageName(), apk);
    this.mClassLoader = createClassLoader(context, apk, this.mNativeLibDir, context.getClassLoader());

    tryToCopyNativeLib(apk);

    // Cache instrumentations
    Map<ComponentName, InstrumentationInfo> instrumentations = new HashMap<ComponentName, InstrumentationInfo>();
    for (PackageParser.Instrumentation instrumentation : this.mPackage.instrumentation) {
        instrumentations.put(instrumentation.getComponentName(), instrumentation.info);
    }
    this.mInstrumentationInfos = Collections.unmodifiableMap(instrumentations);
    this.mPackageInfo.instrumentation = instrumentations.values().toArray(new InstrumentationInfo[instrumentations.size()]);

    // Cache activities
    Map<ComponentName, ActivityInfo> activityInfos = new HashMap<ComponentName, ActivityInfo>();
    for (PackageParser.Activity activity : this.mPackage.activities) {
        activity.info.metaData = activity.metaData;
        activityInfos.put(activity.getComponentName(), activity.info);
    }
    this.mActivityInfos = Collections.unmodifiableMap(activityInfos);
    this.mPackageInfo.activities = activityInfos.values().toArray(new ActivityInfo[activityInfos.size()]);

    // Cache services
    Map<ComponentName, ServiceInfo> serviceInfos = new HashMap<ComponentName, ServiceInfo>();
    for (PackageParser.Service service : this.mPackage.services) {
        serviceInfos.put(service.getComponentName(), service.info);
    }
    this.mServiceInfos = Collections.unmodifiableMap(serviceInfos);
    this.mPackageInfo.services = serviceInfos.values().toArray(new ServiceInfo[serviceInfos.size()]);

    // Cache providers
    Map<String, ProviderInfo> providers = new HashMap<String, ProviderInfo>();
    Map<ComponentName, ProviderInfo> providerInfos = new HashMap<ComponentName, ProviderInfo>();
    for (PackageParser.Provider provider : this.mPackage.providers) {
        providers.put(provider.info.authority, provider.info);
        providerInfos.put(provider.getComponentName(), provider.info);
    }
    this.mProviders = Collections.unmodifiableMap(providers);
    this.mProviderInfos = Collections.unmodifiableMap(providerInfos);
    this.mPackageInfo.providers = providerInfos.values().toArray(new ProviderInfo[providerInfos.size()]);

    // Register broadcast receivers dynamically
    Map<ComponentName, ActivityInfo> receivers = new HashMap<ComponentName, ActivityInfo>();
    for (PackageParser.Activity receiver : this.mPackage.receivers) {
        receivers.put(receiver.getComponentName(), receiver.info);

        BroadcastReceiver br = BroadcastReceiver.class.cast(getClassLoader().loadClass(receiver.getComponentName().getClassName()).newInstance());
        for (PackageParser.ActivityIntentInfo aii : receiver.intents) {
            this.mHostContext.registerReceiver(br, aii);
        }
    }
    this.mReceiverInfos = Collections.unmodifiableMap(receivers);
    this.mPackageInfo.receivers = receivers.values().toArray(new ActivityInfo[receivers.size()]);

    // try to invoke plugin's application
    invokeApplication();
}
 
Example 20
Source File: ComponentResolver.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
List<ResolveInfo> queryServices(Intent intent, String resolvedType, int flags,
        List<PackageParser.Service> services, int userId) {
    synchronized (mLock) {
        return mServices.queryIntentForPackage(intent, resolvedType, flags, services, userId);
    }
}