use of org.robolectric.manifest.IntentFilterData in project robolectric by robolectric.
the class LegacyManifestParser method createPackage.
public static Package createPackage(AndroidManifest androidManifest) {
Package pkg = new Package(androidManifest.getPackageName());
pkg.mVersionName = androidManifest.getVersionName();
pkg.mVersionCode = androidManifest.getVersionCode();
Map<String, PermissionItemData> permissionItemData = androidManifest.getPermissions();
for (PermissionItemData itemData : permissionItemData.values()) {
Permission permission = new Permission(pkg, createPermissionInfo(pkg, itemData));
permission.metaData = permission.info.metaData;
pkg.permissions.add(permission);
}
Map<String, PermissionGroupItemData> permissionGroupItemData = androidManifest.getPermissionGroups();
for (PermissionGroupItemData itemData : permissionGroupItemData.values()) {
PermissionGroup permissionGroup = new PermissionGroup(pkg, createPermissionGroupInfo(pkg, itemData));
permissionGroup.metaData = permissionGroup.info.metaData;
pkg.permissionGroups.add(permissionGroup);
}
pkg.requestedPermissions.addAll(androidManifest.getUsedPermissions());
if (RuntimeEnvironment.getApiLevel() < VERSION_CODES.M) {
List<Boolean> permissionsRequired = ReflectionHelpers.getField(pkg, "requestedPermissionsRequired");
permissionsRequired.addAll(buildBooleanList(pkg.requestedPermissions.size(), true));
}
pkg.applicationInfo.flags = decodeFlags(androidManifest.getApplicationAttributes());
pkg.applicationInfo.targetSdkVersion = androidManifest.getTargetSdkVersion();
pkg.applicationInfo.packageName = androidManifest.getPackageName();
pkg.applicationInfo.processName = androidManifest.getProcessName();
if (!Strings.isNullOrEmpty(androidManifest.getApplicationName())) {
pkg.applicationInfo.className = buildClassName(pkg.applicationInfo.packageName, androidManifest.getApplicationName());
if (RuntimeEnvironment.getApiLevel() >= VERSION_CODES.N_MR1) {
pkg.applicationInfo.name = pkg.applicationInfo.className;
}
}
pkg.applicationInfo.metaData = metaDataToBundle(androidManifest.getApplicationMetaData());
pkg.applicationInfo.uid = Process.myUid();
if (androidManifest.getThemeRef() != null) {
pkg.applicationInfo.theme = RuntimeEnvironment.getAppResourceTable().getResourceId(ResName.qualifyResName(androidManifest.getThemeRef().replace("@", ""), pkg.packageName, "style"));
}
int labelRes = 0;
if (androidManifest.getLabelRef() != null) {
String fullyQualifiedName = ResName.qualifyResName(androidManifest.getLabelRef(), androidManifest.getPackageName());
Integer id = fullyQualifiedName == null ? null : RuntimeEnvironment.getAppResourceTable().getResourceId(new ResName(fullyQualifiedName));
labelRes = id != null ? id : 0;
}
pkg.applicationInfo.labelRes = labelRes;
String labelRef = androidManifest.getLabelRef();
if (labelRef != null && !labelRef.startsWith("@")) {
pkg.applicationInfo.nonLocalizedLabel = labelRef;
}
Map<String, ActivityData> activityDatas = androidManifest.getActivityDatas();
for (ActivityData data : activityDatas.values()) {
ActivityInfo activityInfo = new ActivityInfo();
activityInfo.name = buildClassName(pkg.packageName, data.getName());
activityInfo.packageName = pkg.packageName;
activityInfo.configChanges = getConfigChanges(data);
activityInfo.parentActivityName = data.getParentActivityName();
activityInfo.metaData = metaDataToBundle(data.getMetaData().getValueMap());
activityInfo.applicationInfo = pkg.applicationInfo;
activityInfo.targetActivity = data.getTargetActivityName();
activityInfo.exported = data.isExported();
activityInfo.permission = data.getPermission();
activityInfo.enabled = data.isEnabled();
String themeRef;
// Based on ShadowActivity
if (data.getThemeRef() != null) {
themeRef = data.getThemeRef();
} else {
themeRef = androidManifest.getThemeRef();
}
if (themeRef != null) {
activityInfo.theme = RuntimeEnvironment.getAppResourceTable().getResourceId(ResName.qualifyResName(themeRef.replace("@", ""), pkg.packageName, "style"));
}
if (data.getLabel() != null) {
activityInfo.labelRes = RuntimeEnvironment.getAppResourceTable().getResourceId(ResName.qualifyResName(data.getLabel().replace("@", ""), pkg.packageName, "string"));
if (activityInfo.labelRes == 0) {
activityInfo.nonLocalizedLabel = data.getLabel();
}
}
Activity activity = createActivity(pkg, activityInfo);
for (IntentFilterData intentFilterData : data.getIntentFilters()) {
ActivityIntentInfo outInfo = new ActivityIntentInfo(activity);
populateIntentInfo(intentFilterData, outInfo);
activity.intents.add(outInfo);
}
pkg.activities.add(activity);
}
for (ContentProviderData data : androidManifest.getContentProviders()) {
ProviderInfo info = new ProviderInfo();
populateComponentInfo(info, pkg, data);
info.authority = data.getAuthorities();
List<PathPermission> permissions = new ArrayList<>();
for (PathPermissionData permissionData : data.getPathPermissionDatas()) {
permissions.add(createPathPermission(permissionData));
}
info.pathPermissions = permissions.toArray(new PathPermission[permissions.size()]);
info.readPermission = data.getReadPermission();
info.writePermission = data.getWritePermission();
info.grantUriPermissions = data.getGrantUriPermissions();
info.enabled = data.isEnabled();
pkg.providers.add(createProvider(pkg, info));
}
for (BroadcastReceiverData data : androidManifest.getBroadcastReceivers()) {
ActivityInfo info = new ActivityInfo();
populateComponentInfo(info, pkg, data);
info.permission = data.getPermission();
info.exported = data.isExported();
info.enabled = data.isEnabled();
Activity receiver = createActivity(pkg, info);
for (IntentFilterData intentFilterData : data.getIntentFilters()) {
ActivityIntentInfo outInfo = new ActivityIntentInfo(receiver);
populateIntentInfo(intentFilterData, outInfo);
receiver.intents.add(outInfo);
}
pkg.receivers.add(receiver);
}
for (ServiceData data : androidManifest.getServices()) {
ServiceInfo info = new ServiceInfo();
populateComponentInfo(info, pkg, data);
info.permission = data.getPermission();
info.exported = data.isExported();
info.enabled = data.isEnabled();
Service service = createService(pkg, info);
for (IntentFilterData intentFilterData : data.getIntentFilters()) {
ServiceIntentInfo outInfo = new ServiceIntentInfo(service);
populateIntentInfo(intentFilterData, outInfo);
service.intents.add(outInfo);
}
pkg.services.add(service);
}
String codePath = RuntimeEnvironment.getTempDirectory().createIfNotExists(pkg.packageName + "-codePath").toAbsolutePath().toString();
if (RuntimeEnvironment.getApiLevel() >= LOLLIPOP) {
pkg.codePath = codePath;
} else {
ReflectionHelpers.setField(Package.class, pkg, "mPath", codePath);
}
return pkg;
}
use of org.robolectric.manifest.IntentFilterData in project platform_packages_apps_Settings by BlissRoms.
the class SettingsSuggestionsTest method assertSuggestionEquals.
private void assertSuggestionEquals(String activityName, String category, @StringRes int title, @StringRes int summary) {
final AndroidManifest androidManifest = ShadowApplication.getInstance().getAppManifest();
final ActivityData activityData = androidManifest.getActivityData(activityName);
final Map<String, Object> metaData = activityData.getMetaData().getValueMap();
final Context context = RuntimeEnvironment.application;
final String expectedTitle = context.getString(title);
final String expectedSummary = context.getString(summary);
final String pName = context.getPackageName();
final String actualTitle = context.getString(context.getResources().getIdentifier(((String) metaData.get("com.android.settings.title")).substring(8), "string", pName));
final String actualSummary = context.getString(context.getResources().getIdentifier(((String) metaData.get("com.android.settings.summary")).substring(8), "string", pName));
assertThat(actualTitle).isEqualTo(expectedTitle);
assertThat(actualSummary).isEqualTo(expectedSummary);
final List<IntentFilterData> intentFilters = activityData.getIntentFilters();
final List<String> categories = new ArrayList<>();
for (IntentFilterData intentFilter : intentFilters) {
categories.addAll(intentFilter.getCategories());
}
assertThat(categories).contains(category);
}
Aggregations