diff options
author | tobitege <tobiasteschner@googlemail.com> | 2015-05-17 15:38:00 +0200 |
---|---|---|
committer | Richard MacGregor <rmacgregor@cyngn.com> | 2015-05-19 16:40:03 +0000 |
commit | 4d4c54e33e1f081bb762ad18b6f411fe65036d35 (patch) | |
tree | ee9df701abf2b88f4b8acb1e0c3f88528b6ebcfe | |
parent | a8594f9008f4bcfa7e78efd301f65b748213b307 (diff) | |
download | android_packages_providers_ThemesProvider-4d4c54e33e1f081bb762ad18b6f411fe65036d35.tar.gz android_packages_providers_ThemesProvider-4d4c54e33e1f081bb762ad18b6f411fe65036d35.tar.bz2 android_packages_providers_ThemesProvider-4d4c54e33e1f081bb762ad18b6f411fe65036d35.zip |
Fix exception on themes without lockscreen images
Based on exceptions in logcat like this:
Unable to save preview com.cerj.theme.blakazure/lock_wallpaper_preview
PreviewGenerationService( 5413):
java.lang.NullPointerException: Attempt to get length of null array
at java.io.OutputStream.write(OutputStream.java:82)
Added null checks to insertPreviewItemsIntoDb() for wallpaperItems props.
saveCompressedImage() now immediately returns on null image.
Change-Id: I63709a37780dfeabae14f8c1c34c88f8753728f9
-rw-r--r-- | src/org/cyanogenmod/themes/provider/PreviewGenerationService.java | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java b/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java index e732c45..6d42c04 100644 --- a/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java +++ b/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java @@ -157,8 +157,7 @@ public class PreviewGenerationService extends IntentService { } private void insertPreviewItemsIntoDb(String pkgName, SystemUiItems items, IconItems icons, - WallpaperItems wallpaperItems, StyleItems styleItems, - Bitmap bootAnim) { + WallpaperItems wallpaperItems, StyleItems styleItems, Bitmap bootAnim) { String[] projection = {ThemesColumns._ID}; String selection = ThemesColumns.PKG_NAME + "=?"; String[] selectionArgs = { pkgName }; @@ -268,27 +267,34 @@ public class PreviewGenerationService extends IntentService { themeValues.add(values); } if (wallpaperItems != null) { - path = compressAndSaveJpg(wallpaperItems.wpPreview, filesDir, pkgName, - PreviewColumns.WALLPAPER_PREVIEW); - values = createPreviewEntryString(id, PreviewColumns.WALLPAPER_PREVIEW, path); - themeValues.add(values); - - path = compressAndSavePng(wallpaperItems.wpThumbnail, filesDir, pkgName, - PreviewColumns.WALLPAPER_THUMBNAIL); - values = createPreviewEntryString(id, PreviewColumns.WALLPAPER_THUMBNAIL, path); - themeValues.add(values); - - path = compressAndSaveJpg(wallpaperItems.lsPreview, filesDir, pkgName, - PreviewColumns.LOCK_WALLPAPER_PREVIEW); - values = createPreviewEntryString(id, PreviewColumns.LOCK_WALLPAPER_PREVIEW, - path); - themeValues.add(values); - - path = compressAndSavePng(wallpaperItems.lsThumbnail, filesDir, pkgName, - PreviewColumns.LOCK_WALLPAPER_THUMBNAIL); - values = createPreviewEntryString(id, PreviewColumns.LOCK_WALLPAPER_THUMBNAIL, - path); - themeValues.add(values); + if (wallpaperItems.wpPreview != null) { + path = compressAndSaveJpg(wallpaperItems.wpPreview, filesDir, pkgName, + PreviewColumns.WALLPAPER_PREVIEW); + values = createPreviewEntryString(id, + PreviewColumns.WALLPAPER_PREVIEW, path); + themeValues.add(values); + } + if (wallpaperItems.wpThumbnail != null) { + path = compressAndSavePng(wallpaperItems.wpThumbnail, filesDir, pkgName, + PreviewColumns.WALLPAPER_THUMBNAIL); + values = createPreviewEntryString(id, + PreviewColumns.WALLPAPER_THUMBNAIL, path); + themeValues.add(values); + } + if (wallpaperItems.lsPreview != null) { + path = compressAndSaveJpg(wallpaperItems.lsPreview, filesDir, pkgName, + PreviewColumns.LOCK_WALLPAPER_PREVIEW); + values = createPreviewEntryString(id, + PreviewColumns.LOCK_WALLPAPER_PREVIEW, path); + themeValues.add(values); + } + if (wallpaperItems.lsThumbnail != null) { + path = compressAndSavePng(wallpaperItems.lsThumbnail, filesDir, pkgName, + PreviewColumns.LOCK_WALLPAPER_THUMBNAIL); + values = createPreviewEntryString(id, + PreviewColumns.LOCK_WALLPAPER_THUMBNAIL, path); + themeValues.add(values); + } } if (styleItems != null) { path = compressAndSavePng(styleItems.thumbnail, filesDir, pkgName, @@ -343,13 +349,13 @@ public class PreviewGenerationService extends IntentService { } private static String compressAndSavePng(Bitmap bmp, String baseDir, String pkgName, - String fileName) { + String fileName) { byte[] image = getBitmapBlobPng(bmp); return saveCompressedImage(image, baseDir, pkgName, fileName); } private static String compressAndSaveJpg(Bitmap bmp, String baseDir, String pkgName, - String fileName) { + String fileName) { byte[] image = getBitmapBlobJpg(bmp); return saveCompressedImage(image, baseDir, pkgName, fileName); } @@ -370,7 +376,8 @@ public class PreviewGenerationService extends IntentService { } private static String saveCompressedImage(byte[] image, String baseDir, String pkgName, - String fileName) { + String fileName) { + if (image == null) return null; // Create relevant directories String previewsDir = baseDir + File.separator + PREVIEWS_DIR; String pkgDir = previewsDir + File.separator + pkgName; |