use of org.xmlpull.v1.XmlPullParser in project android_frameworks_base by ParanoidAndroid.
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.XmlPullParser in project android_frameworks_base by ParanoidAndroid.
the class ConnectivityService method getProvisioningUrlBaseFromFile.
private String getProvisioningUrlBaseFromFile(int type) {
FileReader fileReader = null;
XmlPullParser parser = null;
Configuration config = mContext.getResources().getConfiguration();
String tagType;
switch(type) {
case PROVISIONING:
tagType = TAG_PROVISIONING_URL;
break;
case REDIRECTED_PROVISIONING:
tagType = TAG_REDIRECTED_URL;
break;
default:
throw new RuntimeException("getProvisioningUrlBaseFromFile: Unexpected parameter " + type);
}
try {
fileReader = new FileReader(mProvisioningUrlFile);
parser = Xml.newPullParser();
parser.setInput(fileReader);
XmlUtils.beginDocument(parser, TAG_PROVISIONING_URLS);
while (true) {
XmlUtils.nextElement(parser);
String element = parser.getName();
if (element == null)
break;
if (element.equals(tagType)) {
String mcc = parser.getAttributeValue(null, ATTR_MCC);
try {
if (mcc != null && Integer.parseInt(mcc) == config.mcc) {
String mnc = parser.getAttributeValue(null, ATTR_MNC);
if (mnc != null && Integer.parseInt(mnc) == config.mnc) {
parser.next();
if (parser.getEventType() == XmlPullParser.TEXT) {
return parser.getText();
}
}
}
} catch (NumberFormatException e) {
loge("NumberFormatException in getProvisioningUrlBaseFromFile: " + e);
}
}
}
return null;
} catch (FileNotFoundException e) {
loge("Carrier Provisioning Urls file not found");
} catch (XmlPullParserException e) {
loge("Xml parser exception reading Carrier Provisioning Urls file: " + e);
} catch (IOException e) {
loge("I/O exception reading Carrier Provisioning Urls file: " + e);
} finally {
if (fileReader != null) {
try {
fileReader.close();
} catch (IOException e) {
}
}
}
return null;
}
use of org.xmlpull.v1.XmlPullParser in project android_frameworks_base by ParanoidAndroid.
the class UsageStatsService method readHistoryStatsFLOCK.
private void readHistoryStatsFLOCK(AtomicFile file) {
FileInputStream fis = null;
try {
fis = mHistoryFile.openRead();
XmlPullParser parser = Xml.newPullParser();
parser.setInput(fis, null);
int eventType = parser.getEventType();
while (eventType != XmlPullParser.START_TAG) {
eventType = parser.next();
}
String tagName = parser.getName();
if ("usage-history".equals(tagName)) {
String pkg = null;
do {
eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
tagName = parser.getName();
int depth = parser.getDepth();
if ("pkg".equals(tagName) && depth == 2) {
pkg = parser.getAttributeValue(null, "name");
} else if ("comp".equals(tagName) && depth == 3 && pkg != null) {
String comp = parser.getAttributeValue(null, "name");
String lastResumeTimeStr = parser.getAttributeValue(null, "lrt");
if (comp != null && lastResumeTimeStr != null) {
try {
long lastResumeTime = Long.parseLong(lastResumeTimeStr);
synchronized (mStatsLock) {
Map<String, Long> lrt = mLastResumeTimes.get(pkg);
if (lrt == null) {
lrt = new HashMap<String, Long>();
mLastResumeTimes.put(pkg, lrt);
}
lrt.put(comp, lastResumeTime);
}
} catch (NumberFormatException e) {
}
}
}
} else if (eventType == XmlPullParser.END_TAG) {
if ("pkg".equals(parser.getName())) {
pkg = null;
}
}
} while (eventType != XmlPullParser.END_DOCUMENT);
}
} catch (XmlPullParserException e) {
Slog.w(TAG, "Error reading history stats: " + e);
} catch (IOException e) {
Slog.w(TAG, "Error reading history stats: " + e);
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
}
}
}
}
use of org.xmlpull.v1.XmlPullParser in project android_frameworks_base by ParanoidAndroid.
the class Settings method readStoppedLPw.
// Note: assumed "stopped" field is already cleared in all packages.
// Legacy reader, used to read in the old file format after an upgrade. Not used after that.
void readStoppedLPw() {
FileInputStream str = null;
if (mBackupStoppedPackagesFilename.exists()) {
try {
str = new FileInputStream(mBackupStoppedPackagesFilename);
mReadMessages.append("Reading from backup stopped packages file\n");
PackageManagerService.reportSettingsProblem(Log.INFO, "Need to read from backup stopped packages file");
if (mSettingsFilename.exists()) {
// If both the backup and normal file exist, we
// ignore the normal one since it might have been
// corrupted.
Slog.w(PackageManagerService.TAG, "Cleaning up stopped packages file " + mStoppedPackagesFilename);
mStoppedPackagesFilename.delete();
}
} catch (java.io.IOException e) {
// We'll try for the normal settings file.
}
}
try {
if (str == null) {
if (!mStoppedPackagesFilename.exists()) {
mReadMessages.append("No stopped packages file found\n");
PackageManagerService.reportSettingsProblem(Log.INFO, "No stopped packages file file; assuming all started");
// in the stopped state, but not at first boot.
for (PackageSetting pkg : mPackages.values()) {
pkg.setStopped(false, 0);
pkg.setNotLaunched(false, 0);
}
return;
}
str = new FileInputStream(mStoppedPackagesFilename);
}
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(str, null);
int type;
while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
;
}
if (type != XmlPullParser.START_TAG) {
mReadMessages.append("No start tag found in stopped packages file\n");
PackageManagerService.reportSettingsProblem(Log.WARN, "No start tag found in package manager stopped packages");
return;
}
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(TAG_PACKAGE)) {
String name = parser.getAttributeValue(null, ATTR_NAME);
PackageSetting ps = mPackages.get(name);
if (ps != null) {
ps.setStopped(true, 0);
if ("1".equals(parser.getAttributeValue(null, ATTR_NOT_LAUNCHED))) {
ps.setNotLaunched(true, 0);
}
} else {
Slog.w(PackageManagerService.TAG, "No package known for stopped package: " + name);
}
XmlUtils.skipCurrentTag(parser);
} else {
Slog.w(PackageManagerService.TAG, "Unknown element under <stopped-packages>: " + parser.getName());
XmlUtils.skipCurrentTag(parser);
}
}
str.close();
} catch (XmlPullParserException e) {
mReadMessages.append("Error reading: " + e.toString());
PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading stopped packages: " + e);
Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
} catch (java.io.IOException e) {
mReadMessages.append("Error reading: " + e.toString());
PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
}
}
use of org.xmlpull.v1.XmlPullParser in project android_frameworks_base by ParanoidAndroid.
the class Settings method readDefaultPreferredAppsLPw.
void readDefaultPreferredAppsLPw(PackageManagerService service, int userId) {
// Read preferred apps from .../etc/preferred-apps directory.
File preferredDir = new File(Environment.getRootDirectory(), "etc/preferred-apps");
if (!preferredDir.exists() || !preferredDir.isDirectory()) {
return;
}
if (!preferredDir.canRead()) {
Slog.w(TAG, "Directory " + preferredDir + " cannot be read");
return;
}
// Iterate over the files in the directory and scan .xml files
for (File f : preferredDir.listFiles()) {
if (!f.getPath().endsWith(".xml")) {
Slog.i(TAG, "Non-xml file " + f + " in " + preferredDir + " directory, ignoring");
continue;
}
if (!f.canRead()) {
Slog.w(TAG, "Preferred apps file " + f + " cannot be read");
continue;
}
if (PackageManagerService.DEBUG_PREFERRED)
Log.d(TAG, "Reading default preferred " + f);
FileInputStream str = null;
try {
str = new FileInputStream(f);
XmlPullParser parser = Xml.newPullParser();
parser.setInput(str, null);
int type;
while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
;
}
if (type != XmlPullParser.START_TAG) {
Slog.w(TAG, "Preferred apps file " + f + " does not have start tag");
continue;
}
if (!"preferred-activities".equals(parser.getName())) {
Slog.w(TAG, "Preferred apps file " + f + " does not start with 'preferred-activities'");
continue;
}
readDefaultPreferredActivitiesLPw(service, parser, userId);
} catch (XmlPullParserException e) {
Slog.w(TAG, "Error reading apps file " + f, e);
} catch (IOException e) {
Slog.w(TAG, "Error reading apps file " + f, e);
} finally {
if (str != null) {
try {
str.close();
} catch (IOException e) {
}
}
}
}
}
Aggregations