From aafd1085a6ba9d5f4dac1abb521391d02c9fdf6c Mon Sep 17 00:00:00 2001 From: Amir Zaidi Date: Tue, 11 Sep 2018 19:40:14 +0200 Subject: [PATCH] Handle potential security exceptions in WallpaperManagerCompatVL --- .../compat/WallpaperManagerCompatVL.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/com/android/launcher3/compat/WallpaperManagerCompatVL.java b/src/com/android/launcher3/compat/WallpaperManagerCompatVL.java index a93a4284a3..16d3fd1d48 100644 --- a/src/com/android/launcher3/compat/WallpaperManagerCompatVL.java +++ b/src/com/android/launcher3/compat/WallpaperManagerCompatVL.java @@ -148,7 +148,12 @@ private void handleResult(String result) { private static final int getWallpaperId(Context context) { if (!Utilities.ATLEAST_NOUGAT) { - Drawable wallpaper = WallpaperManager.getInstance(context).getDrawable(); + Drawable wallpaper = null; + try { + wallpaper = WallpaperManager.getInstance(context).getDrawable(); + } catch (RuntimeException e) { + Log.e(TAG, "Failed to create a wallpaper ID", e); + } if (wallpaper != null) { Bitmap bm = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); Canvas cv = new Canvas(bm); @@ -261,12 +266,16 @@ public void run() { Rect region = new Rect(0, 0, decoder.getWidth(), decoder.getHeight()); bitmap = decoder.decodeRegion(region, options); decoder.recycle(); - } catch (IOException | NullPointerException e) { + } catch (IOException | RuntimeException e) { Log.e(TAG, "Fetching partial bitmap failed, trying old method", e); } } if (bitmap == null) { - drawable = wm.getDrawable(); + try { + drawable = wm.getDrawable(); + } catch (RuntimeException e) { + Log.e(TAG, "Failed to extract the wallpaper drawable", e); + } } }