use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by DirtyUnicorns.
the class UserManagerService method writeUserListLP.
/*
* Writes the user list file in this format:
*
* <users nextSerialNumber="3">
* <user id="0"></user>
* <user id="2"></user>
* </users>
*/
private void writeUserListLP() {
if (DBG) {
debug("writeUserList");
}
FileOutputStream fos = null;
AtomicFile userListFile = new AtomicFile(mUserListFile);
try {
fos = userListFile.startWrite();
final BufferedOutputStream bos = new BufferedOutputStream(fos);
// XmlSerializer serializer = XmlUtils.serializerInstance();
final XmlSerializer serializer = new FastXmlSerializer();
serializer.setOutput(bos, StandardCharsets.UTF_8.name());
serializer.startDocument(null, true);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(null, TAG_USERS);
serializer.attribute(null, ATTR_NEXT_SERIAL_NO, Integer.toString(mNextSerialNumber));
serializer.attribute(null, ATTR_USER_VERSION, Integer.toString(mUserVersion));
serializer.startTag(null, TAG_GUEST_RESTRICTIONS);
synchronized (mGuestRestrictions) {
UserRestrictionsUtils.writeRestrictions(serializer, mGuestRestrictions, TAG_RESTRICTIONS);
}
serializer.endTag(null, TAG_GUEST_RESTRICTIONS);
synchronized (mRestrictionsLock) {
UserRestrictionsUtils.writeRestrictions(serializer, mDevicePolicyGlobalUserRestrictions, TAG_DEVICE_POLICY_RESTRICTIONS);
}
serializer.startTag(null, TAG_GLOBAL_RESTRICTION_OWNER_ID);
serializer.attribute(null, ATTR_ID, Integer.toString(mGlobalRestrictionOwnerUserId));
serializer.endTag(null, TAG_GLOBAL_RESTRICTION_OWNER_ID);
int[] userIdsToWrite;
synchronized (mUsersLock) {
userIdsToWrite = new int[mUsers.size()];
for (int i = 0; i < userIdsToWrite.length; i++) {
UserInfo user = mUsers.valueAt(i).info;
userIdsToWrite[i] = user.id;
}
}
for (int id : userIdsToWrite) {
serializer.startTag(null, TAG_USER);
serializer.attribute(null, ATTR_ID, Integer.toString(id));
serializer.endTag(null, TAG_USER);
}
serializer.endTag(null, TAG_USERS);
serializer.endDocument();
userListFile.finishWrite(fos);
} catch (Exception e) {
userListFile.failWrite(fos);
Slog.e(LOG_TAG, "Error writing user list");
}
}
use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by DirtyUnicorns.
the class NotificationManagerService method writePolicyXml.
private void writePolicyXml(OutputStream stream, boolean forBackup) throws IOException {
final XmlSerializer out = new FastXmlSerializer();
out.setOutput(stream, StandardCharsets.UTF_8.name());
out.startDocument(null, true);
out.startTag(null, TAG_NOTIFICATION_POLICY);
out.attribute(null, ATTR_VERSION, Integer.toString(DB_VERSION));
mZenModeHelper.writeXml(out, forBackup);
mRankingHelper.writeXml(out, forBackup);
out.endTag(null, TAG_NOTIFICATION_POLICY);
out.endDocument();
}
use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by DirtyUnicorns.
the class XmlUtils method writeMapXml.
/**
* Flatten a Map into an output stream as XML. The map can later be
* read back with readMapXml().
*
* @param val The map to be flattened.
* @param out Where to write the XML data.
*
* @see #writeMapXml(Map, String, XmlSerializer)
* @see #writeListXml
* @see #writeValueXml
* @see #readMapXml
*/
public static final void writeMapXml(Map val, OutputStream out) throws XmlPullParserException, java.io.IOException {
XmlSerializer serializer = new FastXmlSerializer();
serializer.setOutput(out, StandardCharsets.UTF_8.name());
serializer.startDocument(null, true);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
writeMapXml(val, null, serializer);
serializer.endDocument();
}
use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by DirtyUnicorns.
the class XmlUtils method writeListXml.
/**
* Flatten a List into an output stream as XML. The list can later be
* read back with readListXml().
*
* @param val The list to be flattened.
* @param out Where to write the XML data.
*
* @see #writeListXml(List, String, XmlSerializer)
* @see #writeMapXml
* @see #writeValueXml
* @see #readListXml
*/
public static final void writeListXml(List val, OutputStream out) throws XmlPullParserException, java.io.IOException {
XmlSerializer serializer = Xml.newSerializer();
serializer.setOutput(out, StandardCharsets.UTF_8.name());
serializer.startDocument(null, true);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
writeListXml(val, null, serializer);
serializer.endDocument();
}
use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by DirtyUnicorns.
the class DeviceIdleController method handleWriteConfigFile.
void handleWriteConfigFile() {
final ByteArrayOutputStream memStream = new ByteArrayOutputStream();
try {
synchronized (this) {
XmlSerializer out = new FastXmlSerializer();
out.setOutput(memStream, StandardCharsets.UTF_8.name());
writeConfigFileLocked(out);
}
} catch (IOException e) {
}
synchronized (mConfigFile) {
FileOutputStream stream = null;
try {
stream = mConfigFile.startWrite();
memStream.writeTo(stream);
stream.flush();
FileUtils.sync(stream);
stream.close();
mConfigFile.finishWrite(stream);
} catch (IOException e) {
Slog.w(TAG, "Error writing config file", e);
mConfigFile.failWrite(stream);
}
}
}
Aggregations