in shadows/framework/src/main/java/org/robolectric/shadows/ShadowApplicationPackageManager.java [500:574]
private <I extends ComponentInfo> List<ResolveInfo> queryIntentComponents(
Intent intent,
int flags,
Function<PackageInfo, I[]> componentsInPackage,
SortedMap<ComponentName, List<IntentFilter>> filters,
BiConsumer<ResolveInfo, I> componentSetter,
Function<ResolveInfo, I> componentInResolveInfo,
Function<I, I> copyConstructor) {
if (intent.getComponent() != null) {
flags &= ~MATCH_DEFAULT_ONLY;
}
List<ResolveInfo> result = new ArrayList<>();
List<ResolveInfo> resolveInfoList = queryOverriddenIntents(intent, flags);
if (!resolveInfoList.isEmpty()) {
result.addAll(resolveInfoList);
}
result.addAll(queryComponentsInManifest(intent, componentsInPackage, filters, componentSetter));
for (Iterator<ResolveInfo> iterator = result.iterator(); iterator.hasNext(); ) {
ResolveInfo resolveInfo = iterator.next();
I componentInfo = componentInResolveInfo.apply(resolveInfo);
if (hasSomeComponentInfo(resolveInfo) && componentInfo == null) {
Log.d(TAG, "ResolveInfo for different component type");
// different component type
iterator.remove();
continue;
}
if (componentInfo == null) {
// null component? Don't filter this sh...
continue;
}
if (!applyFlagsToResolveInfo(resolveInfo, flags)) {
Log.d(TAG, "ResolveInfo doesn't match flags");
iterator.remove();
continue;
}
ApplicationInfo applicationInfo = componentInfo.applicationInfo;
if (applicationInfo == null) {
String packageName = null;
if (getComponentForIntent(intent) != null) {
packageName = getComponentForIntent(intent).getPackageName();
} else if (intent.getPackage() != null) {
packageName = intent.getPackage();
} else if (componentInfo.packageName != null) {
packageName = componentInfo.packageName;
}
if (packageName != null) {
PackageInfo packageInfo = packageInfos.get(packageName);
if (packageInfo != null && packageInfo.applicationInfo != null) {
applicationInfo = new ApplicationInfo(packageInfo.applicationInfo);
} else {
applicationInfo = new ApplicationInfo();
applicationInfo.packageName = packageName;
applicationInfo.flags = FLAG_INSTALLED;
}
}
} else {
applicationInfo = new ApplicationInfo(applicationInfo);
}
componentInfo = copyConstructor.apply(componentInfo);
componentSetter.accept(resolveInfo, componentInfo);
componentInfo.applicationInfo = applicationInfo;
try {
applyFlagsToComponentInfo(componentInfo, flags);
} catch (NameNotFoundException e) {
Log.d(TAG, "ComponentInfo doesn't match flags:" + e.getMessage());
iterator.remove();
continue;
}
}
Collections.sort(result, new ResolveInfoComparator());
return result;
}