Search in sources :

Example 66 with AttributeSet

use of android.util.AttributeSet in project android_frameworks_base by ResurrectionRemix.

the class PackageParser method parseSplitApk.

/**
     * Parse the manifest of a <em>split APK</em>.
     * <p>
     * Note that split APKs have many more restrictions on what they're capable
     * of doing, so many valid features of a base APK have been carefully
     * omitted here.
     */
private Package parseSplitApk(Package pkg, Resources res, XmlResourceParser parser, int flags, int splitIndex, String[] outError) throws XmlPullParserException, IOException, PackageParserException {
    AttributeSet attrs = parser;
    // We parsed manifest tag earlier; just skip past it
    parsePackageSplitNames(parser, attrs);
    mParseInstrumentationArgs = null;
    mParseActivityArgs = null;
    mParseServiceArgs = null;
    mParseProviderArgs = null;
    int type;
    boolean foundApp = false;
    int outerDepth = parser.getDepth();
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }
        String tagName = parser.getName();
        if (tagName.equals("application")) {
            if (foundApp) {
                if (RIGID_PARSER) {
                    outError[0] = "<manifest> has more than one <application>";
                    mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                    return null;
                } else {
                    Slog.w(TAG, "<manifest> has more than one <application>");
                    XmlUtils.skipCurrentTag(parser);
                    continue;
                }
            }
            foundApp = true;
            if (!parseSplitApplication(pkg, res, parser, flags, splitIndex, outError)) {
                return null;
            }
        } else if (RIGID_PARSER) {
            outError[0] = "Bad element under <manifest>: " + parser.getName();
            mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
            return null;
        } else {
            Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() + " at " + mArchiveSourcePath + " " + parser.getPositionDescription());
            XmlUtils.skipCurrentTag(parser);
            continue;
        }
    }
    if (!foundApp) {
        outError[0] = "<manifest> does not contain an <application>";
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
    }
    return pkg;
}
Also used : AttributeSet(android.util.AttributeSet)

Example 67 with AttributeSet

use of android.util.AttributeSet in project android_frameworks_base by ResurrectionRemix.

the class SearchableInfo method getActivityMetaData.

/**
     * Get the metadata for a given activity
     * 
     * @param context runtime context
     * @param xml XML parser for reading attributes
     * @param cName The component name of the searchable activity
     * 
     * @result A completely constructed SearchableInfo, or null if insufficient XML data for it
     */
private static SearchableInfo getActivityMetaData(Context context, XmlPullParser xml, final ComponentName cName) {
    SearchableInfo result = null;
    Context activityContext = createActivityContext(context, cName);
    if (activityContext == null)
        return null;
    // forward through the file until it's reading the tag of interest.
    try {
        int tagType = xml.next();
        while (tagType != XmlPullParser.END_DOCUMENT) {
            if (tagType == XmlPullParser.START_TAG) {
                if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE)) {
                    AttributeSet attr = Xml.asAttributeSet(xml);
                    if (attr != null) {
                        try {
                            result = new SearchableInfo(activityContext, attr, cName);
                        } catch (IllegalArgumentException ex) {
                            Log.w(LOG_TAG, "Invalid searchable metadata for " + cName.flattenToShortString() + ": " + ex.getMessage());
                            return null;
                        }
                    }
                } else if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE_ACTION_KEY)) {
                    if (result == null) {
                        // Can't process an embedded element if we haven't seen the enclosing
                        return null;
                    }
                    AttributeSet attr = Xml.asAttributeSet(xml);
                    if (attr != null) {
                        try {
                            result.addActionKey(new ActionKeyInfo(activityContext, attr));
                        } catch (IllegalArgumentException ex) {
                            Log.w(LOG_TAG, "Invalid action key for " + cName.flattenToShortString() + ": " + ex.getMessage());
                            return null;
                        }
                    }
                }
            }
            tagType = xml.next();
        }
    } catch (XmlPullParserException e) {
        Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e);
        return null;
    } catch (IOException e) {
        Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e);
        return null;
    }
    return result;
}
Also used : Context(android.content.Context) AttributeSet(android.util.AttributeSet) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 68 with AttributeSet

use of android.util.AttributeSet in project android_frameworks_base by ResurrectionRemix.

the class RegisteredServicesCache method parseServiceInfo.

@VisibleForTesting
protected ServiceInfo<V> parseServiceInfo(ResolveInfo service) throws XmlPullParserException, IOException {
    android.content.pm.ServiceInfo si = service.serviceInfo;
    ComponentName componentName = new ComponentName(si.packageName, si.name);
    PackageManager pm = mContext.getPackageManager();
    XmlResourceParser parser = null;
    try {
        parser = si.loadXmlMetaData(pm, mMetaDataName);
        if (parser == null) {
            throw new XmlPullParserException("No " + mMetaDataName + " meta-data");
        }
        AttributeSet attrs = Xml.asAttributeSet(parser);
        int type;
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
        }
        String nodeName = parser.getName();
        if (!mAttributesName.equals(nodeName)) {
            throw new XmlPullParserException("Meta-data does not start with " + mAttributesName + " tag");
        }
        V v = parseServiceAttributes(pm.getResourcesForApplication(si.applicationInfo), si.packageName, attrs);
        if (v == null) {
            return null;
        }
        final android.content.pm.ServiceInfo serviceInfo = service.serviceInfo;
        return new ServiceInfo<V>(v, serviceInfo, componentName);
    } catch (NameNotFoundException e) {
        throw new XmlPullParserException("Unable to load resources for pacakge " + si.packageName);
    } finally {
        if (parser != null)
            parser.close();
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) AttributeSet(android.util.AttributeSet) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 69 with AttributeSet

use of android.util.AttributeSet in project android_frameworks_base by ResurrectionRemix.

the class GradientColor method createFromXml.

/**
     * A public method to create GradientColor from a XML resource.
     */
public static GradientColor createFromXml(Resources r, XmlResourceParser parser, Theme theme) throws XmlPullParserException, IOException {
    final AttributeSet attrs = Xml.asAttributeSet(parser);
    int type;
    while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
    // Seek parser to start tag.
    }
    if (type != XmlPullParser.START_TAG) {
        throw new XmlPullParserException("No start tag found");
    }
    return createFromXmlInner(r, parser, attrs, theme);
}
Also used : AttributeSet(android.util.AttributeSet) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 70 with AttributeSet

use of android.util.AttributeSet in project android_frameworks_base by ResurrectionRemix.

the class ColorStateList method createFromXml.

/**
     * Creates a ColorStateList from an XML document using given a set of
     * {@link Resources} and a {@link Theme}.
     *
     * @param r Resources against which the ColorStateList should be inflated.
     * @param parser Parser for the XML document defining the ColorStateList.
     * @param theme Optional theme to apply to the color state list, may be
     *              {@code null}.
     * @return A new color state list.
     */
@NonNull
public static ColorStateList createFromXml(@NonNull Resources r, @NonNull XmlPullParser parser, @Nullable Theme theme) throws XmlPullParserException, IOException {
    final AttributeSet attrs = Xml.asAttributeSet(parser);
    int type;
    while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
    // Seek parser to start tag.
    }
    if (type != XmlPullParser.START_TAG) {
        throw new XmlPullParserException("No start tag found");
    }
    return createFromXmlInner(r, parser, attrs, theme);
}
Also used : AttributeSet(android.util.AttributeSet) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NonNull(android.annotation.NonNull)

Aggregations

AttributeSet (android.util.AttributeSet)262 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)160 IOException (java.io.IOException)125 XmlResourceParser (android.content.res.XmlResourceParser)113 TypedArray (android.content.res.TypedArray)78 Resources (android.content.res.Resources)46 Test (org.junit.Test)42 TypedValue (android.util.TypedValue)34 InflateException (android.view.InflateException)28 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)24 PackageManager (android.content.pm.PackageManager)22 Context (android.content.Context)20 ComponentName (android.content.ComponentName)18 XmlPullParser (org.xmlpull.v1.XmlPullParser)17 Intent (android.content.Intent)11 RemoteException (android.os.RemoteException)11 Bundle (android.os.Bundle)9 ArrayList (java.util.ArrayList)9 ActivityInfo (android.content.pm.ActivityInfo)7 ApplicationInfo (android.content.pm.ApplicationInfo)7