Search in sources :

Example 31 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by ResurrectionRemix.

the class UsageStatsXml method write.

static void write(OutputStream out, IntervalStats stats) throws IOException {
    FastXmlSerializer xml = new FastXmlSerializer();
    xml.setOutput(out, "utf-8");
    xml.startDocument("utf-8", true);
    xml.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    xml.startTag(null, USAGESTATS_TAG);
    xml.attribute(null, VERSION_ATTR, Integer.toString(CURRENT_VERSION));
    UsageStatsXmlV1.write(xml, stats);
    xml.endTag(null, USAGESTATS_TAG);
    xml.endDocument();
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 32 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by ResurrectionRemix.

the class UsbSettingsManager method writeSettingsLocked.

private void writeSettingsLocked() {
    if (DEBUG)
        Slog.v(TAG, "writeSettingsLocked()");
    FileOutputStream fos = null;
    try {
        fos = mSettingsFile.startWrite();
        FastXmlSerializer serializer = new FastXmlSerializer();
        serializer.setOutput(fos, StandardCharsets.UTF_8.name());
        serializer.startDocument(null, true);
        serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        serializer.startTag(null, "settings");
        for (DeviceFilter filter : mDevicePreferenceMap.keySet()) {
            serializer.startTag(null, "preference");
            serializer.attribute(null, "package", mDevicePreferenceMap.get(filter));
            filter.write(serializer);
            serializer.endTag(null, "preference");
        }
        for (AccessoryFilter filter : mAccessoryPreferenceMap.keySet()) {
            serializer.startTag(null, "preference");
            serializer.attribute(null, "package", mAccessoryPreferenceMap.get(filter));
            filter.write(serializer);
            serializer.endTag(null, "preference");
        }
        serializer.endTag(null, "settings");
        serializer.endDocument();
        mSettingsFile.finishWrite(fos);
    } catch (IOException e) {
        Slog.e(TAG, "Failed to write settings", e);
        if (fos != null) {
            mSettingsFile.failWrite(fos);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException)

Example 33 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by ResurrectionRemix.

the class AppOpsService method writeState.

void writeState() {
    synchronized (mFile) {
        FileOutputStream stream;
        try {
            stream = mFile.startWrite();
        } catch (IOException e) {
            Slog.w(TAG, "Failed to write state: " + e);
            return;
        }
        SparseArray<UidState> outUidStates = null;
        synchronized (this) {
            final int uidStateCount = mUidStates.size();
            for (int i = 0; i < uidStateCount; i++) {
                UidState uidState = mUidStates.valueAt(i);
                SparseIntArray opModes = uidState.opModes;
                if (opModes != null && opModes.size() > 0) {
                    UidState outUidState = new UidState(uidState.uid);
                    outUidState.opModes = opModes.clone();
                    if (outUidStates == null) {
                        outUidStates = new SparseArray<>();
                    }
                    outUidStates.put(mUidStates.keyAt(i), outUidState);
                }
            }
        }
        List<AppOpsManager.PackageOps> allOps = getPackagesForOps(null);
        try {
            XmlSerializer out = new FastXmlSerializer();
            out.setOutput(stream, StandardCharsets.UTF_8.name());
            out.startDocument(null, true);
            out.startTag(null, "app-ops");
            final int uidStateCount = outUidStates != null ? outUidStates.size() : 0;
            for (int i = 0; i < uidStateCount; i++) {
                UidState uidState = outUidStates.valueAt(i);
                if (uidState.opModes != null && uidState.opModes.size() > 0) {
                    out.startTag(null, "uid");
                    out.attribute(null, "n", Integer.toString(uidState.uid));
                    SparseIntArray uidOpModes = uidState.opModes;
                    final int opCount = uidOpModes.size();
                    for (int j = 0; j < opCount; j++) {
                        final int op = uidOpModes.keyAt(j);
                        final int mode = uidOpModes.valueAt(j);
                        out.startTag(null, "op");
                        out.attribute(null, "n", Integer.toString(op));
                        out.attribute(null, "m", Integer.toString(mode));
                        out.endTag(null, "op");
                    }
                    out.endTag(null, "uid");
                }
            }
            if (allOps != null) {
                String lastPkg = null;
                for (int i = 0; i < allOps.size(); i++) {
                    AppOpsManager.PackageOps pkg = allOps.get(i);
                    if (!pkg.getPackageName().equals(lastPkg)) {
                        if (lastPkg != null) {
                            out.endTag(null, "pkg");
                        }
                        lastPkg = pkg.getPackageName();
                        out.startTag(null, "pkg");
                        out.attribute(null, "n", lastPkg);
                    }
                    out.startTag(null, "uid");
                    out.attribute(null, "n", Integer.toString(pkg.getUid()));
                    synchronized (this) {
                        Ops ops = getOpsRawLocked(pkg.getUid(), pkg.getPackageName(), false);
                        // from Ops.
                        if (ops != null) {
                            out.attribute(null, "p", Boolean.toString(ops.isPrivileged));
                        } else {
                            out.attribute(null, "p", Boolean.toString(false));
                        }
                    }
                    List<AppOpsManager.OpEntry> ops = pkg.getOps();
                    for (int j = 0; j < ops.size(); j++) {
                        AppOpsManager.OpEntry op = ops.get(j);
                        out.startTag(null, "op");
                        out.attribute(null, "n", Integer.toString(op.getOp()));
                        out.attribute(null, "ns", AppOpsManager.opToName(op.getOp()));
                        int defaultMode = getDefaultMode(op.getOp(), pkg.getUid(), pkg.getPackageName());
                        if (op.getMode() != defaultMode) {
                            out.attribute(null, "m", Integer.toString(op.getMode()));
                        } else {
                            out.attribute(null, "dm", Integer.toString(defaultMode));
                        }
                        long time = op.getTime();
                        if (time != 0) {
                            out.attribute(null, "t", Long.toString(time));
                        }
                        time = op.getRejectTime();
                        if (time != 0) {
                            out.attribute(null, "r", Long.toString(time));
                        }
                        int dur = op.getDuration();
                        if (dur != 0) {
                            out.attribute(null, "d", Integer.toString(dur));
                        }
                        int proxyUid = op.getProxyUid();
                        if (proxyUid != -1) {
                            out.attribute(null, "pu", Integer.toString(proxyUid));
                        }
                        String proxyPackageName = op.getProxyPackageName();
                        if (proxyPackageName != null) {
                            out.attribute(null, "pp", proxyPackageName);
                        }
                        int allowed = op.getAllowedCount();
                        if (allowed != 0) {
                            out.attribute(null, "ac", Integer.toString(allowed));
                        }
                        int ignored = op.getIgnoredCount();
                        if (ignored != 0) {
                            out.attribute(null, "ic", Integer.toString(ignored));
                        }
                        out.endTag(null, "op");
                    }
                    out.endTag(null, "uid");
                }
                if (lastPkg != null) {
                    out.endTag(null, "pkg");
                }
            }
            out.endTag(null, "app-ops");
            out.endDocument();
            mFile.finishWrite(stream);
        } catch (IOException e) {
            Slog.w(TAG, "Failed to write state, restoring backup.", e);
            mFile.failWrite(stream);
        }
    }
}
Also used : IOException(java.io.IOException) AppOpsManager(android.app.AppOpsManager) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) SparseIntArray(android.util.SparseIntArray) FileOutputStream(java.io.FileOutputStream) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 34 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by ResurrectionRemix.

the class TaskPersister method saveToXml.

private StringWriter saveToXml(TaskRecord task) throws IOException, XmlPullParserException {
    if (DEBUG)
        Slog.d(TAG, "saveToXml: task=" + task);
    final XmlSerializer xmlSerializer = new FastXmlSerializer();
    StringWriter stringWriter = new StringWriter();
    xmlSerializer.setOutput(stringWriter);
    if (DEBUG)
        xmlSerializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    // save task
    xmlSerializer.startDocument(null, true);
    xmlSerializer.startTag(null, TAG_TASK);
    task.saveToXml(xmlSerializer);
    xmlSerializer.endTag(null, TAG_TASK);
    xmlSerializer.endDocument();
    xmlSerializer.flush();
    return stringWriter;
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) StringWriter(java.io.StringWriter) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 35 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by ResurrectionRemix.

the class Settings method writeLPr.

void writeLPr() {
    // been successfully written.
    if (mSettingsFilename.exists()) {
        // might have been corrupted.
        if (!mBackupSettingsFilename.exists()) {
            if (!mSettingsFilename.renameTo(mBackupSettingsFilename)) {
                Slog.wtf(PackageManagerService.TAG, "Unable to backup package manager settings, " + " current changes will be lost at reboot");
                return;
            }
        } else {
            mSettingsFilename.delete();
            Slog.w(PackageManagerService.TAG, "Preserving older settings backup");
        }
    }
    mPastSignatures.clear();
    try {
        FileOutputStream fstr = new FileOutputStream(mSettingsFilename);
        BufferedOutputStream str = new BufferedOutputStream(fstr);
        //XmlSerializer serializer = XmlUtils.serializerInstance();
        XmlSerializer serializer = new FastXmlSerializer();
        serializer.setOutput(str, StandardCharsets.UTF_8.name());
        serializer.startDocument(null, true);
        serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        serializer.startTag(null, "packages");
        for (int i = 0; i < mVersion.size(); i++) {
            final String volumeUuid = mVersion.keyAt(i);
            final VersionInfo ver = mVersion.valueAt(i);
            serializer.startTag(null, TAG_VERSION);
            XmlUtils.writeStringAttribute(serializer, ATTR_VOLUME_UUID, volumeUuid);
            XmlUtils.writeIntAttribute(serializer, ATTR_SDK_VERSION, ver.sdkVersion);
            XmlUtils.writeIntAttribute(serializer, ATTR_DATABASE_VERSION, ver.databaseVersion);
            XmlUtils.writeStringAttribute(serializer, ATTR_FINGERPRINT, ver.fingerprint);
            serializer.endTag(null, TAG_VERSION);
        }
        if (mVerifierDeviceIdentity != null) {
            serializer.startTag(null, "verifier");
            serializer.attribute(null, "device", mVerifierDeviceIdentity.toString());
            serializer.endTag(null, "verifier");
        }
        if (mReadExternalStorageEnforced != null) {
            serializer.startTag(null, TAG_READ_EXTERNAL_STORAGE);
            serializer.attribute(null, ATTR_ENFORCEMENT, mReadExternalStorageEnforced ? "1" : "0");
            serializer.endTag(null, TAG_READ_EXTERNAL_STORAGE);
        }
        serializer.startTag(null, "permission-trees");
        for (BasePermission bp : mPermissionTrees.values()) {
            writePermissionLPr(serializer, bp);
        }
        serializer.endTag(null, "permission-trees");
        serializer.startTag(null, "permissions");
        for (BasePermission bp : mPermissions.values()) {
            writePermissionLPr(serializer, bp);
        }
        serializer.endTag(null, "permissions");
        for (final PackageSetting pkg : mPackages.values()) {
            writePackageLPr(serializer, pkg);
        }
        for (final PackageSetting pkg : mDisabledSysPackages.values()) {
            writeDisabledSysPackageLPr(serializer, pkg);
        }
        for (final SharedUserSetting usr : mSharedUsers.values()) {
            serializer.startTag(null, "shared-user");
            serializer.attribute(null, ATTR_NAME, usr.name);
            serializer.attribute(null, "userId", Integer.toString(usr.userId));
            usr.signatures.writeXml(serializer, "sigs", mPastSignatures);
            writePermissionsLPr(serializer, usr.getPermissionsState().getInstallPermissionStates());
            serializer.endTag(null, "shared-user");
        }
        if (mPackagesToBeCleaned.size() > 0) {
            for (PackageCleanItem item : mPackagesToBeCleaned) {
                final String userStr = Integer.toString(item.userId);
                serializer.startTag(null, "cleaning-package");
                serializer.attribute(null, ATTR_NAME, item.packageName);
                serializer.attribute(null, ATTR_CODE, item.andCode ? "true" : "false");
                serializer.attribute(null, ATTR_USER, userStr);
                serializer.endTag(null, "cleaning-package");
            }
        }
        if (mRenamedPackages.size() > 0) {
            for (Map.Entry<String, String> e : mRenamedPackages.entrySet()) {
                serializer.startTag(null, "renamed-package");
                serializer.attribute(null, "new", e.getKey());
                serializer.attribute(null, "old", e.getValue());
                serializer.endTag(null, "renamed-package");
            }
        }
        final int numIVIs = mRestoredIntentFilterVerifications.size();
        if (numIVIs > 0) {
            if (DEBUG_DOMAIN_VERIFICATION) {
                Slog.i(TAG, "Writing restored-ivi entries to packages.xml");
            }
            serializer.startTag(null, "restored-ivi");
            for (int i = 0; i < numIVIs; i++) {
                IntentFilterVerificationInfo ivi = mRestoredIntentFilterVerifications.valueAt(i);
                writeDomainVerificationsLPr(serializer, ivi);
            }
            serializer.endTag(null, "restored-ivi");
        } else {
            if (DEBUG_DOMAIN_VERIFICATION) {
                Slog.i(TAG, "  no restored IVI entries to write");
            }
        }
        mKeySetManagerService.writeKeySetManagerServiceLPr(serializer);
        serializer.endTag(null, "packages");
        serializer.endDocument();
        str.flush();
        FileUtils.sync(fstr);
        str.close();
        // New settings successfully written, old ones are no longer
        // needed.
        mBackupSettingsFilename.delete();
        FileUtils.setPermissions(mSettingsFilename.toString(), FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP | FileUtils.S_IWGRP, -1, -1);
        writeKernelMappingLPr();
        writePackageListLPr();
        writeAllUsersPackageRestrictionsLPr();
        writeAllRuntimePermissionsLPr();
        return;
    } catch (XmlPullParserException e) {
        Slog.wtf(PackageManagerService.TAG, "Unable to write package manager settings, " + "current changes will be lost at reboot", e);
    } catch (java.io.IOException e) {
        Slog.wtf(PackageManagerService.TAG, "Unable to write package manager settings, " + "current changes will be lost at reboot", e);
    }
    // Clean up partially written files
    if (mSettingsFilename.exists()) {
        if (!mSettingsFilename.delete()) {
            Slog.wtf(PackageManagerService.TAG, "Failed to clean up mangled file: " + mSettingsFilename);
        }
    }
//Debug.stopMethodTracing();
}
Also used : IOException(java.io.IOException) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) PackageCleanItem(android.content.pm.PackageCleanItem) FileOutputStream(java.io.FileOutputStream) IntentFilterVerificationInfo(android.content.pm.IntentFilterVerificationInfo) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) BufferedOutputStream(java.io.BufferedOutputStream) Map(java.util.Map) ArrayMap(android.util.ArrayMap) 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