Search in sources :

Example 66 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by crdroidandroid.

the class TaskPersister method saveToXml.

private StringWriter saveToXml(TaskRecord task) throws IOException, XmlPullParserException {
    if (DEBUG)
        Slog.d(TAG, "saveToXml: task=" + task);
    final XmlSerializer xmlSerializer = new FastXmlSerializer();
    StringWriter stringWriter = new StringWriter();
    xmlSerializer.setOutput(stringWriter);
    if (DEBUG)
        xmlSerializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    // save task
    xmlSerializer.startDocument(null, true);
    xmlSerializer.startTag(null, TAG_TASK);
    task.saveToXml(xmlSerializer);
    xmlSerializer.endTag(null, TAG_TASK);
    xmlSerializer.endDocument();
    xmlSerializer.flush();
    return stringWriter;
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) StringWriter(java.io.StringWriter) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 67 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by crdroidandroid.

the class PersistentDataStore method save.

private void save() {
    final FileOutputStream os;
    try {
        os = mAtomicFile.startWrite();
        boolean success = false;
        try {
            XmlSerializer serializer = new FastXmlSerializer();
            serializer.setOutput(new BufferedOutputStream(os), StandardCharsets.UTF_8.name());
            saveToXml(serializer);
            serializer.flush();
            success = true;
        } finally {
            if (success) {
                mAtomicFile.finishWrite(os);
            } else {
                mAtomicFile.failWrite(os);
            }
        }
    } catch (IOException ex) {
        Slog.w(InputManagerService.TAG, "Failed to save input manager persistent store data.", ex);
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 68 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by crdroidandroid.

the class PersistentDataStore method save.

private void save() {
    final FileOutputStream os;
    try {
        os = mAtomicFile.startWrite();
        boolean success = false;
        try {
            XmlSerializer serializer = new FastXmlSerializer();
            serializer.setOutput(new BufferedOutputStream(os), StandardCharsets.UTF_8.name());
            saveToXml(serializer);
            serializer.flush();
            success = true;
        } finally {
            if (success) {
                mAtomicFile.finishWrite(os);
                broadcastChangesIfNeeded();
            } else {
                mAtomicFile.failWrite(os);
            }
        }
    } catch (IOException ex) {
        Slog.w(TAG, "Failed to save tv input manager persistent store data.", ex);
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 69 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by crdroidandroid.

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)

Example 70 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by crdroidandroid.

the class NetworkPolicyManagerService method writePolicyAL.

void writePolicyAL() {
    if (LOGV)
        Slog.v(TAG, "writePolicyAL()");
    FileOutputStream fos = null;
    try {
        fos = mPolicyFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.startTag(null, TAG_POLICY_LIST);
        writeIntAttribute(out, ATTR_VERSION, VERSION_LATEST);
        writeBooleanAttribute(out, ATTR_RESTRICT_BACKGROUND, mRestrictBackground);
        // write all known network policies
        for (int i = 0; i < mNetworkPolicy.size(); i++) {
            final NetworkPolicy policy = mNetworkPolicy.valueAt(i);
            final NetworkTemplate template = policy.template;
            if (!template.isPersistable())
                continue;
            out.startTag(null, TAG_NETWORK_POLICY);
            writeIntAttribute(out, ATTR_NETWORK_TEMPLATE, template.getMatchRule());
            final String subscriberId = template.getSubscriberId();
            if (subscriberId != null) {
                out.attribute(null, ATTR_SUBSCRIBER_ID, subscriberId);
            }
            final String networkId = template.getNetworkId();
            if (networkId != null) {
                out.attribute(null, ATTR_NETWORK_ID, networkId);
            }
            writeIntAttribute(out, ATTR_CYCLE_DAY, policy.cycleDay);
            out.attribute(null, ATTR_CYCLE_TIMEZONE, policy.cycleTimezone);
            writeLongAttribute(out, ATTR_WARNING_BYTES, policy.warningBytes);
            writeLongAttribute(out, ATTR_LIMIT_BYTES, policy.limitBytes);
            writeLongAttribute(out, ATTR_LAST_WARNING_SNOOZE, policy.lastWarningSnooze);
            writeLongAttribute(out, ATTR_LAST_LIMIT_SNOOZE, policy.lastLimitSnooze);
            writeBooleanAttribute(out, ATTR_METERED, policy.metered);
            writeBooleanAttribute(out, ATTR_INFERRED, policy.inferred);
            out.endTag(null, TAG_NETWORK_POLICY);
        }
        // write all known uid policies
        for (int i = 0; i < mUidPolicy.size(); i++) {
            final int uid = mUidPolicy.keyAt(i);
            final int policy = mUidPolicy.valueAt(i);
            // skip writing empty policies
            if (policy == POLICY_NONE)
                continue;
            out.startTag(null, TAG_UID_POLICY);
            writeIntAttribute(out, ATTR_UID, uid);
            writeIntAttribute(out, ATTR_POLICY, policy);
            out.endTag(null, TAG_UID_POLICY);
        }
        out.endTag(null, TAG_POLICY_LIST);
        // write all whitelists
        out.startTag(null, TAG_WHITELIST);
        // restrict background whitelist
        int size = mRestrictBackgroundWhitelistUids.size();
        for (int i = 0; i < size; i++) {
            final int uid = mRestrictBackgroundWhitelistUids.keyAt(i);
            out.startTag(null, TAG_RESTRICT_BACKGROUND);
            writeIntAttribute(out, ATTR_UID, uid);
            out.endTag(null, TAG_RESTRICT_BACKGROUND);
        }
        // revoked restrict background whitelist
        size = mRestrictBackgroundWhitelistRevokedUids.size();
        for (int i = 0; i < size; i++) {
            final int uid = mRestrictBackgroundWhitelistRevokedUids.keyAt(i);
            out.startTag(null, TAG_REVOKED_RESTRICT_BACKGROUND);
            writeIntAttribute(out, ATTR_UID, uid);
            out.endTag(null, TAG_REVOKED_RESTRICT_BACKGROUND);
        }
        out.endTag(null, TAG_WHITELIST);
        out.endDocument();
        mPolicyFile.finishWrite(fos);
    } catch (IOException e) {
        if (fos != null) {
            mPolicyFile.failWrite(fos);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) NetworkTemplate(android.net.NetworkTemplate) NetworkPolicy(android.net.NetworkPolicy) FileOutputStream(java.io.FileOutputStream) NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Aggregations

FastXmlSerializer (com.android.internal.util.FastXmlSerializer)169 XmlSerializer (org.xmlpull.v1.XmlSerializer)156 IOException (java.io.IOException)138 FileOutputStream (java.io.FileOutputStream)132 BufferedOutputStream (java.io.BufferedOutputStream)56 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)35 RemoteException (android.os.RemoteException)29 AtomicFile (android.util.AtomicFile)28 FileNotFoundException (java.io.FileNotFoundException)24 ByteArrayOutputStream (java.io.ByteArrayOutputStream)22 Map (java.util.Map)22 ErrnoException (android.system.ErrnoException)20 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)15 JournaledFile (com.android.internal.util.JournaledFile)15 File (java.io.File)13 HashMap (java.util.HashMap)11 UserInfo (android.content.pm.UserInfo)9 SendIntentException (android.content.IntentSender.SendIntentException)8 PackageParserException (android.content.pm.PackageParser.PackageParserException)8 Point (android.graphics.Point)8