Search in sources :

Example 16 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.

the class DreamBackend method getSettingsComponentName.

private static ComponentName getSettingsComponentName(PackageManager pm, ResolveInfo resolveInfo) {
    if (resolveInfo == null || resolveInfo.serviceInfo == null || resolveInfo.serviceInfo.metaData == null)
        return null;
    String cn = null;
    XmlResourceParser parser = null;
    Exception caughtException = null;
    try {
        parser = resolveInfo.serviceInfo.loadXmlMetaData(pm, DreamService.DREAM_META_DATA);
        if (parser == null) {
            Log.w(TAG, "No " + DreamService.DREAM_META_DATA + " meta-data");
            return null;
        }
        Resources res = pm.getResourcesForApplication(resolveInfo.serviceInfo.applicationInfo);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        int type;
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
        }
        String nodeName = parser.getName();
        if (!"dream".equals(nodeName)) {
            Log.w(TAG, "Meta-data does not start with dream tag");
            return null;
        }
        TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.Dream);
        cn = sa.getString(com.android.internal.R.styleable.Dream_settingsActivity);
        sa.recycle();
    } catch (PackageManager.NameNotFoundException | IOException | XmlPullParserException e) {
        caughtException = e;
    } finally {
        if (parser != null)
            parser.close();
    }
    if (caughtException != null) {
        Log.w(TAG, "Error parsing : " + resolveInfo.serviceInfo.packageName, caughtException);
        return null;
    }
    if (cn != null && cn.indexOf('/') < 0) {
        cn = resolveInfo.serviceInfo.packageName + "/" + cn;
    }
    return cn == null ? null : ComponentName.unflattenFromString(cn);
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources) IOException(java.io.IOException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 17 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.

the class ZoneGetter method readTimezonesToDisplay.

private static List<String> readTimezonesToDisplay(Context context) {
    List<String> olsonIds = new ArrayList<String>();
    try (XmlResourceParser xrp = context.getResources().getXml(R.xml.timezones)) {
        while (xrp.next() != XmlResourceParser.START_TAG) {
            continue;
        }
        xrp.next();
        while (xrp.getEventType() != XmlResourceParser.END_TAG) {
            while (xrp.getEventType() != XmlResourceParser.START_TAG) {
                if (xrp.getEventType() == XmlResourceParser.END_DOCUMENT) {
                    return olsonIds;
                }
                xrp.next();
            }
            if (xrp.getName().equals(XMLTAG_TIMEZONE)) {
                String olsonId = xrp.getAttributeValue(0);
                olsonIds.add(olsonId);
            }
            while (xrp.getEventType() != XmlResourceParser.END_TAG) {
                xrp.next();
            }
            xrp.next();
        }
    } catch (XmlPullParserException xppe) {
        Log.e(TAG, "Ill-formatted timezones.xml file");
    } catch (java.io.IOException ioe) {
        Log.e(TAG, "Unable to read timezones.xml file");
    }
    return olsonIds;
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) ArrayList(java.util.ArrayList) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 18 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.

the class StackOverflowXmlParser method parse.

// We don't use namespaces
public List<Entry> parse(InputStream in) throws XmlPullParserException, IOException {
    try {
        XmlPullParser parser = Xml.newPullParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        parser.setInput(in, null);
        parser.nextTag();
        return readFeed(parser);
    } finally {
        in.close();
    }
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 19 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.

the class ExpatPerformanceTest method runExpatPullParser.

private void runExpatPullParser() throws XmlPullParserException, IOException {
    long start = System.currentTimeMillis();
    XmlPullParser pullParser = Xml.newPullParser();
    pullParser.setInput(newInputStream(), "UTF-8");
    withPullParser(pullParser);
    long elapsed = System.currentTimeMillis() - start;
    Log.i(TAG, "expat pull: " + elapsed + "ms");
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 20 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.

the class SyncStorageEngine method readAccountInfoLocked.

/**
     * Read all account information back in to the initial engine state.
     */
private void readAccountInfoLocked() {
    int highestAuthorityId = -1;
    FileInputStream fis = null;
    try {
        fis = mAccountInfoFile.openRead();
        if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
            Slog.v(TAG_FILE, "Reading " + mAccountInfoFile.getBaseFile());
        }
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(fis, StandardCharsets.UTF_8.name());
        int eventType = parser.getEventType();
        while (eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_DOCUMENT) {
            eventType = parser.next();
        }
        if (eventType == XmlPullParser.END_DOCUMENT) {
            Slog.i(TAG, "No initial accounts");
            return;
        }
        String tagName = parser.getName();
        if ("accounts".equals(tagName)) {
            String listen = parser.getAttributeValue(null, XML_ATTR_LISTEN_FOR_TICKLES);
            String versionString = parser.getAttributeValue(null, "version");
            int version;
            try {
                version = (versionString == null) ? 0 : Integer.parseInt(versionString);
            } catch (NumberFormatException e) {
                version = 0;
            }
            if (version < 3) {
                mGrantSyncAdaptersAccountAccess = true;
            }
            String nextIdString = parser.getAttributeValue(null, XML_ATTR_NEXT_AUTHORITY_ID);
            try {
                int id = (nextIdString == null) ? 0 : Integer.parseInt(nextIdString);
                mNextAuthorityId = Math.max(mNextAuthorityId, id);
            } catch (NumberFormatException e) {
            // don't care
            }
            String offsetString = parser.getAttributeValue(null, XML_ATTR_SYNC_RANDOM_OFFSET);
            try {
                mSyncRandomOffset = (offsetString == null) ? 0 : Integer.parseInt(offsetString);
            } catch (NumberFormatException e) {
                mSyncRandomOffset = 0;
            }
            if (mSyncRandomOffset == 0) {
                Random random = new Random(System.currentTimeMillis());
                mSyncRandomOffset = random.nextInt(86400);
            }
            mMasterSyncAutomatically.put(0, listen == null || Boolean.parseBoolean(listen));
            eventType = parser.next();
            AuthorityInfo authority = null;
            PeriodicSync periodicSync = null;
            do {
                if (eventType == XmlPullParser.START_TAG) {
                    tagName = parser.getName();
                    if (parser.getDepth() == 2) {
                        if ("authority".equals(tagName)) {
                            authority = parseAuthority(parser, version);
                            periodicSync = null;
                            if (authority != null) {
                                if (authority.ident > highestAuthorityId) {
                                    highestAuthorityId = authority.ident;
                                }
                            } else {
                                EventLog.writeEvent(0x534e4554, "26513719", -1, "Malformed authority");
                            }
                        } else if (XML_TAG_LISTEN_FOR_TICKLES.equals(tagName)) {
                            parseListenForTickles(parser);
                        }
                    } else if (parser.getDepth() == 3) {
                        if ("periodicSync".equals(tagName) && authority != null) {
                            periodicSync = parsePeriodicSync(parser, authority);
                        }
                    } else if (parser.getDepth() == 4 && periodicSync != null) {
                        if ("extra".equals(tagName)) {
                            parseExtra(parser, periodicSync.extras);
                        }
                    }
                }
                eventType = parser.next();
            } while (eventType != XmlPullParser.END_DOCUMENT);
        }
    } catch (XmlPullParserException e) {
        Slog.w(TAG, "Error reading accounts", e);
        return;
    } catch (java.io.IOException e) {
        if (fis == null)
            Slog.i(TAG, "No initial accounts");
        else
            Slog.w(TAG, "Error reading accounts", e);
        return;
    } finally {
        mNextAuthorityId = Math.max(highestAuthorityId + 1, mNextAuthorityId);
        if (fis != null) {
            try {
                fis.close();
            } catch (java.io.IOException e1) {
            }
        }
    }
    maybeMigrateSettingsForRenamedAuthorities();
}
Also used : Random(java.util.Random) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) PeriodicSync(android.content.PeriodicSync) FileInputStream(java.io.FileInputStream)

Aggregations

XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1071 IOException (java.io.IOException)630 XmlPullParser (org.xmlpull.v1.XmlPullParser)440 FileNotFoundException (java.io.FileNotFoundException)187 XmlResourceParser (android.content.res.XmlResourceParser)186 FileInputStream (java.io.FileInputStream)182 AttributeSet (android.util.AttributeSet)159 TypedArray (android.content.res.TypedArray)156 Resources (android.content.res.Resources)101 File (java.io.File)101 ArrayList (java.util.ArrayList)99 PackageManager (android.content.pm.PackageManager)62 HashMap (java.util.HashMap)58 ComponentName (android.content.ComponentName)57 InputStream (java.io.InputStream)57 Intent (android.content.Intent)54 XmlSerializer (org.xmlpull.v1.XmlSerializer)54 AtomicFile (android.util.AtomicFile)50 BufferedInputStream (java.io.BufferedInputStream)44 TypedValue (android.util.TypedValue)43