Search in sources :

Example 96 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project platform_frameworks_base by android.

the class RegisteredServicesCache method writePersistentServicesLocked.

/**
     * Writes services of a specified user to the file.
     */
private void writePersistentServicesLocked(UserServices<V> user, int userId) {
    if (mSerializerAndParser == null) {
        return;
    }
    AtomicFile atomicFile = createFileForUser(userId);
    FileOutputStream fos = null;
    try {
        fos = atomicFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        out.startTag(null, "services");
        for (Map.Entry<V, Integer> service : user.persistentServices.entrySet()) {
            out.startTag(null, "service");
            out.attribute(null, "uid", Integer.toString(service.getValue()));
            mSerializerAndParser.writeAsXml(service.getKey(), out);
            out.endTag(null, "service");
        }
        out.endTag(null, "services");
        out.endDocument();
        atomicFile.finishWrite(fos);
    } catch (IOException e1) {
        Log.w(TAG, "Error writing accounts", e1);
        if (fos != null) {
            atomicFile.failWrite(fos);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) AtomicFile(android.util.AtomicFile) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Map(java.util.Map) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 97 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project platform_frameworks_base by android.

the class MountService method writeSettingsLocked.

private void writeSettingsLocked() {
    FileOutputStream fos = null;
    try {
        fos = mSettingsFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.startTag(null, TAG_VOLUMES);
        writeIntAttribute(out, ATTR_VERSION, VERSION_FIX_PRIMARY);
        writeStringAttribute(out, ATTR_PRIMARY_STORAGE_UUID, mPrimaryStorageUuid);
        writeBooleanAttribute(out, ATTR_FORCE_ADOPTABLE, mForceAdoptable);
        final int size = mRecords.size();
        for (int i = 0; i < size; i++) {
            final VolumeRecord rec = mRecords.valueAt(i);
            writeVolumeRecord(out, rec);
        }
        out.endTag(null, TAG_VOLUMES);
        out.endDocument();
        mSettingsFile.finishWrite(fos);
    } catch (IOException e) {
        if (fos != null) {
            mSettingsFile.failWrite(fos);
        }
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 98 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project platform_frameworks_base by android.

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 99 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project platform_frameworks_base by android.

the class AppIdleHistory method writeAppIdleTimesLocked.

public void writeAppIdleTimesLocked(int userId) {
    FileOutputStream fos = null;
    AtomicFile appIdleFile = new AtomicFile(getUserFile(userId));
    try {
        fos = appIdleFile.startWrite();
        final BufferedOutputStream bos = new BufferedOutputStream(fos);
        FastXmlSerializer xml = new FastXmlSerializer();
        xml.setOutput(bos, StandardCharsets.UTF_8.name());
        xml.startDocument(null, true);
        xml.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        xml.startTag(null, TAG_PACKAGES);
        ArrayMap<String, PackageHistory> userHistory = getUserHistoryLocked(userId);
        final int N = userHistory.size();
        for (int i = 0; i < N; i++) {
            String packageName = userHistory.keyAt(i);
            PackageHistory history = userHistory.valueAt(i);
            xml.startTag(null, TAG_PACKAGE);
            xml.attribute(null, ATTR_NAME, packageName);
            xml.attribute(null, ATTR_ELAPSED_IDLE, Long.toString(history.lastUsedElapsedTime));
            xml.attribute(null, ATTR_SCREEN_IDLE, Long.toString(history.lastUsedScreenTime));
            xml.endTag(null, TAG_PACKAGE);
        }
        xml.endTag(null, TAG_PACKAGES);
        xml.endDocument();
        appIdleFile.finishWrite(fos);
    } catch (Exception e) {
        appIdleFile.failWrite(fos);
        Slog.e(TAG, "Error writing app idle file for user " + userId);
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) AtomicFile(android.util.AtomicFile) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 100 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project platform_frameworks_base by android.

the class UsageStatsXml method write.

static void write(OutputStream out, IntervalStats stats) throws IOException {
    FastXmlSerializer xml = new FastXmlSerializer();
    xml.setOutput(out, "utf-8");
    xml.startDocument("utf-8", true);
    xml.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    xml.startTag(null, USAGESTATS_TAG);
    xml.attribute(null, VERSION_ATTR, Integer.toString(CURRENT_VERSION));
    UsageStatsXmlV1.write(xml, stats);
    xml.endTag(null, USAGESTATS_TAG);
    xml.endDocument();
}
Also used : 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