Search in sources :

Example 41 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer in project XobotOS by xamarin.

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 (Map.Entry<V, Integer> service : mPersistentServices.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) HashMap(java.util.HashMap) Map(java.util.Map) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 42 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by AOSPA.

the class AccessibilityNodeInfoDumper method dumpWindowToFile.

/**
     * Using {@link AccessibilityNodeInfo} this method will walk the layout hierarchy
     * and generates an xml dump to the location specified by <code>dumpFile</code>
     * @param root The root accessibility node.
     * @param dumpFile The file to dump to.
     * @param rotation The rotaion of current display
     * @param width The pixel width of current display
     * @param height The pixel height of current display
     */
public static void dumpWindowToFile(AccessibilityNodeInfo root, File dumpFile, int rotation, int width, int height) {
    if (root == null) {
        return;
    }
    final long startTime = SystemClock.uptimeMillis();
    try {
        FileWriter writer = new FileWriter(dumpFile);
        XmlSerializer serializer = Xml.newSerializer();
        StringWriter stringWriter = new StringWriter();
        serializer.setOutput(stringWriter);
        serializer.startDocument("UTF-8", true);
        serializer.startTag("", "hierarchy");
        serializer.attribute("", "rotation", Integer.toString(rotation));
        dumpNodeRec(root, serializer, 0, width, height);
        serializer.endTag("", "hierarchy");
        serializer.endDocument();
        writer.write(stringWriter.toString());
        writer.close();
    } catch (IOException e) {
        Log.e(LOGTAG, "failed to dump window to file", e);
    }
    final long endTime = SystemClock.uptimeMillis();
    Log.w(LOGTAG, "Fetch time: " + (endTime - startTime) + "ms");
}
Also used : StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 43 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by DirtyUnicorns.

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)

Example 44 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by DirtyUnicorns.

the class SyncStorageEngine method writeAccountInfoLocked.

/**
     * Write all account information to the account file.
     */
private void writeAccountInfoLocked() {
    if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
        Slog.v(TAG_FILE, "Writing new " + mAccountInfoFile.getBaseFile());
    }
    FileOutputStream fos = null;
    try {
        fos = mAccountInfoFile.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, "accounts");
        out.attribute(null, "version", Integer.toString(ACCOUNTS_VERSION));
        out.attribute(null, XML_ATTR_NEXT_AUTHORITY_ID, Integer.toString(mNextAuthorityId));
        out.attribute(null, XML_ATTR_SYNC_RANDOM_OFFSET, Integer.toString(mSyncRandomOffset));
        // Write the Sync Automatically flags for each user
        final int M = mMasterSyncAutomatically.size();
        for (int m = 0; m < M; m++) {
            int userId = mMasterSyncAutomatically.keyAt(m);
            Boolean listen = mMasterSyncAutomatically.valueAt(m);
            out.startTag(null, XML_TAG_LISTEN_FOR_TICKLES);
            out.attribute(null, XML_ATTR_USER, Integer.toString(userId));
            out.attribute(null, XML_ATTR_ENABLED, Boolean.toString(listen));
            out.endTag(null, XML_TAG_LISTEN_FOR_TICKLES);
        }
        final int N = mAuthorities.size();
        for (int i = 0; i < N; i++) {
            AuthorityInfo authority = mAuthorities.valueAt(i);
            EndPoint info = authority.target;
            out.startTag(null, "authority");
            out.attribute(null, "id", Integer.toString(authority.ident));
            out.attribute(null, XML_ATTR_USER, Integer.toString(info.userId));
            out.attribute(null, XML_ATTR_ENABLED, Boolean.toString(authority.enabled));
            out.attribute(null, "account", info.account.name);
            out.attribute(null, "type", info.account.type);
            out.attribute(null, "authority", info.provider);
            out.attribute(null, "syncable", Integer.toString(authority.syncable));
            out.endTag(null, "authority");
        }
        out.endTag(null, "accounts");
        out.endDocument();
        mAccountInfoFile.finishWrite(fos);
    } catch (java.io.IOException e1) {
        Slog.w(TAG, "Error writing accounts", e1);
        if (fos != null) {
            mAccountInfoFile.failWrite(fos);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 45 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer in project android_frameworks_base by DirtyUnicorns.

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)

Aggregations

XmlSerializer (org.xmlpull.v1.XmlSerializer)307 IOException (java.io.IOException)171 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)157 FileOutputStream (java.io.FileOutputStream)156 BufferedOutputStream (java.io.BufferedOutputStream)61 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)56 ByteArrayOutputStream (java.io.ByteArrayOutputStream)40 AtomicFile (android.util.AtomicFile)39 File (java.io.File)32 FileNotFoundException (java.io.FileNotFoundException)32 StringWriter (java.io.StringWriter)30 RemoteException (android.os.RemoteException)29 Map (java.util.Map)26 ErrnoException (android.system.ErrnoException)20 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)15 JournaledFile (com.android.internal.util.JournaledFile)15 HashMap (java.util.HashMap)14 FileWriter (java.io.FileWriter)12 UserInfo (android.content.pm.UserInfo)9 SendIntentException (android.content.IntentSender.SendIntentException)8