Fix applying live wallpaper keep stopping
After applying the live wallpaper, the device will show Styles &
wallpapers keeps stopping.
NullPointerException: Attempt to invoke virtual method
'android.widget.ImageView.getDrawable()' on a null object reference
Add null check to skip loadPreviewImage().
Bug: 158814822
Test: Manual
Change-Id: I560fac06c2b3be179b399eba9f58db97f9ffc4ba
diff --git a/src/com/android/wallpaper/picker/CategoryFragment.java b/src/com/android/wallpaper/picker/CategoryFragment.java
index f0b4713..5cf612c 100755
--- a/src/com/android/wallpaper/picker/CategoryFragment.java
+++ b/src/com/android/wallpaper/picker/CategoryFragment.java
@@ -676,16 +676,21 @@
boolean renderInImageWallpaperSurface =
!(wallpaperInfo instanceof LiveWallpaperInfo) && isHomeWallpaper;
- wallpaperInfo.getThumbAsset(activity.getApplicationContext())
- .loadPreviewImage(activity,
- renderInImageWallpaperSurface ? mHomeImageWallpaper : thumbnailView,
- getResources().getColor(R.color.secondary_color));
+ ImageView imageView = renderInImageWallpaperSurface ? mHomeImageWallpaper : thumbnailView;
+ if (imageView != null) {
+ wallpaperInfo.getThumbAsset(activity.getApplicationContext())
+ .loadPreviewImage(activity, imageView,
+ getResources().getColor(R.color.secondary_color));
+ }
+
if (isHomeWallpaper) {
LiveTileOverlay.INSTANCE.detach(thumbnailView.getOverlay());
if (wallpaperInfo instanceof LiveWallpaperInfo) {
- wallpaperInfo.getThumbAsset(activity.getApplicationContext()).loadPreviewImage(
- activity, mHomeImageWallpaper,
- getResources().getColor(R.color.secondary_color));
+ if(mHomeImageWallpaper != null) {
+ wallpaperInfo.getThumbAsset(activity.getApplicationContext()).loadPreviewImage(
+ activity, mHomeImageWallpaper,
+ getResources().getColor(R.color.secondary_color));
+ }
setUpLiveWallpaperPreview(wallpaperInfo);
} else {
if (mWallpaperConnection != null) {