Search in sources :

Example 1 with ActivityData

use of org.robolectric.manifest.ActivityData 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 2 with ActivityData

use of org.robolectric.manifest.ActivityData 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 3 with ActivityData

use of org.robolectric.manifest.ActivityData in project android_packages_apps_Settings by LineageOS.

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);
}
Also used : ActivityData(org.robolectric.manifest.ActivityData) Context(android.content.Context) IntentFilterData(org.robolectric.manifest.IntentFilterData) ArrayList(java.util.ArrayList) AndroidManifest(org.robolectric.manifest.AndroidManifest)

Example 4 with ActivityData

use of org.robolectric.manifest.ActivityData in project android_packages_apps_Settings by omnirom.

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);
}
Also used : ActivityData(org.robolectric.manifest.ActivityData) Context(android.content.Context) IntentFilterData(org.robolectric.manifest.IntentFilterData) ArrayList(java.util.ArrayList) AndroidManifest(org.robolectric.manifest.AndroidManifest)

Example 5 with ActivityData

use of org.robolectric.manifest.ActivityData in project android_packages_apps_Settings by crdroidandroid.

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);
}
Also used : ActivityData(org.robolectric.manifest.ActivityData) Context(android.content.Context) IntentFilterData(org.robolectric.manifest.IntentFilterData) ArrayList(java.util.ArrayList) AndroidManifest(org.robolectric.manifest.AndroidManifest)

Aggregations

ActivityData (org.robolectric.manifest.ActivityData)10 ArrayList (java.util.ArrayList)9 AndroidManifest (org.robolectric.manifest.AndroidManifest)8 IntentFilterData (org.robolectric.manifest.IntentFilterData)7 Context (android.content.Context)6 ActivityInfo (android.content.pm.ActivityInfo)4 ProviderInfo (android.content.pm.ProviderInfo)2 ResolveInfo (android.content.pm.ResolveInfo)2 ContentProviderData (org.robolectric.manifest.ContentProviderData)2 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageInfo (android.content.pm.PackageInfo)1 Activity (android.content.pm.PackageParser.Activity)1 ActivityIntentInfo (android.content.pm.PackageParser.ActivityIntentInfo)1 Package (android.content.pm.PackageParser.Package)1 Permission (android.content.pm.PackageParser.Permission)1 PermissionGroup (android.content.pm.PackageParser.PermissionGroup)1 Service (android.content.pm.PackageParser.Service)1 ServiceIntentInfo (android.content.pm.PackageParser.ServiceIntentInfo)1