diff options
author | d34d <clark@cyngn.com> | 2016-04-12 18:35:40 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2016-04-13 14:24:45 -0700 |
commit | bf2ddee45c9063780e095e6a732a51c8bab2df30 (patch) | |
tree | 2bcefedac7a36016a3015a8b37a1566eb8ac3bf9 /core | |
parent | d6f2d2c410963b8566a7d043a6c11eae91a2230d (diff) | |
download | frameworks_base-bf2ddee45c9063780e095e6a732a51c8bab2df30.zip frameworks_base-bf2ddee45c9063780e095e6a732a51c8bab2df30.tar.gz frameworks_base-bf2ddee45c9063780e095e6a732a51c8bab2df30.tar.bz2 |
Themes: Restore original value if getValue fails
Add a catch all around the guts of IconCustomizer.getValue and
restore the original outValue before returning if an exception
does occur, with some log output for our own sanity.
Change-Id: I021760cd5dc07d9cfbbced09c514b86fb997f7d0
TICKET: CYNGNOS-2432
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/app/IconPackHelper.java | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/core/java/android/app/IconPackHelper.java b/core/java/android/app/IconPackHelper.java index 80fb401..9c71ddd 100644 --- a/core/java/android/app/IconPackHelper.java +++ b/core/java/android/app/IconPackHelper.java @@ -633,33 +633,42 @@ public class IconPackHelper { } TypedValue tempValue = new TypedValue(); tempValue.setTo(outValue); - outValue.assetCookie = COMPOSED_ICON_COOKIE; - outValue.data = resId & (COMPOSED_ICON_COOKIE << 24 | 0x00ffffff); - outValue.string = getCachedIconPath(pkgName, resId, outValue.density); - int hashCode = outValue.string.hashCode() & 0x7fffffff; - int defaultSwatchColor = 0; - - if (!(new File(outValue.string.toString()).exists())) { - // compose the icon and cache it - int back = 0; - if (iconInfo.swatchType != ComposedIconInfo.SwatchType.None) { - back = iconInfo.iconPaletteBack; - if (iconInfo.defaultSwatchColors.length > 0) { - defaultSwatchColor =iconInfo.defaultSwatchColors[ - hashCode % iconInfo.defaultSwatchColors.length]; + // Catch all exceptions and restore outValue to tempValue if one occurs + try { + outValue.assetCookie = COMPOSED_ICON_COOKIE; + outValue.data = resId & (COMPOSED_ICON_COOKIE << 24 | 0x00ffffff); + outValue.string = getCachedIconPath(pkgName, resId, outValue.density); + int hashCode = outValue.string.hashCode() & 0x7fffffff; + int defaultSwatchColor = 0; + + if (!(new File(outValue.string.toString()).exists())) { + // compose the icon and cache it + int back = 0; + if (iconInfo.swatchType != ComposedIconInfo.SwatchType.None) { + back = iconInfo.iconPaletteBack; + if (iconInfo.defaultSwatchColors.length > 0) { + defaultSwatchColor = iconInfo.defaultSwatchColors[ + hashCode % iconInfo.defaultSwatchColors.length]; + } + } else if (iconInfo.iconBacks != null && iconInfo.iconBacks.length > 0) { + back = iconInfo.iconBacks[hashCode % iconInfo.iconBacks.length]; + } + if (DEBUG) { + Log.d(TAG, "Composing icon for " + pkgName); + } + Bitmap bmp = createIconBitmap(baseIcon, res, back, defaultSwatchColor, + iconInfo); + if (!cacheComposedIcon(bmp, + getCachedIconName(pkgName, resId, outValue.density))) { + Log.w(TAG, "Unable to cache icon " + outValue.string); + // restore the original TypedValue + outValue.setTo(tempValue); } - } else if (iconInfo.iconBacks != null && iconInfo.iconBacks.length > 0) { - back = iconInfo.iconBacks[hashCode % iconInfo.iconBacks.length]; - } - if (DEBUG) { - Log.d(TAG, "Composing icon for " + pkgName); - } - Bitmap bmp = createIconBitmap(baseIcon, res, back, defaultSwatchColor, iconInfo); - if (!cacheComposedIcon(bmp, getCachedIconName(pkgName, resId, outValue.density))) { - Log.w(TAG, "Unable to cache icon " + outValue.string); - // restore the original TypedValue - outValue.setTo(tempValue); } + } catch (Exception e) { + // catch all, restore the original value and log it + outValue.setTo(tempValue); + Log.w(TAG, "getValue failed for " + outValue.string, e); } } |