Search in sources :

Example 1 with IntentFilterData

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

use of org.robolectric.manifest.IntentFilterData 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)

Example 3 with IntentFilterData

use of org.robolectric.manifest.IntentFilterData in project android_packages_apps_Settings by SudaMod.

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 IntentFilterData

use of org.robolectric.manifest.IntentFilterData in project robolectric by robolectric.

the class DefaultPackageManager method matchIntentFilter.

private boolean matchIntentFilter(ActivityData activityData, Intent intent) {
    for (IntentFilterData intentFilterData : activityData.getIntentFilters()) {
        List<String> actionList = intentFilterData.getActions();
        List<String> categoryList = intentFilterData.getCategories();
        IntentFilter intentFilter = new IntentFilter();
        for (String action : actionList) {
            intentFilter.addAction(action);
        }
        for (String category : categoryList) {
            intentFilter.addCategory(category);
        }
        for (String scheme : intentFilterData.getSchemes()) {
            intentFilter.addDataScheme(scheme);
        }
        for (String mimeType : intentFilterData.getMimeTypes()) {
            try {
                intentFilter.addDataType(mimeType);
            } catch (IntentFilter.MalformedMimeTypeException ex) {
                throw new RuntimeException(ex);
            }
        }
        for (String path : intentFilterData.getPaths()) {
            intentFilter.addDataPath(path, PatternMatcher.PATTERN_LITERAL);
        }
        for (String pathPattern : intentFilterData.getPathPatterns()) {
            intentFilter.addDataPath(pathPattern, PatternMatcher.PATTERN_SIMPLE_GLOB);
        }
        for (String pathPrefix : intentFilterData.getPathPrefixes()) {
            intentFilter.addDataPath(pathPrefix, PatternMatcher.PATTERN_PREFIX);
        }
        for (IntentFilterData.DataAuthority authority : intentFilterData.getAuthorities()) {
            intentFilter.addDataAuthority(authority.getHost(), authority.getPort());
        }
        // match action
        boolean matchActionResult = intentFilter.matchAction(intent.getAction());
        // match category
        String matchCategoriesResult = intentFilter.matchCategories(intent.getCategories());
        // match data
        int matchResult = intentFilter.matchData(intent.getType(), (intent.getData() != null ? intent.getData().getScheme() : null), intent.getData());
        if (matchActionResult && (matchCategoriesResult == null) && (matchResult != IntentFilter.NO_MATCH_DATA && matchResult != IntentFilter.NO_MATCH_TYPE)) {
            return true;
        }
    }
    return false;
}
Also used : IntentFilterData(org.robolectric.manifest.IntentFilterData) IntentFilter(android.content.IntentFilter)

Example 5 with IntentFilterData

use of org.robolectric.manifest.IntentFilterData in project android_packages_apps_Settings by DirtyUnicorns.

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

IntentFilterData (org.robolectric.manifest.IntentFilterData)7 ArrayList (java.util.ArrayList)6 ActivityData (org.robolectric.manifest.ActivityData)6 Context (android.content.Context)5 AndroidManifest (org.robolectric.manifest.AndroidManifest)5 IntentFilter (android.content.IntentFilter)1 ActivityInfo (android.content.pm.ActivityInfo)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 PathPermission (android.content.pm.PathPermission)1 ProviderInfo (android.content.pm.ProviderInfo)1 ServiceInfo (android.content.pm.ServiceInfo)1 BroadcastReceiverData (org.robolectric.manifest.BroadcastReceiverData)1 ContentProviderData (org.robolectric.manifest.ContentProviderData)1 PathPermissionData (org.robolectric.manifest.PathPermissionData)1