Search in sources :

Example 81 with FastXmlSerializer

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

the class PackageInstallerService method writeSessionsLocked.

private void writeSessionsLocked() {
    if (LOGD)
        Slog.v(TAG, "writeSessionsLocked()");
    FileOutputStream fos = null;
    try {
        fos = mSessionsFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.startTag(null, TAG_SESSIONS);
        final int size = mSessions.size();
        for (int i = 0; i < size; i++) {
            final PackageInstallerSession session = mSessions.valueAt(i);
            writeSessionLocked(out, session);
        }
        out.endTag(null, TAG_SESSIONS);
        out.endDocument();
        mSessionsFile.finishWrite(fos);
    } catch (IOException e) {
        if (fos != null) {
            mSessionsFile.failWrite(fos);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) IPackageInstallerSession(android.content.pm.IPackageInstallerSession) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 82 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project platform_frameworks_base by android.

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(InputManagerService.TAG, "Failed to save input manager persistent store data.", ex);
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 83 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project platform_frameworks_base by android.

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");
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) AtomicFile(android.util.AtomicFile) FileOutputStream(java.io.FileOutputStream) UserInfo(android.content.pm.UserInfo) BufferedOutputStream(java.io.BufferedOutputStream) ErrnoException(android.system.ErrnoException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 84 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project platform_frameworks_base by android.

the class UserManagerService method writeApplicationRestrictionsLP.

@VisibleForTesting
static void writeApplicationRestrictionsLP(Bundle restrictions, AtomicFile restrictionsFile) {
    FileOutputStream fos = null;
    try {
        fos = restrictionsFile.startWrite();
        final BufferedOutputStream bos = new BufferedOutputStream(fos);
        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_RESTRICTIONS);
        writeBundle(restrictions, serializer);
        serializer.endTag(null, TAG_RESTRICTIONS);
        serializer.endDocument();
        restrictionsFile.finishWrite(fos);
    } catch (Exception e) {
        restrictionsFile.failWrite(fos);
        Slog.e(LOG_TAG, "Error writing application restrictions list", e);
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) ErrnoException(android.system.ErrnoException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 85 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project platform_frameworks_base by android.

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, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.startTag(null, "policies");
        if (policy.mRestrictionsProvider != null) {
            out.attribute(null, ATTR_PERMISSION_PROVIDER, policy.mRestrictionsProvider.flattenToString());
        }
        if (policy.mUserSetupComplete) {
            out.attribute(null, ATTR_SETUP_COMPLETE, Boolean.toString(true));
        }
        if (policy.mPaired) {
            out.attribute(null, ATTR_DEVICE_PAIRED, Boolean.toString(true));
        }
        if (policy.mDeviceProvisioningConfigApplied) {
            out.attribute(null, ATTR_DEVICE_PROVISIONING_CONFIG_APPLIED, Boolean.toString(true));
        }
        if (policy.mUserProvisioningState != DevicePolicyManager.STATE_USER_UNMANAGED) {
            out.attribute(null, ATTR_PROVISIONING_STATE, Integer.toString(policy.mUserProvisioningState));
        }
        if (policy.mPermissionPolicy != DevicePolicyManager.PERMISSION_POLICY_PROMPT) {
            out.attribute(null, ATTR_PERMISSION_POLICY, Integer.toString(policy.mPermissionPolicy));
        }
        if (policy.mDelegatedCertInstallerPackage != null) {
            out.attribute(null, ATTR_DELEGATED_CERT_INSTALLER, policy.mDelegatedCertInstallerPackage);
        }
        if (policy.mApplicationRestrictionsManagingPackage != null) {
            out.attribute(null, ATTR_APPLICATION_RESTRICTIONS_MANAGER, policy.mApplicationRestrictionsManagingPackage);
        }
        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");
        }
        for (int i = 0; i < policy.mAcceptedCaCertificates.size(); i++) {
            out.startTag(null, TAG_ACCEPTED_CA_CERTIFICATES);
            out.attribute(null, ATTR_NAME, policy.mAcceptedCaCertificates.valueAt(i));
            out.endTag(null, TAG_ACCEPTED_CA_CERTIFICATES);
        }
        for (int i = 0; i < policy.mLockTaskPackages.size(); i++) {
            String component = policy.mLockTaskPackages.get(i);
            out.startTag(null, TAG_LOCK_TASK_COMPONENTS);
            out.attribute(null, "name", component);
            out.endTag(null, TAG_LOCK_TASK_COMPONENTS);
        }
        if (policy.mStatusBarDisabled) {
            out.startTag(null, TAG_STATUS_BAR);
            out.attribute(null, ATTR_DISABLED, Boolean.toString(policy.mStatusBarDisabled));
            out.endTag(null, TAG_STATUS_BAR);
        }
        if (policy.doNotAskCredentialsOnBoot) {
            out.startTag(null, DO_NOT_ASK_CREDENTIALS_ON_BOOT_XML);
            out.endTag(null, DO_NOT_ASK_CREDENTIALS_ON_BOOT_XML);
        }
        for (String id : policy.mAffiliationIds) {
            out.startTag(null, TAG_AFFILIATION_ID);
            out.attribute(null, "id", id);
            out.endTag(null, TAG_AFFILIATION_ID);
        }
        if (policy.mAdminBroadcastPending) {
            out.startTag(null, TAG_ADMIN_BROADCAST_PENDING);
            out.attribute(null, ATTR_VALUE, Boolean.toString(policy.mAdminBroadcastPending));
            out.endTag(null, TAG_ADMIN_BROADCAST_PENDING);
        }
        if (policy.mInitBundle != null) {
            out.startTag(null, TAG_INITIALIZATION_BUNDLE);
            policy.mInitBundle.saveToXml(out);
            out.endTag(null, TAG_INITIALIZATION_BUNDLE);
        }
        out.endTag(null, "policies");
        out.endDocument();
        stream.flush();
        FileUtils.sync(stream);
        stream.close();
        journal.commit();
        sendChangedNotification(userHandle);
    } catch (XmlPullParserException | IOException e) {
        Slog.w(LOG_TAG, "failed writing file", 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) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) ParcelableString(com.android.internal.util.ParcelableString) IOException(java.io.IOException) 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