Search in sources :

Example 21 with JournaledFile

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

the class WallpaperManagerService method loadSettingsLocked.

private void loadSettingsLocked(int userId, boolean keepDimensionHints) {
    if (DEBUG)
        Slog.v(TAG, "loadSettingsLocked");
    JournaledFile journal = makeJournaledFile(userId);
    FileInputStream stream = null;
    File file = journal.chooseForRead();
    if (!file.exists()) {
        // This should only happen one time, when upgrading from a legacy system
        migrateFromOld();
    }
    WallpaperData wallpaper = mWallpaperMap.get(userId);
    if (wallpaper == null) {
        wallpaper = new WallpaperData(userId, WALLPAPER, WALLPAPER_CROP);
        wallpaper.allowBackup = true;
        mWallpaperMap.put(userId, wallpaper);
        if (!wallpaper.cropExists()) {
            generateCrop(wallpaper);
        }
    }
    boolean success = false;
    try {
        stream = new FileInputStream(file);
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(stream, StandardCharsets.UTF_8.name());
        int type;
        do {
            type = parser.next();
            if (type == XmlPullParser.START_TAG) {
                String tag = parser.getName();
                if ("wp".equals(tag)) {
                    // Common to system + lock wallpapers
                    parseWallpaperAttributes(parser, wallpaper, keepDimensionHints);
                    // A system wallpaper might also be a live wallpaper
                    String comp = parser.getAttributeValue(null, "component");
                    wallpaper.nextWallpaperComponent = comp != null ? ComponentName.unflattenFromString(comp) : null;
                    if (wallpaper.nextWallpaperComponent == null || "android".equals(wallpaper.nextWallpaperComponent.getPackageName())) {
                        wallpaper.nextWallpaperComponent = mImageWallpaper;
                    }
                    if (DEBUG) {
                        Slog.v(TAG, "mWidth:" + wallpaper.width);
                        Slog.v(TAG, "mHeight:" + wallpaper.height);
                        Slog.v(TAG, "cropRect:" + wallpaper.cropHint);
                        Slog.v(TAG, "mName:" + wallpaper.name);
                        Slog.v(TAG, "mNextWallpaperComponent:" + wallpaper.nextWallpaperComponent);
                    }
                } else if ("kwp".equals(tag)) {
                    // keyguard-specific wallpaper for this user
                    WallpaperData lockWallpaper = mLockWallpaperMap.get(userId);
                    if (lockWallpaper == null) {
                        lockWallpaper = new WallpaperData(userId, WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP);
                        mLockWallpaperMap.put(userId, lockWallpaper);
                    }
                    parseWallpaperAttributes(parser, lockWallpaper, false);
                }
            }
        } while (type != XmlPullParser.END_DOCUMENT);
        success = true;
    } catch (FileNotFoundException e) {
        Slog.w(TAG, "no current wallpaper -- first boot?");
    } catch (NullPointerException e) {
        Slog.w(TAG, "failed parsing " + file + " " + e);
    } catch (NumberFormatException e) {
        Slog.w(TAG, "failed parsing " + file + " " + e);
    } catch (XmlPullParserException e) {
        Slog.w(TAG, "failed parsing " + file + " " + e);
    } catch (IOException e) {
        Slog.w(TAG, "failed parsing " + file + " " + e);
    } catch (IndexOutOfBoundsException e) {
        Slog.w(TAG, "failed parsing " + file + " " + e);
    }
    IoUtils.closeQuietly(stream);
    if (!success) {
        wallpaper.width = -1;
        wallpaper.height = -1;
        wallpaper.cropHint.set(0, 0, 0, 0);
        wallpaper.padding.set(0, 0, 0, 0);
        wallpaper.name = "";
        mLockWallpaperMap.remove(userId);
    } else {
        if (wallpaper.wallpaperId <= 0) {
            wallpaper.wallpaperId = makeWallpaperIdLocked();
            if (DEBUG) {
                Slog.w(TAG, "Didn't set wallpaper id in loadSettingsLocked(" + userId + "); now " + wallpaper.wallpaperId);
            }
        }
    }
    ensureSaneWallpaperData(wallpaper);
    WallpaperData lockWallpaper = mLockWallpaperMap.get(userId);
    if (lockWallpaper != null) {
        ensureSaneWallpaperData(lockWallpaper);
    }
}
Also used : JournaledFile(com.android.internal.util.JournaledFile) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Point(android.graphics.Point) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) File(java.io.File) JournaledFile(com.android.internal.util.JournaledFile)

Example 22 with JournaledFile

use of com.android.internal.util.JournaledFile in project android_frameworks_base by crdroidandroid.

the class WallpaperManagerService method loadSettingsLocked.

private void loadSettingsLocked(int userId, boolean keepDimensionHints) {
    if (DEBUG)
        Slog.v(TAG, "loadSettingsLocked");
    JournaledFile journal = makeJournaledFile(userId);
    FileInputStream stream = null;
    File file = journal.chooseForRead();
    if (!file.exists()) {
        // This should only happen one time, when upgrading from a legacy system
        migrateFromOld();
    }
    WallpaperData wallpaper = mWallpaperMap.get(userId);
    if (wallpaper == null) {
        wallpaper = new WallpaperData(userId, WALLPAPER, WALLPAPER_CROP);
        wallpaper.allowBackup = true;
        mWallpaperMap.put(userId, wallpaper);
        if (!wallpaper.cropExists()) {
            generateCrop(wallpaper);
        }
    }
    boolean success = false;
    try {
        stream = new FileInputStream(file);
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(stream, StandardCharsets.UTF_8.name());
        int type;
        do {
            type = parser.next();
            if (type == XmlPullParser.START_TAG) {
                String tag = parser.getName();
                if ("wp".equals(tag)) {
                    // Common to system + lock wallpapers
                    parseWallpaperAttributes(parser, wallpaper, keepDimensionHints);
                    // A system wallpaper might also be a live wallpaper
                    String comp = parser.getAttributeValue(null, "component");
                    wallpaper.nextWallpaperComponent = comp != null ? ComponentName.unflattenFromString(comp) : null;
                    if (wallpaper.nextWallpaperComponent == null || "android".equals(wallpaper.nextWallpaperComponent.getPackageName())) {
                        wallpaper.nextWallpaperComponent = mImageWallpaper;
                    }
                    if (DEBUG) {
                        Slog.v(TAG, "mWidth:" + wallpaper.width);
                        Slog.v(TAG, "mHeight:" + wallpaper.height);
                        Slog.v(TAG, "cropRect:" + wallpaper.cropHint);
                        Slog.v(TAG, "mName:" + wallpaper.name);
                        Slog.v(TAG, "mNextWallpaperComponent:" + wallpaper.nextWallpaperComponent);
                    }
                } else if ("kwp".equals(tag)) {
                    // keyguard-specific wallpaper for this user
                    WallpaperData lockWallpaper = mLockWallpaperMap.get(userId);
                    if (lockWallpaper == null) {
                        lockWallpaper = new WallpaperData(userId, WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP);
                        mLockWallpaperMap.put(userId, lockWallpaper);
                    }
                    parseWallpaperAttributes(parser, lockWallpaper, false);
                }
            }
        } while (type != XmlPullParser.END_DOCUMENT);
        success = true;
    } catch (FileNotFoundException e) {
        Slog.w(TAG, "no current wallpaper -- first boot?");
    } catch (NullPointerException e) {
        Slog.w(TAG, "failed parsing " + file + " " + e);
    } catch (NumberFormatException e) {
        Slog.w(TAG, "failed parsing " + file + " " + e);
    } catch (XmlPullParserException e) {
        Slog.w(TAG, "failed parsing " + file + " " + e);
    } catch (IOException e) {
        Slog.w(TAG, "failed parsing " + file + " " + e);
    } catch (IndexOutOfBoundsException e) {
        Slog.w(TAG, "failed parsing " + file + " " + e);
    }
    IoUtils.closeQuietly(stream);
    if (!success) {
        wallpaper.width = -1;
        wallpaper.height = -1;
        wallpaper.cropHint.set(0, 0, 0, 0);
        wallpaper.padding.set(0, 0, 0, 0);
        wallpaper.name = "";
        mLockWallpaperMap.remove(userId);
    } else {
        if (wallpaper.wallpaperId <= 0) {
            wallpaper.wallpaperId = makeWallpaperIdLocked();
            if (DEBUG) {
                Slog.w(TAG, "Didn't set wallpaper id in loadSettingsLocked(" + userId + "); now " + wallpaper.wallpaperId);
            }
        }
    }
    ensureSaneWallpaperData(wallpaper);
    WallpaperData lockWallpaper = mLockWallpaperMap.get(userId);
    if (lockWallpaper != null) {
        ensureSaneWallpaperData(lockWallpaper);
    }
}
Also used : JournaledFile(com.android.internal.util.JournaledFile) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Point(android.graphics.Point) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) File(java.io.File) JournaledFile(com.android.internal.util.JournaledFile)

Example 23 with JournaledFile

use of com.android.internal.util.JournaledFile in project android_frameworks_base by crdroidandroid.

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)

Aggregations

JournaledFile (com.android.internal.util.JournaledFile)23 IOException (java.io.IOException)23 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)17 File (java.io.File)14 FileOutputStream (java.io.FileOutputStream)14 FileNotFoundException (java.io.FileNotFoundException)13 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)10 XmlSerializer (org.xmlpull.v1.XmlSerializer)10 FileInputStream (java.io.FileInputStream)9 XmlPullParser (org.xmlpull.v1.XmlPullParser)9 ParcelableString (com.android.internal.util.ParcelableString)6 ApplicationInfo (android.content.pm.ApplicationInfo)5 AtomicFile (android.util.AtomicFile)5 BufferedOutputStream (java.io.BufferedOutputStream)5 DeviceAdminInfo (android.app.admin.DeviceAdminInfo)4 UserInfo (android.content.pm.UserInfo)4 Point (android.graphics.Point)4 BufferedWriter (java.io.BufferedWriter)4 OutputStreamWriter (java.io.OutputStreamWriter)4 InstallerException (com.android.internal.os.InstallerConnection.InstallerException)3