Buggy code:
private static final HashSet < String > sInvalidPackages = new HashSet < String > ( ) ; private final WidgetPreviewLoader . BitmapCache mCachedShortcutPreviewBitmap = new WidgetPreviewLoader . BitmapCache ( ) ; private final WidgetPreviewLoader . PaintCache mCachedShortcutPreviewPaint = new WidgetPreviewLoader . PaintCache ( ) ; private final WidgetPreviewLoader . CanvasCache mCachedShortcutPreviewCanvas = new WidgetPreviewLoader . CanvasCache ( ) ; private final WidgetPreviewLoader . CanvasCache mCachedAppWidgetPreviewCanvas = new WidgetPreviewLoader . CanvasCache ( ) ; private final WidgetPreviewLoader . RectCache mCachedAppWidgetPreviewSrcRect = new WidgetPreviewLoader . RectCache ( ) ; private final WidgetPreviewLoader . RectCache mCachedAppWidgetPreviewDestRect = new WidgetPreviewLoader . RectCache ( ) ; private final WidgetPreviewLoader . PaintCache mCachedAppWidgetPreviewPaint = new WidgetPreviewLoader . PaintCache ( ) ; private final WidgetPreviewLoader . PaintCache mDefaultAppWidgetPreviewPaint = new WidgetPreviewLoader . PaintCache ( ) ; private final WidgetPreviewLoader . BitmapFactoryOptionsCache mCachedBitmapFactoryOptions = new WidgetPreviewLoader . BitmapFactoryOptionsCache ( ) ; private final HashMap < String , WeakReference < Bitmap > > mLoadedPreviews = new HashMap < > ( ) ; private final ArrayList < SoftReference < Bitmap > > mUnusedBitmaps = new ArrayList < > ( ) ; private final Context mContext ; private final int mAppIconSize ; private final IconCache mIconCache ; private final AppWidgetManagerCompat mManager ; private int mPreviewBitmapWidth ; private int mPreviewBitmapHeight ; private String mSize ; private PagedViewCellLayout mWidgetSpacingLayout ; private String mCachedSelectQuery ; private WidgetPreviewLoader . CacheDb mDb ; private final MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor ( ) ; public WidgetPreviewLoader ( Context context ) { } public void recreateDb ( ) { } public void setPreviewSize ( int previewWidth , int previewHeight , PagedViewCellLayout widgetSpacingLayout ) { } public Bitmap getPreview ( final Object o ) { } public void recycleBitmap ( Object o , Bitmap bitmapToRecycle ) { } static class CacheDb extends SQLiteOpenHelper { static final int DB_VERSION = 2 ; static final String TABLE_NAME = "shortcut_and_widget_previews" ; static final String COLUMN_NAME = "name" ; static final String COLUMN_SIZE = "size" ; static final String COLUMN_PREVIEW_BITMAP = "preview_bitmap" ; Context mContext ; public CacheDb ( Context context ) { } @ Override public void onCreate ( SQLiteDatabase database ) { } @ Override public void onUpgrade ( SQLiteDatabase db , int oldVersion , int newVersion ) { } } private static final String WIDGET_PREFIX = "Widget:" ; private static final String SHORTCUT_PREFIX = "Shortcut:" ; private static String getObjectName ( Object o ) { } private String getObjectPackage ( Object o ) { } private void writeToDb ( Object o , Bitmap preview ) { } private void clearDb ( ) { } public static void removePackageFromDb ( final WidgetPreviewLoader . CacheDb cacheDb , final String packageName ) { } private static void removeItemFromDb ( final WidgetPreviewLoader . CacheDb cacheDb , final String objectName ) { } private Bitmap readFromDb ( String name , Bitmap b ) { } private Bitmap generatePreview ( Object info , Bitmap preview ) { } public Bitmap generateWidgetPreview ( AppWidgetProviderInfo info , Bitmap preview ) { } public int maxWidthForWidgetPreview ( int spanX ) { } public int maxHeightForWidgetPreview ( int spanY ) { } public Bitmap generateWidgetPreview ( AppWidgetProviderInfo info , int cellHSpan , int cellVSpan , int maxPreviewWidth , int maxPreviewHeight , Bitmap preview , int [ ] preScaledWidthOut ) { } private Bitmap generateShortcutPreview ( ResolveInfo info , int maxWidth , int maxHeight , Bitmap preview ) { Bitmap tempBitmap = mCachedShortcutPreviewBitmap . get ( ) ; final Canvas c = mCachedShortcutPreviewCanvas . get ( ) ; if ( ( ( tempBitmap == null ) || ( ( tempBitmap . getWidth ( ) ) != maxWidth ) ) || ( ( tempBitmap . getHeight ( ) ) != maxHeight ) ) { tempBitmap = Bitmap . createBitmap ( maxWidth , maxHeight , ARGB_8888 ) ; mCachedShortcutPreviewBitmap . set ( tempBitmap ) ; } else { c . setBitmap ( tempBitmap ) ; c . drawColor ( 0 , CLEAR ) ; c . setBitmap ( null ) ; } <START_BUG> Drawable icon = mutateOnMainThread ( mIconCache . getFullResIcon ( info ) ) ; <END_BUG> int paddingTop = mContext . getResources ( ) . getDimensionPixelOffset ( shortcut_preview_padding_top ) ; int paddingLeft = mContext . getResources ( ) . getDimensionPixelOffset ( shortcut_preview_padding_left ) ; int paddingRight = mContext . getResources ( ) . getDimensionPixelOffset ( shortcut_preview_padding_right ) ; int scaledIconWidth = ( maxWidth - paddingLeft ) - paddingRight ; WidgetPreviewLoader . renderDrawableToBitmap ( icon , tempBitmap , paddingLeft , paddingTop , scaledIconWidth , scaledIconWidth ) ; if ( ( preview != null ) && ( ( ( preview . getWidth ( ) ) != maxWidth ) || ( ( preview . getHeight ( ) ) != maxHeight ) ) ) { throw new RuntimeException ( "Improperly<seq2seq4repair_space>sized<seq2seq4repair_space>bitmap<seq2seq4repair_space>passed<seq2seq4repair_space>as<seq2seq4repair_space>argument" ) ; } else if ( preview == null ) { preview = Bitmap . createBitmap ( maxWidth , maxHeight , ARGB_8888 ) ; } c . setBitmap ( preview ) ; Paint p = mCachedShortcutPreviewPaint . get ( ) ; if ( p == null ) { p = new Paint ( ) ; ColorMatrix colorMatrix = new ColorMatrix ( ) ; colorMatrix . setSaturation ( 0 ) ; p . setColorFilter ( new android . graphics . ColorMatrixColorFilter ( colorMatrix ) ) ; p . setAlpha ( ( ( int ) ( 255 * 0.06F ) ) ) ; mCachedShortcutPreviewPaint . set ( p ) ; } c . drawBitmap ( tempBitmap , 0 , 0 , p ) ; c . setBitmap ( null ) ; WidgetPreviewLoader . renderDrawableToBitmap ( icon , preview , 0 , 0 , mAppIconSize , mAppIconSize ) ; return preview ; } private static void renderDrawableToBitmap ( Drawable d , Bitmap bitmap , int x , int y , int w , int h ) { } private Drawable mutateOnMainThread ( final Drawable drawable ) { } private static final int MAX_OPEN_FILES = 1024 ; private static final int SAMPLE_RATE = 23 ; private static void dumpOpenFiles ( ) { } }

Fix:
Drawable icon = mutateOnMainThread ( mIconCache . getFullResIcon ( info . activityInfo ) ) ;