use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by ResurrectionRemix.
the class ShortcutService method saveBaseStateLocked.
@VisibleForTesting
void saveBaseStateLocked() {
final AtomicFile file = getBaseStateFile();
if (DEBUG) {
Slog.d(TAG, "Saving to " + file.getBaseFile());
}
FileOutputStream outs = null;
try {
outs = file.startWrite();
// Write to XML
XmlSerializer out = new FastXmlSerializer();
out.setOutput(outs, StandardCharsets.UTF_8.name());
out.startDocument(null, true);
out.startTag(null, TAG_ROOT);
// Body.
writeTagValue(out, TAG_LAST_RESET_TIME, mRawLastResetTime);
// Epilogue.
out.endTag(null, TAG_ROOT);
out.endDocument();
// Close.
file.finishWrite(outs);
} catch (IOException e) {
Slog.e(TAG, "Failed to write to file " + file.getBaseFile(), e);
file.failWrite(outs);
}
}
use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by ResurrectionRemix.
the class UserManagerService method writeUserListLP.
/*
* Writes the user list file in this format:
*
* <users nextSerialNumber="3">
* <user id="0"></user>
* <user id="2"></user>
* </users>
*/
private void writeUserListLP() {
if (DBG) {
debug("writeUserList");
}
FileOutputStream fos = null;
AtomicFile userListFile = new AtomicFile(mUserListFile);
try {
fos = userListFile.startWrite();
final BufferedOutputStream bos = new BufferedOutputStream(fos);
// XmlSerializer serializer = XmlUtils.serializerInstance();
final XmlSerializer serializer = new FastXmlSerializer();
serializer.setOutput(bos, StandardCharsets.UTF_8.name());
serializer.startDocument(null, true);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(null, TAG_USERS);
serializer.attribute(null, ATTR_NEXT_SERIAL_NO, Integer.toString(mNextSerialNumber));
serializer.attribute(null, ATTR_USER_VERSION, Integer.toString(mUserVersion));
serializer.startTag(null, TAG_GUEST_RESTRICTIONS);
synchronized (mGuestRestrictions) {
UserRestrictionsUtils.writeRestrictions(serializer, mGuestRestrictions, TAG_RESTRICTIONS);
}
serializer.endTag(null, TAG_GUEST_RESTRICTIONS);
synchronized (mRestrictionsLock) {
UserRestrictionsUtils.writeRestrictions(serializer, mDevicePolicyGlobalUserRestrictions, TAG_DEVICE_POLICY_RESTRICTIONS);
}
serializer.startTag(null, TAG_GLOBAL_RESTRICTION_OWNER_ID);
serializer.attribute(null, ATTR_ID, Integer.toString(mGlobalRestrictionOwnerUserId));
serializer.endTag(null, TAG_GLOBAL_RESTRICTION_OWNER_ID);
int[] userIdsToWrite;
synchronized (mUsersLock) {
userIdsToWrite = new int[mUsers.size()];
for (int i = 0; i < userIdsToWrite.length; i++) {
UserInfo user = mUsers.valueAt(i).info;
userIdsToWrite[i] = user.id;
}
}
for (int id : userIdsToWrite) {
serializer.startTag(null, TAG_USER);
serializer.attribute(null, ATTR_ID, Integer.toString(id));
serializer.endTag(null, TAG_USER);
}
serializer.endTag(null, TAG_USERS);
serializer.endDocument();
userListFile.finishWrite(fos);
} catch (Exception e) {
userListFile.failWrite(fos);
Slog.e(LOG_TAG, "Error writing user list");
}
}
use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by ResurrectionRemix.
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 org.xmlpull.v1.XmlSerializer in project android_frameworks_base by ResurrectionRemix.
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();
}
}
use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by ResurrectionRemix.
the class AccountManagerBackupHelper method backupAccountAccessPermissions.
public byte[] backupAccountAccessPermissions(int userId) {
final AccountManagerService.UserAccounts accounts = mAccountManagerService.getUserAccounts(userId);
synchronized (accounts.cacheLock) {
SQLiteDatabase db = accounts.openHelper.getReadableDatabase();
try (Cursor cursor = db.rawQuery(ACCOUNT_ACCESS_GRANTS, null)) {
if (cursor == null || !cursor.moveToFirst()) {
return null;
}
final int nameColumnIdx = cursor.getColumnIndex(AccountManagerService.ACCOUNTS_NAME);
final int uidColumnIdx = cursor.getColumnIndex(AccountManagerService.GRANTS_GRANTEE_UID);
ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
try {
final XmlSerializer serializer = new FastXmlSerializer();
serializer.setOutput(dataStream, StandardCharsets.UTF_8.name());
serializer.startDocument(null, true);
serializer.startTag(null, TAG_PERMISSIONS);
PackageManager packageManager = mAccountManagerService.mContext.getPackageManager();
do {
final String accountName = cursor.getString(nameColumnIdx);
final int uid = cursor.getInt(uidColumnIdx);
final String[] packageNames = packageManager.getPackagesForUid(uid);
if (packageNames == null) {
continue;
}
for (String packageName : packageNames) {
String digest = PackageUtils.computePackageCertSha256Digest(packageManager, packageName, userId);
if (digest != null) {
serializer.startTag(null, TAG_PERMISSION);
serializer.attribute(null, ATTR_ACCOUNT_SHA_256, PackageUtils.computeSha256Digest(accountName.getBytes()));
serializer.attribute(null, ATTR_PACKAGE, packageName);
serializer.attribute(null, ATTR_DIGEST, digest);
serializer.endTag(null, TAG_PERMISSION);
}
}
} while (cursor.moveToNext());
serializer.endTag(null, TAG_PERMISSIONS);
serializer.endDocument();
serializer.flush();
} catch (IOException e) {
Log.e(TAG, "Error backing up account access grants", e);
return null;
}
return dataStream.toByteArray();
}
}
}
Aggregations