Merge "Avoid stripping empty screens if the workspace is still loading (issue 12523285)" into ub-now-lunchbox
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
index 80c649a..ab25fa9 100644
--- a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
+++ b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
@@ -16,7 +16,6 @@
 
 package com.android.launcher3;
 
-import android.animation.Animator;
 import android.animation.LayoutTransition;
 import android.app.ActionBar;
 import android.app.Activity;
@@ -33,7 +32,6 @@
 import android.graphics.BitmapFactory;
 import android.graphics.Canvas;
 import android.graphics.Matrix;
-import android.graphics.Paint;
 import android.graphics.Point;
 import android.graphics.PorterDuff;
 import android.graphics.Rect;
@@ -248,6 +246,12 @@
             Drawable defaultWallpaper = WallpaperManager.getInstance(a).getBuiltInDrawable(
                     c.getWidth(), c.getHeight(), false, 0.5f, 0.5f);
 
+            if (defaultWallpaper == null) {
+                Log.w(TAG, "Null default wallpaper encountered.");
+                c.setTileSource(null, null);
+                return;
+            }
+
             c.setTileSource(
                     new DrawableTileSource(a, defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE), null);
             c.setScale(1f);
@@ -257,6 +261,7 @@
         public void onSave(WallpaperPickerActivity a) {
             try {
                 WallpaperManager.getInstance(a).clear();
+                a.setResult(RESULT_OK);
             } catch (IOException e) {
                 Log.w("Setting wallpaper to default threw exception", e);
             }
@@ -419,13 +424,15 @@
         // Add a tile for the default wallpaper
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
             DefaultWallpaperInfo defaultWallpaperInfo = getDefaultWallpaper();
-            FrameLayout defaultWallpaperTile = (FrameLayout) createImageTileView(
-                    getLayoutInflater(), 0, null, mWallpapersView, defaultWallpaperInfo.mThumb);
-            setWallpaperItemPaddingToZero(defaultWallpaperTile);
-            defaultWallpaperTile.setTag(defaultWallpaperInfo);
-            mWallpapersView.addView(defaultWallpaperTile, 0);
-            defaultWallpaperTile.setOnClickListener(mThumbnailOnClickListener);
-            defaultWallpaperInfo.setView(defaultWallpaperTile);
+            if (defaultWallpaperInfo != null) {
+                FrameLayout defaultWallpaperTile = (FrameLayout) createImageTileView(
+                        getLayoutInflater(), 0, null, mWallpapersView, defaultWallpaperInfo.mThumb);
+                setWallpaperItemPaddingToZero(defaultWallpaperTile);
+                defaultWallpaperTile.setTag(defaultWallpaperInfo);
+                mWallpapersView.addView(defaultWallpaperTile, 0);
+                defaultWallpaperTile.setOnClickListener(mThumbnailOnClickListener);
+                defaultWallpaperInfo.setView(defaultWallpaperTile);
+            }
         }
 
         // Select the first item; wait for a layout pass so that we initialize the dimensions of
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 7944173..c22a6bf 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2891,7 +2891,7 @@
                 mWorkspaceBackgroundDrawable : null);
     }
 
-    protected void changeWallpaperVisiblity(boolean visible) {
+    void updateWallpaperVisibility(boolean visible) {
         int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
         int curflags = getWindow().getAttributes().flags
                 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;