Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf2ddee4 authored by d34d's avatar d34d Committed by Gerrit Code Review
Browse files

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
parent d6f2d2c4
Loading
Loading
Loading
Loading
+34 −25
Original line number Diff line number Diff line
@@ -633,6 +633,8 @@ public class IconPackHelper {
            }
            TypedValue tempValue = new TypedValue();
            tempValue.setTo(outValue);
            // 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);
@@ -654,13 +656,20 @@ public class IconPackHelper {
                    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))) {
                    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);
            }
        }

        private static Bitmap createIconBitmap(Drawable icon, Resources res, int iconBack,