Search in sources :

Example 66 with XmlSerializer

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");
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) AtomicFile(android.util.AtomicFile) FileOutputStream(java.io.FileOutputStream) UserInfo(android.content.pm.UserInfo) BufferedOutputStream(java.io.BufferedOutputStream) ErrnoException(android.system.ErrnoException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 67 with XmlSerializer

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();
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 68 with XmlSerializer

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();
}
Also used : XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 69 with XmlSerializer

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();
}
Also used : XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 70 with XmlSerializer

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);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Aggregations

XmlSerializer (org.xmlpull.v1.XmlSerializer)268 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)156 IOException (java.io.IOException)151 FileOutputStream (java.io.FileOutputStream)144 BufferedOutputStream (java.io.BufferedOutputStream)57 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)40 AtomicFile (android.util.AtomicFile)39 RemoteException (android.os.RemoteException)29 File (java.io.File)26 FileNotFoundException (java.io.FileNotFoundException)26 StringWriter (java.io.StringWriter)26 Map (java.util.Map)23 ErrnoException (android.system.ErrnoException)20 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)15 JournaledFile (com.android.internal.util.JournaledFile)15 UserInfo (android.content.pm.UserInfo)9 HashMap (java.util.HashMap)9 SendIntentException (android.content.IntentSender.SendIntentException)8 PackageParserException (android.content.pm.PackageParser.PackageParserException)8