Search in sources :

Example 76 with FastXmlSerializer

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

the class AppWidgetServiceImpl method writeProfileStateToFileLocked.

private boolean writeProfileStateToFileLocked(FileOutputStream stream, int userId) {
    int N;
    try {
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(stream, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.startTag(null, "gs");
        out.attribute(null, "version", String.valueOf(CURRENT_VERSION));
        N = mProviders.size();
        for (int i = 0; i < N; i++) {
            Provider provider = mProviders.get(i);
            // Save only providers for the user.
            if (provider.getUserId() != userId) {
                continue;
            }
            if (provider.widgets.size() > 0) {
                serializeProvider(out, provider);
            }
        }
        N = mHosts.size();
        for (int i = 0; i < N; i++) {
            Host host = mHosts.get(i);
            // Save only hosts for the user.
            if (host.getUserId() != userId) {
                continue;
            }
            serializeHost(out, host);
        }
        N = mWidgets.size();
        for (int i = 0; i < N; i++) {
            Widget widget = mWidgets.get(i);
            // Save only widgets hosted by the user.
            if (widget.host.getUserId() != userId) {
                continue;
            }
            serializeAppWidget(out, widget);
        }
        Iterator<Pair<Integer, String>> it = mPackagesWithBindWidgetPermission.iterator();
        while (it.hasNext()) {
            Pair<Integer, String> binding = it.next();
            // Save only white listings for the user.
            if (binding.first != userId) {
                continue;
            }
            out.startTag(null, "b");
            out.attribute(null, "packageName", binding.second);
            out.endTag(null, "b");
        }
        out.endTag(null, "gs");
        out.endDocument();
        return true;
    } catch (IOException e) {
        Slog.w(TAG, "Failed to write state: " + e);
        return false;
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) IAppWidgetHost(com.android.internal.appwidget.IAppWidgetHost) IOException(java.io.IOException) Point(android.graphics.Point) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) WidgetBackupProvider(com.android.server.WidgetBackupProvider) Pair(android.util.Pair)

Example 77 with FastXmlSerializer

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

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

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

the class PackageInstallerService method writeSessionsLocked.

private void writeSessionsLocked() {
    if (LOGD)
        Slog.v(TAG, "writeSessionsLocked()");
    FileOutputStream fos = null;
    try {
        fos = mSessionsFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.startTag(null, TAG_SESSIONS);
        final int size = mSessions.size();
        for (int i = 0; i < size; i++) {
            final PackageInstallerSession session = mSessions.valueAt(i);
            writeSessionLocked(out, session);
        }
        out.endTag(null, TAG_SESSIONS);
        out.endDocument();
        mSessionsFile.finishWrite(fos);
    } catch (IOException e) {
        if (fos != null) {
            mSessionsFile.failWrite(fos);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) IPackageInstallerSession(android.content.pm.IPackageInstallerSession) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 79 with FastXmlSerializer

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

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

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

the class WallpaperManagerService method saveSettingsLocked.

private void saveSettingsLocked(int userId) {
    JournaledFile journal = makeJournaledFile(userId);
    FileOutputStream fstream = null;
    BufferedOutputStream stream = null;
    try {
        XmlSerializer out = new FastXmlSerializer();
        fstream = new FileOutputStream(journal.chooseForWrite(), false);
        stream = new BufferedOutputStream(fstream);
        out.setOutput(stream, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        WallpaperData wallpaper;
        wallpaper = mWallpaperMap.get(userId);
        if (wallpaper != null) {
            writeWallpaperAttributes(out, "wp", wallpaper);
        }
        wallpaper = mLockWallpaperMap.get(userId);
        if (wallpaper != null) {
            writeWallpaperAttributes(out, "kwp", wallpaper);
        }
        out.endDocument();
        // also flushes fstream
        stream.flush();
        FileUtils.sync(fstream);
        // also closes fstream
        stream.close();
        journal.commit();
    } catch (IOException e) {
        IoUtils.closeQuietly(stream);
        journal.rollback();
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) JournaledFile(com.android.internal.util.JournaledFile) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) 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