Skip to content

Commit

Permalink
Handle potential security exceptions in WallpaperManagerCompatVL
Browse files Browse the repository at this point in the history
  • Loading branch information
amirzaidi committed Sep 11, 2018
1 parent d85b164 commit aafd108
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/com/android/launcher3/compat/WallpaperManagerCompatVL.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit aafd108

Please sign in to comment.