Search in sources :

Example 6 with AndroidManifest

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;
}
Also used : FsFile(org.robolectric.res.FsFile) AndroidManifest(org.robolectric.manifest.AndroidManifest)

Example 7 with AndroidManifest

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;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityData(org.robolectric.manifest.ActivityData) ActivityInfo(android.content.pm.ActivityInfo) ArrayList(java.util.ArrayList) AndroidManifest(org.robolectric.manifest.AndroidManifest) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Example 8 with AndroidManifest

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;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) AndroidManifest(org.robolectric.manifest.AndroidManifest) PackageItemData(org.robolectric.manifest.PackageItemData)

Example 9 with AndroidManifest

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;
}
Also used : ActivityData(org.robolectric.manifest.ActivityData) ActivityInfo(android.content.pm.ActivityInfo) AndroidManifest(org.robolectric.manifest.AndroidManifest)

Example 10 with AndroidManifest

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"));
}
Also used : AndroidManifest(org.robolectric.manifest.AndroidManifest) ShadowApplication(org.robolectric.shadows.ShadowApplication) Application(android.app.Application) Test(org.junit.Test)

Aggregations

AndroidManifest (org.robolectric.manifest.AndroidManifest)40 Test (org.junit.Test)21 Config (org.robolectric.annotation.Config)6 BuildConfig (org.robolectric.gradleapp.BuildConfig)6 FsFile (org.robolectric.res.FsFile)5 FileFsFile (org.robolectric.res.FileFsFile)4 ActivityInfo (android.content.pm.ActivityInfo)3 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 DefaultManifestFactory (org.robolectric.internal.DefaultManifestFactory)3 ManifestFactory (org.robolectric.internal.ManifestFactory)3 ContentProviderData (org.robolectric.manifest.ContentProviderData)3 File (java.io.File)2 ActivityData (org.robolectric.manifest.ActivityData)2 ResourcePath (org.robolectric.res.ResourcePath)2 Application (android.app.Application)1 ContentProvider (android.content.ContentProvider)1 ProviderInfo (android.content.pm.ProviderInfo)1 ResolveInfo (android.content.pm.ResolveInfo)1 ServiceInfo (android.content.pm.ServiceInfo)1