Search in sources :

Example 16 with FastXmlSerializer

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

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, StandardCharsets.UTF_8.name());
        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 17 with FastXmlSerializer

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

the class WallpaperManagerService method saveSettingsLocked.

private void saveSettingsLocked(int userId) {
    JournaledFile journal = makeJournaledFile(userId);
    FileOutputStream fstream = null;
    BufferedOutputStream stream = null;
    try {
        XmlSerializer out = new FastXmlSerializer();
        fstream = new FileOutputStream(journal.chooseForWrite(), false);
        stream = new BufferedOutputStream(fstream);
        out.setOutput(stream, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        WallpaperData wallpaper;
        wallpaper = mWallpaperMap.get(userId);
        if (wallpaper != null) {
            writeWallpaperAttributes(out, "wp", wallpaper);
        }
        wallpaper = mLockWallpaperMap.get(userId);
        if (wallpaper != null) {
            writeWallpaperAttributes(out, "kwp", wallpaper);
        }
        out.endDocument();
        // also flushes fstream
        stream.flush();
        FileUtils.sync(fstream);
        // also closes fstream
        stream.close();
        journal.commit();
    } catch (IOException e) {
        IoUtils.closeQuietly(stream);
        journal.rollback();
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) JournaledFile(com.android.internal.util.JournaledFile) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 18 with FastXmlSerializer

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

the class AppOpsService method writeState.

void writeState() {
    synchronized (mFile) {
        List<AppOpsManager.PackageOps> allOps = getPackagesForOps(null);
        FileOutputStream stream;
        try {
            stream = mFile.startWrite();
        } catch (IOException e) {
            Slog.w(TAG, "Failed to write state: " + e);
            return;
        }
        try {
            XmlSerializer out = new FastXmlSerializer();
            out.setOutput(stream, "utf-8");
            out.startDocument(null, true);
            out.startTag(null, "app-ops");
            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()));
                    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()));
                        if (op.getMode() != AppOpsManager.MODE_ALLOWED) {
                            out.attribute(null, "m", Integer.toString(op.getMode()));
                        }
                        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));
                        }
                        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) FileOutputStream(java.io.FileOutputStream) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 19 with FastXmlSerializer

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

the class AppWidgetServiceImpl method writeStateToFileLocked.

boolean writeStateToFileLocked(FileOutputStream stream) {
    int N;
    try {
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(stream, "utf-8");
        out.startDocument(null, true);
        out.startTag(null, "gs");
        int providerIndex = 0;
        N = mInstalledProviders.size();
        for (int i = 0; i < N; i++) {
            Provider p = mInstalledProviders.get(i);
            if (p.instances.size() > 0) {
                out.startTag(null, "p");
                out.attribute(null, "pkg", p.info.provider.getPackageName());
                out.attribute(null, "cl", p.info.provider.getClassName());
                out.endTag(null, "p");
                p.tag = providerIndex;
                providerIndex++;
            }
        }
        N = mHosts.size();
        for (int i = 0; i < N; i++) {
            Host host = mHosts.get(i);
            out.startTag(null, "h");
            out.attribute(null, "pkg", host.packageName);
            out.attribute(null, "id", Integer.toHexString(host.hostId));
            out.endTag(null, "h");
            host.tag = i;
        }
        N = mAppWidgetIds.size();
        for (int i = 0; i < N; i++) {
            AppWidgetId id = mAppWidgetIds.get(i);
            out.startTag(null, "g");
            out.attribute(null, "id", Integer.toHexString(id.appWidgetId));
            out.attribute(null, "h", Integer.toHexString(id.host.tag));
            if (id.provider != null) {
                out.attribute(null, "p", Integer.toHexString(id.provider.tag));
            }
            if (id.options != null) {
                out.attribute(null, "min_width", Integer.toHexString(id.options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)));
                out.attribute(null, "min_height", Integer.toHexString(id.options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT)));
                out.attribute(null, "max_width", Integer.toHexString(id.options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH)));
                out.attribute(null, "max_height", Integer.toHexString(id.options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT)));
                out.attribute(null, "host_category", Integer.toHexString(id.options.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY)));
            }
            out.endTag(null, "g");
        }
        Iterator<String> it = mPackagesWithBindWidgetPermission.iterator();
        while (it.hasNext()) {
            out.startTag(null, "b");
            out.attribute(null, "packageName", it.next());
            out.endTag(null, "b");
        }
        out.endTag(null, "gs");
        out.endDocument();
        return true;
    } catch (IOException e) {
        Slog.w(TAG, "Failed to write state: " + e);
        return false;
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) IAppWidgetHost(com.android.internal.appwidget.IAppWidgetHost) IOException(java.io.IOException) Point(android.graphics.Point) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 20 with FastXmlSerializer

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

the class WallpaperManagerService method saveSettingsLocked.

private void saveSettingsLocked(WallpaperData wallpaper) {
    JournaledFile journal = makeJournaledFile(wallpaper.userId);
    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, "wp");
        out.attribute(null, "width", Integer.toString(wallpaper.width));
        out.attribute(null, "height", Integer.toString(wallpaper.height));
        out.attribute(null, "name", wallpaper.name);
        if (wallpaper.wallpaperComponent != null && !wallpaper.wallpaperComponent.equals(IMAGE_WALLPAPER)) {
            out.attribute(null, "component", wallpaper.wallpaperComponent.flattenToShortString());
        }
        out.endTag(null, "wp");
        out.endDocument();
        stream.close();
        journal.commit();
    } 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)

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