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);
}
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;
}
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();
}
}
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");
}
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();
}
Aggregations