use of org.xmlpull.v1.XmlPullParser in project platform_frameworks_base by android.
the class InputManagerService method getExcludedDeviceNames.
// Native callback.
private String[] getExcludedDeviceNames() {
ArrayList<String> names = new ArrayList<String>();
// Read partner-provided list of excluded input devices
XmlPullParser parser = null;
// Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
FileReader confreader = null;
try {
confreader = new FileReader(confFile);
parser = Xml.newPullParser();
parser.setInput(confreader);
XmlUtils.beginDocument(parser, "devices");
while (true) {
XmlUtils.nextElement(parser);
if (!"device".equals(parser.getName())) {
break;
}
String name = parser.getAttributeValue(null, "name");
if (name != null) {
names.add(name);
}
}
} catch (FileNotFoundException e) {
// It's ok if the file does not exist.
} catch (Exception e) {
Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
} finally {
try {
if (confreader != null)
confreader.close();
} catch (IOException e) {
}
}
return names.toArray(new String[names.size()]);
}
use of org.xmlpull.v1.XmlPullParser in project platform_frameworks_base by android.
the class PackageManagerService method restorePreferredActivities.
@Override
public void restorePreferredActivities(byte[] backup, int userId) {
if (Binder.getCallingUid() != Process.SYSTEM_UID) {
throw new SecurityException("Only the system may call restorePreferredActivities()");
}
try {
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(new ByteArrayInputStream(backup), StandardCharsets.UTF_8.name());
restoreFromXml(parser, userId, TAG_PREFERRED_BACKUP, new BlobXmlRestorer() {
@Override
public void apply(XmlPullParser parser, int userId) throws XmlPullParserException, IOException {
synchronized (mPackages) {
mSettings.readPreferredActivitiesLPw(parser, userId);
}
}
});
} catch (Exception e) {
if (DEBUG_BACKUP) {
Slog.e(TAG, "Exception restoring preferred activities: " + e.getMessage());
}
}
}
use of org.xmlpull.v1.XmlPullParser in project platform_frameworks_base by android.
the class PackageManagerService method restorePermissionGrants.
@Override
public void restorePermissionGrants(byte[] backup, int userId) {
if (Binder.getCallingUid() != Process.SYSTEM_UID) {
throw new SecurityException("Only the system may call restorePermissionGrants()");
}
try {
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(new ByteArrayInputStream(backup), StandardCharsets.UTF_8.name());
restoreFromXml(parser, userId, TAG_PERMISSION_BACKUP, new BlobXmlRestorer() {
@Override
public void apply(XmlPullParser parser, int userId) throws XmlPullParserException, IOException {
synchronized (mPackages) {
processRestoredPermissionGrantsLPr(parser, userId);
}
}
});
} catch (Exception e) {
if (DEBUG_BACKUP) {
Slog.e(TAG, "Exception restoring preferred activities: " + e.getMessage());
}
}
}
use of org.xmlpull.v1.XmlPullParser in project platform_frameworks_base by android.
the class BootReceiver method readTimestamps.
private static HashMap<String, Long> readTimestamps() {
synchronized (sFile) {
HashMap<String, Long> timestamps = new HashMap<String, Long>();
boolean success = false;
try (final FileInputStream stream = sFile.openRead()) {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(stream, StandardCharsets.UTF_8.name());
int type;
while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
;
}
if (type != XmlPullParser.START_TAG) {
throw new IllegalStateException("no start tag found");
}
// Skip the outer <log-files> tag.
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("log")) {
final String filename = parser.getAttributeValue(null, "filename");
final long timestamp = Long.valueOf(parser.getAttributeValue(null, "timestamp"));
timestamps.put(filename, timestamp);
} else {
Slog.w(TAG, "Unknown tag: " + parser.getName());
XmlUtils.skipCurrentTag(parser);
}
}
success = true;
} catch (FileNotFoundException e) {
Slog.i(TAG, "No existing last log timestamp file " + sFile.getBaseFile() + "; starting empty");
} catch (IOException e) {
Slog.w(TAG, "Failed parsing " + e);
} catch (IllegalStateException e) {
Slog.w(TAG, "Failed parsing " + e);
} catch (NullPointerException e) {
Slog.w(TAG, "Failed parsing " + e);
} catch (XmlPullParserException e) {
Slog.w(TAG, "Failed parsing " + e);
} finally {
if (!success) {
timestamps.clear();
}
}
return timestamps;
}
}
use of org.xmlpull.v1.XmlPullParser in project platform_frameworks_base by android.
the class SettingsState method readStateSyncLocked.
private void readStateSyncLocked() {
FileInputStream in;
if (!mStatePersistFile.exists()) {
Slog.i(LOG_TAG, "No settings state " + mStatePersistFile);
addHistoricalOperationLocked(HISTORICAL_OPERATION_INITIALIZE, null);
return;
}
try {
in = new AtomicFile(mStatePersistFile).openRead();
} catch (FileNotFoundException fnfe) {
String message = "No settings state " + mStatePersistFile;
Slog.wtf(LOG_TAG, message);
Slog.i(LOG_TAG, message);
return;
}
try {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(in, StandardCharsets.UTF_8.name());
parseStateLocked(parser);
} catch (XmlPullParserException | IOException e) {
String message = "Failed parsing settings file: " + mStatePersistFile;
Slog.wtf(LOG_TAG, message);
throw new IllegalStateException(message, e);
} finally {
IoUtils.closeQuietly(in);
}
}
Aggregations