Search in sources :

Example 86 with FastXmlSerializer

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) {
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 87 with FastXmlSerializer

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();
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) JournaledFile(com.android.internal.util.JournaledFile) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 88 with FastXmlSerializer

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);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 89 with FastXmlSerializer

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);
            }
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 90 with FastXmlSerializer

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);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) AtomicLong(java.util.concurrent.atomic.AtomicLong) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) 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