use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.
the class MavenManifestFactory method createLibraryManifests.
/**
* Search through an AndroidManifest's library directories to load library AppManifest files.
* For testing, allow a parameter override of the library directories.
* @param androidManifest The main AppManifest which may have library resources.
* @param libraryDirectories If not null, override the libraries in androidManifest.
* @return A list of AndroidManifest objects, one for each library found.
*/
private static List<AndroidManifest> createLibraryManifests(AndroidManifest androidManifest, List<FsFile> libraryDirectories) {
List<AndroidManifest> libraryManifests = new ArrayList<>();
if (androidManifest != null) {
// If there is no library override, look through subdirectories.
if (libraryDirectories == null) {
libraryDirectories = findLibraries(androidManifest);
}
for (FsFile libraryBaseDir : libraryDirectories) {
AndroidManifest libraryManifest = createLibraryAndroidManifest(libraryBaseDir);
libraryManifest.setLibraryManifests(createLibraryManifests(libraryManifest, null));
libraryManifests.add(libraryManifest);
}
}
return libraryManifests;
}
use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.
the class DefaultPackageManager method queryImplicitIntent.
private List<ResolveInfo> queryImplicitIntent(Intent intent, int flags) {
List<ResolveInfo> resolveInfoList = new ArrayList<>();
for (Map.Entry<String, AndroidManifest> androidManifest : androidManifests.entrySet()) {
String packageName = androidManifest.getKey();
AndroidManifest appManifest = androidManifest.getValue();
for (Map.Entry<String, ActivityData> activity : appManifest.getActivityDatas().entrySet()) {
String activityName = activity.getKey();
ActivityData activityData = activity.getValue();
if (activityData.getTargetActivity() != null) {
activityName = activityData.getTargetActivityName();
}
if (matchIntentFilter(activityData, intent)) {
ResolveInfo resolveInfo = new ResolveInfo();
resolveInfo.resolvePackageName = packageName;
resolveInfo.activityInfo = new ActivityInfo();
resolveInfo.activityInfo.targetActivity = activityName;
resolveInfoList.add(resolveInfo);
}
}
}
return resolveInfoList;
}
use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.
the class DefaultPackageManager method getReceiverInfo.
@Override
public ActivityInfo getReceiverInfo(ComponentName className, int flags) throws NameNotFoundException {
String packageName = className.getPackageName();
AndroidManifest androidManifest = androidManifests.get(packageName);
String classString = resolvePackageName(packageName, className);
for (PackageItemData receiver : androidManifest.getBroadcastReceivers()) {
if (receiver.getClassName().equals(classString)) {
ActivityInfo activityInfo = new ActivityInfo();
activityInfo.packageName = packageName;
activityInfo.name = classString;
if ((flags & GET_META_DATA) != 0) {
activityInfo.metaData = metaDataToBundle(receiver.getMetaData().getValueMap());
}
return activityInfo;
}
}
return null;
}
use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.
the class DefaultPackageManager method getActivityInfo.
@Override
public ActivityInfo getActivityInfo(ComponentName className, int flags) throws NameNotFoundException {
ActivityInfo activityInfo = new ActivityInfo();
String packageName = className.getPackageName();
String activityName = className.getClassName();
activityInfo.name = activityName;
activityInfo.packageName = packageName;
AndroidManifest androidManifest = androidManifests.get(packageName);
// simply an android.app.Activity just return what we have.
if (androidManifest == null) {
return activityInfo;
}
ActivityData activityData = androidManifest.getActivityData(activityName);
if (activityData != null) {
activityInfo.configChanges = getConfigChanges(activityData);
activityInfo.parentActivityName = activityData.getParentActivityName();
activityInfo.metaData = metaDataToBundle(activityData.getMetaData().getValueMap());
String themeRef;
// Based on ShadowActivity
if (activityData.getThemeRef() != null) {
themeRef = activityData.getThemeRef();
} else {
themeRef = androidManifest.getThemeRef();
}
if (themeRef != null) {
activityInfo.theme = RuntimeEnvironment.application.getResources().getIdentifier(themeRef.replace("@", ""), "style", packageName);
}
}
activityInfo.applicationInfo = getApplicationInfo(packageName, flags);
return activityInfo;
}
use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.
the class DefaultTestLifecycleTest method shouldRegisterReceiversFromTheManifest.
@Test
public void shouldRegisterReceiversFromTheManifest() throws Exception {
AndroidManifest appManifest = newConfig("TestAndroidManifestWithReceivers.xml");
Application application = defaultTestLifecycle.createApplication(null, appManifest, null);
shadowOf(application).bind(appManifest);
List<ShadowApplication.Wrapper> receivers = shadowOf(application).getRegisteredReceivers();
assertThat(receivers.size()).isEqualTo(5);
assertTrue(receivers.get(0).intentFilter.matchAction("org.robolectric.ACTION1"));
}
Aggregations