Search in sources :

Example 11 with FastXmlSerializer

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

the class DisplaySettings method writeSettingsLocked.

public void writeSettingsLocked() {
    FileOutputStream stream;
    try {
        stream = mFile.startWrite();
    } catch (IOException e) {
        Slog.w(TAG, "Failed to write display settings: " + e);
        return;
    }
    try {
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(stream, "utf-8");
        out.startDocument(null, true);
        out.startTag(null, "display-settings");
        for (Entry entry : mEntries.values()) {
            out.startTag(null, "display");
            out.attribute(null, "name", entry.name);
            if (entry.overscanLeft != 0) {
                out.attribute(null, "overscanLeft", Integer.toString(entry.overscanLeft));
            }
            if (entry.overscanTop != 0) {
                out.attribute(null, "overscanTop", Integer.toString(entry.overscanTop));
            }
            if (entry.overscanRight != 0) {
                out.attribute(null, "overscanRight", Integer.toString(entry.overscanRight));
            }
            if (entry.overscanBottom != 0) {
                out.attribute(null, "overscanBottom", Integer.toString(entry.overscanBottom));
            }
            out.endTag(null, "display");
        }
        out.endTag(null, "display-settings");
        out.endDocument();
        mFile.finishWrite(stream);
    } catch (IOException e) {
        Slog.w(TAG, "Failed to write display settings, restoring backup.", e);
        mFile.failWrite(stream);
    }
}
Also used : 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 12 with FastXmlSerializer

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

the class UsbSettingsManager method writeSettingsLocked.

private void writeSettingsLocked() {
    if (DEBUG)
        Slog.v(TAG, "writeSettingsLocked()");
    FileOutputStream fos = null;
    try {
        fos = mSettingsFile.startWrite();
        FastXmlSerializer serializer = new FastXmlSerializer();
        serializer.setOutput(fos, "utf-8");
        serializer.startDocument(null, true);
        serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        serializer.startTag(null, "settings");
        for (DeviceFilter filter : mDevicePreferenceMap.keySet()) {
            serializer.startTag(null, "preference");
            serializer.attribute(null, "package", mDevicePreferenceMap.get(filter));
            filter.write(serializer);
            serializer.endTag(null, "preference");
        }
        for (AccessoryFilter filter : mAccessoryPreferenceMap.keySet()) {
            serializer.startTag(null, "preference");
            serializer.attribute(null, "package", mAccessoryPreferenceMap.get(filter));
            filter.write(serializer);
            serializer.endTag(null, "preference");
        }
        serializer.endTag(null, "settings");
        serializer.endDocument();
        mSettingsFile.finishWrite(fos);
    } catch (IOException e) {
        Slog.e(TAG, "Failed to write settings", e);
        if (fos != null) {
            mSettingsFile.failWrite(fos);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException)

Example 13 with FastXmlSerializer

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

the class BootReceiver method writeTimestamps.

private void writeTimestamps(HashMap<String, Long> timestamps) {
    synchronized (sFile) {
        final FileOutputStream stream;
        try {
            stream = sFile.startWrite();
        } catch (IOException e) {
            Slog.w(TAG, "Failed to write timestamp file: " + e);
            return;
        }
        try {
            XmlSerializer out = new FastXmlSerializer();
            out.setOutput(stream, StandardCharsets.UTF_8.name());
            out.startDocument(null, true);
            out.startTag(null, "log-files");
            Iterator<String> itor = timestamps.keySet().iterator();
            while (itor.hasNext()) {
                String filename = itor.next();
                out.startTag(null, "log");
                out.attribute(null, "filename", filename);
                out.attribute(null, "timestamp", timestamps.get(filename).toString());
                out.endTag(null, "log");
            }
            out.endTag(null, "log-files");
            out.endDocument();
            sFile.finishWrite(stream);
        } catch (IOException e) {
            Slog.w(TAG, "Failed to write timestamp file, using the backup: " + e);
            sFile.failWrite(stream);
        }
    }
}
Also used : 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 14 with FastXmlSerializer

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

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

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

the class SyncStorageEngine method writeAccountInfoLocked.

/**
     * Write all account information to the account file.
     */
private void writeAccountInfoLocked() {
    if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
        Slog.v(TAG_FILE, "Writing new " + mAccountInfoFile.getBaseFile());
    }
    FileOutputStream fos = null;
    try {
        fos = mAccountInfoFile.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, "accounts");
        out.attribute(null, "version", Integer.toString(ACCOUNTS_VERSION));
        out.attribute(null, XML_ATTR_NEXT_AUTHORITY_ID, Integer.toString(mNextAuthorityId));
        out.attribute(null, XML_ATTR_SYNC_RANDOM_OFFSET, Integer.toString(mSyncRandomOffset));
        // Write the Sync Automatically flags for each user
        final int M = mMasterSyncAutomatically.size();
        for (int m = 0; m < M; m++) {
            int userId = mMasterSyncAutomatically.keyAt(m);
            Boolean listen = mMasterSyncAutomatically.valueAt(m);
            out.startTag(null, XML_TAG_LISTEN_FOR_TICKLES);
            out.attribute(null, XML_ATTR_USER, Integer.toString(userId));
            out.attribute(null, XML_ATTR_ENABLED, Boolean.toString(listen));
            out.endTag(null, XML_TAG_LISTEN_FOR_TICKLES);
        }
        final int N = mAuthorities.size();
        for (int i = 0; i < N; i++) {
            AuthorityInfo authority = mAuthorities.valueAt(i);
            EndPoint info = authority.target;
            out.startTag(null, "authority");
            out.attribute(null, "id", Integer.toString(authority.ident));
            out.attribute(null, XML_ATTR_USER, Integer.toString(info.userId));
            out.attribute(null, XML_ATTR_ENABLED, Boolean.toString(authority.enabled));
            out.attribute(null, "account", info.account.name);
            out.attribute(null, "type", info.account.type);
            out.attribute(null, "authority", info.provider);
            out.attribute(null, "syncable", Integer.toString(authority.syncable));
            out.endTag(null, "authority");
        }
        out.endTag(null, "accounts");
        out.endDocument();
        mAccountInfoFile.finishWrite(fos);
    } catch (java.io.IOException e1) {
        Slog.w(TAG, "Error writing accounts", e1);
        if (fos != null) {
            mAccountInfoFile.failWrite(fos);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) 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