use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by AOSPA.
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);
}
}
}
use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by AOSPA.
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);
} else {
mAtomicFile.failWrite(os);
}
}
} catch (IOException ex) {
Slog.w(TAG, "Failed to save display manager persistent store data.", ex);
}
}
use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by crdroidandroid.
the class CompatModePackages method saveCompatModes.
void saveCompatModes() {
HashMap<String, Integer> pkgs;
synchronized (mService) {
pkgs = new HashMap<String, Integer>(mPackages);
}
FileOutputStream fos = null;
try {
fos = mFile.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, "compat-packages");
final IPackageManager pm = AppGlobals.getPackageManager();
final int screenLayout = mService.mConfiguration.screenLayout;
final int smallestScreenWidthDp = mService.mConfiguration.smallestScreenWidthDp;
final Iterator<Map.Entry<String, Integer>> it = pkgs.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Integer> entry = it.next();
String pkg = entry.getKey();
int mode = entry.getValue();
if (mode == 0) {
continue;
}
ApplicationInfo ai = null;
try {
ai = pm.getApplicationInfo(pkg, 0, 0);
} catch (RemoteException e) {
}
if (ai == null) {
continue;
}
CompatibilityInfo info = new CompatibilityInfo(ai, screenLayout, smallestScreenWidthDp, false);
if (info.alwaysSupportsScreen()) {
continue;
}
if (info.neverSupportsScreen()) {
continue;
}
out.startTag(null, "pkg");
out.attribute(null, "name", pkg);
out.attribute(null, "mode", Integer.toString(mode));
out.endTag(null, "pkg");
}
out.endTag(null, "compat-packages");
out.endDocument();
mFile.finishWrite(fos);
} catch (java.io.IOException e1) {
Slog.w(TAG, "Error writing compat packages", e1);
if (fos != null) {
mFile.failWrite(fos);
}
}
}
use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by crdroidandroid.
the class ShortcutService method saveUserInternalLocked.
private void saveUserInternalLocked(@UserIdInt int userId, OutputStream os, boolean forBackup) throws IOException, XmlPullParserException {
final BufferedOutputStream bos = new BufferedOutputStream(os);
// Write to XML
XmlSerializer out = new FastXmlSerializer();
out.setOutput(bos, StandardCharsets.UTF_8.name());
out.startDocument(null, true);
getUserShortcutsLocked(userId).saveToXml(out, forBackup);
out.endDocument();
bos.flush();
os.flush();
}
use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by crdroidandroid.
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);
}
}
Aggregations