use of com.android.internal.util.FastXmlSerializer in project platform_frameworks_base by android.
the class BatteryStatsImpl method recordDailyStatsLocked.
public void recordDailyStatsLocked() {
DailyItem item = new DailyItem();
item.mStartTime = mDailyStartTime;
item.mEndTime = System.currentTimeMillis();
boolean hasData = false;
if (mDailyDischargeStepTracker.mNumStepDurations > 0) {
hasData = true;
item.mDischargeSteps = new LevelStepTracker(mDailyDischargeStepTracker.mNumStepDurations, mDailyDischargeStepTracker.mStepDurations);
}
if (mDailyChargeStepTracker.mNumStepDurations > 0) {
hasData = true;
item.mChargeSteps = new LevelStepTracker(mDailyChargeStepTracker.mNumStepDurations, mDailyChargeStepTracker.mStepDurations);
}
if (mDailyPackageChanges != null) {
hasData = true;
item.mPackageChanges = mDailyPackageChanges;
mDailyPackageChanges = null;
}
mDailyDischargeStepTracker.init();
mDailyChargeStepTracker.init();
updateDailyDeadlineLocked();
if (hasData) {
mDailyItems.add(item);
while (mDailyItems.size() > MAX_DAILY_ITEMS) {
mDailyItems.remove(0);
}
final ByteArrayOutputStream memStream = new ByteArrayOutputStream();
try {
XmlSerializer out = new FastXmlSerializer();
out.setOutput(memStream, StandardCharsets.UTF_8.name());
writeDailyItemsLocked(out);
BackgroundThread.getHandler().post(new Runnable() {
@Override
public void run() {
synchronized (mCheckinFile) {
FileOutputStream stream = null;
try {
stream = mDailyFile.startWrite();
memStream.writeTo(stream);
stream.flush();
FileUtils.sync(stream);
stream.close();
mDailyFile.finishWrite(stream);
} catch (IOException e) {
Slog.w("BatteryStats", "Error writing battery daily items", e);
mDailyFile.failWrite(stream);
}
}
}
});
} catch (IOException e) {
}
}
}
use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by ParanoidAndroid.
the class DevicePolicyManagerService method saveSettingsLocked.
private void saveSettingsLocked(int userHandle) {
DevicePolicyData policy = getUserData(userHandle);
JournaledFile journal = makeJournaledFile(userHandle);
FileOutputStream stream = null;
try {
stream = new FileOutputStream(journal.chooseForWrite(), false);
XmlSerializer out = new FastXmlSerializer();
out.setOutput(stream, "utf-8");
out.startDocument(null, true);
out.startTag(null, "policies");
final int N = policy.mAdminList.size();
for (int i = 0; i < N; i++) {
ActiveAdmin ap = policy.mAdminList.get(i);
if (ap != null) {
out.startTag(null, "admin");
out.attribute(null, "name", ap.info.getComponent().flattenToString());
ap.writeToXml(out);
out.endTag(null, "admin");
}
}
if (policy.mPasswordOwner >= 0) {
out.startTag(null, "password-owner");
out.attribute(null, "value", Integer.toString(policy.mPasswordOwner));
out.endTag(null, "password-owner");
}
if (policy.mFailedPasswordAttempts != 0) {
out.startTag(null, "failed-password-attempts");
out.attribute(null, "value", Integer.toString(policy.mFailedPasswordAttempts));
out.endTag(null, "failed-password-attempts");
}
if (policy.mActivePasswordQuality != 0 || policy.mActivePasswordLength != 0 || policy.mActivePasswordUpperCase != 0 || policy.mActivePasswordLowerCase != 0 || policy.mActivePasswordLetters != 0 || policy.mActivePasswordNumeric != 0 || policy.mActivePasswordSymbols != 0 || policy.mActivePasswordNonLetter != 0) {
out.startTag(null, "active-password");
out.attribute(null, "quality", Integer.toString(policy.mActivePasswordQuality));
out.attribute(null, "length", Integer.toString(policy.mActivePasswordLength));
out.attribute(null, "uppercase", Integer.toString(policy.mActivePasswordUpperCase));
out.attribute(null, "lowercase", Integer.toString(policy.mActivePasswordLowerCase));
out.attribute(null, "letters", Integer.toString(policy.mActivePasswordLetters));
out.attribute(null, "numeric", Integer.toString(policy.mActivePasswordNumeric));
out.attribute(null, "symbols", Integer.toString(policy.mActivePasswordSymbols));
out.attribute(null, "nonletter", Integer.toString(policy.mActivePasswordNonLetter));
out.endTag(null, "active-password");
}
out.endTag(null, "policies");
out.endDocument();
stream.close();
journal.commit();
sendChangedNotification(userHandle);
} catch (IOException e) {
try {
if (stream != null) {
stream.close();
}
} catch (IOException ex) {
// Ignore
}
journal.rollback();
}
}
use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by ParanoidAndroid.
the class NotificationManagerService method writeHaloBlockDb.
private synchronized void writeHaloBlockDb() {
FileOutputStream outfile = null;
try {
outfile = mHaloPolicyFile.startWrite();
XmlSerializer out = new FastXmlSerializer();
out.setOutput(outfile, "utf-8");
out.startDocument(null, true);
out.startTag(null, TAG_BODY);
{
out.attribute(null, ATTR_VERSION, String.valueOf(DB_VERSION));
out.attribute(null, ATTR_HALO_POLICY_IS_BLACK, (mHaloPolicyisBlack ? "1" : "0"));
out.startTag(null, TAG_BLOCKED_PKGS);
{
for (String blockedPkg : mHaloBlacklist) {
out.startTag(null, TAG_PACKAGE);
{
out.attribute(null, ATTR_NAME, blockedPkg);
}
out.endTag(null, TAG_PACKAGE);
}
}
out.endTag(null, TAG_BLOCKED_PKGS);
out.startTag(null, TAG_ALLOWED_PKGS);
{
for (String allowedPkg : mHaloWhitelist) {
out.startTag(null, TAG_PACKAGE);
{
out.attribute(null, ATTR_NAME, allowedPkg);
}
out.endTag(null, TAG_PACKAGE);
}
}
out.endTag(null, TAG_ALLOWED_PKGS);
}
out.endTag(null, TAG_BODY);
out.endDocument();
mHaloPolicyFile.finishWrite(outfile);
} catch (IOException e) {
if (outfile != null) {
mHaloPolicyFile.failWrite(outfile);
}
}
}
use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by ParanoidAndroid.
the class NotificationManagerService method writeBlockDb.
private void writeBlockDb() {
synchronized (mBlockedPackages) {
FileOutputStream outfile = null;
try {
outfile = mPolicyFile.startWrite();
XmlSerializer out = new FastXmlSerializer();
out.setOutput(outfile, "utf-8");
out.startDocument(null, true);
out.startTag(null, TAG_BODY);
{
out.attribute(null, ATTR_VERSION, String.valueOf(DB_VERSION));
out.startTag(null, TAG_BLOCKED_PKGS);
{
// write all known network policies
for (String pkg : mBlockedPackages) {
out.startTag(null, TAG_PACKAGE);
{
out.attribute(null, ATTR_NAME, pkg);
}
out.endTag(null, TAG_PACKAGE);
}
}
out.endTag(null, TAG_BLOCKED_PKGS);
}
out.endTag(null, TAG_BODY);
out.endDocument();
mPolicyFile.finishWrite(outfile);
} catch (IOException e) {
if (outfile != null) {
mPolicyFile.failWrite(outfile);
}
}
}
}
use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by ParanoidAndroid.
the class UsageStatsService method writeHistoryStatsFLOCK.
private void writeHistoryStatsFLOCK(AtomicFile historyFile) {
FileOutputStream fos = null;
try {
fos = historyFile.startWrite();
XmlSerializer out = new FastXmlSerializer();
out.setOutput(fos, "utf-8");
out.startDocument(null, true);
out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
out.startTag(null, "usage-history");
synchronized (mStatsLock) {
for (Map.Entry<String, Map<String, Long>> pkgEntry : mLastResumeTimes.entrySet()) {
out.startTag(null, "pkg");
out.attribute(null, "name", pkgEntry.getKey());
for (Map.Entry<String, Long> compEntry : pkgEntry.getValue().entrySet()) {
out.startTag(null, "comp");
out.attribute(null, "name", compEntry.getKey());
out.attribute(null, "lrt", compEntry.getValue().toString());
out.endTag(null, "comp");
}
out.endTag(null, "pkg");
}
}
out.endTag(null, "usage-history");
out.endDocument();
historyFile.finishWrite(fos);
} catch (IOException e) {
Slog.w(TAG, "Error writing history stats" + e);
if (fos != null) {
historyFile.failWrite(fos);
}
}
}
Aggregations