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;
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
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();
}
}
Aggregations