Search in sources :

Example 26 with FastXmlSerializer

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

the class UserManagerService method writeUserListLocked.

/*
     * Writes the user list file in this format:
     *
     * <users nextSerialNumber="3">
     *   <user id="0"></user>
     *   <user id="2"></user>
     * </users>
     */
private void writeUserListLocked() {
    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, "utf-8");
        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));
        for (int i = 0; i < mUsers.size(); i++) {
            UserInfo user = mUsers.valueAt(i);
            serializer.startTag(null, TAG_USER);
            serializer.attribute(null, ATTR_ID, Integer.toString(user.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) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 27 with FastXmlSerializer

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

the class DisplaySettings method writeSettingsLocked.

public void writeSettingsLocked() {
    FileOutputStream stream;
    try {
        stream = mFile.startWrite();
    } catch (IOException e) {
        Slog.w(TAG, "Failed to write display settings: " + e);
        return;
    }
    try {
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(stream, "utf-8");
        out.startDocument(null, true);
        out.startTag(null, "display-settings");
        for (Entry entry : mEntries.values()) {
            out.startTag(null, "display");
            out.attribute(null, "name", entry.name);
            if (entry.overscanLeft != 0) {
                out.attribute(null, "overscanLeft", Integer.toString(entry.overscanLeft));
            }
            if (entry.overscanTop != 0) {
                out.attribute(null, "overscanTop", Integer.toString(entry.overscanTop));
            }
            if (entry.overscanRight != 0) {
                out.attribute(null, "overscanRight", Integer.toString(entry.overscanRight));
            }
            if (entry.overscanBottom != 0) {
                out.attribute(null, "overscanBottom", Integer.toString(entry.overscanBottom));
            }
            out.endTag(null, "display");
        }
        out.endTag(null, "display-settings");
        out.endDocument();
        mFile.finishWrite(stream);
    } catch (IOException e) {
        Slog.w(TAG, "Failed to write display settings, restoring backup.", e);
        mFile.failWrite(stream);
    }
}
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 28 with FastXmlSerializer

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

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, "utf-8");
        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 29 with FastXmlSerializer

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

the class RegisteredServicesCache method writePersistentServicesLocked.

/**
     * Write all sync status to the sync status file.
     */
private void writePersistentServicesLocked() {
    if (mSerializerAndParser == null) {
        return;
    }
    FileOutputStream fos = null;
    try {
        fos = mPersistentServicesFile.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, "services");
        for (int i = 0; i < mUserServices.size(); i++) {
            final UserServices<V> user = mUserServices.valueAt(i);
            for (Map.Entry<V, Integer> service : user.persistentServices.entrySet()) {
                out.startTag(null, "service");
                out.attribute(null, "uid", Integer.toString(service.getValue()));
                mSerializerAndParser.writeAsXml(service.getKey(), out);
                out.endTag(null, "service");
            }
        }
        out.endTag(null, "services");
        out.endDocument();
        mPersistentServicesFile.finishWrite(fos);
    } catch (java.io.IOException e1) {
        Log.w(TAG, "Error writing accounts", e1);
        if (fos != null) {
            mPersistentServicesFile.failWrite(fos);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Map(java.util.Map) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 30 with FastXmlSerializer

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

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);
        }
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) CompatibilityInfo(android.content.res.CompatibilityInfo) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) IPackageManager(android.content.pm.IPackageManager) FileOutputStream(java.io.FileOutputStream) RemoteException(android.os.RemoteException) 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