Example usage for android.content IntentFilter.MalformedMimeTypeException toString

List of usage examples for android.content IntentFilter.MalformedMimeTypeException toString

Introduction

In this page you can find the example usage for android.content IntentFilter.MalformedMimeTypeException toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:android.content.pm.PackageParser.java

private boolean parseIntent(Resources res, XmlPullParser parser, AttributeSet attrs, boolean allowGlobs,
        boolean allowAutoVerify, IntentInfo outInfo, String[] outError)
        throws XmlPullParserException, IOException {

    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestIntentFilter);

    int priority = sa.getInt(com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
    outInfo.setPriority(priority);//ww w  .  j  av a  2  s  . c  om

    TypedValue v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
    if (v != null && (outInfo.labelRes = v.resourceId) == 0) {
        outInfo.nonLocalizedLabel = v.coerceToString();
    }

    outInfo.icon = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);

    outInfo.logo = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);

    outInfo.banner = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestIntentFilter_banner, 0);

    if (allowAutoVerify) {
        outInfo.setAutoVerify(
                sa.getBoolean(com.android.internal.R.styleable.AndroidManifestIntentFilter_autoVerify, false));
    }

    sa.recycle();

    int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        String nodeName = parser.getName();
        if (nodeName.equals("action")) {
            String value = attrs.getAttributeValue(ANDROID_RESOURCES, "name");
            if (value == null || value == "") {
                outError[0] = "No value supplied for <android:name>";
                return false;
            }
            XmlUtils.skipCurrentTag(parser);

            outInfo.addAction(value);
        } else if (nodeName.equals("category")) {
            String value = attrs.getAttributeValue(ANDROID_RESOURCES, "name");
            if (value == null || value == "") {
                outError[0] = "No value supplied for <android:name>";
                return false;
            }
            XmlUtils.skipCurrentTag(parser);

            outInfo.addCategory(value);

        } else if (nodeName.equals("data")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestData);

            String str = sa.getNonConfigurationString(
                    com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
            if (str != null) {
                try {
                    outInfo.addDataType(str);
                } catch (IntentFilter.MalformedMimeTypeException e) {
                    outError[0] = e.toString();
                    sa.recycle();
                    return false;
                }
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
            if (str != null) {
                outInfo.addDataScheme(str);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_ssp, 0);
            if (str != null) {
                outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_LITERAL);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_sspPrefix,
                    0);
            if (str != null) {
                outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_PREFIX);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_sspPattern,
                    0);
            if (str != null) {
                if (!allowGlobs) {
                    outError[0] = "sspPattern not allowed here; ssp must be literal";
                    return false;
                }
                outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
            }

            String host = sa
                    .getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_host, 0);
            String port = sa
                    .getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_port, 0);
            if (host != null) {
                outInfo.addDataAuthority(host, port);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_path, 0);
            if (str != null) {
                outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_pathPrefix,
                    0);
            if (str != null) {
                outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_pathPattern,
                    0);
            if (str != null) {
                if (!allowGlobs) {
                    outError[0] = "pathPattern not allowed here; path must be literal";
                    return false;
                }
                outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
            }

            sa.recycle();
            XmlUtils.skipCurrentTag(parser);
        } else if (!RIGID_PARSER) {
            Slog.w(TAG, "Unknown element under <intent-filter>: " + parser.getName() + " at "
                    + mArchiveSourcePath + " " + parser.getPositionDescription());
            XmlUtils.skipCurrentTag(parser);
        } else {
            outError[0] = "Bad element under <intent-filter>: " + parser.getName();
            return false;
        }
    }

    outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);

    if (DEBUG_PARSER) {
        final StringBuilder cats = new StringBuilder("Intent d=");
        cats.append(outInfo.hasDefault);
        cats.append(", cat=");

        final Iterator<String> it = outInfo.categoriesIterator();
        if (it != null) {
            while (it.hasNext()) {
                cats.append(' ');
                cats.append(it.next());
            }
        }
        Slog.d(TAG, cats.toString());
    }

    return true;
}